source: trunk/preferences/preferences.php @ 1002

Revision 1002, 17.7 KB checked in by amuller, 15 years ago (diff)

Ticket #485 - Correção de assinatura com texto rico

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]1<?php
2        /**************************************************************************\
3        * phpGroupWare - Preferences                                               *
4        * http://www.phpgroupware.org                                              *
5        * --------------------------------------------                             *
6        *  This program is free software; you can redistribute it and/or modify it *
7        *  under the terms of the GNU General Public License as published by the   *
8        *  Free Software Foundation; either version 2 of the License, or (at your  *
9        *  option) any later version.                                              *
10        \**************************************************************************/
11
12
13        $GLOBALS['phpgw_info']['flags'] = array(
14                'noheader'                => True,
15                'noappheader'             => True,
16                'nonavbar'                => True,
17                'currentapp'              => @$_GET['appname'] ? $_GET['appname'] : 'preferences',
18                'enable_nextmatchs_class' => True
19        );
20        include('../header.inc.php');
21       
22        if ($_POST['cancel'])
23        {
24                $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
25        }
26       
27        $user    = get_var('user',Array('POST'));
28        $forced  = get_var('forced',Array('POST'));
29        $default = get_var('default',Array('POST'));
30
31        $t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('preferences'));
32        $t->set_file(array(
33                'preferences' => 'preferences.tpl'
34        ));
35        $t->set_block('preferences','list','lists');
36        $t->set_block('preferences','row','rowhandle');
37        $t->set_block('preferences','help_row','help_rowhandle');
38        $t->set_var(array('rowhandle' => '','help_rowhandle' => '','messages' => ''));
39       
40        if ($_GET['appname'] != 'preferences')
41        {
42                $GLOBALS['phpgw']->translation->add_app('preferences'); // we need the prefs translations too
43        }
44
45        /* Make things a little easier to follow */
46        /* Some places we will need to change this if there in common */
47        function check_app()
48        {
49                if ($_GET['appname'] == 'preferences')
50                {
51                        return 'common';
52                }
53                else
54                {
[879]55                        return ($_GET['appname'] == 'expressoMail1_2'?'expressoMail':$_GET['appname']);             
[2]56                }
57        }
58
59        function is_forced_value($_appname,$preference_name)
60        {
61                if (isset($GLOBALS['phpgw']->preferences->forced[$_appname][$preference_name]) && $GLOBALS['type'] != 'forced')
62                {
63                        return True;
64                }
65                else
66                {
67                        return False;
68                }
69        }
70
71        function create_password_box($label_name,$preference_name,$help='',$size = '',$max_size = '',$run_lang=True)
72        {
73                global $user,$forced,$default;
74               
75                $_appname = check_app();
76                if (is_forced_value($_appname,$preference_name))
77                {
78                        return True;
79                }
80                create_input_box($label_name,$preference_name.'][pw',$help,'',$size,$max_size,'password',$run_lang);
81        }
82       
83        function create_input_box($label,$name,$help='',$default='',$size = '',$max_size = '',$type='',
84                $run_lang=True)
85        {
86                global $t,$prefs;
87
88                $charSet = $GLOBALS['phpgw']->translation->charset();
89
90                $_appname = check_app();
91                if (is_forced_value($_appname,$name))
92                {
93                        return True;
94                }
95
96                if ($type)      // used to specify password
97                {
98                        $options = " TYPE='$type'";
99                }
100                if ($size)
101                {
102                        $options .= " SIZE='$size'";
103                }
104                if ($maxsize)
105                {
106                        $options .= " MAXSIZE='$maxsize'";
107                }
108
109                if (isset($prefs[$name]) || $GLOBALS['type'] != 'user')
110                {
111                        $default = $prefs[$name];
112                }
113               
114                if ($GLOBALS['type'] == 'user')
115                {
116                        $def_text = !$GLOBALS['phpgw']->preferences->user[$_appname][$name] ? $GLOBALS['phpgw']->preferences->data[$_appname][$name] : $GLOBALS['phpgw']->preferences->default[$_appname][$name];
117
118                        if (isset($notifys[$name]))     // translate the substitution names
119                        {
120                                $def_text = $GLOBALS['phpgw']->preferences->lang_notify($def_text,$notifys[$name]);
121                        }
122                        $def_text = $def_text != '' ? ' <i><font size="-1">'.lang('default').':&nbsp;'.$def_text.'</font></i>' : '';
123                }
124                $t->set_var('row_value',"<input name=\"${GLOBALS[type]}[$name]\"value=\"".
125                        @htmlentities($default,ENT_COMPAT,$charSet)."\"$options>$def_text");
126                $t->set_var('row_name',lang($label));
127                $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color($t);
128
129                $t->fp('rows',process_help($help,$run_lang) ? 'help_row' : 'row',True);
130        }
131       
132        function process_help($help,$run_lang=True)
133        {
134                global $t,$show_help,$has_help;
135
136                if (!empty($help))
137                {
138                        $has_help = True;
139                       
140                        if ($show_help)
141                        {
142                                $t->set_var('help_value',$run_lang ? lang($help) : $help);
143                               
144                                return True;
145                        }
146                }
147                return False;
148        }
149
150        function create_check_box($label,$name,$help='',$default='',$run_lang=True)
151        {
152                // checkboxes itself can't be use as they return nothing if uncheckt !!!
153                global $prefs;
154               
155                if ($GLOBALS['type'] != 'user')
156                {
157                        $default = '';  // no defaults for default or forced prefs
158                }
159                if (isset($prefs[$name]))
160                {
161                        $prefs[$name] = (int)(!!$prefs[$name]); // to care for '' and 'True'
162                }
163               
164                return create_select_box($label,$name,array(
165                        '0' => lang('No'),
166                        '1' => lang('Yes')
167                ),$help,$default,$run_lang);
168        }
169
170        function create_option_string($selected,$values)
171        {
172                while (is_array($values) && list($var,$value) = each($values))
173                {
174                        $s .= '<option value="' . $var . '"';
175                        if ("$var" == "$selected")      // the "'s are necessary to force a string-compare
176                        {
177                                $s .= ' selected';
178                        }
179                        $s .= '>' . $value . '</option>';
180                }
181                return $s;
182        }
183
184        /* for creating different sections with a title */
[43]185        function create_section($title='',$value = '')
[2]186        {
187                global $t;
188
189                        $t->set_var('row_value','');
[43]190                        $t->set_var('row_name','<span class="prefSection">'.lang($title,$value).'</span>');
[2]191                        $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color($t);
192
193                        $t->fp('rows',process_help($help) ? 'help_row' : 'row',True);
[873]194        }
[1002]195        function create_html_code($name,$code,$appendcode)
[873]196        {
[1002]197                global $t,$prefs;
198                $t->set_var('row_value',$code.$prefs[$name].$appendcode);
[873]199                $t->set_var('row_name',lang("signature"));
200                $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color($t);
201                $t->fp('rows','row',True);
202        }
[2]203
[873]204        function create_select_box($label,$name,$values,$help='',$default='',$run_lang=True,$select_prop = '')
[2]205        {
206                global $t,$prefs;
207
208                $_appname = check_app();
209                if (is_forced_value($_appname,$name))
210                {
211                        return True;
212                }
213               
214                if (isset($prefs[$name]) || $GLOBALS['type'] != 'user')
215                {
216                        $default = $prefs[$name];
217                }
218
219                switch ($GLOBALS['type'])
220                {
221                        case 'user':
222                                $s = '<option value="">' . lang('Use default') . '</option>';
223                                break;
224                        case 'default':
225                                $s = '<option value="">' . lang('No default') . '</option>';
226                                break;
227                        case 'forced':
228                                $s = '<option value="**NULL**">' . lang('Users choice') . '</option>';
229                                break;
230                }
231                $s .= create_option_string($default,$values);
232                if ($GLOBALS['type'] == 'user')
233                {
234                        $def_text = $GLOBALS['phpgw']->preferences->default[$_appname][$name];
235                        $def_text = $def_text != '' ? ' <i><font size="-1">'.lang('default').':&nbsp;'.$values[$def_text].'</font></i>' : '';
236                }
[873]237                $t->set_var('row_value',"<select name=\"${GLOBALS[type]}[$name]\" $select_prop>$s</select>$def_text");
[2]238                $t->set_var('row_name',lang($label));
239                $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color($t);
240
241                $t->fp('rows',process_help($help,$run_lang) ? 'help_row' : 'row',True);
242        }
243       
244        /*!
245        @function create_notify
246        @abstract creates text-area or inputfield with subtitution-variables
247        @syntax create_notify($label,$name,$rows,$cols,$help='',$default='',$vars2='')
248        @param $label untranslated label
249        @param $name name of the pref
250        @param $rows, $cols of the textarea or input-box ($rows==1)
251        @param $help untranslated help-text
252        @param $default default-value
253        @param $vars2 array with extra substitution-variables of the form key => help-text
254        */
255        function create_notify($label,$name,$rows,$cols,$help='',$default='',$vars2='',$subst_help=True,$run_lang=True)
256        {
257                global $t,$prefs,$notifys;
258
259                $vars = $GLOBALS['phpgw']->preferences->vars;
260                if (is_array($vars2))
261                {
262                        $vars += $vars2;
263                }
264                $prefs[$name] = $GLOBALS['phpgw']->preferences->lang_notify($prefs[$name],$vars);
265
266                $notifys[$name] = $vars;        // this gets saved in the app_session for re-translation
267
268                $help = $help && $run_lang ? lang($help) : $help;
269                if ($subst_help)
270                {
271                        $help .= '<p><b>'.lang('Substitutions and their meanings:').'</b>';
272                        foreach($vars as $var => $var_help)
273                        {
274                                $lname = ($lname = lang($var)) == $var.'*' ? $var : $lname;
275                                $help .= "<br>\n".'<b>$$'.$lname.'$$</b>: '.$var_help;
276                        }
277                        $help .= "</p>\n";
278                }
279                if ($row == 1)
280                {
281                        create_input_box($label,$name,$help,$default,$cols,'','',False);
282                }
283                else
284                {
285                        create_text_area($label,$name,$rows,$cols,$help,$default,False);
286                }
287        }
288
289        function create_text_area($label,$name,$rows,$cols,$help='',$default='',$run_lang=True)
290        {
291                global $t,$prefs,$notifys;
292               
293                $charSet = $GLOBALS['phpgw']->translation->charset();
294
295                $_appname = check_app();
296                if (is_forced_value($_appname,$name))
297                {
298                        return True;
299                }
300               
301                if (isset($prefs[$name]) || $GLOBALS['type'] != 'user')
302                {
303                        $default = $prefs[$name];
304                }
305
306                if ($GLOBALS['type'] == 'user')
307                {
308                        $def_text = !$GLOBALS['phpgw']->preferences->user[$_appname][$name] ? $GLOBALS['phpgw']->preferences->data[$_appname][$name] : $GLOBALS['phpgw']->preferences->default[$_appname][$name];
309
310                        if (isset($notifys[$name]))     // translate the substitution names
311                        {
312                                $def_text = $GLOBALS['phpgw']->preferences->lang_notify($def_text,$notifys[$name]);
313                        }
314                        $def_text = $def_text != '' ? '<br><i><font size="-1"><b>'.lang('default').'</b>:<br>'.nl2br($def_text).'</font></i>' : '';
315                }
316                $t->set_var('row_value',"<textarea rows=\"$rows\" cols=\"$cols\" name=\"${GLOBALS[type]}[$name]\">".
317                        htmlentities($default,ENT_COMPAT,$charSet)."</textarea>$def_text");
318                $t->set_var('row_name',lang($label));
319                $GLOBALS['phpgw']->nextmatchs->template_alternate_row_color($t);
320
321                $t->fp('rows',process_help($help,$run_lang) ? 'help_row' : 'row',True);
322        }
323
324        function process_array(&$repository,$array,$notifys,$prefix='')
325        {
326                $_appname = check_app();
327
328                $prefs = &$repository[$_appname];
329
330                if ($prefix != '')
331                {
332                        $prefix_arr = explode('/',$prefix);
333                        foreach ($prefix_arr as $pre)
334                        {
335                                $prefs = &$prefs[$pre];
336                        }
337                }
338                unset($prefs['']);
339                //echo "array:<pre>"; print_r($array); echo "</pre>\n";
340                while (is_array($array) && list($var,$value) = each($array))
341                {
342                        if (isset($value) && $value != '' && $value != '**NULL**')
343                        {
344                                if (is_array($value))
345                                {
346                                        $value = $value['pw'];
347                                        if (empty($value))
348                                        {
349                                                continue;       // dont write empty password-fields
350                                        }
351                                }
352                                $prefs[$var] = stripslashes($value);
353
354                                if ($notifys[$var])     // need to translate the key-words back
355                                {
356                                        $prefs[$var] = $GLOBALS['phpgw']->preferences->lang_notify($prefs[$var],$notifys[$var],True);
357                                }
358                        }
359                        else
360                        {
361                                unset($prefs[$var]);
362                        }
363                }
364                //echo "prefix='$prefix', prefs=<pre>"; print_r($repository[$_appname]); echo "</pre>\n";
365
366                // the following hook can be used to verify the prefs
367                // if you return something else than False, it is treated as an error-msg and
368                // displayed to the user (the prefs get not saved !!!)
369                //
370                if ($error = $GLOBALS['phpgw']->hooks->single(array(
371                        'location' => 'verify_settings',
372                        'prefs'    => $repository[$_appname],
373                        'prefix'   => $prefix,
374                        'type'     => $GLOBALS['type']
375                ),$_GET['appname']))
376                {
377                        return $error;
378                }
379               
380                $GLOBALS['phpgw']->preferences->save_repository(True,$GLOBALS['type']);
381               
382                return False;
383        }
384
385        /* Only check this once */
386        if ($GLOBALS['phpgw']->acl->check('run',1,'admin'))
387        {
388                /* Don't use a global variable for this ... */
389                define('HAS_ADMIN_RIGHTS',1);
390        }
391
392        /* Makes the ifs a little nicer, plus ... this will change once the ACL manager is in place */
393        /* and is able to create less powerfull admins.  This will handle the ACL checks for that (jengo) */
394        function is_admin()
395        {
396                global $prefix;
397
398                if (HAS_ADMIN_RIGHTS == 1 && empty($prefix))    // tabs only without prefix
399                {
400                        return True;
401                }
402                else
403                {
404                        return False;
405                }
406        }
407       
408        function show_list($header = '&nbsp;')
409        {
410                global $t,$list_shown;
411
412                $t->set_var('list_header',$header);
413                $t->parse('lists','list',$list_shown);
414
415                $t->set_var('rows','');
416                $list_shown = True;
417        }
418
419        $session_data = $GLOBALS['phpgw']->session->appsession('session_data','preferences');
420
421        $prefix = get_var('prefix',array('GET'),$session_data['appname'] == $_GET['appname'] ? $session_data['prefix'] : '');
422       
423        if (is_admin())
424        {
425                /* This is where we will keep track of our postion. */
426                /* Developers won't have to pass around a variable then */
427
428                $GLOBALS['type'] = get_var('type',Array('GET','POST'),$session_data['type']);
429
430                if (empty($GLOBALS['type']))
431                {
432                        $GLOBALS['type'] = 'user';
433                }
434        }
435        else
436        {
437                $GLOBALS['type'] = 'user';
438        }
439        $show_help = "$session_data[show_help]" != '' && $session_data['appname'] == $_GET['appname'] ?
440                $session_data['show_help'] : (int)$GLOBALS['phpgw_info']['user']['preferences']['common']['show_help'];
441
442        if ($toggle_help = get_var('toggle_help','POST'))
443        {
444                $show_help = (int)(!$show_help);
445        }
446        $has_help = 0;
447
448        if ($_POST['submit'])
449        {
450                /* Don't use a switch here, we need to check some permissions durring the ifs */
451                if ($GLOBALS['type'] == 'user' || !($GLOBALS['type']))
452                {
453                        $error = process_array($GLOBALS['phpgw']->preferences->user,$user,$session_data['notifys'],$prefix);
454                }
455
456                if ($GLOBALS['type'] == 'default' && is_admin())
457                {
458                        $error = process_array($GLOBALS['phpgw']->preferences->default, $default,$session_data['notifys']);
459                }
460
461                if ($GLOBALS['type'] == 'forced' && is_admin())
462                {
463                        $error = process_array($GLOBALS['phpgw']->preferences->forced, $forced,$session_data['notifys']);
464                }
465
466                if (!is_admin() || $error)
467                {
468                        $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
469                }
470               
471                if ($GLOBALS['type'] == 'user' && $_GET['appname'] == 'preferences' && $user['show_help'] != '')
472                {
473                        $show_help = $user['show_help'];        // use it, if admin changes his help-prefs
474                }
475        }
476        $GLOBALS['phpgw']->session->appsession('session_data','preferences',array(
477                'type'      => $GLOBALS['type'],        // save our state in the app-session
478                'show_help' => $show_help,
479                'prefix'    => $prefix,
480                'appname'   => $_GET['appname']         // we use this to reset prefix on appname-change
481        ));
482        // changes for the admin itself, should have immediate feedback ==> redirect
483        if (!$error && $_POST['submit'] && $GLOBALS['type'] == 'user' && $_GET['appname'] == 'preferences') {
484                $GLOBALS['phpgw']->redirect_link('/preferences/preferences.php','appname='.$_GET['appname']);
485        }
486
487        $GLOBALS['phpgw_info']['flags']['app_header'] = $_GET['appname'] == 'preferences' ?
488                lang('Preferences') : lang('%1 - Preferences',$GLOBALS['phpgw_info']['apps'][$_GET['appname']]['title']);
489        $GLOBALS['phpgw']->common->phpgw_header();
490        echo parse_navbar();
491
492        $t->set_var('messages',$error);
493        $t->set_var('action_url',$GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $_GET['appname']));
494        $t->set_var('th_bg',  $GLOBALS['phpgw_info']['theme']['th_bg']);
495        $t->set_var('th_text',$GLOBALS['phpgw_info']['theme']['th_text']);
496        $t->set_var('row_on', $GLOBALS['phpgw_info']['theme']['row_on']);
497        $t->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
498
499        switch ($GLOBALS['type'])       // set up some globals to be used by the hooks
500        {
501                case 'forced': 
502                        $prefs = &$GLOBALS['phpgw']->preferences->forced[check_app()];
503                        break;
504                case 'default':
505                        $prefs = &$GLOBALS['phpgw']->preferences->default[check_app()];
506                        break;
507                default:
508                        $prefs = &$GLOBALS['phpgw']->preferences->user[check_app()];
509                        // use prefix if given in the url, used for email extra-accounts
510                        if ($prefix != '')
511                        {
512                                $prefix_arr = explode('/',$prefix);
513                                foreach ($prefix_arr as $pre)
514                                {
515                                        $prefs = &$prefs[$pre];
516                                }
517                        }
518        }
519        //echo "prefs=<pre>"; print_r($prefs); echo "</pre>\n";
520       
521        $notifys = array();
522        if (!$GLOBALS['phpgw']->hooks->single('settings',$_GET['appname']))
523        {
524                $t->set_block('preferences','form','formhandle');       // skip the form
525                $t->set_var('formhandle','');
526               
527                $t->set_var('messages',lang('Error: There was a problem finding the preference file for %1 in %2',
528                        $GLOBALS['phpgw_info']['navbar'][$_GET['appname']]['title'],PHPGW_SERVER_ROOT . SEP
529                        . $_GET['appname'] . SEP . 'inc' . SEP . 'hook_settings.inc.php'));
530        }
531        $tmpl_settings = PHPGW_TEMPLATE_DIR.'/hook_settings.inc.php';
532        if ($_GET['appname'] == 'preferences' && file_exists($tmpl_settings))
533        {
534                include($tmpl_settings);
535        }
536
537        if (count($notifys))    // there have been notifys in the hook, we need to save in the session
538        {
539                $GLOBALS['phpgw']->session->appsession('session_data','preferences',array(
540                        'type'      => $GLOBALS['type'],        // save our state in the app-session
541                        'show_help' => $show_help,
542                        'prefix'    => $prefix,
543                        'appname'   => $_GET['appname'],        // we use this to reset prefix on appname-change
544                        'notifys'   => $notifys
545                ));
546                //echo "notifys:<pre>"; print_r($notifys); echo "</pre>\n";
547        }
548        if (is_admin())
549        {
550                $tabs[] = array(
551                        'label' => lang('Your preferences'),
552                        'link'  => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $_GET['appname'] . "&type=user")
553                );
554                $tabs[] = array(
555                        'label' => lang('Default preferences'),
556                        'link'  => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $_GET['appname'] . "&type=default")
557                );
558                $tabs[] = array(
559                        'label' => lang('Forced preferences'),
560                        'link'  => $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=' . $_GET['appname'] . "&type=forced")
561                );
562
563                switch($GLOBALS['type'])
564                {
565                        case 'user':    $selected = 0; break;
566                        case 'default': $selected = 1; break;
567                        case 'forced':  $selected = 2; break;
568                }
569                $t->set_var('tabs',$GLOBALS['phpgw']->common->create_tabs($tabs,$selected));
570        }
571        $t->set_var('lang_submit', lang('save'));
572        $t->set_var('lang_cancel', lang('cancel'));
573        $t->set_var('show_help',(int)$show_help);
574        $t->set_var('help_button',$has_help ? '<input type="submit" name="toggle_help" value="'.
575                ($show_help ? lang('help off') : lang('help')).'">' : '');
576
577        if (!$list_shown)
578        {
579                show_list();
580        }
581        $t->pfp('phpgw_body','preferences');
582       
583        //echo '<pre style="text-align: left;">'; print_r($GLOBALS['phpgw']->preferences->data); echo "</pre>\n";
584       
585        $GLOBALS['phpgw']->common->phpgw_footer();
586?>
Note: See TracBrowser for help on using the repository browser.