MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/sb_web/b2920/hilmajohnson.com/admin/
File Upload :
Current < : /hermes/sb_web/b2920/hilmajohnson.com/admin/editcat.php

<?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");


    if (isset($_SESSION['pathphoto']) && isset($_SESSION['photocatname'])){
        $finale= xml2ary(file_get_contents($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".xml"));
        $photosize=count($finale['items']['_c']['item']);

    }


    if (isset($_POST['editlist']))
    { 

        $_SESSION['pathlist'] =$_POST['listname'];




        echo ("<h1>YOU ARE EDITING GALLERY FROM ".$_POST['listname']." FOLDER.<br/><br/><br/><a href='list.php' >GO EDIT</a></h1>");

    }

    else if (isset($_POST['deletelist']))
    { 


        echo" <SCRIPT LANGUAGE='javascript'>submitFormList('".$_POST['listname']."','list','deletefolder');</SCRIPT>";





    } else if (isset($_GET['deletelist'])=='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['pathlist']);
                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>Custom list 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['items']['_c']['item'][$numdamod]['_c']['title']['_v']=  $_POST['title'];  
        $finale['items']['_c']['item'][$numdamod]['_c']['link']['_v']=  $_POST['link'];  
        $finale['items']['_c']['item'][$numdamod]['_c']['thumb']['_v']=  "thumbs/".$_POST['thumb'];  
        $finale['items']['_c']['item'][$numdamod]['_c']['price']['_v']=  $_POST['price']; 
       
        //print_r ($finale['team']['_c']['item'][$numdamod]);
        $last= ary2xml($finale);
        //write();
        $fh = fopen($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".xml", "w");

        if($fh==false)
        die("unable to create file");

        fwrite($fh, $last);
        fclose($fh);
        echo ("<h1>Item data Edited!<br/><br/><br/><a href='editcat.php'>Back to ITEM</a></h1>");


    } else if (isset($_POST['savenew']))
    { 

        $newdata=$finale['items']['_c']['item'][0];
        //cambio i dati


        $newdata['_c']['title']['_v']=  $_POST['title'];
        $newdata['_c']['link']['_v']=  $_POST['link'];
        $newdata['_c']['thumb']['_v']=  "thumbs/".$_POST['thumb'];
        $newdata['_c']['price']['_v']=  $_POST['price'];
        
        

        ins2ary($finale['items']['_c']['item'],$newdata,$photosize+1);

        $last= ary2xml($finale);
        //write();
        $fh = fopen($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".xml", "w");

        if($fh==false)
        die("unable to create file");

        fwrite($fh, $last);
        fclose($fh);
        echo ("<h1>Item inserted!<br/><br/><br/><a href='editcat.php'>Back to ITEM</a></h1>");


    } 
    else  if ($_GET['deletephotocat']=='delete')
    { 
        //  echo("delete".$_POST['itemnumber']);
        $selected= $_GET['itemnumber'];
        // print_r ($finale['item'][$numdamod]);
        if ($selected==0){
            //   echo("number 0");
            array_shift($finale['items']['_c']['item']);
            $last= ary2xml($finale);

        }else{

            // print_r ($finale['team']['_c']['item'][$selected]);
            unset($finale['items']['_c']['item'][$selected]);
            //  print_r ($finale);

            $last= ary2xml($finale);
        }


        //write();
        $fh = fopen($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".xml", "w");

        if($fh==false)
        die("unable to create file");

        fwrite($fh, $last);
        fclose($fh);
        echo ("<h1>Item deleted!!<br/><br/><br/><a href='editcat.php'>Back to ITEM</a></h1>");




    } 

    //////////////////////rename category/////////////////////////////
    else  if ($_POST['rename'])
    { 
        $torename= xml2ary(file_get_contents($_SESSION['pathphoto']."/categories.xml"));
        $selected= $_SESSION['photocatnumber'];
        $newname=$_POST['name'];        

        //change categories.xml

        if ($_SESSION['catsize']==1){

            $torename['categories']['_c']['cat']['_c']['title']['_v']=$newname;
            $last= ary2xml($torename);

        }else{


            $torename['categories']['_c']['cat'][$selected]['_c']['title']['_v']=$newname;


            $last= ary2xml($torename);
        }
        rename($_SESSION['pathphoto']."/assets/".$_SESSION['photocatname'], $_SESSION['pathphoto']."/assets/".$newname);
        rename($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".xml", $_SESSION['pathphoto']."/".$newname.".xml");



        //write();
        $fh = fopen($_SESSION['pathphoto']."/categories.xml", "w");

        if($fh==false)
        die("unable to create file");

        fwrite($fh, $last);
        fclose($fh);


        $_SESSION['photocatname']=$newname;
        header("Location:editcat.php");

        ///////////////////////////////////////////////////////////


    }
    //////////////////////EDIT ITEM///////////////////////////// 




    else  if (isset($_POST['edit'])) 

    {
        // echo("edit ".$_POST['itemnumber']);

        $selected= $_POST['itemnumber'];

         $filejpg=scan_directory_recursively($_SESSION['pathphoto'].'/assets/'.$_SESSION['photocatname'].'/thumbs');
        $filejpgbig=scan_directory_recursively($_SESSION['pathphoto'].'/assets/'.$_SESSION['photocatname'].'/');
        // 
        $filenumber= sizeof($filejpg);
        $filenumberbig= sizeof($filejpgbig);



        /////edit
        echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>"  ;
        echo "<form action='editcat.php' method='post'>";   

        // 
        echo "<tr>";
        echo "<td align='center' colspan='2'><br/><h1>EDIT ITEM</h1><br/></td>";
        echo "</tr>";

        // 
        $valuethumb=substr($finale['items']['_c']['item'][$selected]['_c']['thumb']['_v'],7);


        echo "<tr>";    
        echo "<td><p>Caption:</p> </td><td> <textarea name='title' cols='40' rows='4'>".$finale['items']['_c']['item'][$selected]['_c']['title']['_v']."</textarea></td>";
        echo "</tr>";   
        echo  "<td><p>Thumbnail</p></td><td><select name='thumb' id='thumb'>";
        echo "<option value='".$valuethumb."'>".$valuethumb."</option>";
        for ($i=0;$i<$filenumber;$i++){

            if ($filejpg[$i]['kind']=="file"){
                echo "<option value='".$filejpg[$i]['name']."'>".$filejpg[$i]['name']."</option>";
            }
        }
        echo "</select></td>" ;
        echo "</tr>";
        echo "<tr>";
        echo  "<td><p>Image - Video</p></td><td><select name='link' id='link'>";
        echo "<option value='".$finale['items']['_c']['item'][$selected]['_c']['link']['_v']."'>".$finale['items']['_c']['item'][$selected]['_c']['link']['_v']."</option>";
        for ($i=0;$i<$filenumberbig;$i++){

            if ($filejpgbig[$i]['kind']=="file"){
                echo "<option value='".$filejpgbig[$i]['name']."'>".$filejpgbig[$i]['name']."</option>";
            }
        }
        echo "</select></td>" ;
        echo "</tr>";
        echo "<tr>";
        echo "<td><p>Price:</p> </td><td><input name='price' value='".$finale['items']['_c']['item'][$selected]['_c']['price']['_v']."' type='text'></textarea></td>";

        echo "</tr>";
        echo "<tr>";

        echo "<input name='number' type='hidden' value='".$selected."' />";
        echo "<td colspan='2' align='center'><input name='save' type='submit' value='save' /><input name='cancel' type='submit' value='cancel' ></td>";

        echo "</form>";
        echo "</tr>";
        echo "</table>";
        /////fine edit


        //////////////////////ADD NEW///////////////////////////// 

    } else  if (isset($_POST['new'])) 

    {

        $filejpg=scan_directory_recursively($_SESSION['pathphoto'].'/assets/'.$_SESSION['photocatname'].'/thumbs');
        $filejpgbig=scan_directory_recursively($_SESSION['pathphoto'].'/assets/'.$_SESSION['photocatname'].'/');
        // 
        $filenumber= sizeof($filejpg);
        $filenumberbig= sizeof($filejpgbig);


        echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>"  ;
        echo "<form action='editcat.php' method='post'>";   

        // 
        echo "<tr>";
        echo "<td align='center' colspan='2'><br/><h1>ADD A NEW ITEM</h1><br/></td>";
        echo "</tr>";


        echo "<tr>";
        echo "<td><p>Caption:</p> </td><td><textarea name='title' cols='40' rows='4' ><p><span class='footer' >This is a CSS formatted txt with a <a href='www.thissisalink.com'>hyperlink</a> and change color text!</span></p></textarea></td>";

        echo "</tr>"; 
        echo "<tr>";
        echo  "<td><p>Thumbnails</p></td> <td><select name='thumb' id='thumb'>";
        for ($i=0;$i<$filenumber;$i++){

            if ($filejpg[$i]['kind']=="file"){
                echo "<option value='".$filejpg[$i]['name']."'>".$filejpg[$i]['name']."</option>";
            }
        }
        echo "</select></td>" ;
        echo "</tr>";
        echo "<tr>";
        echo  "<td><p>Image - Video</p></td> <td><select name='link' id='link'>";
        for ($i=0;$i<$filenumberbig;$i++){

            if ($filejpgbig[$i]['kind']=="file"){
                echo "<option value='".$filejpgbig[$i]['name']."'>".$filejpgbig[$i]['name']."</option>";
            }
        }
        echo "</select></td>" ;
        echo "</tr>";
                echo "<tr>";
        echo "<td><p>Price:</p> </td><td><input name='price' value='0' type='text'></textarea></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['items']['_c']['item'][$selected-1];
        $finale['items']['_c']['item'][$selected-1] = $finale['items']['_c']['item'][$selected];
        $finale['items']['_c']['item'][$selected] = $temp; 
        $last= ary2xml($finale);




        //write();
        $fh = fopen($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".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:editcat.php");

        //////////////////////MOVE DOWN///////////////////////////// 


    }
    else  if (isset($_POST['down'])) 

    {
        // echo("up".$_POST['itemnumber']);
        $selected= $_POST['itemnumber'];



        $temp = $finale['items']['_c']['item'][$selected+1];
        $finale['items']['_c']['item'][$selected+1] = $finale['items']['_c']['item'][$selected];
        $finale['items']['_c']['item'][$selected] = $temp; 
        $last= ary2xml($finale);




        //write();
        $fh = fopen($_SESSION['pathphoto']."/".$_SESSION['photocatname'].".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:editcat.php");

    }





    else  
    {

        echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>"  ;



        echo "<tr><td colspan='2'><h1>".$_SESSION['photocatname']." ADMIN PANEL</h1></td><td colspan='3' align='center'><form action='editcat.php' method='post'>"; 
        echo   "<br/><input name='new' type='submit' value='ADD A ITEM' /><br/><br/><input type='text' name='name' value='".$_SESSION['photocatname']."' size='20' maxlength='20'><input type='submit' name='rename' value='Change name'>" ;
        echo "</form></td></tr>"; 
        //upload picture
         echo "<tr><form enctype='multipart/form-data' action='upload.php' method='post'><input type='hidden' name='MAX_FILE_SIZE' value='40000000' /><td colspan='5' align='center'><br/><h1>UPLOAD A ITEM</h1>
         <p><label>
        <input name='imagefolder' type='radio' id='imagetype_0' value='". $_SESSION['pathphoto'].'/assets/'.$_SESSION['photocatname']."' checked='checked' />
        picture or video</label>
        <br />
        <label>
        <input type='radio' name='imagefolder' value='". $_SESSION['pathphoto'].'/assets/'.$_SESSION['photocatname']."/thumbs' id='imagetype_1' />
        thumb</label></p>
         
         
         <h1>Choose a file to upload:<br/><input name='uploaded_file' type='file' size='60' /><input type='submit' value='Upload' /></h1><br/>" ;
        echo "<input name='page' type='hidden' value='editcat' /></form></td></tr>";
        
        
        
        
        
        for($i=0;$i<$photosize;$i++){ 
            echo "<form action='editcat.php' method='post'>";   
            echo "<tr>"       ;





            echo   "<td width='100' align='center'><a href='".$_SESSION['pathphoto']."/assets/".$_SESSION['photocatname']."/".$finale['items']['_c']['item'][$i]['_c']['link']['_v']."' class='preview'><img src='".$_SESSION['pathphoto']."/assets/".$_SESSION['photocatname']."/".$finale['items']['_c']['item'][$i]['_c']['thumb']['_v']."'></a></td>" ; 


            echo   "<td>".$finale['items']['_c']['item'][$i]['_c']['title']['_v']." <input name='itemnumber' type='hidden' value='".$i."' /></td>" ; 

            echo   "<td width='60'>";
            if ($_SESSION['scart_v']=='true'){
            
            echo "<p>Price: ".$finale['items']['_c']['item'][$i]['_c']['price']['_v']."</p></td>" ; 
            }else{
            
            echo "<p> S. Cart disabled </p> </td>" ; 
            
            }

            echo   "<td align='center'><input name='edit' type='submit' value='edit' />";

            if($photosize>2){
                echo"<input name='delete'  onClick=\"submitFormPhotoCat(".$i.",'editcat','delete');\"  type='button' value='delete' /></td>";  
            }         

            echo "<td align='center'>";
            if ($i!=0){

                echo "<input name='up' type='submit' value='move up' />" ;
            }
            if ($i!=$photosize-1){
                echo "<input name='down' type='submit' value='move down' />" ;    
            }
            echo "</td>";



            echo "</tr> "  ;


            echo "</form>";
        }
        echo "<tr> "  ;
        echo "<td align='center' colspan='5'><h1><a href='photo.php'>Back to Categories</a></h1></td> "  ;
        echo "</tr> "  ;

        echo "</table> " ;





    }    



?>