From ce195b4f2c3e83c001edc5057d178ba4b92db17c Mon Sep 17 00:00:00 2001 From: skeeter Date: Wed, 27 Dec 2000 21:14:41 +0000 Subject: [PATCH] fix for preferences on login --- phpgwapi/inc/phpgw.inc.php | 7 ++- phpgwapi/inc/phpgw_accounts_shared.inc.php | 60 ++++++++++++++++------ 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/phpgwapi/inc/phpgw.inc.php b/phpgwapi/inc/phpgw.inc.php index ab19b66637..3b8aec9c89 100644 --- a/phpgwapi/inc/phpgw.inc.php +++ b/phpgwapi/inc/phpgw.inc.php @@ -132,7 +132,7 @@ function phpgw_() { - global $phpgw_info, $sessionid; + global $phpgw_info, $sessionid, $login; /**************************************************************************\ * Required classes * \**************************************************************************/ @@ -167,6 +167,9 @@ include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); $this->auth = new auth; $this->session = new sessions; + $log = explode("@",$login); + $this->preferences = new preferences($log[0]); +// $this->preferences->preferences_($log[0]); }else{ /* Load selected authentication class */ if (empty($phpgw_info["server"]["auth_type"])){$phpgw_info["server"]["auth_type"] = "sql";} @@ -182,11 +185,11 @@ include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_".$phpgw_info["server"]["account_repository"].".inc.php"); include($phpgw_info["server"]["api_inc"] . "/phpgw_accounts_shared.inc.php"); $this->auth = new auth; + $this->preferences = new preferences; } $this->accounts = new accounts; $this->translation = new translation; $this->common = new common; - $this->preferences = new preferences($phpgw_info["user"]["account_id"]); $this->acl = new acl; $this->hooks = new hooks; diff --git a/phpgwapi/inc/phpgw_accounts_shared.inc.php b/phpgwapi/inc/phpgw_accounts_shared.inc.php index 41f09426d3..28baf93da9 100644 --- a/phpgwapi/inc/phpgw_accounts_shared.inc.php +++ b/phpgwapi/inc/phpgw_accounts_shared.inc.php @@ -21,7 +21,10 @@ //echo "accounts_const called
line: $line
$file"; $phpgw->accounts->phpgw_fillarray(); - $preferences = new preferences($phpgw_info["user"]["account_id"]); + if(! $phpgw->preferences->account_id) { + $phpgw->preferences->preferences($phpgw_info["user"]["account_id"]); + } + $phpgw_info["user"]["preferences"] = $phpgw->preferences->get_preferences(); $this->groups = $this->read_groups($phpgw_info["user"]["userid"]); $this->apps = $this->read_apps($phpgw_info["user"]["userid"]); @@ -47,8 +50,7 @@ $phpgw_info_temp["apps"] = $phpgw_info["apps"]; $phpgw_info_temp["server"] = $phpgw_info["server"]; $phpgw_info_temp["hooks"] = $phpgw->hooks->read(); - $p = new preferences($phpgw_info["user"]["account_id"]); - $phpgw_info_temp["user"]["preferences"] = $p->preferences; + $phpgw_info_temp["user"]["preferences"] = $phpgw_info["user"]["preferences"]; $phpgw_info_temp["user"]["kp3"] = ""; // We don't want it anywhere in the // database for security. @@ -197,13 +199,26 @@ function preferences($account_id) { global $phpgw; - $db2 = $phpgw->db; - $this->account_id = $account_id; + $db2 = $phpgw->db; + $load_pref = True; + if (is_long($account_id)) { + $this->account_id = $account_id; + } elseif(is_string($account_id)) { + $db2->query("SELECT account_id FROM accounts WHERE account_lid='".$account_id."'"); + if($db2->num_rows()) { + $db2->next_record(); + $this->account_id = $db2->f("account_id"); + } + } else { + $load_pref = False; + } - $db2->query("select preference_value from preferences where preference_owner='" - . $this->account_id . "'",__LINE__,__FILE__); - $db2->next_record(); - $this->preferences = unserialize($db2->f("preference_value")); + if ($load_pref) { + $db2->query("select preference_value from preferences where preference_owner='" + . $this->account_id . "'",__LINE__,__FILE__); + $db2->next_record(); + $this->preferences = unserialize($db2->f("preference_value")); + } } // This should be called when you are done makeing changes to the preferences @@ -212,16 +227,19 @@ //echo "
commit called
Line: $line
File: $file"; global $phpgw, $phpgw_info; - $db = $phpgw->db; + if ($this->account_id) { + $db = $phpgw->db; - $db->query("delete from preferences where preference_owner='" . $this->account_id . "'",__LINE__,__FILE__); + $db->query("delete from preferences where preference_owner='" . $this->account_id . "'",__LINE__,__FILE__); - $db->query("insert into preferences (preference_owner,preference_value) values ('" - . $this->account_id . "','" . serialize($this->preferences) . "')",__LINE__,__FILE__); + $db->query("insert into preferences (preference_owner,preference_value) values ('" + . $this->account_id . "','" . serialize($this->preferences) . "')",__LINE__,__FILE__); - if ($phpgw_info["user"]["account_id"] == $this->account_id) { - $phpgw->accounts->sync(__LINE__,__FILE__); - } + if ($phpgw_info["user"]["account_id"] == $this->account_id) { + $phpgw_info["user"]["preferences"] = $this->preferences; + $phpgw->accounts->sync(__LINE__,__FILE__); + } + } } // Add a new preference. @@ -239,7 +257,11 @@ function delete($app_name,$var) { - $this->change($app_name,$var,""); + if (! $var) { + $this->reset($app_name); + } else { + unset($this->preferences[$app_name][$var]); + } } // This will kill all preferences within a certain app @@ -248,6 +270,10 @@ $this->preferences[$app_name] = array(); } + function get_preferences() + { + return $this->preferences; + } } //end of preferences class