<?php
////////////////////////////////
ob_start();
session_start(); /// initialize session
include("./inc/pw.php");
check_logged();
include("./inc/dirscan.php");
include("./inc/array_xml.php");
include("./inc/jscript.php");
$module= xml2ary(file_get_contents('tmp/module.xml'));
$modulesize=count($module['module']['_c']['item']);
if (isset($_SESSION['pathphoto'])){
$finale= xml2ary(file_get_contents($_SESSION['pathphoto']."/categories.xml"));
$catsize=count($finale['categories']['_c']['cat']);
// print_r($finale);
}
$tmpcat=xml2ary(file_get_contents('tmp/template/photo/categories.xml'));
if (isset($_POST['editphoto']))
{
$_SESSION['pathphoto'] =$_POST['photoname'];
$_SESSION['scart_v'] =$finale['categories']['_c']['scart']['_v'];
echo ("<h1>YOU ARE EDITING GALLERY FROM ".$_POST['photoname']." FOLDER.<br/><br/><br/><a href='photo.php' >GO EDIT</a></h1>");
}
else if (isset($_POST['deletephoto']))
{
echo" <SCRIPT LANGUAGE='javascript'>submitFormPhoto('".$_POST['photoname']."','photo','deletefolder');</SCRIPT>";
} else if (isset($_GET['deletephoto'])=='deletefolder')
{
$directory=$_GET['name'];
// echo $directory;
for($i=0;$i<$modulesize;$i++){
if($i>1 && $module['module']['_c']['item'][$i]['_c']['path']['_v'] == $directory){
unset($_SESSION['pathphoto']);
unset($module['module']['_c']['item'][$i]);
$last= ary2xml($module);
//write();
$fh = fopen("tmp/module.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
}
}
// Delete it
if (recursive_remove_directory($directory))
{
//echo "{$directory} has been deleted";
echo ("<h1>GALLERY folder deleted!<br/><br/><br/><a href='index.php' target='_top'>Close</a></h1>");
}
else
{
echo "{$directory} could not be deleted";
}
}
/* else if (isset($_POST['save']))
{
//echo("inviato".$_POST['number']);
$numdamod= $_POST['number'];
// print_r ($finale['item'][$numdamod]);
//cambio i dati
$finale['team']['_c']['item'][$numdamod]['_c'][txt]['_v']= $_POST['txt'];
$finale['team']['_c']['item'][$numdamod]['_c'][txtbig]['_v']= $_POST['txtbig'];
$finale['team']['_c']['item'][$numdamod]['_c'][link]['_v']= $_POST['link'];
$finale['team']['_c']['item'][$numdamod]['_c'][img]['_v']= $_POST['img'];
$finale['team']['_c']['item'][$numdamod]['_c'][imgbig]['_v']= $_POST['imgbig'];
//print_r ($finale['team']['_c']['item'][$numdamod]);
$last= ary2xml($finale);
//write();
$fh = fopen($_SESSION['pathlist']."/team.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Item Edited!<br/><br/><br/><a href='list.php'>Back to LIST</a></h1>");
}*/
else if (isset($_POST['savenew']))
{
if ($catsize>1){
$newdata=$tmpcat['categories']['_c']['cat'][0];
//cambio i dati
$newdata['_c'][title]['_v']= $_POST['name'];
ins2ary($finale['categories']['_c']['cat'],$newdata,$catsize+1);
}else{
$onetmp=$finale['categories']['_c']['cat']['_c']['title']['_v'];
$finale=$tmpcat;
$finale['categories']['_c']['path']['_v']=substr($_SESSION['pathphoto'],3)."/";
$finale['categories']['_c']['cat'][0]['_c']['title']['_v']=$onetmp;
$finale['categories']['_c']['cat'][1]['_c']['title']['_v']=$_POST['name'];
unset($finale['categories']['_c']['cat'][2]);
unset($finale['categories']['_c']['cat'][3]);
unset($finale['categories']['_c']['cat'][4]);
}
if (!copy("tmp/template/photo/testcat2.xml", $_SESSION['pathphoto']."/".$_POST['name'].".xml")) {
echo "failed to copy $file...\n";
}
if (!smartCopy("tmp/template/photo/assets/testcat2", $_SESSION['pathphoto']."/assets/".$_POST['name'], $folderPermission=0777,$filePermission=0777)){
}else{
}
$last= ary2xml($finale);
//write();
$fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Category inserted!<br/><br/><br/><a href='photo.php'>Back to CATEGORIES</a></h1>");
}
else if (isset($_POST['scart']))
{
$finale['categories']['_c']['scart']['_v']=$_POST['scart_v'];
$last= ary2xml($finale);
//write();
$fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Shopping Cart Updated!<br/><br/><br/><a href='photo.php'>Back to CATEGORIES</a></h1>");
}
else if (isset($_POST['password']))
{
if($_POST['pass']!="" && $_POST['pass']!="none" ) {
$finale['categories']['_c']['password']['_v']=$_POST['pass'];
}else{
$finale['categories']['_c']['password']['_v']='none';
}
$last= ary2xml($finale);
//write();
$fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>password Updated!<br/><br/><br/><a href='photo.php'>Back to CATEGORIES</a></h1>");
}
else if ($_GET['delete']=='delete')
{
$selected= $_GET['itemnumber'];
$directory=$_SESSION['pathphoto']."/assets/".$finale['categories']['_c']['cat'][$selected]['_c']['title']['_v'];
unlink($_SESSION['pathphoto']."/".$finale['categories']['_c']['cat'][$selected]['_c']['title']['_v'].".xml");
if ($selected==0){
array_shift($finale['categories']['_c']['cat']);
$last= ary2xml($finale);
}else{
unset($finale['categories']['_c']['cat'][$selected]);
$last= ary2xml($finale);
}
// Delete it
if (recursive_remove_directory($directory))
{
//echo "{$directory} has been deleted";
// echo ("<h1>GALLERY folder deleted!<br/><br/><br/><a href='index.php' target='_top'>Close</a></h1>");
}
else
{
// echo "{$directory} could not be deleted";
}
//write();
$fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Category deleted!!<br/><br/><br/><a href='photo.php'>Back to CATEGORIES</a></h1>");
//////////////////////EDIT category/////////////////////////////
} else if (isset($_POST['edit']))
{
$selected= $_POST['itemname'];
$_SESSION['photocatname']=$selected;
$_SESSION['photocatnumber']=$_POST['itemnumber'];
$_SESSION['catsize']=$catsize;
$_SESSION['scart_v'] =$finale['categories']['_c']['scart']['_v'];
header("Location:editcat.php");
/////edit
echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>" ;
//
echo "<tr>";
echo "<td align='center' colspan='2'><br/><h1>EDIT CATEGORY ".$_POST['itemname']."</h1><br/></td>";
echo "</tr>";
//
echo "<tr>";
echo "<br/><br/><br/><td align='center'><h1><a href='editcat.php'>GO TO EDITOR</a></h1></td>";
echo "</tr>";
echo "</table>";
/////fine edit
}
//////////////////////ADD NEW/////////////////////////////
else if (isset($_POST['new']))
{
$filejpg=scan_directory_recursively($_SESSION['pathlist'].'/img');
$filejpgbig=scan_directory_recursively($_SESSION['pathlist'].'/img/big');
// print_r($filejpg) ;
$filenumber= sizeof($filejpg);
$filenumberbig= sizeof($filejpgbig);
// echo $filenumber;
/////edit
echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>" ;
echo "<form action='photo.php' method='post'>";
//
echo "<tr>";
echo "<td align='center' colspan='2'><br/><h1>ADD A NEW CATEGORY</h1><br/></td>";
echo "</tr>";
echo "<tr>";
echo "<td><p>Category name :</p> </td><td><input name='name' size='40' ></input></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2' align='center'><input name='savenew' type='submit' value='save new' /><input name='cancel' type='submit' value='cancel' ></td>";
echo "</form>";
echo "</tr>";
echo "</table>";
/////fine new
}
//////////////////////MOVE UP/////////////////////////////
else if (isset($_POST['up']))
{
$selected= $_POST['itemnumber'];
$temp = $finale['categories']['_c']['cat'][$selected-1];
$finale['categories']['_c']['cat'][$selected-1] = $finale['categories']['_c']['cat'][$selected];
$finale['categories']['_c']['cat'][$selected] = $temp;
$last= ary2xml($finale);
//write();
$fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
header("Location:photo.php");
//////////////////////MOVE DOWN/////////////////////////////
}
else if (isset($_POST['down']))
{
$selected= $_POST['itemnumber'];
$temp = $finale['categories']['_c']['cat'][$selected+1];
$finale['categories']['_c']['cat'][$selected+1] = $finale['categories']['_c']['cat'][$selected];
$finale['categories']['_c']['cat'][$selected] = $temp;
$last= ary2xml($finale);
//write();
$fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
//echo ("edit effettuata<a href='list.php'> torna all'elenco</a>");
header("Location:photo.php");
}
else
{
echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>" ;
echo "<tr><td colspan='2'><h1>GALLERY CATEGORIES PANEL</h1></td><td colspan='3' align='center'><form action='photo.php' method='post'>";
echo "<br/><input name='new' type='submit' value='ADD A CATEGORY' /><br/><br/>" ;
echo "</form></td></tr>";
echo "<tr><td ><h1>SHOPPING CART:</h1></td><td colspan='3' align='center'><form action='photo.php' method='post'>";
echo "<label><p>
<input name='scart_v' type='radio' value='true'";
if ($finale['categories']['_c']['scart']['_v']=='true' ){
echo"checked='checked' />";
}else{
echo" />";
}echo"
ENABLED </p></label>
<label><p>
<input type='radio' name='scart_v' value='false' ";
if ($finale['categories']['_c']['scart']['_v']=='false' ){
echo"checked='checked' />";
}else{
echo" />";
}echo"
DISABLED</p></label><br/><input name='scart' type='submit' value='SAVE' /><br/><br/>" ;
echo "</form></td></tr>";
echo "<tr><td ><h1>PASSWORD PROTECTION:</h1></td><td colspan='3' align='center'><form action='photo.php' method='post'>";
echo "<p>Set password (blank or none= no password)<br><br><br /> <input name='pass' type='text' value='".$finale['categories']['_c']['password']['_v']."' width='40'></p><input name='password' type='submit' value='SET' /><br/>" ;
echo "</form></td></tr>";
for($i=0;$i<$catsize;$i++){
echo "<form action='photo.php' method='post'>";
echo "<tr>" ;
if($catsize==1){
echo "<td width='100' align='center' colspan='2'><p>".$finale['categories']['_c']['cat']['_c']['title']['_v']."</p><input name='itemname' type='hidden' value='".$finale['categories']['_c']['cat']['_c']['title']['_v']."' /><input name='itemnumber' type='hidden' value='alone' /></td>" ;
}else{
echo "<td width='100' align='center' colspan='2'><p>".$finale['categories']['_c']['cat'][$i]['_c']['title']['_v']."</p><input name='itemname' type='hidden' value='".$finale['categories']['_c']['cat'][$i]['_c']['title']['_v']."' /><input name='itemnumber' type='hidden' value='".$i."' /></td>" ;
}
echo "<td align='center'><input name='edit' type='submit' value='edit' />";
if($catsize>1){
echo"<input name='delete' onClick=\"submitForm(".$i.",'photo','delete');\" type='button' value='delete' /></td>";
}
echo "<td align='center'>";
if ($i!=0){
echo "<input name='up' type='submit' value='move up' />" ;
}
if ($i!=$catsize-1){
echo "<input name='down' type='submit' value='move down' />" ;
}
echo "</td>";
echo "</tr> " ;
echo "</form>";
}
echo "</table> " ;
}
?>