Location: PHPKode > projects > O - OpenSource GroupWare > osgw/calendar/preferences.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)
   @package calendar
***************************************************************************/

if(isset($_POST['update_calendar']))
{
	$values = $_POST;
	$values['day_starts'] = $_POST['day_start_hr'] .":". $_POST['day_start_min'];
	$values['day_ends'] = $_POST['day_end_hr'] .":". $_POST['day_end_min'];

	if(!isset($values['show_birthdays']))
	{
		$values['show_birthdays'] = 'FALSE';
	}
	
	if(!isset($values['mini_months']))
	{
		$values['mini_months'] = 'FALSE';
	}

	foreach($values as $key=>$value)
	{

		$sql = "UPDATE o_preferences SET value='$value' WHERE preference='$key' AND user_id='". $user->user_id ."' AND service='cl'";
		$db->query($sql);
	}
}



$sql = "SELECT * FROM o_preferences WHERE user_id='". $user->user_id ."' AND service='cl'";
$db->query($sql);
while($db->fetch_results())
{
	$pref = $db->record['preference'];
	$results[$pref] = $db->record['value'];
}

	$day_start = explode(':',$results['day_starts']);
	$day_end = explode(':',$results['day_ends']);

?>
<br>

<form action="<?php echo $_SERVER['PHP_SELF']. "?x=". $_GET['x']. "&s=". $_GET['s']?>" method="post">
<table width="400" cellspacing="0">
<tr>
<td class="input_header">Day starts at:</td>
<td>
<input type="text" name="day_start_hr" value="<?php echo $day_start[0]?>" size="2" maxlength="2"> :
<input type="text" name="day_start_min" value="<?php echo $day_start[1]?>" size="2" maxlength="2">
</td>
</tr>
<tr>
<td class="input_header">Day ends at:</td>
<td>
<input type="text" name="day_end_hr" value="<?php echo $day_end[0]?>" size="2" maxlength="2"> :
<input type="text" name="day_end_min" value="<?php echo $day_end[1]?>" size="2" maxlength="2">
</td>
</tr>
<tr>
<td class="input_header">Increment:</td>
<td><input type="text" name="increments" value="<?php echo $results['increments']?>" size="2" maxlength="2"> minutes
</tr>
<tr>
<td class="input_header">Display Mini Months:</td>
<td><input type="checkbox" name="mini_months" value="TRUE"
<?php
if($results['mini_months'] == 'TRUE')
{
	echo " checked=\"checked\"";
}
?>>
</td>
</tr>
<tr>
<td class="input_header">Display Contact Birthdays</td>
<td><input type="checkbox" name="show_birthdays" value="TRUE"
<?php
if($results['show_birthdays'] == 'TRUE')
{
	echo " checked=\"checked\"";
}
?>>
</td>
</tr>
<td class="input_header">Display Holidays for:</td>
<td>
	<select name="show_holidays_for">
	<?php
		$sql = "SELECT o_countries.country, o_preferences.value FROM o_countries LEFT JOIN  o_preferences ON o_preferences.value=o_countries.c_id
			WHERE o_preferences.service='cl' AND o_preferences.preference='show_holidays_for'";
		$db->query($sql);
		$db->fetch_results();
	?>
		<option value="<?php echo $db->record['value']?>"><?php echo $db->record['country']?></option>
		<option value="0">--------------</option>
		<option value="0">None</option>
	<?php

		$sql = "SELECT o_countries.country, o_countries.c_id FROM o_countries 
			RIGHT JOIN o_holidays ON o_holidays.country=o_countries.c_id GROUP BY o_countries.c_id, o_countries.country";
		$db->query($sql);
		while($db->fetch_results())
		{

			echo "<option value=\"". $db->record['country_id'] ."\">". $db->record['country'] ."</option>\n";

		}
	?>
	</select>
</td>
</tr>
<tr>
<td class="input_header">Default View:</td>

<td>
	<?php $views = array('day'=>'Day','week'=>'Week','month'=>'Month','year'=>'Year');?>
	<select name="view">
	<?php

		foreach($views as $key=>$value)
		{
			echo "<option value=\"$key\"";
			if($results['view'] == $key)
			{
				echo " selected=\"selected\"";
			}

			echo ">$value</option>";

		}
	?>

	</select>
</td>
</tr>
<tr>
<td class="input_header">Week starts on:</td>
<td>
<select name="week_starts">
<?php
	$days_of_week = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	$i = 0;
	while($i < count($days_of_week))
	{
		echo "<option value=\"$i\"";
		if($results['view'] == $i)
		{
			echo " selected=\"selected\"";
		}

		echo ">". $days_of_week[$i] ."</option>";

		$i++;
	}
?>
</select>
</td>
</tr>
<tr>
<td class="input_header">Day View Format:</td>
<td>
<select name="hours">
	<option value="24"
	<?php if($results['hours'] == 24){ echo " selected=\"selected\"";}?>
	>24 hour</option>
	<option value="12"
	<?php if($results['hours'] == 12){ echo " selected=\"selected\"";}?>
	>12 hour</option>
</select>
</td>
<tr>
<td>
<input type="submit" name="update_calendar" value="Save Settings" class="button1">
</td>
<td>
<input type="reset" value="Cancel" name="cancel" class="button1">
</td>
</table>
Return current item: O - OpenSource GroupWare