Location: PHPKode > projects > O - OpenSource GroupWare > osgw/calendar/view_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: view_event.php,v 1.2 2004/05/27 16:54:40 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']);



$events = new events();

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->update_event($_POST['event_id'], $_POST);
		$O->redirect("/calendar/edit_event.php?id={$_POST['event_id']}");
	}
	
}
echo $layout->page_header;
echo $cal->nav_buttons($_GET['v']);
if($error->buffer)
{
	echo $error->display();	
}

$sql = "SELECT * FROM o_calendar WHERE event_id='{$_GET['id']}' AND user_id='{$user->user_id}'";
$db->query($sql);
$db->fetch_results();
$event_data = $db->record;

	if(isset($_POST['all_day']))
	{
		$all_day_checked = " checked=\"checked\"";
	}
	
	$sql = "SELECT * FROM o_recurrence WHERE event_id='{$_GET['id']}'";
	$db->query($sql);
	$db->fetch_results();
	$recurrence_data = $db->record;
	$tmp = explode(':', $lang->msgs['recur_type']);
	$type = $recurrence_data['type'];
	
	$recurrence_type = $tmp[$type];
	if($recurrence_data['rend'] == 0)
	{
		$recure_end_date = $lang->msgs['never'];
	} elseif($recurrence_data['times'] > 0) {
		$recure_end_date = $after_occur = str_replace('%NUMBER_BOX%', 
			"{$recurrence_data['times']}", $lang->msgs['after_occur']);

	} else {
		$recure_end_date = date($date->long_date, $recurrence_data['rend']);
	}

	if($recurrence_data['times'] != '-1' && $recurrence_data['times'] != '0')
	{
		
		$recure_end = 2;
	} elseif($recurrence_data['times'] == 0)
	{
		$recure_end = 0;
		$recurrence_data['times'] = NULL;
	} elseif($recurrence_data['rend'] != 0)
	{
		$recure_end = 1;
		$recurrence_data['times'] = NULL;
	}
	
	$after_occur = str_replace('%NUMBER_BOX%', 
	"<input type=\"text\" size=\"3\" name=\"recur_after\" value=\"{$recurrence_data['times']}\">", $lang->msgs['after_occur']);
	
	$checked  = " checked=\"checked\"";
	switch($recure_end)
	{
		case 0:
			$checked_never = $checked;
		break;
		case 1:
			$checked_on = $checked;
		break;
		case 2:
			$checked_after = $checked;
		break;
	}
	$recure_info = explode(':', $recurrence_data['data']);
	switch($recure_info['0'])
	{
		case 0:
			$checked_monthly_0 = $checked;
		break;
		case 1:
			$checked_monthly_1 = $checked;
		break;
	}
	

	$i = 0;

	$weekdays = explode(':', $lang->msgs['long_weekdays']);
	if($recurrence_data['type'] == 2)
	{
		$selected_days = unserialize(stripslashes($recurrence_data['data'])); 
	}
	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($selected_days))
		{
			if(in_array($i, $selected_days))
			{
				$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";
	}
	if($recurrence_data['type'] == 1)
	{
		$frequency = $recurrence_data['frequency'] / DAY_SEC;
	} else {
		$frequency = $recurrence_data['frequency'];
	}
	
	$sql = "SELECT o_categories.category FROM o_categories LEFT JOIN o_categorize
		ON o_categorize.category=o_categories.category_id 
		WHERE o_categorize.service='cl' AND o_categorize.id='{$_GET['id']}'";
	$db->query($sql);
	echo $db->error;
	$db->fetch_results();
	$category = $db->record['category'];
	echo $html->create_list(array("FORM_LINK"=>"/calendar/edit_event.php" ."?id={$_GET['id']}",
				"EVENT_ID"=>$_GET['id'],
				"SUBJECT_TEXT"=>$lang->msgs['subject'],
				"EVENT_SUBJECT"=>$event_data['subject'],
				"LOCATION_TEXT"=>$lang->msgs['location'],
				"EVENT_LOCATION"=>$event_data['location'],
				"CATEGORY_TEXT"=>$lang->msgs['category'],
				"EVENT_CATEGORY"=>$category,
				"DESCRIPTION_TEXT"=>$lang->msgs['description'],
				"EVENT_DESCRIPTION"=>str_replace("\n","<br />", $event_data['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_DATE"=>date($date->long_date . ' - '. $date->time, $event_data['evt_start']),
				"END_TEXT"=>$lang->msgs['end'],
				"END_DATE"=>date($date->long_date . ' - '. $date->time, $event_data['evt_end']),				
				"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"=>$frequency,
				"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'],
				"VIEW_EVENT_TEXT"=>$lang->msgs['edit_event'],
				"WEEKLY_CHECKBOXES"=>$week_checkboxes),
			"{$layout->service_theme}/view_event.html");	



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