<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
//
// Revised: 10/11/2011	ELL
// Fixed bug of not being able to de-activate event.
// Revised: 2/10/2012	ELL
// Added table prefix handling.
// Revised: 7/3/2012	ELL
// Added user/group assigned events.
// Revised: 4/24/2014	ELL
// Added ability to set target for event URL.


	include ("check_session.php");
	
	$ID = $_REQUEST['ID'];
	$Description = $_REQUEST['Description'];
	$EventDate = $_REQUEST['EventDate'];
	$StartTime = $_REQUEST['StartTime'];
	$EndTime = $_REQUEST['EndTime'];

	$URL = $_REQUEST['URL'];
	$target = $_REQUEST['target'];
	$Active= $_REQUEST['Active'];
	$user_table = $_REQUEST['user_table'];
	$UserID= $_REQUEST['UserID'];
	$AccessLevel= $_REQUEST['AccessLevel'];
			
	$Description=addslashes($Description);
	$EventDate=addslashes($EventDate);
	$StartTime=addslashes($StartTime);
	$EndTime=addslashes($EndTime);
	$URL=addslashes($URL);
	
	$EventDateSort = $EventDate;
	$EventDateArr = explode("-", $EventDate);
	$EventDate = $EventDateArr[1] . "/" . $EventDateArr[2] . "/" . $EventDateArr[0];

	
	if ($ID == -1)
		$query = "INSERT INTO " . BWB_TABLE_PREFIX . "schedule SET Description = '" . $Description . "', EventDate = '" . $EventDate . "', StartTime = '" . $StartTime . "', EndTime = '" . $EndTime . "', URL = '" . $URL . "', `target` = '" . $target . "', EventDateSort = '" . $EventDateSort . "', Active = " . $Active . ", user_table = '" . $user_table . "', UserID = '" . $UserID . "', AccessLevel = '" . $AccessLevel . "'";
	else
		$query = "UPDATE " . BWB_TABLE_PREFIX . "schedule SET Description = '" . $Description . "', EventDate = '" . $EventDate . "', StartTime = '" . $StartTime . "', EndTime = '" . $EndTime . "', URL = '" . $URL ."', `target` = '" . $target . "', EventDateSort = '" . $EventDateSort . "', Active = " . $Active . ", user_table = '" . $user_table . "', UserID = '" . $UserID . "', AccessLevel = '" . $AccessLevel . "' WHERE ID = " . $ID;

	$cnt = $bwb_dbh->exec($query);
	
	if ($ID == -1)
	{
		$lastID = $bwb_dbh->lastInsertId();
		print "Event <b>$Description</b> has been added. [" . $lastID . "]";
	}
	else
		print "Event <b>$Description</b> has been updated.";
//	echo $query;
	
?>
