<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: movecategory.php,v 1.7.2.2 2004/04/18 12:46:51 ajvwaay Exp $




function movecategory($gid) {
    global $adminurl, $module_name, $imagepath, $gallerypath, $adminpath, $languagepath, $baseurl, $adminurl;
    global $bgcolor1, $bgcolor2, $version, $mpnTables, $textcolor1;

#  include ("header.php");
#  GraphicAdmin($hlpfile);
  OpenTable();
  echo "<center><font size=\"4\"><b>"._GALADMIN."</b></font></center>";
  CloseTable();
  echo "<br>";
  OpenTable();
  echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
        <tr><td>";
    echo "
    <!-- Start of Main body table -->
        <table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\" align=\"center\">
    <tr>
    <td bgcolor=\"$bgcolor2\">
        <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
        <tr>
          <td><strong><font size=\"2\">
          <a href=\"$adminurl\">"._GALCONFIG."</a> &gt;
          <a href=\"$adminurl&amp;do=editallcategories\">"._GALEDITALLCATEGORIES."</a> &gt;
          "._GALMOVECATEGORY."
          </strong></font></td>
        </tr>
        </table>
    </td>
    </tr>
    <tr>
    <td bgcolor=\"$bgcolor1\" width=\"100%\">
          <!-- Start of Body -->
          <table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\">
          <tr>
            <td width=\"100%\" align=\"center\"><p><p>
            <form action=\"$adminurl\" method=\"post\">
            <input type=\"hidden\" name=\"op\" value=\"editcategory\">
            <input type=\"hidden\" name=\"type\" value=\"move\">";

            list($cat) = mysql_fetch_row(mysql_query("SELECT gallname FROM ".$mpnTables['gallery_categories']." WHERE gallid=$gid"));

            echo "<br>
            <b>"._GALMOVEOPTION." '$cat'</b>
            <table border=\"0\">
            <tr>
              <td>
              <br>"._GALMOVEWARNING."<br><br>"._GALMOVESELECT."
                <input type=\"hidden\" name=\"oldlocation\" size=\"14\" value=\"$gid\">
                    <select size=\"1\" name=\"newparent\">";

                $categories = listcategories("$gallerypath");
                $categories = explode(" ", trim($categories));
                echo "<option selected value=\"-1\">/</option> ";
                while(list($key, $val) = each($categories)) {
                    $result = mysql_query("select gallid, gallname, parent from ".$mpnTables['gallery_categories']." where gallid=".$val);

                    list($gallid, $gallname, $parent) = mysql_fetch_row($result);
                    $nbtabs = indent($gallid);
                    $tab = "";
                    for ($i=0; $i<$nbtabs; $i++)
                        $tab .= "&nbsp;&nbsp;&nbsp;";
                    if ($gallid!=$gid)
                        echo "<option value=\"$gallid\">$tab$gallname</option> ";
                }
                    echo "</select><br><br>
              </td>
            </tr>
            </table>
            <input class=\"button\" type=\"submit\" name=\"confirmed\" value=\""._GALMOVE."\">
            </form>
            </td>
          </tr>
          </table>
          <!-- End of Body -->
    </td>
    </tr>
    </table>";
  echo "</td></tr></table>";
  CloseTable();
  print '<br>';
    // Start Of Footer
    OpenTable();
    print '
    <table><tr>
    <td>'
      ."<font face=\"Verdana,Arial\" color=\"$textcolor1\">mpn eGallery Version - $version<br>"._GALVISITUPDATE.'</font>
    </td>
    </tr></table>';
    CloseTable();
#  include("footer.php");
}


function copydir($source , $destination){
    global $adminurl, $module_name, $imagepath, $gallerypath, $adminpath, $languagepath, $baseurl, $adminurl, $mpnTables;


    $dossier=opendir($source);
    if (!file_exists($destination))
        $old_mask = umask(0000);
        mkdir($destination, 0777);
        umask($old_mask);
    $total = 0;
    while ($file = readdir($dossier)) {
        if ($file != "." && $file != ".."){
            if (is_dir($source."/".$file)){
                $total += copydir("$source/$file", "$destination/$file");
                $newgalloc = substr($destination, strlen("$gallerypath/"));
                $oldgalloc = substr($source, strlen("$gallerypath/"));
                mysql_query("UPDATE ".$mpnTables['gallery_categories']." SET galloc='$newgalloc/$file' WHERE galloc='$oldgalloc/$file'");
            } else {
                copy("$source/$file", "$destination/$file");
                @chmod("$destination/$file", 0666);
                $total++;
            }
        }
    }
    return $total;
}



function rmove($source, $destination)
{
    if (copydir($source, $destination))
        rdel($source);
}

function rdel($path) {
    global $adminurl, $module_name, $imagepath, $gallerypath, $adminpath, $languagepath, $baseurl, $adminurl, $mpnTables;

    if ($path[strlen($path)-1] != "/")
        $path .= "/";

    if (is_dir($path))
    {
        $d = opendir($path);

        while ($f = readdir($d))
        {
            if ($f != "." && $f != "..")
            {
                $rf = $path . $f;
                if (is_dir($rf)) {
            $galloc = substr($rf, strlen("$gallerypath/"));
            list($gallid) = mysql_fetch_row(mysql_query("SELECT gallid FROM ".$mpnTables['gallery_categories']." where galloc='$galloc'"));
            mysql_query("DELETE FROM ".$mpnTables['gallery_categories']." WHERE gallid=$gallid");
            mysql_query("DELETE FROM ".$mpnTables['gallery_pictures']." WHERE gid=$gallid");
            mysql_query("DELETE FROM ".$mpnTables['gallery_template']." WHERE gid=$gallid");
                    rdel($rf);
        }
                else
                    unlink($rf);
            }
        }

        closedir($d);


        return rmdir($path);
    }
}

?>
