}
             // get the public custom fields for this item
             $rec->fields = Gallery_utils::Getcustomfields($rec->fileid, $rec->isdir, '', 1);
             if ($rec->thumb != $folderpath) {
                 Gallery_utils::CreateThumbnail($rec->thumb, $originalimage, $galleryinfo['thumbwidth'] > 0 ? $galleryinfo['thumbwidth'] : IM_THUMBWIDTH, $galleryinfo['thumbwidth'] > 0 ? $galleryinfo['thumbheight'] : IM_THUMBHEIGHT, $galleryinfo['thumbwidth'] > 0 ? $galleryinfo['resizemethod'] : 'sc');
             }
             array_push($images, $rec);
         }
     }
     // Sort array $images
     // second parameter of _ArraySort is an array of strings, which contains:
     // n for number, s for string
     // + for ascending, - for descending
     // fieldname
     $sortarray = explode('/', 'n+fileorder/' . $galleryinfo['sortitems']);
     $images = Gallery_utils::ArraySort($images, $sortarray, false);
     $itemcount = count($images);
     // Get the images we want
     $images = array_splice($images, $start - 1, $number);
 } else {
     $params['module_message'] = $this->Lang('message_wrongdir', htmlspecialchars($params['dir']));
     $smarty->assign('hideparentlink', true);
 }
 // Expose the list to smarty. Use "by_ref" to save memory.
 $smarty->assign_by_ref('images', $images);
 // and a count of records
 $smarty->assign('imagecount', $imgcount . ' ' . ($imgcount == 1 ? $this->Lang('image') : $this->Lang('images')));
 $smarty->assign('itemcount', $itemcount);
 $smarty->assign('numimages', $imgcount);
 $smarty->assign('numdirs', $itemcount - $imgcount);
 $smarty->assign('number', $number);
 function GetGallerytree($subgallery, $sortitems, &$output, &$galleries)
 {
     $sortarray = explode('/', 'n+fileorder/' . $sortitems);
     $subgalleries = Gallery_utils::ArraySort($subgallery, $sortarray, false);
     foreach ($subgalleries as $key => $subgallery) {
         $output[] = $subgallery;
         if (array_key_exists('gid' . $subgallery->fileid, $galleries)) {
             GetGallerytree($galleries['gid' . $subgallery->fileid], $subgallery->sortitems, $output, $galleries);
         }
     }
 }
         if (!file_exists('../' . DEFAULT_GALLERY_PATH . $file['filepath'] . IM_PREFIX . $file['filename'])) {
             Gallery_utils::CreateThumbnail('../' . DEFAULT_GALLERY_PATH . $file['filepath'] . IM_PREFIX . $file['filename'], '../' . DEFAULT_GALLERY_PATH . $file['filepath'] . $file['filename'], IM_THUMBWIDTH, IM_THUMBHEIGHT, 'sc');
         }
         $onerow->editlink = $permission_to_edit ? $this->CreateLink($id, 'editimage', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', $this->Lang('editimage'), '', '', 'systemicon'), array('fid' => $file['fileid'], 'mode' => 'edit')) : '';
         $onerow->editurl = $permission_to_edit ? $this->CreateLink($id, 'editimage', $returnid, '', array('fid' => $file['fileid'], 'mode' => 'edit'), '', true) : '';
         $onerow->edittext = $this->Lang('editimage');
         $onerow->deletelink = $permission_to_edit ? $this->CreateLink($id, 'multiaction', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', $this->Lang('delete'), '', '', 'systemicon'), array('multiaction' => 'delete', 'gid' => $file['galleryid'], 'fid' => $file['fileid'], 'origaction' => 'editgallery'), $this->Lang('areyousure')) : '';
         $onerow->activelink = $permission_to_edit ? $onerow->activelink : ($file['active'] ? $trueimage : $falseimage);
     }
     $onerow->imgselect = $this->CreateInputCheckbox($id, 'imgselect[' . $file['fileid'] . ']', 1);
     if ($file['fileid'] != 1) {
         array_push($showgallery, $onerow);
     }
 }
 $sortarray = explode('/', 'n+fileorder/' . $galleryinfo['sortitems']);
 $showgallery = Gallery_utils::ArraySort($showgallery, $sortarray, false);
 $smarty->assign_by_ref('items', $showgallery);
 $smarty->assign('itemcount', count($showgallery));
 $smarty->assign('item', $this->Lang('item'));
 $smarty->assign('title', $this->Lang('title'));
 $smarty->assign('comment', $this->Lang('comment'));
 $smarty->assign('filedate', $this->Lang('date'));
 $smarty->assign('cover', $this->Lang('albumcover'));
 $smarty->assign('active', $this->Lang('active'));
 $smarty->assign('nofilestext', $this->lang("nofilestext"));
 $smarty->assign('formstart', $this->CreateFormStart($id, 'do_editgallery', $returnid, 'post', '', false, '', $params));
 $smarty->assign('gallerytitle', $this->CreateInputText($id, 'gallerytitle', $galleryinfo['title'], 40, 100, $disabled));
 $smarty->assign('gallerycomment', $this->CreateTextArea($this->GetPreference('use_comment_wysiwyg', 1), $id, $galleryinfo['comment'], 'gallerycomment', 'fake" style="height:6em;', '', '', '', '80', '3', '', '', $disabled));
 if ($this->GetPreference('editdirdates')) {
     $smarty->assign('gallerydate', $this->CreateInputText($id, 'gallerydate', substr($galleryinfo['filedate'], 0, 10), 10, 10, $disabled));
 } else {