<?PHP
// $Id: action.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("admin_header.php");


//***********************************************
function Delete($id) {

global $db, $HTTP_POST_VARS, $HTTP_GET_VARS;
$id = !empty($HTTP_POST_VARS['id']) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];

	mysql_query("DELETE FROM ".$db->prefix("ecal")." WHERE id = '$id'");
	redirect_header("index.php",1,_OK_DEL);
}

//***********************************************


function DeleteS() {

global $db, $HTTP_POST_VARS, $HTTP_GET_VARS;
$id = !empty($HTTP_POST_VARS['id']) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];

		$status = 0;
		$size = sizeof($id);
        	for ( $i=0;$i<$size;$i++ ) {
			$sql = "DELETE FROM ".$db->prefix("ecal")." WHERE id=".$id[$i]."";
        		if ( !$db->queryF($sql) ) {
				exit();
        		} else {
				$status = 1;
			}
		}

		if ( $status ) {
	redirect_header("index.php",1,_OK_DEL);
			exit();
		}
}

//*****************************************************
function Valid() {

global $db, $myts, $xoopsUser, $xoopsConfig, $HTTP_POST_VARS;

$id			 = intval($HTTP_POST_VARS['id']);
$cid		 = intval($HTTP_POST_VARS['cid']);
$username 	 = $HTTP_POST_VARS['username'];
$umail 		 = $HTTP_POST_VARS['umail'];
$subject	 = $myts->makeTboxData4Save($HTTP_POST_VARS['subject']);
$description = $myts->makeTboxData4Save($HTTP_POST_VARS['description1']);
$url 		 = $HTTP_POST_VARS['url'];
$valid		 = $HTTP_POST_VARS['valid'];
$flayer		 = $HTTP_POST_VARS['flayer'];
$privat		 = intval($HTTP_POST_VARS['privat']);
$locationid	 = intval($HTTP_POST_VARS['locationid']);

$heure		 = $HTTP_POST_VARS['heure'];
$minute		 = $HTTP_POST_VARS['minute'];
$heureend	 = $HTTP_POST_VARS['heureend'];
$minuteend	 = $HTTP_POST_VARS['minuteend'];
$month		 = $HTTP_POST_VARS['month'];
$year		 = $HTTP_POST_VARS['year'];
$day		 = $HTTP_POST_VARS['day'];
$high		 = $HTTP_POST_VARS['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 != $xoopsConfig['anonymous']) {
	$query = $db->query("SELECT email  FROM ".$db->prefix("users")." WHERE uname = '$username'");
	list($email) = $db->fetch_row($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." ".$meta['title']."";

	$from = $xoopsConfig['adminmail'];

	mail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion());
}
redirect_header("index.php",1,_OK_UPDATE);
}

//********************************************************
function ModifEvent() {

global $db, $myts, $xoopsUser, $HTTP_POST_VARS;

$id			 = intval($HTTP_POST_VARS['id']);
$cid		 = intval($HTTP_POST_VARS['cid']);
$username 	 = $HTTP_POST_VARS['username'];
$umail 		 = $HTTP_POST_VARS['umail'];
$subject	 = $myts->makeTboxData4Save($HTTP_POST_VARS['subject']);
$description = $myts->makeTboxData4Save($HTTP_POST_VARS['description1']);
$url 		 = $HTTP_POST_VARS['url'];
$valid		 = $HTTP_POST_VARS['valid'];
$flayer		 = $HTTP_POST_VARS['flayer'];
$privat		 = intval($HTTP_POST_VARS['privat']);
$locationid	 = intval($HTTP_POST_VARS['locationid']);

$heure		 = $HTTP_POST_VARS['heure'];
$minute		 = $HTTP_POST_VARS['minute'];
$heureend	 = $HTTP_POST_VARS['heureend'];
$minuteend	 = $HTTP_POST_VARS['minuteend'];
$month		 = $HTTP_POST_VARS['month'];
$year		 = $HTTP_POST_VARS['year'];
$day		 = $HTTP_POST_VARS['day'];
$high		 = intval($HTTP_POST_VARS['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, $HTTP_POST_VARS;
$day = $HTTP_POST_VARS['day'];
$month = $HTTP_POST_VARS['month'];
$year = $HTTP_POST_VARS['year'];
$date = $year."-".$month."-".$day." 00:00:00";

$query=$db->query("SELECT id FROM ".$db->prefix("ecal")." WHERE stamp <= '$date'");
$tid = $db->fetch_array($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($HTTP_POST_VARS['pa']) ? $HTTP_POST_VARS['pa'] : $HTTP_GET_VARS['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;
}
?>

