2001-01-11 10:52:33 +01:00
< ? php
2001-02-08 01:49:34 +01:00
/************************************************************************** \
2002-01-11 03:01:24 +01:00
* phpGroupWare API - Preferences *
* This file written by Joseph Engo < jengo @ phpgroupware . org > *
* and Mark Peters < skeeter @ phpgroupware . org > *
* Manages user preferences *
2003-08-28 16:31:11 +02:00
* Copyright ( C ) 2000 , 2001 Joseph Engo *
2002-01-11 03:01:24 +01:00
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
2003-08-28 16:31:11 +02:00
* http :// www . phpgroupware . org / api *
2002-01-11 03:01:24 +01:00
* ------------------------------------------------------------------------ *
* This library is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation ; either version 2.1 of the License , *
* or any later version . *
* This library is distributed in the hope that it will be useful , but *
* WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . *
* See the GNU Lesser General Public License for more details . *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library ; if not , write to the Free Software Foundation , *
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA *
2001-02-08 01:49:34 +01:00
\ **************************************************************************/
2003-08-28 16:31:11 +02:00
2001-02-08 01:49:34 +01:00
/* $Id$ */
2002-01-11 03:01:24 +01:00
2001-03-09 05:38:42 +01:00
/*!
@ class preferences
@ abstract preferences class used for setting application preferences
2003-05-01 11:19:50 +02:00
@ 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
2001-03-09 05:38:42 +01:00
*/
2001-02-08 01:49:34 +01:00
class preferences
2001-07-26 13:13:15 +02:00
{
/*! @var account_id */
2001-02-08 01:49:34 +01:00
var $account_id ;
2001-03-09 05:38:42 +01:00
/*! @var account_type */
2001-02-08 01:49:34 +01:00
var $account_type ;
2003-05-01 11:19:50 +02:00
/*! @var data effectiv user prefs, used by all apps */
2001-08-25 22:26:22 +02:00
var $data = array ();
2003-05-01 11:19:50 +02:00
/*! @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 ();
2004-03-21 22:17:34 +01:00
/*! @var session session / tempory prefs */
var $session = array ();
2001-03-09 05:38:42 +01:00
/*! @var db */
2001-02-08 01:49:34 +01:00
var $db ;
2003-12-13 16:03:23 +01:00
2003-05-02 03:33:32 +02:00
var $values , $vars ; // standard notify substitues, will be set by standard_substitues()
2001-01-11 10:52:33 +01:00
2001-02-08 01:49:34 +01:00
/************************************************************************** \
* Standard constructor for setting $this -> account_id *
\ **************************************************************************/
2001-03-09 05:38:42 +01:00
/*!
@ function preferences
@ abstract Standard constructor for setting $this -> account_id
@ discussion Author :
*/
2001-03-19 21:25:04 +01:00
function preferences ( $account_id = '' )
2001-02-08 01:49:34 +01:00
{
2003-10-08 00:38:06 +02:00
$this -> db = is_object ( $GLOBALS [ 'phpgw' ] -> db ) ? $GLOBALS [ 'phpgw' ] -> db : $GLOBALS [ 'phpgw_setup' ] -> db ;
2003-08-28 16:31:11 +02:00
$this -> account_id = get_account_id ( $account_id );
2001-02-08 01:49:34 +01:00
}
2001-02-03 11:48:41 +01:00
2001-02-08 01:49:34 +01:00
/************************************************************************** \
* These are the standard $this -> account_id specific functions *
\ **************************************************************************/
2001-07-26 13:13:15 +02:00
2003-05-02 03:33:32 +02:00
/*!
@ function parse_notify
@ abstract parses a notify and replaces the substitutes
@ syntax parse_notify ( $msg , $values = '' , $use_standard_values = True )
@ param $msg message to parse / substitute
@ param $values extra vars to replace in addition to $this -> values , vars are in an array with \
$key => $value pairs , $key does not include the $ ' s and is the * untranslated * name
@ param $use_standard_values should the standard values are used
@ returns the parsed notify - msg
*/
function parse_notify ( $msg , $values = '' , $use_standard_values = True )
{
$vals = $values ? $values : array ();
if ( $use_standard_values && is_array ( $this -> values ))
{
$vals += $this -> values ;
}
foreach ( $vals as $key => $val )
{
$replace [] = '$$' . $key . '$$' ;
$with [] = $val ;
}
return str_replace ( $replace , $with , $msg );
}
/*!
@ function lang_notify
@ abstract replaces the english key ' s with translated ones , or if $un_lang the opposite
@ syntax lang_notify ( $msg , $values = '' , $un_lang = False )
@ param $msg message to translate
@ param $values extra vars to replace in addition to $this -> values , vars are in an array with \
$key => $value pairs , $key does not include the $ ' s and is the * untranslated * name
@ param $un_lang if true translate back
@ returns the result
*/
function lang_notify ( $msg , $vals = array (), $un_lang = False )
{
foreach ( $vals as $key => $val )
{
$lname = ( $lname = lang ( $key )) == $key . '*' ? $key : $lname ;
if ( $un_lang )
{
$langs [ $lname ] = '$$' . $key . '$$' ;
}
else
{
$langs [ $key ] = '$$' . $lname . '$$' ;
}
}
return $this -> parse_notify ( $msg , $langs , False );
}
/*!
@ function standard_substitues
@ abstract define some standard substitues - values and use them on the prefs , if needed
*/
function standard_substitutes ()
{
2003-10-24 02:54:28 +02:00
if ( ! is_array ( @ $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ]))
2003-05-02 03:33:32 +02:00
{
$GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ] = $this -> data ; // else no lang()
}
// we cant use phpgw_info/user/fullname, as it's not set when we run
$GLOBALS [ 'phpgw' ] -> accounts -> get_account_name ( $this -> account_id , $lid , $fname , $lname );
$this -> values = array ( // standard notify replacements
2003-05-17 22:37:51 +02:00
'fullname' => $GLOBALS [ 'phpgw' ] -> common -> display_fullname ( '' , $fname , $lname ),
2003-05-02 03:33:32 +02:00
'firstname' => $fname ,
'lastname' => $lname ,
2003-05-04 12:30:38 +02:00
'domain' => $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_suffix' ],
2003-05-02 03:33:32 +02:00
'email' => $this -> email_address ( $this -> account_id ),
'date' => $GLOBALS [ 'phpgw' ] -> common -> show_date ( '' , $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ]),
);
2003-05-04 12:30:38 +02:00
// do this first, as it might be already contain some substitues
//
$this -> values [ 'email' ] = $this -> parse_notify ( $this -> values [ 'email' ]);
2003-05-02 03:33:32 +02:00
$this -> vars = array ( // langs have to be in common !!!
2003-05-17 22:37:51 +02:00
'fullname' => lang ( 'name of the user, eg. "%1"' , $this -> values [ 'fullname' ]),
2003-05-02 03:33:32 +02:00
'firstname' => lang ( 'first name of the user, eg. "%1"' , $this -> values [ 'firstname' ]),
'lastname' => lang ( 'last name of the user, eg. "%1"' , $this -> values [ 'lastname' ]),
2003-05-04 12:30:38 +02:00
'domain' => lang ( 'domain name for mail-address, eg. "%1"' , $this -> values [ 'domain' ]),
2003-05-02 03:33:32 +02:00
'email' => lang ( 'email-address of the user, eg. "%1"' , $this -> values [ 'email' ]),
'date' => lang ( 'todays date, eg. "%1"' , $this -> values [ 'date' ]),
);
// do the substituetion in the effective prefs (data)
//
foreach ( $this -> data as $app => $data )
{
foreach ( $data as $key => $val )
{
if ( ! is_array ( $val ) && strstr ( $val , '$$' ) !== False )
{
$this -> data [ $app ][ $key ] = $this -> parse_notify ( $val );
}
elseif ( is_array ( $val ))
{
foreach ( $val as $k => $v )
{
if ( ! is_array ( $v ) && strstr ( $val , '$$' ) !== False )
{
$this -> data [ $app ][ $key ][ $k ] = $this -> parse_notify ( $v );
}
}
}
}
}
}
2003-05-01 11:19:50 +02:00
/*!
@ 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
{
2003-12-13 16:03:23 +01:00
$arr [ $key ] = stripslashes ( $value );
2003-05-01 11:19:50 +02:00
}
}
}
2001-03-09 05:38:42 +01:00
/*!
@ function read_repository
@ abstract private - read preferences from the repository
2003-05-01 11:19:50 +02:00
@ note the function ready all 3 prefs user / default / forced and merges them to the effective ones
2001-03-09 05:38:42 +01:00
@ discussion private function should only be called from within this class
*/
2001-02-08 01:49:34 +01:00
function read_repository ()
{
2004-03-21 22:17:34 +01:00
$this -> session = $GLOBALS [ 'phpgw' ] -> session -> appsession ( 'preferences' , 'preferences' );
if ( ! is_array ( $this -> session ))
{
$this -> session = array ();
}
2003-12-13 16:03:23 +01:00
$this -> db -> query ( " SELECT * FROM phpgw_preferences "
. " WHERE preference_owner IN (-1,-2, " . ( int ) $this -> account_id . ')' , __LINE__ , __FILE__ );
2001-08-25 22:26:22 +02:00
2003-05-01 11:19:50 +02:00
$this -> forced = $this -> default = $this -> user = array ();
while ( $this -> db -> next_record ())
2001-08-25 22:26:22 +02:00
{
2003-12-20 19:32:53 +01:00
// The following replacement is required for PostgreSQL to work
$app = str_replace ( ' ' , '' , $this -> db -> f ( 'preference_app' ));
2003-05-01 11:19:50 +02:00
$value = unserialize ( $this -> db -> f ( 'preference_value' ));
$this -> unquote ( $value );
if ( ! is_array ( $value ))
{
2003-05-02 03:33:32 +02:00
continue ;
2003-05-01 11:19:50 +02:00
}
switch ( $this -> db -> f ( 'preference_owner' ))
{
case - 1 : // forced
2003-05-02 03:33:32 +02:00
$this -> forced [ $app ] = $value ;
2003-05-01 11:19:50 +02:00
break ;
case - 2 : // default
2003-05-02 03:33:32 +02:00
$this -> default [ $app ] = $value ;
2003-05-01 11:19:50 +02:00
break ;
default : // user
2003-05-02 03:33:32 +02:00
$this -> user [ $app ] = $value ;
2003-05-01 11:19:50 +02:00
break ;
}
}
2004-03-21 22:17:34 +01:00
$this -> data = array_merge_recursive ( $this -> user , $this -> session );
2003-08-28 16:31:11 +02:00
2003-05-01 11:19:50 +02:00
// now use defaults if needed (user-value unset or empty)
//
foreach ( $this -> default as $app => $values )
{
foreach ( $values as $var => $value )
2001-08-25 22:26:22 +02:00
{
2003-05-01 11:19:50 +02:00
if ( ! isset ( $this -> data [ $app ][ $var ]) || $this -> data [ $app ][ $var ] === '' )
2001-08-25 22:26:22 +02:00
{
2003-05-01 11:19:50 +02:00
$this -> data [ $app ][ $var ] = $value ;
2001-08-25 22:26:22 +02:00
}
}
}
2003-05-01 11:19:50 +02:00
// now set/force forced values
//
foreach ( $this -> forced as $app => $values )
2001-07-26 13:13:15 +02:00
{
2003-05-01 11:19:50 +02:00
foreach ( $values as $var => $value )
{
$this -> data [ $app ][ $var ] = $value ;
}
2001-02-08 01:49:34 +01:00
}
2003-12-20 19:32:53 +01:00
// setup the standard substitutes and substitutes the data in $this->data
2003-05-02 03:33:32 +02:00
//
$this -> standard_substitutes ();
2003-12-13 16:03:23 +01:00
2003-12-20 19:32:53 +01:00
// This is to supress warnings during login
2001-08-25 22:26:22 +02:00
if ( is_array ( $this -> data ))
{
reset ( $this -> data );
}
2003-12-20 19:32:53 +01:00
if ( isset ( $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 " ;
2003-05-01 11:19:50 +02:00
}
2001-02-08 01:49:34 +01:00
return $this -> data ;
}
2001-07-26 13:13:15 +02:00
2001-03-09 05:38:42 +01:00
/*!
@ function read
@ abstract public - read preferences from repository and stores in an array
@ discussion Syntax array read (); <>
Example1 : preferences -> read ();
@ result $data array containing user preferences
*/
2001-02-08 01:49:34 +01:00
function read ()
{
2001-07-26 13:13:15 +02:00
if ( count ( $this -> data ) == 0 )
{
$this -> read_repository ();
}
2001-02-08 01:49:34 +01:00
reset ( $this -> data );
return $this -> data ;
}
2001-07-26 13:13:15 +02:00
2001-03-09 05:38:42 +01:00
/*!
@ function add
@ abstract add preference to $app_name a particular app
@ discussion
@ param $app_name name of the app
@ param $var name of preference to be stored
@ param $value value of the preference
2003-05-20 01:05:32 +02:00
@ param $type of preference to set : forced , default , user
@ note the effective prefs ( $this -> data ) are updated to reflect the change
@ returns the new effective prefs ( even when forced or default prefs are set ! )
2001-03-09 05:38:42 +01:00
*/
2003-05-20 01:05:32 +02:00
function add ( $app_name , $var , $value = '##undef##' , $type = 'user' )
2001-02-08 01:49:34 +01:00
{
2003-05-01 11:19:50 +02:00
//echo "<p>add('$app_name','$var','$value')</p>\n";
2003-10-03 12:00:21 +02:00
if ( $value === '##undef##' )
2001-07-26 13:13:15 +02:00
{
2001-02-08 01:49:34 +01:00
global $$var ;
$value = $$var ;
}
2001-01-11 10:52:33 +01:00
2003-05-20 01:05:32 +02:00
switch ( $type )
{
2004-03-21 22:17:34 +01:00
case 'session' :
if ( ! isset ( $this -> forced [ $app_name ][ $var ]) || $this -> forced [ $app_name ][ $var ] === '' )
{
$this -> session [ $app_name ][ $var ] = $this -> data [ $app_name ][ $var ] = $value ;
$GLOBALS [ 'phpgw' ] -> sessions -> appsession ( 'preferences' , 'preferences' , $this -> session );
}
break ;
2003-05-20 01:05:32 +02:00
case 'forced' :
$this -> data [ $app_name ][ $var ] = $this -> forced [ $app_name ][ $var ] = $value ;
break ;
case 'default' :
$this -> default [ $app_name ][ $var ] = $value ;
if (( ! isset ( $this -> forced [ $app_name ][ $var ]) || $this -> forced [ $app_name ][ $var ] === '' ) &&
2003-12-13 16:03:23 +01:00
( ! isset ( $this -> user [ $app_name ][ $var ]) || $this -> user [ $app_name ][ $var ] === '' ))
2003-05-20 01:05:32 +02:00
{
$this -> data [ $app_name ][ $var ] = $value ;
}
break ;
case user :
default :
$this -> user [ $app_name ][ $var ] = $value ;
if ( ! isset ( $this -> forced [ $app_name ][ $var ]) || $this -> forced [ $app_name ][ $var ] === '' )
{
$this -> data [ $app_name ][ $var ] = $value ;
}
break ;
}
2001-02-08 01:49:34 +01:00
reset ( $this -> data );
return $this -> data ;
}
2001-07-26 13:13:15 +02:00
2001-03-09 05:38:42 +01:00
/*!
@ function delete
@ abstract delete preference from $app_name
@ discussion
@ param $app_name name of app
@ param $var variable to be deleted
2003-05-20 01:05:32 +02:00
@ param $type of preference to set : forced , default , user
@ note the effektive prefs ( $this -> data ) are updated to reflect the change
@ returns the new effective prefs ( even when forced or default prefs are deleted ! )
2001-03-09 05:38:42 +01:00
*/
2003-05-20 01:05:32 +02:00
function delete ( $app_name , $var = False , $type = 'user' )
2001-02-08 01:49:34 +01:00
{
2003-09-06 05:23:37 +02:00
//echo "<p>delete('$app_name','$var','$type')</p>\n";
2003-05-20 01:05:32 +02:00
$set_via = array (
'forced' => array ( 'user' , 'default' ),
'default' => array ( 'forced' , 'user' ),
'user' => array ( 'forced' , 'default' )
);
if ( ! isset ( $set_via [ $type ]))
2001-07-26 13:13:15 +02:00
{
2003-05-20 01:05:32 +02:00
$type = 'user' ;
}
2003-09-06 05:23:37 +02:00
$pref = & $this -> $type ;
2003-05-20 01:05:32 +02:00
if ( $all = ( is_string ( $var ) && $var == '' ))
{
2003-09-06 05:23:37 +02:00
unset ( $pref [ $app_name ]);
2001-10-21 12:49:29 +02:00
unset ( $this -> data [ $app_name ]);
2001-07-26 13:13:15 +02:00
}
else
{
2003-09-06 05:23:37 +02:00
unset ( $pref [ $app_name ][ $var ]);
2001-02-08 01:49:34 +01:00
unset ( $this -> data [ $app_name ][ $var ]);
2003-05-20 01:05:32 +02:00
}
// set the effectiv pref again if needed
//
foreach ( $set_via [ $type ] as $set_from )
{
if ( $all )
{
if ( isset ( $this -> $set_from [ $app_name ]))
{
$this -> data [ $app_name ] = $this -> $set_from [ $app_name ];
break ;
}
}
else
{
2003-12-27 19:05:20 +01:00
$arr = $this -> $set_from ;
if ( $var && @ isset ( $arr [ $app_name ][ $var ]) && $arr [ $app_name ][ $var ] !== '' )
2003-05-20 01:05:32 +02:00
{
$this -> data [ $app_name ][ $var ] = $this -> $set_from [ $app_name ][ $var ];
break ;
}
2003-12-27 19:05:20 +01:00
unset ( $arr );
2003-05-20 01:05:32 +02:00
}
2001-02-08 01:49:34 +01:00
}
reset ( $this -> data );
return $this -> data ;
}
2001-07-26 13:13:15 +02:00
2002-01-10 11:09:10 +01:00
/*!
@ function add_struct
@ abstract add complex array data preference to $app_name a particular app
@ discussion Use for sublevels of prefs , such as email app ' s extra accounts preferences
@ param $app_name name of the app
2003-05-01 11:19:50 +02:00
@ param $var array keys separated by '/' , eg . 'ex_accounts/1'
2002-01-10 11:09:10 +01:00
@ param $value value of the preference
2003-05-01 11:19:50 +02:00
@ note the function works on user and data , to be able to save the pref and to have imediate effect
2002-01-10 11:09:10 +01:00
*/
function add_struct ( $app_name , $var , $value = '' )
{
2003-05-01 11:19:50 +02:00
/* eval is slow and dangerous
2002-01-10 11:09:10 +01:00
$code = '$this->data[$app_name]' . $var . ' = $value;' ;
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: add_struct: $code: ' , $code , 'api' );
2002-01-10 11:09:10 +01:00
eval ( $code );
2003-05-01 11:19:50 +02:00
*/
$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' );
2002-01-10 11:09:10 +01:00
reset ( $this -> data );
return $this -> data ;
}
/*!
@ function delete_struct
@ abstract delete complex array data preference from $app_name
@ discussion Use for sublevels of prefs , such as email app ' s extra accounts preferences
@ param $app_name name of app
2003-05-01 11:19:50 +02:00
@ param $var array keys separated by '/' , eg . 'ex_accounts/1'
2003-12-20 19:32:53 +01:00
@ note the function works on user and data , to be able to save the pref and to have immediate effect
2002-01-10 11:09:10 +01:00
*/
function delete_struct ( $app_name , $var = '' )
{
2003-05-01 11:19:50 +02:00
/* eval is slow and dangerous
2002-01-10 11:09:10 +01:00
$code_1 = '$this->data[$app_name]' . $var . ' = "";' ;
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: delete_struct: $code_1:' , $code_1 , 'api' );
2002-01-10 11:09:10 +01:00
eval ( $code_1 );
$code_2 = 'unset($this->data[$app_name]' . $var . ');' ;
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: delete_struct: $code_2: ' , $code_2 , 'api' );
2002-01-10 11:09:10 +01:00
eval ( $code_2 );
2003-05-01 11:19:50 +02:00
*/
$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' );
2002-01-10 11:09:10 +01:00
reset ( $this -> data );
return $this -> data ;
}
2003-05-01 11:19:50 +02:00
/*!
@ 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 );
}
}
}
2003-12-13 16:03:23 +01:00
2001-03-09 05:38:42 +01:00
/*!
@ function save_repository
@ abstract save the the preferences to the repository
2003-05-01 11:19:50 +02:00
@ 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
2001-03-09 05:38:42 +01:00
*/
2003-05-01 11:19:50 +02:00
function save_repository ( $update_session_info = False , $type = 'user' )
2001-02-08 01:49:34 +01:00
{
2003-05-01 11:19:50 +02:00
switch ( $type )
{
case 'forced' :
$account_id = - 1 ;
$prefs = & $this -> forced ;
break ;
case 'default' :
$account_id = - 2 ;
$prefs = & $this -> default ;
break ;
default :
2003-12-13 16:03:23 +01:00
$account_id = ( int ) $this -> account_id ;
2003-05-01 11:19:50 +02:00
$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";
2001-10-02 05:52:56 +02:00
if ( ! $GLOBALS [ 'phpgw' ] -> acl -> check ( 'session_only_preferences' , 1 , 'preferences' ))
2001-04-04 06:54:12 +02:00
{
2001-06-04 03:17:40 +02:00
$this -> db -> transaction_begin ();
2003-12-13 16:03:23 +01:00
$this -> db -> query ( " DELETE FROM phpgw_preferences WHERE preference_owner=' $account_id ' " ,
__LINE__ , __FILE__
);
2001-06-22 02:49:32 +02:00
2003-05-01 11:19:50 +02:00
foreach ( $prefs as $app => $value )
2001-04-04 06:54:12 +02:00
{
2003-12-20 19:32:53 +01:00
if ( ! is_array ( $value ))
{
continue ;
}
2003-05-01 11:19:50 +02:00
$this -> quote ( $value );
2003-08-28 16:31:11 +02:00
$value = addslashes ( serialize ( $value )); // this addslashes is for the database
2003-05-01 11:19:50 +02:00
$app = $this -> db -> db_addslashes ( $app );
2003-12-20 19:32:53 +01:00
2003-12-13 16:03:23 +01:00
$this -> db -> query ( $sql = " INSERT INTO phpgw_preferences "
. " (preference_owner,preference_app,preference_value) "
. " VALUES ( $account_id ,' $app ',' $value ') " , __LINE__ , __FILE__ );
2001-04-04 06:54:12 +02:00
}
2001-06-04 03:17:40 +02:00
$this -> db -> transaction_commit ();
2001-02-08 01:49:34 +01:00
}
2001-04-04 06:54:12 +02:00
else
{
2001-10-02 05:52:56 +02:00
$GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ] = $this -> data ;
$GLOBALS [ 'phpgw' ] -> session -> save_repositories ();
2001-02-08 01:49:34 +01:00
}
2001-04-04 06:54:12 +02:00
2003-05-01 11:19:50 +02:00
if (( $type == 'user' || ! $type ) && $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'cache_phpgw_info' ] && $this -> account_id == $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ])
2001-04-04 06:54:12 +02:00
{
2002-01-13 04:58:41 +01:00
$GLOBALS [ 'phpgw' ] -> session -> delete_cache ( $this -> account_id );
2001-10-02 05:52:56 +02:00
$GLOBALS [ 'phpgw' ] -> session -> read_repositories ( False );
2001-06-22 02:49:32 +02:00
}
2003-12-13 16:03:23 +01:00
2003-05-01 11:19:50 +02:00
return $this -> data ;
2001-02-08 01:49:34 +01:00
}
2001-07-26 13:13:15 +02:00
2002-01-03 19:11:10 +01:00
/*!
@ function create_defaults
@ abstract insert a copy of the default preferences for use by real account_id
@ discussion
@ param $account_id numerical id of account for which to create the prefs
*/
2001-10-05 05:15:45 +02:00
function create_defaults ( $account_id )
{
2003-05-01 11:19:50 +02:00
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__ );
2001-10-05 05:15:45 +02:00
$this -> db -> next_record ();
2002-01-03 19:11:10 +01:00
if ( $this -> db -> f ( 'preference_value' ))
{
2003-08-28 16:31:11 +02:00
$this -> db -> query ( " insert into phpgw_preferences values (' $account_id ',' "
2002-01-03 19:11:10 +01:00
. $this -> db -> f ( 'preference_value' ) . " ') " , __LINE__ , __FILE__ );
}
2003-12-13 16:03:23 +01:00
2002-01-13 04:58:41 +01:00
if ( $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'cache_phpgw_info' ] && $account_id == $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'account_id' ])
{
$GLOBALS [ 'phpgw' ] -> session -> read_repositories ( False );
}
2001-10-05 05:15:45 +02:00
}
2001-03-09 05:38:42 +01:00
/*!
@ function update_data
@ abstract update the preferences array
@ discussion
@ param $data array of preferences
*/
2001-07-26 13:13:15 +02:00
function update_data ( $data )
{
2001-02-08 01:49:34 +01:00
reset ( $data );
$this -> data = Array ();
$this -> data = $data ;
reset ( $this -> data );
return $this -> data ;
}
2001-01-11 10:52:33 +01:00
2001-02-08 01:49:34 +01:00
/* legacy support */
function change ( $app_name , $var , $value = " " )
{
return $this -> add ( $app_name , $var , $value );
}
2001-06-22 02:49:32 +02:00
function commit ( $update_session_info = True )
2001-02-08 01:49:34 +01:00
{
2003-08-28 16:31:11 +02:00
//return $this->save_repository($update_session_info);
2001-02-08 01:49:34 +01:00
}
2001-02-05 23:30:21 +01:00
2001-02-08 01:49:34 +01:00
/************************************************************************** \
* These are the non - standard $this -> account_id specific functions *
\ **************************************************************************/
2001-07-26 13:13:15 +02:00
2001-03-09 05:38:42 +01:00
/*!
@ function verify_basic_settings
@ abstract verify basic settings
@ discussion
*/
2001-02-08 01:49:34 +01:00
function verify_basic_settings ()
{
2003-12-13 16:03:23 +01:00
if ( !@ is_array ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ]))
2001-07-26 13:13:15 +02:00
{
2003-12-13 16:03:23 +01:00
$GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ] = array ();
2001-02-08 01:49:34 +01:00
}
2003-12-13 16:03:23 +01:00
/* This takes care of new users who don't have proper default prefs setup */
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'nocommon_preferences' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'flags' ][ 'nocommon_preferences' ])
2001-07-26 13:13:15 +02:00
{
2001-05-14 05:54:40 +02:00
$preferences_update = False ;
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'maxmatchs' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'maxmatchs' ])
2001-07-26 13:13:15 +02:00
{
$this -> add ( 'common' , 'maxmatchs' , 15 );
2001-02-08 01:49:34 +01:00
$preferences_update = True ;
}
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ])
2001-07-26 13:13:15 +02:00
{
$this -> add ( 'common' , 'theme' , 'default' );
2001-02-08 01:49:34 +01:00
$preferences_update = True ;
}
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'template_set' ])
2001-07-26 13:13:15 +02:00
{
$this -> add ( 'common' , 'template_set' , 'default' );
2001-02-08 01:49:34 +01:00
$preferences_update = True ;
}
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ])
2001-07-26 13:13:15 +02:00
{
$this -> add ( 'common' , 'dateformat' , 'm/d/Y' );
2001-02-08 01:49:34 +01:00
$preferences_update = True ;
}
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ])
2001-07-26 13:13:15 +02:00
{
$this -> add ( 'common' , 'timeformat' , 12 );
2001-02-08 01:49:34 +01:00
$preferences_update = True ;
}
2001-10-02 05:52:56 +02:00
if ( ! isset ( $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'lang' ]) ||
! $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'lang' ])
2001-07-26 13:13:15 +02:00
{
2001-10-02 05:52:56 +02:00
$this -> add ( 'common' , 'lang' , $GLOBALS [ 'phpgw' ] -> common -> getPreferredLanguage ());
2001-02-08 01:49:34 +01:00
$preferences_update = True ;
}
2001-05-14 05:54:40 +02:00
if ( $preferences_update )
{
2001-02-08 01:49:34 +01:00
$this -> save_repository ();
}
unset ( $preferences_update );
}
}
2001-12-24 05:53:07 +01:00
/**************************************************** \
* Email Preferences and Private Support Functions *
\ ****************************************************/
2001-11-12 22:44:31 +01:00
/*!
2001-12-17 19:37:59 +01:00
@ function sub_get_mailsvr_port
@ abstract Helper function for create_email_preferences , gets mail server port number .
2001-11-12 22:44:31 +01:00
@ discussion This will generate the appropriate port number to access a
2001-12-17 19:37:59 +01:00
mail server of type pop3 , pop3s , imap , imaps users value from
$phpgw_info [ 'user' ][ 'preferences' ][ 'email' ][ 'mail_port' ] .
if that value is not set , it generates a default port for the given $server_type .
Someday , this * MAY * be
( a ) a se4rver wide admin setting , or
( b ) user custom preference
Until then , simply set the port number based on the mail_server_type , thereof
ONLY call this function AFTER [ 'email' ][ 'mail_server_type' ] has been set .
@ param $prefs - user preferences array based on element [ 'email' ][]
@ author Angles
@ access Private
2001-12-24 05:53:07 +01:00
*/
2003-08-28 16:31:11 +02:00
function sub_get_mailsvr_port ( $prefs , $acctnum = 0 )
2001-11-12 22:44:31 +01:00
{
// first we try the port number supplied in preferences
2003-12-13 16:03:23 +01:00
if (( isset ( $prefs [ 'email' ][ 'accounts' ][ $acctnum ][ 'mail_port' ])) &&
( $prefs [ 'email' ][ 'accounts' ][ $acctnum ][ 'mail_port' ] != '' ))
2001-11-12 22:44:31 +01:00
{
2003-08-28 16:31:11 +02:00
$port_number = $prefs [ 'email' ][ 'accounts' ][ $acctnum ][ 'mail_port' ];
2001-11-12 22:44:31 +01:00
}
// preferences does not have a port number, generate a default value
else
{
2003-08-28 16:31:11 +02:00
if ( ! isset ( $prefs [ 'email' ][ 'accounts' ][ $acctnum ][ 'mail_server_type' ]))
{
$prefs [ 'email' ][ 'accounts' ][ $acctnum ][ 'mail_server_type' ] = $prefs [ 'email' ][ 'mail_server_type' ];
}
2003-12-13 16:03:23 +01:00
2003-08-28 16:31:11 +02:00
switch ( $prefs [ 'email' ][ 'accounts' ][ $acctnum ][ 'mail_server_type' ])
2001-11-12 22:44:31 +01:00
{
2001-12-24 05:53:07 +01:00
case 'pop3s' :
// POP3 over SSL
2001-11-12 22:44:31 +01:00
$port_number = 995 ;
break ;
2001-12-24 05:53:07 +01:00
case 'pop3' :
// POP3 normal connection, No SSL
// ( same string as normal imap above)
2001-11-12 22:44:31 +01:00
$port_number = 110 ;
break ;
2001-12-24 05:53:07 +01:00
case 'nntp' :
// NNTP news server port
2001-11-12 22:44:31 +01:00
$port_number = 119 ;
break ;
2003-08-28 16:31:11 +02:00
case 'imaps' :
// IMAP over SSL
$port_number = 993 ;
break ;
2001-12-24 05:53:07 +01:00
case 'imap' :
// IMAP normal connection, No SSL
default :
// UNKNOWN SERVER in Preferences, return a
// default value that is likely to work
// probably should raise some kind of error here
2001-11-12 22:44:31 +01:00
$port_number = 143 ;
break ;
}
2003-08-28 16:31:11 +02:00
}
2001-11-12 22:44:31 +01:00
return $port_number ;
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
/*!
@ function sub_default_userid
@ abstract Helper function for create_email_preferences , gets default userid for email
@ discussion This will generate the appropriate userid for accessing an email server .
In the absence of a custom [ 'email' ][ 'userid' ], this function should be used to set it .
@ param $accountid - as determined in and / or passed to " create_email_preferences "
@ access Private
*/
function sub_default_userid ( $account_id = '' )
{
if ( $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_login_type' ] == 'vmailmgr' )
{
$prefs_email_userid = $GLOBALS [ 'phpgw' ] -> accounts -> id2name ( $account_id )
. '@' . $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_suffix' ];
}
else
{
$prefs_email_userid = $GLOBALS [ 'phpgw' ] -> accounts -> id2name ( $account_id );
}
return $prefs_email_userid ;
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
/*!
2003-05-02 03:33:32 +02:00
@ function email_address
@ abstract returns the custom email - address ( if set ) or generates a default one
2001-12-17 19:37:59 +01:00
@ discussion This will generate the appropriate email address used as the " From: "
email address when the user sends email , the localpert @ domain part . The " personal "
part is generated elsewhere .
In the absence of a custom [ 'email' ][ 'address' ], this function should be used to set it .
@ param $accountid - as determined in and / or passed to " create_email_preferences "
2003-05-02 03:33:32 +02:00
@ access Public now
2001-12-17 19:37:59 +01:00
*/
2003-05-02 03:33:32 +02:00
function email_address ( $account_id = '' )
2001-12-17 19:37:59 +01:00
{
2003-10-24 02:54:28 +02:00
if ( isset ( $this -> data [ 'email' ][ 'address' ]))
2003-05-02 03:33:32 +02:00
{
return $this -> data [ 'email' ][ 'address' ];
}
$prefs_email_address = $GLOBALS [ 'phpgw' ] -> accounts -> id2name ( $account_id );
if ( strstr ( $prefs_email_address , '@' ) === False )
{
$prefs_email_address .= '@' . $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_suffix' ];
}
2001-12-17 19:37:59 +01:00
return $prefs_email_address ;
}
2001-12-24 05:53:07 +01:00
2003-05-03 12:58:46 +02:00
function sub_default_address ( $account_id = '' )
{
return $this -> email_address ( $account_id );
}
2001-11-12 22:44:31 +01:00
/*!
@ function create_email_preferences
@ abstract create email preferences
2001-12-17 19:37:59 +01:00
@ param $account_id - optional defaults to : get_account_id ()
@ discussion fills a local copy of [ 'email' ][] prefs array which is then returned to the calling
function , which the calling function generally tacks onto the $GLOBALS [ 'phpgw_info' ] array as such :
2001-12-01 01:03:30 +01:00
$GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ] = $GLOBALS [ 'phpgw' ] -> preferences -> create_email_preferences ();
which fills an array based at :
2001-12-17 19:37:59 +01:00
$GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'email' ][ prefs_are_elements_here ]
Reading the raw preference DB data and comparing to the email preference schema defined in
/ email / class . bopreferences . inc . php ( see discussion there and below ) to create default preference values
for the in the [ 'email' ][] pref data array in cases where the user has not supplied
a preference value for any particular preference item available to the user .
@ access Public
2001-12-24 05:53:07 +01:00
*/
2003-08-28 16:31:11 +02:00
function create_email_preferences ( $accountid = '' , $acctnum = 0 )
2001-11-12 22:44:31 +01:00
{
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: create_email_preferences: ENTERING<br>' , 'messageonly' , 'api' );
2001-12-17 19:37:59 +01:00
// we may need function "html_quotes_decode" from the mail_msg class
$email_base = CreateObject ( " email.mail_msg " );
2001-12-24 05:53:07 +01:00
2001-11-12 22:44:31 +01:00
$account_id = get_account_id ( $accountid );
// If the current user is not the request user, grab the preferences
// and reset back to current user.
if ( $account_id != $this -> account_id )
{
// Temporarily store the values to a temp, so when the
// read_repository() is called, it doesn't destory the
// current users settings.
$temp_account_id = $this -> account_id ;
$temp_data = $this -> data ;
2001-12-24 05:53:07 +01:00
2001-11-12 22:44:31 +01:00
// Grab the new users settings, only if they are not the
// current users settings.
$this -> account_id = $account_id ;
$prefs = $this -> read_repository ();
2001-12-24 05:53:07 +01:00
2001-11-12 22:44:31 +01:00
// Reset the data to what it was prior to this call
$this -> account_id = $temp_account_id ;
$this -> data = $temp_data ;
}
else
{
$prefs = $this -> data ;
}
2002-01-10 11:09:10 +01:00
// are we dealing with the default email account or an extra email account?
2003-08-28 16:31:11 +02:00
if ( $acctnum != 0 )
2002-01-10 11:09:10 +01:00
{
// prefs are actually a sub-element of the main email prefs
// at location [email][ex_accounts][X][...pref names] => pref values
// make this look like "prefs[email] so the code below code below will do its job transparently
// store original prefs
$orig_prefs = array ();
$orig_prefs = $prefs ;
// obtain the desired sub-array of extra account prefs
$sub_prefs = array ();
$sub_prefs [ 'email' ] = $prefs [ 'email' ][ 'ex_accounts' ][ $acctnum ];
// make the switch, make it seem like top level email prefs
$prefs = array ();
$prefs [ 'email' ] = $sub_prefs [ 'email' ];
// since we return just $prefs, it's up to the calling program to put the sub prefs in the right place
}
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: create_email_preferences: $acctnum: [' . $acctnum . '] ; raw $this->data dump' , $this -> data , 'api' );
2001-11-12 22:44:31 +01:00
2001-12-17 19:37:59 +01:00
// = = = = NOT-SIMPLE PREFS = = = =
// Default Preferences info that is:
// (a) not controlled by email prefs itself (mostly api and/or server level stuff)
// (b) too complicated to be described in the email prefs data array instructions
2002-01-10 11:09:10 +01:00
2001-12-17 19:37:59 +01:00
// --- [server][mail_server_type] ---
// Set API Level Server Mail Type if not defined
// if for some reason the API didnot have a mail server type set during initialization
if ( empty ( $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_server_type' ]))
2001-11-12 22:44:31 +01:00
{
2001-12-17 19:37:59 +01:00
$GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_server_type' ] = 'imap' ;
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- [server][mail_folder] ---
// ==== UWash Mail Folder Location used to be "mail", now it's changeable, but keep the
// ==== default to "mail" so upgrades happen transparently
// --- TEMP MAKE DEFAULT UWASH MAIL FOLDER ~/mail (a.k.a. $HOME/mail)
$GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_folder' ] = 'mail' ;
// --- DELETE THE ABOVE WHEN THIS OPTION GETS INTO THE SYSTEM SETUP
// pick up custom "mail_folder" if it exists (used for UWash and UWash Maildir servers)
// else use the system default (which we temporarily hard coded to "mail" just above here)
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
//--- [email][mail_port] ---
// These sets the mail_port server variable
// someday (not currently) this may be a site-wide property set during site setup
// additionally, someday (not currently) the user may be able to override this with
// a custom email preference. Currently, we simply use standard port numbers
// for the service in question.
$prefs [ 'email' ][ 'mail_port' ] = $this -> sub_get_mailsvr_port ( $prefs );
2003-12-13 16:03:23 +01:00
2002-01-10 11:09:10 +01:00
//--- [email][fullname] ---
// we pick this up from phpgw api for the default account
// the user does not directly manipulate this pref for the default email account
if (( string ) $acctnum == '0' )
{
$prefs [ 'email' ][ 'fullname' ] = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'fullname' ];
}
2003-12-13 16:03:23 +01:00
2001-12-17 19:37:59 +01:00
// = = = = SIMPLER PREFS = = = =
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// Default Preferences info that is articulated in the email prefs schema array itself
// such email prefs schema array is described and established in /email/class.bopreferences
// by function "init_available_prefs", see the discussion there.
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- create the objectified /email/class.bopreferences.inc.php ---
$bo_mail_prefs = CreateObject ( 'email.bopreferences' );
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- bo_mail_prefs->init_available_prefs() ---
// this fills object_email_bopreferences->std_prefs and ->cust_prefs
// we will initialize the users preferences according to the rules and instructions
// embodied in those prefs arrays, applying those rules to the unprocessed
// data read from the preferences DB. By taking the raw data and applying those rules,
// we will construct valid and known email preference data for this user.
$bo_mail_prefs -> init_available_prefs ();
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- combine the two array (std and cust) for 1 pass handling ---
// when this preference DB was submitted and saved, it was hopefully so well structured
// that we can simply combine the two arrays, std_prefs and cust_prefs, and do a one
// pass analysis and preparation of this users preferences.
$avail_pref_array = $bo_mail_prefs -> std_prefs ;
$c_cust_prefs = count ( $bo_mail_prefs -> cust_prefs );
for ( $i = 0 ; $i < $c_cust_prefs ; $i ++ )
{
// add each custom prefs to the std prefs array
$next_idx = count ( $avail_pref_array );
$avail_pref_array [ $next_idx ] = $bo_mail_prefs -> cust_prefs [ $i ];
}
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: create_email_preferences: std AND cust arrays combined:' , $avail_pref_array , 'api' );
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- make the schema-based pref data for this user ---
// user defined values and/or user specified custom email prefs are read from the
// prefs DB with mininal manipulation of the data. Currently the only change to
// users raw data is related to reversing the encoding of "database un-friendly" chars
// which itself may become unnecessary if and when the database handlers can reliably
// take care of this for us. Of course, password data requires special decoding,
// but the password in the array [email][paswd] should be left in encrypted form
// and only decrypted seperately when used to login in to an email server.
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- generating a default value if necessary ---
// in the absence of a user defined custom email preference for a particular item, we can
// determine the desired default value for that pref as such:
// $this_avail_pref['init_default'] is a comma seperated seperated string which should
// be exploded into an array containing 2 elements that are:
// exploded[0] : an description of how to handle the next string element to get a default value.
// Possible "instructional tokens" for exploded[0] (called $set_proc[0] below) are:
// string
// set_or_not
// function
// init_no_fill
// varEVAL
// tells you how to handle the string in exploded[1] (called $set_proc[1] below) to get a valid
// default value for a particular preference if one is needed (i.e. if no user custom
// email preference exists that should override that default value, in which case we
// do not even need to obtain such a default value as described in ['init_default'] anyway).
2002-01-10 11:09:10 +01:00
2001-12-17 19:37:59 +01:00
// --- loop thru $avail_pref_array and process each pref item ---
$c_prefs = count ( $avail_pref_array );
for ( $i = 0 ; $i < $c_prefs ; $i ++ )
{
$this_avail_pref = $avail_pref_array [ $i ];
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: create_email_preferences: value from DB for $prefs[email][' . $this_avail_pref [ 'id' ] . '] = [' . $prefs [ 'email' ][ $this_avail_pref [ 'id' ]] . ']' , 'messageonly' , 'api' );
print_debug ( 'class.preferences: create_email_preferences: std/cust_prefs $this_avail_pref[' . $i . '] dump:' , $this_avail_pref , 'api' );
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- is there a value in the DB for this preference item ---
// if the prefs DB has no value for this defined available preference, we must make one.
// This occurs if (a) this is user's first login, or (b) this is a custom pref which the user
// has not overriden, do a default (non-custom) value is needed.
if ( ! isset ( $prefs [ 'email' ][ $this_avail_pref [ 'id' ]]))
2001-11-12 22:44:31 +01:00
{
2001-12-17 19:37:59 +01:00
// now we are analizing an individual pref that is available to the user
// AND the user had no existing value in the prefs DB for this.
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- get instructions on how to generate a default value ---
$set_proc = explode ( ',' , $this_avail_pref [ 'init_default' ]);
2003-08-28 16:31:11 +02:00
print_debug ( ' * set_proc=[' . serialize ( $set_proc ) . ']' , 'messageonly' , 'api' );
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- use "instructional token" in $set_proc[0] to take appropriate action ---
// STRING
if ( $set_proc [ 0 ] == 'string' )
{
// means this pref item's value type is string
// which defined string default value is in $set_proc[1]
2003-08-28 16:31:11 +02:00
print_debug ( '* handle "string" set_proc: ' , serialize ( $set_proc ), 'api' );
2001-12-17 19:37:59 +01:00
if ( trim ( $set_proc [ 1 ]) == '' )
{
// this happens when $this_avail_pref['init_default'] = "string, "
$this_string = '' ;
}
else
{
$this_string = $set_proc [ 1 ];
}
$prefs [ 'email' ][ $this_avail_pref [ 'id' ]] = $this_string ;
}
// SET_OR_NOT
elseif ( $set_proc [ 0 ] == 'set_or_not' )
{
// typical with boolean options, True = "set/exists" and False = unset
2003-08-28 16:31:11 +02:00
print_debug ( '* handle "set_or_not" set_proc: ' , serialize ( $set_proc ), 'api' );
2001-12-17 19:37:59 +01:00
if ( $set_proc [ 1 ] == 'not_set' )
{
// leave it NOT SET
}
else
{
// opposite of boolean not_set = string "True" which simply sets a
// value it exists in the users session [email][] preference array
$prefs [ 'email' ][ $this_avail_pref [ 'id' ]] = 'True' ;
}
}
// FUNCTION
elseif ( $set_proc [ 0 ] == 'function' )
{
// string in $set_proc[1] should be "eval"uated as code, calling a function
// which will give us a default value to put in users session [email][] prefs array
2003-08-28 16:31:11 +02:00
print_debug ( ' * handle "function" set_proc: ' , serialize ( $set_proc ), 'api' );
2001-12-17 19:37:59 +01:00
$evaled = '' ;
//eval('$evaled = $this->'.$set_proc[1].'('.$account_id.');');
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
$code = '$evaled = $this->' . $set_proc [ 1 ] . '(' . $account_id . ');' ;
2003-08-28 16:31:11 +02:00
print_debug ( ' * $code: ' , $code , 'api' );
2001-12-17 19:37:59 +01:00
eval ( $code );
2001-12-24 05:53:07 +01:00
2003-08-28 16:31:11 +02:00
print_debug ( '* $evaled:' , $evaled , 'api' );
2001-12-17 19:37:59 +01:00
$prefs [ 'email' ][ $this_avail_pref [ 'id' ]] = $evaled ;
}
// INIT_NO_FILL
elseif ( $set_proc [ 0 ] == 'init_no_fill' )
{
// we have an available preference item that we may NOT fill with a default
// value. Only the user may supply a value for this pref item.
2003-08-28 16:31:11 +02:00
print_debug ( '* handle "init_no_fill" set_proc:' , serialize ( $set_proc ), 'api' );
2001-12-17 19:37:59 +01:00
// we are FORBADE from filling this at this time!
}
// varEVAL
elseif ( $set_proc [ 0 ] == 'varEVAL' )
{
// similar to "function" but used for array references, the string in $set_proc[1]
// represents code which typically is an array referencing a system/api property
2003-08-28 16:31:11 +02:00
print_debug ( '* handle "GLOBALS" set_proc:' , serialize ( $set_proc ), 'api' );
2001-12-17 19:37:59 +01:00
$evaled = '' ;
$code = '$evaled = ' . $set_proc [ 1 ];
2003-08-28 16:31:11 +02:00
print_debug ( ' * $code:' , $code , 'api' );
2001-12-17 19:37:59 +01:00
eval ( $code );
2003-08-28 16:31:11 +02:00
print_debug ( '* $evaled:' , $evaled , 'api' );
2001-12-17 19:37:59 +01:00
$prefs [ 'email' ][ $this_avail_pref [ 'id' ]] = $evaled ;
}
else
{
// error, no instructions on how to handle this element's default value creation
echo 'class.preferences: create_email_preferences: set_proc ERROR: ' . serialize ( $set_proc ) . '<br>' ;
}
2001-11-12 22:44:31 +01:00
}
else
{
2001-12-17 19:37:59 +01:00
// we have a value in the database, do we need to prepare it in any way?
// (the following discussion is unconfirmed:)
// DO NOT ALTER the data in the prefs array!!!! or the next time we call
// save_repository withOUT undoing what we might do here, the
// prefs will permenantly LOOSE the very thing(s) we are un-doing
/// here until the next OFFICIAL submit email prefs function, where it
// will again get this preparation before being written to the database.
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// NOTE: if database de-fanging is eventually handled deeper in the
// preferences class, then the following code would become depreciated
// and should be removed in that case.
2001-12-24 05:53:07 +01:00
if (( $this_avail_pref [ 'type' ] == 'user_string' ) &&
( stristr ( $this_avail_pref [ 'write_props' ], 'no_db_defang' ) == False ))
2001-12-17 19:37:59 +01:00
{
// this value was "de-fanged" before putting it in the database
// undo that defanging now
$db_unfriendly = $email_base -> html_quotes_decode ( $prefs [ 'email' ][ $this_avail_pref [ 'id' ]]);
$prefs [ 'email' ][ $this_avail_pref [ 'id' ]] = $db_unfriendly ;
}
2001-11-12 22:44:31 +01:00
}
}
2001-12-17 19:37:59 +01:00
// users preferences are now established to known structured values...
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// SANITY CHECK
// --- [email][use_trash_folder] ---
// --- [email][use_sent_folder] ---
// is it possible to use Trash and Sent folders - i.e. using IMAP server
// if not - force settings to false
if ( stristr ( $prefs [ 'email' ][ 'mail_server_type' ], 'imap' ) == False )
2001-11-12 22:44:31 +01:00
{
2001-12-17 19:37:59 +01:00
if ( isset ( $prefs [ 'email' ][ 'use_trash_folder' ]))
{
unset ( $prefs [ 'email' ][ 'use_trash_folder' ]);
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
if ( isset ( $prefs [ 'email' ][ 'use_sent_folder' ]))
{
unset ( $prefs [ 'email' ][ 'use_sent_folder' ]);
}
2001-11-12 22:44:31 +01:00
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// DEBUG : force some settings to test stuff
//$prefs['email']['p_persistent'] = 'True';
2003-08-28 16:31:11 +02:00
print_debug ( 'class.preferences: $acctnum: [' . $acctnum . '] ; create_email_preferences: $prefs[email]' , $prefs [ 'email' ], 'api' );
print_debug ( 'class.preferences: create_email_preferences: LEAVING' , 'messageonly' , 'api' );
2001-12-17 19:37:59 +01:00
return $prefs ;
}
/*
2003-12-13 16:03:23 +01:00
// ==== DEPRECATED - ARCHIVAL CODE ====
2001-12-17 19:37:59 +01:00
// used to be part of function this->create_email_preferences()
// = = = = SIMPLER PREFS = = = =
// Default Preferences info that is:
// described in the email prefs array itself
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
$default_trash_folder = 'Trash' ;
$default_sent_folder = 'Sent' ;
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- userid ---
if ( ! isset ( $prefs [ 'email' ][ 'userid' ]))
{
$prefs [ 'email' ][ 'userid' ] = $this -> sub_default_userid ( $accountid );
}
// --- address ---
2001-11-12 22:44:31 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'address' ]))
{
2003-05-02 03:33:32 +02:00
$prefs [ 'email' ][ 'address' ] = $this -> email_address ( $accountid );
2001-11-12 22:44:31 +01:00
}
2001-12-17 19:37:59 +01:00
// --- mail_server ---
2001-11-12 22:44:31 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'mail_server' ]))
{
$prefs [ 'email' ][ 'mail_server' ] = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_server' ];
}
2001-12-17 19:37:59 +01:00
// --- mail_server_type ---
2001-11-12 22:44:31 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'mail_server_type' ]))
{
$prefs [ 'email' ][ 'mail_server_type' ] = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_server_type' ];
}
2001-12-17 19:37:59 +01:00
// --- imap_server_type ---
2001-11-12 22:44:31 +01:00
if ( ! isset ( $prefs [ 'email' ][ 'imap_server_type' ]))
{
$prefs [ 'email' ][ 'imap_server_type' ] = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'imap_server_type' ];
}
2001-12-17 19:37:59 +01:00
// --- mail_folder ---
2001-11-12 22:44:31 +01:00
// because of the way this option works, an empty string IS ACTUALLY a valid value
// which represents the $HOME/* as the UWash mail files location
// THERFOR we must check the "Use_custom_setting" option to help us figure out what to do
if ( ! isset ( $prefs [ 'email' ][ 'use_custom_settings' ]))
{
// we are NOT using custom settings so this MUST be the server default
$prefs [ 'email' ][ 'mail_folder' ] = $GLOBALS [ 'phpgw_info' ][ 'server' ][ 'mail_folder' ];
}
else
{
// we ARE using custom settings AND a BLANK STRING is a valid option, so...
if (( isset ( $prefs [ 'email' ][ 'mail_folder' ]))
&& ( $prefs [ 'email' ][ 'mail_folder' ] != '' ))
{
2001-12-01 01:03:30 +01:00
// using custom AND a string exists, so "mail_folder" is that string stored in the custom prefs by the user
2001-11-12 22:44:31 +01:00
// DO NOTING - VALID OPTION VALUE for $prefs['email']['mail_folder']
}
else
{
// using Custom Prefs BUT this text box was left empty by the user on submit, so no value stored
// BUT since we are using custom prefs, "mail_folder" MUST BE AN EMPTY STRING
2001-12-01 01:03:30 +01:00
// which is an acceptable, valid preference, overriding any value which
// may have been set in ["server"]["mail_folder"]
// This is one of the few instances in the preference class where an empty, unspecified value
// actually does NOT get deleted from the repository.
2001-11-12 22:44:31 +01:00
$prefs [ 'email' ][ 'mail_folder' ] = '' ;
}
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- use_trash_folder ---
// --- trash_folder_name ---
2001-11-12 22:44:31 +01:00
// if the option to use the Trash folder is ON, make sure a proper name is specified
if ( isset ( $prefs [ 'email' ][ 'use_trash_folder' ]))
{
if (( ! isset ( $prefs [ 'email' ][ 'trash_folder_name' ]))
|| ( $prefs [ 'email' ][ 'trash_folder_name' ] == '' ))
{
$prefs [ 'email' ][ 'trash_folder_name' ] = $default_trash_folder ;
}
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// --- use_sent_folder ---
// --- sent_folder_name ---
2001-11-12 22:44:31 +01:00
// if the option to use the sent folder is ON, make sure a proper name is specified
if ( isset ( $prefs [ 'email' ][ 'use_sent_folder' ]))
{
if (( ! isset ( $prefs [ 'email' ][ 'sent_folder_name' ]))
|| ( $prefs [ 'email' ][ 'sent_folder_name' ] == '' ))
{
$prefs [ 'email' ][ 'sent_folder_name' ] = $default_sent_folder ;
}
2001-12-24 05:53:07 +01:00
}
2001-11-12 22:44:31 +01:00
2001-12-17 19:37:59 +01:00
// --- layout ---
// Layout Template Preference
// layout 1 = default ; others are prefs
if ( ! isset ( $prefs [ 'email' ][ 'layout' ]))
{
$prefs [ 'email' ][ 'layout' ] = 1 ;
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
//// --- font_size_offset ---
//// Email Index Page Font Size Preference
//// layout 1 = default ; others are prefs
//if (!isset($prefs['email']['font_size_offset']))
//{
// $prefs['email']['font_size_offset'] = 'normal';
//}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// SANITY CHECK
// --- use_trash_folder ---
// --- use_sent_folder ---
// is it possible to use Trash and Sent folders - i.e. using IMAP server
2001-11-12 22:44:31 +01:00
// if not - force settings to false
2001-12-17 19:37:59 +01:00
if ( stristr ( $prefs [ 'email' ][ 'mail_server_type' ], 'imap' ) == False )
2001-11-12 22:44:31 +01:00
{
if ( isset ( $prefs [ 'email' ][ 'use_trash_folder' ]))
{
unset ( $prefs [ 'email' ][ 'use_trash_folder' ]);
}
2001-12-17 19:37:59 +01:00
if ( isset ( $prefs [ 'email' ][ 'use_sent_folder' ]))
{
unset ( $prefs [ 'email' ][ 'use_sent_folder' ]);
}
2001-11-12 22:44:31 +01:00
}
2001-12-24 05:53:07 +01:00
2001-12-17 19:37:59 +01:00
// DEBUG : force some settings to test stuff
2001-11-12 22:44:31 +01:00
//$prefs['email']['layout'] = 1;
//$prefs['email']['layout'] = 2;
2001-12-17 19:37:59 +01:00
//$prefs['email']['font_size_offset'] = (-1);
2001-12-24 05:53:07 +01:00
2001-11-12 22:44:31 +01:00
// DEBUG
//echo "<br>prefs['email']: <br>"
// .'<pre>'.serialize($prefs['email']) .'</pre><br>';
return $prefs ;
2001-12-17 19:37:59 +01:00
*/
2001-07-26 13:13:15 +02:00
} /* end of preferences class */
2001-02-14 21:55:10 +01:00
?>