source: sandbox/expresso2.2/phpgwapi/inc/class.preferences.inc.php @ 1914

Revision 1914, 46.2 KB checked in by amuller, 14 years ago (diff)

Ticket #670 - Implementação de pref. obrig. por grupo

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