' . $lang_search_new_php['select_album'] . '\n'; foreach ($rowset as $row) { $select .= "\n"; } } return "\n\n"; } /** * 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 $CONFIG, $lang_search_new_php; $warning = ''; if (!is_writable($CONFIG['fullpath'] . $dir)) $warning = "\n" . "{$lang_search_new_php['warning']}: {$lang_search_new_php['change_perm']}\n"; return "\n" . sprintf($lang_search_new_php['target_album'], $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 $CONFIG, $expic_array; $encoded_picfile = base64_encode($picfile); $picname = $CONFIG['fullpath'] . $picfile; $pic_url = urlencode($picfile); $pic_fname = basename($picfile); $pic_dirname = dirname($picname); $thumb_file = dirname($picname) . '/' . $CONFIG['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 = ''; } elseif (is_image($picname)) { $img = ''; } else { $file['filepath'] = $pic_dirname.'/'; //substr($picname,0,strrpos($picname,'/')) $file['filename'] = $pic_fname; $filepathname = get_pic_url($file,'thumb'); //$mime_content = get_type($picname); //$extension = file_exists("images/thumb_{$mime_content['extension']}.jpg") ? $mime_content['extension']:$mime_content['content']; //$img = ''; $img = ''; } if (filesize($picname) && is_readable($picname)) { //$fullimagesize = getimagesize($picname); COMMENTED OUT FOR VIDEO SUPPORT $winsizeX = ($fullimagesize[0] + 16); $winsizeY = ($fullimagesize[1] + 16); //$checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked'; $checked = isset($expic_array[$picfile]) ? '' : '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 $CONFIG; $dir = opendir($CONFIG['fullpath'] . $folder); while ($file = readdir($dir)) { if (is_dir($CONFIG['fullpath'] . $folder . $file)) { if ($file != "." && $file != "..") $dir_array[] = $file; } if (is_file($CONFIG['fullpath'] . $folder . $file)) { if (strncmp($file, $CONFIG['thumb_pfx'], strlen($CONFIG['thumb_pfx'])) != 0 && strncmp($file, $CONFIG['normal_pfx'], strlen($CONFIG['normal_pfx'])) != 0 && $file != 'index.html') $pic_array[] = $file; } } closedir($dir); natcasesort($dir_array); natcasesort($pic_array); } function display_dir_tree($folder, $ident) { global $CONFIG, $PHP_SELF, $lang_search_new_php; $dir_path = $CONFIG['fullpath'] . $folder; if (!is_readable($dir_path)) return; $dir = opendir($dir_path); while ($file = readdir($dir)) { //if (is_dir($CONFIG['fullpath'] . $folder . $file) && $file != "." && $file != "..") { // removed by following line for 'do not show folders with dots': gaugau 03-11-02 if (is_dir($CONFIG['fullpath'] . $folder . $file) && substr($file,0,1) != "." && strpos($file,"'") == FALSE && $file != substr($CONFIG['userpics'],0,strlen($CONFIG['userpics'])-1) && $file != "edit" ) { $start_target = $folder . $file; $dir_path = $CONFIG['fullpath'] . $folder . $file; $warnings = ''; if (!is_writable($dir_path)) $warnings .= $lang_search_new_php['dir_ro']; if (!is_readable($dir_path)) $warnings .= $lang_search_new_php['dir_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 $CONFIG; $sql = "SELECT filepath, filename " . "FROM {$CONFIG['TABLE_PICTURES']} " . "WHERE filepath LIKE '$startdir%'"; $result = db_query($sql); while ($row = mysql_fetch_array($result)) { $pic_file = $row['filepath'] . $row['filename']; $pic_array[$pic_file] = 1; } mysql_free_result($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 $CONFIG; $sql = "SELECT aid, title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "WHERE 1"; $result = db_query($sql); while ($row = mysql_fetch_array($result)) { $album_array[$row['aid']] = $row['title']; } mysql_free_result($result); } /** * CPGscandir() //renamed because php5 has same function as 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 CPGscandir($dir, &$expic_array) { $dir = str_replace(".","" ,$dir); 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) { if (substr($directory,0,1) != ".") // added do not show folders with dots: gaugau 03-11-02 CPGscandir($dir . $directory . '/', $expic_array); } } return $count; } /** * Main code */ $album_array = array(); getallalbumsindb($album_array); // We need at least one album if (!count($album_array)) cpg_die(ERROR, $lang_search_new_php['need_one_album'], __FILE__, __LINE__); if (isset($HTTP_POST_VARS['insert'])) { if (!isset($HTTP_POST_VARS['pics'])) cpg_die(ERROR, $lang_search_new_php['no_pic_to_add'], __FILE__, __LINE__); pageheader($lang_search_new_php['page_title']); starttable("100%"); echo <<

{$lang_search_new_php['insert']}

{$lang_search_new_php['folder']} {$lang_search_new_php['image']} {$lang_search_new_php['album']} {$lang_search_new_php['result']} EOT; $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]; $pic_file = base64_decode($HTTP_POST_VARS['picfile_' . $pic_id]); $dir_name = dirname($pic_file) . "/"; $file_name = basename($pic_file); if ($album_id) { // To avoid problems with PHP scripts max execution time limit, each picture is // added individually using a separate script that returns an image $status = "\"\"
"; $album_name = $album_array[$album_id]; } else { $album_name = $lang_search_new_php['no_album']; $status = "\""
"; } echo "\n"; echo "$dir_name\n"; echo "$file_name\n"; echo "$album_name\n"; echo "$status\n"; echo "\n"; $count++; flush(); } echo << {$lang_search_new_php['be_patient']} {$lang_search_new_php['notes']} EOT; endtable(); pagefooter(); ob_end_flush(); } elseif (isset($HTTP_GET_VARS['startdir'])) { pageheader($lang_search_new_php['page_title']); starttable("100%"); echo <<

{$lang_search_new_php['list_new_pic']}

EOT; $expic_array = array(); $check_all = $lang_search_new_php['check_all']; $uncheck_all = $lang_search_new_php['uncheck_all']; // added below table, JavaScript and additional check/uncheck options: gaugau 03-11-02 getallpicindb($expic_array, $HTTP_GET_VARS['startdir']); if (CPGscandir($HTTP_GET_VARS['startdir'] . '/', $expic_array)) { echo <<
EOT; } else { echo <<

{$lang_search_new_php['no_pic_found']}


EOT; } endtable(); pagefooter(); ob_end_flush(); } else { pageheader($lang_search_new_php['page_title']); starttable(-1, $lang_search_new_php['select_dir']); display_dir_tree('', ''); echo << {$lang_search_new_php['select_dir_msg']} EOT; endtable(); pagefooter(); ob_end_flush(); } ?>