Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
user_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
36 {
37 
38 
43  function User_Edit_Fns()
44  {
45  $this->Asset_Edit_Fns();
46 
47  }//end constructor
48 
49 
60  function paintPasswordNote(&$asset, &$o, $prefix)
61  {
62  if ($asset->writeAccess('attributes')) {
63  $o->note(translate('password_entry_instructions').'<br />'.$asset->getPasswordRulesDescription());
64  return TRUE;
65  }
66  return FALSE;
67 
68  }//end paintPasswordNote()
69 
70 
79  function _getLinkedGroups(&$asset)
80  {
81  $group_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, 1,'user_group', FALSE, 'minor');
82 
83  $group_assetids = Array();
84  foreach ($group_links as $group_link) {
85  $group_assetids[] = $group_link['majorid'];
86  }
87 
88  $groups_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($group_assetids);
89 
90  return $groups_info;
91 
92  }//end _getLinkedGroups()
93 
94 
105  function paintUserConditions(&$asset, &$o, $prefix)
106  {
107  // get a list of directly linked groups
108  $groups = $this->_getLinkedGroups($asset);
109 
110  if (empty($groups)) {
111  $o->openField('');
112  echo translate('user_cannot_be_restricted');
113  $o->closeField();
114  return FALSE;
115  }
116 
117  $admin_access = $asset->adminAccess('attributes');
118 
119  if ($admin_access) {
120  $conditions = Array('' => '-- Select Type --') + $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($GLOBALS['SQ_SYSTEM']->am->getTypeDescendants('condition'), 'name');
121  }
122 
123  // get a list of user restrictions
124  $restrictions = $asset->attr('restrictions');
125 
126  foreach ($groups as $group_assetid => $group) {
127  $o->openSection($group['name'].' (#'.$group_assetid.')');
128  $o->openField('');
129 
130  // if user has restrictions related to this group
131  if (!array_get_index($restrictions, $group_assetid, FALSE)) {
132  echo translate('no_membership_conditions', $group['name']);
133  } else {
134  ?>
135  This user is part of this group when...
136  <table class="sq-backend-table" border="1">
137  <tr>
138  <th>&nbsp;&nbsp;&nbsp;</th>
139  <th>Condition</th>
140  <?php
141  if ($admin_access) {
142  ?>
143  <th>Delete</th>
144  <?php
145  }
146  ?>
147  </tr>
148  <?php
149  foreach ($restrictions[$group_assetid] as $key => $restriction) {
150  $condition_prefix = $prefix.'_condition_'.$group_assetid.'_'.$key;
151  ?>
152  <tr>
153  <td><?php echo $key; ?></td>
154  <td>
155  <?php
156  $edit_fns_classname = $restriction['name'].'_edit_fns';
157  $GLOBALS['SQ_SYSTEM']->am->includeAsset($restriction['name'], TRUE);
158 
159  if ($admin_access) {
160  $match_options = call_user_func(Array($restriction['name'], 'getMatchKeywords'), $restriction['name']);
161  combo_box($condition_prefix.'_match', $match_options, FALSE, $restriction['match']);
162  } else {
163  echo translate($restriction['name'].'_'.($restriction['match'] ? 'true' : 'false'));
164  }
165  echo '<br />';
166  call_user_func(Array($edit_fns_classname, 'paintEditInterface'), $restriction['condition_data'], $o, $condition_prefix, $admin_access, Array());
167  ?>
168  </td>
169  <?php
170  if ($admin_access) {
171  ?>
172  <td><?php check_box($condition_prefix.'[delete]', '1'); ?></td>
173  <?php
174  }
175  ?>
176  </tr>
177  <?php
178  }//end foreach restriction
179  ?>
180  </table>
181  <?php
182  }//end else - membership conditions
183 
184  if ($admin_access) {
185  ?>
186  <p>Add new condition: <?php combo_box($prefix.'_'.$group_assetid.'_new_condition', $conditions, FALSE, ''); ?></p>
187  <?php
188  }
189 
190  $o->closeField();
191  $o->closeSection();
192 
193  }//end foreach $groups
194 
195  // field closed by asset_edit_functions
196 
197  return TRUE;
198 
199  }//end paintUserConditions()
200 
201 
212  function processUserConditions(&$asset, &$o, $prefix)
213  {
214  // get a list of directly linked groups
215  $groups = $this->_getLinkedGroups($asset);
216  $admin_access = $asset->adminAccess('attributes');
217  $restrictions = $asset->attr('restrictions');
218 
219  // -- PROCESS CONDITIONS --//
220  foreach ($groups as $group_assetid => $group) {
221 
222  // if user has restrictions related to this group
223  if (array_get_index($restrictions, $group_assetid, NULL)) {
224 
225  // get array of restrictions for this group
226  foreach ($restrictions[$group_assetid] as $key => $restriction) {
227  $condition_prefix = $prefix.'_condition_'.$group_assetid.'_'.$key;
228 
229  // if this condition has been marked to delete, unset it now
230  if (isset($_POST[$condition_prefix]) && array_get_index($_POST[$condition_prefix], 'delete', 0)) {
231  unset($restrictions[$group_assetid][$key]);
232  } else {
233  // prepare condition data
234  $dir = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($restriction['name'], 'dir');
235  $edit_fns_classname = $restriction['name'].'_edit_fns';
236  require_once SQ_SYSTEM_ROOT.'/'.$dir.'/'.$edit_fns_classname.'.inc';
237  $condition_data = call_user_func(Array($edit_fns_classname, 'processEditInterface'), $o, $condition_prefix);
238  $restrictions[$group_assetid][$key]['condition_data'] = $condition_data;
239  $restrictions[$group_assetid][$key]['match'] = array_get_index($_POST, $condition_prefix.'_match', '1');
240  }
241  }
242  }
243  if ($new_name = array_get_index($_POST, $prefix.'_'.$group_assetid.'_new_condition')) {
244  $restrictions[$group_assetid][] = Array('name' => $new_name, 'match' => 1, 'condition_data' => Array());
245  }
246  }
247 
248  return $asset->setAttrValue('restrictions', $restrictions);
249 
250  }//end processUserConditions()
251 
252 
263  function paintLocale(&$asset, &$o, $prefix)
264  {
265  $write_access = $asset->writeAccess('attributes');
266 
267  require SQ_FUDGE_PATH.'/standards_lists/locales.inc';
268  $current_locale = $asset->attr('locale');
269 
270  if ($write_access) {
271  $standards_lists_locales = array_reverse($standards_lists_locales);
272  $standards_lists_locales[''] = '** Use System Default **';
273  $standards_lists_locales = array_reverse($standards_lists_locales);
274  combo_box($prefix.'_locale', $standards_lists_locales, FALSE, $current_locale);
275  } else {
276  if (isset($standards_lists_locales[$current_locale])) {
277  echo $standards_lists_locales[$current_locale];
278  } else if ($current_locale == '') {
279  // add system default to this message when it is determined
280  echo translate('no_locale_set_for_user', $standards_lists_locales[SQ_CONF_DEFAULT_BACKEND_LOCALE]);
281  } else {
282  echo translate('unknown_locale', $current_locale);
283  }
284  }
285 
286  return $write_access;
287 
288  }//end paintLocale()
289 
290 
301  function processLocale(&$asset, &$o, $prefix)
302  {
303  if (!$asset->writeAccess('attributes')) return FALSE;
304  $asset->setAttrValue('locale', $_POST[$prefix.'_locale']);
305  return $asset->saveAttributes();
306 
307  }//end processLocale()
308 
309 
320  function paintRoles(&$asset, &$o, $prefix)
321  {
322  $GLOBALS['SQ_SYSTEM']->am->includeAsset('user_group');
323  $user_group = new User_Group();
324  $user_group_edit_fns = $user_group->getEditFns();
325 
326  return $user_group_edit_fns->paintRoles($asset, $o, $prefix);
327 
328  }//end paintRoles()
329 
330 
341  function processRoles(&$asset, &$o, $prefix)
342  {
343  $GLOBALS['SQ_SYSTEM']->am->includeAsset('user_group');
344  $user_group = new User_Group();
345  $user_group_edit_fns = $user_group->getEditFns();
346 
347  return $user_group_edit_fns->processRoles($asset, $o, $prefix);
348 
349  }//end processRoles()
350 
351 
362  function paintLockDetails(&$asset, &$o, $prefix)
363  {
364  $current_locks = $asset->getUserLocks();
365 
366  if ($current_locks === FALSE) {
367  $o->openField(translate('current_locks'));
368  echo 'No ability to show active locks in current lock method';
369  $o->closeField();
370  return FALSE;
371  }
372 
373  $num_locks = count($current_locks);
374  $write_access = $asset->writeAccess('attributes');
375  $o->openField(translate('current_locks'));
376  echo translate('user_held_locks', htmlspecialchars($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), $num_locks);
377  ?>
378  <script type="text/javascript">
379  function sq_user_held_locks_info()
380  {
381  var userLockInfo = document.getElementById('sq_user_held_locks_details');
382  var userLockToggle = document.getElementById('sq_user_held_locks_toggle');
383  if (userLockInfo.style.display == 'none') {
384  userLockInfo.style.display = 'block';
385  userLockToggle.innerHTML = '<?php echo translate('hide_user_held_locks_details'); ?>';
386  } else {
387  userLockInfo.style.display = 'none';
388  userLockToggle.innerHTML = '<?php echo translate('show_user_held_locks_details'); ?>';
389  }
390  }
391  </script>
392  <?php
393  // Restrict to the top 100 other the page will take forever to load up
394  $restricted_locks = array_slice($current_locks, 0, 100);
395  echo '<br /><b class="clickable" onclick="sq_user_held_locks_info();" id="sq_user_held_locks_toggle">'.translate('show_user_held_locks_details').'</b><br />';
396  echo '<div id="sq_user_held_locks_details" style="display:none;">';
397  echo translate('showing_first', count($restricted_locks), $num_locks);
398  echo '<table class="sq-backend-table">';
399  echo '<tr>';
400  echo '<td class="sq-backend-table-header">Asset</td>';
401  echo '<td class="sq-backend-table-header">Screen</td>';
402  echo '</tr>';
403  foreach ($restricted_locks as $current_lock) {
404  if (isset($current_lock['lockid'])) {
405  $shown = FALSE;
406  if (strpos($current_lock['lockid'], 'asset') === 0) {
407  $asset_details = explode('.', $current_lock['lockid']);
408  if (isset($asset_details[1]) && isset($asset_details[2])) {
409  $locked_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($asset_details[1], '', TRUE);
410  if (!is_null($locked_asset)) {
411  echo '<tr><td>';
412  echo get_asset_tag_line($locked_asset->id);
413  echo '</td><td>';
414  echo ucwords($asset_details[2]);
415  echo '</td></tr>';
416  $shown = TRUE;
417  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($locked_asset);
418  }//end if
419  }//end if
420  }//end if
421 
422  if (!$shown) {
423  $unknown_lock_id = ucwords(str_replace('_', ' ', $current_lock['lockid']));
424  echo '<tr>';
425  echo '<td colspan="2">'.$unknown_lock_id.'</td>';
426  echo '</tr>';
427  }//end if
428  }//end if
429  }//end foreach
430  echo '</table></div>';
431 
432  $o->closeField();
433  $o->openField(translate('release_locks'));
434  if (!$write_access) {
435  ?>
436  <script type="text/javascript">
437 
438  // Confirms that this is what the user wants to do
439  function onReleaseAllClick() {
440  if (confirm('Are you sure you want to release all user locks?')) {
441  set_hidden_field("process_form", "1");
442  return true;
443  } else {
444  return false;
445  }
446  }
447  </script>
448 
449  <?php
450  // No lock, so we need to create our own commit button
451  submit_button($prefix.'_release_all_locks', 'Release All Locks', 'return onReleaseAllClick();');
452  } else {
453  // We have the lock, so we can use the normal commit button. Just print a dropdown box
454  $options = Array(
455  'yes' => translate('yes'),
456  'no' => translate('no'),
457  );
458  combo_box($prefix.'_release_all_locks_dropdown', $options, FALSE, 'no');
459  }
460  $o->note(translate('release_locks_note'));
461  $o->closeField();
462 
463  return FALSE;
464 
465  }//end paintLockDetails()
466 
467 
478  function processLockDetails(&$asset, &$o, $prefix)
479  {
480  $admin_access = $asset->adminAccess();
481  if (!$admin_access) return FALSE;
482 
483  if ((isset($_POST[$prefix.'_release_all_locks'])) || (isset($_POST[$prefix.'_release_all_locks_dropdown']) && ($_POST[$prefix.'_release_all_locks_dropdown'] == 'yes'))) {
484  $asset->releaseUserLocks();
485  }
486  return TRUE;
487 
488  }//end processLockDetails()
489 
490 
491 }//end class
492 
493 ?>