[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - Preferences * |
---|
| 4 | * This file written by Joseph Engo <jengo@phpgroupware.org> * |
---|
| 5 | * and Mark Peters <skeeter@phpgroupware.org> * |
---|
| 6 | * Manages user preferences * |
---|
| 7 | * Copyright (C) 2000, 2001 Joseph Engo * |
---|
| 8 | * -------------------------------------------------------------------------* |
---|
| 9 | * This library is part of the eGroupWare API * |
---|
| 10 | * http://www.egroupware.org/api * |
---|
| 11 | * ------------------------------------------------------------------------ * |
---|
| 12 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 13 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 14 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 15 | * or any later version. * |
---|
| 16 | * This library is distributed in the hope that it will be useful, but * |
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 19 | * See the GNU Lesser General Public License for more details. * |
---|
| 20 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 21 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 22 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 23 | \**************************************************************************/ |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /*! |
---|
| 27 | @class preferences |
---|
| 28 | @abstract preferences class used for setting application preferences |
---|
| 29 | @discussion the prefs are read into 4 arrays: \ |
---|
| 30 | $data the effective prefs used everywhere in phpgw, they are merged from the other 3 arrays \ |
---|
| 31 | $user the stored user prefs, only used for manipulating and storeing the user prefs \ |
---|
| 32 | $default the default preferences, always used when the user has no own preference set \ |
---|
| 33 | $forced forced preferences set by the admin, they take precedence over user or default prefs |
---|
| 34 | */ |
---|
| 35 | class preferences |
---|
| 36 | { |
---|
| 37 | /*! @var account_id */ |
---|
| 38 | var $account_id; |
---|
| 39 | /*! @var account_type */ |
---|
| 40 | var $account_type; |
---|
| 41 | /*! @var data effectiv user prefs, used by all apps */ |
---|
| 42 | var $data = array(); |
---|
| 43 | /*! @var user set user prefs for saveing (no defaults/forced prefs merged) */ |
---|
| 44 | var $user = array(); |
---|
| 45 | /*! @var default default prefs */ |
---|
| 46 | var $default = array(); |
---|
| 47 | /*! @var forced forced prefs */ |
---|
| 48 | var $forced = array(); |
---|
| 49 | /*! @var session session / tempory prefs */ |
---|
| 50 | var $session = array(); |
---|
| 51 | /*! @var db */ |
---|
| 52 | var $db; |
---|
| 53 | |
---|
| 54 | var $values,$vars; // standard notify substitues, will be set by standard_substitues() |
---|
| 55 | |
---|
| 56 | /**************************************************************************\ |
---|
| 57 | * Standard constructor for setting $this->account_id * |
---|
| 58 | \**************************************************************************/ |
---|
| 59 | /*! |
---|
| 60 | @function preferences |
---|
| 61 | @abstract Standard constructor for setting $this->account_id |
---|
| 62 | @discussion Author: |
---|
| 63 | */ |
---|
| 64 | function preferences($account_id = '') |
---|
| 65 | { |
---|
| 66 | $this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db; |
---|
| 67 | $this->account_id = get_account_id($account_id); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /**************************************************************************\ |
---|
| 71 | * These are the standard $this->account_id specific functions * |
---|
| 72 | \**************************************************************************/ |
---|
| 73 | |
---|
| 74 | /*! |
---|
| 75 | @function parse_notify |
---|
| 76 | @abstract parses a notify and replaces the substitutes |
---|
| 77 | @syntax parse_notify($msg,$values='',$use_standard_values=True) |
---|
| 78 | @param $msg message to parse / substitute |
---|
| 79 | @param $values extra vars to replace in addition to $this->values, vars are in an array with \ |
---|
| 80 | $key => $value pairs, $key does not include the $'s and is the *untranslated* name |
---|
| 81 | @param $use_standard_values should the standard values are used |
---|
| 82 | @returns the parsed notify-msg |
---|
| 83 | */ |
---|
| 84 | function parse_notify($msg,$values='',$use_standard_values=True) |
---|
| 85 | { |
---|
| 86 | $vals = $values ? $values : array(); |
---|
| 87 | |
---|
| 88 | if ($use_standard_values && is_array($this->values)) |
---|
| 89 | { |
---|
| 90 | $vals += $this->values; |
---|
| 91 | } |
---|
| 92 | foreach($vals as $key => $val) |
---|
| 93 | { |
---|
| 94 | $replace[] = '$$'.$key.'$$'; |
---|
| 95 | $with[] = $val; |
---|
| 96 | } |
---|
| 97 | return str_replace($replace,$with,$msg); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /*! |
---|
| 101 | @function lang_notify |
---|
| 102 | @abstract replaces the english key's with translated ones, or if $un_lang the opposite |
---|
| 103 | @syntax lang_notify($msg,$values='',$un_lang=False) |
---|
| 104 | @param $msg message to translate |
---|
| 105 | @param $values extra vars to replace in addition to $this->values, vars are in an array with \ |
---|
| 106 | $key => $value pairs, $key does not include the $'s and is the *untranslated* name |
---|
| 107 | @param $un_lang if true translate back |
---|
| 108 | @returns the result |
---|
| 109 | */ |
---|
| 110 | function lang_notify($msg,$vals=array(),$un_lang=False) |
---|
| 111 | { |
---|
| 112 | foreach($vals as $key => $val) |
---|
| 113 | { |
---|
| 114 | $lname = ($lname = lang($key)) == $key.'*' ? $key : $lname; |
---|
| 115 | if ($un_lang) |
---|
| 116 | { |
---|
| 117 | $langs[$lname] = '$$'.$key.'$$'; |
---|
| 118 | } |
---|
| 119 | else |
---|
| 120 | { |
---|
| 121 | $langs[$key] = '$$'.$lname.'$$'; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | return $this->parse_notify($msg,$langs,False); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /*! |
---|
| 128 | @function standard_substitues |
---|
| 129 | @abstract define some standard substitues-values and use them on the prefs, if needed |
---|
| 130 | */ |
---|
| 131 | function standard_substitutes() |
---|
| 132 | { |
---|
| 133 | if (!is_array(@$GLOBALS['phpgw_info']['user']['preferences'])) |
---|
| 134 | { |
---|
| 135 | $GLOBALS['phpgw_info']['user']['preferences'] = $this->data; // else no lang() |
---|
| 136 | } |
---|
| 137 | // we cant use phpgw_info/user/fullname, as it's not set when we run |
---|
| 138 | $GLOBALS['phpgw']->accounts->get_account_name($this->account_id,$lid,$fname,$lname); |
---|
| 139 | |
---|
| 140 | $this->values = array( // standard notify replacements |
---|
| 141 | 'fullname' => $GLOBALS['phpgw']->common->display_fullname('',$fname,$lname), |
---|
| 142 | 'firstname' => $fname, |
---|
| 143 | 'lastname' => $lname, |
---|
| 144 | 'domain' => $GLOBALS['phpgw_info']['server']['mail_suffix'], |
---|
| 145 | 'email' => $this->email_address($this->account_id), |
---|
| 146 | 'date' => $GLOBALS['phpgw']->common->show_date('',$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']), |
---|
| 147 | ); |
---|
| 148 | // do this first, as it might be already contain some substitues |
---|
| 149 | // |
---|
| 150 | $this->values['email'] = $this->parse_notify($this->values['email']); |
---|
| 151 | |
---|
| 152 | $this->vars = array( // langs have to be in common !!! |
---|
| 153 | 'fullname' => lang('name of the user, eg. "%1"',$this->values['fullname']), |
---|
| 154 | 'firstname' => lang('first name of the user, eg. "%1"',$this->values['firstname']), |
---|
| 155 | 'lastname' => lang('last name of the user, eg. "%1"',$this->values['lastname']), |
---|
| 156 | 'domain' => lang('domain name for mail-address, eg. "%1"',$this->values['domain']), |
---|
| 157 | 'email' => lang('email-address of the user, eg. "%1"',$this->values['email']), |
---|
| 158 | 'date' => lang('todays date, eg. "%1"',$this->values['date']), |
---|
| 159 | ); |
---|
| 160 | // do the substituetion in the effective prefs (data) |
---|
| 161 | // |
---|
| 162 | foreach($this->data as $app => $data) |
---|
| 163 | { |
---|
| 164 | foreach($data as $key => $val) |
---|
| 165 | { |
---|
[41] | 166 | if (empty($val)) |
---|
| 167 | continue; |
---|
[2] | 168 | if (!is_array($val) && strstr($val,'$$') !== False) |
---|
| 169 | { |
---|
| 170 | $this->data[$app][$key] = $this->parse_notify($val); |
---|
| 171 | } |
---|
| 172 | elseif (is_array($val)) |
---|
| 173 | { |
---|
| 174 | foreach($val as $k => $v) |
---|
| 175 | { |
---|
[2549] | 176 | if (!is_array($v) && is_string( $val ) && strstr($val,'$$') !== False) |
---|
[2] | 177 | { |
---|
| 178 | $this->data[$app][$key][$k] = $this->parse_notify($v); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /*! |
---|
| 187 | @function unquote |
---|
| 188 | @abstract unquote (stripslashes) recursivly the whole array |
---|
| 189 | @param $arr array to unquote (var-param!) |
---|
| 190 | */ |
---|
| 191 | function unquote(&$arr) |
---|
| 192 | { |
---|
| 193 | if (!is_array($arr)) |
---|
| 194 | { |
---|
| 195 | $arr = stripslashes($arr); |
---|
| 196 | return; |
---|
| 197 | } |
---|
| 198 | foreach($arr as $key => $value) |
---|
| 199 | { |
---|
| 200 | if (is_array($value)) |
---|
| 201 | { |
---|
| 202 | $this->unquote($arr[$key]); |
---|
| 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | $arr[$key] = stripslashes($value); |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | /*! |
---|
| 212 | @function read_repository |
---|
| 213 | @abstract private - read preferences from the repository |
---|
| 214 | @note the function ready all 3 prefs user/default/forced and merges them to the effective ones |
---|
| 215 | @discussion private function should only be called from within this class |
---|
| 216 | */ |
---|
| 217 | function read_repository() |
---|
| 218 | { |
---|
| 219 | $this->session = $GLOBALS['phpgw']->session->appsession('preferences','preferences'); |
---|
| 220 | if (!is_array($this->session)) |
---|
| 221 | { |
---|
| 222 | $this->session = array(); |
---|
| 223 | } |
---|
[1999] | 224 | $groups = $GLOBALS['phpgw']->accounts->membership(); |
---|
[2002] | 225 | if (is_array($groups)) |
---|
[1999] | 226 | foreach($groups as $group) |
---|
| 227 | $gids .= ",".$group['account_id']; |
---|
| 228 | $account_id = (int)$this->account_id; |
---|
| 229 | |
---|
[2] | 230 | $this->db->query("SELECT * FROM phpgw_preferences" |
---|
[1999] | 231 | . " WHERE preference_owner IN (-1,-2," . $account_id . $gids . ')',__LINE__,__FILE__); |
---|
[2] | 232 | |
---|
| 233 | $this->forced = $this->default = $this->user = array(); |
---|
| 234 | while($this->db->next_record()) |
---|
| 235 | { |
---|
| 236 | // The following replacement is required for PostgreSQL to work |
---|
| 237 | $app = str_replace(' ','',$this->db->f('preference_app')); |
---|
| 238 | $value = unserialize($this->db->f('preference_value')); |
---|
| 239 | $this->unquote($value); |
---|
| 240 | if (!is_array($value)) |
---|
| 241 | { |
---|
| 242 | continue; |
---|
| 243 | } |
---|
| 244 | switch($this->db->f('preference_owner')) |
---|
| 245 | { |
---|
| 246 | case -1: // forced |
---|
| 247 | $this->forced[$app] = $value; |
---|
| 248 | break; |
---|
| 249 | case -2: // default |
---|
| 250 | $this->default[$app] = $value; |
---|
| 251 | break; |
---|
[1999] | 252 | case $account_id: //user |
---|
[2] | 253 | $this->user[$app] = $value; |
---|
| 254 | break; |
---|
[1999] | 255 | default: // group |
---|
| 256 | $this->group[$app] = $value; |
---|
| 257 | break; |
---|
[2] | 258 | } |
---|
| 259 | } |
---|
| 260 | $this->data = $this->user; |
---|
| 261 | |
---|
| 262 | // let the (temp.) session prefs. override the user prefs. |
---|
| 263 | // |
---|
| 264 | foreach($this->session as $app => $values) |
---|
| 265 | { |
---|
| 266 | foreach($values as $var => $value) |
---|
| 267 | { |
---|
| 268 | $this->data[$app][$var] = $value; |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | // now use defaults if needed (user-value unset or empty) |
---|
| 273 | // |
---|
| 274 | foreach($this->default as $app => $values) |
---|
| 275 | { |
---|
| 276 | foreach($values as $var => $value) |
---|
| 277 | { |
---|
| 278 | if (!isset($this->data[$app][$var]) || $this->data[$app][$var] === '') |
---|
| 279 | { |
---|
| 280 | $this->data[$app][$var] = $value; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | } |
---|
[1999] | 284 | // now set/force forced values for groups |
---|
| 285 | // |
---|
[2001] | 286 | if (is_array($this->group)) |
---|
[1999] | 287 | foreach($this->group as $app => $values) |
---|
| 288 | { |
---|
| 289 | foreach($values as $var => $value) |
---|
| 290 | { |
---|
| 291 | $this->data[$app][$var] = $value; |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
[2] | 295 | // now set/force forced values |
---|
| 296 | // |
---|
| 297 | foreach($this->forced as $app => $values) |
---|
| 298 | { |
---|
| 299 | foreach($values as $var => $value) |
---|
| 300 | { |
---|
| 301 | $this->data[$app][$var] = $value; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | // setup the standard substitutes and substitutes the data in $this->data |
---|
| 305 | // |
---|
| 306 | $this->standard_substitutes(); |
---|
| 307 | |
---|
| 308 | // This is to supress warnings during login |
---|
| 309 | if (is_array($this->data)) |
---|
| 310 | { |
---|
| 311 | reset($this->data); |
---|
| 312 | } |
---|
| 313 | if (isset($this->debug) && substr($GLOBALS['phpgw_info']['flags']['currentapp'],0,3) != 'log') |
---|
| 314 | { |
---|
| 315 | echo 'user<pre>'; print_r($this->user); echo "</pre>\n"; |
---|
| 316 | echo 'forced<pre>'; print_r($this->forced); echo "</pre>\n"; |
---|
| 317 | echo 'default<pre>'; print_r($this->default); echo "</pre>\n"; |
---|
| 318 | echo 'effectiv<pre>'; print_r($this->data); echo "</pre>\n"; |
---|
| 319 | } |
---|
| 320 | return $this->data; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | /*! |
---|
| 324 | @function read |
---|
| 325 | @abstract public - read preferences from repository and stores in an array |
---|
| 326 | @discussion Syntax array read(); <> |
---|
| 327 | Example1: preferences->read(); |
---|
| 328 | @result $data array containing user preferences |
---|
| 329 | */ |
---|
| 330 | function read() |
---|
| 331 | { |
---|
| 332 | if (count($this->data) == 0) |
---|
| 333 | { |
---|
| 334 | $this->read_repository(); |
---|
| 335 | } |
---|
| 336 | reset ($this->data); |
---|
| 337 | return $this->data; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | /*! |
---|
| 341 | @function add |
---|
| 342 | @abstract add preference to $app_name a particular app |
---|
| 343 | @discussion |
---|
| 344 | @param $app_name name of the app |
---|
| 345 | @param $var name of preference to be stored |
---|
| 346 | @param $value value of the preference |
---|
| 347 | @param $type of preference to set: forced, default, user |
---|
| 348 | @note the effective prefs ($this->data) are updated to reflect the change |
---|
| 349 | @returns the new effective prefs (even when forced or default prefs are set !) |
---|
| 350 | */ |
---|
| 351 | function add($app_name,$var,$value = '##undef##',$type='user') |
---|
| 352 | { |
---|
| 353 | //echo "<p>add('$app_name','$var','$value')</p>\n"; |
---|
| 354 | if ($value === '##undef##') |
---|
| 355 | { |
---|
| 356 | global $$var; |
---|
| 357 | $value = $$var; |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | switch ($type) |
---|
| 361 | { |
---|
| 362 | case 'session': |
---|
| 363 | if (!isset($this->forced[$app_name][$var]) || $this->forced[$app_name][$var] === '') |
---|
| 364 | { |
---|
| 365 | $this->session[$app_name][$var] = $this->data[$app_name][$var] = $value; |
---|
| 366 | $GLOBALS['phpgw']->session->appsession('preferences','preferences',$this->session); |
---|
| 367 | } |
---|
| 368 | break; |
---|
| 369 | |
---|
| 370 | case 'forced': |
---|
| 371 | $this->data[$app_name][$var] = $this->forced[$app_name][$var] = $value; |
---|
| 372 | break; |
---|
| 373 | |
---|
| 374 | case 'default': |
---|
| 375 | $this->default[$app_name][$var] = $value; |
---|
| 376 | if ((!isset($this->forced[$app_name][$var]) || $this->forced[$app_name][$var] === '') && |
---|
| 377 | (!isset($this->user[$app_name][$var]) || $this->user[$app_name][$var] === '')) |
---|
| 378 | { |
---|
| 379 | $this->data[$app_name][$var] = $value; |
---|
| 380 | } |
---|
| 381 | break; |
---|
| 382 | |
---|
| 383 | case user: |
---|
| 384 | default: |
---|
| 385 | $this->user[$app_name][$var] = $value; |
---|
| 386 | if (!isset($this->forced[$app_name][$var]) || $this->forced[$app_name][$var] === '') |
---|
| 387 | { |
---|
| 388 | $this->data[$app_name][$var] = $value; |
---|
| 389 | } |
---|
| 390 | break; |
---|
| 391 | } |
---|
| 392 | reset($this->data); |
---|
| 393 | return $this->data; |
---|
| 394 | } |
---|
| 395 | |
---|
| 396 | /*! |
---|
| 397 | @function delete |
---|
| 398 | @abstract delete preference from $app_name |
---|
| 399 | @discussion |
---|
| 400 | @param $app_name name of app |
---|
| 401 | @param $var variable to be deleted |
---|
| 402 | @param $type of preference to set: forced, default, user |
---|
| 403 | @note the effektive prefs ($this->data) are updated to reflect the change |
---|
| 404 | @returns the new effective prefs (even when forced or default prefs are deleted!) |
---|
| 405 | */ |
---|
| 406 | function delete($app_name, $var = False,$type = 'user') |
---|
| 407 | { |
---|
| 408 | //echo "<p>delete('$app_name','$var','$type')</p>\n"; |
---|
| 409 | $set_via = array( |
---|
| 410 | 'forced' => array('user','default'), |
---|
| 411 | 'default' => array('forced','user'), |
---|
| 412 | 'user' => array('forced','default') |
---|
| 413 | ); |
---|
| 414 | if (!isset($set_via[$type])) |
---|
| 415 | { |
---|
| 416 | $type = 'user'; |
---|
| 417 | } |
---|
| 418 | $pref = &$this->$type; |
---|
| 419 | |
---|
| 420 | if ($all = (is_string($var) && $var == '')) |
---|
| 421 | { |
---|
| 422 | unset($pref[$app_name]); |
---|
| 423 | unset($this->data[$app_name]); |
---|
| 424 | } |
---|
| 425 | else |
---|
| 426 | { |
---|
| 427 | unset($pref[$app_name][$var]); |
---|
| 428 | unset($this->data[$app_name][$var]); |
---|
| 429 | } |
---|
| 430 | // set the effectiv pref again if needed |
---|
| 431 | // |
---|
| 432 | foreach ($set_via[$type] as $set_from) |
---|
| 433 | { |
---|
| 434 | if ($all) |
---|
| 435 | { |
---|
| 436 | if (isset($this->$set_from[$app_name])) |
---|
| 437 | { |
---|
| 438 | $this->data[$app_name] = $this->$set_from[$app_name]; |
---|
| 439 | break; |
---|
| 440 | } |
---|
| 441 | } |
---|
| 442 | else |
---|
| 443 | { |
---|
| 444 | $arr = $this->$set_from; |
---|
| 445 | if($var && @isset($arr[$app_name][$var]) && $arr[$app_name][$var] !== '') |
---|
| 446 | { |
---|
| 447 | $this->data[$app_name][$var] = $this->$set_from[$app_name][$var]; |
---|
| 448 | break; |
---|
| 449 | } |
---|
| 450 | unset($arr); |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | reset ($this->data); |
---|
| 454 | return $this->data; |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | /*! |
---|
| 458 | @function add_struct |
---|
| 459 | @abstract add complex array data preference to $app_name a particular app |
---|
| 460 | @discussion Use for sublevels of prefs, such as email app's extra accounts preferences |
---|
| 461 | @param $app_name name of the app |
---|
| 462 | @param $var array keys separated by '/', eg. 'ex_accounts/1' |
---|
| 463 | @param $value value of the preference |
---|
| 464 | @note the function works on user and data, to be able to save the pref and to have imediate effect |
---|
| 465 | */ |
---|
| 466 | function add_struct($app_name,$var,$value = '') |
---|
| 467 | { |
---|
| 468 | /* eval is slow and dangerous |
---|
| 469 | $code = '$this->data[$app_name]'.$var.' = $value;'; |
---|
| 470 | print_debug('class.preferences: add_struct: $code: ', $code,'api'); |
---|
| 471 | eval($code); |
---|
| 472 | */ |
---|
| 473 | $parts = explode('/',str_replace(array('][','[',']','"',"'"),array('/','','','',''),$var)); |
---|
| 474 | $data = &$this->data[$app_name]; |
---|
| 475 | $user = &$this->user[$app_name]; |
---|
| 476 | foreach($parts as $name) |
---|
| 477 | { |
---|
| 478 | $data = &$data[$name]; |
---|
| 479 | $user = &$user[$name]; |
---|
| 480 | } |
---|
| 481 | $data = $user = $value; |
---|
| 482 | print_debug('class.preferences: add_struct: $this->data[$app_name] dump:', $this->data[$app_name],'api'); |
---|
| 483 | reset($this->data); |
---|
| 484 | return $this->data; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | /*! |
---|
| 488 | @function delete_struct |
---|
| 489 | @abstract delete complex array data preference from $app_name |
---|
| 490 | @discussion Use for sublevels of prefs, such as email app's extra accounts preferences |
---|
| 491 | @param $app_name name of app |
---|
| 492 | @param $var array keys separated by '/', eg. 'ex_accounts/1' |
---|
| 493 | @note the function works on user and data, to be able to save the pref and to have immediate effect |
---|
| 494 | */ |
---|
| 495 | function delete_struct($app_name, $var = '') |
---|
| 496 | { |
---|
| 497 | /* eval is slow and dangerous |
---|
| 498 | $code_1 = '$this->data[$app_name]'.$var.' = "";'; |
---|
| 499 | print_debug('class.preferences: delete_struct: $code_1:', $code_1,'api'); |
---|
| 500 | eval($code_1); |
---|
| 501 | $code_2 = 'unset($this->data[$app_name]'.$var.');' ; |
---|
| 502 | print_debug('class.preferences: delete_struct: $code_2: ', $code_2,'api'); |
---|
| 503 | eval($code_2); |
---|
| 504 | */ |
---|
| 505 | $parts = explode('/',str_replace(array('][','[',']','"',"'"),array('/','','','',''),$var)); |
---|
| 506 | $last = array_pop($parts); |
---|
| 507 | $data = &$this->data[$app_name]; |
---|
| 508 | $user = &$this->user[$app_name]; |
---|
| 509 | foreach($parts as $name) |
---|
| 510 | { |
---|
| 511 | $data = &$data[$name]; |
---|
| 512 | $user = &$user[$name]; |
---|
| 513 | } |
---|
| 514 | unset($data[$last]); |
---|
| 515 | unset($user[$last]); |
---|
| 516 | print_debug('* $this->data[$app_name] dump:', $this->data[$app_name],'api'); |
---|
| 517 | reset ($this->data); |
---|
| 518 | return $this->data; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | /*! |
---|
| 522 | @function quote |
---|
| 523 | @abstract quote (addslashes) recursivly the whole array |
---|
| 524 | @param $arr array to unquote (var-param!) |
---|
| 525 | */ |
---|
| 526 | function quote(&$arr) |
---|
| 527 | { |
---|
| 528 | if (!is_array($arr)) |
---|
| 529 | { |
---|
| 530 | $arr = addslashes($arr); |
---|
| 531 | return; |
---|
| 532 | } |
---|
| 533 | foreach($arr as $key => $value) |
---|
| 534 | { |
---|
| 535 | if (is_array($value)) |
---|
| 536 | { |
---|
| 537 | $this->quote($arr[$key]); |
---|
| 538 | } |
---|
| 539 | else |
---|
| 540 | { |
---|
| 541 | $arr[$key] = addslashes($value); |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | /*! |
---|
| 547 | @function save_repository |
---|
| 548 | @abstract save the the preferences to the repository |
---|
| 549 | @syntax save_repository($update_session_info = False,$type='') |
---|
| 550 | @param $update_session_info old param, seems not to be used |
---|
| 551 | @param $type which prefs to update: user/default/forced |
---|
| 552 | @note the user prefs for saveing are in $this->user not in $this->data, which are the effectiv prefs only |
---|
| 553 | */ |
---|
[1999] | 554 | function save_repository($update_session_info = False,$type='user',$account_id = null) |
---|
[2] | 555 | { |
---|
| 556 | switch($type) |
---|
| 557 | { |
---|
| 558 | case 'forced': |
---|
[1999] | 559 | if ($account_id == null) |
---|
| 560 | $account_id = -1; |
---|
[2] | 561 | $prefs = &$this->forced; |
---|
| 562 | break; |
---|
| 563 | case 'default': |
---|
| 564 | $account_id = -2; |
---|
| 565 | $prefs = &$this->default; |
---|
| 566 | break; |
---|
| 567 | default: |
---|
| 568 | $account_id = (int)$this->account_id; |
---|
| 569 | $prefs = &$this->user; // we use the user-array as data contains default values too |
---|
| 570 | break; |
---|
| 571 | } |
---|
| 572 | //echo "<p>preferences::save_repository(,$type): account_id=$account_id, prefs="; print_r($prefs); echo "</p>\n"; |
---|
| 573 | |
---|
| 574 | if (! $GLOBALS['phpgw']->acl->check('session_only_preferences',1,'preferences')) |
---|
| 575 | { |
---|
| 576 | $this->db->transaction_begin(); |
---|
| 577 | foreach($prefs as $app => $value) |
---|
| 578 | { |
---|
| 579 | if (!is_array($value)) |
---|
| 580 | { |
---|
| 581 | continue; |
---|
| 582 | } |
---|
| 583 | $this->quote($value); |
---|
[1999] | 584 | $value = $this->db->db_addslashes(serialize($value)); // this addslashes is for the database |
---|
[2] | 585 | $app = $this->db->db_addslashes($app); |
---|
| 586 | |
---|
[1999] | 587 | $query = "SELECT (preference_owner, preference_app) FROM phpgw_preferences WHERE preference_owner = '".$account_id."' AND preference_app = '".$app."'"; |
---|
| 588 | |
---|
| 589 | $this->db->query($query, __LINE__, __FILE__); |
---|
| 590 | |
---|
| 591 | if(!$this->db->next_record()) |
---|
| 592 | { |
---|
| 593 | // Insert Db |
---|
| 594 | $query = "INSERT INTO phpgw_preferences(preference_owner,preference_app, preference_value) ". |
---|
| 595 | "VALUES('".$account_id."','".$app."','".$value."')"; |
---|
| 596 | } |
---|
| 597 | else |
---|
| 598 | { |
---|
| 599 | // Update Db |
---|
| 600 | $query = "UPDATE phpgw_preferences SET preference_value = '".$value."' WHERE ". |
---|
| 601 | "preference_owner = '".$account_id."' AND preference_app = '".$app."'"; |
---|
| 602 | } |
---|
| 603 | $this->db->query($query, __LINE__, __FILE__); |
---|
[2] | 604 | } |
---|
| 605 | $this->db->transaction_commit(); |
---|
| 606 | } |
---|
| 607 | else |
---|
| 608 | { |
---|
| 609 | $GLOBALS['phpgw_info']['user']['preferences'] = $this->data; |
---|
| 610 | $GLOBALS['phpgw']->session->save_repositories(); |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | if (($type == 'user' || !$type) && $GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $this->account_id == $GLOBALS['phpgw_info']['user']['account_id']) |
---|
| 614 | { |
---|
| 615 | $GLOBALS['phpgw']->session->delete_cache($this->account_id); |
---|
| 616 | $GLOBALS['phpgw']->session->read_repositories(False); |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | return $this->data; |
---|
| 620 | } |
---|
| 621 | |
---|
| 622 | /*! |
---|
| 623 | @function create_defaults |
---|
| 624 | @abstract insert a copy of the default preferences for use by real account_id |
---|
| 625 | @discussion |
---|
| 626 | @param $account_id numerical id of account for which to create the prefs |
---|
| 627 | */ |
---|
| 628 | function create_defaults($account_id) |
---|
| 629 | { |
---|
| 630 | return; // not longer needed, as the defaults are merged in on runtime |
---|
| 631 | $this->db->query("select * from phpgw_preferences where preference_owner='-2'",__LINE__,__FILE__); |
---|
| 632 | $this->db->next_record(); |
---|
| 633 | |
---|
| 634 | if($this->db->f('preference_value')) |
---|
| 635 | { |
---|
| 636 | $this->db->query("insert into phpgw_preferences values ('$account_id','" |
---|
| 637 | . $this->db->f('preference_value') . "')",__LINE__,__FILE__); |
---|
| 638 | } |
---|
| 639 | |
---|
| 640 | if ($GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $account_id == $GLOBALS['phpgw_info']['user']['account_id']) |
---|
| 641 | { |
---|
| 642 | $GLOBALS['phpgw']->session->read_repositories(False); |
---|
| 643 | } |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | /*! |
---|
| 647 | @function update_data |
---|
| 648 | @abstract update the preferences array |
---|
| 649 | @discussion |
---|
| 650 | @param $data array of preferences |
---|
| 651 | */ |
---|
| 652 | function update_data($data) |
---|
| 653 | { |
---|
| 654 | reset($data); |
---|
| 655 | $this->data = Array(); |
---|
| 656 | $this->data = $data; |
---|
| 657 | reset($this->data); |
---|
| 658 | return $this->data; |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | /* legacy support */ |
---|
| 662 | function change($app_name,$var,$value = "") |
---|
| 663 | { |
---|
| 664 | return $this->add($app_name,$var,$value); |
---|
| 665 | } |
---|
| 666 | function commit($update_session_info = True) |
---|
| 667 | { |
---|
| 668 | //return $this->save_repository($update_session_info); |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | /**************************************************************************\ |
---|
| 672 | * These are the non-standard $this->account_id specific functions * |
---|
| 673 | \**************************************************************************/ |
---|
| 674 | |
---|
| 675 | /*! |
---|
| 676 | @function verify_basic_settings |
---|
| 677 | @abstract verify basic settings |
---|
| 678 | @discussion |
---|
| 679 | */ |
---|
| 680 | function verify_basic_settings() |
---|
| 681 | { |
---|
| 682 | if (!@is_array($GLOBALS['phpgw_info']['user']['preferences'])) |
---|
| 683 | { |
---|
| 684 | $GLOBALS['phpgw_info']['user']['preferences'] = array(); |
---|
| 685 | } |
---|
| 686 | /* This takes care of new users who don't have proper default prefs setup */ |
---|
| 687 | if (!isset($GLOBALS['phpgw_info']['flags']['nocommon_preferences']) || |
---|
| 688 | !$GLOBALS['phpgw_info']['flags']['nocommon_preferences']) |
---|
| 689 | { |
---|
| 690 | $preferences_update = False; |
---|
| 691 | if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) || |
---|
| 692 | !$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) |
---|
| 693 | { |
---|
| 694 | $this->add('common','maxmatchs',15); |
---|
| 695 | $preferences_update = True; |
---|
| 696 | } |
---|
| 697 | if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['theme']) || |
---|
| 698 | !$GLOBALS['phpgw_info']['user']['preferences']['common']['theme']) |
---|
| 699 | { |
---|
| 700 | $this->add('common','theme','default'); |
---|
| 701 | $preferences_update = True; |
---|
| 702 | } |
---|
| 703 | if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']) || |
---|
| 704 | !$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']) |
---|
| 705 | { |
---|
| 706 | $this->add('common','template_set','default'); |
---|
| 707 | $preferences_update = True; |
---|
| 708 | } |
---|
| 709 | if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) || |
---|
| 710 | !$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) |
---|
| 711 | { |
---|
| 712 | $this->add('common','dateformat','m/d/Y'); |
---|
| 713 | $preferences_update = True; |
---|
| 714 | } |
---|
| 715 | if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat']) || |
---|
| 716 | !$GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat']) |
---|
| 717 | { |
---|
| 718 | $this->add('common','timeformat',12); |
---|
| 719 | $preferences_update = True; |
---|
| 720 | } |
---|
| 721 | if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) || |
---|
| 722 | !$GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) |
---|
| 723 | { |
---|
| 724 | $this->add('common','lang',$GLOBALS['phpgw']->common->getPreferredLanguage()); |
---|
| 725 | $preferences_update = True; |
---|
| 726 | } |
---|
| 727 | if ($preferences_update) |
---|
| 728 | { |
---|
| 729 | $this->save_repository(); |
---|
| 730 | } |
---|
| 731 | unset($preferences_update); |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | /****************************************************\ |
---|
| 736 | * Email Preferences and Private Support Functions * |
---|
| 737 | \****************************************************/ |
---|
| 738 | |
---|
| 739 | /*! |
---|
| 740 | @function sub_get_mailsvr_port |
---|
| 741 | @abstract Helper function for create_email_preferences, gets mail server port number. |
---|
| 742 | @discussion This will generate the appropriate port number to access a |
---|
| 743 | mail server of type pop3, pop3s, imap, imaps users value from |
---|
| 744 | $phpgw_info['user']['preferences']['email']['mail_port']. |
---|
| 745 | if that value is not set, it generates a default port for the given $server_type. |
---|
| 746 | Someday, this *MAY* be |
---|
| 747 | (a) a se4rver wide admin setting, or |
---|
| 748 | (b)user custom preference |
---|
| 749 | Until then, simply set the port number based on the mail_server_type, thereof |
---|
| 750 | ONLY call this function AFTER ['email']['mail_server_type'] has been set. |
---|
| 751 | @param $prefs - user preferences array based on element ['email'][] |
---|
| 752 | @author Angles |
---|
| 753 | @access Private |
---|
| 754 | */ |
---|
| 755 | function sub_get_mailsvr_port($prefs, $acctnum=0) |
---|
| 756 | { |
---|
| 757 | // first we try the port number supplied in preferences |
---|
| 758 | if((isset($prefs['email']['accounts'][$acctnum]['mail_port'])) && |
---|
| 759 | ($prefs['email']['accounts'][$acctnum]['mail_port'] != '')) |
---|
| 760 | { |
---|
| 761 | $port_number = $prefs['email']['accounts'][$acctnum]['mail_port']; |
---|
| 762 | } |
---|
| 763 | // preferences does not have a port number, generate a default value |
---|
| 764 | else |
---|
| 765 | { |
---|
| 766 | if (!isset($prefs['email']['accounts'][$acctnum]['mail_server_type'])) |
---|
| 767 | { |
---|
| 768 | $prefs['email']['accounts'][$acctnum]['mail_server_type'] = $prefs['email']['mail_server_type']; |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | switch($prefs['email']['accounts'][$acctnum]['mail_server_type']) |
---|
| 772 | { |
---|
| 773 | case 'pop3s': |
---|
| 774 | // POP3 over SSL |
---|
| 775 | $port_number = 995; |
---|
| 776 | break; |
---|
| 777 | case 'pop3': |
---|
| 778 | // POP3 normal connection, No SSL |
---|
| 779 | // ( same string as normal imap above) |
---|
| 780 | $port_number = 110; |
---|
| 781 | break; |
---|
| 782 | case 'nntp': |
---|
| 783 | // NNTP news server port |
---|
| 784 | $port_number = 119; |
---|
| 785 | break; |
---|
| 786 | case 'imaps': |
---|
| 787 | // IMAP over SSL |
---|
| 788 | $port_number = 993; |
---|
| 789 | break; |
---|
| 790 | case 'imap': |
---|
| 791 | // IMAP normal connection, No SSL |
---|
| 792 | default: |
---|
| 793 | // UNKNOWN SERVER in Preferences, return a |
---|
| 794 | // default value that is likely to work |
---|
| 795 | // probably should raise some kind of error here |
---|
| 796 | $port_number = 143; |
---|
| 797 | break; |
---|
| 798 | } |
---|
| 799 | } |
---|
| 800 | return $port_number; |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | /*! |
---|
| 804 | @function sub_default_userid |
---|
| 805 | @abstract Helper function for create_email_preferences, gets default userid for email |
---|
| 806 | @discussion This will generate the appropriate userid for accessing an email server. |
---|
| 807 | In the absence of a custom ['email']['userid'], this function should be used to set it. |
---|
| 808 | @param $accountid - as determined in and/or passed to "create_email_preferences" |
---|
| 809 | @access Private |
---|
| 810 | */ |
---|
| 811 | function sub_default_userid($account_id='') |
---|
| 812 | { |
---|
| 813 | if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr') |
---|
| 814 | { |
---|
| 815 | $prefs_email_userid = $GLOBALS['phpgw']->accounts->id2name($account_id) |
---|
| 816 | . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']; |
---|
| 817 | } |
---|
| 818 | else |
---|
| 819 | { |
---|
| 820 | $prefs_email_userid = $GLOBALS['phpgw']->accounts->id2name($account_id); |
---|
| 821 | } |
---|
| 822 | return $prefs_email_userid; |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | /*! |
---|
| 826 | @function email_address |
---|
| 827 | @abstract returns the custom email-address (if set) or generates a default one |
---|
| 828 | @discussion This will generate the appropriate email address used as the "From:" |
---|
| 829 | email address when the user sends email, the localpert@domain part. The "personal" |
---|
| 830 | part is generated elsewhere. |
---|
| 831 | In the absence of a custom ['email']['address'], this function should be used to set it. |
---|
| 832 | @param $accountid - as determined in and/or passed to "create_email_preferences" |
---|
| 833 | @access Public now |
---|
| 834 | */ |
---|
| 835 | function email_address($account_id='') |
---|
| 836 | { |
---|
| 837 | if (isset($this->data['email']['address'])) |
---|
| 838 | { |
---|
| 839 | return $this->data['email']['address']; |
---|
| 840 | } |
---|
| 841 | // if email-address is set in the account, return it |
---|
| 842 | if ($email = $GLOBALS['phpgw']->accounts->id2name($account_id,'account_email')) |
---|
| 843 | { |
---|
| 844 | return $email; |
---|
| 845 | } |
---|
| 846 | $prefs_email_address = $GLOBALS['phpgw']->accounts->id2name($account_id); |
---|
| 847 | if (strstr($prefs_email_address,'@') === False) |
---|
| 848 | { |
---|
| 849 | $prefs_email_address .= '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']; |
---|
| 850 | } |
---|
| 851 | return $prefs_email_address; |
---|
| 852 | } |
---|
| 853 | |
---|
| 854 | function sub_default_address($account_id='') |
---|
| 855 | { |
---|
| 856 | return $this->email_address($account_id); |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | /*! |
---|
| 860 | @function create_email_preferences |
---|
| 861 | @abstract create email preferences |
---|
| 862 | @param $account_id -optional defaults to : get_account_id() |
---|
| 863 | @discussion fills a local copy of ['email'][] prefs array which is then returned to the calling |
---|
| 864 | function, which the calling function generally tacks onto the $GLOBALS['phpgw_info'] array as such: |
---|
| 865 | $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences(); |
---|
| 866 | which fills an array based at: |
---|
| 867 | $GLOBALS['phpgw_info']['user']['preferences']['email'][prefs_are_elements_here] |
---|
| 868 | Reading the raw preference DB data and comparing to the email preference schema defined in |
---|
| 869 | /email/class.bopreferences.inc.php (see discussion there and below) to create default preference values |
---|
| 870 | for the in the ['email'][] pref data array in cases where the user has not supplied |
---|
| 871 | a preference value for any particular preference item available to the user. |
---|
| 872 | @access Public |
---|
| 873 | */ |
---|
| 874 | function create_email_preferences($accountid='', $acctnum=0) |
---|
| 875 | { |
---|
| 876 | print_debug('class.preferences: create_email_preferences: ENTERING<br>', 'messageonly','api'); |
---|
| 877 | // we may need function "html_quotes_decode" from the mail_msg class |
---|
| 878 | $email_base = CreateObject("email.mail_msg"); |
---|
| 879 | |
---|
| 880 | $account_id = get_account_id($accountid); |
---|
| 881 | // If the current user is not the request user, grab the preferences |
---|
| 882 | // and reset back to current user. |
---|
| 883 | if($account_id != $this->account_id) |
---|
| 884 | { |
---|
| 885 | // Temporarily store the values to a temp, so when the |
---|
| 886 | // read_repository() is called, it doesn't destory the |
---|
| 887 | // current users settings. |
---|
| 888 | $temp_account_id = $this->account_id; |
---|
| 889 | $temp_data = $this->data; |
---|
| 890 | |
---|
| 891 | // Grab the new users settings, only if they are not the |
---|
| 892 | // current users settings. |
---|
| 893 | $this->account_id = $account_id; |
---|
| 894 | $prefs = $this->read_repository(); |
---|
| 895 | |
---|
| 896 | // Reset the data to what it was prior to this call |
---|
| 897 | $this->account_id = $temp_account_id; |
---|
| 898 | $this->data = $temp_data; |
---|
| 899 | } |
---|
| 900 | else |
---|
| 901 | { |
---|
| 902 | $prefs = $this->data; |
---|
| 903 | } |
---|
| 904 | // are we dealing with the default email account or an extra email account? |
---|
| 905 | if ($acctnum != 0) |
---|
| 906 | { |
---|
| 907 | // prefs are actually a sub-element of the main email prefs |
---|
| 908 | // at location [email][ex_accounts][X][...pref names] => pref values |
---|
| 909 | // make this look like "prefs[email] so the code below code below will do its job transparently |
---|
| 910 | |
---|
| 911 | // store original prefs |
---|
| 912 | $orig_prefs = array(); |
---|
| 913 | $orig_prefs = $prefs; |
---|
| 914 | // obtain the desired sub-array of extra account prefs |
---|
| 915 | $sub_prefs = array(); |
---|
| 916 | $sub_prefs['email'] = $prefs['email']['ex_accounts'][$acctnum]; |
---|
| 917 | // make the switch, make it seem like top level email prefs |
---|
| 918 | $prefs = array(); |
---|
| 919 | $prefs['email'] = $sub_prefs['email']; |
---|
| 920 | // since we return just $prefs, it's up to the calling program to put the sub prefs in the right place |
---|
| 921 | } |
---|
| 922 | print_debug('class.preferences: create_email_preferences: $acctnum: ['.$acctnum.'] ; raw $this->data dump', $this->data,'api'); |
---|
| 923 | |
---|
| 924 | // = = = = NOT-SIMPLE PREFS = = = = |
---|
| 925 | // Default Preferences info that is: |
---|
| 926 | // (a) not controlled by email prefs itself (mostly api and/or server level stuff) |
---|
| 927 | // (b) too complicated to be described in the email prefs data array instructions |
---|
| 928 | |
---|
| 929 | // --- [server][mail_server_type] --- |
---|
| 930 | // Set API Level Server Mail Type if not defined |
---|
| 931 | // if for some reason the API didnot have a mail server type set during initialization |
---|
| 932 | if (empty($GLOBALS['phpgw_info']['server']['mail_server_type'])) |
---|
| 933 | { |
---|
| 934 | $GLOBALS['phpgw_info']['server']['mail_server_type'] = 'imap'; |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | // --- [server][mail_folder] --- |
---|
| 938 | // ==== UWash Mail Folder Location used to be "mail", now it's changeable, but keep the |
---|
| 939 | // ==== default to "mail" so upgrades happen transparently |
---|
| 940 | // --- TEMP MAKE DEFAULT UWASH MAIL FOLDER ~/mail (a.k.a. $HOME/mail) |
---|
| 941 | $GLOBALS['phpgw_info']['server']['mail_folder'] = 'mail'; |
---|
| 942 | // --- DELETE THE ABOVE WHEN THIS OPTION GETS INTO THE SYSTEM SETUP |
---|
| 943 | // pick up custom "mail_folder" if it exists (used for UWash and UWash Maildir servers) |
---|
| 944 | // else use the system default (which we temporarily hard coded to "mail" just above here) |
---|
| 945 | |
---|
| 946 | //--- [email][mail_port] --- |
---|
| 947 | // These sets the mail_port server variable |
---|
| 948 | // someday (not currently) this may be a site-wide property set during site setup |
---|
| 949 | // additionally, someday (not currently) the user may be able to override this with |
---|
| 950 | // a custom email preference. Currently, we simply use standard port numbers |
---|
| 951 | // for the service in question. |
---|
| 952 | $prefs['email']['mail_port'] = $this->sub_get_mailsvr_port($prefs); |
---|
| 953 | |
---|
| 954 | //--- [email][fullname] --- |
---|
| 955 | // we pick this up from phpgw api for the default account |
---|
| 956 | // the user does not directly manipulate this pref for the default email account |
---|
| 957 | if ((string)$acctnum == '0') |
---|
| 958 | { |
---|
| 959 | $prefs['email']['fullname'] = $GLOBALS['phpgw_info']['user']['fullname']; |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | // = = = = SIMPLER PREFS = = = = |
---|
| 963 | |
---|
| 964 | // Default Preferences info that is articulated in the email prefs schema array itself |
---|
| 965 | // such email prefs schema array is described and established in /email/class.bopreferences |
---|
| 966 | // by function "init_available_prefs", see the discussion there. |
---|
| 967 | |
---|
| 968 | // --- create the objectified /email/class.bopreferences.inc.php --- |
---|
| 969 | //Begin Jakjr |
---|
| 970 | #$bo_mail_prefs = CreateObject('email.bopreferences'); |
---|
| 971 | |
---|
| 972 | // --- bo_mail_prefs->init_available_prefs() --- |
---|
| 973 | // this fills object_email_bopreferences->std_prefs and ->cust_prefs |
---|
| 974 | // we will initialize the users preferences according to the rules and instructions |
---|
| 975 | // embodied in those prefs arrays, applying those rules to the unprocessed |
---|
| 976 | // data read from the preferences DB. By taking the raw data and applying those rules, |
---|
| 977 | // we will construct valid and known email preference data for this user. |
---|
| 978 | #$bo_mail_prefs->init_available_prefs(); |
---|
| 979 | |
---|
| 980 | // --- combine the two array (std and cust) for 1 pass handling --- |
---|
| 981 | // when this preference DB was submitted and saved, it was hopefully so well structured |
---|
| 982 | // that we can simply combine the two arrays, std_prefs and cust_prefs, and do a one |
---|
| 983 | // pass analysis and preparation of this users preferences. |
---|
| 984 | #$avail_pref_array = $bo_mail_prefs->std_prefs; |
---|
| 985 | #$c_cust_prefs = count($bo_mail_prefs->cust_prefs); |
---|
| 986 | #for($i=0;$i<$c_cust_prefs;$i++) |
---|
| 987 | #{ |
---|
| 988 | # // add each custom prefs to the std prefs array |
---|
| 989 | # $next_idx = count($avail_pref_array); |
---|
| 990 | # $avail_pref_array[$next_idx] = $bo_mail_prefs->cust_prefs[$i]; |
---|
| 991 | #} |
---|
| 992 | print_debug('class.preferences: create_email_preferences: std AND cust arrays combined:', $avail_pref_array,'api'); |
---|
| 993 | |
---|
| 994 | // --- make the schema-based pref data for this user --- |
---|
| 995 | // user defined values and/or user specified custom email prefs are read from the |
---|
| 996 | // prefs DB with mininal manipulation of the data. Currently the only change to |
---|
| 997 | // users raw data is related to reversing the encoding of "database un-friendly" chars |
---|
| 998 | // which itself may become unnecessary if and when the database handlers can reliably |
---|
| 999 | // take care of this for us. Of course, password data requires special decoding, |
---|
| 1000 | // but the password in the array [email][paswd] should be left in encrypted form |
---|
| 1001 | // and only decrypted seperately when used to login in to an email server. |
---|
| 1002 | |
---|
| 1003 | // --- generating a default value if necessary --- |
---|
| 1004 | // in the absence of a user defined custom email preference for a particular item, we can |
---|
| 1005 | // determine the desired default value for that pref as such: |
---|
| 1006 | // $this_avail_pref['init_default'] is a comma seperated seperated string which should |
---|
| 1007 | // be exploded into an array containing 2 elements that are: |
---|
| 1008 | // exploded[0] : an description of how to handle the next string element to get a default value. |
---|
| 1009 | // Possible "instructional tokens" for exploded[0] (called $set_proc[0] below) are: |
---|
| 1010 | // string |
---|
| 1011 | // set_or_not |
---|
| 1012 | // function |
---|
| 1013 | // init_no_fill |
---|
| 1014 | // varEVAL |
---|
| 1015 | // tells you how to handle the string in exploded[1] (called $set_proc[1] below) to get a valid |
---|
| 1016 | // default value for a particular preference if one is needed (i.e. if no user custom |
---|
| 1017 | // email preference exists that should override that default value, in which case we |
---|
| 1018 | // do not even need to obtain such a default value as described in ['init_default'] anyway). |
---|
| 1019 | |
---|
| 1020 | // --- loop thru $avail_pref_array and process each pref item --- |
---|
| 1021 | $c_prefs = count($avail_pref_array); |
---|
| 1022 | for($i=0;$i<$c_prefs;$i++) |
---|
| 1023 | { |
---|
| 1024 | $this_avail_pref = $avail_pref_array[$i]; |
---|
| 1025 | 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'); |
---|
| 1026 | print_debug('class.preferences: create_email_preferences: std/cust_prefs $this_avail_pref['.$i.'] dump:', $this_avail_pref,'api'); |
---|
| 1027 | |
---|
| 1028 | // --- is there a value in the DB for this preference item --- |
---|
| 1029 | // if the prefs DB has no value for this defined available preference, we must make one. |
---|
| 1030 | // This occurs if (a) this is user's first login, or (b) this is a custom pref which the user |
---|
| 1031 | // has not overriden, do a default (non-custom) value is needed. |
---|
| 1032 | if (!isset($prefs['email'][$this_avail_pref['id']])) |
---|
| 1033 | { |
---|
| 1034 | // now we are analizing an individual pref that is available to the user |
---|
| 1035 | // AND the user had no existing value in the prefs DB for this. |
---|
| 1036 | |
---|
| 1037 | // --- get instructions on how to generate a default value --- |
---|
| 1038 | $set_proc = explode(',', $this_avail_pref['init_default']); |
---|
| 1039 | print_debug(' * set_proc=['.serialize($set_proc).']', 'messageonly','api'); |
---|
| 1040 | |
---|
| 1041 | // --- use "instructional token" in $set_proc[0] to take appropriate action --- |
---|
| 1042 | // STRING |
---|
| 1043 | if ($set_proc[0] == 'string') |
---|
| 1044 | { |
---|
| 1045 | // means this pref item's value type is string |
---|
| 1046 | // which defined string default value is in $set_proc[1] |
---|
| 1047 | print_debug('* handle "string" set_proc: ', serialize($set_proc),'api'); |
---|
| 1048 | if (trim($set_proc[1]) == '') |
---|
| 1049 | { |
---|
| 1050 | // this happens when $this_avail_pref['init_default'] = "string, " |
---|
| 1051 | $this_string = ''; |
---|
| 1052 | } |
---|
| 1053 | else |
---|
| 1054 | { |
---|
| 1055 | $this_string = $set_proc[1]; |
---|
| 1056 | } |
---|
| 1057 | $prefs['email'][$this_avail_pref['id']] = $this_string; |
---|
| 1058 | } |
---|
| 1059 | // SET_OR_NOT |
---|
| 1060 | elseif ($set_proc[0] == 'set_or_not') |
---|
| 1061 | { |
---|
| 1062 | // typical with boolean options, True = "set/exists" and False = unset |
---|
| 1063 | print_debug('* handle "set_or_not" set_proc: ', serialize($set_proc),'api'); |
---|
| 1064 | if ($set_proc[1] == 'not_set') |
---|
| 1065 | { |
---|
| 1066 | // leave it NOT SET |
---|
| 1067 | } |
---|
| 1068 | else |
---|
| 1069 | { |
---|
| 1070 | // opposite of boolean not_set = string "True" which simply sets a |
---|
| 1071 | // value it exists in the users session [email][] preference array |
---|
| 1072 | $prefs['email'][$this_avail_pref['id']] = 'True'; |
---|
| 1073 | } |
---|
| 1074 | } |
---|
| 1075 | // FUNCTION |
---|
| 1076 | elseif ($set_proc[0] == 'function') |
---|
| 1077 | { |
---|
| 1078 | // string in $set_proc[1] should be "eval"uated as code, calling a function |
---|
| 1079 | // which will give us a default value to put in users session [email][] prefs array |
---|
| 1080 | print_debug(' * handle "function" set_proc: ', serialize($set_proc),'api'); |
---|
| 1081 | $evaled = ''; |
---|
| 1082 | //eval('$evaled = $this->'.$set_proc[1].'('.$account_id.');'); |
---|
| 1083 | |
---|
| 1084 | $code = '$evaled = $this->'.$set_proc[1].'('.$account_id.');'; |
---|
| 1085 | print_debug(' * $code: ', $code,'api'); |
---|
| 1086 | eval($code); |
---|
| 1087 | |
---|
| 1088 | print_debug('* $evaled:', $evaled,'api'); |
---|
| 1089 | $prefs['email'][$this_avail_pref['id']] = $evaled; |
---|
| 1090 | } |
---|
| 1091 | // INIT_NO_FILL |
---|
| 1092 | elseif ($set_proc[0] == 'init_no_fill') |
---|
| 1093 | { |
---|
| 1094 | // we have an available preference item that we may NOT fill with a default |
---|
| 1095 | // value. Only the user may supply a value for this pref item. |
---|
| 1096 | print_debug('* handle "init_no_fill" set_proc:', serialize($set_proc),'api'); |
---|
| 1097 | // we are FORBADE from filling this at this time! |
---|
| 1098 | } |
---|
| 1099 | // varEVAL |
---|
| 1100 | elseif ($set_proc[0] == 'varEVAL') |
---|
| 1101 | { |
---|
| 1102 | // similar to "function" but used for array references, the string in $set_proc[1] |
---|
| 1103 | // represents code which typically is an array referencing a system/api property |
---|
| 1104 | print_debug('* handle "GLOBALS" set_proc:', serialize($set_proc),'api'); |
---|
| 1105 | $evaled = ''; |
---|
| 1106 | $code = '$evaled = '.$set_proc[1]; |
---|
| 1107 | print_debug(' * $code:', $code,'api'); |
---|
| 1108 | eval($code); |
---|
| 1109 | print_debug('* $evaled:', $evaled,'api'); |
---|
| 1110 | $prefs['email'][$this_avail_pref['id']] = $evaled; |
---|
| 1111 | } |
---|
| 1112 | else |
---|
| 1113 | { |
---|
| 1114 | // error, no instructions on how to handle this element's default value creation |
---|
| 1115 | echo 'class.preferences: create_email_preferences: set_proc ERROR: '.serialize($set_proc).'<br>'; |
---|
| 1116 | } |
---|
| 1117 | } |
---|
| 1118 | else |
---|
| 1119 | { |
---|
| 1120 | // we have a value in the database, do we need to prepare it in any way? |
---|
| 1121 | // (the following discussion is unconfirmed:) |
---|
| 1122 | // DO NOT ALTER the data in the prefs array!!!! or the next time we call |
---|
| 1123 | // save_repository withOUT undoing what we might do here, the |
---|
| 1124 | // prefs will permenantly LOOSE the very thing(s) we are un-doing |
---|
| 1125 | /// here until the next OFFICIAL submit email prefs function, where it |
---|
| 1126 | // will again get this preparation before being written to the database. |
---|
| 1127 | |
---|
| 1128 | // NOTE: if database de-fanging is eventually handled deeper in the |
---|
| 1129 | // preferences class, then the following code would become depreciated |
---|
| 1130 | // and should be removed in that case. |
---|
| 1131 | if (($this_avail_pref['type'] == 'user_string') && |
---|
| 1132 | (stristr($this_avail_pref['write_props'], 'no_db_defang') == False)) |
---|
| 1133 | { |
---|
| 1134 | // this value was "de-fanged" before putting it in the database |
---|
| 1135 | // undo that defanging now |
---|
| 1136 | $db_unfriendly = $email_base->html_quotes_decode($prefs['email'][$this_avail_pref['id']]); |
---|
| 1137 | $prefs['email'][$this_avail_pref['id']] = $db_unfriendly; |
---|
| 1138 | } |
---|
| 1139 | } |
---|
| 1140 | } |
---|
| 1141 | // users preferences are now established to known structured values... |
---|
| 1142 | |
---|
| 1143 | // SANITY CHECK |
---|
| 1144 | // --- [email][use_trash_folder] --- |
---|
| 1145 | // --- [email][use_sent_folder] --- |
---|
| 1146 | // is it possible to use Trash and Sent folders - i.e. using IMAP server |
---|
| 1147 | // if not - force settings to false |
---|
[771] | 1148 | if (strpos($prefs['email']['mail_server_type'], 'imap') == False) |
---|
[2] | 1149 | { |
---|
| 1150 | if (isset($prefs['email']['use_trash_folder'])) |
---|
| 1151 | { |
---|
| 1152 | unset($prefs['email']['use_trash_folder']); |
---|
| 1153 | } |
---|
| 1154 | |
---|
| 1155 | if (isset($prefs['email']['use_sent_folder'])) |
---|
| 1156 | { |
---|
| 1157 | unset($prefs['email']['use_sent_folder']); |
---|
| 1158 | } |
---|
| 1159 | } |
---|
| 1160 | |
---|
| 1161 | // DEBUG : force some settings to test stuff |
---|
| 1162 | //$prefs['email']['p_persistent'] = 'True'; |
---|
| 1163 | |
---|
| 1164 | print_debug('class.preferences: $acctnum: ['.$acctnum.'] ; create_email_preferences: $prefs[email]', $prefs['email'],'api'); |
---|
| 1165 | print_debug('class.preferences: create_email_preferences: LEAVING', 'messageonly','api'); |
---|
| 1166 | return $prefs; |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | /* |
---|
| 1170 | // ==== DEPRECATED - ARCHIVAL CODE ==== |
---|
| 1171 | // used to be part of function this->create_email_preferences() |
---|
| 1172 | // = = = = SIMPLER PREFS = = = = |
---|
| 1173 | // Default Preferences info that is: |
---|
| 1174 | // described in the email prefs array itself |
---|
| 1175 | |
---|
| 1176 | $default_trash_folder = 'Trash'; |
---|
| 1177 | $default_sent_folder = 'Sent'; |
---|
| 1178 | |
---|
| 1179 | // --- userid --- |
---|
| 1180 | if (!isset($prefs['email']['userid'])) |
---|
| 1181 | { |
---|
| 1182 | $prefs['email']['userid'] = $this->sub_default_userid($accountid); |
---|
| 1183 | } |
---|
| 1184 | // --- address --- |
---|
| 1185 | if (!isset($prefs['email']['address'])) |
---|
| 1186 | { |
---|
| 1187 | $prefs['email']['address'] = $this->email_address($accountid); |
---|
| 1188 | } |
---|
| 1189 | // --- mail_server --- |
---|
| 1190 | if (!isset($prefs['email']['mail_server'])) |
---|
| 1191 | { |
---|
| 1192 | $prefs['email']['mail_server'] = $GLOBALS['phpgw_info']['server']['mail_server']; |
---|
| 1193 | } |
---|
| 1194 | // --- mail_server_type --- |
---|
| 1195 | if (!isset($prefs['email']['mail_server_type'])) |
---|
| 1196 | { |
---|
| 1197 | $prefs['email']['mail_server_type'] = $GLOBALS['phpgw_info']['server']['mail_server_type']; |
---|
| 1198 | } |
---|
| 1199 | // --- imap_server_type --- |
---|
| 1200 | if (!isset($prefs['email']['imap_server_type'])) |
---|
| 1201 | { |
---|
| 1202 | $prefs['email']['imap_server_type'] = $GLOBALS['phpgw_info']['server']['imap_server_type']; |
---|
| 1203 | } |
---|
| 1204 | // --- mail_folder --- |
---|
| 1205 | // because of the way this option works, an empty string IS ACTUALLY a valid value |
---|
| 1206 | // which represents the $HOME/* as the UWash mail files location |
---|
| 1207 | // THERFOR we must check the "Use_custom_setting" option to help us figure out what to do |
---|
| 1208 | if (!isset($prefs['email']['use_custom_settings'])) |
---|
| 1209 | { |
---|
| 1210 | // we are NOT using custom settings so this MUST be the server default |
---|
| 1211 | $prefs['email']['mail_folder'] = $GLOBALS['phpgw_info']['server']['mail_folder']; |
---|
| 1212 | } |
---|
| 1213 | else |
---|
| 1214 | { |
---|
| 1215 | // we ARE using custom settings AND a BLANK STRING is a valid option, so... |
---|
| 1216 | if ((isset($prefs['email']['mail_folder'])) |
---|
| 1217 | && ($prefs['email']['mail_folder'] != '')) |
---|
| 1218 | { |
---|
| 1219 | // using custom AND a string exists, so "mail_folder" is that string stored in the custom prefs by the user |
---|
| 1220 | // DO NOTING - VALID OPTION VALUE for $prefs['email']['mail_folder'] |
---|
| 1221 | } |
---|
| 1222 | else |
---|
| 1223 | { |
---|
| 1224 | // using Custom Prefs BUT this text box was left empty by the user on submit, so no value stored |
---|
| 1225 | // BUT since we are using custom prefs, "mail_folder" MUST BE AN EMPTY STRING |
---|
| 1226 | // which is an acceptable, valid preference, overriding any value which |
---|
| 1227 | // may have been set in ["server"]["mail_folder"] |
---|
| 1228 | // This is one of the few instances in the preference class where an empty, unspecified value |
---|
| 1229 | // actually does NOT get deleted from the repository. |
---|
| 1230 | $prefs['email']['mail_folder'] = ''; |
---|
| 1231 | } |
---|
| 1232 | } |
---|
| 1233 | |
---|
| 1234 | // --- use_trash_folder --- |
---|
| 1235 | // --- trash_folder_name --- |
---|
| 1236 | // if the option to use the Trash folder is ON, make sure a proper name is specified |
---|
| 1237 | if (isset($prefs['email']['use_trash_folder'])) |
---|
| 1238 | { |
---|
| 1239 | if ((!isset($prefs['email']['trash_folder_name'])) |
---|
| 1240 | || ($prefs['email']['trash_folder_name'] == '')) |
---|
| 1241 | { |
---|
| 1242 | $prefs['email']['trash_folder_name'] = $default_trash_folder; |
---|
| 1243 | } |
---|
| 1244 | } |
---|
| 1245 | |
---|
| 1246 | // --- use_sent_folder --- |
---|
| 1247 | // --- sent_folder_name --- |
---|
| 1248 | // if the option to use the sent folder is ON, make sure a proper name is specified |
---|
| 1249 | if (isset($prefs['email']['use_sent_folder'])) |
---|
| 1250 | { |
---|
| 1251 | if ((!isset($prefs['email']['sent_folder_name'])) |
---|
| 1252 | || ($prefs['email']['sent_folder_name'] == '')) |
---|
| 1253 | { |
---|
| 1254 | $prefs['email']['sent_folder_name'] = $default_sent_folder; |
---|
| 1255 | } |
---|
| 1256 | } |
---|
| 1257 | |
---|
| 1258 | // --- layout --- |
---|
| 1259 | // Layout Template Preference |
---|
| 1260 | // layout 1 = default ; others are prefs |
---|
| 1261 | if (!isset($prefs['email']['layout'])) |
---|
| 1262 | { |
---|
| 1263 | $prefs['email']['layout'] = 1; |
---|
| 1264 | } |
---|
| 1265 | |
---|
| 1266 | //// --- font_size_offset --- |
---|
| 1267 | //// Email Index Page Font Size Preference |
---|
| 1268 | //// layout 1 = default ; others are prefs |
---|
| 1269 | //if (!isset($prefs['email']['font_size_offset'])) |
---|
| 1270 | //{ |
---|
| 1271 | // $prefs['email']['font_size_offset'] = 'normal'; |
---|
| 1272 | //} |
---|
| 1273 | |
---|
| 1274 | // SANITY CHECK |
---|
| 1275 | // --- use_trash_folder --- |
---|
| 1276 | // --- use_sent_folder --- |
---|
| 1277 | // is it possible to use Trash and Sent folders - i.e. using IMAP server |
---|
| 1278 | // if not - force settings to false |
---|
| 1279 | if (stristr($prefs['email']['mail_server_type'], 'imap') == False) |
---|
| 1280 | { |
---|
| 1281 | if (isset($prefs['email']['use_trash_folder'])) |
---|
| 1282 | { |
---|
| 1283 | unset($prefs['email']['use_trash_folder']); |
---|
| 1284 | } |
---|
| 1285 | |
---|
| 1286 | if (isset($prefs['email']['use_sent_folder'])) |
---|
| 1287 | { |
---|
| 1288 | unset($prefs['email']['use_sent_folder']); |
---|
| 1289 | } |
---|
| 1290 | } |
---|
| 1291 | |
---|
| 1292 | // DEBUG : force some settings to test stuff |
---|
| 1293 | //$prefs['email']['layout'] = 1; |
---|
| 1294 | //$prefs['email']['layout'] = 2; |
---|
| 1295 | //$prefs['email']['font_size_offset'] = (-1); |
---|
| 1296 | |
---|
| 1297 | // DEBUG |
---|
| 1298 | //echo "<br>prefs['email']: <br>" |
---|
| 1299 | // .'<pre>'.serialize($prefs['email']) .'</pre><br>'; |
---|
| 1300 | return $prefs; |
---|
| 1301 | */ |
---|
| 1302 | } /* end of preferences class */ |
---|
| 1303 | ?> |
---|