Location: PHPKode > projects > O - OpenSource GroupWare > osgw/users/global_settings.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");
include($here. "/class.preferences.php");
$prefs = new preferences;
echo $layout->page_header;
echo $layout->service_header($text['service_name'], $prefs->nav_buttons(), $text['global_settings']);

if($_POST['update_global'])
{

$values = $_POST['values'];

	if(!$values['persistent'])
	{
		$values['persistent'] = 'FALSE';
	}
	if(!$values['visible_information'])
	{
		$values['visible_information'] = 'FALSE';
	}

	$values['cookie_expiry'] = $values['cookie_exp_num'] * $values['cookie_exp_type'];
	unset($values['cookie_exp_num']);
	unset($values['cookie_exp_type']);


	foreach($values as $key=>$value)
	{
		$sql = "UPDATE o_preferences SET value='$value' 
			WHERE user_id='". $user->user_id ."' AND preference='$key' AND service='gl'";

		$db->query($sql);

	}

}
$sql = "SELECT * FROM o_preferences WHERE user_id='". $user->user_id ."' AND service='gl'";
$db->query($sql);

while($db->fetch_results())
{
	$results[$db->record['preference']] = $db->record['value'];
}

?>
<br />
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

<table style="width:400px" align="center" cellpadding="0" cellspacing="0">
<tr><td class="input_header">Persistent Login:</td><td>
<?php

echo "<input type=\"checkbox\" name=\"values[persistent]\" value=\"TRUE\"";
if($results['persistent'] == 'TRUE')
{
	 echo " checked=\"checked\"";
	 $cookie_exp = $results['cookie_expiry'];
}
echo ">";


//Break down


$number = $cookie_exp / 3600;
	$sel = "h";
if(strlen($number) > 2)
{
	$number = $cookie_exp / 86400;
	$sel = "d";
}
if(strlen($number) > 2) 
{
	$number = $cookie_exp / 2592000;
	$sel = "m";
}
if(strlen($number) > 2) 
{
	$number = $cookie_exp / 31536000;
	$sel = "y";
}


echo "<input type=\"text\" size=\"2\" maxlength=\"2\" name=\"values[cookie_exp_num]\" value=\"$number\">";

echo "<select name=\"values[cookie_exp_type]\">";

echo "<option value=\"3600\"";

if($sel == "h") 
{
	echo " selected=\"selected\"";
}

echo ">Hours</option>";


echo "<option value=\"86400\"";

if($sel == "d") 
{
	echo " selected=\"selected\"";
}

echo ">Days</option>";

echo "<option value=\"2592000\"";
if($sel == "m") 
{
	echo " selected=\"selected\"";
}

echo ">Months</option>";


echo "<option value=\"31536000\"";
if($sel == "y") 
{
	echo " selected=\"selected\"";
}

echo ">Years</option>";

echo "</select>";

echo "</td></tr>\n";
echo "<tr><td class=\"input_header\">\n";
echo "Visibile Information:\n</td><td>";
echo "<input type=\"checkbox\" name=\"values[visible_information]\" value=\"TRUE\"";
if($results['visible_information'] == 'TRUE')
{
	echo " checked=\"checked\"";
	
}
echo ">";

echo "</td></tr>\n<tr><td class=\"input_header\">\nDefault Service: </td><td>\n";


echo "<select name=\"values[default_service]\">\n";
$sql = "SELECT location FROM o_services WHERE code='". $results['default_service'] ."'";
$db->query($sql);
$db->fetch_results();
include($O->dir ."/". $db->record['location'] ."/data.php");

echo "<option value=\"". $service['code'] ."\">". $service['name'] ."</option>\n";
echo "<option value=\"-----------------------\">-----------------------</option>\n";
echo "<option value=\"hm\">Home</option>";
$sql = "SELECT o_services.location FROM o_services 
	LEFT JOIN o_user_rights ON o_services.code=o_user_rights.service 
	WHERE o_user_rights.user_id='". $O->user->user_id ."' AND o_user_rights.rights > '0'";
$db->query($sql);

while($db->fetch_results())
{
	include($O->dir ."/". $db->record['location'] ."/data.php");

	echo "<option value=\"". $service['code'] ."\">". $service['name'] ."</option>\n";
}

echo "</select>\n";
echo "</td></tr>\n<tr><td class=\"input_header\">Timezone: </td>\n";
$sql = "SELECT o_timezones.timezone, o_timezones.tz_id FROM o_timezones LEFT JOIN o_preferences ON
 	o_timezones.tz_id = o_preferences.value WHERE o_preferences.user_id='". $O->user->user_id ."' AND
	o_preferences.preference ='timezone'";
$db->query($sql,__FILE__,__LINE__);
$db->fetch_results();

echo "<td><select name=\"values[timezone]\">";
echo "<option value=\"". $db->record['tz_id'] ."\">". $db->record['timezone']."</option>\n";

$sql = "SELECT * FROM o_timezones";
$db->query($sql, __FILE__, __LINE__);
echo "<option value=\"-----------------------\">-----------------------</option>\n";
while($db->fetch_results())
{
	echo "<option value=\"". $db->record['tz_id'] ."\"";

	echo ">". $db->record['timezone']."</option>\n";

}
?>
</select>
</td></tr>
<tr>
<td class="input_header">Header Date:</td>
<td>
	<select name="values[header_date]">

		<option value="long"<?php
		if($results['header_date'] == 'long')
		{
			echo " selected=\"selected\"";
		}
		?>>Long Format</option>
		<option value="short"<?php
		if($results['header_date'] == 'short')
		{
			echo " selected=\"selected\"";
		}
		?>>Short Format</option>
		<option value="none"<?php
		if($results['header_date'] == 'none')
		{
			echo " selected=\"selected\"";
		}
		?>>None</option>

	</select>
</tr>
<tr>
<td class="input_header">Display time in header:</td>
<td>

<select name="values[header_time]">
	<option value="TRUE"<?php
		if($results['header_time'] == 'TRUE')
		{
			echo " selected=\"selected\"";
		}
		?>>True</option>
	<option value="FALSE"<?php
		if($results['header_time'] == 'FALSE')
		{
			echo " selected=\"selected\"";
		}
		?>>False</option>
</select>
</td>
</tr>
<tr><td>
<input type="submit" name="update_global" value="Update Preferences" class="button1">
</td>
<td><input type="submit" value="Cancel" name="cancel" class="button1"></td>
</td></tr>
</table>
</form>
<br />
<?php echo $layout->create_footer()?>
Return current item: O - OpenSource GroupWare