Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
user_prefs.inc
1 <?php
18 require_once SQ_LIB_PATH.'/config/prefs.inc';
19 require_once SQ_ATTRIBUTES_PATH.'/duration/duration.inc';
20 require_once SQ_ATTRIBUTES_PATH.'/int/int.inc';
21 
22 
23 
35 class User_Prefs extends Prefs
36 {
37  var $pref_vars = Array (
38  'SQ_USER_SESSION_PREFS' => Array(
39  'name' => 'user_prefs_session_settings_header',
40  'description' => 'This preference allows you to change the session settings for this user group',
41  'default' => Array(Array('persist' => '0', 'timeout' => '0', 'max_length' => '0')),
42  'protected' => FALSE,
43  ),
44  'SQ_USER_ASSET_MAP_LINEAGE' => Array(
45  'name' => 'user_prefs_asset_map_root_asset_header',
46  'description' => 'This preference allows you to change the root node that is displated in the Asset Map',
47  'default' => '',
48  'protected' => FALSE,
49  ),
50  'SQ_USER_SAFE_TYPE3_TRASH' => Array(
51  'name' => 'safe_trash',
52  'description' => 'This preference allows you to prohibit the deletion of an asset until all notice links are removed',
53  'default' => FALSE,
54  'protected' => FALSE,
55  ),
56  'SQ_USER_ASSET_MAP_WIDTH' => Array(
57  'name' => 'asset_map_width',
58  'description' => 'Allows changing of asset map frame width',
59  'default' => 275,
60  'protected' => FALSE,
61  ),
62  'SQ_USER_COMMIT_BUTTON_POS' => Array(
63  'name' => 'commit_button_position',
64  'description' => '',
65  'default' => FALSE,
66  'protected' => FALSE,
67  ),
68  'SQ_USER_LIMBO_HIDE_FRAMES' => Array(
69  'name' => 'user_prefs_limbo_hide_frames',
70  'description' => 'This preference determines whether or not the default frames are painted in Simple Edit',
71  'default' => FALSE,
72  'protected' => FALSE,
73  ),
74  'SQ_USER_ATTRIBUTE_IMAGE' => Array(
75  'name' => 'user_prefs_attribute_image',
76  'description' => 'This preference allows you to specify settings for the attribute images',
77  'default' => Array('face' => '3', 'size' => '12', 'hpad' => '0', 'vpad' => '0', 'fgcol' => '000000', 'bgcol' => 'FFFFFF'),
78  'protected' => FALSE,
79  ),
80  'SQ_USER_SET_CONTEXT_ON_LOGIN' => Array(
81  'name' => 'user_prefs_set_context_on_login',
82  'description' => 'Set the selected context when a user in this user group logs in.',
83  'default' => 'default',
84  'protected' => FALSE,
85  ),
86  'SQ_USER_FILTER_FRONT_END_INPUT' => Array(
87  'name' => 'filter_front_end_user_input',
88  'description' => 'Filter (strip keywords, strip script tags and escape html) of any input by the user from the front end.',
89  'default' => FALSE,
90  'protected' => FALSE,
91  ),
92  );
93 
94  var $int_am_frame_width;
95  var $int_am_frame_width_default = 275;
96 
97 
102  function User_Prefs($pref_file='')
103  {
104  $this->Prefs($pref_file);
105 
106  // attribute for input of SQ_COMMENT_MAX_LENGTH
107  $this->int_am_frame_width = new Asset_Attribute_Int();
108  $this->int_am_frame_width->setParam('allow_negative', FALSE);
109  $this->int_am_frame_width->setParam('allow_empty', FALSE);
110  $this->int_am_frame_width->setParam('range_lower', $this->int_am_frame_width_default);
111 
112  }//end constructor
113 
114 
125  function paintBackend(&$o, $have_lock, $pref=NULL)
126  {
127  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
128  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
129 
130  if (is_null($pref) || $pref == 'SQ_USER_SESSION_PREFS') {
131  if (is_null($pref)) {
132  $o->openField(translate($this->pref_vars['SQ_USER_SESSION_PREFS']['name']));
133  }
134  $session_settings = $this->pref_vars['SQ_USER_SESSION_PREFS']['default'];
135  ?>
136  <style type="text/css">
137  ul#user-prefs {
138  list-style-type: none;
139  padding-left: 8px;
140  margin: 2px 0px;
141  }
142  ul#user-prefs li {
143  white-space: nowrap;
144  margin-left: 8px;
145  height: 22px;
146  }
147  div.sq-backend-table-cell {
148  width: auto;
149  margin: 3px;
150  }
151  </style>
152  <?php
153  foreach ($session_settings as $id => $extra_setting) {
154  ?>
155  <div class="sq-backend-table sq-backend-table-cell">
156  <?php echo ($id == '0') ? translate('default').' '.translate('rule') : translate('rule_number', $id); ?><br />
157  <?php echo translate('end_user_session'); ?>...
158  <ul id="user-prefs">
159  <li>
160  <?php
161  if ($have_lock && $is_admin) {
162  check_box('prefs[SQ_USER_SESSION_PREFS]['.$id.'][persist]', '0', ($extra_setting['persist'] == 0), '', 'id="prefs_SQ_USER_SESSION_PREFS_'.$id.'_persist"');
163  label(translate('session_persist'), 'prefs_SQ_USER_SESSION_PREFS_'.$id.'_persist');
164  } else {
165  echo '<img src="'.sq_web_path('lib').'/web/images/'.(empty($extra_setting['persist']) ? 'tick' : 'cross').'.gif" />';
166  echo translate('session_persist');
167  }
168  ?>
169  </li>
170  <li id="timeout<?php echo $id; ?>">
171  <?php
172  $dur = new Asset_Attribute_Duration(0, $extra_setting['timeout']);
173  if ($have_lock && $is_admin) {
174  check_box('prefs[SQ_USER_SESSION_PREFS]['.$id.'][timeout_enabled]', '1', ($extra_setting['timeout'] != 0), 'toggleInputs(this.parentNode)', 'id="prefs_SQ_USER_SESSION_PREFS_'.$id.'_timeout_enabled"');
175  label(translate('session_timeout'), 'prefs_SQ_USER_SESSION_PREFS_'.$id.'_timeout_enabled');
176  echo ' ';
177  } else {
178  echo '<img src="'.sq_web_path('lib').'/web/images/'.(!empty($extra_setting['timeout']) ? 'tick' : 'cross').'.gif" />';
179  echo translate('session_timeout');
180  }
181  $dur->paint('prefs_dur_timeout_'.$id, !$have_lock);
182  ?>
183  </li>
184  <li id="max_length<?php echo $id; ?>">
185  <?php
186  $dur = new Asset_Attribute_Duration(0, $extra_setting['max_length']);
187  if ($have_lock && $is_admin) {
188  check_box('prefs[SQ_USER_SESSION_PREFS]['.$id.'][max_length_enabled]', '1', ($extra_setting['max_length'] != 0), 'toggleInputs(this.parentNode)', 'id="prefs_SQ_USER_SESSION_PREFS_'.$id.'_max_length_enabled"');
189  label(translate('session_max_length'), 'prefs_SQ_USER_SESSION_PREFS_'.$id.'_max_length_enabled');
190  echo ' ';
191  } else {
192  echo '<img src="'.sq_web_path('lib').'/web/images/'.(!empty($extra_setting['max_length']) ? 'tick' : 'cross').'.gif" />';
193  echo translate('session_max_length');
194  }
195  $dur->paint('prefs_dur_max_length_'.$id, !$have_lock); ?>
196  </li>
197  <li>
198  <?php
199  // Do some checks first
200  if (!isset($extra_setting['ip_from'])) {
201  $extra_setting['ip_from'] = '';
202  }//end if
203  if (!isset($extra_setting['ip_to'])) {
204  $extra_setting['ip_to'] = '';
205  }//end if
206 
207  // Paint the interface
208  if ($have_lock && $is_admin) {
209  $js = "onChange=\"Javascript: if (this.checked == false) { document.getElementById('prefs[SQ_USER_SESSION_PREFS][".$id."][ip_from]').value = ''; } \"";
210  check_box('prefs[SQ_USER_SESSION_PREFS]['.$id.'][limit]', '0', (!empty($extra_setting['ip_from'])), '', 'id="prefs_SQ_USER_SESSION_PREFS_'.$id.'_limit" '.$js);
211  label(translate('limit_by_ip_address'), 'prefs_SQ_USER_SESSION_PREFS_'.$id.'_limit');
212  echo ' ';
213  text_box('prefs[SQ_USER_SESSION_PREFS]['.$id.'][ip_from]', $extra_setting['ip_from']);
214  echo ' to ';
215  text_box('prefs[SQ_USER_SESSION_PREFS]['.$id.'][ip_to]', $extra_setting['ip_to']);
216  } else {
217  echo '<img src="'.sq_web_path('lib').'/web/images/'.((!empty($extra_setting['ip_from'])) ? 'tick' : 'cross').'.gif" />';
218  echo translate('limit_by_ip_address');
219  echo ' ';
220  echo $extra_setting['ip_from'];
221  if (!empty($extra_setting['ip_to'])) {
222  echo ' to ';
223  echo $extra_setting['ip_to'];
224  }//end if
225  }//end if
226  ?>
227  </li>
228  <?php
229  // Don't delete the first rule, but allow every other
230  if ($id != '0' && $have_lock && $is_admin) {
231  ?>
232  <li>
233  <?php
234  $js = "onChange=\"Javascript: if (this.checked == true) { if(!confirm(js_translate('confirm_delete_rule'))) { this.checked=false; } } \"";
235  check_box('prefs_delete_rule_number_'.$id, '1', FALSE, 'prefs_sq_user_prefs_delete_'.$id, $js);
236  label(translate('delete_rule'), 'prefs_sq_user_prefs_delete_'.$id);
237  ?>
238  </li>
239  <?php
240  }//end if
241  ?>
242  </ul>
243  </div>
244  <?php
245  }//end foreach
246  echo '*'.translate('session_timeout_explanation');
247  ?>
248  <br />
249  <?php
250 
251  if ($have_lock && $is_admin) {
252  check_box('prefs_make_new_rule', '1', FALSE, 'prefs_sq_user_prefs_new');
253  label(translate('add_session_expiry_rule'), 'prefs_sq_user_prefs_new');
254  }//end if
255 
256  if ($have_lock && $is_admin) {
257  ?>
258  <script type="text/javascript">
259  function toggleInputs(elt) {
260  var inputs = elt.getElementsByTagName('INPUT');
261  for (var i=0; i < inputs.length; i++) {
262  if (inputs[i].type.toLowerCase() == 'text') {
263  inputs[i].disabled = !inputs[i].disabled;
264  }
265  }
266  }
267  <?php
268  // disable fields initially if appropriate
269  foreach (Array('timeout', 'max_length') as $field) {
270  foreach ($session_settings as $id => $session_setting) {
271  if (empty($session_setting[$field])) {
272  ?>
273  toggleInputs(document.getElementById('<?php echo $field.$id; ?>'));
274  <?php
275  }//end if
276  }//end foreach
277  }//end foreach
278  ?>
279  </script>
280  <?php
281  }
282  if (is_null($pref)) $o->closeField();
283  }//end if
284 
285  if (is_null($pref) || $pref == 'SQ_USER_ASSET_MAP_LINEAGE') {
286  if (is_null($pref)) {
287  $o->openField(translate($this->pref_vars['SQ_USER_ASSET_MAP_LINEAGE']['name']));
288  }
289  ?>
290  <div class="sq-backend-table sq-backend-table-cell">
291  <?php
292 
293  if ($have_lock && $is_admin) {
294 
295  if (isset($this->pref_vars['SQ_USER_ASSET_MAP_LINEAGE']['default'])) {
296  $asset_map_settings = $this->pref_vars['SQ_USER_ASSET_MAP_LINEAGE']['default'];
297  } else {
298  $asset_map_settings = '';
299  }
300  asset_finder('prefs[SQ_USER_ASSET_MAP_LINEAGE]', $asset_map_settings);
301  } else {
302  if (!empty($this->pref_vars['SQ_USER_ASSET_MAP_LINEAGE']['default'])) {
303  echo get_asset_tag_line($this->pref_vars['SQ_USER_ASSET_MAP_LINEAGE']['default']);
304  } else {
305  echo translate('root_folder');
306  }
307  }
308  ?>
309  <br /><br />
310  <?php
311  echo translate('user_prefs_asset_map_root_asset_explanation');
312  ?>
313  </div>
314  <?php
315 
316  if (is_null($pref)) $o->closeField();
317  }//end if
318 
319  if (is_null($pref) || $pref == 'SQ_USER_SAFE_TYPE3_TRASH') {
320  if (is_null($pref)) $o->openField(translate($this->pref_vars['SQ_USER_SAFE_TYPE3_TRASH']['name']));
321  ?>
322  <div class="sq-backend-table sq-backend-table-cell">
323  <?php
324  $safe_trash = $this->pref_vars['SQ_USER_SAFE_TYPE3_TRASH']['default'];
325  if ($have_lock && $is_admin) {
326  check_box('prefs[SQ_USER_SAFE_TYPE3_TRASH]', 1, ($safe_trash), '', 'id="prefs_SQ_USER_SAFE_TYPE3_TRASH"');
327  label('Check this box if you want to prohibit the deletion of an asset until all notice links are removed', 'prefs_SQ_USER_SAFE_TYPE3_TRASH');
328  } else {
329  echo '<img src="'.sq_web_path('lib').'/web/images/'.($safe_trash ? 'tick' : 'cross').'.gif" />';
330  echo('Check this box if you want the system to prohibit the deletion of an asset until all notice links are removed');
331  }
332  ?>
333  <br />
334  </div>
335  <?php
336 
337  if (is_null($pref)) $o->closeField();
338  }//end if
339 
340 
341  if (is_null($pref) || $pref == 'SQ_USER_ASSET_MAP_WIDTH') {
342  if (is_null($pref)) $o->openField(translate($this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['name']));
343  ?>
344  <div class="sq-backend-table sq-backend-table-cell">
345  <?php
346 
347  if ($have_lock && $is_admin) {
348 
349  if (isset($this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['default'])) {
350  $asset_map_settings = $this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['default'];
351  } else {
352  $asset_map_settings = '';
353  }
354  $this->int_am_frame_width->value = $asset_map_settings;
355  $this->int_am_frame_width->paint($pref.'_am_frame_width', !$have_lock);
356  } else {
357  if (!empty($this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['default'])) {
358  echo $this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['default'];
359  }
360  }
361  ?>
362  <br /><br />
363  <?php
364  echo $this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['description'];
365  ?>
366  </div>
367  <?php
368 
369  if (is_null($pref)) $o->closeField();
370  }//end if
371 
372  if (is_null($pref) || $pref == 'SQ_USER_COMMIT_BUTTON_POS') {
373  if (is_null($pref)) $o->openField(translate($this->pref_vars['SQ_USER_COMMIT_BUTTON_POS']['name']));
374  ?>
375  <div class="sq-backend-table sq-backend-table-cell">
376  <?php
377  $options = Array(
378  FALSE => 'Bottom of page',
379  TRUE => 'Anchored to bottom of frame',
380  );
381 
382  $position = $this->pref_vars['SQ_USER_COMMIT_BUTTON_POS']['default'];
383  if ($have_lock && $is_admin) {
384  combo_box('prefs[SQ_USER_COMMIT_BUTTON_POS]', $options, FALSE, $position, 0, 'id="prefs_SQ_USER_COMMIT_BUTTON_POS"');
385  ?><br/><?php
386  label('If set to "Anchored to bottom of frame", the Commit button will appear at the bottom of the frame and not scroll with the rest of the page. Note that this setting does not affect Simple Edit mode', 'prefs_SQ_USER_COMMIT_BUTTON_POS');
387  } else {
388  echo $options[$position].'<br/>';
389  echo('If set to "Anchored to bottom of frame", the Commit button will appear at the bottom of the frame and not scroll with the rest of the page. Note that this setting does not affect Simple Edit mode');
390  }
391  ?>
392  <br />
393  </div>
394  <?php
395 
396  if (is_null($pref)) $o->closeField();
397  }//end if
398 
399  if (is_null($pref) || $pref == 'SQ_USER_LIMBO_HIDE_FRAMES') {
400  if (is_null($pref)) $o->openField(translate($this->pref_vars['SQ_USER_LIMBO_HIDE_FRAMES']['name']));
401  ?>
402  <div class="sq-backend-table sq-backend-table-cell">
403  <?php
404  $options = Array(
405  FALSE => 'Do not hide frames',
406  TRUE => 'Hide frames',
407  );
408  $hide_frames = $this->pref_vars['SQ_USER_LIMBO_HIDE_FRAMES']['default'];
409  if ($have_lock && $is_admin) {
410  combo_box('prefs[SQ_USER_LIMBO_HIDE_FRAMES]', $options, FALSE, $hide_frames, 0, 'id="prefs_SQ_USER_LIMBO_HIDE_FRAMES"');
411  ?><br/><?php
412  label('If set to "Do not hide frames", MySource Matrix will paint the default Simple Edit Interface which includes the header bar and Asset Map resizing frame.', 'prefs_SQ_USER_LIMBO_HIDE_FRAMES');
413  } else {
414  echo $options[$hide_frames].'<br/>';
415  echo('If set to "Do not hide frames", MySource Matrix will paint the default Simple Edit Interface which includes the header bar and Asset Map resizing frame');
416  }
417  ?>
418  <br />
419  </div>
420  <?php
421 
422  }//end if
423 
424  if (is_null($pref) || $pref == 'SQ_USER_ATTRIBUTE_IMAGE') {
425  if (is_null($pref)) {
426  $o->openField(translate($this->pref_vars['SQ_USER_ATTRIBUTE_IMAGE']['name']));
427  }
428  $attribute_settings = $this->pref_vars['SQ_USER_ATTRIBUTE_IMAGE']['default'];
429  ?>
430  <table class="sq-backend-table" style="width: 350px;">
431  <tr>
432  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('attribute_image_face'); ?></td>
433  <td class="sq-backend-table-cell" style="width: 100%;">
434  <?php
435  require_once(SQ_FUDGE_PATH.'/general/file_system.inc');
436  $font_files = list_files(SQ_LIB_PATH.'/fonts');
437  $fonts_installed = Array(
438  1 => translate('default_gd_font_1'),
439  2 => translate('default_gd_font_2'),
440  3 => translate('default_gd_font_3'),
441  4 => translate('default_gd_font_4'),
442  5 => translate('default_gd_font_5'),
443  );
444  foreach ($font_files as $font_file) {
445  $result = preg_match('/(.*)\.ttf$/i', $font_file, $matches);
446  if (isset($matches[1]) && !empty($matches[1])) {
447  $fonts_installed[$matches[1]] = ucwords($matches[1]);
448  }//end if
449  }//end foreach
450  if ($have_lock && $is_admin) {
451  combo_box('prefs[SQ_USER_ATTRIBUTE_IMAGE][face]', $fonts_installed, FALSE, $attribute_settings['face'], 1, 'id="prefs_SQ_USER_ATTRIBUTE_IMAGE_face"');
452  } else {
453  if (isset($fonts_installed[$attribute_settings['face']])) {
454  echo $fonts_installed[$attribute_settings['face']];
455  } else {
456  echo translate('no_valid_font');
457  }//end if
458  }//end if
459  ?>
460  </td>
461  </tr>
462  <tr>
463  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('attribute_image_size'); ?></td>
464  <td class="sq-backend-table-cell" style="width: 100%;">
465  <?php
466  $default_fonts = Array( 1,2,3,4,5 );
467  if ($have_lock && $is_admin && !in_array($attribute_settings['face'], $default_fonts)) {
468  text_box('prefs[SQ_USER_ATTRIBUTE_IMAGE][size]', $attribute_settings['size'], 'id="prefs_SQ_USER_ATTRIBUTE_IMAGE_size"');
469  } else {
470  if (in_array($attribute_settings['face'], $default_fonts)) {
471  echo translate('using_default_font');
472  } else {
473  echo $attribute_settings['size'];
474  }//end if
475  }
476  ?>
477  </td>
478  </tr>
479  <tr>
480  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('attribute_image_hpad'); ?></td>
481  <td class="sq-backend-table-cell" style="width: 100%;">
482  <?php
483  if ($have_lock && $is_admin) {
484  text_box('prefs[SQ_USER_ATTRIBUTE_IMAGE][hpad]', $attribute_settings['hpad'], 'id="prefs_SQ_USER_ATTRIBUTE_IMAGE_hpad"');
485  } else {
486  echo $attribute_settings['hpad'];
487  }
488  ?>
489  </td>
490  </tr>
491  <tr>
492  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('attribute_image_vpad'); ?></td>
493  <td class="sq-backend-table-cell" style="width: 100%;">
494  <?php
495  if ($have_lock && $is_admin) {
496  text_box('prefs[SQ_USER_ATTRIBUTE_IMAGE][vpad]', $attribute_settings['vpad'], 'id="prefs_SQ_USER_ATTRIBUTE_IMAGE_vpad"');
497  } else {
498  echo $attribute_settings['vpad'];
499  }
500  ?>
501  </td>
502  </tr>
503  <tr>
504  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('attribute_image_fgcol'); ?></td>
505  <td class="sq-backend-table-cell" style="width: 100%;">
506  <?php
507  require_once(SQ_ATTRIBUTES_PATH.'/colour/colour.inc');
508  $fg = new Asset_Attribute_Colour(0, $attribute_settings['fgcol']);
509  $fg->paint('prefs_image_fgcol_', !($have_lock && $is_admin));
510  ?>
511  </td>
512  </tr>
513  <tr>
514  <td class="sq-backend-table-header" nowrap="nowrap"><?php echo translate('attribute_image_bgcol'); ?></td>
515  <td class="sq-backend-table-cell" style="width: 100%;">
516  <?php
517  require_once(SQ_ATTRIBUTES_PATH.'/colour/colour.inc');
518  $bg = new Asset_Attribute_Colour(0, $attribute_settings['bgcol']);
519  $bg->paint('prefs_image_bgcol_', !($have_lock && $is_admin));
520  ?>
521  </td>
522  </tr>
523  </table>
524  <?php
525  if (is_null($pref)) $o->closeField();
526  }//end if
527 
528 
529  if (is_null($pref) || $pref == 'SQ_USER_SET_CONTEXT_ON_LOGIN') {
530  if (is_null($pref)) $o->openField(translate($this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['name']));
531  $contexts = $GLOBALS['SQ_SYSTEM']->getAllContexts();
532  $options = Array(
533  'default' => 'Do not change context on login',
534  'sep' => '-----------',
535  );
536  foreach ($contexts as $contextid => $context_data) {
537  $options[$contextid] = $context_data['name'];
538  }
539  ?>
540  <div class="sq-backend-table sq-backend-table-cell">
541  <?php
542 
543  if ($have_lock && $is_admin) {
544  if (isset($this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['default'])) {
545  $set_context_on_login = $this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['default'];
546  if (array_key_exists($set_context_on_login, $contexts) === FALSE) {
547  $set_context_on_login = 'default';
548  } else {
549  $set_context_on_login = (int)$set_context_on_login;
550  }
551  } else {
552  $set_context_on_login = 'default';
553  }
554 
555  $default = $set_context_on_login;
556 
557  combo_box('prefs[SQ_USER_SET_CONTEXT_ON_LOGIN]', $options, FALSE, Array($default));
558  } else {
559  if (!empty($this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['default'])) {
560  echo $options[$this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['default']];
561  }
562  }
563  ?>
564  <br /><br />
565  <?php
566  echo $this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['description'];
567  ?>
568  </div>
569  <?php
570 
571  if (is_null($pref)) $o->closeField();
572  }//end if
573 
574  if (is_null($pref) || $pref == 'SQ_USER_FILTER_FRONT_END_INPUT') {
575  if (is_null($pref)) $o->openField(translate($this->pref_vars['SQ_USER_FILTER_FRONT_END_INPUT']['name']));
576  ?>
577  <div class="sq-backend-table sq-backend-table-cell">
578  <?php
579  $options = Array(
580  FALSE => 'Do not filter input',
581  TRUE => 'Filter input',
582  );
583  $filter_input = $this->pref_vars['SQ_USER_FILTER_FRONT_END_INPUT']['default'];
584  if ($have_lock && $is_admin) {
585  combo_box('prefs[SQ_USER_FILTER_FRONT_END_INPUT]', $options, FALSE, $filter_input, 0, 'id="prefs_SQ_USER_FILTER_FRONT_END_INPUT"');
586  ?><br/><?php
587  label("If set to 'Filter Input', Matrix will ".$this->pref_vars['SQ_USER_FILTER_FRONT_END_INPUT']['description'], 'prefs_SQ_USER_FILTER_FRONT_END_INPUT');
588  } else {
589  echo $options[$filter_input].'<br/>';
590  echo("If set to 'Filter Input', Matrix will ".$this->pref_vars['SQ_USER_FILTER_FRONT_END_INPUT']['description']);
591  }
592  ?>
593  <br />
594  </div>
595  <?php
596  if (is_null($pref)) $o->closeField();
597  }//end if
598  return TRUE;
599 
600  }//end paintBackend()
601 
602 
613  function processBackend(&$o, $have_lock, $pref=NULL)
614  {
615  if (!($GLOBALS['SQ_SYSTEM']->userRoot() || $GLOBALS['SQ_SYSTEM']->userSystemAdmin())) {
616  return FALSE;
617  }
618 
619  // Default
620  $make_new = Array(
621  'ip_from' => '',
622  'ip_to' => '',
623  'persist' => 0,
624  'timeout' => 0,
625  'max_length' => 0,
626  );
627  $new_prefs = Array( $make_new );
628  if (is_null($pref) || $pref == 'SQ_USER_SESSION_PREFS') {
629  foreach ($_POST['prefs']['SQ_USER_SESSION_PREFS'] as $id => $submitted_pref) {
630  $new_prefs[$id]['ip_from'] = (isset($submitted_pref['ip_from'])) ? $submitted_pref['ip_from'] : '';
631  $new_prefs[$id]['ip_to'] = (isset($submitted_pref['ip_to'])) ? $submitted_pref['ip_to'] : '';
632  $new_prefs[$id]['persist'] = !isset($submitted_pref['persist']);
633 
634  if (isset($submitted_pref['timeout_enabled'])) {
635  $timeout_dur = new Asset_Attribute_Duration();
636  $timeout_dur->process('prefs_dur_timeout_'.$id);
637  $new_prefs[$id]['timeout'] = $timeout_dur->value;
638  } else {
639  $new_prefs[$id]['timeout'] = '0';
640  }//end if
641  if (isset($submitted_pref['max_length_enabled'])) {
642  $max_length_dur = new Asset_Attribute_Duration();
643  $max_length_dur->process('prefs_dur_max_length_'.$id);
644  $new_prefs[$id]['max_length'] = $max_length_dur->value;
645  } else {
646  $new_prefs[$id]['max_length'] = '0';
647  }//end if
648 
649  if ($id != '0') {
650  if (isset($_POST['prefs_delete_rule_number_'.$id]) && $_POST['prefs_delete_rule_number_'.$id]) {
651  unset($new_prefs[$id]);
652  }//end if
653  }//end if
654  }//end foreach
655 
656  // Was a new rules selected?
657  if (isset($_POST['prefs_make_new_rule']) && $_POST['prefs_make_new_rule']) {
658  $new_prefs[] = $make_new;
659  }//end if
660 
661  $this->pref_vars['SQ_USER_SESSION_PREFS']['default'] = $new_prefs;
662  }//end if
663 
664  if (is_null($pref) || $pref == 'SQ_USER_ASSET_MAP_LINEAGE') {
665  // update lineage pref
666  if (isset($_POST['prefs']['SQ_USER_ASSET_MAP_LINEAGE'])) {
667  $this->pref_vars['SQ_USER_ASSET_MAP_LINEAGE']['default'] = $_POST['prefs']['SQ_USER_ASSET_MAP_LINEAGE']['assetid'];
668  }
669  }
670 
671  // Go through the valid entries and look for the most valid
672  $gc_min = 0;
673  foreach ($new_prefs as $id => $new_pref) {
674  $temp = 0;
675  if (isset($new_pref['ip_from'])) {
676  if (!empty($new_pref['ip_from'])) {
677  continue;
678  }//end if
679  }//end if
680 
681  // No IP Restriction found, continue
682  $temp = max($new_pref['timeout'], $new_pref['max_length']);
683 
684  // Look for the largest general result
685  if (!empty($temp) && $temp > $gc_min) {
686  $gc_min = $temp;
687  }//end if
688  }//end foreach
689 
690  if ($gc_min > SQ_CONF_SESSION_GC_MAXLIFETIME) {
691  // update the main conf
692  include_once(SQ_INCLUDE_PATH.'/system_config.inc');
693  $system_conf = new System_Config();
694  if (!$system_conf->canAcquireLock()) {
695  trigger_localised_error('CORE0233', E_USER_NOTICE);
696  return FALSE;
697  }
698 
699  $system_conf->acquireLock();
700  $system_conf->save(Array('SQ_CONF_SESSION_GC_MAXLIFETIME' => $gc_min + 86400), FALSE, FALSE);
701  $system_conf->releaseLock();
702  }
703 
704  if (is_null($pref) || $pref == 'SQ_USER_SAFE_TYPE3_TRASH') {
705  // safe trash pref
706  if (isset($_POST['prefs']['SQ_USER_SAFE_TYPE3_TRASH'])) {
707  $this->pref_vars['SQ_USER_SAFE_TYPE3_TRASH']['default'] = $_POST['prefs']['SQ_USER_SAFE_TYPE3_TRASH'];
708  } else {
709  $this->pref_vars['SQ_USER_SAFE_TYPE3_TRASH']['default'] = FALSE;
710  }
711  }
712 
713  if (is_null($pref) || $pref == 'SQ_USER_COMMIT_BUTTON_POS') {
714  // commit button position pref
715  if (isset($_POST['prefs']['SQ_USER_COMMIT_BUTTON_POS'])) {
716  $this->pref_vars['SQ_USER_COMMIT_BUTTON_POS']['default'] = $_POST['prefs']['SQ_USER_COMMIT_BUTTON_POS'];
717  } else {
718  $this->pref_vars['SQ_USER_COMMIT_BUTTON_POS']['default'] = FALSE;
719  }
720  }
721 
722 
723  if (is_null($pref) || $pref == 'SQ_USER_ASSET_MAP_WIDTH') {
724  @$this->int_am_frame_width->process($pref.'_am_frame_width');
725  if (!empty($this->int_am_frame_width->value)) {
726  $this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['default'] = $this->int_am_frame_width->value;
727  } else {
728  trigger_localised_error('CORE0270', E_USER_NOTICE);
729  $this->pref_vars['SQ_USER_ASSET_MAP_WIDTH']['default'] = $this->int_am_frame_width_default;
730  }
731  }
732 
733  if (is_null($pref) || $pref == 'SQ_USER_SET_CONTEXT_ON_LOGIN') {
734  // Set user context upon login pref
735  if (isset($_POST['prefs']['SQ_USER_SET_CONTEXT_ON_LOGIN']) && (strpos($_POST['prefs']['SQ_USER_SET_CONTEXT_ON_LOGIN'], 'sep') === FALSE)) {
736  $this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['default'] = $_POST['prefs']['SQ_USER_SET_CONTEXT_ON_LOGIN'];
737  } else {
738  $this->pref_vars['SQ_USER_SET_CONTEXT_ON_LOGIN']['default'] = 'default';
739  }
740  }
741 
742  if (is_null($pref) || $pref == 'SQ_USER_LIMBO_HIDE_FRAMES') {
743  // hide frames in limbo pref
744  if (isset($_POST['prefs']['SQ_USER_LIMBO_HIDE_FRAMES'])) {
745  $this->pref_vars['SQ_USER_LIMBO_HIDE_FRAMES']['default'] = $_POST['prefs']['SQ_USER_LIMBO_HIDE_FRAMES'];
746  } else {
747  $this->pref_vars['SQ_USER_LIMBO_HIDE_FRAMES']['default'] = FALSE;
748  }
749  }
750 
751  if (is_null($pref) || $pref == 'SQ_USER_FILTER_FRONT_END_INPUT') {
752  // filter front end input
753  if (isset($_POST['prefs']['SQ_USER_FILTER_FRONT_END_INPUT'])) {
754  $this->pref_vars['SQ_USER_FILTER_FRONT_END_INPUT']['default'] = $_POST['prefs']['SQ_USER_FILTER_FRONT_END_INPUT'];
755  } else {
756  $this->pref_vars['SQ_USER_FILTER_FRONT_END_INPUT']['default'] = FALSE;
757  }
758  }
759 
760  if (is_null($pref) || $pref == 'SQ_USER_ATTRIBUTE_IMAGE') {
761  $new_prefs = Array(
762  'face' => 'arial',
763  'size' => '12',
764  'hpad' => 0,
765  'vpad' => 0,
766  'fgcol' => '000000',
767  'bgcol' => 'FFFFFF',
768  );
769  if (isset($_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['face'])) {
770  $new_prefs['face'] = $_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['face'];
771  }
772  if (isset($_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['size'])) {
773  $new_prefs['size'] = $_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['size'];
774  }
775  if (isset($_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['hpad'])) {
776  $new_prefs['hpad'] = $_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['hpad'];
777  }
778  if (isset($_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['vpad'])) {
779  $new_prefs['vpad'] = $_POST['prefs']['SQ_USER_ATTRIBUTE_IMAGE']['vpad'];
780  }
781  require_once(SQ_ATTRIBUTES_PATH.'/colour/colour.inc');
782  $fg = new Asset_Attribute_Colour();
783  $fg->process('prefs_image_fgcol_');
784  $new_prefs['fgcol'] = $fg->value;
785  $bg = new Asset_Attribute_Colour();
786  $bg->process('prefs_image_bgcol_');
787  $new_prefs['bgcol'] = $bg->value;
788  $this->pref_vars['SQ_USER_ATTRIBUTE_IMAGE']['default'] = $new_prefs;
789  }//end if
790 
791 
792  return TRUE;
793 
794  }//end processBackend()
795 
796 
811  function mergePrefs($prefs1, $prefs2)
812  {
813  $res = Array();
814  if (isset($prefs1['SQ_USER_SESSION_PREFS']['default']) && isset($prefs2['SQ_USER_SESSION_PREFS']['default'])) {
815  // Follow the princple that the most-open option (the one with the check disabled,
816  // or with the longest timeout) wins.
817  $session_settings_1 = $prefs1['SQ_USER_SESSION_PREFS']['default'];
818  if (is_array($prefs2['SQ_USER_SESSION_PREFS']) && isset($prefs2['SQ_USER_SESSION_PREFS']['default'])) {
819  $session_settings_2 = $prefs2['SQ_USER_SESSION_PREFS']['default'];
820  } else {
821  $session_settings_2 = $prefs2['SQ_USER_SESSION_PREFS'];
822  }
823  $merged['persist'] = max($session_settings_1['persist'], $session_settings_2['persist']);
824  foreach (Array('timeout', 'max_length') as $pref_comp) {
825  if (0 == min($session_settings_1[$pref_comp], $session_settings_2[$pref_comp])) {
826  $merged[$pref_comp] = 0;
827  } else {
828  $merged[$pref_comp] = max($session_settings_1[$pref_comp], $session_settings_2[$pref_comp]);
829  }
830  }
831 
832  $res['SQ_USER_SESSION_PREFS']['default'] = $merged;
833  } else if (isset($prefs1['SQ_USER_ASSET_MAP_LINEAGE']['default']) && isset($prefs2['SQ_USER_ASSET_MAP_LINEAGE'])) {
834 
835  // asset map settings merge get the common
836  $asset_map_settings1 = $prefs1['SQ_USER_ASSET_MAP_LINEAGE']['default'];
837  if (is_array($prefs2['SQ_USER_ASSET_MAP_LINEAGE']) && isset($prefs2['SQ_USER_ASSET_MAP_LINEAGE']['default'])) {
838  $asset_map_settings2 = $prefs2['SQ_USER_ASSET_MAP_LINEAGE']['default'];
839  } else {
840  $asset_map_settings2 = $prefs2['SQ_USER_ASSET_MAP_LINEAGE'];
841  }
842 
843  if (empty($asset_map_settings1) && !empty($asset_map_settings2)) {
844  $asset_map_settings1 = $asset_map_settings2;
845  $asset_map_settings2 = '';
846  }
847 
848  $res['SQ_USER_ASSET_MAP_LINEAGE']['default'] = $asset_map_settings1;
849 
850  if (!empty($asset_map_settings2)) {
851  $res['SQ_USER_ASSET_MAP_LINEAGE']['default'] .= ','.$asset_map_settings2;
852  }
853 
854  }
855 
856  if (isset($prefs1['SQ_USER_SAFE_TYPE3_TRASH']['default']) && isset($prefs2['SQ_USER_SAFE_TYPE3_TRASH'])) {
857 
858  // for safe trash option, if user belongs to multiple user groupS, option Yes > No
859  // note that param 2 is value only
860  $safe_trash1 = $prefs1['SQ_USER_SAFE_TYPE3_TRASH']['default'];
861  $safe_trash2 = $prefs2['SQ_USER_SAFE_TYPE3_TRASH']['default'];
862  $res['SQ_USER_SAFE_TYPE3_TRASH']['default'] = ($safe_trash1 || $safe_trash2) ? TRUE : FALSE;
863 
864  }
865 
866  return $res;
867 
868  }//end mergePrefs()
869 
870 
871 }//end class
872 
873 ?>