<?php
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.4 www.exoops.info 2006/03 
// $Id: blockconf.php,v 1.3 2004/02/13 19:51:03 nobse Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Nobse
// Author Website : http://www.e-xoops.de
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include("header.php");
include(XOOPS_ROOT_PATH."/header.php");
function edit() {
include_once(XOOPS_ROOT_PATH."/class/xoopsform/themeform.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formtext.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formselect.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formhidden.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formbutton.php");
global $db, $xoopsUser;
$bllimit = 5;
$result=$db->query("SELECT locationid, catid, bllimit FROM ".$db->prefix("ecal_userblock")." WHERE uid=".$xoopsUser->uid()."");
$myrow = $db->fetchArray($result);
if ($myrow) {
	$lidu = $myrow['locationid'];
	$cidu = $myrow['catid'];
	$bllimit = $myrow['bllimit'];
} else {
	$neu = 1;
}
$form = new XoopsThemeForm(_CAL_BLOCKCONFIG, "loc_mod", "blockconf.php");
$result=$db->query("SELECT location, lid FROM ".$db->prefix("ecal_location")." ORDER BY location ASC");
while(list($location, $lid) = $db->fetchRow($result)){
	$loc[$lid] = $location;
} 
$loc_select = new XoopsFormSelect(_CAL_USERLOC, "lid", $lidu);
$loc_select->addOptionArray($loc);
$form->addElement($loc_select);
$result=$db->query("SELECT title, cid FROM ".$db->prefix("ecal_cat")." ORDER BY title ASC");
while(list($title, $cid) = $db->fetchRow($result)){
	$cat[$cid] = $title;
}
$cat_select = new XoopsFormSelect(_CAL_USERCAT, "cid", $cidu);
$cat_select->addOptionArray($cat);
$form->addElement($cat_select);
$bllimit_text = new XoopsFormText(_CAL_BLLIMIT, "bllimit", 5, 2, $bllimit);
$form->addElement($bllimit_text);
$op_hidden = new XoopsFormHidden("op", "save");
$form->addElement($op_hidden);
$neu_hidden = new XoopsFormHidden("neu", $neu);
$form->addElement($neu_hidden);
$submit_button = new XoopsFormButton("", "button", _SAVE, "submit");
$form->addElement($submit_button);		
OpenTable();
$form->display();
CloseTable();
include(XOOPS_ROOT_PATH."/footer.php");
}
//**************************************************************
function save() {
global $_POST, $db, $xoopsUser;
$cid = $_POST['cid'];
$lid = $_POST['lid'];
$bllimit = $_POST['bllimit'];
$neu = $_POST['neu'];
if ($neu == 1) {
    $db->query("INSERT INTO ".$db->prefix('ecal_userblock')." SET uid=".$xoopsUser->uid()." , locationid=$lid, catid=$cid, bllimit=$bllimit");
} else {
	$db->query("UPDATE ".$db->prefix("ecal_userblock")." SET locationid=$lid, catid=$cid, bllimit=$bllimit WHERE uid=".$xoopsUser->uid()."");
}
redirect_header("index.php",1,_MSG4);
}
$op = !empty($_POST['op']) ? $_POST['op'] : $_GET['op'];
switch($op) {
    case "edit":
		edit();
	break;
    case "save":
		save();
	break;
	
	default:
		redirect_header("index.php",1,_NO_AUTHORIZ);
	break;
}
?>