mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 09:04:53 +01:00
113 lines
3.6 KiB
PHP
113 lines
3.6 KiB
PHP
<?php
|
|
/**************************************************************************\
|
|
* phpGroupWare *
|
|
* http://www.phpgroupware.org *
|
|
* -------------------------------------------- *
|
|
* 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. *
|
|
\**************************************************************************/
|
|
|
|
/* $Id$ */
|
|
|
|
class preferences
|
|
{
|
|
var $account_id;
|
|
var $preference;
|
|
|
|
function preferences($account_id)
|
|
{
|
|
global $phpgw;
|
|
// echo "Account ID (Initializing) = ".$account_id."<br>\n";
|
|
|
|
|
|
$db2 = $phpgw->db;
|
|
$load_pref = True;
|
|
if (is_long($account_id) && $account_id) {
|
|
$this->account_id = $account_id;
|
|
} elseif(is_string($account_id)) {
|
|
$db2->query("SELECT account_id FROM accounts WHERE account_lid='".$account_id."'",__LINE__,__FILE__);
|
|
if($db2->num_rows()) {
|
|
$db2->next_record();
|
|
$this->account_id = $db2->f("account_id");
|
|
} else {
|
|
$load_pref = False;
|
|
}
|
|
} else {
|
|
$load_pref = False;
|
|
}
|
|
|
|
//echo "Load Pref = $load_pref<br>\n";
|
|
//echo "Account ID (After Initializing) = ".$this->account_id."<br>\n";
|
|
|
|
if ($load_pref) {
|
|
$db2->query("SELECT preference_value FROM preferences WHERE preference_owner=".$this->account_id,__LINE__,__FILE__);
|
|
$db2->next_record();
|
|
$pref_info = $db2->f("preference_value");
|
|
$this->preference = unserialize($pref_info);
|
|
// echo "Preferences = ".$this->get_preferences()."<br>\n";
|
|
}
|
|
}
|
|
|
|
// This should be called when you are done makeing changes to the preferences
|
|
function commit($line = "",$file = "")
|
|
{
|
|
global $phpgw, $phpgw_info;
|
|
|
|
//echo "<br>commit called<br>Line: $line<br>File: $file".$phpgw_info["user"]["account_id"]."<br>";
|
|
if ($this->account_id) {
|
|
$db = $phpgw->db;
|
|
|
|
$db->query("delete from preferences where preference_owner=" . $this->account_id,__LINE__,__FILE__);
|
|
|
|
if ($PHP_VERSION < "4.0.0") {
|
|
$pref_info = addslashes(serialize($this->preference));
|
|
} else {
|
|
$pref_info = serialize($this->preference);
|
|
}
|
|
|
|
$db->query("insert into preferences (preference_owner,preference_value) values ("
|
|
. $this->account_id . ",'" . $pref_info . "')",__LINE__,__FILE__);
|
|
|
|
if ($phpgw_info["user"]["account_id"] == $this->account_id) {
|
|
$phpgw->preferences->preference = $this->get_preferences();
|
|
$phpgw->accounts->sync(__LINE__,__FILE__);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add a new preference.
|
|
function change($app_name,$var,$value = "")
|
|
{
|
|
global $phpgw_info;
|
|
|
|
if (! $value) {
|
|
global $$var;
|
|
$value = $$var;
|
|
}
|
|
|
|
$this->preference["$app_name"]["$var"] = $value;
|
|
}
|
|
|
|
function delete($app_name,$var)
|
|
{
|
|
if (! $var) {
|
|
$this->reset($app_name);
|
|
} else {
|
|
unset($this->preference["$app_name"]["$var"]);
|
|
}
|
|
}
|
|
|
|
// This will kill all preferences within a certain app
|
|
function reset($app_name)
|
|
{
|
|
$this->preference["$app_name"] = array();
|
|
}
|
|
|
|
function get_preferences()
|
|
{
|
|
return $this->preference;
|
|
}
|
|
} //end of preferences class
|
|
?>
|