We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21595
    • 159 Posts
    y aurait-il par là un courageux qui pourrait adapter le snippet etogal - galerie de photos - pour l’avoir essayé avec etomite cra j’ai été conquis.
    J’ai essayé de mettre un peu les mains dans le code mais les résultats ne sont pas convaincants.
    merci
      • 18397
      • 3,250 Posts
      Assuming this is what you said in English,

      "would be there by there courageous which could adapt the snippet etogal - gallery of photographs - to have tested it with etomite CRA I was conquered. I tried to put a little the hands in the code but the results are not convincing mercy"

      Minigallery:

      /*
      Modified version of "Etogal" snippet by "hugelmopf".
      
      http://www.etomite.org/forums/index.php?showtopic=3022
      
      Add this gallery to any page by calling [[MiniGallery]].
      
      A folder with the name of the page alias will be created automatically in $path_to_galleries (the only thing you have to adjust - see below), and all pictures/thumbnails for this page's gallery will be uploaded/created in this folder. Database creation and everything else is taken care of automatically.
      
      Access rights for managing the pictures (uploading, changing the title, deleting) are granted according to the access rights of the page that the gallery is created on. This of course means, the user has to have logged in before (in the Manager), for managing pictures.
      
      There are the following options you can pass to the MiniGallery Snippet:
      
      [[MiniGallery?display=embedded]]       no title/description will be displayed for the gallery (useful to embed it within some text on any page).
      [[MiniGallery?display=childgalleries]] it will display an overview of all galleries that exist in its children pages
      If none of these are passed (which should be what you use most of the time), it displays gallery title, gallery description, pictures with their titles and if approbiate the manage-link. Just try it out ...
      
      [[MiniGallery?pics_in_a_row=3]]        to make it display 3 pictures in a row (default: 3)
      
      [[MiniGallery?max_dim=150]]            to specify the maximum dimension for thumbnail CREATION (default: 150)
      
      or e. g. [[MiniGallery?display=embedded&pics_in_a_row=4]] for more then one Option.
      */
      
      // ----- Setting(s) ------
      // Path where the galleries will be stored (you have to create it and make it writeable!)
      $path_to_galleries="assets/galleries/";
      // ---------------------
      
      $tbl_prefix=$etomite->dbConfig['table_prefix'];
      $pics_tbl="etogal";
      $pics_tbl_full=$tbl_prefix.$pics_tbl;
      
      $returnstring="";
      
      if(!isset($pics_in_a_row)) $pics_in_a_row=3;
      if(!isset($max_dim)) $max_dim=150;
      
      // If gallery table has not been created yet, create it now:
      $query=mysql_query("SELECT COUNT(*) FROM $pics_tbl_full");
      if(!$query) {
        $sql="  CREATE TABLE $pics_tbl_full (
                `id` int(10) unsigned NOT NULL auto_increment,
                `gal_alias` varchar(50) NOT NULL,
                `filename` varchar(50) NOT NULL,
                `title` text NOT NULL,
                `date` datetime NOT NULL,
                PRIMARY KEY  (`id`)
                ) TYPE=MyISAM AUTO_INCREMENT=1 ;";
        $query1=$etomite->dbQuery($sql);
      }
      
      
      
      if($display=="childgalleries") {
        $pageinfo=$etomite->getPageInfo($etomite->documentIdentifier,1, "id, pagetitle, description, alias, createdby");
        $children = $etomite->getActiveChildren($pageinfo['id'], "menuindex", "ASC", $fields='id, pagetitle, longtitle, description, parent, alias');
        $returnstring.="<table border=\"0\" width=\"100%\">";
      
        $number_in_row=0;
        $total_number=0;
        foreach($children as $child) {
          $thumb=$modx->getIntTableRows("filename", $pics_tbl, "gal_alias='" . $child['alias'] . "'","date","DESC","1");
          if($thumb[0]['filename']=="") continue ;
          if($number_in_row==0) {
            $returnstring.="<tr>";
          }
          $childself = $this->config['friendly_urls']==1 ? $child['alias'] : "index.php?id=".$child['id'];
      
          $returnstring.="
            <td align=\"center\" style=\"width:" . floor(100/$pics_in_a_row) . "%\">
            <a href=\"".$childself."\">
            <img src=\"".$path_to_galleries.$child['alias']."/tn_".$thumb[0]['filename']."\" class=\"thumbnail\" title=\"Go to gallery ->\" alt=\"Preview of gallery\" />
            </a>
            <br/>" . htmlentities(stripslashes($child['pagetitle'])) . "</td>";
      
          if($number_in_row==($pics_in_a_row-1) || $total_number==count($children)) {
            $returnstring.="</tr>";
            $number_in_row=-1;
          }
          $number_in_row++;
          $total_number++;
        }
      
        $returnstring.="</table>";
        return $returnstring;
      }
      
      
      
      $pageinfo=$etomite->getPageInfo($etomite->documentIdentifier,1, "id, pagetitle, longtitle, description, alias, createdby");
      
      $path_to_gal=$path_to_galleries.$pageinfo['alias']."/";
      
      $phpself = $this->config['friendly_urls']==1 ? $pageinfo['alias'] : "index.php?id=".$pageinfo['id'];
      $append = $this->config['friendly_urls']==1 ? "?" : "&";
      
      // figure out access permissions of the user viewing this page
      //$userdetails=$etomite->userLoggedIn();
      $userdetails['id']=$_SESSION['mgrInternalKey'];
      
      if($userdetails['id']) {
        // check whether user is allowed to modify this page (-> $result1=1)
        $rs1=$etomite->dbQuery("SELECT * FROM (" . $tbl_prefix . "member_groups JOIN " . $tbl_prefix . "membergroup_access ON user_group=membergroup) JOIN " . $tbl_prefix . "document_groups ON documentgroup=document_group WHERE member='" . $userdetails['id'] . "' and document='" . $etomite->documentIdentifier . "'");
        $result1=mysql_num_rows($rs1);
      
        // check if user is administrator (-> $result2=1)
        $rs2=$etomite->dbQuery("SELECT * FROM " . $tbl_prefix . "user_attributes WHERE id='" . $userdetails['id'] . "' AND role='1'");
        $result2=mysql_num_rows($rs2);
      
        if($result1>0 || $result2>0) $access_permitted=1;
        else $access_permitted=0;
      }
      else $access_permitted=0;
      
      
      function createthumb($filename,$path_to_gal,$max_dim) {
        // Create thumbnails
        $src=imagecreatefromjpeg($path_to_gal.$filename);
        $src_size = getimagesize( $path_to_gal.$filename );
      
        if($src_size[0]>$src_size[1]) { //if width > height
          $new_width=$max_dim;
          $new_height=$src_size[1]*($new_width/$src_size[0]);
        }
      
        else {
          $new_height=$max_dim;
          $new_width=$src_size[0]*($new_height/$src_size[1]);
        }
        $dest=imagecreatetruecolor($new_width,$new_height);
        imagecopyresized($dest,$src,0,0,0,0,$new_width,$new_height,$src_size[0],$src_size[1]);
        imagejpeg($dest,$path_to_gal."tn_".$filename);
      }
      
      
      
      
      
      if($access_permitted==1) {
        if($_REQUEST['mode']=="admin") {  // if user is allowed to modify and has entered admin mode:
          // Processors -----------------
          if($_REQUEST['action']=="upload_pics") {    // If "Upload pictures" has been used
            if(!file_exists($path_to_gal)) {
              mkdir($path_to_gal);
            }
            for($i=0;$i<10;$i++) {
              $name=strtolower($_FILES['file'.$i]['name']);
              if (file_exists($path_to_gal.$name)) { $name="a" . $name; }
              if($name!="" && $name!="a") {
                // Upload file(s) to gallery folder
                if(substr_count($name,".jpg")>0 || substr_count($name,".jpeg")>0) {
                  move_uploaded_file( $_FILES['file'.$i]['tmp_name'] , $path_to_gal.$name );
                  chmod($path_to_gal.$name,0644);
                  createthumb($name,$path_to_gal,$max_dim);
                  $rs1=$etomite->dbQuery("INSERT INTO " . $pics_tbl_full . " VALUES(NULL,'" . $pageinfo['alias'] . "','" . $name . "','',NOW())");
                }
      
                if(substr_count($name,".zip")>0) {
                  move_uploaded_file( $_FILES['file'.$i]['tmp_name'] , $path_to_gal.$name );
                  chmod($path_to_gal.$name,0644);
      
                  $zip = zip_open($path_to_gal.$name);
      
                  if ($zip) {
                    while ($zip_entry = zip_read($zip)) {
                      $jpgfilename=strtolower(zip_entry_name($zip_entry));
                      if (file_exists($path_to_gal.$jpgfilename)) { $jpgfilename="a" . $jpgfilename; }
                      if (zip_entry_open($zip, $zip_entry, "r")) {
                        $jpgfile=fopen($path_to_gal.$jpgfilename,"a+b");
                        fwrite($jpgfile,zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
                        fclose($jpgfile);
                        createthumb($jpgfilename,$path_to_gal,$max_dim);
                        $rs1=$etomite->dbQuery("INSERT INTO " . $pics_tbl_full . " VALUES(NULL,'" . $pageinfo['alias'] . "','" . $jpgfilename . "','',NOW())");
                        zip_entry_close($zip_entry);
                      }
                    }
                    zip_close($zip);
                  }
                  unlink($path_to_gal.$name);
                }
              }
            }
            $returnstring.="Pictures successfully uploaded.";
          }
        
      
          if($_REQUEST['action']=="edit_pics") {    // If "Edit Gallery and its pictures" has been used
            for($i=0;$i<$_REQUEST['number'];$i++) {
              if($_REQUEST['delete'.$i]=="yes") {
                $rs0=$etomite->dbQuery("SELECT id,filename FROM $pics_tbl_full WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
                $deletepic=$etomite->fetchRow($rs0);
                unlink($path_to_gal.$deletepic['filename']);
                unlink($path_to_gal . "tn_" . $deletepic['filename']);
                $rs1=$etomite->dbQuery("DELETE FROM $pics_tbl_full WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
              }
              if($_REQUEST['modified'.$i]=="yes") {
                $rs2=$etomite->dbQuery("UPDATE " . $pics_tbl_full . " SET title='" . addslashes($_REQUEST['title'.$i]) . "',date=NOW() WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
              }
            }
            $returnstring.="Changes have been saved.";
          }
      
          // Forms -----------
          // Edit gallery and its pictures
          $returnstring.="
          <form action=\"".$phpself."\" method=\"post\" name=\"activateviewform\">
          <input type=\"hidden\" name=\"mode\" value=\"view\">
          <center><input type=\"submit\" value=\"Back to normal view\"></center>
          </form>";
          $returnstring.="<h2>" . htmlentities($pageinfo['pagetitle']) . "</h2>";
          $returnstring.="<p style=\"padding-left:4px;\">" . htmlentities($pageinfo['description']) . "</p>
          <form action=\"".$phpself."\" method=\"post\" name=\"editform\">
          <input type=\"hidden\" name=\"action\" value=\"edit_pics\">
          <input type=\"hidden\" name=\"mode\" value=\"admin\">
          <input type=\"submit\" value=\"Save changes\">
          <table border=\"0\">
          ";
        
          $rs1=$etomite->dbQuery("SELECT id,title,filename FROM " . $pics_tbl_full . " WHERE gal_alias='" . $pageinfo['alias'] . "' ORDER BY date DESC");
      
      
          $i=0;
          while($pic=$etomite->fetchRow($rs1)) {
            $file = $path_to_gal.$pic['filename'] ;
            $tn_file = $path_to_gal . "tn_" . $pic['filename'] ;
        
            $returnstring.="
            <input type=\"hidden\" name=\"pic_id$i\" value=\"" . $pic['id'] . "\">
            <input type=\"hidden\" name=\"modified$i\" value=\"no\">
            <tr>
              <td><a href=\"$file\" target=_new><img src=\"$tn_file\" class=\"thumbnail\" alt=\"Thumbnail: Click to zoom ->\" /></a></td>
              <td>Delete: <input type=\"checkbox\" name=\"delete$i\" value=\"yes\" title=\"Check to delete this picture\"></td>
              <td>Title: <textarea name=\"title$i\" rows=\"3\" cols=\"30\" onKeyDown=\"document.editform.modified$i.value='yes'\">" . stripslashes($pic['title']) . "</textarea></td>
            </tr>
            ";
            $i++;
          }
          $returnstring.="
          </table>
          <input type=\"hidden\" name=\"number\" value=\"$i\">
          <input type=\"submit\" value=\"Save changes\">
          </form>
          <form action=\"".$phpself."\" method=\"post\" enctype=\"multipart/form-data\" name=\"uploadform\">
          <input type=\"hidden\" name=\"action\" value=\"upload_pics\">
          <input type=\"hidden\" name=\"mode\" value=\"admin\">
          ";
          for($i=0;$i<10;$i++) $returnstring.="<input name=\"file$i\" type=\"file\">";
          $returnstring.="
          <input type=\"submit\" value=\"Upload Pictures\">
          </form>
          ";
      
          return $returnstring;
        }
      
        
        else { // if user is allowed to modify, but has not entered admin mode yet
          $returnstring.="
          <form action=\"".$phpself."\" method=\"post\" name=\"activateadminform\">
          <input type=\"hidden\" name=\"mode\" value=\"admin\">
          <center><input type=\"submit\" value=\"Manage Pictures\"></center>
          </form>
          ";
        }
      }
      
      
      
      if ($_REQUEST['pic']) { // Show single Pic
        $pics=$modx->getIntTableRows("title,filename", $pics_tbl, "id='" . $_REQUEST['pic'] . "'");
      
        $returnstring.="
        <p style=\"padding-left:10px;\">
          <a href=\"".$phpself."\">" . htmlentities($pageinfo['pagetitle']) . "</a> »
          <a href=\"" . $path_to_gal . $pics[0]['filename'] . "\" target=_blank>" . htmlentities($pics[0]['filename']) . "</a>
        </p>";
      
        $returnstring.="
        <center>
          <a href=\"".$phpself."\"><img src=\"" . $path_to_gal.$pics[0]['filename'] . "\" class=\"imageview\" title=\"<- Back\" alt=\"<- Click to go back\" /></a><br/>
        <p>" . htmlentities(stripslashes($pics[0]['title'])) . "</p></center>
        ";
      }
      
      else { // Show gallery overview with thumbnails
        if(!$display=="embedded") {
          $returnstring.="
          <h2>" . htmlentities($pageinfo['pagetitle']) . "</h2>";
          $returnstring.="
          <p style=\"padding-left:4px;\">" . htmlentities($pageinfo['description']) . "</p>" ;
        }
      
        $returnstring.="
        <table border=\"0\" width=\"100%\">";
      
        $pics=$modx->getIntTableRows("id,title,filename", $pics_tbl, "gal_alias='" . $pageinfo['alias'] . "'","date","DESC");
        $number_in_row=0;
        $total_number=0;
        foreach($pics as $pic) {
          $file = $path_to_gal . $pic['filename'] ;
      
          $tn_file = $path_to_gal . "tn_" . $pic['filename'] ;
          if($number_in_row==0) {
            $returnstring.="<tr>";
          }
      
          $link=($display==embedded) ? ($file) : ($phpself.$append."pic=" . $pic['id']);
          $returnstring.="
          <td align=\"center\" style=\"width:" . floor(100/$pics_in_a_row) . "%\">
            <a href=\"" . $link . "\"><img src=\"$tn_file\" class=\"thumbnail\" title=\"Zoom ->\" alt=\"Click to zoom ->\" /></a><br/>
            " . htmlentities(stripslashes($pic['title'])) . "
          </td>";
      
          if($number_in_row==($pics_in_a_row-1) || $total_number==(count($pics)-1)) {
            $returnstring.="
            </tr>";
            $number_in_row=-1;
          }
          $number_in_row++;
          $total_number++;
        }
        $returnstring.="
        </table>";
      }
      
      
      return $returnstring;
      
        • 21595
        • 159 Posts
        one thousands thanks.
        I try immediatly.
        Good translation wink not for the CRA it was a mistake rolleyes

        everythihng is working grin
          • 6726
          • 7,075 Posts
          This is cool laugh

          Thanks Mark !!!
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 18397
            • 3,250 Posts
            Your welcome.

            NOTE: I did not write or modify the snippet in any way. This one has been floating around the forums for quite some time.....
              • 1448
              • 15 Posts
              Hello

              I tried to install and use the MiniGallery snippet, but when I call a page with this snippet I get the following error:

              « MODx Parse Error »
              MODx encountered the following error while attempting to parse the requested resource:
              « Execution of a query to the database failed - You have an error in your SQL syntax near ’ON user_group=membergroup) JOIN modx_document_groups ON documentgroup=document_g’ at line 1 »
              SQL: SELECT * FROM (modx_member_groups JOIN modx_membergroup_access ON user_group=membergroup) JOIN modx_document_groups ON documentgroup=document_group WHERE member=’1’ and document=’14’

              Can someone help me with this?

              Thanks!
                • 18397
                • 3,250 Posts
                It seems that some changes in MODx9 broke this snippet.
                  • 18397
                  • 3,250 Posts
                  The problem was not with x9 but a developer mistake:

                  Here is the working code:

                  /*
                  Modified version of "Etogal" snippet by "hugelmopf".
                  
                  http://www.modx.org/forums/index.php?showtopic=3022
                  
                  Add this gallery to any page by calling [[MiniGallery]].
                  
                  A folder with the name of the page alias will be created automatically in $path_to_galleries (the only thing you have to adjust - see below), and all pictures/thumbnails for this page's gallery will be uploaded/created in this folder. Database creation and everything else is taken care of automatically.
                  
                  Access rights for managing the pictures (uploading, changing the title, deleting) are granted according to the access rights of the page that the gallery is created on. This of course means, the user has to have logged in before (in the Manager), for managing pictures.
                  
                  There are the following options you can pass to the MiniGallery Snippet:
                  
                  [[MiniGallery?display=embedded]]       no title/description will be displayed for the gallery (useful to embed it within some text on any page).
                  [[MiniGallery?display=childgalleries]] it will display an overview of all galleries that exist in its children pages
                  If none of these are passed (which should be what you use most of the time), it displays gallery title, gallery description, pictures with their titles and if approbiate the manage-link. Just try it out ...
                  
                  [[MiniGallery?pics_in_a_row=3]]        to make it display 3 pictures in a row (default: 3)
                  
                  [[MiniGallery?max_dim=150]]            to specify the maximum dimension for thumbnail CREATION (default: 150)
                  
                  or e. g. [[MiniGallery?display=embedded&pics_in_a_row=4]] for more then one Option.
                  */
                  
                  // ----- Setting(s) ------
                  // Path where the galleries will be stored (you have to create it and make it writeable!)
                  $path_to_galleries="assets/galleries/";
                  // ---------------------
                  
                  $tbl_prefix=$modx->dbConfig['table_prefix'];
                  $pics_tbl="etogal";
                  $pics_tbl_full=$tbl_prefix.$pics_tbl;
                  
                  $returnstring="";
                  
                  if(!isset($pics_in_a_row)) $pics_in_a_row=3;
                  if(!isset($max_dim)) $max_dim=150;
                  
                  // If gallery table has not been created yet, create it now:
                  $query=$modx->dbQuery("SELECT COUNT(*) FROM $pics_tbl_full");
                  if(!$query) {
                    $sql="  CREATE TABLE $pics_tbl_full (
                            `id` int(10) unsigned NOT NULL auto_increment,
                            `gal_alias` varchar(50) NOT NULL,
                            `filename` varchar(50) NOT NULL,
                            `title` text NOT NULL,
                            `date` datetime NOT NULL,
                            PRIMARY KEY  (`id`)
                            ) TYPE=MyISAM AUTO_INCREMENT=1 ;";
                    $query1=$modx->dbQuery($sql);
                  }
                  
                  
                  
                  if($display=="childgalleries") {
                    $pageinfo=$modx->getPageInfo($modx->documentIdentifier,1, "id, pagetitle, description, alias, createdby");
                    $children = $modx->getActiveChildren($pageinfo['id'], "menuindex", "ASC", $fields='id, pagetitle, longtitle, description, parent, alias');
                    $returnstring.="<table border=\"0\" width=\"100%\">";
                  
                    $number_in_row=0;
                    $total_number=0;
                    foreach($children as $child) {
                      $thumb=$modx->getIntTableRows("filename", $pics_tbl, "gal_alias='" . $child['alias'] . "'","date","DESC","1");
                      if($thumb[0]['filename']=="") continue ;
                      if($number_in_row==0) {
                        $returnstring.="<tr>";
                      }
                      $childself = $this->config['friendly_urls']==1 ? $child['alias'] : "index.php?id=".$child['id'];
                  
                      $returnstring.="
                        <td align=\"center\" style=\"width:" . floor(100/$pics_in_a_row) . "%\">
                        <a href=\"".$childself."\">
                        <img src=\"".$path_to_galleries.$child['alias']."/tn_".$thumb[0]['filename']."\" class=\"thumbnail\" title=\"Go to gallery ->\" alt=\"Preview of gallery\" />
                        </a>
                        <br/>" . htmlentities(stripslashes($child['pagetitle'])) . "</td>";
                  
                      if($number_in_row==($pics_in_a_row-1) || $total_number==count($children)) {
                        $returnstring.="</tr>";
                        $number_in_row=-1;
                      }
                      $number_in_row++;
                      $total_number++;
                    }
                  
                    $returnstring.="</table>";
                    return $returnstring;
                  }
                  
                  
                  
                  $pageinfo=$modx->getPageInfo($modx->documentIdentifier,1, "id, pagetitle, longtitle, description, alias, createdby");
                  
                  $path_to_gal=$path_to_galleries.$pageinfo['alias']."/";
                  
                  $phpself = $this->config['friendly_urls']==1 ? $pageinfo['alias'] : "index.php?id=".$pageinfo['id'];
                  $append = $this->config['friendly_urls']==1 ? "?" : "&";
                  
                  // figure out access permissions of the user viewing this page
                  //$userdetails=$modx->userLoggedIn();
                  $userdetails['id']=$_SESSION['mgrInternalKey'];
                  
                  if($userdetails['id']) {
                    // check whether user is allowed to modify this page (-> $result1=1)
                    $rs1=$modx->dbQuery("SELECT * FROM (" . $tbl_prefix . "member_groups JOIN " . $tbl_prefix . "membergroup_access ON user_group=membergroup) JOIN " . $tbl_prefix . "document_groups ON documentgroup=document_group WHERE member='" . $userdetails['id'] . "' and document='" . $modx->documentIdentifier . "'");
                    $result1=mysql_num_rows($rs1);
                  
                    // check if user is administrator (-> $result2=1)
                    $rs2=$modx->dbQuery("SELECT * FROM " . $tbl_prefix . "user_attributes WHERE id='" . $userdetails['id'] . "' AND role='1'");
                    $result2=mysql_num_rows($rs2);
                  
                    if($result1>0 || $result2>0) $access_permitted=1;
                    else $access_permitted=0;
                  }
                  else $access_permitted=0;
                  
                  
                  function createthumb($filename,$path_to_gal,$max_dim) {
                    // Create thumbnails
                    $src=imagecreatefromjpeg($path_to_gal.$filename);
                    $src_size = getimagesize( $path_to_gal.$filename );
                  
                    if($src_size[0]>$src_size[1]) { //if width > height
                      $new_width=$max_dim;
                      $new_height=$src_size[1]*($new_width/$src_size[0]);
                    }
                  
                    else {
                      $new_height=$max_dim;
                      $new_width=$src_size[0]*($new_height/$src_size[1]);
                    }
                    $dest=imagecreatetruecolor($new_width,$new_height);
                    imagecopyresized($dest,$src,0,0,0,0,$new_width,$new_height,$src_size[0],$src_size[1]);
                    imagejpeg($dest,$path_to_gal."tn_".$filename);
                  }
                  
                  
                  
                  
                  
                  if($access_permitted==1) {
                    if($_REQUEST['mode']=="admin") {  // if user is allowed to modify and has entered admin mode:
                      // Processors -----------------
                      if($_REQUEST['action']=="upload_pics") {    // If "Upload pictures" has been used
                        if(!file_exists($path_to_gal)) {
                          mkdir($path_to_gal);
                        }
                        for($i=0;$i<10;$i++) {
                          $name=strtolower($_FILES['file'.$i]['name']);
                          if (file_exists($path_to_gal.$name)) { $name="a" . $name; }
                          if($name!="" && $name!="a") {
                            // Upload file(s) to gallery folder
                            if(substr_count($name,".jpg")>0 || substr_count($name,".jpeg")>0) {
                              move_uploaded_file( $_FILES['file'.$i]['tmp_name'] , $path_to_gal.$name );
                              chmod($path_to_gal.$name,0644);
                              createthumb($name,$path_to_gal,$max_dim);
                              $rs1=$modx->dbQuery("INSERT INTO " . $pics_tbl_full . " VALUES(NULL,'" . $pageinfo['alias'] . "','" . $name . "','',NOW())");
                            }
                  
                            if(substr_count($name,".zip")>0) {
                              move_uploaded_file( $_FILES['file'.$i]['tmp_name'] , $path_to_gal.$name );
                              chmod($path_to_gal.$name,0644);
                  
                              $zip = zip_open($path_to_gal.$name);
                  
                              if ($zip) {
                                while ($zip_entry = zip_read($zip)) {
                                  $jpgfilename=strtolower(zip_entry_name($zip_entry));
                                  if (file_exists($path_to_gal.$jpgfilename)) { $jpgfilename="a" . $jpgfilename; }
                                  if (zip_entry_open($zip, $zip_entry, "r")) {
                                    $jpgfile=fopen($path_to_gal.$jpgfilename,"a+b");
                                    fwrite($jpgfile,zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
                                    fclose($jpgfile);
                                    createthumb($jpgfilename,$path_to_gal,$max_dim);
                                    $rs1=$modx->dbQuery("INSERT INTO " . $pics_tbl_full . " VALUES(NULL,'" . $pageinfo['alias'] . "','" . $jpgfilename . "','',NOW())");
                                    zip_entry_close($zip_entry);
                                  }
                                }
                                zip_close($zip);
                              }
                              unlink($path_to_gal.$name);
                            }
                          }
                        }
                        $returnstring.="Pictures successfully uploaded.";
                      }
                    
                  
                      if($_REQUEST['action']=="edit_pics") {    // If "Edit Gallery and its pictures" has been used
                        for($i=0;$i<$_REQUEST['number'];$i++) {
                          if($_REQUEST['delete'.$i]=="yes") {
                            $rs0=$modx->dbQuery("SELECT id,filename FROM $pics_tbl_full WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
                            $deletepic=$modx->fetchRow($rs0);
                            unlink($path_to_gal.$deletepic['filename']);
                            unlink($path_to_gal . "tn_" . $deletepic['filename']);
                            $rs1=$modx->dbQuery("DELETE FROM $pics_tbl_full WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
                          }
                          if($_REQUEST['modified'.$i]=="yes") {
                            $rs2=$modx->dbQuery("UPDATE " . $pics_tbl_full . " SET title='" . addslashes($_REQUEST['title'.$i]) . "',date=NOW() WHERE id='" . $_REQUEST['pic_id'.$i] . "'");
                          }
                        }
                        $returnstring.="Changes have been saved.";
                      }
                  
                      // Forms -----------
                      // Edit gallery and its pictures
                      $returnstring.="
                      <form action=\"".$phpself."\" method=\"post\" name=\"activateviewform\">
                      <input type=\"hidden\" name=\"mode\" value=\"view\">
                      <center><input type=\"submit\" value=\"Back to normal view\"></center>
                      </form>";
                      $returnstring.="<h2>" . htmlentities($pageinfo['pagetitle']) . "</h2>";
                      $returnstring.="<p style=\"padding-left:4px;\">" . htmlentities($pageinfo['description']) . "</p>
                      <form action=\"".$phpself."\" method=\"post\" name=\"editform\">
                      <input type=\"hidden\" name=\"action\" value=\"edit_pics\">
                      <input type=\"hidden\" name=\"mode\" value=\"admin\">
                      <input type=\"submit\" value=\"Save changes\">
                      <table border=\"0\">
                      ";
                    
                      $rs1=$modx->dbQuery("SELECT id,title,filename FROM " . $pics_tbl_full . " WHERE gal_alias='" . $pageinfo['alias'] . "' ORDER BY date DESC");
                  
                  
                      $i=0;
                      while($pic=$modx->fetchRow($rs1)) {
                        $file = $path_to_gal.$pic['filename'] ;
                        $tn_file = $path_to_gal . "tn_" . $pic['filename'] ;
                    
                        $returnstring.="
                        <input type=\"hidden\" name=\"pic_id$i\" value=\"" . $pic['id'] . "\">
                        <input type=\"hidden\" name=\"modified$i\" value=\"no\">
                        <tr>
                          <td><a href=\"$file\" target=_new><img src=\"$tn_file\" class=\"thumbnail\" alt=\"Thumbnail: Click to zoom ->\" /></a></td>
                          <td>Delete: <input type=\"checkbox\" name=\"delete$i\" value=\"yes\" title=\"Check to delete this picture\"></td>
                          <td>Title: <textarea name=\"title$i\" rows=\"3\" cols=\"30\" onKeyDown=\"document.editform.modified$i.value='yes'\">" . stripslashes($pic['title']) . "</textarea></td>
                        </tr>
                        ";
                        $i++;
                      }
                      $returnstring.="
                      </table>
                      <input type=\"hidden\" name=\"number\" value=\"$i\">
                      <input type=\"submit\" value=\"Save changes\">
                      </form>
                      <form action=\"".$phpself."\" method=\"post\" enctype=\"multipart/form-data\" name=\"uploadform\">
                      <input type=\"hidden\" name=\"action\" value=\"upload_pics\">
                      <input type=\"hidden\" name=\"mode\" value=\"admin\">
                      ";
                      for($i=0;$i<10;$i++) $returnstring.="<input name=\"file$i\" type=\"file\">";
                      $returnstring.="
                      <input type=\"submit\" value=\"Upload Pictures\">
                      </form>
                      ";
                  
                      return $returnstring;
                    }
                  
                    
                    else { // if user is allowed to modify, but has not entered admin mode yet
                      $returnstring.="
                      <form action=\"".$phpself."\" method=\"post\" name=\"activateadminform\">
                      <input type=\"hidden\" name=\"mode\" value=\"admin\">
                      <center><input type=\"submit\" value=\"Manage Pictures\"></center>
                      </form>
                      ";
                    }
                  }
                  
                  
                  
                  if ($_REQUEST['pic']) { // Show single Pic
                    $pics=$modx->getIntTableRows("title,filename", $pics_tbl, "id='" . $_REQUEST['pic'] . "'");
                  	$img = $_REQUEST['pic'];
                  	$prev = $img - 1;
                  	$next = $img + 1;
                    $returnstring.="
                    <p style=\"padding-left:10px;\">
                      <a href=\"".$phpself."\">" . htmlentities($pageinfo['pagetitle']) . "</a> »
                      <a href=\"" . $path_to_gal . $pics[0]['filename'] . "\" target=_blank>" . htmlentities($pics[0]['filename']) . "</a>
                    </p>";
                  
                    $returnstring.="
                    <center>
                        <p style=\"text-align:center;\">
                        <a href=\"".$phpself."&pic=".$prev."\">Previous</a> |
                        <a href=\" ".$phpself."&pic=".$next." \">Next</a>
                      </p>
                      <a href=\"".$phpself."\"><img src=\"" . $path_to_gal.$pics[0]['filename'] . "\" class=\"imageview\" style=\"width: 99%\" title=\"<- Back\" alt=\"<- Click to go back\" /></a><br/>
                    <p>" . htmlentities(stripslashes($pics[0]['title'])) . "</p></center>
                    ";
                  }
                  
                  else { // Show gallery overview with thumbnails
                    if(!$display=="embedded") {
                      $returnstring.="
                      <h2>" . htmlentities($pageinfo['pagetitle']) . "</h2>";
                      $returnstring.="
                      <p style=\"padding-left:4px;\">" . htmlentities($pageinfo['description']) . "</p>" ;
                    }
                  
                    $returnstring.="
                    <table border=\"0\" width=\"100%\">";
                  
                    $pics=$modx->getIntTableRows("id,title,filename", $pics_tbl, "gal_alias='" . $pageinfo['alias'] . "'","date","DESC");
                    $number_in_row=0;
                    $total_number=0;
                    foreach($pics as $pic) {
                      $file = $path_to_gal . $pic['filename'] ;
                  
                      $tn_file = $path_to_gal . "tn_" . $pic['filename'] ;
                      if($number_in_row==0) {
                        $returnstring.="<tr>";
                      }
                  
                      $link=($display==embedded) ? ($file) : ($phpself.$append."pic=" . $pic['id']);
                      $returnstring.="
                      <td align=\"center\" style=\"width:" . floor(100/$pics_in_a_row) . "%\">
                        <a href=\"" . $link . "\"><img src=\"$tn_file\" class=\"thumbnail\" title=\"Zoom ->\" alt=\"Click to zoom ->\" /></a><br/>
                        " . htmlentities(stripslashes($pic['title'])) . "
                      </td>";
                  
                      if($number_in_row==($pics_in_a_row-1) || $total_number==(count($pics)-1)) {
                        $returnstring.="
                        </tr>";
                        $number_in_row=-1;
                      }
                      $number_in_row++;
                      $total_number++;
                    }
                    $returnstring.="
                    </table>";
                  }
                  
                  
                  return $returnstring;