<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v2.0 www.exoops.info 2006/03 
// $Id: action.php,v 1.9 2004/01/22 10:34:00 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("admin_header.php");
//***********************************************
function Delete($id) {
global $db, $_POST, $_GET;
$id = !empty($_POST['id']) ? $_POST['id'] : $_GET['id'];
	mysql_query("DELETE FROM ".$db->prefix("ecal")." WHERE id = '$id'");
	redirect_header("index.php",1,_OK_DEL);
}
//***********************************************
function DeleteS() {
global $db, $_POST, $_GET;
$id = !empty($_POST['id']) ? $_POST['id'] : $_GET['id'];
		$status = 0;
		$size = sizeof($id);
        	for ( $i=0;$i<$size;$i++ ) {
			$sql = "DELETE FROM ".$db->prefix("ecal")." WHERE id=".$id[$i]."";
        		if ( !$db->query($sql) ) {
				exit();
        		} else {
				$status = 1;
			}
		}
		if ( $status ) {
	redirect_header("index.php",1,_OK_DEL);
			exit();
		}
}
//*****************************************************
function Valid() {
global $db, $myts, $xoopsUser, $bcoosConfig, $_POST;
$id			 = intval($_POST['id']);
$cid		 = intval($_POST['cid']);
$username 	 = $_POST['username'];
$umail 		 = $_POST['umail'];
$subject	 = $myts->makeTboxData4Save($_POST['subject']);
$description = $myts->makeTboxData4Save($_POST['description1']);
$url 		 = $_POST['url'];
$valid		 = $_POST['valid'];
$flayer		 = $_POST['flayer'];
$privat		 = intval($_POST['privat']);
$locationid	 = intval($_POST['locationid']);
$heure		 = $_POST['heure'];
$minute		 = $_POST['minute'];
$heureend	 = $_POST['heureend'];
$minuteend	 = $_POST['minuteend'];
$month		 = $_POST['month'];
$year		 = $_POST['year'];
$day		 = $_POST['day'];
$high		 = $_POST['high'];
$eventend = "$heureend:$minuteend";
$time = "$heure:$minute:00";
$db->query("UPDATE ".$db->prefix("ecal")." SET cid=$cid, username = '$username' , umail='$umail',
	 stamp = '$year-$month-$day $time' , eventend='$eventend', subject = '$subject', description = '$description',
	 url = '$url', valid = '$valid', flayer = '$flayer', privat = $privat, locationid = $locationid, high=$high WHERE id=$id");
if ($username != $bcoosConfig['anonymous']) {
	$query = $db->query("SELECT email  FROM ".$db->prefix("users")." WHERE uname = '$username'");
	list($email) = $db->fetchRow($query);
	$subject = ""._CAL_ANNACCEPT."";
	$message = ""._CAL_HELLO." $username,\n\n "._CAL_ANNACCEPT." :\n\n$description\n\n\n"._CAL_CONSULTTO." ".XOOPS_URL."/modules/ecal/\n\n "._CAL_THANK."\n\n"._CAL_TEAMOF." ".$bcoosConfig['title']."";
	$from = $bcoosConfig['adminmail'];
	mail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());
}
redirect_header("index.php",1,_OK_UPDATE);
}
//********************************************************
function ModifEvent() {
global $db, $myts, $xoopsUser, $_POST;
$id			 = intval($_POST['id']);
$cid		 = intval($_POST['cid']);
$username 	 = $_POST['username'];
$umail 		 = $_POST['umail'];
$subject	 = $myts->makeTboxData4Save($_POST['subject']);
$description = $myts->makeTboxData4Save($_POST['description1']);
$url 		 = $_POST['url'];
$valid		 = $_POST['valid'];
$flayer		 = $_POST['flayer'];
$privat		 = intval($_POST['privat']);
$locationid	 = intval($_POST['locationid']);
$heure		 = $_POST['heure'];
$minute		 = $_POST['minute'];
$heureend	 = $_POST['heureend'];
$minuteend	 = $_POST['minuteend'];
$month		 = $_POST['month'];
$year		 = $_POST['year'];
$day		 = $_POST['day'];
$high		 = intval($_POST['high']);
if (!$id) {
	redirect_header("index.php",1,_ERRORMSG1);
break;
}
$eventend = "$heureend:$minuteend";
$time = "$heure:$minute:00";
$db->query("UPDATE ".$db->prefix("ecal")." SET cid=$cid, username = '$username' , umail='$umail',
	 stamp = '$year-$month-$day $time' , eventend='$eventend', subject = '$subject', description = '$description',
	 url = '$url', valid = '$valid', flayer = '$flayer', privat = $privat, locationid = $locationid, high=$high WHERE id=$id");
redirect_header("index.php",1,_ERRORMSG5);
}
//*********************************
function eventdel() {
global $db, $_POST;
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$date = $year."-".$month."-".$day." 00:00:00";
$query=$db->query("SELECT id FROM ".$db->prefix("ecal")." WHERE stamp <= '$date'");
$tid = $db->fetchArray($query);
mysql_query("DELETE FROM ".$db->prefix("ecal")." WHERE stamp <= '$date'");
$size = sizeof($tid);
for ( $i=0;$i<$size;$i++ ) {
	$sql = "DELETE FROM ".$db->prefix("ecal_teiln")." WHERE tid=".$tid[$i]."";
}
	redirect_header("index.php",1,_OK_DEL);
}
//********************************************************
$pa = !empty($_POST['pa']) ? $_POST['pa'] : $_GET['pa'];
switch($pa) {
    case "ModifEvent":
		ModifEvent();
	break;
    case "Valid":
		Valid();
	break;
    case "Delete":
		Delete();
	break;
    case "DeleteS":
		DeleteS();
	break;
	
	case "eventdel":
		eventdel();
	break;
	default:
		redirect_header("index.php",1,_NO_AUTHORIZ);
	break;
}
?>
