[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: phpgwapi/inc class.preferences.inc.php,1.48,1.49
From: |
Ralf Becker <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: phpgwapi/inc class.preferences.inc.php,1.48,1.49 |
Date: |
Thu, 01 May 2003 05:19:14 -0400 |
Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv18271
Modified Files:
class.preferences.inc.php
Log Message:
reworked preferences (ported from .16 incl. fixes):
- not set user-prefs use the default value, default values have been used only
for new accounts before
- preference-table has new column preference_app
- preferences got automaticaly quoted now, eg. its save to use single and
double quotes as well as backslashs
Index: class.preferences.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.preferences.inc.php,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -r1.48 -r1.49
*** class.preferences.inc.php 19 Apr 2003 23:17:40 -0000 1.48
--- class.preferences.inc.php 1 May 2003 09:19:11 -0000 1.49
***************
*** 27,31 ****
@class preferences
@abstract preferences class used for setting application preferences
! @discussion Author: none yet
*/
class preferences
--- 27,35 ----
@class preferences
@abstract preferences class used for setting application preferences
! @discussion the prefs are read into 4 arrays: \
! $data the effective prefs used everywhere in phpgw, they are
merged from the other 3 arrays \
! $user the stored user prefs, only used for manipulating and
storeing the user prefs \
! $default the default preferences, always used when the user has
no own preference set \
! $forced forced preferences set by the admin, they take
precedence over user or default prefs
*/
class preferences
***************
*** 35,40 ****
/*! @var account_type */
var $account_type;
! /*! @var data */
var $data = array();
/*! @var db */
var $db;
--- 39,50 ----
/*! @var account_type */
var $account_type;
! /*! @var data effectiv user prefs, used by all apps */
var $data = array();
+ /*! @var user set user prefs for saveing (no defaults/forced
prefs merged) */
+ var $user = array();
+ /*! @var default default prefs */
+ var $default = array();
+ /*! @var forced forced prefs */
+ var $forced = array();
/*! @var db */
var $db;
***************
*** 63,100 ****
\**************************************************************************/
/*!
@function read_repository
@abstract private - read preferences from the repository
@discussion private function should only be called from within
this class
*/
function read_repository()
{
! $this->db->query("SELECT * FROM phpgw_preferences WHERE
"
! . "preference_owner='" . $this->account_id . "'
OR "
! . "preference_owner='-1' ORDER BY
preference_owner DESC",__LINE__,__FILE__);
! $this->db->next_record();
! $pref_info = $this->db->f('preference_value');
! $this->data = unserialize($pref_info);
!
! if ($this->db->next_record())
{
! $global_defaults =
unserialize($this->db->f('preference_value'));
!
! while (is_array($global_defaults) &&
list($appname,$values) = each($global_defaults))
{
! while (is_array($values) &&
list($var,$value) = each($values))
{
! $this->data[$appname][$var] =
$value;
}
}
}
!
! /* This is to supress warnings during login */
! if (is_array($this->data))
{
! reset ($this->data);
}
-
// This is to supress warnings durring login
if (is_array($this->data))
--- 73,179 ----
\**************************************************************************/
+ /*!
+ @function unquote
+ @abstract unquote (stripslashes) recursivly the whole array
+ @param $arr array to unquote (var-param!)
+ */
+ function unquote(&$arr)
+ {
+ if (!is_array($arr))
+ {
+ $arr = stripslashes($arr);
+ return;
+ }
+ foreach($arr as $key => $value)
+ {
+ if (is_array($value))
+ {
+ $this->unquote($arr[$key]);
+ }
+ else
+ {
+ $arr[$key] = stripslashes($value);
+ }
+ }
+ }
+
/*!
@function read_repository
@abstract private - read preferences from the repository
+ @note the function ready all 3 prefs user/default/forced and
merges them to the effective ones
@discussion private function should only be called from within
this class
*/
function read_repository()
{
! $this->db->query("SELECT * FROM phpgw_preferences".
! " WHERE preference_owner IN
(-1,-2,".intval($this->account_id).")",__LINE__,__FILE__);
! $this->forced = $this->default = $this->user = array();
! while($this->db->next_record())
{
! $app = $this->db->f('preference_app');
! $value =
unserialize($this->db->f('preference_value'));
! $this->unquote($value);
! if (!is_array($value))
! {
! $value = array();
! }
! switch($this->db->f('preference_owner'))
! {
! case -1: // forced
! if (empty($app)) // db
not updated
! {
! $this->forced = $value;
! }
! else
! {
! $this->forced[$app] =
$value;
! }
! break;
! case -2: // default
! if (empty($app)) // db
not updated
! {
! $this->default = $value;
! }
! else
! {
! $this->default[$app] =
$value;
! }
! break;
! default: // user
! if (empty($app)) // db
not updated
! {
! $this->user = $value;
! }
! else
! {
! $this->user[$app] =
$value;
! }
! break;
! }
! }
! $this->data = $this->user;
!
! // now use defaults if needed (user-value unset or
empty)
! //
! foreach($this->default as $app => $values)
! {
! foreach($values as $var => $value)
{
! if (!isset($this->data[$app][$var]) ||
$this->data[$app][$var] === '')
{
! $this->data[$app][$var] =
$value;
}
}
}
! // now set/force forced values
! //
! foreach($this->forced as $app => $values)
{
! foreach($values as $var => $value)
! {
! $this->data[$app][$var] = $value;
! }
}
// This is to supress warnings durring login
if (is_array($this->data))
***************
*** 102,105 ****
--- 181,190 ----
reset($this->data);
}
+ if ($this->debug &&
substr($GLOBALS['phpgw_info']['flags']['currentapp'],0,3) != 'log') {
+ echo "user<pre>"; print_r($this->user); echo
"</pre>\n";
+ echo "forced<pre>"; print_r($this->forced);
echo "</pre>\n";
+ echo "default<pre>"; print_r($this->default);
echo "</pre>\n";
+ echo "effectiv<pre>";print_r($this->data); echo
"</pre>\n";
+ }
return $this->data;
}
***************
*** 129,135 ****
--- 214,222 ----
@param $var name of preference to be stored
@param $value value of the preference
+ @note the function works on user and data, to be able to save
the pref and to have imediate effect
*/
function add($app_name,$var,$value = '')
{
+ //echo "<p>add('$app_name','$var','$value')</p>\n";
if ($value == '')
{
***************
*** 138,142 ****
}
! $this->data[$app_name][$var] = $value;
reset($this->data);
return $this->data;
--- 225,229 ----
}
! $this->user[$app_name][$var] =
$this->data[$app_name][$var] = $value;
reset($this->data);
return $this->data;
***************
*** 149,163 ****
--- 236,254 ----
@param $app_name name of app
@param $var variable to be deleted
+ @note the function works on user and data, to be able to save
the pref and to have imediate effect
*/
function delete($app_name, $var = '')
{
+ //echo "<p>delete('$app_name','$var')</p>\n";
if (is_string($var) && $var == '')
{
// $this->data[$app_name] = array();
unset($this->data[$app_name]);
+ unset($this->user[$app_name]);
}
else
{
unset($this->data[$app_name][$var]);
+ unset($this->user[$app_name][$var]);
}
reset ($this->data);
***************
*** 170,182 ****
@discussion Use for sublevels of prefs, such as email app's
extra accounts preferences
@param $app_name name of the app
! @param $var String to be evaled's as an ARRAY structure, name
of preference to be stored
@param $value value of the preference
*/
function add_struct($app_name,$var,$value = '')
{
$code = '$this->data[$app_name]'.$var.' = $value;';
//echo 'class.preferences: add_struct: $code:
'.$code.'<br>';
eval($code);
! //echo 'class.preferences: add_struct:
$this->data[$app_name] dump:'; _debug_array($this->data[$app_name]); echo
'<br>';
reset($this->data);
return $this->data;
--- 261,285 ----
@discussion Use for sublevels of prefs, such as email app's
extra accounts preferences
@param $app_name name of the app
! @param $var array keys separated by '/', eg. 'ex_accounts/1'
@param $value value of the preference
+ @note the function works on user and data, to be able to save
the pref and to have imediate effect
*/
function add_struct($app_name,$var,$value = '')
{
+ /* eval is slow and dangerous
$code = '$this->data[$app_name]'.$var.' = $value;';
//echo 'class.preferences: add_struct: $code:
'.$code.'<br>';
eval($code);
! */
! $parts =
explode('/',str_replace(array('][','[',']','"',"'"),array('/','','','',''),$var));
! $data = &$this->data[$app_name];
! $user = &$this->user[$app_name];
! foreach($parts as $name)
! {
! $data = &$data[$name];
! $user = &$user[$name];
! }
! $data = $user = $value;
! print_debug('class.preferences: add_struct:
$this->data[$app_name] dump:', $this->data[$app_name],'api');
reset($this->data);
return $this->data;
***************
*** 188,195 ****
@discussion Use for sublevels of prefs, such as email app's
extra accounts preferences
@param $app_name name of app
! @param $var String to be evaled's as an ARRAY structure, name
of preference to be deleted
*/
function delete_struct($app_name, $var = '')
{
$code_1 = '$this->data[$app_name]'.$var.' = "";';
//echo 'class.preferences: delete_struct: $code_1:
'.$code_1.'<br>';
--- 291,300 ----
@discussion Use for sublevels of prefs, such as email app's
extra accounts preferences
@param $app_name name of app
! @param $var array keys separated by '/', eg. 'ex_accounts/1'
! @note the function works on user and data, to be able to save
the pref and to have imediate effect
*/
function delete_struct($app_name, $var = '')
{
+ /* eval is slow and dangerous
$code_1 = '$this->data[$app_name]'.$var.' = "";';
//echo 'class.preferences: delete_struct: $code_1:
'.$code_1.'<br>';
***************
*** 198,232 ****
//echo 'class.preferences: delete_struct: $code_2:
'.$code_2.'<br>';
eval($code_2);
! //echo ' * $this->data[$app_name] dump:';
_debug_array($this->data[$app_name]); echo '<br>';
reset ($this->data);
return $this->data;
}
!
/*!
@function save_repository
@abstract save the the preferences to the repository
! @discussion
*/
! function save_repository($update_session_info = False)
{
! $temp_data = $this->data;
if (!
$GLOBALS['phpgw']->acl->check('session_only_preferences',1,'preferences'))
{
$this->db->transaction_begin();
! $this->db->query("DELETE FROM phpgw_preferences
WHERE preference_owner=" . intval($this->account_id),
__LINE__,__FILE__);
! if (floor(phpversion()) < 4)
{
! $pref_info =
addslashes(serialize($this->data));
}
- else
- {
- $pref_info = serialize($this->data);
- }
- $this->db->query("INSERT INTO phpgw_preferences
(preference_owner,preference_value) VALUES ("
- . intval($this->account_id) . ",'" .
$pref_info . "')",__LINE__,__FILE__);
-
$this->db->transaction_commit();
}
--- 303,392 ----
//echo 'class.preferences: delete_struct: $code_2:
'.$code_2.'<br>';
eval($code_2);
! */
! $parts =
explode('/',str_replace(array('][','[',']','"',"'"),array('/','','','',''),$var));
! $last = array_pop($parts);
! $data = &$this->data[$app_name];
! $user = &$this->user[$app_name];
! foreach($parts as $name)
! {
! $data = &$data[$name];
! $user = &$user[$name];
! }
! unset($data[$last]);
! unset($user[$last]);
! print_debug('* $this->data[$app_name] dump:',
$this->data[$app_name],'api');
reset ($this->data);
return $this->data;
}
! /*!
! @function quote
! @abstract quote (addslashes) recursivly the whole array
! @param $arr array to unquote (var-param!)
! */
! function quote(&$arr)
! {
! if (!is_array($arr))
! {
! $arr = addslashes($arr);
! return;
! }
! foreach($arr as $key => $value)
! {
! if (is_array($value))
! {
! $this->quote($arr[$key]);
! }
! else
! {
! $arr[$key] = addslashes($value);
! }
! }
! }
!
/*!
@function save_repository
@abstract save the the preferences to the repository
! @syntax save_repository($update_session_info = False,$type='')
! @param $update_session_info old param, seems not to be used
! @param $type which prefs to update: user/default/forced
! @note the user prefs for saveing are in $this->user not in
$this->data, which are the effectiv prefs only
*/
! function save_repository($update_session_info =
False,$type='user')
{
! switch($type)
! {
! case 'forced':
! $account_id = -1;
! $prefs = &$this->forced;
! break;
! case 'default':
! $account_id = -2;
! $prefs = &$this->default;
! break;
! default:
! $account_id = intval($this->account_id);
! $prefs = &$this->user; // we use the
user-array as data contains default values too
! break;
! }
! //echo "<p>preferences::save_repository(,$type):
account_id=$account_id, prefs="; print_r($prefs); echo "</p>\n";
!
if (!
$GLOBALS['phpgw']->acl->check('session_only_preferences',1,'preferences'))
{
$this->db->transaction_begin();
! $this->db->query("delete from phpgw_preferences
where preference_owner=$account_id",
__LINE__,__FILE__);
! foreach($prefs as $app => $value)
{
! if (!is_array($value)) continue;
! $this->quote($value);
! $value =
$this->db->db_addslashes(serialize($value)); // this addslashes is for the
database
! $app = $this->db->db_addslashes($app);
!
! $this->db->query($sql = "INSERT INTO
phpgw_preferences".
! "
(preference_owner,preference_app,preference_value)".
! " VALUES
($account_id,'$app','$value')",__LINE__,__FILE__);
}
$this->db->transaction_commit();
}
***************
*** 237,241 ****
}
! if
($GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $this->account_id ==
$GLOBALS['phpgw_info']['user']['account_id'])
{
$GLOBALS['phpgw']->session->delete_cache($this->account_id);
--- 397,401 ----
}
! if (($type == 'user' || !$type) &&
$GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $this->account_id ==
$GLOBALS['phpgw_info']['user']['account_id'])
{
$GLOBALS['phpgw']->session->delete_cache($this->account_id);
***************
*** 243,247 ****
}
! return $temp_data;
}
--- 403,407 ----
}
! return $this->data;
}
***************
*** 254,258 ****
function create_defaults($account_id)
{
! $this->db->query("SELECT * FROM phpgw_preferences WHERE
preference_owner='-2'",__LINE__,__FILE__);
$this->db->next_record();
--- 414,419 ----
function create_defaults($account_id)
{
! return; // not longer needed, as the defaults are
merged in on runtime
! $this->db->query("select * from phpgw_preferences where
preference_owner='-2'",__LINE__,__FILE__);
$this->db->next_record();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: phpgwapi/inc class.preferences.inc.php,1.48,1.49,
Ralf Becker <address@hidden> <=
- Prev by Date:
[Phpgroupware-cvs] CVS: phpgwapi/setup setup.inc.php,1.54,1.55 tables_current.inc.php,1.43,1.44 tables_update.inc.php,1.68,1.69
- Next by Date:
[Phpgroupware-cvs] CVS: preferences preferences.php,1.31,1.32
- Previous by thread:
[Phpgroupware-cvs] CVS: phpgwapi/setup setup.inc.php,1.54,1.55 tables_current.inc.php,1.43,1.44 tables_update.inc.php,1.68,1.69
- Next by thread:
[Phpgroupware-cvs] CVS: preferences preferences.php,1.31,1.32
- Index(es):