<?php
// $Id: addlocation.php,v 1.1 2004/07/11 10:27:51 Farsus Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Nobse, bama
// Author Website : http://www.e-xoops.de, http://service.bama-webdesign.de
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include_once("admin_header.php");
include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsform/formdhtmltextarea.php");
$mytree = new XoopsTree($db->prefix('ecal_cat'), "cid", "pid");

//bama
include("../cache/config.php");
if (!defined("ecal_LOCATION_INCLUDED")) {include_once(XOOPS_ROOT_PATH."/modules/ecal/class/location.php");}
//---------------------------------------------------------------------------------------//
    function addlocation() {
        global $mytree, $locat_yn, $xoopsUser;    
        xoops_cp_header();
        OpenTable();
        echo "<h5><a href='index.php'>"._MAIN."</a>: "._CAL_INDEXLOCATION."</h5>";
        if (intval($locat_yn) == 0){echo "<b><font color='red'>"._CAL_WARNING2."</font> "._CAL_LOCYESNOWARN."</b><br><br>";}
        CloseTable();
        echo "<br />";
        if (CalLocation::countAllLocations() > 0){            
            OpenTable();        
            include_once(XOOPS_ROOT_PATH."/class/xoopsform/themeform.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");            
            $form = new XoopsThemeForm(_CAL_EDITLOCATION, "loc_mod", "addlocation.php");
            $loc_select = new XoopsFormSelect(_CAL_LOCATION, "lid");
            $loc_select->addOptionArray(CalLocation::getAllLocationsList('', "location ASC"));
            $form->addElement($loc_select);	
            $op_hidden = new XoopsFormHidden("op", "editlocation");
            $form->addElement($op_hidden);
            $submit_button = new XoopsFormButton("", "button", _MODIFY, "submit");            
            $form->addElement($submit_button);	
            $form->display();            
            CloseTable();
            echo "<br />";
        }    
        
        OpenTable();
        $form_titel = _CAL_ADDLOCATION;
        $form_action = "addlocation.php";
        $ophidden = "addsave";
        $sub_button_text = _ADD;
        include_once(XOOPS_ROOT_PATH."/modules/ecal/include/form_location.php");
        CloseTable();
        xoops_cp_footer();
    }

//---------------------------------------------------------------------------------------//
    function addsave() {
        global $HTTP_POST_VARS, $myts, $db;

        $loc_store = new CalLocation();
        $loc_store->setVar("cid", intval($HTTP_POST_VARS['cid']));
        $loc_store->setVar("location", $myts->makeTboxData4Save($HTTP_POST_VARS['location']));
        $loc_store->setVar("beschreibung", $myts->makeTboxData4Save($HTTP_POST_VARS['beschreibung']));
        $loc_store->setVar("ort", $myts->makeTboxData4Save($HTTP_POST_VARS['ort']));
        $loc_store->setVar("plz", $myts->makeTboxData4Save($HTTP_POST_VARS['plz']));
        $loc_store->setVar("strasse", $myts->makeTboxData4Save($HTTP_POST_VARS['strasse']));
        $loc_store->setVar("tel", $myts->makeTboxData4Save($HTTP_POST_VARS['tel']));
        $loc_store->setVar("email", $myts->makeTboxData4Save($HTTP_POST_VARS['email']));
        $loc_store->setVar("url", $myts->makeTboxData4Save($HTTP_POST_VARS['url']));
        $loc_store->setVar("valid", $myts->makeTboxData4Save($HTTP_POST_VARS['valid']));
        $result = $loc_store->store();
        if (!$result){
            xoops_cp_header();
            OpenTable();
            echo "konnte nicht in Location DB Schreiben";
            CloseTable();
            xoops_cp_footer();
            
        }else{
            redirect_header("addlocation.php", 1, _CAL_NEWLOCADDED);
            exit();
        }
    }


//---------------------------------------------------------------------------------------//
    function editlocation() {
        global $HTTP_POST_VARS, $HTTP_GET_VARS, $mytree, $db, $myts, $xoopsUser, $ret;
    
        $lid = !empty($HTTP_POST_VARS['lid']) ? $HTTP_POST_VARS['lid'] : $HTTP_GET_VARS['lid'];
        xoops_cp_header();
        OpenTable();
        echo "<h5><a href='index.php'>"._MAIN."</a>: "._CAL_INDEXLOCATION."</h5>";
        CloseTable();
        echo "<br />";        
        OpenTable();
        if ($lid > 0){
            $loc_dat = new CalLocation($lid);
            $cid = $loc_dat->cid();
            $location = $myts->makeTboxData4Edit($loc_dat->location());
            $beschreibung = $myts->makeTboxData4Edit($loc_dat->beschreibung());
            $ort = $myts->makeTboxData4Edit($loc_dat->ort());
            $plz = $myts->makeTboxData4Edit($loc_dat->plz());
            $strasse = $myts->makeTboxData4Edit($loc_dat->strasse());
            $tel  = $myts->makeTboxData4Edit($loc_dat->tel());
            $email = $myts->makeTboxData4Edit($loc_dat->email());
            $url = $myts->makeTboxData4Edit($loc_dat->url());
            $valid = $loc_dat->valid();
            $form_titel = _CAL_EDITLOCATION;
            if ($valid == 0){
                $form_titel .= "&nbsp;&nbsp;&nbsp;<img src='../images/new.gif' border='0' width='25' height='12'>";
                $sub_button_text = _VALID;
            }else{
                $sub_button_text = _SAVE;
            }
            $form_action = "addlocation.php";
            $ophidden = "editsave";
            
            include_once(XOOPS_ROOT_PATH."/modules/ecal/include/form_location.php");    
        }else{
            echo "keine Location ausgewählt !";
        }
        CloseTable();
        xoops_cp_footer();
    }

//---------------------------------------------------------------------------------------//
    function editsave() {
        global $HTTP_POST_VARS, $HTTP_GET_VARS, $myts, $db;

        $loc_store = new CalLocation($HTTP_POST_VARS['lid']);
        $loc_store->setVar("cid", intval($HTTP_POST_VARS['cid']));
        $loc_store->setVar("location", $myts->makeTboxData4Save($HTTP_POST_VARS['location']));
        $loc_store->setVar("beschreibung", $myts->makeTboxData4Save($HTTP_POST_VARS['beschreibung']));
        $loc_store->setVar("ort", $myts->makeTboxData4Save($HTTP_POST_VARS['ort']));
        $loc_store->setVar("plz", $myts->makeTboxData4Save($HTTP_POST_VARS['plz']));
        $loc_store->setVar("strasse", $myts->makeTboxData4Save($HTTP_POST_VARS['strasse']));
        $loc_store->setVar("tel", $myts->makeTboxData4Save($HTTP_POST_VARS['tel']));
        $loc_store->setVar("email", $myts->makeTboxData4Save($HTTP_POST_VARS['email']));
        $loc_store->setVar("url", $myts->makeTboxData4Save($HTTP_POST_VARS['url']));
        $loc_store->setVar("valid", $myts->makeTboxData4Save($HTTP_POST_VARS['valid']));
        $result = $loc_store->store();
        if (!$result){
            xoops_cp_header();
            OpenTable();
            echo "konnte nicht in Location DB Schreiben";
            CloseTable();
            xoops_cp_footer();
        }else{
            if ($HTTP_POST_VARS['ret'] == 1){$retour = "index.php";}else{$retour = "addlocation.php";}
            redirect_header($retour, 1, _CAL_NEWLOCEDIT);
            exit();
        }
    }


//---------------------------------------------------------------------------------------//
    function dellocation() {
        global $HTTP_POST_VARS, $db, $ret, $lid;
        $sql = "SELECT COUNT(*) FROM ".$db->prefix("ecal")." where locationid = ".$lid."";
        list($count_loc_event) = $db->fetch_row($db->query($sql));
        if ($ret == 1){$retour = "index.php";}else{$retour = "addlocation.php?op=editlocation&lid=".$lid."";}
        if ($count_loc_event > 0){
            xoops_cp_header();
            OpenTable();
            echo "<br><center><h5>".sprintf(_CAL_NODELLOC, $count_loc_event)."</h5>";
            echo "<form method='post' action='".$retour."'>";
            echo "<input type='submit' class='button' name='next' value='"._CAL_NEXT."'>";
            echo "</form>";
            echo "</center>";
            CloseTable();
            xoops_cp_footer();
        }else{
            $db->query("DELETE FROM ".$db->prefix('ecal_location')." WHERE lid = $lid");           
            redirect_header($retour, 1, _CAL_NEWLOCDELETED);
            exit();
        }
    }
//---------------------------------------------------------------------------------------//
$op = !empty($HTTP_POST_VARS['op']) ? $HTTP_POST_VARS['op'] : $HTTP_GET_VARS['op'];

switch ($op) {

case "addsave":
	addsave();
	break;

case "dellocation":
	dellocation();
	break;

case "editlocation":
	editlocation();
	break;

case "editsave":
	editsave();
	break;

default:
	addlocation();
	break;
}

?>