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