Location: PHPKode > projects > O - OpenSource GroupWare > osgw/calendar/add_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)
***************************************************************************/
include("./data.php");
$service['add_header'] = TRUE;
include("../config.inc.php");
require('classes/class.format.php');
require('classes/class.recurrence.php');


$format = new format();
$events = new recurrence();


$cal->med_months = $med_months;
$cal->weekdays = $weekdays;
$cal->months = $months;
//If new event has a set date on load (directed from a month, day, etc. view) use
//That as default staring date. Else use current date.
if(!isset($_GET['nd']))
{
	$cal->current_day = date('j');
	$cal->current_month = date('n');
	$cal->current_year = date('Y');
} else {
	$cal->current_day = $_GET['d'];
	$cal->current_month = $_GET['m'];
	$cal->current_year = $_GET['y'];
}

if(isset($_POST['create_event']))
{
	//Make sure date is valid and return a Unix timestamp
	$start_time = $events->check_date(
			$_POST['start_day'],
			$_POST['start_month'],
			$_POST['start_year'],
			$_POST['start_hour'],
			$_POST['start_min']);

	
	$end_time = $events->check_date(
			$_POST['end_day'],
			$_POST['end_month'],
			$_POST['end_year'],
			$_POST['end_hour'],
			$_POST['end_min']);

	if($start_time && $end_time)
	{
		//Make sure event doesn't start after it ends.
		if($events->compare_start_end($start_time, $end_time))
		{
	
			if($events->verify_required_fields($_POST))
			{
				$id = $events->create_event($_POST, $start_time, $end_time);
				if(strlen($_POST['category']) > 0)
				{
					$events->categorize($id, $_POST['category'], $service['code']);
				}
				if($_POST['recur_type'] != 0)
				{
				
					$events->set_recurrence($_POST, $_POST['recur_type'], $id, $start_time, $end_time, 'INSERT');
				}
			}
		}
	}

}
echo $layout->page_header;

echo $format->create_title('create_event');

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

?>

<br>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table width="80%" cellspacing="0" align="center" border="0">
<tr>
	<td class="input_header"><?php echo $lang->get_msg('subject','gl')?>:</td>
	<td colspan='2'><input type="text" name="event_subject" value="<?php echo $_POST['event_subject']?>" size="50"></td>
</tr>
<tr>
	<td class="input_header"><?php echo $lang->get_msg('location','cl')?>:</td>
	<td colspan='2'><input type="text" name="location" value="<?php echo $_POST['location']?>" size="50"></td>
</tr>
<tr>
	<td class="input_header"><?php echo $lang->get_msg('category','gl')?>:</td>
	<td colspan='2'>

		<select name="category">
		<option value="">--------------------</option>
		<?php //
		$sql = "SELECT * FROM o_categories WHERE user_id='". $user->user_id ."'
			AND service='$service[code]'";
		$db->query($sql);
		while($db->fetch_results())
		{
			echo "<option value=\"". $db->record['category_id'] ."\"";

			if($_POST[category] == $db->record['category_id'])
			{
				echo " selected=\"selected\"";
			}
			echo ">". $db->record['category'] ."</option>\n";

		}
		?>
		</select>
	</td>
</tr>
<tr>
	<td class="input_header" valign="top"><?php echo $lang->get_msg('description','gl')?>:</td>
	<td colspan='2'>
	<textarea cols="75" rows="15" name="description"><?php echo $_POST['description']?></textarea></td>
</tr>
<tr>
<td class="input_header">&nbsp;</td><td width="200" class="input_header">Date</td><td class="input_header">Time</td>
</tr>
<tr>
<td class="input_header"><?php echo $lang->get_msg('start','gl')?>:</td>
<td>

	<?php echo $format->day_select_box('start_day', '', $_POST['start_day']);?>
	<?php echo $format->month_select_box('start_month', '', $_POST['start_month']);?>
	<?php echo $format->year_select_box('start_year', '', $_POST['start_year']);?>
</td>
<td>

<?php
	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';
	}

?>
	<input type="text" name="start_hour" value="<?php echo $start_hour?>" size="2" maxlength="2"> :
	<input type="text" name="start_min" value="<?php echo $start_min?>" size="2" maxlength="2">
<?php
$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')
{
?>
	<select name="start_md">

	<option value="am" <?php if($_POST['start_md'] == 'am'){echo "selected=\"selected\"";}?>>AM</option>
	<option value="pm" <?php if($_POST['start_md'] == 'pm'){echo "selected=\"selected\"";}?>>PM</option>
	</select>
<?php
} else {
	echO "24hr Format";
}
?>
</td>
</tr>
<tr>
<td class="input_header"><?php echo $lang->get_msg('end','gl')?>:</td>
<td>

	<?php echo $format->day_select_box('end_day', '', $_POST['end_day']);?>
	<?php echo $format->month_select_box('end_month', '', $_POST['end_month']);?>
	<?php echo $format->year_select_box('end_year', '', $_POST['end_year']);?>
</td>
<td>
	<input type="text" name="end_hour" value="<?php echo $end_hour?>" size="2" maxlength="2"> :
	<input type="text" name="end_min" value="<?php echo $end_min?>" size="2" maxlength="2">
<?php
if($db->record['value'] == '12')
{
?>
	<select name="end_md">

	<option value="am" <?php if($_POST['end_md'] == 'am'){echo "selected=\"selected\"";}?>>AM</option>
	<option value="pm" <?php if($_POST['end_md'] == 'pm'){echo "selected=\"selected\"";}?>>PM</option>
	</select>
<?php
}
?>
</td>
</tr>
<tr>
<td class="input_header">All Day</td>
<td><input type="checkbox" name="all_day" value="1"
<?php
	if($_POST['all_day'])
	{
		echo " checked=\"checked\"";
	}
?>
</td>
</tr>
<tr>
	<td></td>
	<td>
</table>

<table width="98%" align="center">
<tr>
<td class="input_header" width="150"><?php echo $format->msg('recur_event')?></td>
</tr>
<tr>
<td class="input_header"><?php echo $format->msg('recurrence')?></td>
<td class="light">
<select name="recur_type">
<?php	
	$i = 0;
	$r_type = explode(':', $format->msg('recur_type'));
	while($i < count($r_type))
	{
		echo "<option value=\"$i\"";
		if($_POST['recur_type'] == $i)
		{
			echo " selected=\"selected\"";
		}

		echo ">". $r_type[$i] ."</option>\n";
		$i++;
	}
?>

</select>

</td>
</tr>
<tr>

<td class="input_header" valign="top">End</td>
<td class="light">
	<?php
		$r_end = $_POST['recur_end'];
	?>
	<input type="radio" name="recur_end" value="0"
	<?php if($r_end == 0){ echo " checked=\"checked\"";}?>>Never<br>

	<input type="radio" name="recur_end" value="1"
	<?php if($r_end == 1){ echo " checked=\"checked\"";}?>>On
	<?php
		echo $format->day_select_box('recur_end_day', '', $_POST['recur_end_day']);
		echo $format->month_select_box('recur_end_month', '', $_POST['recur_end_month']);
		echo $format->year_select_box('recur_end_year', '', $_POST['recur_end_year']);
	?>
	<br>
	<input type="radio" name="recur_end" value="2"
	<?php if($r_end == 2){ echo " checked=\"checked\"";}?>>After <input type="text" size="3" name="recur_after" value="<?php echo $_POST['recur_after']?>"> occurrences<br>

</td>

</tr>
<tr>
	<td class="input_header">Frequency:</td>
	<td class="light"><input type="text" size="2" name="recur_freq" value="<?php if(isset($_POST['recur_freq'])){echo $_POST['recur_freq'];} else{ echo '1';}?>">
</tr>
<tr>
	<td class="input_header">Weekly:</td>
	<td class="light">
	<?php
		$i = 0;
		$weekdays = explode(':', $events->msg('long_weekdays','gl'));
		
		while($i < 7)
		{
			echo "<input type=\"checkbox\" name=\"recur_weekday[$i]\" value=\"$i\"";
			//Because it's not created when first visiting the page we need
			//to stop if from looking in an array that doesn't exist yet.
			if(is_array($_POST['recur_weekday']))
			{
				if(in_array($i, $_POST['recur_weekday']))
				{
					echo " checked=\"checked\"";
				}
			}

			echo ">\n";
			echo $weekdays[$i];
			$i++;
		}
	?>
	</td>
</tr>
<tr>
	<td class="input_header">Monthly:</td>
	<td class="light">
		<input type="radio" name="recur_monthly_type" value="0"
		<?php
			if($_POST['recur_monthly_type'] == 0)
			{
				echo " checked=\"checked\"";
			}
		
		?>>on the above day of the month.
			<br>
		<input type="radio" name="recur_monthly_type" value="1"<?php
			if($_POST['recur_monthly_type'] == 1)
			{
				echo " checked=\"checked\"";
			}
		
		?>> on the weekday/week number of the month corresponding to
			the above date.
	</td>
</tr>
<tr>
	<td class="input_header">Annually:</td>
	<td class="light">On the above date</td>
</tr>
</table>

<input type="submit" name="create_event" value="<?php echo $events->msg('add_event');?>" class="button1">
</form>
<?php
echo $layout->create_footer();
Return current item: O - OpenSource GroupWare