prefix("xcgal_albums")." ". "ORDER BY title"; $result = $xoopsDB->query($sql); $user_handler =& xoops_gethandler('member'); while ($row = $xoopsDB->fetchArray($result)) { $alb_owner =& $user_handler->getUser($row['category']-FIRST_USER_CAT); if (is_object ($alb_owner)) $row["title"]= "- (".$alb_owner->uname().")".$row["title"]; $select .= ""; } $xoopsDB->freeRecordSet($result); } return ""; } /** * dirheader() * * return the HTML code for the row to be displayed when we start a new * directory * * @param $dir the directory * @param $dirid the name of the listbox that will list the albums * @return the HTML code **/ function dirheader($dir, $dirid) { global $xoopsModuleConfig; $warning = ''; if (!is_writable(XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$dir)) $warning ="\n". "
"._AM_SRCHNEW_WARNING.": "._AM_SRCHNEW_CHG_PERM."
\n"; return "\n". sprintf(_AM_SRCHNEW_TARGET_ALB, $dir, albumselect($dirid))."\n".$warning; } /** * picrow() * * return the HTML code for a row to be displayed for an image * the row contains a checkbox, the image name, a thumbnail * * @param $picfile the full path of the file that contains the picture * @param $picid the name of the check box * @return the HTML code **/ function picrow($picfile, $picid, $albid) { global $xoopsModuleConfig, $expic_array; $encoded_picfile = base64_encode($picfile); $picname = XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$picfile; $pic_url = urlencode($picfile); $picpath = XOOPS_URL."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$picfile; $pic_fname = basename($picfile); $thumb_file = dirname($picname).'/'.$xoopsModuleConfig['thumb_pfx'].$pic_fname; if(file_exists($thumb_file)){ $thumb_info = getimagesize($picname); $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48); $img =''; } else { $img =''; } if (filesize($picname) && is_readable($picname)) { $fullimagesize = getimagesize($picname); $winsizeX = ($fullimagesize[0] + 16); $winsizeY = ($fullimagesize[1] + 16); $checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked="checked"'; return << $pic_fname $img
EOT; } else { $winsizeX = (300); $winsizeY = (300); return <<   $pic_fname
EOT; } } /** * getfoldercontent() * * return the files and directories of a folder in two arrays * * @param $folder the folder to read * @param $dir_array the array that will contain name of sub-dir * @param $pic_array the array that will contain name of picture * @param $expic_array an array that contains pictures already in db * @return **/ function getfoldercontent($folder, &$dir_array, &$pic_array, &$expic_array) { global $xoopsModuleConfig; $dir = opendir(XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$folder); while($file = readdir($dir)){ if(is_dir(XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$folder.$file)) { if ($file != "." && $file != "..") $dir_array[] = $file; } if(is_file(XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$folder.$file)) { if(strncmp($file, $xoopsModuleConfig['thumb_pfx'], strlen($xoopsModuleConfig['thumb_pfx'])) != 0 && strncmp($file, $xoopsModuleConfig['normal_pfx'], strlen($xoopsModuleConfig['normal_pfx'])) != 0) $pic_array[] = $file; } } closedir($dir); natcasesort($dir_array); natcasesort($pic_array); } function display_dir_tree($folder, $ident) { global $xoopsModuleConfig, $PHP_SELF; $dir_path = XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$folder; if (!is_readable($dir_path)) return; $dir = opendir($dir_path); while($file = readdir($dir)){ if(is_dir(XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$folder.$file) && $file != "." && $file != "..") { $start_target = $folder.$file; $dir_path = XOOPS_ROOT_PATH."/modules/xcgal/".$xoopsModuleConfig['fullpath'].$folder.$file; $warnings = ''; if (!is_writable($dir_path)) $warnings .= _AM_SRCHNEW_DIR_RO; if (!is_readable($dir_path)) $warnings .= _AM_SRCHNEW_CANT_READ; if ($warnings) $warnings = '   '.$warnings.''; echo << $ident $file$warnings EOT; display_dir_tree($folder.$file.'/', $ident.'    '); } } closedir($dir); } /** * getallpicindb() * * Fill an array where keys are the full path of all images in the picture table * * @param $pic_array the array to be filled * @return **/ function getallpicindb(&$pic_array, $startdir) { global $xoopsDB; $sql = "SELECT filepath, filename ". "FROM ".$xoopsDB->prefix("xcgal_pictures")." ". "WHERE filepath LIKE '$startdir%'"; $result = $xoopsDB->query($sql); while ($row = $xoopsDB->fetchArray($result)) { $pic_file = $row['filepath'].$row['filename']; $pic_array[$pic_file]=1; } $xoopsDB->freeRecordSet($result); } /** * getallalbumsindb() * * Fill an array with all albums where keys are aid of albums and values are * album title * * @param $album_array the array to be filled * @return **/ function getallalbumsindb(&$album_array) { global $xoopsDB; $sql = "SELECT aid, title ". "FROM ".$xoopsDB->prefix("xcgal_albums")." ". "WHERE 1"; $result = $xoopsDB->query($sql); while ($row = $xoopsDB->fetchArray($result)) { $album_array[$row['aid']]= $row['title']; } $xoopsDB->freeRecordSet($result); } /** * scandir() * * recursive function that scan a directory, create the HTML code for each * picture and add new pictures in an array * * @param $dir the directory to be scanned * @param $expic_array the array that contains pictures already in DB * @param $newpic_array the array that contains new pictures found * @return **/ function scandir($dir, &$expic_array) { static $dir_id = 0; static $count =0; static $pic_id=0; $pic_array = array(); $dir_array = array(); getfoldercontent($dir, $dir_array, $pic_array, $expic_array ); if (count($pic_array) > 0){ $dir_id_str=sprintf("d%04d", $dir_id++); echo dirheader($dir, $dir_id_str); foreach ($pic_array as $picture) { $count++; $pic_id_str=sprintf("i%04d", $pic_id++); echo picrow($dir.$picture, $pic_id_str, $dir_id_str ); } } if (count($dir_array) > 0){ foreach ($dir_array as $directory) { scandir($dir.$directory.'/', $expic_array); } } return $count; } /************************************************************************** * Main code **************************************************************************/ $album_array = array(); getallalbumsindb($album_array); // We need at least one album if (!count($album_array)) redirect_header('index.php',2,_AM_SRCHNEW_NEED_ONE_ALB); if (isset($HTTP_POST_VARS['insert'])){ if(!isset($HTTP_POST_VARS['pics'])) redirect_header('index.php',2,_AM_SRCHNEW_NO_PIC_ADD); xoops_cp_header(); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $count=0; foreach ($HTTP_POST_VARS['pics'] as $pic_id){ $album_lb_id = $HTTP_POST_VARS['album_lb_id_'.$pic_id]; $album_id = $HTTP_POST_VARS[$album_lb_id]; $album_name = $album_array[$album_id]; $pic_file = base64_decode($HTTP_POST_VARS['picfile_'.$pic_id]); $dir_name = dirname($pic_file)."/"; $file_name = basename($pic_file); // To avoid problems with PHP scripts max execution time limit, each picture is // added individually using a separate script that returns an image $status = "
"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $count++; } echo ""; echo ""; } elseif(isset($HTTP_GET_VARS['startdir'])){ xoops_cp_header(); echo "
"._AM_SRCHNEW_TITLE."
"._AM_SRCHNEW_INSERT."
"._AM_SRCHNEW_FOLDER.""._AM_SRCHNEW_IMAGE.""._AM_SRCHNEW_ALB.""._AM_SRCHNEW_RESULT."
$dir_name$file_name$album_name$status
"._AM_SRCHNEW_PATIENT."
"._AM_SRCHNEW_NOTES."
"; echo ""; echo ""; echo ""; $expic_array = array(); getallpicindb($expic_array, $HTTP_GET_VARS['startdir']); if (scandir($HTTP_GET_VARS['startdir'].'/', $expic_array)){ echo ""; } else { echo ""; } } else { xoops_cp_header(); echo "
"._AM_SRCHNEW_TITLE."
"._AM_SRCHNEW_LIST_NEW."
"; echo ""; echo "
"; echo "


"; echo ""._AM_SRCHNEW_NO_PIC.""; echo "


"; echo ""; display_dir_tree('',''); echo ""; } echo "
"._AM_SRCHNEW_TITLE."
"._AM_SRCHNEW_SEL_DIR_MSG."
"; xoops_cp_footer(); ?>