Location: PHPKode > projects > O - OpenSource GroupWare > osgw/users/locale.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)
***************************************************************************/

//GET USERS DATA store in $user_locale
if($_POST['update_locale'])
{
	$sql = "SELECT * FROM o_languages WHERE language_id='$_POST[language]' AND enabled='1'";
	$db->query($sql);
	//This is checked and updated first incase the language isn't supported.
	if($db->num_rows != 0)
	{
		$sql = "UPDATE o_user_locale SET language='$_POST[language]' WHERE user_id='". $O->user->user_id ."'";
		$db->query($sql);
	}
	$sql = "UPDATE user_locale SET locale='$_POST[locale]',
	country='$_POST[country]', num_decimal='$_POST[num_decimal]',
	num_separator='$_POST[num_separator]',num_pos='$_POST[num_pos]', 
	num_neg='$_POST[num_neg]',money_currency='$_POST[money_currency]', 
	money_decimal='$_POST[money_decimal]', money_thousands='$_POST[money_thousands]',
	money_fraction_digits='$_POST[money_fraction_digits]', 
	pos_pfx_symbol='$_POST[pos_pfx_symbol]',pos_position='$_POST[pos_position]',
	neg_pfx_symbol='$_POST[neg_pfx_symbol]',neg_position='$_POST[neg_position]',
	date='$_POST[date]',short_date='$_POST[short_date]', time='$_POST[time]' 
	WHERE user_id='". $O->user->user_id ."'";
	$db->query($sql);

}
$sql = "SELECT o_user_locale.*, o_locales.locale_name, o_languages.* 
	FROM o_user_locale LEFT JOIN o_locales ON o_user_locale.locale=o_locales.locale 
	LEFT JOIN o_languages ON o_user_locale.locale=o_languages.language_id WHERE o_user_locale.user_id='" . $O->user->user_id ."'";
$db->query($sql, __FILE__, __LINE__);
$db->fetch_results();
$user_locale = $db->record;




//Get supported languages
$sql = "SELECT * FROM languages WHERE enabled='1'";
$db->query($sql, __FILE__, __LINE__);
while($db->fetch_results())
{
	$language[$db->record['language_id']] = $db->record['language'];
}

?>
<script>
	function get_locale_data(form_data)
	{


		fd = form_data;
		switch(fd.locale.value)
		{

<?php
//GET ALL Locales store in $locales
$sql = "SELECT locales.*, languages.* FROM locales LEFT JOIN languages ON locales.locale=languages.language_id";

$db->query($sql, __FILE__, __LINE__);

while($db->fetch_results())
{
	$locales[$db->record['locale']] = $db->record;
	echo "case '". $db->record['locale'] ."':\n";
	
	echo "fd.language.value='". $db->record['locale'] ."';\n";
	echo "fd.num_decimal.value='". $db->record['num_decimal'] ."';\n";
	echo "fd.num_separator.value='". $db->record['num_seperator'] ."';\n";
	echo "fd.num_pos.value='". $db->record['num_pos'] ."';\n";
	echo "fd.num_neg.value='". $db->record['num_neg'] ."';\n";
	echo "fd.money_currency.value='". $db->record['money_currency'] ."';\n";
	echo "fd.money_thousands.value='". $db->record['money_thousands'] ."';\n";
	echo "fd.money_fraction_digits.value='". $db->record['money_fraction_digits'] ."';\n";
	echo "fd.pos_pfx_symbol.value='". $db->record['pos_pfx_symbol'] ."';\n";
	echo "fd.pos_position.value='". $db->record['pos_position'] ."';\n";
	echo "fd.neg_position.value='". $db->record['neg_position'] ."';\n";
	echo "fd.neg_pfx_symbol.value='". $db->record['neg_pfx_symbol'] ."';\n";
	echo "fd.date.value='". $db->record['date'] ."';\n";
	echo "fd.date_ex.value='". date($db->record['date']) ."';\n";
	echo "fd.short_date.value='". $db->record['short_date'] ."';\n";
	echo "fd.short_date_ex.value='". date($db->record['short_date']) ."';\n";
	echo "fd.time.value='". $db->record['time'] ."';\n";
	echo "fd.time_ex.value='". date($db->record['time']) ."';\n";

	echo "break;\n";

	}




?>


}



	}
	

function number_change(formData)
{
	example_pos = "%P1%S234%S567%S890%D45";
	example_neg = "%N1%S234%S567%S890%D45";

	decimal = /%D/
	example_pos = example_pos.replace(decimal, formData.num_decimal.value)
	example_neg = example_neg.replace(decimal, formData.num_decimal.value)

	seperator = /%S/
	i = 0;
	while(i < 3)
	{

		example_pos = example_pos.replace(seperator, formData.num_separator.value);
		example_neg = example_neg.replace(seperator, formData.num_separator.value);
		i++;
	}
	
	pos = /%P/
	example_pos = example_pos.replace(pos, formData.num_pos.value);
	neg = /%N/
	example_neg = example_neg.replace(neg, formData.num_neg.value);

	formData.positive_numbers.value = example_pos;
	formData.negative_numbers.value = example_neg;
}
function currency_change(formData)
{
	example_c_pos = "%P1%S234%S567%S890%D45";
	i = 0;

	formData.positive_numbers.value = example;
}

</script>
<form action="<?php echo "$_SERVER[PHP_SELF]?x=". $_GET['x']. "&s=". $_GET['s']?>" method="post" name="user_locale">
<table>
<tr><td class="input_header">Locale:</td>
<td><select name="locale" onChange="get_locale_data(user_locale)">
	<option value="<?php echo $user_locale['locale']?>"><?php echo $user_locale['language']?></option>
	<option value="">-----------------------------------</option>
	<?php
	foreach($locales AS $key=>$value)
	{
		echo "<option value=\"". $locales[$key][locale] ."\">". $locales[$key]['language'] ."</option>\n";
	}
	?>
	</select>

</tr>
<tr>
<td class="input_header">Language:</td>
<td>
<select name="language">

<?php

foreach($language AS $key=>$value)
{
echo $user_locale['language_id'];
	if($key == $user_locale['language_id'])
	{
		echo "<option value=\"". $user_locale['language_id'] ."\">$value</option>\n";
		break;
	}
}
?>
	<option value="">-----------------------------------</option>
<?php
foreach($language AS $key=>$value)
{
	echo "<option value=\"$key\"> $value</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td class="input_header">Country: </td>
<td>
<select name="country">
	<?php
	echo $user_locale['country'];
		$sql = "SELECT * FROM countries ORDER BY country";
		$db->query($sql, __LINE__, __FILE__);

		while($db->fetch_results())
		{
			echo "<option value=\"". $db->record['country_id'] ."\"";
			if($db->record['country_id'] == $user_locale['country'])
			{
				echo " selected=\"selected\"";
			}

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

</select>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center" class="list_header">Numbers</td>
<tr>
<td class="input_header">Numeric Decimal Symbol:</td>
<td><input type="text" name="num_decimal" value="<?php echo $user_locale['num_decimal']?>" size="5" style="text-align:center" onChange="number_change(user_locale)">
<?php

$value = "%P1%S234%S567%S890%D45";
$value = str_replace('%P', $user_locale['num_pos'], $value);
$value = str_replace('%S', $user_locale['num_separator'], $value);
$value = str_replace('%D', $user_locale['num_decimal'], $value);
?>
<td>Positive Numbers:</td>
<td><input type="text" name="positive_numbers" value="<?php echo $value?>" id="examples" readOnly></td>
</tr>
<tr>
<td class="input_header">Thousands Seperator:</td>
<td><input type="text" name="num_separator" value="<?php echo $user_locale['num_separator']?>" size="5" style="text-align:center" onChange='number_change(user_locale)'>
<td>Negative Numbers:</td>
<?php

$value = "%N1%S234%S567%S890%D45";
$value = str_replace('%N', $user_locale['num_neg'], $value);
$value = str_replace('%S', $user_locale['num_separator'], $value);
$value = str_replace('%D', $user_locale['num_decimal'], $value);
?>
<td><input type="text" name="negative_numbers"  id="examples" value="<?php echo $value?>" readOnly></td>
</tr>
<tr>
<td class="input_header">Positive Symbol:</td>
<td><input type="text" name="num_pos" value="<?php echo $user_locale['num_pos']?>" size="5" style="text-align:center" onChange='number_change(user_locale)'>
</tr>
<tr>
<td class="input_header">Negative Symbol:</td>
<td><input type="text" name="num_neg" value="<?php echo $user_locale['num_neg']?>" size="5" style="text-align:center" onChange='number_change(user_locale)'>
</tr>
<tr>
<td colspan="2" style="text-align:center" class="list_header">Money</td>
<tr>
<tr>
<td class="input_header">Currency:</td>
<td><input type="text" name="money_currency" value="<?php echo $user_locale['money_currency']?>" size="5" style="text-align:center">
<td>Positive Currency:</td>
<?php

$value = "1%S234%S567%S890%D";

$value = str_replace('%N', $user_locale['num_neg'], $value);
$value = str_replace('%S', $user_locale['num_separator'], $value);
$i = 0;
$t = 4;

while($i < $user_locale['money_fraction_digits'])
{

	$temp .= $t;
	$t++;
	if($t == 10)
	{
		$t = 0;
	}
	$i++;
}
$value = str_replace('%D', $user_locale['num_decimal'] . $temp, $value);



switch($user_locale['pos_position'])
{
	case "Before Quantity":

		if($user_locale['pos_pfx_symbol'])
		{
			$value = $user_locale['money_currency']. $user_locale['num_pos']  .$value;
		} else {
			$value = $user_locale['num_pos']. $value .$user_locale['money_currency'];
		}

	break;
	case "Parentheses":
		if($user_locale['pos_pfx_symbol'])
		{
			$value = $user_locale['money_currency'] ."($value)";
		} else {
			$value = "($value)". $user_locale['money_currency'];
		}
	break;
	case "Before":
		if($user_locale['pos_pfx_symbol'])
		{
			$value = $user_locale['num_pos'] .$user_locale['money_currency'] .$value;
		} else {
			$value = $user_locale['num_pos'] . $value. $user_locale['money_currency'];
		}
	break;
	case "After":
		if($user_locale['pos_pfx_symbol'])
		{
			$value = $user_locale['num_pos'] .$user_locale['money_currency'] .$value;
		} else {
			$value = $value. $user_locale['money_currency']. $user_locale['num_pos'];
		}
	break;
	case "After Quantity":
		if($user_locale['pos_pfx_symbol'])
		{
			$value = $user_locale['money_currency']. $value. $user_locale['num_pos'];
		} else {
			$value = $value. $user_locale['num_pos']. $user_locale['money_currency'];
		}
	break;


}



?>
<td><input type="text" name="positive_currency" id="examples" value="<?php echo $value?>" readOnly></td>
</tr>
<tr>
<td class="input_header">Decimal Symbol:</td>
<td><input type="text" name="money_decimal" value="<?php echo $user_locale['money_decimal']?>" size="5" style="text-align:center">
<td>Negative Currency:</td>


<?php

$value = "1%S234%S567%S890%D";

$value = str_replace('%S', $user_locale['num_separator'], $value);
$i = 0;
$t = 4;

while($i < $user_locale['money_fraction_digits'])
{

	$temp .= $t;
	$t++;
	if($t == 10)
	{
		$t = 0;
	}
	$i++;
}
$value = str_replace('%D', $user_locale['num_decimal'] . $temp, $value);



switch($user_locale['neg_position'])
{
	case "Before Quantity":

		if($user_locale['neg_pfx_symbol'])
		{
			$value = $user_locale['money_currency']. $user_locale['num_neg']  .$value;
		} else {
			$value = $user_locale['num_neg']. $value .$user_locale['money_currency'];
		}

	break;
	case "Parentheses":
		if($user_locale['neg_pfx_symbol'])
		{
			$value = $user_locale['money_currency'] ."($value)";
		} else {
			$value = "($value)". $user_locale['money_currency'];
		}
	break;
	case "Before":
		if($user_locale['neg_pfx_symbol'])
		{
			$value = $user_locale['num_neg'] .$user_locale['money_currency'] .$value;
		} else {
			$value = $user_locale['num_neg'] . $value. $user_locale['money_currency'];
		}
	break;
	case "After":
		if($user_locale['neg_pfx_symbol'])
		{
			$value = $user_locale['num_neg'] .$user_locale['money_currency'] .$value;
		} else {
			$value = $value. $user_locale['money_currency']. $user_locale['num_neg'];
		}
	break;
	case "After Quantity":
		if($user_locale['neg_pfx_symbol'])
		{
			$value = $user_locale['money_currency']. $value. $user_locale['num_neg'];
		} else {
			$value = $value. $user_locale['num_neg']. $user_locale['money_currency'];
		}
	break;


}


?>
<td><input type="text" id="examples"  name="negative_currency" value="<?php echo $value?>" readOnly></td>
</tr>
<tr>
<td class="input_header">Thousands Seperator:</td>
<td><input type="text" name="money_thousands" value="<?php echo $user_locale['money_thousands']?>" size="5" style="text-align:center">
</tr>
<tr>
<td class="input_header">Decimal Digits:</td>
<td>

<input type="text" name="money_fraction_digits" value="<?php echo $user_locale['money_fraction_digits']?>" size="3" maxlength="2" style="text-align:center">
</tr>

<tr>
<td class="input_header">Prefix Currency Symbol (Positive):</td>

<td>
<input type="checkbox" name="pos_pfx_symbol" value="1"
<?php

if($user_locale['pos_pfx_symbol'])
{
	echo " checked=\"checked\"";
}

?>>
</td>
</tr>
<tr>
<td class="input_header">Sign Position (Positive):</td>
<td><select name="pos_position">
	<option value="<?php echo $user_locale['pos_position']?>"><?php echo $user_locale['pos_position']?></option>
	<option value="">--------------------</option>
	<option value="Parentheses">Parentheses</option>
	<option value="Before">Before Money</option>
	<option value="Before Quantity">Before Quantity</option>
	<option value="After">After Money</option>
	<option value="After Quantity">After Quantity</option>

</select>
</td>
</tr>
<tr>
<td class="input_header">Prefix Currency Symbol (Negative):</td>
<td>
<input type="checkbox" name="neg_pfx_symbol" value="1"
<?php

if($user_locale['neg_pfx_symbol'])
{
	echo " checked=\"checked\"";
}

?>>
</td>
</tr>
<tr>
<td class="input_header">Sign Position (Negative):</td>
<td><select name="neg_position">
	<option value="<?php echo $user_locale['neg_position']?>"><?php echo $user_locale['neg_position']?></option>
	<option value="">--------------------</option>
	<option value="Parentheses">Parentheses</option>
	<option value="Before">Before Money</option>
	<option value="Before Quantity">Before Quantity</option>
	<option value="After">After Money</option>
	<option value="After Quantity">After Quantity</option>

</select>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center" class="list_header">Date</td>
</tr>
<tr>
<td class="input_header">Date Format: <a href="javascript:openpopup('http://tigger.osgw.org/help/index.php?app=dates')" class="input_header">(?)</a></td>
<td><input type="text" name="date" value="<?php echo $user_locale['date']?>"></td>
<td>Date Example:</td>
<td><input type="text" name="date_ex" id="examples"  value="<?php echo date($user_locale['date'])?>" readOnly></td>
</tr>
<tr>
<td class="input_header">Short Format: <a href="javascript:openpopup('http://tigger.osgw.org/help/index.php?app=dates')" class="input_header">(?)</a></td>
<td><input type="text" name="short_date" value="<?php echo $user_locale['short_date']?>"></td>
<td>Short Date Example:</td>
<td><input type="text" name="short_date_ex" id="examples"  value="<?php echo date($user_locale['short_date'])?>" readOnly></td>
</tr>
<tr>
<td class="input_header">Time Format:<a href="javascript:openpopup('http://tigger.osgw.org/help/index.php?app=dates')" class="input_header">(?)</a></td>
<td><input type="text" name="time" value="<?php echo $user_locale['time']?>"></td>
<td>Time Example: </td>
<td><input type="text" name="time_ex" id="examples"  value="<?php echo date($user_locale['time'])?>" readOnly></td>
</tr>
<tr>
<td><input type="submit" name="update_locale" value="Save Settings" class="button1"></td>
<td><input type="reset" name="clear" value="Reset" class="button1"></td>
</tr>
</table>
</form>
Return current item: O - OpenSource GroupWare