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".$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 <<
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 "
"._AM_SRCHNEW_TITLE."
";
echo "
"._AM_SRCHNEW_INSERT."
";
echo "
";
echo "
"._AM_SRCHNEW_FOLDER."
";
echo "
"._AM_SRCHNEW_IMAGE."
";
echo "
"._AM_SRCHNEW_ALB."
";
echo "
"._AM_SRCHNEW_RESULT."
";
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 "