<?
// ********************************************************************
// ********************* DON'T CHANGE BELOW HERE **********************
// ********************************************************************
$serverpath=substr(__FILE__, 0, strrpos(__FILE__, "/"));
$imgdir=$serverpath."/images/";
$me=$_SERVER['PHP_SELF'];
$version="1.5";
$now=time();
$logfile=$serverpath."/log.dat.php";
$galfile=$serverpath."/galleries.dat";
$tplfile=$serverpath."/templates.tpl";
$showedit=false;
// ********************** CLASSES/FUNCTIONS **********************
// ***************************************************************
class mdasort {
var $data;//the array we want to sort.
var $sortkeys;//the order in which we want the array to be sorted.
function _sortcmp($a, $b, $i=0) {
$r = strnatcmp($a[$this->sortkeys[$i][0]],$b[$this->sortkeys[$i][0]]);
if ($this->sortkeys[$i][1] == "DESC") $r = $r * -1;
if($r==0) {
$i++;
if ($this->sortkeys[$i]) $r = $this->_sortcmp($a, $b, $i);
}
return $r;
}
function sort() {
if(count($this->sortkeys)) {
usort($this->data,array($this,"_sortcmp"));
}
}
}
function savegals($gal, $galfile){
$fp=fopen($galfile, "w");
ksort($gal);
foreach($gal as $g) fputs($fp, "$g[0]|$g[1]|$g[2]\n");
fclose($fp);
}
function adminloggedin($logfile) {
include($logfile);
$logged=false;
if (count($admins)>0){
foreach ($admins as $line){
if ($line['hash']==md5($_REQUEST['mghash'])) $logged=true;
}
}
return $logged;
}
function clearoldadmins($logfile, $now, $adminexpire) {
include($logfile);
if (count($admins)>0){
$i=0;
$fp=fopen($logfile, "w");
fputs($fp, "<?\n");
foreach ($admins as $line){
if ($now-$line['time']<$adminexpire)
fputs($fp, "\$admins[$i]['time']=".$line[time]."; \$admins[$i]['hash']='".$line['hash']."';\n");
$i++;
}
fputs($fp, "?>");
fclose($fp);
}
}
function mkthumbnail($src, $dst, $hv="w", $size=80, $quality=80){
$info=getimagesize($src);
if ($info[2]==2){ // if it's jpg
if ($hv=="w"){
$nw=$size;
$nh=round(($info[1]*$size)/$info[0], 0);
}else if ($hv=="h"){
$nh=$size;
$nw=round(($info[0]*$size)/$info[1], 0);
}
$dst_p=imagecreatetruecolor($nw, $nh);
$src_p=imagecreatefromjpeg($src);
imagecopyresampled($dst_p, $src_p, 0,0,0,0,$nw, $nh, $info[0], $info[1]);
imagejpeg($dst_p, $dst, $quality);
imagedestroy($src_p);
imagedestroy($dst_p);
return true;
}else return false;
}
function getpics($gal, $imgdir, $pathtoscript, $thumbnails){
$dir="$imgdir$gal";
$dp=opendir($dir);
$pictures= new mdasort;
$i=0;
while ($file=readdir($dp)){
if ($file!="." && $file!=".."){
if (strpos($file, "thumb")===false && $file!="captions.dat"){
$pictures->data[$i]['id']=substr($file, 0, strrpos($file, "."));
$pictures->data[$i]['pic']=$pathtoscript."images/$gal/$file";
if ($thumbnails) $pictures->data[$i]['thumb']=$pathtoscript."images/$gal/thumb_$file";
$i++;
}
}
}
if ($i>0){
$pictures->sortkeys = array(array('id','ASC'));
$pictures->sort();
return $pictures->data;
}else return false;
}
function getImageName($gal, $name){
global $imgdir, $pathtoscript, $thumbnails;
$name = substr($name, 0, strrpos($name, "."));
$name = strtolower(preg_replace("/[^a-zA-Z0-9]/", "_", $name)).".jpg";
$images = getpics($gal, $imgdir, $pathtoscript, $thumbnails);
if (is_array($images)){
foreach ($images as $img){
// if file exists rename it
if ($img['id'].".jpg" == $name){
$version=1;
$versionext="";
while(file_exists($imgdir.$gal."/".$name)){
$name=substr($name, 0, strrpos($name, "$versionext."))."_$version".substr($name, strrpos($name, "."));
$versionext="_$version";
$version++;
}
}
}
}
return substr($name, 0, strrpos($name, "."));;
}
function getcaps($gal, $imgdir){
$caps=false;
$cappath=$imgdir.$gal."/captions.dat";
if (file_exists($cappath)){
$stuff=file($cappath);
foreach ($stuff as $line){
$cap=explode("|", rtrim($line));
$caps[$cap[0]]=$cap[1];
}
}
return $caps;
}
function nltobr($str){
return str_replace(array("\n", "\r"), array("<br>", ""), $str);
}
function brtonl($str){
return str_replace("<br>", "\n", $str);
}
function isBiggerWidth($path, $size){
if ($size!==false){
$foo=getimagesize($path);
if ($foo[0]>$size) return true;
else return false;
}else return false;
}
function getTemplate($tpl, $html){
$match="/<\!\-\-$tpl\-\->(.*?)<\!\-\-$tpl\-\->/s";
preg_match($match, $html, $tmp);
return $tmp[1];
}
function paging(
$pages,
$pagevar="page",
$ppv=10,
$first ="<a href='{url}'>«««</a> ",
$firsts ="««« ",
$prev ="<a href='{url}'>««</a> ",
$prevs ="«« ",
$num ="<a href='{url}'>{page}</a>",
$nums ="{page}",
$sep =" | ",
$more ="[<a href='{url}'>...</a>]",
$next =" <a href='{url}'>»»</a>",
$nexts =" »»",
$last =" <a href='{url}'>»»»</a>",
$lasts =" »»»"){
// get URI parameters
$getvars=$_SERVER['PHP_SELF']."?";
foreach ($_GET as $key => $val){
if ($key!=$pagevar){
if (isset($val) && $val!=""){
$getvars.="$key=$val&";
}else{
$getvars.="$key&";
}
}
}
$page=(is_numeric($_GET[$pagevar])) ? $_GET[$pagevar] : 1;
$page=($page>$pages) ? $pages : $page;
$prevpage=($page>1) ? $page-1 : 1;
$nextpage=($page < $pages) ? $page+1 : $pages;
$paging="";
if ($pages>1){
// first
$paging.=($page>1) ? str_replace("{url}", "$getvars$pagevar=1", $first) : $firsts;
// prev
$paging.=($page>1) ? str_replace("{url}", "$getvars$pagevar=$prevpage", $prev) : $prevs;
// pages
$ppvrange=ceil($page/$ppv);
$start=($ppvrange-1)*$ppv;
$end=($ppvrange-1)*$ppv+$ppv;
$end=($end>$pages) ? $pages : $end;
$paging.=($start>1) ? str_replace("{url}", "$getvars$pagevar=".($start-1), $more).$sep : "";
for ($i=1; $i<=$pages; $i++){
if ($i>$start && $i<= $end){
$paging.=($page==$i) ? str_replace("{page}", $i, $nums).(($i<$end) ? $sep : "") : str_replace(array("{url}", "{page}"), array("$getvars$pagevar=$i", $i), $num).(($i<$end) ? $sep : "");
}
}
$paging.=($end<$pages) ? $sep.str_replace("{url}", "$getvars$pagevar=".($end+1), $more) : "" ;
// next
$paging.=($page<$pages) ? str_replace("{url}", "$getvars$pagevar=$nextpage", $next) : $nexts;
// last
$paging.=($page<$pages) ? str_replace("{url}", "$getvars$pagevar=$pages", $last) : $lasts;
}
return $paging;
}
// **************************** INIT *****************************
// ***************************************************************
if (!isset($_REQUEST['mghash']) || $_REQUEST['mghash']=="") {
srand($now);
for ($i=0; $i<16 ; $i++) $secret.=chr(rand(60, 127));
$secret=md5($secret);
$hash=md5($_SERVER['HTTP_USER_AGENT'].$now.$secret);
}else $hash= $_REQUEST['mghash'];
$getvars="?".(($phpwcmsalias!="") ? "$phpwcmsalias&" : "")."mghash=$hash";
clearoldadmins($logfile, $now, $adminexpire);
// **************************** ADMIN ****************************
// ***************************************************************
if ($_REQUEST['mgdo']=="admin"){
// if login
if ($_REQUEST['mgaction']=="login"){
if ($_REQUEST['mglogin']==$adminlogin && $_REQUEST['mgpwd']==$adminpwd){
include($logfile);
$fp=fopen($logfile, "w");
fputs($fp, "<?\n");
$i=0;
if (count($admins)>0){
foreach ($admins as $line){
fputs($fp, "\$admins[$i]['time']=".$line[time]."; \$admins[$i]['hash']='".$line['hash']."';\n");
$i++;
}
}
fputs($fp, "\$admins[$i]['time']=".$now."; \$admins[$i]['hash']='".md5($hash)."';\n?>");
fclose($fp);
}
}
if (adminloggedin($logfile)){
// get gallery list from data file
$galleries=false;
if ($gals=file($galfile)){
foreach ($gals as $gal){
$gal= explode('|', rtrim($gal));
$galleries[$gal[0]] = array($gal[0], $gal[1], $gal[2]);
}
krsort($galleries, SORT_NUMERIC);
reset($galleries);
$nextindex=key($galleries)+1;
}else $nextindex=1;
// delete a gallery
if ($_REQUEST['mgaction']=="delete" && is_numeric($_REQUEST['mgid'])){
unset($galleries[$_REQUEST['mgid']]);
savegals($galleries, $galfile);
$dir="$imgdir".$_REQUEST['mgid']."/";
$dp=opendir($dir);
while ($file=readdir($dp)){
if ($file!="." && $file!="..") unlink($dir.$file);
}
closedir($dp);
rmdir($dir);
}
// move gallery upwards or downwards
if ($_REQUEST['mgaction']=="move" && is_numeric($_REQUEST['mgid']) && isset($_REQUEST['mgcmd'])){
$id=$_REQUEST['mgid'];
$cmd=$_REQUEST['mgcmd'];
$keys=array_keys($galleries);
if ($cmd=="up") sort($keys);
else if ($cmd=="down") rsort($keys);
$oid=false;
foreach ($keys as $key){
if ($cmd=="up"){
if ($key>$id){
$oid=$key;
break;
}
}else{
if ($key<$id){
$oid=$key;
break;
}
}
}
if ($oid!==false){
// exchanging the 2 array elements
$galleries[$id][0]=$oid;
$galleries[$oid][0]=$id;
list ($galleries[$id], $galleries[$oid]) = array($galleries[$oid], $galleries[$id]);
savegals($galleries, $galfile);
$tmpdir=$imgdir.$id."_tmp";
rename($imgdir.$id, $tmpdir);
rename($imgdir.$oid, $imgdir.$id);
rename($tmpdir, $imgdir.$oid);
}
}
// save edited gallery
if ($_REQUEST['mgaction']=="savegal" && isset($_REQUEST['mggal'])){
if ($_REQUEST['mggallery']!=""){
$gal=$_REQUEST['mggal'];
// delete pics?
if (is_array($_REQUEST['mgtodel'])){
foreach ($_REQUEST['mgtodel'] as $id => $val){
// delete pic
unlink($imgdir.$gal."/$id.jpg");
if ($thumbnails) unlink($imgdir.$gal."/thumb_$id.jpg");
unset($_REQUEST['mgfilename'][$id]);
}
}
// file renaming
$caps="";
foreach ($_REQUEST['mgfilename'] as $id => $newid){
$ok = true;
if ($id != $newid){
$newid = getImageName($gal, $newid.".jpg");
if (rename($imgdir.$gal."/$id.jpg", $imgdir.$gal."/$newid.jpg")) $ok = true;
else $ok = false;
if (rename($imgdir.$gal."/thumb_$id.jpg", $imgdir.$gal."/thumb_$newid.jpg")) $ok = true;
else $ok = false;
}
$cap = $_REQUEST['mgcap'][$id];
if ($cap!=""){
if ($ok===false) $newid=$id;
$caps.="$newid|".htmlentities($cap, ENT_QUOTES)."\n";
}
}
$fp=fopen($imgdir.$gal."/captions.dat", "w");
fputs($fp, $caps);
fclose($fp);
$galleries[$gal][1]=htmlentities($_REQUEST['mggallery'], ENT_QUOTES);
$galleries[$gal][2]=nltobr(htmlentities($_REQUEST['mgdescr'], ENT_QUOTES));
savegals($galleries, $galfile);
$output= $txtsavedchanges;
}else $output=$txtnoname;
$showedit=true;
}
// save new or edited gallery pictures
if ($_REQUEST['mgaction']=="upload"){
$error=false;
if (is_numeric($_REQUEST['mggal'])){
$gal=$_REQUEST['mggal'];
$showedit=true;
}else $gal=false;
if ($gal===false && $_REQUEST['mggallery']=="") $error=$txtnozip;
if ($error===false && is_uploaded_file($_FILES['mgfile']['tmp_name']) && $_FILES['mgfile']['size']>0){
// check whether new gallery or adding pics to existing one
if ($gal===false){
if (!mkdir("$imgdir$nextindex", 0777)) $error.=$txtnodir;
$galleries[$nextindex]=array($nextindex, htmlentities($_REQUEST['mggallery'], ENT_QUOTES), nltobr(htmlentities($_REQUEST['mgdescr'], ENT_QUOTES)));
krsort($galleries);
savegals($galleries, $galfile);
$i=1;
}else if (is_numeric($gal)){
if ($pictures=getpics($gal, $imgdir, $pathtoscript, $thumbnails)){
foreach ($pictures as $pic){
$ids[]=$pic['id'];
}
rsort($ids);
$i=$ids[0]+1;
}else $i=1;
$nextindex=$gal;
}
// handling single jpg upload
if ($_FILES['mgfile']['type']=="image/jpeg" || $_FILES['mgfile']['type']=="image/pjpeg"){
$name = getImageName($nextindex, $_FILES['mgfile']['name']);
if (move_uploaded_file($_FILES['mgfile']['tmp_name'], "$imgdir$nextindex/$name.jpg")){
chmod("$imgdir$nextindex/$name.jpg", 0777);
if (isBiggerWidth("$imgdir$nextindex/$name.jpg", $originalsize)) mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/$name.jpg", "w", $originalsize, $jpgquality);
if ($thumbnails)
mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/thumb_$name.jpg", $thumbhv, $thumbsize, $jpgquality);
}
// handling zip uploads
}else{
// use pclzip.lib.php for unzipping
if ($unzipmode == "pclzip"){
// thanks to 'ivugrinec2' from the planetluc.com boards for this zip mod!
include_once ('pclzip.lib.php');
if ($zip = new PclZip($_FILES['mgfile']['tmp_name'])){
if (($list = $zip->listContent()) == 0) {
die($error=$zip->errorInfo(true));
}
for ($i=0; $i<sizeof($list); $i++){
$name = $list[$i]['filename'];
$newname = getImageName($nextindex, $name);
$tmplist = $zip->extract(PCLZIP_OPT_BY_NAME, $name, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $pathtoscript."images/_tmp/");
if ($tmplist == 0) $error=$zip->errorInfo(true);
if (substr($name, -1) != "/"){
$name = (strpos($name, "/") !== false) ? substr($name, strrpos($name, "/")+1) : $name;
rename($pathtoscript."images/_tmp/$name", $pathtoscript."images/$nextindex/$newname.jpg");
chmod("$imgdir$nextindex/$newname.jpg", 0777);
if (isBiggerWidth("$imgdir$nextindex/$newname.jpg", $originalsize)) mkthumbnail("$imgdir$nextindex/$newname.jpg", "$imgdir$nextindex/$newname.jpg", "w", $originalsize, $jpgquality);
if ($thumbnails) mkthumbnail("$imgdir$nextindex/$newname.jpg", "$imgdir$nextindex/thumb_$newname.jpg", $thumbhv, $thumbsize, $jpgquality);
}
}
}
// or use php built in zip functions
}else{
if ($zip=zip_open($_FILES['mgfile']['tmp_name'])){
while($zipe=zip_read($zip)){
zip_entry_open($zip, $zipe);
$name = zip_entry_name($zipe);
$name = getImageName($nextindex, $name);
$size=zip_entry_filesize($zipe);
$tmp=zip_entry_read($zipe, $size);
$fp=fopen($pathtoscript."images/$nextindex/$name.jpg", "w");
fputs($fp, $tmp);
fclose($fp);
chmod("$imgdir$nextindex/$name.jpg", 0777);
if (isBiggerWidth("$imgdir$nextindex/$name.jpg", $originalsize)) mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/$name.jpg", "w", $originalsize, $jpgquality);
if ($thumbnails)
mkthumbnail("$imgdir$nextindex/$name.jpg", "$imgdir$nextindex/thumb_$name.jpg", $thumbhv, $thumbsize, $jpgquality);
zip_entry_close($zipe);
$i++;
}
zip_close($zip);
}
}
}// endif zip handling
}else $error=$txtnozip;
if ($error!==false) $output=$error;
}
// display admin cp header
echo "<table border='0' align='center' cellpadding='2' cellspacing='2' class='mgtxt'>\n";
echo "<tr><td class='mgadmincap'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0' class='mgtxt'>\n";
echo "<tr><td ><font color='#FFFFFF'><strong>MyGallery Admin CP</strong></font></td>\n";
echo "<td align='right' style='color:#ffffff;'>[<a href='$me$getvars' style='color:#ffffff;'>$txtlogout</a>] </td>\n";
echo "</tr></table>\n";
echo "</td></tr>\n";
// if in gallery edit mode
if ($showedit || $_REQUEST['mgaction']=="edit"){
$gal=$_REQUEST['mggal'];
echo "<tr><td class='mgadmintdbg'>\n";
echo "<strong>$txtediting <em style='letter-spacing:1px'>".$galleries[$gal][1]."</em></strong><br><br> \n";
echo "<form name='form1' enctype='multipart/form-data' method='post' action='$me$getvars'>\n";
echo "<strong>$txtaddpicscap</strong><br>$txtaddpics<br><input name='mgfile' type='file' id='mgfile' class='mginputln'><br>\n";
echo "<input type='submit' name='Submit' value='$txtadd'>\n";
echo "<input name='mgdo' type='hidden' id='mgdo' value='admin'>\n";
echo "<input name='mgaction' type='hidden' id='mgdo' value='upload'>\n";
echo "<input name='mggal' type='hidden' id='mgdo' value='$gal'>\n";
echo "<input name='mghash' type='hidden' id='mgdo' value='$hash'>\n";
echo "<center style='color:#cc0000;'>$output</center>\n";
echo "</form><br> \n";
$caps=getcaps($gal, $imgdir);
$i=1;
$pictures = getpics($gal, $imgdir, $pathtoscript, $thumbnails);
if ($pictures!==false){
echo "<form name='fomr9' method='post' action='$me$getvars'>\n";
echo "<strong>$txtgalname</strong><br>";
echo "<input name='mggallery' type='text' id='mggallery' style='width:100%;' value='".(stripslashes($galleries[$gal][1]))."' class='mginputln'><br><br>\n";
echo "<strong>$txtdescription</strong><br>";
echo "<textarea name='mgdescr' id='mgdescr' style='width:100%;' rows='5' class='mginputln'>".(brtonl(stripslashes($galleries[$gal][2])))."</textarea><br> \n";
echo "<table width='100%' border='0' align='center' cellpadding='2' cellspacing='2' class='mgtxt'><tr class='mgsmall'>\n\n";
foreach ($pictures as $pic){
$img=($thumbnails) ? $pic['thumb'] : $pic['pic'];
$size=getimagesize($img);
$attr=($size[0]>$thumbsize) ? "width='$thumbsize' height='".($thumbsize*$size[1]/$size[0])."'" : "width='$size[0]' height='$size[1]'";
echo "<td width='25%' valign='top' class='mgaltbgcol'>\n";
echo "$txtcaption<br><input name='mgcap[".$pic['id']."]' type='text' id='mglogin' size='15' value='".(stripslashes($caps[$pic['id']]))."' class='mginputln'><br>\n";
// rename file
echo "$txtfilename<br><input name='mgfilename[".$pic['id']."]' type='text' id='mglogin' size='15' value='".$pic['id']."' class='mginputln'><br>\n";
echo "<input name='mgtodel[".$pic['id']."]' type='checkbox' value='1' style='vertical-align:-5px;' id='mgtodel[".$pic['id']."]'>[<label for='mgtodel[".$pic['id']."]'>$txtdelete</label>]<br />\n";
echo "<img src='$img' $attr border='0' class='mgimgbrd' align='texttop' title='".$pic['id'].".jpg'>\n";
echo "</td>\n\n";
if (fmod($i, $thumbcolsadmin)==0) echo "</tr><tr class='mgsmall'>\n";
$i++;
}
echo "</tr><tr><td colspan='$thumbcolsadmin' align='center' height='40' valign='bottom'>";
echo "<input type='submit' name='Submit' value='$txtsavechange'>\n";
echo "<input type='button' value='$txtback' onClick='location.href=\"$me$getvars&mgdo=admin\"'>\n";
echo "<input name='mgdo' type='hidden' id='mgdo' value='admin'>\n";
echo "<input name='mgaction' type='hidden' id='mgdo' value='savegal'>\n";
echo "<input name='mghash' type='hidden' id='mgdo' value='$hash'>\n";
echo "<input name='mggal' type='hidden' id='mgdo' value='$gal'>\n";
echo "</td></tr></table></form>\n";
}// endif $pictures!==false
echo "</td></tr>\n";
// else in not edit mode
}else{
// upload new gallery form
echo "<tr><td class='mgadmintdbg'>\n";
echo "<form name='form1' enctype='multipart/form-data' method='post' action='$me$getvars'>\n";
echo "<strong>$txtnewgal</strong><br>$txtzipdesc<br><br>\n";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='1' class='mgtxt'>\n";
echo "<tr><td width='100'>$txtgalname:</td>\n";
echo "<td><input name='mggallery' type='text' id='mggallery' style='width:100%;' class='mginputln'></td></tr>\n";
echo "<tr><td width='100'>$txtdescription:</td>\n";
echo "<td><textarea name='mgdescr' type='text' id='mgdescr'style='width:100%;' rows='4' class='mginputln'></textarea></td></tr>\n";
echo "<tr><td> </td>\n";
echo "<td>($txtselzip) <br><input name='mgfile' type='file' id='mgfile' class='mginputln'>\n";
echo "</td></tr>\n";
echo "<tr><td> </td>\n";
echo "<td height='40'>\n";
echo "<input type='submit' name='Submit' value='$txtbuild'>\n";
echo "<input name='mgdo' type='hidden' id='mgdo' value='admin'>\n";
echo "<input name='mgaction' type='hidden' id='mgdo' value='upload'>\n";
echo "<input name='mghash' type='hidden' id='mgdo' value='$hash'>\n";
echo "</td></tr></table>\n";
echo "<center style='color:#cc0000;'>$output</center>\n";
echo "</form></td></tr>\n";
// show gallery list
if($galleries!==false){
echo "<tr><td class='mgadmintdbg'><strong>$txtexgals<br><br></strong>\n";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='mgtxt'>\n";
echo "<tr>\n";
echo "<td width='30' align='center' class='mgadmincap'><font color='#FFFFFF'>#</font></td>\n";
echo "<td class='mgadmincap'><font color='#FFFFFF'>$txtname</font></td>\n";
echo "<td class='mgadmincap'> </td>\n";
echo "</tr>\n";
$i=1;
$bgcol[0]="";
$bgcol[1]="class='mgaltbgcol'";
krsort($galleries);
//print_r($galleries);
foreach($galleries as $gal){
echo "<tr ".$bgcol[fmod($i,2)].">\n";
echo "<td align='center'>$i</td>\n";
echo "<td><a href='$me$getvars&mggal=$gal[0]'>".stripslashes($gal[1])."</a></td>\n";
echo "<td align='right'>";
echo "<a href='$me$getvars&mgdo=admin&mgaction=move&mgcmd=up&mgid=$gal[0]'>$txtup</a> \n";
echo "<a href='$me$getvars&mgdo=admin&mgaction=move&mgcmd=down&mgid=$gal[0]'>$txtdown</a> \n";
echo "<a href='$me$getvars&mgdo=admin&mgaction=edit&mggal=$gal[0]'>$txtedit</a> \n";
echo "<a href='javascript: if(confirm(\"$txtasktodel\")){ location.href=\"$me$getvars&mgdo=admin&mgaction=delete&mgid=$gal[0]\";}'>$txtdelete</a>\n";
echo "</td>\n";
echo "</tr>\n";
$i++;
}
echo "</table>\n";
echo "</td></tr>\n";
}
}// endif (not edit mode)
echo "</table>\n";
// if not logged in -> admin login form
}else{
echo "<script language='JavaScript'>\n";
echo "window.onload=function(){ document.forms['loginform'].elements['mglogin'].focus(); }\n";
echo "</script>\n";
echo "<table border='0' align='center' cellpadding='2' cellspacing='2' class='mgtxt'>\n";
echo "<tr><td class='mgadmincap'><font color='#FFFFFF'><strong>MyGallery Admin CP </strong></font></td></tr>\n";
echo "<tr><td class='mgadmintdbg'>\n";
echo "<form name='loginform' method='post' action='$me$getvars'>\n";
echo "$txtlogin <input name='mglogin' type='text' id='mglogin' size='20' class='mginputln'>\n";
echo "$txtpass <input name='mgpwd' type='password' id='mgpwd' size='20' class='mginputln'>\n";
echo "<input type='submit' name='Submit' value='Login'>\n";
echo "<input name='mgdo' type='hidden' id='mgdo' value='admin'>\n";
echo "<input name='mgaction' type='hidden' id='mgaction' value='login'>\n";
echo "<input name='mghash' type='hidden' id='mgdo' value='$hash'>\n";
echo "</form></td></tr></table>\n";
}
// ***************************** MAIN *****************************
// ****************************************************************
// if not in admin mode
}else{
// get gallery list from data file
$galleries=false;
if ($gals=file($galfile)){
foreach ($gals as $gal){
$gal= explode('|', rtrim($gal));
$galleries[$gal[0]] = array($gal[0], $gal[1], $gal[2]);
}
krsort($galleries, SORT_NUMERIC);
}
// show the gallery list
if (!isset($_REQUEST['mggal'])){
if ($galleries!==false){
// reorganize $galleries array
$foo=$galleries;
$galleries=array();
foreach ($foo as $g) $galleries[]=$g;
// paging
$page=(is_numeric($_REQUEST['mgpage'])) ? $_REQUEST['mgpage'] : 1;
$start= ($page-1) * $gpp;
$numgals=count($galleries);
$pages=ceil($numgals/$gpp);
$paging=paging($pages, "mgpage");
// get template for gallleries list
$tpl=getTemplate("GALLERIES", implode("", file($tplfile)));
$tplrow=getTemplate("ROW", $tpl);
$rows="";
for ($i=$start; $i<($start+$gpp); $i++){
if (is_array($galleries[$i])){
$gal=$galleries[$i];
// get random preview thumbnail
$pictures = getpics($gal[0], $imgdir, $pathtoscript, $thumbnails);
$c=count($pictures);
$imgsrc=$pictures[rand(0, ($c-1))]['thumb'];
$match=array("{urlthumb}", "{title}", "{description}", "{urlgallery}");
$replace=array($imgsrc, stripslashes($gal[1]), $gal[2], $me.$getvars."&mggal=".$gal[0]);
$rows.=str_replace($match, $replace, $tplrow);
}
}
$match= array("/\{paging\}/", "/<\!\-\-ROW\-\->(.*?)<\!\-\-ROW\-\->/s");
$replace= array($paging, $rows);
echo preg_replace($match, $replace, $tpl);
}// endif $galleries!==false)
// show specific gallery
}else{
$gal=$_REQUEST['mggal'];
if ($pictures = getpics($gal, $imgdir, $pathtoscript, $thumbnails)){
$numpics=count($pictures);
// show thumbnails page
if (!isset($_REQUEST['mgid']) && $thumbnails){
// get template for this gallery
$tpl=getTemplate("GALLERY", implode("", file($tplfile)));
$tplpic=getTemplate("PIC", $tpl);
$pictable= "<table border='0' cellpadding='0' cellspacing='5'><tr>\n";
$i=0;
$caps=getcaps($gal, $imgdir);
foreach ($pictures as $pic){
$pictable.= "<td valign='top' align='center'>";
$match= array("{urlpicture}", "{urlthumb}", "{captionpicture}");
$replace= array("$me$getvars&mggal=$gal&mgid=$i&mgcmd=noslide", $pic['thumb'], stripslashes($caps[$pic['id']]));
$pictable.= str_replace($match, $replace, $tplpic);
$pictable.= "</td>\n";
if (fmod(($i+1), $thumbcols)==0) $pictable.= "</tr><tr>\n";
$i++;
}
$pictable.= "</tr></table>\n";
$match=array("/\{captiongallery\}/", "/\{urlslideshow\}/", "/\{urlbacktoindex\}/", "/<\!\-\-PIC\-\->(.*?)<\!\-\-PIC\-\->/s");
$replace=array(stripslashes($galleries[$gal][1]), $me.$getvars."&mggal=$gal&mgid=0", $me.$getvars, $pictable);
echo preg_replace($match, $replace, $tpl);
// show specific pic
}else {
if (!isset($_REQUEST['mgid'])) $id=0;
else $id=$_REQUEST['mgid'];
$backurl="$me$getvars".(($thumbnails) ? "&mggal=$gal" : "");
if ($id==($numpics-1)) $nexturl=$backurl;
else $nexturl="$me$getvars&mggal=$gal&mgid=".($id+1);
// get caps
$caps=getcaps($gal, $imgdir);
// get template for this picture
$tpl=getTemplate("PICTURE", implode("", file($tplfile)));
$match= array("{captiongallery}", "{info}", "{urlpic}", "{captionpicture}", "{urlbacktoindex}", "{urlnextpicture}", "{urlnextpictureslideshow}");
$replace= array( stripslashes($galleries[$gal][1]),
(($_REQUEST['mgcmd']!="noslide" && $slideshow) ? "$txtnextslide<br>$txtclickpic" : $txtclickpic),
$pictures[$id]['pic'],
stripslashes($caps[$pictures[$id]['id']]),
$backurl,
$nexturl."&mgcmd=noslide",
$nexturl);
echo str_replace($match, $replace, $tpl);
if ($_REQUEST['mgcmd']!="noslide" && $slideshow) echo "<meta http-equiv='refresh' content='$slideshowtime;URL=$nexturl#mgtop'>\n";
}
}else echo "<center class='mgtxt'><a href='$me$getvars'>$txtback</a></center>";
}
}
echo "<br><br><center><span class='mgsmall'>[<a href='$me$getvars&mgdo=admin'>$txtadmin</a>] </span></center>";
?>