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

Revision 7979, 45.5 KB checked in by angelo, 11 years ago (diff)

Ticket #3367 - Problema ao gravar assinatura com formatacao no banco

  • 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                                        if ($this->db->Type == "pgsql" && isset($value['signature'])){
570                                                $value['signature'] = pg_escape_string($value['signature']);                                                   
571                                        }
572                                        $this->db->query($sql = "INSERT INTO phpgw_preferences"
573                                                . " (preference_owner,preference_app,preference_value)"
574                                                . " VALUES ($account_id,'$app','$value')",__LINE__,__FILE__);
575                                }
576                                $this->db->transaction_commit();
577                        }
578                        else
579                        {
580                                $GLOBALS['phpgw_info']['user']['preferences'] = $this->data;
581                                $GLOBALS['phpgw']->session->save_repositories();
582                        }
583
584                        if (($type == 'user' || !$type) && $GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $this->account_id == $GLOBALS['phpgw_info']['user']['account_id'])
585                        {
586                                $GLOBALS['phpgw']->session->delete_cache($this->account_id);
587                                $GLOBALS['phpgw']->session->read_repositories(False);
588                        }
589
590                        return $this->data;
591                }
592
593                /*!
594                @function create_defaults
595                @abstract insert a copy of the default preferences for use by real account_id
596                @discussion
597                @param $account_id numerical id of account for which to create the prefs
598                */
599                function create_defaults($account_id)
600                {
601                        return; // not longer needed, as the defaults are merged in on runtime
602                        $this->db->query("select * from phpgw_preferences where preference_owner='-2'",__LINE__,__FILE__);
603                        $this->db->next_record();
604
605                        if($this->db->f('preference_value'))
606                        {
607                                $this->db->query("insert into phpgw_preferences values ('$account_id','"
608                                        . $this->db->f('preference_value') . "')",__LINE__,__FILE__);
609                        }
610
611                        if ($GLOBALS['phpgw_info']['server']['cache_phpgw_info'] && $account_id == $GLOBALS['phpgw_info']['user']['account_id'])
612                        {
613                                $GLOBALS['phpgw']->session->read_repositories(False);
614                        }
615                }
616
617                /*!
618                @function update_data
619                @abstract update the preferences array
620                @discussion
621                @param $data array of preferences
622                */
623                function update_data($data)
624                {
625                        reset($data);
626                        $this->data = Array();
627                        $this->data = $data;
628                        reset($this->data);
629                        return $this->data;
630                }
631
632                /* legacy support */
633                function change($app_name,$var,$value = "")
634                {
635                        return $this->add($app_name,$var,$value);
636                }
637                function commit($update_session_info = True)
638                {
639                        //return $this->save_repository($update_session_info);
640                }
641
642                /**************************************************************************\
643                * These are the non-standard $this->account_id specific functions          *
644                \**************************************************************************/
645
646                /*!
647                @function verify_basic_settings
648                @abstract verify basic settings
649                @discussion
650                */
651                function verify_basic_settings()
652                {
653                        if (!@is_array($GLOBALS['phpgw_info']['user']['preferences']))
654                        {
655                                $GLOBALS['phpgw_info']['user']['preferences'] = array();
656                        }
657                        /* This takes care of new users who don't have proper default prefs setup */
658                        if (!isset($GLOBALS['phpgw_info']['flags']['nocommon_preferences']) ||
659                                !$GLOBALS['phpgw_info']['flags']['nocommon_preferences'])
660                        {
661                                $preferences_update = False;
662                                if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) ||
663                                        !$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'])
664                                {
665                                        $this->add('common','maxmatchs',15);
666                                        $preferences_update = True;
667                                }
668                                if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['theme']) ||
669                                        !$GLOBALS['phpgw_info']['user']['preferences']['common']['theme'])
670                                {
671                                        $this->add('common','theme','default');
672                                        $preferences_update = True;
673                                }
674                                if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']) ||
675                                        !$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'])
676                                {
677                                        $this->add('common','template_set','default');
678                                        $preferences_update = True;
679                                }
680                                if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) ||
681                                        !$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
682                                {
683                                        $this->add('common','dateformat','m/d/Y');
684                                        $preferences_update = True;
685                                }
686                                if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat']) ||
687                                        !$GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'])
688                                {
689                                        $this->add('common','timeformat',12);
690                                        $preferences_update = True;
691                                }
692                                if (!isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) ||
693                                        !$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
694                                {
695                                        $this->add('common','lang',$GLOBALS['phpgw']->common->getPreferredLanguage());
696                                        $preferences_update = True;
697                                }
698                                if ($preferences_update)
699                                {
700                                        $this->save_repository();
701                                }
702                                unset($preferences_update);
703                        }
704                }
705
706                /****************************************************\
707                * Email Preferences and Private Support Functions   *
708                \****************************************************/
709
710                /*!
711                @function sub_get_mailsvr_port
712                @abstract Helper function for create_email_preferences, gets mail server port number.
713                @discussion This will generate the appropriate port number to access a
714                mail server of type pop3, pop3s, imap, imaps users value from
715                $phpgw_info['user']['preferences']['email']['mail_port'].
716                if that value is not set, it generates a default port for the given $server_type.
717                Someday, this *MAY* be
718                (a) a se4rver wide admin setting, or
719                (b)user custom preference
720                Until then, simply set the port number based on the mail_server_type, thereof
721                ONLY call this function AFTER ['email']['mail_server_type'] has been set.
722                @param $prefs - user preferences array based on element ['email'][]
723                @author  Angles
724                @access Private
725                */
726                function sub_get_mailsvr_port($prefs, $acctnum=0)
727                {
728                        // first we try the port number supplied in preferences
729                        if((isset($prefs['email']['accounts'][$acctnum]['mail_port'])) &&
730                                ($prefs['email']['accounts'][$acctnum]['mail_port'] != ''))
731                        {
732                                $port_number = $prefs['email']['accounts'][$acctnum]['mail_port'];
733                        }
734                        // preferences does not have a port number, generate a default value
735                        else
736                        {
737                                if (!isset($prefs['email']['accounts'][$acctnum]['mail_server_type']))
738                                {
739                                        $prefs['email']['accounts'][$acctnum]['mail_server_type'] = $prefs['email']['mail_server_type'];
740                                }
741
742                                switch($prefs['email']['accounts'][$acctnum]['mail_server_type'])
743                                {
744                                        case 'pop3s':
745                                                // POP3 over SSL
746                                                $port_number = 995;
747                                                break;
748                                        case 'pop3':
749                                                // POP3 normal connection, No SSL
750                                                // ( same string as normal imap above)
751                                                $port_number = 110;
752                                                break;
753                                        case 'nntp':
754                                                // NNTP news server port
755                                                $port_number = 119;
756                                                break;
757                                        case 'imaps':
758                                                // IMAP over SSL
759                                                $port_number = 993;
760                                                break;
761                                        case 'imap':
762                                                // IMAP normal connection, No SSL
763                                        default:
764                                                // UNKNOWN SERVER in Preferences, return a
765                                                // default value that is likely to work
766                                                // probably should raise some kind of error here
767                                                $port_number = 143;
768                                                break;
769                                }
770                        }
771                        return $port_number;
772                }
773
774                /*!
775                @function sub_default_userid
776                @abstract Helper function for create_email_preferences, gets default userid for email
777                @discussion This will generate the appropriate userid for accessing an email server.
778                In the absence of a custom ['email']['userid'], this function should be used to set it.
779                @param $accountid - as determined in and/or passed to "create_email_preferences"
780                @access Private
781                */
782                function sub_default_userid($account_id='')
783                {
784                        if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr')
785                        {
786                                $prefs_email_userid = $GLOBALS['phpgw']->accounts->id2name($account_id)
787                                        . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
788                        }
789                        else
790                        {
791                                $prefs_email_userid = $GLOBALS['phpgw']->accounts->id2name($account_id);
792                        }
793                        return $prefs_email_userid;
794                }
795
796                /*!
797                @function email_address
798                @abstract returns the custom email-address (if set) or generates a default one
799                @discussion This will generate the appropriate email address used as the "From:"
800                email address when the user sends email, the localpert@domain part. The "personal"
801                part is generated elsewhere.
802                In the absence of a custom ['email']['address'], this function should be used to set it.
803                @param $accountid - as determined in and/or passed to "create_email_preferences"
804                @access Public now
805                */
806                function email_address($account_id='')
807                {
808                        if (isset($this->data['email']['address']))
809                        {
810                                return $this->data['email']['address'];
811                        }
812                        // if email-address is set in the account, return it
813                        if ($email = $GLOBALS['phpgw']->accounts->id2name($account_id,'account_email'))
814                        {
815                                return $email;
816                        }
817                        $prefs_email_address = $GLOBALS['phpgw']->accounts->id2name($account_id);
818                        if (strstr($prefs_email_address,'@') === False)
819                        {
820                                $prefs_email_address .= '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
821                        }
822                        return $prefs_email_address;
823                }
824
825                function sub_default_address($account_id='')
826                {
827                        return $this->email_address($account_id);
828                }
829
830                /*!
831                @function create_email_preferences
832                @abstract create email preferences
833                @param $account_id -optional defaults to : get_account_id()
834                @discussion fills a local copy of ['email'][] prefs array which is then returned to the calling
835                function, which the calling function generally tacks onto the $GLOBALS['phpgw_info'] array as such:
836                        $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences();
837                which fills an array based at:
838                        $GLOBALS['phpgw_info']['user']['preferences']['email'][prefs_are_elements_here]
839                Reading the raw preference DB data and comparing to the email preference schema defined in
840                /email/class.bopreferences.inc.php (see discussion there and below) to create default preference values
841                for the  in the ['email'][] pref data array in cases where the user has not supplied
842                a preference value for any particular preference item available to the user.
843                @access Public
844                */
845                function create_email_preferences($accountid='', $acctnum=0)
846                {
847                        print_debug('class.preferences: create_email_preferences: ENTERING<br>', 'messageonly','api');
848                        // we may need function "html_quotes_decode" from the mail_msg class
849                        $email_base = CreateObject("email.mail_msg");
850
851                        $account_id = get_account_id($accountid);
852                        // If the current user is not the request user, grab the preferences
853                        // and reset back to current user.
854                        if($account_id != $this->account_id)
855                        {
856                                // Temporarily store the values to a temp, so when the
857                                // read_repository() is called, it doesn't destory the
858                                // current users settings.
859                                $temp_account_id = $this->account_id;
860                                $temp_data = $this->data;
861
862                                // Grab the new users settings, only if they are not the
863                                // current users settings.
864                                $this->account_id = $account_id;
865                                $prefs = $this->read_repository();
866
867                                // Reset the data to what it was prior to this call
868                                $this->account_id = $temp_account_id;
869                                $this->data = $temp_data;
870                        }
871                        else
872                        {
873                                $prefs = $this->data;
874                        }
875                        // are we dealing with the default email account or an extra email account?
876                        if ($acctnum != 0)
877                        {
878                                // prefs are actually a sub-element of the main email prefs
879                                // at location [email][ex_accounts][X][...pref names] => pref values
880                                // make this look like "prefs[email] so the code below code below will do its job transparently
881                               
882                                // store original prefs
883                                $orig_prefs = array();
884                                $orig_prefs = $prefs;
885                                // obtain the desired sub-array of extra account prefs
886                                $sub_prefs = array();
887                                $sub_prefs['email'] = $prefs['email']['ex_accounts'][$acctnum];
888                                // make the switch, make it seem like top level email prefs
889                                $prefs = array();
890                                $prefs['email'] = $sub_prefs['email'];
891                                // since we return just $prefs, it's up to the calling program to put the sub prefs in the right place
892                        }
893                        print_debug('class.preferences: create_email_preferences: $acctnum: ['.$acctnum.'] ; raw $this->data dump', $this->data,'api');
894
895                        // = = = =  NOT-SIMPLE  PREFS  = = = =
896                        // Default Preferences info that is:
897                        // (a) not controlled by email prefs itself (mostly api and/or server level stuff)
898                        // (b) too complicated to be described in the email prefs data array instructions
899                       
900                        // ---  [server][mail_server_type]  ---
901                        // Set API Level Server Mail Type if not defined
902                        // if for some reason the API didnot have a mail server type set during initialization
903                        if (empty($GLOBALS['phpgw_info']['server']['mail_server_type']))
904                        {
905                                $GLOBALS['phpgw_info']['server']['mail_server_type'] = 'imap';
906                        }
907
908                        // ---  [server][mail_folder]  ---
909                        // ====  UWash Mail Folder Location used to be "mail", now it's changeable, but keep the
910                        // ====  default to "mail" so upgrades happen transparently
911                        // ---  TEMP MAKE DEFAULT UWASH MAIL FOLDER ~/mail (a.k.a. $HOME/mail)
912                        $GLOBALS['phpgw_info']['server']['mail_folder'] = 'mail';
913                        // ---  DELETE THE ABOVE WHEN THIS OPTION GETS INTO THE SYSTEM SETUP
914                        // pick up custom "mail_folder" if it exists (used for UWash and UWash Maildir servers)
915                        // else use the system default (which we temporarily hard coded to "mail" just above here)
916
917                        //---  [email][mail_port]  ---
918                        // These sets the mail_port server variable
919                        // someday (not currently) this may be a site-wide property set during site setup
920                        // additionally, someday (not currently) the user may be able to override this with
921                        // a custom email preference. Currently, we simply use standard port numbers
922                        // for the service in question.
923                        $prefs['email']['mail_port'] = $this->sub_get_mailsvr_port($prefs);
924
925                        //---  [email][fullname]  ---
926                        // we pick this up from phpgw api for the default account
927                        // the user does not directly manipulate this pref for the default email account
928                        if ((string)$acctnum == '0')
929                        {
930                                $prefs['email']['fullname'] = $GLOBALS['phpgw_info']['user']['fullname'];
931                        }
932
933                        // = = = =  SIMPLER PREFS  = = = =
934
935                        // Default Preferences info that is articulated in the email prefs schema array itself
936                        // such email prefs schema array is described and established in /email/class.bopreferences
937                        // by function "init_available_prefs", see the discussion there.
938
939                        // --- create the objectified /email/class.bopreferences.inc.php ---
940                        //Begin Jakjr
941                        #$bo_mail_prefs = CreateObject('email.bopreferences');
942
943                        // --- bo_mail_prefs->init_available_prefs() ---
944                        // this fills object_email_bopreferences->std_prefs and ->cust_prefs
945                        // we will initialize the users preferences according to the rules and instructions
946                        // embodied in those prefs arrays, applying those rules to the unprocessed
947                        // data read from the preferences DB. By taking the raw data and applying those rules,
948                        // we will construct valid and known email preference data for this user.
949                        #$bo_mail_prefs->init_available_prefs();
950
951                        // --- combine the two array (std and cust) for 1 pass handling ---
952                        // when this preference DB was submitted and saved, it was hopefully so well structured
953                        // that we can simply combine the two arrays, std_prefs and cust_prefs, and do a one
954                        // pass analysis and preparation of this users preferences.
955                        #$avail_pref_array = $bo_mail_prefs->std_prefs;
956                        #$c_cust_prefs = count($bo_mail_prefs->cust_prefs);
957                        #for($i=0;$i<$c_cust_prefs;++$i)
958                        #{
959                        #       // add each custom prefs to the std prefs array
960                        #       $next_idx = count($avail_pref_array);
961                        #       $avail_pref_array[$next_idx] = $bo_mail_prefs->cust_prefs[$i];
962                        #}
963                        print_debug('class.preferences: create_email_preferences: std AND cust arrays combined:', $avail_pref_array,'api');
964
965                        // --- make the schema-based pref data for this user ---
966                        // user defined values and/or user specified custom email prefs are read from the
967                        // prefs DB with mininal manipulation of the data. Currently the only change to
968                        // users raw data is related to reversing the encoding of "database un-friendly" chars
969                        // which itself may become unnecessary if and when the database handlers can reliably
970                        // take care of this for us. Of course, password data requires special decoding,
971                        // but the password in the array [email][paswd] should be left in encrypted form
972                        // and only decrypted seperately when used to login in to an email server.
973
974                        // --- generating a default value if necessary ---
975                        // in the absence of a user defined custom email preference for a particular item, we can
976                        // determine the desired default value for that pref as such:
977                        // $this_avail_pref['init_default']  is a comma seperated seperated string which should
978                        // be exploded into an array containing 2 elements that are:
979                        // exploded[0] : an description of how to handle the next string element to get a default value.
980                        // Possible "instructional tokens" for exploded[0] (called $set_proc[0] below) are:
981                        //      string
982                        //      set_or_not
983                        //      function
984                        //      init_no_fill
985                        //      varEVAL
986                        // tells you how to handle the string in exploded[1] (called $set_proc[1] below) to get a valid
987                        // default value for a particular preference if one is needed (i.e. if no user custom
988                        // email preference exists that should override that default value, in which case we
989                        // do not even need to obtain such a default value as described in ['init_default'] anyway).
990                       
991                        // --- loop thru $avail_pref_array and process each pref item ---
992                        $c_prefs = count($avail_pref_array);
993                        for($i=0;$i<$c_prefs;++$i)
994                        {
995                                $this_avail_pref = $avail_pref_array[$i];
996                                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');
997                                print_debug('class.preferences: create_email_preferences: std/cust_prefs $this_avail_pref['.$i.'] dump:', $this_avail_pref,'api');
998
999                                // --- is there a value in the DB for this preference item ---
1000                                // if the prefs DB has no value for this defined available preference, we must make one.
1001                                // This occurs if (a) this is user's first login, or (b) this is a custom pref which the user
1002                                // has not overriden, do a default (non-custom) value is needed.
1003                                if (!isset($prefs['email'][$this_avail_pref['id']]))
1004                                {
1005                                        // now we are analizing an individual pref that is available to the user
1006                                        // AND the user had no existing value in the prefs DB for this.
1007
1008                                        // --- get instructions on how to generate a default value ---
1009                                        $set_proc = explode(',', $this_avail_pref['init_default']);
1010                                        print_debug(' * set_proc=['.serialize($set_proc).']', 'messageonly','api');
1011
1012                                        // --- use "instructional token" in $set_proc[0] to take appropriate action ---
1013                                        // STRING
1014                                        if ($set_proc[0] == 'string')
1015                                        {
1016                                                // means this pref item's value type is string
1017                                                // which defined string default value is in $set_proc[1]
1018                                                print_debug('* handle "string" set_proc: ', serialize($set_proc),'api');
1019                                                if (trim($set_proc[1]) == '')
1020                                                {
1021                                                        // this happens when $this_avail_pref['init_default'] = "string, "
1022                                                        $this_string = '';
1023                                                }
1024                                                else
1025                                                {
1026                                                        $this_string = $set_proc[1];
1027                                                }
1028                                                $prefs['email'][$this_avail_pref['id']] = $this_string;
1029                                        }
1030                                        // SET_OR_NOT
1031                                        elseif ($set_proc[0] == 'set_or_not')
1032                                        {
1033                                                // typical with boolean options, True = "set/exists" and False = unset
1034                                                print_debug('* handle "set_or_not" set_proc: ', serialize($set_proc),'api');
1035                                                if ($set_proc[1] == 'not_set')
1036                                                {
1037                                                        // leave it NOT SET
1038                                                }
1039                                                else
1040                                                {
1041                                                        // opposite of boolean not_set  = string "True" which simply sets a
1042                                                        // value it exists in the users session [email][] preference array
1043                                                        $prefs['email'][$this_avail_pref['id']] = 'True';
1044                                                }
1045                                        }
1046                                        // FUNCTION
1047                                        elseif ($set_proc[0] == 'function')
1048                                        {
1049                                                // string in $set_proc[1] should be "eval"uated as code, calling a function
1050                                                // which will give us a default value to put in users session [email][] prefs array
1051                                                print_debug(' * handle "function" set_proc: ', serialize($set_proc),'api');
1052                                                $evaled = '';
1053                                                //eval('$evaled = $this->'.$set_proc[1].'('.$account_id.');');
1054
1055                                                $code = '$evaled = $this->'.$set_proc[1].'('.$account_id.');';
1056                                                print_debug(' * $code: ', $code,'api');
1057                                                eval($code);
1058
1059                                                print_debug('* $evaled:', $evaled,'api');
1060                                                $prefs['email'][$this_avail_pref['id']] = $evaled;
1061                                        }
1062                                        // INIT_NO_FILL
1063                                        elseif ($set_proc[0] == 'init_no_fill')
1064                                        {
1065                                                // we have an available preference item that we may NOT fill with a default
1066                                                // value. Only the user may supply a value for this pref item.
1067                                                print_debug('* handle "init_no_fill" set_proc:', serialize($set_proc),'api');
1068                                                // we are FORBADE from filling this at this time!
1069                                        }
1070                                        // varEVAL
1071                                        elseif ($set_proc[0] == 'varEVAL')
1072                                        {
1073                                                // similar to "function" but used for array references, the string in $set_proc[1]
1074                                                // represents code which typically is an array referencing a system/api property
1075                                                print_debug('* handle "GLOBALS" set_proc:', serialize($set_proc),'api');
1076                                                $evaled = '';
1077                                                $code = '$evaled = '.$set_proc[1];
1078                                                print_debug(' * $code:', $code,'api');
1079                                                eval($code);
1080                                                print_debug('* $evaled:', $evaled,'api');
1081                                                $prefs['email'][$this_avail_pref['id']] = $evaled;
1082                                        }
1083                                        else
1084                                        {
1085                                                // error, no instructions on how to handle this element's default value creation
1086                                                echo 'class.preferences: create_email_preferences: set_proc ERROR: '.serialize($set_proc).'<br>';
1087                                        }
1088                                }
1089                                else
1090                                {
1091                                        // we have a value in the database, do we need to prepare it in any way?
1092                                        // (the following discussion is unconfirmed:)
1093                                        // DO NOT ALTER the data in the prefs array!!!! or the next time we call
1094                                        // save_repository withOUT undoing what we might do here, the
1095                                        // prefs will permenantly LOOSE the very thing(s) we are un-doing
1096                                        /// here until the next OFFICIAL submit email prefs function, where it
1097                                        // will again get this preparation before being written to the database.
1098
1099                                        // NOTE: if database de-fanging is eventually handled deeper in the
1100                                        // preferences class, then the following code would become depreciated
1101                                        // and should be removed in that case.
1102                                        if (($this_avail_pref['type'] == 'user_string') &&
1103                                                (stristr($this_avail_pref['write_props'], 'no_db_defang') == False))
1104                                        {
1105                                                // this value was "de-fanged" before putting it in the database
1106                                                // undo that defanging now
1107                                                $db_unfriendly = $email_base->html_quotes_decode($prefs['email'][$this_avail_pref['id']]);
1108                                                $prefs['email'][$this_avail_pref['id']] = $db_unfriendly;
1109                                        }
1110                                }
1111                        }
1112                        // users preferences are now established to known structured values...
1113
1114                        // SANITY CHECK
1115                        // ---  [email][use_trash_folder]  ---
1116                        // ---  [email][use_sent_folder]  ---
1117                        // is it possible to use Trash and Sent folders - i.e. using IMAP server
1118                        // if not - force settings to false
1119                        if (strpos($prefs['email']['mail_server_type'], 'imap') == False)
1120                        {
1121                                if (isset($prefs['email']['use_trash_folder']))
1122                                {
1123                                        unset($prefs['email']['use_trash_folder']);
1124                                }
1125
1126                                if (isset($prefs['email']['use_sent_folder']))
1127                                {
1128                                        unset($prefs['email']['use_sent_folder']);
1129                                }
1130                        }
1131
1132                        // DEBUG : force some settings to test stuff
1133                        //$prefs['email']['p_persistent'] = 'True';
1134                       
1135                        print_debug('class.preferences: $acctnum: ['.$acctnum.'] ; create_email_preferences: $prefs[email]', $prefs['email'],'api');
1136                        print_debug('class.preferences: create_email_preferences: LEAVING', 'messageonly','api');
1137                        return $prefs;
1138                }
1139
1140                        /*
1141                        // ==== DEPRECATED - ARCHIVAL CODE ====
1142                        // used to be part of function this->create_email_preferences()
1143                        // = = = =  SIMPLER PREFS  = = = =
1144                        // Default Preferences info that is:
1145                        // described in the email prefs array itself
1146
1147                        $default_trash_folder = 'Trash';
1148                        $default_sent_folder = 'Sent';
1149
1150                        // ---  userid  ---
1151                        if (!isset($prefs['email']['userid']))
1152                        {
1153                                $prefs['email']['userid'] = $this->sub_default_userid($accountid);
1154                        }
1155                        // ---  address  ---
1156                        if (!isset($prefs['email']['address']))
1157                        {
1158                                $prefs['email']['address'] = $this->email_address($accountid);
1159                        }
1160                        // ---  mail_server  ---
1161                        if (!isset($prefs['email']['mail_server']))
1162                        {
1163                                $prefs['email']['mail_server'] = $GLOBALS['phpgw_info']['server']['mail_server'];
1164                        }
1165                        // ---  mail_server_type  ---
1166                        if (!isset($prefs['email']['mail_server_type']))
1167                        {
1168                                $prefs['email']['mail_server_type'] = $GLOBALS['phpgw_info']['server']['mail_server_type'];
1169                        }
1170                        // ---  imap_server_type  ---
1171                        if (!isset($prefs['email']['imap_server_type']))
1172                        {
1173                                $prefs['email']['imap_server_type'] = $GLOBALS['phpgw_info']['server']['imap_server_type'];
1174                        }
1175                        // ---  mail_folder  ---
1176                        // because of the way this option works, an empty string IS ACTUALLY a valid value
1177                        // which represents the $HOME/* as the UWash mail files location
1178                        // THERFOR we must check the "Use_custom_setting" option to help us figure out what to do
1179                        if (!isset($prefs['email']['use_custom_settings']))
1180                        {
1181                                // we are NOT using custom settings so this MUST be the server default
1182                                $prefs['email']['mail_folder'] = $GLOBALS['phpgw_info']['server']['mail_folder'];
1183                        }
1184                        else
1185                        {
1186                                // we ARE using custom settings AND a BLANK STRING is a valid option, so...
1187                                if ((isset($prefs['email']['mail_folder']))
1188                                && ($prefs['email']['mail_folder'] != ''))
1189                                {
1190                                        // using custom AND a string exists, so "mail_folder" is that string stored in the custom prefs by the user
1191                                        // DO NOTING - VALID OPTION VALUE for $prefs['email']['mail_folder']
1192                                }
1193                                else
1194                                {
1195                                        // using Custom Prefs BUT this text box was left empty by the user on submit, so no value stored
1196                                        // BUT since we are using custom prefs, "mail_folder" MUST BE AN EMPTY STRING
1197                                        // which is an acceptable, valid preference, overriding any value which
1198                                        // may have been set in ["server"]["mail_folder"]
1199                                        // This is one of the few instances in the preference class where an empty, unspecified value
1200                                        // actually does NOT get deleted from the repository.
1201                                        $prefs['email']['mail_folder'] = '';
1202                                }
1203                        }
1204
1205                        // ---  use_trash_folder  ---
1206                        // ---  trash_folder_name  ---
1207                        // if the option to use the Trash folder is ON, make sure a proper name is specified
1208                        if (isset($prefs['email']['use_trash_folder']))
1209                        {
1210                                if ((!isset($prefs['email']['trash_folder_name']))
1211                                || ($prefs['email']['trash_folder_name'] == ''))
1212                                {
1213                                        $prefs['email']['trash_folder_name'] = $default_trash_folder;
1214                                }
1215                        }
1216
1217                        // ---  use_sent_folder  ---
1218                        // ---  sent_folder_name  ---
1219                        // if the option to use the sent folder is ON, make sure a proper name is specified
1220                        if (isset($prefs['email']['use_sent_folder']))
1221                        {
1222                                if ((!isset($prefs['email']['sent_folder_name']))
1223                                || ($prefs['email']['sent_folder_name'] == ''))
1224                                {
1225                                        $prefs['email']['sent_folder_name'] = $default_sent_folder;
1226                                }
1227                        }
1228
1229                        // ---  layout  ---
1230                        // Layout Template Preference
1231                        // layout 1 = default ; others are prefs
1232                        if (!isset($prefs['email']['layout']))
1233                        {
1234                                $prefs['email']['layout'] = 1;
1235                        }
1236
1237                        //// ---  font_size_offset  ---
1238                        //// Email Index Page Font Size Preference
1239                        //// layout 1 = default ; others are prefs
1240                        //if (!isset($prefs['email']['font_size_offset']))
1241                        //{
1242                        //      $prefs['email']['font_size_offset'] = 'normal';
1243                        //}
1244
1245                        // SANITY CHECK
1246                        // ---  use_trash_folder  ---
1247                        // ---  use_sent_folder  ---
1248                        // is it possible to use Trash and Sent folders - i.e. using IMAP server
1249                        // if not - force settings to false
1250                        if (stristr($prefs['email']['mail_server_type'], 'imap') == False)
1251                        {
1252                                if (isset($prefs['email']['use_trash_folder']))
1253                                {
1254                                        unset($prefs['email']['use_trash_folder']);
1255                                }
1256                               
1257                                if (isset($prefs['email']['use_sent_folder']))
1258                                {
1259                                        unset($prefs['email']['use_sent_folder']);
1260                                }
1261                        }
1262
1263                        // DEBUG : force some settings to test stuff
1264                        //$prefs['email']['layout'] = 1;
1265                        //$prefs['email']['layout'] = 2;
1266                        //$prefs['email']['font_size_offset'] = (-1);
1267
1268                        // DEBUG
1269                        //echo "<br>prefs['email']: <br>"
1270                        //      .'<pre>'.serialize($prefs['email']) .'</pre><br>';
1271                        return $prefs;
1272                        */
1273        } /* end of preferences class */
1274?>
Note: See TracBrowser for help on using the repository browser.