strtolower($b[$w_o])) ? -1 : 1; } function asc ($a, $b) { global $cfg; $w_o='name'; if ($a[$w_o] == $b[$w_o]) return 0; return (strtolower($a[$w_o]) < strtolower($b[$w_o])) ? -1 : 1; } function printFolderName($dir) { global $db,$cfg; $result=mysql_query("SELECT displayName FROM al_directories WHERE dir_id=$dir",$db); $myrow=mysql_fetch_row($result); echo $myrow[0]; } function checkValidation($dir,$okDir,$target) { global $db,$cfg; $result=mysql_query("SELECT access FROM al_directories WHERE dir_id=$dir",$db); $myrow=mysql_fetch_row($result); if (in_array($myrow[0],$okDir)) { return(true); } } function checkPwdValidity($dir,$password) { global $db,$cfg; $result=mysql_query("SELECT access FROM al_directories WHERE dir_id=$dir",$db); $myrow=mysql_fetch_row($result); if ($password==$myrow[0]) { return($password); } else { return (false); } } function picToDir($pic) { global $db,$cfg; $result=mysql_query("SELECT dir_id FROM al_images WHERE id=$pic",$db); $myrow=mysql_fetch_row($result); $dir=$myrow[0]; return($dir); } function imagesInDir($dir) { //get all the images for the directory global $db,$cfg; $result=mysql_query("SELECT id FROM al_images WHERE dir_id=$dir;",$db); return(mysql_num_rows($result)); } function rebuildDbase($db) { global $cfg; $sql="DELETE FROM al_directories"; $write=mysql_query($sql); $sql="DELETE FROM al_images"; $write=mysql_query($sql); $sql="DELETE FROM al_comments"; $write=mysql_query($sql); } function doHit($pic) { global $cfg,$db; $result=mysql_query("SELECT al_images.*,al_directories.folder,al_directories.displayName FROM al_images,al_directories WHERE al_images.dir_id=al_directories.dir_id AND al_images.id=$pic",$db); $myrow=mysql_fetch_array($result); $viewHitCounter=$myrow['hits']+1; $sql="UPDATE al_images SET hits=$viewHitCounter WHERE id=$myrow[0]"; $update = mysql_query($sql); //$imgPath=$cfg['imagePath'].$myrow['folder']."/".$myrow['name']; //printf("",$imgPath); } function doPic($pic) { global $cfg,$db; $result=mysql_query("SELECT al_images.*,al_directories.folder,al_directories.displayName FROM al_images,al_directories WHERE al_images.dir_id=al_directories.dir_id AND al_images.id=$pic",$db); $myrow=mysql_fetch_array($result); $result2=mysql_query("SELECT * FROM al_images WHERE id<$pic and dir_id=$myrow[1] ORDER BY id DESC LIMIT 1",$db); $result3=mysql_query("SELECT * FROM al_images WHERE id>$pic and dir_id=$myrow[1] ORDER BY id LIMIT 1",$db); $myrow2=mysql_fetch_array($result2); $myrow3=mysql_fetch_array($result3); $viewHitCounter=$myrow['hits']+1; $sql="UPDATE al_images SET hits=$viewHitCounter WHERE id=$myrow[0]"; $update = mysql_query($sql); $dir_choice=$myrow['displayName']; if ($cfg['pics']['dirNameCaps']=='TRUE') { $dir_choice=strtoupper($dir_choice); } printf("",$cfg['colours']['picHeaderBack']); getParentDirs($myrow['dir_id']); printf("
ALBUM INDEX» %s » %s
",$myrow['dir_id'],$dir_choice,$myrow['name']); printf("",$cfg['colours']['picHeaderBack']); if ($myrow2) { printf("«\n",$myrow2['id'],stripslashes($myrow2['caption'])); } if ($myrow3){ printf("»\n",$myrow3['id'],stripslashes($myrow3['caption'])); } echo"\n\n\n\n\n\n\n"; $imgPath=$cfg['imagePath'].$myrow['folder']."/".$myrow['name']; $size = getimagesize($imgPath); printf("",stripslashes($myrow['caption'])); } else { echo ""; } printf("\n\n",$cfg['colours']['picBack'],$viewHitCounter); $com_result=mysql_query("SELECT al_comments.comment,date_format(al_comments.date, '%d-%m-%y') AS date,al_users.u_name FROM al_comments,al_users WHERE al_comments.user_id=al_users.user_id and al_comments.image_id=$myrow[0] ORDER BY al_comments.date ASC",$db); if (!mysql_numrows($com_result)=="0") { printf(""; } } function getParentDirs($pDir){ global $cfg,$db; //$foundParent=true; //get parent directory (if not 0) and print the link $findParentQuery=mysql_query("SELECT parent_dir_id FROM al_directories where dir_id=$pDir",$db); $parentDirResult=mysql_fetch_array($findParentQuery); if ($parentDirResult["parent_dir_id"]!=0) { //found a parent $parentDirId=$parentDirResult["parent_dir_id"]; //retrieve name $parentDirName=mysql_query("SELECT * FROM al_directories where dir_id=$parentDirId",$db); $parentDirNameResult=mysql_fetch_array($parentDirName); //echo the link if ($cfg['pics']['dirNameCaps']=='TRUE') { $dirName=strtoupper($parentDirNameResult["displayName"]); } printf ("",$parentDirNameResult["dir_id"],$dirName); getParentDirs($parentDirNameResult["dir_id"]); } } function getChildDirs($pDir){ global $cfg,$db; //get child directory and print the links $findChildQuery=mysql_query("SELECT * FROM al_directories where parent_dir_id=$pDir",$db); echo ""; } function doThumbnailHeader($dir) { global $cfg,$db; //get the directory name $dirName=getFolderName($dir); //add slashes to it $dirNameSlashes=addslashes($dirName); //get the directory from the db $result4=mysql_query("SELECT * FROM al_directories WHERE dir_id=$dir",$db); //determine if there are any pics in the directory $resultImages=mysql_query("SELECT * FROM al_images WHERE dir_id=$dir",$db); //get previous and next link directories if ($cfg['sortFolders']==true) { $sqlPrev="SELECT dir_id,displayName FROM al_directories WHERE displayName<'$dirNameSlashes' ORDER BY displayName DESC LIMIT 1"; $sqlNext="SELECT dir_id,displayName FROM al_directories WHERE displayName>'$dirNameSlashes' ORDER BY displayName LIMIT 1"; } else { $sqlPrev="SELECT dir_id,displayName FROM al_directories WHERE dir_id<$dir ORDER BY dir_id DESC LIMIT 1"; $sqlNext="SELECT dir_id,displayName FROM al_directories WHERE dir_id>$dir ORDER BY dir_id LIMIT 1"; } //retrieve these from the db $prevsql=mysql_query($sqlPrev,$db); $nextsql=mysql_query($sqlNext,$db); $prevdir=mysql_fetch_array($prevsql); $nextdir=mysql_fetch_array($nextsql); $myrow4=mysql_fetch_array($result4); //retrive the current directory as myrow4 //set $dir_choice to the name of the directory $dir_choice=$myrow4['displayName']; if ($cfg['pics']['dirNameCaps']=='TRUE') { $dir_choice=strtoupper($dir_choice); } //get parent directories (if not 0) and print the "up" link getParentDirs($dir); //echo the CHOSEN directory //display the slideshow link if there are any images if(mysql_fetch_array($resultImages)) { echo ""; } else { echo ""; } echo "
",$cfg['colours']['picBack']); if ($myrow3){ printf("",$myrow3['id']); } printf("",$size[0],$size[1],$imgPath); if ($myrow3){ printf(""); } if ($myrow['caption']) { printf("
%s
[viewed %s times]
",$cfg['colours']['commentsBack']); $count=1; while($mycomments=mysql_fetch_row($com_result)) { if ($count>1) { $colour=$cfg['colours']['comment1']; $count=0; } else { $colour=$cfg['colours']['comment2']; } printf("%s: %s (%s)
\n",stripslashes($mycomments[2]),$colour,stripslashes($mycomments[0]),$mycomments[1]); $count++; } echo "
» %s"; while($childDirResult=mysql_fetch_array($findParentQuery)){ //found a child $childDirId=$childDirResult["dir_id"]; //echo the link if ($cfg['pics']['dirNameCaps']=='TRUE') { $dirName=strtoupper($childDirResult["displayName"]); } printf ("» %s 
",$childDirId,$dirName); getChildDirs($childDirId); } echo "
» ".$dir_choice." | SLIDESHOW» ".$dir_choice." 
"; printf("",$cfg['colours']['picHeaderBack']); //link to previous and next directories if ($prevdir) { printf("«prev   ",$prevdir['dir_id'],stripslashes($prevdir['displayName'])); if ($nextdir){ echo "|"; } //insert divider if next and prev present } if ($nextdir){ printf("   next»\n",$nextdir['dir_id'],stripslashes($nextdir['displayName'])); } } function doThumbnails($dir,$numThumbs,$thumbsOffset) { global $cfg,$db; //get any subdirectories and print out links to them $sqlQuery="SELECT * FROM al_directories WHERE parent_dir_id='$dir'"; if ($cfg['sortFolders']=="asc") { $sqlQuery=$sqlQuery." ORDER BY displayName ASC"; } else if ($cfg['sortFolders']=="desc") { $sqlQuery=$sqlQuery." ORDER BY displayName DESC"; } $child_dirs_query=mysql_query($sqlQuery,$db); //if there are any... if (mysql_num_rows($child_dirs_query)) { //print their names and link to them $dirCount=0; echo ""; //reset the query pointer //mysql_data_seek( $child_dirs_query ); while ($child_dirs=mysql_fetch_array($child_dirs_query)) { if($dirCount == 0){ echo "\n"; } $child_dir_display_name = $child_dirs['displayName']; echo ""; $dirCount++; if($dirCount==2){ echo"\n"; $dirCount=0; } } if($dirCount != 2 && $dirCount != 0){ $neededtds = 2 - $dirCount; for($i=0;$i<$neededtds;$i++){ echo "\n"; } echo "
".$child_dir_display_name."
"; //show a few sample thumbnails showSampleThumbnails($child_dirs['dir_id'],2,false); echo "
"; } else { echo ""; } } //get all the images for the directory $result=mysql_query("SELECT * FROM al_images WHERE dir_id=$dir ORDER BY name ASC;",$db); $resultDir=mysql_query("SELECT * FROM al_directories WHERE dir_id=$dir", $db); $myrow4=mysql_fetch_array($resultDir); //thumbs remaining are the total number of thumbnails returned //minus the offset. $totalThumbs=mysql_num_rows($result); echo""; //count through the returned images and find the id of the image in the $thumbsOffset location $offsetCounter=0; $thumbsPrinted=0; while ($offsetCounter < $totalThumbs) { //get the image $myrow=mysql_fetch_array($result); //if it's offset is == to the offest Counter, then set the index to that image's id if ($thumbsOffset <= $offsetCounter) { $thumbIndex[$thumbsPrinted]['id']=$myrow['id']; $thumbIndex[$thumbsPrinted]['name']=$myrow[2]; $thumbIndex[$thumbsPrinted]['caption']=$myrow[3]; $thumbIndex[$thumbsPrinted]['hits']=$myrow[4]; $thumbsPrinted++; } $offsetCounter++; } echo ""; $count=1; $thumbsShown=0; //if the total available thumbs is less than the number of thumbs configured to show //only show up to the total number of thumbs remaining if (sizeof($thumbIndex) < $numThumbs) { $thumbsToShow = sizeof($thumbIndex); } else { $thumbsToShow = $numThumbs; } //loop through until you've shown enough thumbnails (per the config file) if (sizeof($thumbIndex)) { while($thumbsShown < $thumbsToShow) { if ($count==$cfg['thumbnailsprow']) { echo "\n"; $count=1; } //construct the image path $img_path=$cfg['imagePath'].$myrow4['folder']."/"; $img_path .= $thumbIndex[$thumbsShown]['name']; //get the image size & dimensions $size = getimagesize($img_path); echo '"; $count ++; $thumbsShown++; } } if ($count<$cfg['thumbnailsprow']) { for ($i=1;$i<=($cfg['thumbnailsprow']-$count);$i++) { printf("",$cfg['colours']['thumbBack']); } } if ($cfg['commentsOn']) { printf("\n",$cfg['thumbnailsprow'],$cfg['colours']['thumbBack']); } echo "
'; //print the link to view it. if ($cfg['popupImages']==true) { printf("",$thumbIndex[$thumbsShown]['id'],$size[0]+20,$size[1]+50); } else { printf("",$img_path,stripslashes($thumbIndex[$thumbsShown]['caption']),$thumbIndex[$thumbsShown]['id']); //printf('',$thumbIndex[$thumbsShown]['id']); } printThumbnail($thumbIndex[$thumbsShown]['name'],$myrow4['folder'],stripslashes($thumbIndex[$thumbsShown]['caption']),false); echo ""; //print out the hits if any if ($thumbIndex[$thumbsShown]['hits'] != "") { printf("
[%s views]",$thumbIndex[$thumbsShown]['hits']); } //get the comments and display them (if any) $thumbId=$thumbIndex[$thumbsShown]['id']; $com_result=mysql_query("SELECT al_comments.image_id,date_format(al_comments.date, '%d-%m-%y') AS date,al_users.u_name FROM al_comments,al_users WHERE al_comments.user_id=al_users.user_id and image_id=$thumbId ORDER BY al_comments.date DESC",$db); $num_rows = mysql_num_rows($com_result); if ($mycom=mysql_fetch_row($com_result)) { if ($cfg['popupImages']==true) { $size=getPicSize($mycom[0]); printf("
‹c› %s",$mycom[0],$size[0]+20,$size[1]+50,$mycom[2],$mycom[1],$num_rows); } else { printf("
‹c› %s",$mycom[0],$mycom[2],$mycom[1],$num_rows); } } echo "
 
Roll your mouse over the comment icon ‹c› to see when it was writen and by whom.
"; return($totalThumbs); } function doPageNos($dir,$numThumbs,$thumbsOffset){ global $cfg,$db; //get the description for this folder from the database $result=mysql_query("SELECT * FROM al_directories WHERE dir_id=$dir", $db); $myrow4=mysql_fetch_array($result); //print previous and next page links //if the offset is greater than zero $prevPageOffset = 0; if ($thumbsOffset > 0) { //get previous link //if the offset is greater than the number of thumbs, //subtract that from the number for the previous offset if($thumbsOffset >= $numThumbs) { $prevPageOffset = $thumbsOffset - $numThumbs; } else { $prevPageOffset = 0; } } //get all the images for the directory $result=mysql_query("SELECT * FROM al_images WHERE dir_id=$dir ORDER BY id ASC;",$db); //thumbs remaining are the total number of thumbnails returned //minus the offset. $totalThumbs=mysql_num_rows($result); $thumbsRemaining=$totalThumbs - $thumbsOffset; //get nextPage link //if numThumbs is less than the total thumbs minus the offset //add numThumbs to the offset to get the next page $nextPageOffset=0; if ($numThumbs < $thumbsRemaining) { $nextPageOffset = $thumbsOffset + $numThumbs; } //print previous page link and a "first page" link if not on it if ($prevPageOffset != $thumbsOffset) { printf("«prev  ",$dir, $prevPageOffset); } //print page numbers for all pages. $i=0; $page=1; if ($numThumbs <= $totalThumbs) { while ($i < $totalThumbs) { //if not on this page, print link, else, just print number if ($i != $thumbsOffset) { printf("[%s] ",$dir, $i,$page); } else { echo "[$page] "; } $i+=$numThumbs; $page++; } } //print next page link if ($nextPageOffset > 0) { printf(" next»",$dir, $nextPageOffset); } } function doPopupImage($pic) { global $cfg,$db; $result=mysql_query("SELECT al_images.*,al_directories.folder,al_directories.displayName FROM al_images,al_directories WHERE al_images.dir_id=al_directories.dir_id AND al_images.id=$pic",$db); $myrow=mysql_fetch_array($result); $result2=mysql_query("SELECT * FROM al_images WHERE id<$pic and dir_id=$myrow[1] ORDER BY id DESC LIMIT 1",$db); $result3=mysql_query("SELECT * FROM al_images WHERE id>$pic and dir_id=$myrow[1] ORDER BY id LIMIT 1",$db); $myrow2=mysql_fetch_array($result2); $myrow3=mysql_fetch_array($result3); $viewHitCounter=$myrow['hits']+1; $sql="UPDATE al_images SET hits=$viewHitCounter WHERE id=$myrow[0]"; $update = mysql_query($sql); $dir_choice=$myrow['displayName']; $imgPath=$cfg['imagePath'].$myrow['folder']."/".$myrow['name']; $size = getimagesize($imgPath); if ($cfg['pics']['dirNameCaps']=='TRUE') { $dir_choice=strtoupper($dir_choice); } //print link to the slideshow printf(" SLIDESHOW",$cfg['colours']['picHeaderBack'],$myrow[1]); //print next and back navigation printf("",$cfg['colours']['picHeaderBack']); if ($myrow2) { printf("«\n",$myrow2['id'],stripslashes($myrow2['caption'])); } if ($myrow3){ printf("»\n",$myrow3['id'],stripslashes($myrow3['caption'])); } echo"\n\n\n\n\n\n\n"; printf("",stripslashes($myrow['caption'])); } else { echo ""; } printf("\n\n",$cfg['colours']['picBack'],$viewHitCounter); $com_result=mysql_query("SELECT al_comments.comment,date_format(al_comments.date, '%d-%m-%y') AS date,al_users.u_name FROM al_comments,al_users WHERE al_comments.user_id=al_users.user_id and al_comments.image_id=$myrow[0] ORDER BY al_comments.date ASC",$db); if (!mysql_numrows($com_result)=="0") { printf(""; } } function doEditCaptions($dir) { global $cfg,$db; $result=mysql_query("SELECT * FROM al_directories WHERE dir_id=$dir",$db); $myrow=mysql_fetch_array($result); echo "
",$cfg['colours']['picBack']); if ($myrow3){ printf("",$myrow3['id']); } printf("",$size[0],$size[1],$imgPath); if ($myrow3){ printf(""); } if ($myrow['caption']) { printf("
%s
[viewed %s times]
",$cfg['colours']['commentsBack']); $count=1; while($mycomments=mysql_fetch_row($com_result)) { if ($count>1) { $colour=$cfg['colours']['comment1']; $count=0; } else { $colour=$cfg['colours']['comment2']; } printf("%s: %s (%s)
\n",stripslashes($mycomments[2]),$colour,stripslashes($mycomments[0]),$mycomments[1]); $count++; } echo "
\n "; printf("",$myrow['displayName']); $result2=mysql_query("SELECT * FROM al_images WHERE dir_id=$dir ORDER BY name ASC",$db); echo ""; $count=1; while($myrow2=mysql_fetch_array($result2)) { if ($count==3) { echo "\n"; $count=1; } $img_path=$cfg['imagePath'].$myrow['folder']."/"; $img_path .= $myrow2['name']; $admin_path=$cfg['adminImagePath'].$myrow['folder']."/".$myrow2['name']; printf(" ",$myrow2['id'],stripslashes($myrow2['caption'])); $count ++; } echo "
%s
",$cfg['colours']['captionEdit'],$admin_path); printThumbnail($myrow2['name'],$myrow['folder'],$myrow2['caption'],true); echo ""; printf("   
"; } function updateAccess($formVars,$db) { global $cfg; $result=mysql_query("SELECT * FROM al_directories",$db); $counter=1; while($myrow=mysql_fetch_row($result)) { if ($myrow[2]!=$formVars[$myrow[0]]) { $id_array[$counter]['id']=$myrow[0]; $id_array[$counter]['pwd']=$formVars[$id_array[$counter]['id']]; $counter++; } $i++; } for ($i=1;$i<$counter;$i++) { $acc_pwd=$id_array[$i]['pwd']; $id=$id_array[$i]['id']; $sql = "UPDATE al_directories SET access='$acc_pwd' WHERE dir_id=$id" or die ("unable to update id $id_array[$i]"); $result = mysql_query($sql); } return ($id_array); } function updateCaptions($formVars,$dir) { global $cfg,$db; $result=mysql_query("SELECT * FROM al_images WHERE dir_id=$dir",$db); $counter=1; while($myrow=mysql_fetch_array($result)) { $fieldName="caption".$myrow['id']; if (stripslashes($myrow['caption'])!=stripslashes($formVars[$fieldName])) { $id_array[$counter]['id']=$myrow['id']; $id_array[$counter]['caption']=$formVars[$fieldName]; $counter++; } $i++; } for ($i=1;$i<$counter;$i++) { $caption=$id_array[$i]['caption']; $id=$id_array[$i]['id']; $sql = "UPDATE al_images SET caption='$caption' WHERE id=$id" or die ("unable to update id $id_array[$i]"); $result = mysql_query($sql); } return ($id_array); } function updateFolders($formVars) { global $cfg,$db; $result=mysql_query("SELECT * FROM al_directories",$db); $counter=1; while($myrow=mysql_fetch_array($result)) { $fieldName="folder".$myrow['dir_id']; if (stripslashes($myrow['displayName'])!=stripslashes($formVars[$fieldName])) { $id_array[$counter]['id']=$myrow['dir_id']; $id_array[$counter]['caption']=$formVars[$fieldName]; $counter++; } $i++; } for ($i=1;$i<$counter;$i++) { $caption=$id_array[$i]['caption']; $id=$id_array[$i]['id']; if ($caption!=="") { $sql = "UPDATE al_directories SET displayName='$caption' WHERE dir_id=$id" or die ("unable to update id $id_array[$i]"); $result = mysql_query($sql); } else { unset($id_array[$i]); } } return ($id_array); } function printUpdatedFolders($folderArray,$db) { global $cfg; //this function displays the updated information for submitted folder changes //loop through the folders passed in $headerPrinted=false; foreach ($folderArray as $v1) { if (!$headerPrinted) { echo "The passwords for the following folders have been updated:
"; $headerPrinted=true; } //get the id $id=$v1['id']; //get the folder $result=mysql_query("SELECT displayName FROM al_directories WHERE dir_id=$id",$db); $myrow=mysql_fetch_row($result); //if the pwd is not empty note it's status if ($v1['pwd']!="") { printf("%s. %s is now \"%s\"
",$v1['id'],stripslashes($myrow[0]),$v1['pwd']); } else { //else note that there is no password protection printf("%s. %s now has no password protection.
",$v1['id'],stripslashes($myrow[0])); } } } function printUpdatedCaptions($folderArray,$db) { global $cfg; echo "The following have been updated:
"; foreach ($folderArray as $v1) { $id=$v1['id']; if ($v1['caption']!="") { printf("%s. has been changed to \"%s\"
",$v1['id'],stripslashes($v1['caption'])); } else { printf("%s. has had its caption removed.
",$v1['id']); } } } function printFolderAccess($db) { global $cfg; $result=mysql_query("SELECT * FROM al_directories",$db); $counter=1; while($myrow=mysql_fetch_row($result)) { printf("",$cfg['colours']['tableLine']); printf("%s.%s%s\n",$myrow[0],$myrow[1],stripslashes($myrow[3]),$myrow[0],$myrow[2]); } } function addComment($rawUser,$rawComment,$pic) { global $db,$cfg; $user=cleanString($rawUser); $comment=cleanString($rawComment); $user_result=mysql_query("SELECT * from al_users WHERE u_name='$user'"); if(!$my_user=mysql_fetch_row($user_result)) { $sql="INSERT INTO al_users (u_name) VALUES ('$user')"; $result=mysql_query($sql); $user_result=mysql_query("SELECT * from al_users WHERE u_name='$user'"); $my_user=mysql_fetch_row($user_result); } $today=date ("Y-m-d-H-i" ,time()+$cfg['timeAdjust']); $sql="INSERT INTO al_comments (user_id,image_id,comment,date) VALUES ('$my_user[0]','$pic','$comment','$today')"; $result=mysql_query($sql); } function checkComment($dID){ global $cfg,$db; $com_result=mysql_query("SELECT al_comments.image_id,date_format(al_comments.date, '%d-%m-%y') AS date,al_users.u_name FROM al_comments,al_users,al_directories,al_images WHERE al_images.dir_id=al_directories.dir_id and al_comments.image_id=al_images.id and al_comments.user_id=al_users.user_id and al_directories.dir_id=$dID ORDER BY al_comments.com_id DESC",$db); //if there are any comments for these photos if ($mycom=mysql_fetch_row($com_result)) { //if they should be popups or not... if ($cfg['popupImages']==true) { //get the image size $size=getPicSize($mycom[0]); //print a link to pop open the images that have comments (I think?) printf("‹c›",$dID,$mycom[0],$size[0]+20,$size[1]+50,$mycom[2],$mycom[1]); } else { //else just link to the pictures with the comment image (if there are any comments) printf(" ‹c›",$mycom[0],$mycom[2],$mycom[1]); } } } function buildAlbumIndex($db) { global $cfg; //this builds the index page for the entire album echo "\n "; //get all the directories that are in the root of the album (where the parent id is 0) $sqlQuery="SELECT * FROM al_directories WHERE parent_dir_id='0'"; if ($cfg['sortFolders']=="asc") { $sqlQuery=$sqlQuery." ORDER BY displayName ASC"; } else if ($cfg['sortFolders']=="desc") { $sqlQuery=$sqlQuery." ORDER BY displayName DESC"; } $result=mysql_query($sqlQuery,$db); $counter=1; //loop through them while($myrow=mysql_fetch_array($result)) { //$com_result=mysql_query("SELECT al_comments.image_id,date_format(al_comments.date, '%d-%m-%y') AS date,al_users.u_name FROM al_comments,al_users,al_directories,al_images WHERE al_images.dir_id=al_directories.dir_id and al_comments.image_id=al_images.id and al_comments.user_id=al_users.user_id and al_directories.dir_id=$myrow[0] ORDER BY al_comments.com_id DESC",$db); if ($counter>$cfg['noColumns']) { echo ""; $counter=1; } //get the display name of this directory //set it's caps according to the config file if ($cfg['index']['dirNameCaps']=='TRUE') { $dir_choice=strtoupper($myrow['displayName']); } else { $dir_choice=$myrow['displayName']; } echo ""; $counter ++; } while ($counter<=$cfg['noColumns']) { printf("",$cfg['colours']['indexBack']); $counter ++; } echo "\n
"; echo ""; //print it's name and a link to it. printf("
%s %s",$myrow['dir_id'],$cfg['indexBullet'],$dir_choice); //if there are any comments for these photos checkComment($myrow[0]); //get the first level children directories for this directory $dir_id=$myrow['dir_id']; $queryString="SELECT * FROM al_directories WHERE parent_dir_id='$dir_id'"; if ($cfg['sortFolders']==true) { $queryString=$queryString." ORDER BY displayName DESC"; } $child_dirs_query=mysql_query($queryString,$db); //print their names and link to them echo ""; $noShown=0; while ($child_dirs=mysql_fetch_array($child_dirs_query)) { if($noShown<$cfg['noSubdirsDisplayed']){ echo "» ".$child_dirs['displayName'].""; checkComment($myrow[0]); echo"
"; $noShown++; } else if($noShown==$cfg['noSubdirsDisplayed']){ echo"» more..."; $noShown++; } } echo "
"; //show a few sample thumbnails showSampleThumbnails($myrow['dir_id'],$cfg['sampleThumbsOnHome'],false); echo"
"; //echo "
"; echo "
 
"; } function manageIndex() { global $cfg,$db; echo "\n "; $result=mysql_query("SELECT * FROM al_directories",$db); $counter=1; while($myrow=mysql_fetch_array($result)) { if ($counter>2) { echo ""; $counter=1; } printf(""; $counter ++; } if ($counter<3) { printf("",$cfg['colours']['indexBack']); } echo "\n

edit captions",$cfg['colours']['manageFolder'],$myrow['dir_id'],stripslashes($myrow['displayName']),$myrow['dir_id']); echo "
 
"; } function RecurseDir($basedir,$AllDirectories) { global $db; global $cfg; $thumbDir = substr($cfg['thumbDirectory'],0,strrpos($cfg['thumbDirectory'],'/')); $slideImagesDir = substr($cfg['slideDirectory'],0,strrpos($cfg['slideDirectory'],'/')); #Create array for current directory's contents $ThisDir=array(); #switch to the directory we wish to scan chdir($basedir); //change back slashes to forward slashes for compatability $current=str_replace('\\', '/', getcwd()); #open current directory for reading $handle=opendir("."); while ($file = readdir($handle)) { #Don't add special directories '..' or '.' to the list if (($file!='..') & ($file!='.') & ($file!=$thumbDir) & ($file!=$slideImagesDir)) { if (is_dir($file)) { #build an array of contents for this directory array_push($ThisDir,$current.'/'.$file); } } } closedir($handle); #Loop through each directory, run RecurseDir function on each one foreach ($ThisDir as $key=>$var) { array_push($AllDirectories, $var); $AllDirectories=RecurseDir($var, $AllDirectories); } #make sure we go back to our origin chdir($basedir); return $AllDirectories; } function GetFileArray($imageBaseDir,$dir) { //this function gets all the files in a directory ($dir) //relative to the base image directory ($imageBaseDir) global $db; global $cfg; //add slashes to the directory $dirSlashed = addslashes($dir); //imageBaseDir + dir = entire path to the directory $path = $imageBaseDir.$dir; echo "
   - scanning $dir for images."; //add the trailing slash for the directory $path .= '/'; //search the database for this directory $result=mysql_query("SELECT dir_id FROM al_directories WHERE folder='$dirSlashed'",$db); $mydir=mysql_result($result,0,"dir_id"); //open the directory $subdir = opendir($path); $count=1; //if it's found, look for images if ($subdir) { echo "     found the following images:"; } } function UpdateFileArray($imageBaseDir, $dirName, $overwriteThumb=false, $overwriteSlide=false) { //this function searches the contents of a directory already in the db //and adds and removes any files that are new or missing respectively. global $db; global $cfg; if ($cfg['forceCreateThumbs']) { $overwriteThumb=true; } if ($cfg['forceCreateSlides']) { $overwriteSlide=true; } //add slashes to the directory $dirSlashed = addslashes($dirName); //imageBaseDir + dir = entire path to the directory $path = $imageBaseDir.$dirName; echo "   - scanning $dirName for images.
"; //add the trailing slash for the directory $path .= '/'; //search the database for this directory $result=mysql_query("SELECT dir_id FROM al_directories WHERE folder='$dirSlashed'",$db); $mydir=mysql_result($result,0,"dir_id"); //open the directory $subdir = opendir($path); $count=1; if ($subdir) { echo"
"; $ret_file = Array(); while ($file = readdir($subdir)) { //get the file extention //get the extension of the file $fileExtension=getExtension($file); //if it's a file and it's extension is in the config file as being acceptable if ((is_file($path.$file)) && (in_array($fileExtension,$cfg['acceptTypes']))) { //save the file $ret_file[] = $file; //add slashes to it for retrieval $fileSlashed = addslashes($file); //see if it's in the db $result2=mysql_query("SELECT id FROM al_images WHERE name='$fileSlashed' AND dir_id='$mydir'",$db); $myfile=mysql_fetch_row($result2); // if it's not in the db, add it if (!$myfile) { $name=$file; $caption=null; //strip the file extension and replace any underscores with spaces for the caption of the file foreach ($cfg['acceptTypes'] as $aT) { $aTindex = strpos(strtolower($name), ".$aT"); if ($aTindex > 0) { $caption = str_replace("_"," ",substr ($name,0,$aTindex)); } } //if caption wasn't defined, set the caption to the file name if ($caption==null){ $caption=$name; } echo "
  • adding: $name
    "; echo ("setting caption to: "); echo $caption; echo ("
    "); //add slashes to the name and caption for insertion $name=addslashes($name); $caption=addslashes($caption); //insert the file $sql="INSERT INTO al_images (dir_id,name,caption) VALUES ($mydir,'$name','$caption')"; $write=mysql_query($sql); //get it from the db as $myfile $result2=mysql_query("SELECT id FROM al_images WHERE name='$fileSlashed' AND dir_id='$mydir'",$db); $myfile=mysql_fetch_row($result2); } //createFiles($path, $file, $overwriteThumb, $overwriteSlide); } } closedir($subdir); } //get all the images for this directory and see if they all still exist, delete those that do not $result3=mysql_query("SELECT * FROM al_images WHERE dir_id='$mydir'",$db); while ($myrow3=mysql_fetch_row($result3)) { //if the file isn't still there $exists=in_array($myrow3[2],$ret_file); if (!$exists) { //remove it $sql="DELETE FROM al_images WHERE id='$myrow3[0]'"; $write=mysql_query($sql); printf ('
  • -deleted %s',$myrow3[2]); } } } function getParentDir ($basepath, $path) { global $db; global $cfg; //get the name of this directory $dirName=substr($path,(strrpos($path,'/') + 1)); //get the full path of the parent of this directory $parentPath = substr($path,0,(strrpos($path,'/'))); //get the name of the parent directory of this directory $relativeParentName = substr($parentPath,(strpos($parentPath,$basepath) + strlen($basepath))); return $relativeParentName; } function GetDirArray($checkTransfer) { global $db; global $cfg; //get the current working directory $cwd = getcwd(); //change to the image directory chdir($cfg['adminImagePath']); //save this path, change back slashes to forward slashes for compatability $imageBaseDir = str_replace('\\', '/', getcwd()); //get all the directories and files for this path if (!$AllDirectories) { $AllDirectories = array(); $AllDirectories = RecurseDir (".",$AllDirectories); } echo "Scanning your album contents via:  ".$imageBaseDir."
    "; //check for removed directories $removedList=searchForRemoved($imageBaseDir, $AllDirectories); //for each directory... echo "
    :: Checking for directories that were not present previously...
    "; foreach ($AllDirectories as $dir) { //open the directory $handle = opendir($dir); $thumbDir = $dir . '/' . $cfg['thumbDirectory']; $slideDir = $dir . '/' . $cfg['slideDirectory']; if (! @opendir($thumbDir)) { echo "creating $thumbDir
    "; if (! @mkdir($thumbDir, 0700)) { echo "cannot create $thumbDir
    "; } } if (! @opendir($slideDir)) { echo "creating $slideDir
    "; if (! @mkdir($slideDir, 0700)) { echo "cannot create $slideDir
    "; } } //get the name of this directory relative to the admin imagepath ($imageBaseDir) $dirName=substr($dir,(strpos($dir,$imageBaseDir) + strlen($imageBaseDir))); //add slashes to look it up $dirSlashed=addslashes($dirName); //get it from the db $result=mysql_query("SELECT * FROM al_directories WHERE folder='$dirSlashed'",$db); $myrow=mysql_fetch_row($result); //if it's not in the db... if (!$myrow){ $match=false; //check if the folder name matches one of the removed based on the flag 'checkTransfer' if($checkTransfer){ $nameOnly=substr($dirName,strrpos($dirName,"/")); for($i=0; $i"; } else { $parent_dir_id = $parentDirRow['0']; } } if($match===false){ echo ("»adding: $displayName ($dirNameSlashed)
    "); //insert the folder into the db $sql="INSERT INTO al_directories (folder,displayName,parent_dir_id) VALUES('$dirNameSlashed','$displayName','$parent_dir_id')"; $write=mysql_query($sql); //get the files GetFileArray($imageBaseDir, $dirName); } else { $movedList[]=array($removedList[$match][0],$removedList[$match][1],$parent_dir_id,$dirNameSlashed); //add to the possible 'moved' list array_splice($removedList,$match,1); //remove from 'removed' list } } else { //if the directory was already in the db, update it based on the contents. //echo "::Searching for file updates."; UpdateFileArray($imageBaseDir, $dirName); } closedir($handle); } //remove those in the remove list that were not found in the 'movers', if any if(sizeof($removedList)>0){ removeDir($imageBaseDir, $removedList); } //display possible movers if(sizeof($movedList)>0){ echo "
    :: Move directories:"; echo ""; echo ""; foreach ($movedList as $value){ //display row printf ('',$value[1],$value[3],$value[0],$value[2],$value[0],$value[3]); } echo "
    The following directories look like they may have been moved. Select any folders that you may have relocated. This will ensure that all the associated meta data that applies to the images, like the comments and number of views will be retained. Those left unchecked will be removed and new entries created in the database!
    %s -> %s
    "; } chdir($cwd); } function updateDir($dID, $newParent, $folder){ global $db; $sql="UPDATE al_directories SET parent_dir_id=$newParent,folder='$folder' WHERE dir_id=$dID"; $write=mysql_query($sql); if($write){ echo "directory successfully updated!
    "; } else { echo "update failed
    "; } } function removeDir($imageBaseDir, $toRemove){ global $db; echo "
    Removing the following directory entries:
    "; //loop through them foreach ($toRemove as $value){ // ($myrow=mysql_fetch_row($result)) //remove it and it's images $sql="DELETE FROM al_images WHERE dir_id=$value[0]"; $write=mysql_query($sql); $sql="DELETE FROM al_directories WHERE dir_id=$value[0]"; $write=mysql_query($sql); printf ('
  • deleted folder, %s and all its images.
  • ',$value[1]); } } function searchAndRemove ($imageBaseDir, $AllDirectories) { global $cfg,$db; //this function looks at each directory in the db //if the directory is no longer on the file system //it removes it from the db echo "
    :: Checking for removed folders...
    "; $result=mysql_query("SELECT dir_id,folder FROM al_directories",$db); //loop through them while ($myrow=mysql_fetch_row($result)) { //if the folder is not on the file system if (!in_array($imageBaseDir.$myrow[1],$AllDirectories)) { //remove it and it's images $sql="DELETE FROM al_images WHERE dir_id=$myrow[0]"; $write=mysql_query($sql); $sql="DELETE FROM al_directories WHERE dir_id=$myrow[0]"; $write=mysql_query($sql); printf ('
  • -deleted folder, %s and all its images.
    ',$myrow[1]); } } } function searchForRemoved ($imageBaseDir, $AllDirectories) { global $db; //this function looks at each directory in the db //if the directory is no longer on the file system //it adss it to an array that will be used to check if the folders have been 'moved' echo ":: Checking for removed folders...
    "; $result=mysql_query("SELECT dir_id,folder FROM al_directories",$db); //loop through them while ($myrow=mysql_fetch_row($result)) { //if the folder is not on the file system if (!in_array($imageBaseDir.$myrow[1],$AllDirectories)) { echo "  - ".$myrow[1]." has been moved or removed
    "; //add to a 'removed' array $removedDir[]=array($myrow[0],$myrow[1]); } } return($removedDir); } function showSampleThumbnails($dir,$numThumbs,$admin) { global $cfg,$db; //print $numThumbs thumbnails, starting at $thumbsOffset from the directory $dir //get the images for that directory ($dir) //get the directory $resultDir=mysql_query("SELECT * FROM al_directories WHERE dir_id=$dir",$db); $myrowDir=mysql_fetch_array($resultDir); $result=mysql_query("SELECT * FROM al_images WHERE dir_id=$dir ORDER BY id ASC;",$db); //figure out the total amount of thumbs available $offsetCounter=0; while($myrow=mysql_fetch_array($result)){ //if it's offset is == to the offest Counter, then set the index to that image's id if ($offsetCounter < $numThumbs) { $thumbIndex[$offsetCounter]['id']=$myrow['id']; $thumbIndex[$offsetCounter]['name']=$myrow[2]; $thumbIndex[$offsetCounter]['caption']=$myrow[3]; $thumbIndex[$offsetCounter]['folder']=$myrowDir['folder']; //echo "thumb added: ".$myrow[2]; } $offsetCounter++; } //if the total available thumbs is less than the number of thumbs configured to show //check child dirs if ($offsetCounter < $numThumbs) { $childResult=mysql_query("SELECT * FROM al_images,al_directories WHERE al_directories.parent_dir_id=$dir AND al_images.dir_id=al_directories.dir_id ORDER BY al_directories.displayName DESC",$db); while($myrow=mysql_fetch_array($childResult)){ //if it's offset is == to the offest Counter, then set the index to that image's id if ($offsetCounter < $numThumbs) { $thumbIndex[$offsetCounter]['id']=$myrow['id']; $thumbIndex[$offsetCounter]['name']=$myrow[2]; $thumbIndex[$offsetCounter]['caption']=$myrow[3]; $thumbIndex[$offsetCounter]['folder']=$myrow['folder']; } $offsetCounter++; } } //loop until you've shown the images for($j=0;$j",$dir,$thumbIndex[$j]['id'],$size[0]+20,$size[1]+50); } else { printf('',$dir); //$thumbIndex[$j]['id']); } printThumbnail($thumbIndex[$j]['name'],$thumbIndex[$j]['folder'],stripslashes($thumbIndex[$j]['caption']),$admin); echo " "; } } function printThumbnail($name,$folder,$caption,$admin) { global $cfg; if ($cfg['autoThumbnail']==true) { if ($admin==true) { $path=$cfg['imagePath'].$folder."/".$name; $generator="../imagetest.php?path=".$path; } else { $path=$cfg['imagePath'].$folder."/".$name; $generator="imagetest.php?path=".$path; } } else { if ($admin==true) { $generator=$cfg['adminImagePath'].$folder."/thumbnails/".$name; } else { $generator=$cfg['imagePath'].$folder."/thumbnails/".$name; } } printf("\"%s\"",$generator,$caption); } function getExtension($fileName) { $extension=strtolower(substr(strstr($fileName,"."),1)); return $extension; } function getFolderName($dir) { global $db; $result=mysql_query("SELECT displayName FROM al_directories WHERE dir_id=$dir",$db); $myrow=mysql_fetch_row($result); return $myrow[0]; } function getPicSize($pic) { global $db,$cfg; $result=mysql_query("SELECT al_images.name,al_directories.folder FROM al_images,al_directories WHERE al_images.dir_id=al_directories.dir_id AND al_images.id=$pic",$db); $myrow=mysql_fetch_array($result); $imgPath=$cfg['imagePath'].$myrow['folder']."/".$myrow['name']; $size = getimagesize($imgPath); return $size; } function cleanString($string) { $testString=strtolower($string); $forbidString=array("","