<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v3.1 www.exoops.info 2006/03
##################################################################################
# Friend Finder for e-xoops  Version 3.02 beta                                 #
#                                                                                #
# Script design  : PhpMeet  :   Copyright 2002 Jeremy Ross-webmaster@phprank.com #
# Created 15/01/02              Last Modified 15/01/02                           #
# Scripts Home              :   http://www.jrscripts.com                         #
#                                                                                #
# Xoops-RC2 French Version  :   jokerman@free.fr                                 #
# Web Home                     :   http://www.webetfric.com                      #
#                                                                                #
# Xoops-RC2 English Version :          Neon@neon.qldgamers.com                   #
# Web Home                  :   http://neon.qldgamers.com                        #
#                                                                                #
#                 Redesigned and new improvemends by                             #
#        eagle81 Manuel Caballero       Manuel@dancepartner.net                  #
#                    http://www.dancepartner.net                                 #
#                             2002-09-12                                         #
##################################################################################
include("admin_header.php");
include(XOOPS_ROOT_PATH"/modules/friendfinder/cache/config.php");
#  function Index
#####################################################
function Index() {
    global  $db, $bcoosConfig, $xoopsModule;
		echo "<br />\n";
		
		OpenTable();
	//	echo "<CENTER><A HREF=\"pref.php\">"._CLA_CONF."</A /></CENTER>";
		CloseTable();
   		echo "<br />\n";
// Add a new State
    OpenTable();
    echo "<form method=\"post\" action=\"select.php\">
		<b>"._CLA_ADDSTATE."</b><br><br>
		"._CLA_STATENAME." <input type=\"text\" class=\"text\" name=\"title\" size=\"30\" maxlength=\"100\">	<input type=\"hidden\" name=\"op\" value=\"AddNewState\">
		<input type=\"submit\" class=\"button\" value=\""._CLA_ADD."\">
		</form>";
    echo "<br>";
// Modify State
	list($numrows) = $db->fetchRow($db->query("SELECT COUNT(*) FROM ".$db->prefix("friendfinder_state").""));
    if ($numrows>0) {	
	echo "<form method=\"post\" action=\"select.php\">
	 <b>"._CLA_MODIFSTATE."</b></font><br><br>";
	$result = $db->query("select cid, title from ".$db->prefix("friendfinder_state")." order by title");
	echo ""._CLA_STATE." <select class='select' name=\"cat\">";
	while(list($cid, $title) = $db->fetchRow($result)) {
	    echo "<option value=\"$cid\">$title</option>";
	   	}
	echo "</select>"
	    ."<input type=\"hidden\" name=\"op\" value=\"ModState\"> <input type=\"submit\" class=\"button\" value=\""._CLA_MODIFSTATE."\">"
	    ."</form>";
	
    }
CloseTable();
	echo "<br>";
    // Add a new SEX
    OpenTable();
    echo "<form method=\"post\" action=\"select.php\">
		<b>"._CLA_ADDSEX."</b><br><br>
		"._CLA_SEXNAME." <input type=\"text\" class=\"text\" name=\"sextitle\" size=\"30\" maxlength=\"100\">	<input type=\"hidden\" name=\"op\" value=\"AddNewSex\">
		<input type=\"submit\" class=\"button\" value=\""._CLA_ADD."\">
		</form>";
    echo "<br>";
    // Modify SEX
	list($numrows) = $db->fetchRow($db->query("SELECT COUNT(*) FROM ".$db->prefix("friendfinder_sex").""));
    if ($numrows>0) {	
	echo "<form method=\"post\" action=\"select.php\">
	 <b>"._CLA_MODIFSEX."</b></font><br><br>";
	$result = $db->query("select sid, sextitle from ".$db->prefix("friendfinder_sex")." order by sextitle");
	echo ""._CLA_SEX." <select class=\"select\" name=\"catS\">";
	while(list($sid, $sextitle) = $db->fetchRow($result)) {
	    echo "<option value=\"$sid\">$sextitle</option>";
	   	}
	echo "</select>"
	    ."<input type=\"hidden\" name=\"op\" value=\"ModSex\"> <input type=\"submit\" class=\"button\" value=\""._CLA_MODIFSEX."\">"
	    ."</form>";
    }
    CloseTable();
	echo "<br>";
    
       // Add a new Category
    OpenTable();
    echo "<form method=\"post\" action=\"select.php\">
		<b>"._CLA_ADDCATEGORY."</b><br><br>
		"._CLA_CATEGORYNAME." <input type=\"text\" class=\"text\" name=\"cattitle\" size=\"30\" maxlength=\"100\">	<input type=\"hidden\" name=\"op\" value=\"AddNewCat\">
		<input type=\"submit\" class=\"button\" value=\""._CLA_ADD."\">
		</form>";
    echo "<br>";
    // Modify Category
	list($numrows) = $db->fetchRow($db->query("SELECT COUNT(*) FROM ".$db->prefix("friendfinder_category").""));
    if ($numrows>0) {	
	echo "<form method=\"post\" action=\"select.php\">
	 <b>"._CLA_MODIFCAT."</b></font><br><br>";
	$result = $db->query("select catid, cattitle from ".$db->prefix("friendfinder_category")." order by cattitle");
	echo ""._CATEGORY." <select class=\"select\" name=\"catC\">";
	while(list($catid, $cattitle) = $db->fetchRow($result)) {
	    echo "<option value=\"$catid\">$cattitle</option>";
	   	}
	echo "</select>"
	    ."<input type=\"hidden\" name=\"op\" value=\"ModCat\"> <input type=\"submit\" class=\"button\" value=\""._CLA_MODIFCAT."\">"
	    ."</form>";
	
    }
    CloseTable();
	echo "<br>";
    include("admin_footer.php");
}
#  function ModState
#####################################################
function ModState($cat) {
    global $db, $bcoosConfig, $xoopsModule;
	
  	echo "<br />\n";
    OpenTable();
    $cat = explode("-", $cat);
    if ($cat[1]==0) {
	echo "<b>"._CLA_MODIFSTATE."</b><br><br>";
	$result = $db->query("select title, cdescription from ".$db->prefix("friendfinder_state")." where cid=$cat[0]");
	list($title,$cdescription) = $db->fetchRow($result);
	
	$cdescription = stripslashes($cdescription);
	
	echo "<form action=\"select.php\" method=\"post\">"
	    .""._CLA_STATE." : <input type=\"text\" class=\"text\" name=\"title\" value=\"$title\" size=\"51\" maxlength=\"50\"><br>"
	    ."<input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"ModStateSave\">"
	    ."<table border=\"0\"><tr><td>"
	    ."<input type=\"submit\" class=\"button\" value=\""._CLA_SAVMOD."\"></form></td><td>"
	    ."<form action=\"select.php\" method=\"post\">"
	    	    ."<input type=\"hidden\" name=\"cid\" value=\"$cat[0]\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"DelState\">"
	    ."<input type=\"submit\" class=\"button\" value=\""._DELETE."\"></form></td></tr></table>";
    }
    CloseTable();
    include("admin_footer.php");
}
#  function ModStateSave
#####################################################
function ModStateSave($cid, $title) {
    global $db,$bcoosConfig;
	
    if ($sub==0) {
	$db->query("update ".$db->prefix("friendfinder_state")." set title='$title' where cid=$cid");
    } else {
	}
	
redirect_header("select.php",1,_CLA_CATSMOD);
exit();
}
#  function DelState
#####################################################
function DelState($cid) {
    global $db, $bcoosConfig, $xoopsModule;
	
 	    $db->query("delete from ".$db->prefix("friendfinder_state")." where cid=$cid");
	
redirect_header("select.php",1,_CLA_CATDEL);
exit();
    xoops_cp_header();
		echo "<br />\n";
	OpenTable();
	echo "<br><center><b>"._CLA_SURDELCAT."</b><br><br>";
	echo "[ <a href=\"select.php?op=DelState&cid=$cid\">"._YES."</a> | <a href=\"select.php\">"._NO."</a> ]<br><br>";
	CloseTable();
    include("admin_footer.php");
}
#  function AddNewState
#####################################################
function AddNewState($title, $cdescription) {
    global $db, $bcoosConfig;
	
	list($numrows) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("friendfinder_state")." where title='$title'"));
    if ($numrows>0) {
	xoops_cp_header();
	OpenTable();
	echo "<br><center><b>"._CLA_ERRORCAT." $title "._CLA_EXIST."</b><br><br>";
	echo "<form method=\"post\" action=\"select.php\">
		<b>"._ADDMAINCATEGORY."</b><br><br>
		"._CLA_CATNAME." <input type=\"text\" class=\"text\" name=\"title\" size=\"30\" maxlength=\"100\">	<input type=\"hidden\" name=\"op\" value=\"AddNewState\">
		<input type=\"submit\" class=\"button\" value=\""._CLA_ADD."\">
		</form>";
	CloseTable();
    include("admin_footer.php");
    } else {
	$db->query("insert into ".$db->prefix("friendfinder_state")." values (NULL, '$title', '$cdescription')");
	
redirect_header("select.php",1,_CLA_CATADD);
exit();
    }
}
#  function AddNewSex
#####################################################
function AddNewSex($sextitle, $sexdescription) {
    global $db, $bcoosConfig;
	
	list($numrows) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("friendfinder_sex")." where sextitle='$sextitle'"));
    if ($numrows>0) {
	xoops_cp_header();
	OpenTable();
	echo "<br><center><b>"._CLA_ERRORCAT." $sextitle "._CLA_EXIST."</b><br><br>";
	echo "<form method=\"post\" action=\"select.php\">
		<b>"._ADDMAINCATEGORY."</b><br><br>
		"._CLA_CATNAME." <input type=\"text\" class=\"text\" name=\"sextitle\" size=\"30\" maxlength=\"100\">	<input type=\"hidden\" name=\"op\" value=\"AddNewSex\">
		<input type=\"submit\" class=\"button\" value=\""._CLA_ADD."\">
		</form>";
	CloseTable();
    include("admin_footer.php");
    } else {
	$db->query("insert into ".$db->prefix("friendfinder_sex")." values (NULL, '$sextitle', '$sexdescription')");
	
redirect_header("select.php",1,_CLA_CATADD);
exit();
    }
}
#  function AddNewCat
#####################################################
function AddNewCat($cattitle, $catdescription) {
    global $db, $bcoosConfig;
	
	list($numrows) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("friendfinder_category")." where cattitle='$cattitle'"));
    if ($numrows>0) {
	xoops_cp_header();
	OpenTable();
	echo "<br><center><b>"._CLA_ERRORCAT." $cattitle "._CLA_EXIST."</b><br><br>";
	echo "<form method=\"post\" action=\"select.php\">
		<b>"._ADDMAINCATEGORY."</b><br><br>
		"._CLA_CATNAME." <input type=\"text\" class=\"text\" name=\"cattitle\" size=\"30\" maxlength=\"100\">	<input type=\"hidden\" name=\"op\" value=\"AddNewCat\">
		<input type=\"submit\" class=\"select\" value=\""._CLA_ADD."\">
		</form>";
	CloseTable();
    include("admin_footer.php");
    } else {
	$db->query("insert into ".$db->prefix("friendfinder_category")." values (NULL, '$cattitle', '$catdescription')");
	
redirect_header("select.php",1,_CLA_CATADD);
exit();
    }
}
#  function ModSex
#####################################################
function ModSex($catS) {
    global $db, $bcoosConfig, $xoopsModule;
	
  	echo "<br />\n";
    OpenTable();
    $catS = explode("-", $catS);
    if ($catS[1]==0) {
	echo "<b>"._CLA_MODIFSEX."</b><br><br>";
	$result = $db->query("select sextitle, sexdescription from ".$db->prefix("friendfinder_sex")." where sid=$catS[0]");
	list($sextitle,$sexdescription) = $db->fetchRow($result);
	
	$sexdescription = stripslashes($sexdescription);
	
	echo "<form action=\"select.php\" method=\"post\">"
	    .""._CLA_SEXNAME." <input type=\"text\" class=\"text\" name=\"sextitle\" value=\"$sextitle\" size=\"51\" maxlength=\"50\"><br>"
	    ."<input type=\"hidden\" name=\"sid\" value=\"$catS[0]\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"ModSexSave\">"
	    ."<table border=\"0\"><tr><td>"
	    ."<input type=\"submit\" class=\"button\" value=\""._CLA_SAVMOD."\"></form></td><td>"
	    ."<form action=\"select.php\" method=\"post\">"
	    ."<input type=\"hidden\" name=\"sid\" value=\"$catS[0]\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"DelSex\">"
	    ."<input type=\"submit\" class=\"button\" value=\""._DELETE."\"></form></td></tr></table>";
    }
    CloseTable();
    include("admin_footer.php");
}
#  function ModCat
#####################################################
function ModCat($catC) {
    global $db, $bcoosConfig, $xoopsModule;
	
  	echo "<br />\n";
    OpenTable();
    $catC = explode("-", $catC);
    if ($catC[1]==0) {
	echo "<b>"._CLA_MODIFCATEGORY."</b><br><br>";
	$result = $db->query("select cattitle, catdescription from ".$db->prefix("friendfinder_category")." where catid=$catC[0]");
	list($cattitle,$catdescription) = $db->fetchRow($result);
	
	$catdescription = stripslashes($catdescription);
	
	echo "<form action=\"select.php\" method=\"post\">"
	    .""._CLA_MODIFCATEGORY." : <input type=\"text\" class=\"text\" name=\"cattitle\" value=\"$cattitle\" size=\"51\" maxlength=\"50\"><br>"
	    ."<input type=\"hidden\" name=\"catid\" value=\"$catC[0]\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"ModCatSave\">"
	    ."<table border=\"0\"><tr><td>"
	    ."<input type=\"submit\" class=\"button\" value=\""._CLA_SAVMOD."\"></form></td><td>"
	    ."<form action=\"select.php\" method=\"post\">"
	    ."<input type=\"hidden\" name=\"catid\" value=\"$catC[0]\">"
	    ."<input type=\"hidden\" name=\"op\" value=\"DelCat\">"
	    ."<input type=\"submit\" class=\"button\" value=\""._DELETE."\"></form></td></tr></table>";
    }
    CloseTable();
    include("admin_footer.php");
}
#  function ModSexSave
#####################################################
function ModSexSave($sid, $sextitle) {
    global $db,$bcoosConfig;
	
    if ($sub==0) {
	$db->query("update ".$db->prefix("friendfinder_sex")." set sextitle='$sextitle' where sid=$sid");
    } else {
	}
	
redirect_header("select.php",1,_CLA_CATSMOD);
exit();
}
#  function ModCatSave
#####################################################
function ModCatSave($catid, $cattitle) {
    global $db,$bcoosConfig;
	
    if ($sub==0) {
	$db->query("update ".$db->prefix("friendfinder_category")." set cattitle='$cattitle' where catid=$catid");
    } else {
	}
	
redirect_header("select.php",1,_CLA_CATSMOD);
exit();
}
#  function DelSex
#####################################################
function DelSex($sid) {
    global $db, $bcoosConfig, $xoopsModule;
	
 	    $db->query("delete from ".$db->prefix("friendfinder_sex")." where sid=$sid");
	
redirect_header("select.php",1,_CLA_CATDEL);
exit();
    xoops_cp_header();
		echo "<br />\n";
	OpenTable();
	echo "<br><center><b>"._CLA_SURDELCAT."</b><br><br>";
	echo "[ <a href=\"select.php?op=DelSex&sid=$sid\">"._YES."</a> | <a href=\"select.php\">"._NO."</a> ]<br><br>";
	CloseTable();
	
    include("admin_footer.php");
}
#  function DelCat
#####################################################
function DelCat($catid) {
    global $db, $bcoosConfig, $xoopsModule;
	
 	    $db->query("delete from ".$db->prefix("friendfinder_category")." where catid=$catid");
	
redirect_header("select.php",1,_CLA_CATDEL);
exit();
    xoops_cp_header();
		echo "<br />\n";
	OpenTable();
	echo "<br><center><b>"._CLA_SURDELCAT."</b><br><br>";
	echo "[ <a href=\"select.php?op=DelCat&catid=$catid\">"._YES."</a> | <a href=\"select.php\">"._NO."</a> ]<br><br>";
	CloseTable();
	
    include("admin_footer.php");
}
switch ($op) {
    case "AddNewState":
    AddNewState($title, $cdescription);
    break;
    
    case "AddNewSex":
    AddNewSex($sextitle, $sexdescription);
    break;
    
    case "AddNewCat":
    AddNewCat($cattitle, $catdescription);
    break;
    case "DelState":
    DelState($cid, $ok);
    break;
    case "DelSex":
    DelSex($sid, $ok);
    break;
    
    case "DelCat":
    DelCat($catid, $ok);
    break;
    
    case "ModState":
    ModState($cat);
    break;
    case "ModSex":
    ModSex($catS);
    break;
    
    case "ModCat":
    ModCat($catC);
    break;
    
    case "ModStateSave":
    ModStateSave($cid, $title, $cdescription);
    break;
    case "ModSexSave":
    ModSexSave($sid, $sextitle, $sexdescription);
    break;
    
    case "ModCatSave":
    ModCatSave($catid, $cattitle, $catdescription);
    break;
    default:
    Index();
    break;
}
?>
