Location: PHPKode > projects > O - OpenSource GroupWare > osgw/calendar/create_event.php
<?php
/**************************************************************************
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: create_event.php,v 1.2 2004/05/26 08:37:24 rthomp Exp $*/
include("./data.php");
$service['add_header'] = TRUE;
include("../config.inc.php");
//Define month first. The events class inherits Calendar which is declared in the month class file
require('classes/class.calendar.php');

$cal = new calendar('event', $_GET['d'], $_GET['m'], $_GET['y']);

echo $layout->page_header;
echo $cal->nav_buttons($_GET['v']);

$events = new events();

if(!isset($_GET['d']))
{
	$start_day = date('j');
	$start_month = date('n');
	$start_year = date('Y');
	$end_day = date('j');
	$end_month = date('n');
	$end_year = date('Y');
} else {
	$start_day = $_GET['d'];
	$start_month = $_GET['m'];
	$start_year = $_GET['y'];
	$end_day = $_GET['d'];
	$end_month = $_GET['m'];
	$end_year = $_GET['y'];
}

if(isset($_POST['create_event']))
{
	$start_day = $_POST['start_day'];
	$start_month = $_POST['start_month'];
	$start_year = $_POST['start_year'];
	$start_hour = $_POST['start_hour'];
	$start_min = $_POST['start_min'];

	$end_day = $_POST['end_day'];
	$end_month = $_POST['end_month'];
	$end_year = $_POST['end_year'];
	$end_hour = $_POST['end_hour'];
	$end_min = $_POST['end_min'];
	
	//Check validity of starting date and time
	if(!$start = $events->check_date($_POST['start_day'],	$_POST['start_month'], $_POST['start_year'],
			$_POST['start_hour'], $_POST['start_min']))
	{
		$error->get_message(10001, '%DATE%', strtolower($text['start_date']));
		
	
	}
	
	//Check validity of ending date/time
	if(!$end = $events->check_date($_POST['end_day'], $_POST['end_month'], $_POST['end_year'],
			$_POST['end_hour'],	$_POST['end_min']))
	{
			$error->get_message(10001, '%DATE%', strtolower($text['end_date']));
	}
	
	if($end < $start)
	{
		$error->get_message(10002);
	}
	//Set this to true because under certain circumstances it won't be evaluated and will end up FALSE causing
	//problems adding non-recurring events.
	$recure_end = TRUE;
	
	//If it a recurring event with a set end date then check to see if the ending date is valid. 
	//Otherwise ignore.
	if($_POST['recure_type'] != 0 && $_POST['recure_end'] == 1 && !$recure_end = $events->check_date($_POST['recure_end_day'], $_POST['recure_end_month'], $_POST['recure_end_year'], 0, 0))
	{
		$error->get_message(10001, '%DATE%', strtolower($text['recurrence']));
	}
		
	if($start && $end && $recure_end)
	{
		if($missing_fields = $events->verify_fields($_POST))
		{
			
		} else {
			$error->get_message(10003);
		}
	}
	
	//If there's no error create the event.
	if(is_null($error->error_id))
	{
		$id = $events->create_event($_POST);
	}
	
}

if($error->buffer)
{
	echo $error->display();	
}

	$event_start = $date->date_select('start_day', 'day', $start_day);
	$event_start .= $date->date_select('start_month', 'month', $start_month);
	$event_start .= $date->date_select('start_year', 'year', $start_year);
	$event_end =$date->date_select('end_day', 'day', $end_day);
	$event_end .= $date->date_select('end_month', 'month', $end_month);
	$event_end .= $date->date_select('end_year', 'year', $end_year);
	if(isset($_POST['start_hour']))
	{
	
		$start_hour = $_POST['start_hour'];
		$start_min = $_POST['start_min'];
		$end_hour = $_POST['end_hour'];
		$end_min = $_POST['end_min'];	
	} else {
		$start_hour = '12';
		$start_min = '00';
		$end_hour = '12';
		$end_min = '00';
	}

	$sql = "SELECT value FROM o_preferences WHERE user_id='". $user->user_id ."' AND preference='hours' AND service='cl'";
	$db->query($sql);
	$db->fetch_results();
	if($db->record['value'] == '12')
	{
		$start_md = $html->select_box('start_md', 'array', $date = array('am'=>'AM','pm'=>'PM'), $_POST['start_md']);
		$end_md = $html->select_box('end_md', 'array', $date = array('am'=>'AM','pm'=>'PM'), $_POST['end_md']);
	} else {
		$start_md = $lang->msgs['24_format'];
		$end_md = $lang->msgs['24_format'];
	}
	
	if(isset($_POST['all_day']))
	{
		$all_day_checked = " checked=\"checked\"";
	}
	
	$recurrence_type = $html->select_box('recure_type', 'value_count', explode(':', $lang->msgs['recur_type']), $_POST['recure_type']);

	$recure_end_date = $date->date_select('recure_end_day', 'day', $_POST['recure_end_day']);
	$recure_end_date .= $date->date_select('recure_end_month', 'month', $_POST['recure_end_month']);
	$recure_end_date .= $date->date_select('recure_end_year', 'year', $_POST['recure_end_year']);
	
	$after_occur = str_replace('%NUMBER_BOX%', 
	"<input type=\"text\" size=\"3\" name=\"recur_after\" value=\"{$_POST['recur_after']}\">", $lang->msgs['after_occur']);
	
	$checked  = " checked=\"checked\"";
	switch($_POST['recure_end'])
	{
		case 0:
			$checked_never = $checked;
		break;
		case 1:
			$checked_on = $checked;
		break;
		case 2:
			$checked_after = $checked;
		break;
	}
	
	switch($_POST['recure_monthly_type'])
	{
		case 0:
			$checked_monthly_0 = $checked;
		break;
		case 1:
			$checked_monthly_1 = $checked;
		break;
	}
	$i = 0;
	$weekdays = explode(':', $lang->msgs['long_weekdays']);
		
	while($i < 7)
	{
		$week_checkboxes .= "<input type=\"checkbox\" name=\"recure_weekday[$i]\" value=\"$i\"";
		
		//Because it's not created when first visiting the page we need
		//to stop it from looking in an array that doesn't exist yet.
		if(is_array($_POST['recure_weekday']))
		{
			if(in_array($i, $_POST['recure_weekday']))
			{
				$week_checkboxes .= $checked;
			}
		}

		$week_checkboxes .= ">\n";
		$week_checkboxes .= $weekdays[$i];
		$i++;
	}		
	
	if(isset($_POST['enable_sharing']))
	{
	
		$share_enabled = " checked=\"checked\"";
		$display = "display:block";
	} else {
		$display = "display:none";
	}
	echo $html->create_list(array("FORM_LINK"=>$_SERVER['PHP_SELF'],
				"SUBJECT_TEXT"=>$lang->msgs['subject'],
				"EVENT_SUBJECT"=>$_POST['event_subject'],
				"LOCATION_TEXT"=>$lang->msgs['location'],
				"EVENT_LOCATION"=>$_POST['location'],
				"CATEGORY_TEXT"=>$lang->msgs['category'],
				"EVENT_CATEGORY"=>$category->get_category_select($user->user_id, 'cl', 'create_event.php', 0),
				"DESCRIPTION_TEXT"=>$lang->msgs['description'],
				"EVENT_DESCRIPTION"=>$_POST['description'],
				
				"SHARING"=>$text['share'],
				"SHARE_ENABLED"=>$share_enabled,
				"DISPLAY"=>$display,
				"SHARE_SELECT"=>$share->share_select($user->user_id, $_POST['share_groups']),
				"USER_SELECT"=>$share->share_select_users($_POST['share_groups'], $_POST['share_users']),
				
				"START_TEXT"=>$lang->msgs['start'],
				"EVENT_START_DATE"=>$event_start,
				"DATE"=>$lang->msgs['date'],
				"TIME"=>$lang->msgs['time'],
				"START_HOUR"=>$start_hour,
				"START_MINUTES"=>$start_min,
				"START_MD"=>$start_md,
				"END_TEXT"=>$lang->msgs['end'],
				"EVENT_END_DATE"=>$event_end,
				"END_HOUR"=>$end_hour,
				"END_MINUTES"=>$end_min,
				"END_MD"=>$end_md,
				"ALL_DAY"=>$lang->msgs['all_day'],
				"ALL_DAY_CHECKED"=>$all_day_checked,
				"RECURRING_EVENT"=>$lang->msgs['recurring_event'],
				"RECURRENCE"=>$lang->msgs['recurrence'],
				"RECURRENCE_TYPE"=>$recurrence_type,
				"NEVER"=>$lang->msgs['never'],
				"ON"=>$lang->msgs['on'],
				"RECURE_END_DATE"=>$recure_end_date,
				"CHECKED_NEVER"=>$checked_never,
				"CHECKED_ON"=>$checked_on,
				"AFTER_OCCUR"=>$after_occur,
				"CHECKED_AFTER"=>$checked_after,
				"FREQUENCY"=>$lang->msgs['frequency'],
				"RECURRING_FREQUENCY"=>$_POST['recure_freq'],
				"WEEKLY_TEXT"=>$lang->msgs['weekly'],
				"ANNUALLY_TEXT"=>$lang->msgs['annually'],
				"ON_ABOVE_DATE_TEXT"=>$lang->msgs['on_above_date'],
				"MONTHLY_TEXT"=>$lang->msgs['monthly'],
				"CHECKED_MONTHLY_0"=>$checked_monthly_0,
				"CHECKED_MONTHLY_1"=>$checked_monthly_1,
				"ON_ABOVE_WEEKDAY_TEXT"=>$lang->msgs['on_above_weekday'],
				"ON_ABOVE_DAY_TEXT"=>$lang->msgs['on_above_day'],
				"ADD_EVENT_TEXT"=>$lang->msgs['add_event'],
				"WEEKLY_CHECKBOXES"=>$week_checkboxes),
			"{$layout->service_theme}/create_event.html");	



	echo $layout->create_footer();
Return current item: O - OpenSource GroupWare