<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.6 www.exoops.info 2006/03 
// $Id: addlocation.php,v 1.5 2004/02/13 19:51:05 nobse 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 $_POST, $myts, $db;
        $loc_store = new CalLocation();
        $loc_store->setVar("cid", intval($_POST['cid']));
        $loc_store->setVar("location", $myts->makeTboxData4Save($_POST['location']));
        $loc_store->setVar("beschreibung", $myts->makeTboxData4Save($_POST['beschreibung']));
        $loc_store->setVar("ort", $myts->makeTboxData4Save($_POST['ort']));
        $loc_store->setVar("plz", $myts->makeTboxData4Save($_POST['plz']));
        $loc_store->setVar("strasse", $myts->makeTboxData4Save($_POST['strasse']));
        $loc_store->setVar("tel", $myts->makeTboxData4Save($_POST['tel']));
        $loc_store->setVar("email", $myts->makeTboxData4Save($_POST['email']));
        $loc_store->setVar("url", $myts->makeTboxData4Save($_POST['url']));
        $loc_store->setVar("valid", $myts->makeTboxData4Save($_POST['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 $_POST, $_GET, $mytree, $db, $myts, $xoopsUser, $ret,$bcoosConfig;
    
        $lid = !empty($_POST['lid']) ? $_POST['lid'] : $_GET['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='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."newred.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 $_POST, $_GET, $myts, $db;
        $loc_store = new CalLocation($_POST['lid']);
        $loc_store->setVar("cid", intval($_POST['cid']));
        $loc_store->setVar("location", $myts->makeTboxData4Save($_POST['location']));
        $loc_store->setVar("beschreibung", $myts->makeTboxData4Save($_POST['beschreibung']));
        $loc_store->setVar("ort", $myts->makeTboxData4Save($_POST['ort']));
        $loc_store->setVar("plz", $myts->makeTboxData4Save($_POST['plz']));
        $loc_store->setVar("strasse", $myts->makeTboxData4Save($_POST['strasse']));
        $loc_store->setVar("tel", $myts->makeTboxData4Save($_POST['tel']));
        $loc_store->setVar("email", $myts->makeTboxData4Save($_POST['email']));
        $loc_store->setVar("url", $myts->makeTboxData4Save($_POST['url']));
        $loc_store->setVar("valid", $myts->makeTboxData4Save($_POST['valid']));
        $result = $loc_store->store();
        if (!$result){
            xoops_cp_header();
            OpenTable();
            echo "konnte nicht in Location DB Schreiben";
            CloseTable();
            xoops_cp_footer();
        }else{
            if ($_POST['ret'] == 1){$retour = "index.php";}else{$retour = "addlocation.php";}
            redirect_header($retour, 1, _CAL_NEWLOCEDIT);
            exit();
        }
    }
//---------------------------------------------------------------------------------------//
    function dellocation() {
        global $_POST, $db, $ret, $lid;
        $sql = "SELECT COUNT(*) FROM ".$db->prefix("ecal")." where locationid = ".$lid."";
        list($count_loc_event) = $db->fetchRow($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($_POST['op']) ? $_POST['op'] : $_GET['op'];
switch ($op) {
case "addsave":
	addsave();
	break;
case "dellocation":
	dellocation();
	break;
case "editlocation":
	editlocation();
	break;
case "editsave":
	editsave();
	break;
default:
	addlocation();
	break;
}
?>