<?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: deletecategory.php,v 1.3.2.2 2004/04/18 12:46:51 ajvwaay Exp $




function rdel($path)
{
    global $gallerypath, $module_name, $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");
                    rdel($rf);
        }
                else
                {
                    unlink($rf);
                }
            }
        }

        closedir($d);


        return rmdir($path);
    }
}


function deletecategory($gallid)
{
    global $module_name, $gallerypath, $mpnTables;

    list($galloc, $gallimg) = mysql_fetch_row(mysql_query("SELECT galloc, gallimg FROM ".$mpnTables['gallery_categories']." where gallid=$gallid"));
    $basedir = $gallerypath;
    if ($galloc != "")
    {
        rdel($basedir."/".$galloc);
    }
    else
    {
        echo "ERROR : Galloc is Wrong !";
    }

    mysql_query("DELETE FROM ".$mpnTables['gallery_categories']." WHERE gallid=$gallid");
    mysql_query("DELETE FROM ".$mpnTables['gallery_pictures']." WHERE gid=$gallid");
    $result = mysql_query("SELECT pid FROM ".$mpnTables['gallery_pictures']." WHERE gid = $gallid");
    while(list($pid) = mysql_fetch_row($result))
    {
        mysql_query("DELETE FROM ".$mpnTables['gallery_comments']." WHERE pid=$pid");
    }
}

?>
