<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.8 www.exoops.info 2006/03
// 
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Pascal Le Boustouller
// Author Website : http://www.perso-search.com/e-xoopsien/
// Licence Type   : GPL
// ------------------------------------------------------------------------- //
include("admin_header.php");
include(XOOPS_ROOT_PATH."/modules/MyAnnonces/cache/config.php");
#  function AnnoncesNewCat
#####################################################
function AnnoncesNewCat($cat) {
    global $db, $bcoosConfig, $xoopsModule, $classm, $ynprice, $myts;
	
include(XOOPS_ROOT_PATH."/modules/MyAnnonces/include/functions.php");
include_once(XOOPS_ROOT_PATH."/modules/MyAnnonces/class/arbre.php");
$mytree = new XoopsArbre($db->prefix("ann_categories"),"cid","pid");
ShowImg();
xoops_cp_header();
    OpenTable();
	
	echo "<form method=\"post\" action=\"gest-cat.php\" name=\"imcat\"><input type=\"hidden\" name=\"op\" value=\"AnnoncesAddCat\">
	    <b>".__ADDSUBCATEGORY."</b></font><br><br>
		<TABLE BORDER=0>
    <TR>
      <TD>"._CLA_CATNAME." </TD><TD colspan=2><input type=\"text\" class=\"text\" name=\"title\" size=\"30\" maxlength=\"100\">&nbsp; "._CLA_IN." &nbsp;";
	  
	  $result = $db->query("select pid, title, img, ordre from ".$db->prefix("ann_categories")." where cid=$cat");
	list($pid, $title, $imgs, $ordre) = $db->fetchRow($result);
$mytree->makeMySelBox("title", "title", $cat, 1);
	echo "</TD>
	</TR>
    <TR>
      <TD>"._CLA_IMGCAT."  </TD><TD colspan=2><SELECT NAME=\"img\" onChange=\"showimage()\" class=\"select\">";	  
	  
	$rep = XOOPS_ROOT_PATH."/modules/MyAnnonces/images/cat";
	$handle=opendir($rep);
		while ($file = readdir($handle)) {
			$filelist[] = $file;
		}
		asort($filelist);
		while (list ($key, $file) = each ($filelist)) {
			if (!ereg(".gif|.jpg|.png",$file)) {
				if ($file == "." || $file == "..") $a=1;
			} else {
			if ($file == "default.gif") {
				echo "<option value=$file selected>$file</option>";
				} else {
				echo "<option value=$file>$file</option>";
				}
			}
		}
		echo "</select>&nbsp;&nbsp;<img src=\"".XOOPS_URL."/modules/MyAnnonces/images/cat/default.gif\" name=\"avatar\" align=\"absmiddle\"> </TD></TR><TR><TD>&nbsp;</TD><TD colspan=2>"._CLA_REPIMGCAT." /modules/MyAnnonces/images/cat/</TD></TR>";
if ($ynprice == 1) {
echo "<TR><TD>"._CLA_DISPLPRICE2." </TD><TD colspan=2><input type=\"radio\" class=\"radio\" name=\"affprix\" value=\"1\">"._YES."&nbsp;&nbsp; <input type=\"radio\" class=\"radio\" name=\"affprix\" value=\"0\">"._NO." ("._CLA_INTHISCAT.")</TD></TR>";
}
if ($classm == "ordre") {
	echo "<TR><TD>"._CLA_ORDRE." </TD><TD><input type=\"text\" class=\"text\" name=\"ordre\" size=\"4\"></TD><TD><input type=\"submit\" value=\""._CLA_ADD."\"></TD></TR>";
} else {
	echo "<TR><TD colspan=3><input type=\"submit\" value=\""._CLA_ADD."\" class=\"button\"></TD></TR>";
}
echo "</TABLE>
	    </form>";
	echo "<br>";
	
		CloseTable();
xoops_cp_footer();
}
	
	
#  function AnnoncesModCat
#####################################################
function AnnoncesModCat($cat) {
    global $db, $bcoosConfig, $xoopsModule, $classm, $ynprice, $myts;
include(XOOPS_ROOT_PATH."/modules/MyAnnonces/include/functions.php");
include_once(XOOPS_ROOT_PATH."/modules/MyAnnonces/class/arbre.php");
$mytree = new XoopsArbre($db->prefix("ann_categories"),"cid","pid");
	
xoops_cp_header();
    OpenTable();
	
ShowImg();
	echo "<b>"._CLA_MODIFCAT."</b><br><br>";
	$result = $db->query("select pid, title, img, ordre, affprix from ".$db->prefix("ann_categories")." where cid=$cat");
	list($pid, $title, $imgs, $ordre, $affprix) = $db->fetchRow($result);
	
	$title = $myts->makeTboxData4Edit($title);
	
	echo "<form action=\"gest-cat.php\" method=\"post\" name=\"imcat\">
	    		
		<table border=\"0\"><TR>
	<TD>"._CLA_CATNAME."   </TD><TD><input type=\"text\" class=\"text\" name=\"title\" value=\"$title\" size=\"30\" maxlength=\"50\">&nbsp; "._CLA_IN." &nbsp;";
	$mytree->makeMySelBox("title", "title", $pid, 1);
	echo "</TD></TR><TR>
	<TD>"._CLA_IMGCAT."  </TD><TD><SELECT NAME=\"img\" onChange=\"showimage()\" class=\"select\">";	  
	  
	$rep = XOOPS_ROOT_PATH."/modules/MyAnnonces/images/cat";
	$handle=opendir($rep);
		while ($file = readdir($handle)) {
			$filelist[] = $file;
		}
		asort($filelist);
		while (list ($key, $file) = each ($filelist)) {
			if (!ereg(".gif|.jpg|.png",$file)) {
				if ($file == "." || $file == "..") $a=1;
			} else {
			if ($file == $imgs) {
				echo "<option value=$file selected>$file</option>";
				} else {
				echo "<option value=$file>$file</option>";
				}
			}
		}
		echo "</select>&nbsp;&nbsp;<img src=\"".XOOPS_URL."/modules/MyAnnonces/images/cat/$imgs\" name=\"avatar\" align=\"absmiddle\"> </TD></TR><TR><TD>&nbsp;</TD><TD>"._CLA_REPIMGCAT." /modules/MyAnnonces/images/cat/</TD></TR>";
if ($ynprice == 1) {
echo "<TR><TD>"._CLA_DISPLPRICE2." </TD><TD colspan=2><input type=\"radio\" class=\"radio\" name=\"affprix\" value=\"1\""; if ($affprix == "1") echo "checked"; 
echo ">"._YES."&nbsp;&nbsp; <input type=\"radio\" class=\"radio\" name=\"affprix\" value=\"0\""; if ($affprix == "0") echo "checked"; echo ">"._NO." ("._CLA_INTHISCAT.")</TD></TR>";
}
if ($classm == "ordre") {
echo "<TR><TD>"._CLA_ORDRE." </TD><TD><input type=\"text\" class=\"text\" name=\"ordre\" size=\"4\" value=\"$ordre\"></TD></TR>";
}
echo "</table><P>";
		
		
	    echo "<input type=\"hidden\" name=\"cidd\" value=\"$cat\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"AnnoncesModCatS\">"
	    ."<table border=\"0\"><tr><td>"
	    ."<input type=\"submit\" value=\""._CLA_SAVMOD."\" class=\"button\"></form></td><td>"
	    ."<form action=\"gest-cat.php\" method=\"post\">"
	    ."<input type=\"hidden\" name=\"cid\" value=\"$cat\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"AnoncesDelCat\">"
	    ."<input type=\"submit\" value=\""._DELETE."\" class=\"button\"></form></td></tr></table>";
 
    CloseTable();
xoops_cp_footer();
}
	
#  function AnnoncesModCatS
#####################################################
function AnnoncesModCatS($cidd, $cid, $img, $title, $ordre, $affprix) {
    global $db,$bcoosConfig, $myts;
	
	if ($cidd == $cid) {
		redirect_header("map.php",1,_CLA_OOPSCATSMOD);
		exit();
	}
	
	$title = $myts->makeTboxData4Save($title);
	
	$db->query("update ".$db->prefix("ann_categories")." set title='$title', pid='$cid', img='$img', ordre='$ordre', affprix='$affprix' where cid=$cidd");
	
		redirect_header("map.php",1,_CLA_CATSMOD);
		exit();
}
	
	#  function AnnoncesAddCat
#####################################################
function AnnoncesAddCat($title, $cid, $img, $ordre, $affprix) {
    global $db, $bcoosConfig, $myts;
	$title = $myts->makeTboxData4Save($title);
	
	if ($title == "") { $title = "! ! ? ! !";}
	
	$db->query("insert into ".$db->prefix("ann_categories")." values (NULL, '$cid', '$title', '$img', '$ordre', '$affprix')");
	
redirect_header("map.php",1,_CLA_CATADD);
exit();
}
#  function AnoncesDelCat
#####################################################
function AnoncesDelCat($cid, $ok=0) {
    global $db, $bcoosConfig, $xoopsModule;
	
    if($ok==1) {
	    $db->query("delete from ".$db->prefix("ann_categories")." where cid=$cid");
		$db->query("delete from ".$db->prefix("ann_categories")." where pid=$cid");
	    $db->query("delete from ".$db->prefix("ann_annonces")." where cid=$cid");
	
redirect_header("map.php",1,_CLA_CATDEL);
exit();   
    } else {
	
xoops_cp_header();
	OpenTable();
	echo "<br><center><b>"._CLA_SURDELCAT."</b><br><br>";
	echo "[ <a href=\"gest-cat.php?op=AnoncesDelCat&cid=$cid&ok=1\">"._YES."</a> | <a href=\"map.php\">"._NO."</a> ]<br><br>";
	CloseTable();
xoops_cp_footer();
		    }	
}
switch ($op) {
    case "AnnoncesNewCat":
    AnnoncesNewCat($cid);
    break;
    case "AnnoncesAddCat":
    AnnoncesAddCat($title, $cid, $img, $ordre, $affprix);
    break;
    case "AnoncesDelCat":
    AnoncesDelCat($cid, $ok);
    break;
    case "AnnoncesModCat":
    AnnoncesModCat($cid);
    break;
    case "AnnoncesModCatS":
    AnnoncesModCatS($cidd, $cid, $img, $title, $ordre, $affprix);
    break;
    default:
    Index();
    break;
}
?>
