source: trunk/phpgwapi/inc/class.preferences.inc.php @ 7655

Revision 7655, 45.4 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

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