Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_config_edit_interface.inc
1 <?php
30 {
31 
32 
38  {
39 
40  }//end constructor
41 
42 
50  function paint(&$backend)
51  {
52  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
53  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
54 
55  // if we dont have access, go away
56  if (!$is_admin) {
57  $GLOBALS['SQ_SYSTEM']->paintLogin(translate('login'), translate('cannot_access_asset', $owner->name));
58  exit();
59  }
60 
61  $o = $backend->out;
62 
63  $o->setHeading(translate('system_configuration'), sq_get_icon($o->filesPath('/images/icons/header/system_config.png'), 20, 20, 'System Configuration'));
64  $o->setPageTitle(translate('system_configuration'));
65  $o->addHiddenField('config_posted', '1');
66 
67 
69  // ACTIVE SCREEN //
71  if (empty($_REQUEST['config_screen'])) {
72  $active_screen = 'system_config';
73  $_REQUEST['config_screen'] = $active_screen;
74  } else {
75  $active_screen = $_REQUEST['config_screen'];
76  }
77 
78  // make sure that we have the screen for next time
79  $o->addFormActionGetVar('config_screen', $active_screen);
80 
81 
83  // SCREEN MENU //
85  $o->addFormActionGetVar('config_screen', $active_screen, TRUE);
86  $current_location = $o->getCurrentLocation();
87  list($current_loc_base, $current_loc_query) = explode('?', $current_location);
88  $config_screens = Array(
89  'system_config' => translate('system_configuration'),
90  'squiz_server_config' => translate('squiz_server_configuration'),
91  'apache_config' => translate('apache_configuration'),
92  'hipo_config' => translate('hipo_configuration'),
93  'external_tools_config' => translate('external_tools_configuration'),
94  'user_prefs' => translate('global_preferences'),
95  'password_rules_config' => translate('password_rules_configuration'),
96  'messaging_service_config' => translate('messaging_service_configuration'),
97  'proxy_authentication_config' => translate('proxy_configuration'),
98  'context_config' => translate('context_configuration'),
99  'locks' => translate('active_locks'),
100  );
101 
102  foreach ($config_screens as $screen_code => $screen_name) {
103  $url = replace_query_string_vars(Array('config_screen' => rawurlencode($screen_code)), $current_loc_base, $current_loc_query);
104  $o->addStaticScreen($url, $screen_name);
105  }
106 
107 
108  switch ($active_screen) {
109  case 'system_config' :
110  case 'squiz_server_config' :
111  case 'apache_config' :
112  case 'hipo_config' :
113  case 'external_tools_config' :
114  case 'password_rules_config' :
115  case 'session_rules_config' :
116  case 'messaging_service_config' :
117  case 'proxy_authentication_config' :
118  case 'context_config':
119 
120  $config = null;
121 
122  switch ($active_screen) {
123  case 'system_config' :
124  require_once SQ_INCLUDE_PATH.'/system_config.inc';
125  $config = new System_Config();
126  break;
127  case 'squiz_server_config' :
128  require_once SQ_SYSTEM_ROOT.'/core/server/squiz_server_config.inc';
129  $config = new Squiz_Server_Config();
130  break;
131  case 'apache_config' :
132  require_once SQ_INCLUDE_PATH.'/apache_config.inc';
133  $config = new Apache_Config();
134  break;
135  case 'hipo_config' :
136  require_once SQ_SYSTEM_ROOT.'/core/hipo/hipo_config.inc';
137  $config = new HIPO_Config();
138  break;
139  case 'external_tools_config' :
140  require_once SQ_INCLUDE_PATH.'/external_tools_config.inc';
141  $config = new External_Tools_Config();
142  break;
143  case 'password_rules_config' :
144  require_once SQ_INCLUDE_PATH.'/password_rules_config.inc';
145  $config = new Password_Rules_Config();
146  break;
147  case 'session_rules_config' :
148  require_once SQ_INCLUDE_PATH.'/session_rules_config.inc';
149  $config = new Session_Rules_Config();
150  break;
151  case 'messaging_service_config' :
152  require_once SQ_INCLUDE_PATH.'/messaging_service_config.inc';
153  $config = new Messaging_Service_Config();
154  break;
155  case 'proxy_authentication_config' :
156  require_once SQ_INCLUDE_PATH.'/proxy_authentication_config.inc';
157  $config = new Proxy_Authentication_Config();
158  break;
159  case 'context_config' :
160  require_once SQ_INCLUDE_PATH.'/context_config.inc';
161  $config = new Context_Config();
162  break;
163 
164  }// end switch
165  if (!empty($_POST['config_posted'])) {
166  $config->processBackend($o);
167  }
168 
169  $config->paintBackend($o);
170 
171  return;
172 
173  break;
174 
175  case 'user_prefs' :
176 
177  if (!empty($_POST['config_posted'])) {
178  $this->processUserPrefs($o);
179  }
180 
181  $this->paintUserPrefs($o);
182 
183  return;
184 
185  case 'locks' :
186  $this->paintActiveLocks($o);
187  return;
188  default :
189  trigger_localised_error('SYS0076', E_USER_WARNING, $active_screen);
190  }// end switch
191 
192  }//end paint()
193 
194 
203  function paintUserPrefs(&$o)
204  {
205  $lock_code = get_class($this).'_user_prefs';
206  $lock = $GLOBALS['SQ_SYSTEM']->getLockInfo($lock_code);
207  $have_lock = (!empty($lock) && $GLOBALS['SQ_SYSTEM']->currentUserId() == $lock['userid']);
208 
209  $is_admin = ($GLOBALS['SQ_SYSTEM']->userRoot() || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
210 
211  $o->openSection(translate('locking_/_editing'));
212  $o->openRaw();
213  ?>
214  <table border="0" cellspacing="3" cellpadding="1">
215  <tr>
216  <td>
217  <?php sq_print_icon(sq_web_path('lib').'/web/images/icons/'.((empty($lock)) ? 'un' : '').'locked.png', 16, 16); ?>
218  </td>
219  <td>
220  <p class="sq-lock-message">
221  <?php
222  if (!empty($lock)) {
223  // this asset is currently locked
224  // so display message to the user
225  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['userid']);
226 
227  $now = time();
228 
229  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
230  $expires_in = easy_time_total(($lock['expires'] - $now), true);
231  if (!$expires_in) $expires_in = '1 second';
232  $expires_in = translate('due_to_expire', $expires_in);
233  if ($have_lock) {
234  echo translate('release_lock', translate('release_lock_button'), translate('user_preferences'));
235  echo '<br />';
236  }
237  echo $expires_in;
238 
239  } else {
240  echo translate('acquire_lock', translate('acquire_lock_button'), translate('user_preferences'));
241  }
242  echo '</p>';
243  if (!empty($lock)) {
244  if ($have_lock) {
245  submit_button('sq_lock_release_manual', translate('release_lock_button'), 'set_hidden_field("process_form", "0");', 'accesskey="r"');
246  }
247  } else {
248  submit_button('sq_lock_acquire', translate('acquire_lock_button'), 'set_hidden_field("process_form", "0");', 'accesskey="a"');
249  }
250  ?>
251  </td>
252  </tr>
253  </table>
254  <?php
255  $o->closeRaw();
256  $o->closeSection();
257 
258  include SQ_DATA_PATH.'/private/conf/preferences.inc';
259 
260  foreach ($preferences as $type_code => $pref_vars) {
261  $o->openSection($GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code, 'name').' '.translate('preferences'));
262 
263  // We need to include the asset the prefs are for to make sure all locales are imported for it
264  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
265 
266  $path = SQ_SYSTEM_ROOT.'/'.$GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code, 'dir').'/'.$type_code.'_prefs.inc';
267  require_once $path;
268  $pref_name = $type_code.'_Prefs';
269  $prefs = new $pref_name();
270  $prefs->paintBackend($o, $have_lock);
271  $o->closeSection();
272  }
273 
274  if ($have_lock) $o->commitButton('', true);
275 
276  }//end paintUserPrefs()
277 
278 
287  function processUserPrefs(&$o)
288  {
289  $is_admin = ($GLOBALS['SQ_SYSTEM']->userRoot() || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
290 
291  $lock_code = get_class($this).'_user_prefs';
292  $lock = $GLOBALS['SQ_SYSTEM']->getLockInfo($lock_code);
293  $have_lock = (!empty($lock) && $GLOBALS['SQ_SYSTEM']->currentUserId() == $lock['userid']);
294 
295  if (!empty($_POST['process_form'])) {
296 
297  include SQ_DATA_PATH.'/private/conf/preferences.inc';
298  $new_preferences = $preferences;
299 
300  foreach ($preferences as $type_code => $pref_vars) {
301  // We need to include the asset the prefs are for to make sure all locales are imported for it
302  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
303 
304  $path = SQ_SYSTEM_ROOT.'/'.$GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code, 'dir').'/'.$type_code.'_prefs.inc';
305  require_once $path;
306  $pref_name = $type_code.'_Prefs';
307  $prefs = new $pref_name();
308  if ($prefs->processBackend($o, $have_lock)) {
309  $new_preferences[$type_code] = $prefs->pref_vars;
310  }
311  }
312 
313 
314  // go through and work out which vars have changed
315  $changed_vars = Array();
316  foreach ($preferences as $type_code => $pref_data) {
317  foreach ($pref_data as $var_name => $var_data) {
318  $current_value = $preferences[$type_code][$var_name]['default'];
319  $new_value = $new_preferences[$type_code][$var_name]['default'];
320 
321  if ($current_value !== $new_value) {
322  $changed_vars[$var_name] = Array('old' => $current_value, 'new' => $new_value, 'type_code' => $type_code);
323  }
324  }
325  }
326 
327  // output the new preference file
328  $str = '<'.'?php $preferences = '.var_export($new_preferences, true).'; ?'.'>';
329  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
330  if (!string_to_file($str, SQ_DATA_PATH.'/private/conf/preferences.inc')) {
331  return false;
332  }
333 
334  if ($changed_vars) {
335  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
336  $ms->openQueue();
337  foreach ($changed_vars as $var_name => $values) {
338  $msg_reps = Array(
339  'type_code' => ucwords(str_replace('_', ' ', $values['type_code'])),
340  'setting' => $var_name,
341  'old_value' => var_export($values['old'], true),
342  'new_value' => var_export($values['new'], true),
343  );
344  $message = $ms->newMessage(Array(), 'prefs.system', $msg_reps);
345  $ms->enqueueMessage($message);
346  }
347  $ms->closeQueue();
348 
349 
350  }// end if
351 
352 
353  }// end if process_form
354 
355  if (!empty($_POST['sq_lock_release']) || !empty($_POST['sq_lock_release_manual'])) {
356  $GLOBALS['SQ_SYSTEM']->releaseLock($lock_code);
357  }
358 
359  // if there is no lock currently and we want it (and we are an admin)
360  if (!empty($_POST['sq_lock_acquire']) && $is_admin) {
361  $GLOBALS['SQ_SYSTEM']->acquireLock($lock_code);
362  }
363 
364 
365  return true;
366 
367  }//end processUserPrefs()
368 
369 
378  function paintActiveLocks(&$o)
379  {
380  $class_name = 'locking_method_'.SQ_CONF_LOCKING_METHOD;
381  $GLOBALS['SQ_SYSTEM']->am->includeAsset($class_name);
382  $current_time = time();
383 
384  try {
385  if (eval('return '.$class_name.'::supportsGetActiveLocks();') === FALSE) {
386  $o->openSection(translate('active_locks'));
387  $o->openField(translate('system_config_active_locks_no_support', SQ_CONF_LOCKING_METHOD));
388  $o->closeField();
389  $o->openSection();
390  return TRUE;
391  } else {
392  $db_locks = eval('return '.$class_name.'::getActiveLocks(NULL);');
393  }
394  } catch (Exception $e) {
395  return 'Unable to get active locks, '.$e->getMessage();
396  }
397 
398  if (empty($db_locks)) {
399  $o->openSection(translate('active_locks'));
400  $o->openField(translate('no_active_locks'));
401  $o->closeField();
402  $o->openSection();
403  return true;
404  }
405 
406  $active_locks = Array();
407  $asset_info_ids = Array();
408  foreach ($db_locks as $lock) {
409  $lockid = $lock['lockid'];
410  if (substr($lockid, 0, 6) != 'asset.') continue;
411  $lockid = substr($lockid, 6);
412  $lock_type = substr($lockid, strrpos($lockid, '.') + 1);
413  $assetid = substr($lockid, 0, strrpos($lockid, '.'));
414 
415  // Using assetExists() will not work for shadow assets to check if asset exists in system
416  if (!$GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, '', TRUE)) continue;
417 
418  $active_locks[$lock['userid']]['locks'][$assetid][$lock_type] = $lock['expires'];
419 
420  if (!isset($active_locks[$lock['userid']]['num_locks'])) $active_locks[$lock['userid']]['num_locks'] = 0;
421  $active_locks[$lock['userid']]['num_locks']++;
422 
423  $asset_info_ids[$lock['userid']] = $lock['userid'];
424  $asset_info_ids[$assetid] = $assetid;
425  }
426 
427  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($asset_info_ids));
428 
429  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
430 
431  $o->openSection(translate('active_locks'));
432  $o->openField('');
433  ?>
434  <table class="sq-backend-table">
435  <tr>
436  <td class="sq-backend-table-header"><?php echo translate('user'); ?></td>
437  <td class="sq-backend-table-header"><?php echo translate('lock_type'); ?></td>
438  <td class="sq-backend-table-header"><?php echo translate('maps_held_at'); ?></td>
439  <td class="sq-backend-table-header"><?php echo translate('expires'); ?></td>
440  </tr>
441  <?php
442  foreach ($active_locks as $userid => $locks) {
443  $printed_header = false;
444  foreach ($locks['locks'] as $assetid => $lock_info) {
445  foreach ($lock_info as $lock_type => $expires) {
446  ?>
447  <tr>
448  <?php
449  if (!$printed_header) {
450  ?>
451  <td class="sq-backend-table-cell" rowspan="<?php echo $locks['num_locks']; ?>">
452  <?php
453  if (isset($asset_info[$userid])) {
454  $name = $asset_info[$userid]['name'];
455  $type = $asset_info[$userid]['type_code'];
456  } else {
457  $asset = &$GLOBALS['SQ_SYSTEM']->am->getAsset($userid);
458  $name = $asset->name;
459  $type = $asset->type();
460  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
461  }
462  ?>
463  <script language="JavaScript" type="text/javascript">sq_print_icon("<?php echo $GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($type); ?>", "16", "16", "");</script>
464  &nbsp;<acronym title="<?php echo ucwords(str_replace('_', ' ', $type)); ?> - <?php echo $userid; ?>"><?php echo $name; ?></acronym>
465  </td>
466  <?php
467  $printed_header = true;
468  }
469  ?>
470 
471  <td class="sq-backend-table-cell">
472  <?php echo $lock_type; ?>
473  </td>
474  <td class="sq-backend-table-cell">
475  <?php
476  if (isset($asset_info[$assetid])) {
477  $name = $asset_info[$assetid]['name'];
478  $type = $asset_info[$assetid]['type_code'];
479  } else {
480  $asset = &$GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
481  $name = $asset->name;
482  $type = $asset->type();
483  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
484  }
485  ?>
486  <script language="JavaScript" type="text/javascript">sq_print_icon("<?php echo $GLOBALS['SQ_SYSTEM']->am->getAssetIconURL($type); ?>", "16", "16", "");</script>
487  &nbsp;<acronym title="<?php echo ucwords(str_replace('_', ' ', $type)); ?> - <?php echo $assetid; ?>"><?php echo $name; ?></acronym>
488  </td>
489  <td class="sq-backend-table-cell">
490  <?php
491  $expires_in = easy_time_total((strtotime($expires) - $current_time), true);
492  if (!$expires_in) $expires_in = '1 second';
493  echo translate('due_to_expire', $expires_in);
494  ?>
495  </td>
496  </tr>
497  <?php
498  }
499  }
500  }
501  ?>
502  </table>
503  <?php
504  $o->closeField();
505  $o->closeSection();
506 
507  }//end paintActiveLocks()
508 
509 
518  function processActiveLocks(&$o)
519  {
520 
521  }//end processActiveLocks()
522 
523 
524 }//end class
525 
526 ?>