<?php
// $Id: blockconf.php,v 1.1 2004/07/11 10:27:50 Farsus 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->fetch_array($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->fetch_row($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->fetch_row($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 $HTTP_POST_VARS, $db, $xoopsUser;

$cid = $HTTP_POST_VARS['cid'];
$lid = $HTTP_POST_VARS['lid'];
$bllimit = $HTTP_POST_VARS['bllimit'];
$neu = $HTTP_POST_VARS['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($HTTP_POST_VARS['op']) ? $HTTP_POST_VARS['op'] : $HTTP_GET_VARS['op'];
switch($op) {

    case "edit":
		edit();
	break;

    case "save":
		save();
	break;
	
	default:
		redirect_header("index.php",1,_NO_AUTHORIZ);
	break;
}
?>