17 require_once SQ_CORE_PACKAGE_PATH.
'/folder/folder_edit_fns.inc';
57 $sql =
'SELECT type_code, screen, section
58 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_edit_access ';
59 $where =
'userid = :userid';
60 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
67 }
catch (Exception $e) {
68 throw new Exception(
'Unable to get current restriction information for userid #'.$asset->id.
' due to the following database error:'.$e->getMessage());
91 return !empty($current);
109 $admin_access = $asset->adminAccess(
'security');
111 if (empty($current) && !$admin_access) {
113 $o->note(translate(
'user_group_unrestricted_access_granted'));
117 foreach ($current as $type_code => $type_data) {
118 if ($type_code ==
'0')
continue;
120 $o->openSection($type_code);
123 <table
class=
"sq-backend-table">
125 <td
class=
"sq-backend-table-header" style=
"width: 75%;"><?php echo translate(
'screen_name'); ?></td>
126 <?php
if ($admin_access) {
127 ?><td
class=
"sq-backend-table-header" style=
"width: 25%;"><?php echo translate(
'remove_question'); ?></td><?php
131 $granted_screens = Array();
132 foreach ($type_data as $screen_data) {
133 $granted_screens[] = $screen_data[
'screen'];
134 if ($screen_data[
'screen'] ==
'0') {
135 $screen_name =
'<b>'.translate(
'all_screens').
'</b>';
137 $screen_name = ucwords(str_replace(
'_',
'', $screen_data[
'screen']));
141 <td
class=
"sq-backend-table-cell"><?php echo $screen_name; ?></td>
142 <?php
if ($admin_access) {
143 ?><td
class=
"sq-backend-table-cell">
144 <?php check_box($prefix.
'_remove_type_screen['.$type_code.
']['.$screen_data[
'screen'].
']'); ?>
157 if (!in_array(
'0', $granted_screens)) {
160 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
161 $asset =
new $type_code();
162 $ef = $asset->getEditFns();
164 $screens = Array(
' ' =>
'');
165 $screens[
'0'] =
'-- '.translate(
'all_screens').
' --';
166 foreach (array_keys($ef->static_screens) as $screen) {
167 if (in_array($screen, $granted_screens))
continue;
168 $screens[$screen] = ucfirst($screen);
170 foreach (array_keys($ei->getScreens()) as $screen) {
171 if (in_array($screen, $granted_screens))
continue;
172 $screens[$screen] = ucfirst($screen);
175 echo
'<br />'.translate(
'grant_screen_access').
' ';
176 combo_box($prefix.
'_add_type_screen['.$type_code.
']', $screens, FALSE, Array());
178 echo
'<br />'.translate(
'granted_unrestricted_access_explanation');
179 if (count($current[$type_code]) == 1) {
180 echo
'<br />'.translate(
'remove_all_screens_explanation');
192 $types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
194 foreach ($types as $type) {
195 if (isset($current[$type]))
continue;
196 $uc_types[$type] = ucwords(str_replace(
'_',
' ', $type));
199 $o->openSection(translate(
'restrict_screen_access_to_new_type'));
201 combo_box($prefix.
'_restrict_types', $uc_types, TRUE,
'', 6);
206 return $admin_access;
223 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
227 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
230 'userid' => $asset->id,
236 if (isset($_POST[$prefix.
'_restrict_types'])) {
237 $new_types = $_POST[$prefix.
'_restrict_types'];
240 foreach ($new_types as $type) {
241 if (isset($current[$type]))
continue;
243 $bind_vars[
'type_code'] = $type;
244 $bind_vars[
'screen'] =
'details';
248 }
catch (Exception $e) {
249 throw new Exception(
'Unable to add access for new asset type due to the following database error:'.$e->getMessage());
259 if (isset($_POST[$prefix.
'_remove_type_screen'])) {
260 $doomed_screens = $_POST[$prefix.
'_remove_type_screen'];
261 foreach ($doomed_screens as $type_code => $screen_data) {
263 $bind_vars[
'type_code'] = $type_code;
264 $bind_vars[
'screen'] =
'details';
266 foreach ($screen_data as $doomed_screen => $on) {
268 if ($doomed_screen ==
'0' && count($current[$type_code]) == 1) {
274 }
catch (Exception $e) {
275 throw new Exception(
'Unable to add access for userid #'.$asset->id.
' due to the following database error:'.$e->getMessage());
282 $bind_vars[
'screen'] = $doomed_screen;
286 }
catch (Exception $e) {
287 throw new Exception(
'Unable to delete access for userid #'.$asset->id.
' due to the following database error:'.$e->getMessage());
298 if (isset($_POST[$prefix.
'_add_type_screen'])) {
299 $new_screens = $_POST[$prefix.
'_add_type_screen'];
301 foreach ($new_screens as $type_code => $new_screen) {
302 if (trim($new_screen) ==
'')
continue;
304 $bind_vars[
'type_code'] = $type_code;
305 $bind_vars[
'screen'] = $new_screen;
309 }
catch (Exception $e) {
310 throw new Exception(
'Unable to add access for new asset type due to the following database error:'.$e->getMessage());
316 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
317 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
336 $write_access = $asset->adminAccess(
'preferences');
338 $pref_file_path = $asset->data_path.
'/.preferences.inc';
339 if (is_file($pref_file_path)) {
340 include $pref_file_path;
341 $custom_preferences = $preferences;
343 $custom_preferences = Array();
346 include SQ_DATA_PATH.
'/private/conf/preferences.inc';
348 foreach ($preferences as $type_code => $pref_vars) {
349 $o->openSection($GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code,
'name').
' Preferences');
351 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
352 $path = SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code,
'dir').
'/'.$type_code.
'_prefs.inc';
354 $pref_name = $type_code.
'_Prefs';
355 $prefs =
new $pref_name($pref_file_path);
357 foreach ($pref_vars as $var_name => $var_data) {
358 $o->openField(translate($var_data[
'name']));
359 if (isset($custom_preferences[$type_code][$var_name])) {
360 echo
'<p>'.translate(
'preference_currently_customised');
363 check_box($prefix.
'_revert['.$type_code.
']['.$var_name.
']');
364 echo
' <b>'.translate(
'revert_to_global_preferences').
'</b>';
367 $prefs->paintBackend($o, $write_access, $var_name);
369 echo
'<p>'.translate(
'preference_not_customised');
372 check_box($prefix.
'_customise['.$type_code.
']['.$var_name.
']');
373 echo
' <b>'.translate(
'customise_this_preference').
'</b>';
382 return $write_access;
399 if (!$asset->adminAccess(
'preferences'))
return FALSE;
401 $new_preferences = Array();
403 if (isset($_POST[$prefix.
'_customise'])) {
405 include SQ_DATA_PATH.
'/private/conf/preferences.inc';
406 foreach ($_POST[$prefix.
'_customise'] as $type_code => $var_data) {
407 foreach ($var_data as $var_name => $on) {
408 if (isset($preferences[$type_code][$var_name])) {
409 $new_preferences[$type_code][$var_name] = $preferences[$type_code][$var_name];
415 $pref_file_path = $asset->data_path.
'/.preferences.inc';
416 if (is_file($pref_file_path)) {
417 include $pref_file_path;
418 foreach ($preferences as $type_code => $pref_vars) {
419 $path = SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code,
'dir').
'/'.$type_code.
'_prefs.inc';
421 $pref_name = $type_code.
'_Prefs';
422 $prefs =
new $pref_name();
423 foreach ($pref_vars as $var_name => $var_data) {
424 if (!isset($_POST[$prefix.
'_revert'][$type_code][$var_name])) {
425 if ($prefs->processBackend($o, TRUE, $var_name)) {
426 $new_preferences[$type_code][$var_name] = $prefs->pref_vars[$var_name];
433 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
434 $str =
'<'.
'?php $preferences = '.var_export($new_preferences, TRUE).
'; ?'.
'>';
435 if (!is_dir($asset->data_path) && !create_directory($asset->data_path)) {
438 if (!string_to_file($str, $asset->data_path.
'/.preferences.inc')) {
459 function _printRoleTable($prefix, $pag_id, $roles, $write_access=FALSE, $include_userid=FALSE)
461 if (empty($roles))
return;
464 <table
class=
"sq-backend-table">
467 if ($include_userid) {
468 ?><th
class=
"sq-backend-table-header"><?php echo translate(
'role_assigned_to'); ?></td><?php
471 <th
class=
"sq-backend-table-header"><?php echo translate(
'role'); ?></td>
472 <th
class=
"sq-backend-table-header">
Asset for which the role is to be performed</td>
475 ?><th
class=
"sq-backend-table-header"><?php echo translate(
'role_reassign'); ?></td><?php
486 $start_printing_at = array_get_index($_REQUEST, $prefix.$pag_id.
'_start_at', 0);
487 $role_tag_lines = Array();
488 $user_tag_lines = Array();
489 $asset_tag_lines = Array();
491 foreach ($roles as $roleid => $userids) {
492 foreach ($userids as $userid => $assetids) {
493 $num_roles += count($assetids);
494 foreach ($assetids as $assetid) {
495 if ($roles_pointer < $start_printing_at) {
499 if ($roles_pointer >= $start_printing_at + $num_per_page) {
503 if (!isset($asset_tag_lines[$assetid])) {
504 $asset_tag_lines[$assetid] = get_asset_tag_line($assetid);
506 if (!isset($role_tag_lines[$roleid])) {
507 $role_tag_lines[$roleid] = get_asset_tag_line($roleid);
513 if ($include_userid) {
514 if (!isset($user_tag_lines[$userid])) {
515 $user_tag_lines[$userid] = get_asset_tag_line($userid);
517 ?><td
class=
"sq-backend-table-cell"><?php echo $user_tag_lines[$userid]; ?></td><?php
520 <td
class=
"sq-backend-table-cell"><?php echo $role_tag_lines[$roleid] ?></td>
521 <td
class=
"sq-backend-table-cell"><?php echo get_asset_tag_line($assetid); ?></td>
524 ?><td
class=
"sq-backend-table-cell"><?php echo check_box($prefix.
'_reassign[]', $assetid); ?></td><?php
534 if ($num_roles > $num_per_page) {
537 <td colspan=
"3" align=
"center" class=
"sq-backend-table-header">
539 hidden_field($prefix.$pag_id.
'_start_at', $start_printing_at);
540 if ($start_printing_at > 0) {
541 ?><a style=
"text-decoration: none;" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix.$pag_id; ?>_start_at', '<?php echo $start_printing_at - $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
543 ?><span style=
"color: #84848F"><?php
546 << <?php echo translate(
'previous_page');
548 if ($start_printing_at > 0) {
554 <b><?php echo translate(
'page_number', (floor($start_printing_at / $num_per_page) + 1), ceil($num_roles / $num_per_page)); ?></b>
557 if (($start_printing_at + $num_per_page) < $num_roles) {
558 ?><a style=
"text-decoration: none;" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix.$pag_id; ?>_start_at', '<?php echo $start_printing_at + $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
560 ?><span style=
"color: #84848F"><?php
563 echo translate(
'next_page'); ?> >>
565 if (($start_printing_at + $num_per_page) < $num_roles) {
594 $write_access = $asset->adminAccess(
'roles');
595 $string_code_suffix = ($asset instanceof
User_Group) ?
'group' :
'user';
597 $o->openSection(translate(
'role_directly_assigned_section_'.$string_code_suffix));
600 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'0' && SQ_CONF_ENABLE_ROLES_WF_SYSTEM ==
'0') {
601 echo translate(
'roles_system_disabled');
603 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole(NULL, NULL, $asset->id, TRUE, FALSE, FALSE, FALSE);
605 echo translate(
'no_roles_set');
609 echo translate(
'role_new_user').
': ';
610 echo asset_finder($prefix.
'_reassignee', 0, Array(
'user' =>
'D',
'user_group' =>
'D'));
618 $group_descendants = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants(
'user_group', TRUE);
619 $group_descendants = array_diff($group_descendants, Array(
'role'));
621 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($asset->id);
624 $parent_groups = Array();
625 foreach ($parents as $assetid => $type_code) {
626 if (in_array($type_code, $group_descendants)) {
627 $roles += $GLOBALS[
'SQ_SYSTEM']->am->getRole(NULL, NULL, $assetid, TRUE, FALSE, FALSE, FALSE);
628 $normal_role = $GLOBALS[
'SQ_SYSTEM']->am->getRole(NULL, NULL, $assetid, TRUE, FALSE, FALSE, FALSE);
629 foreach ($normal_role as $roleid => $userids) {
630 foreach ($userids as $userid => $assetids) {
631 foreach ($assetids as $assetid) {
632 $roles[$roleid][$userid][] = $assetid;
633 $roles[$roleid][$userid] = array_unique($roles[$roleid][$userid]);
638 $global_role = $GLOBALS[
'SQ_SYSTEM']->am->getRole(NULL, $assetid, 0, TRUE, FALSE, FALSE, FALSE);
639 foreach ($global_role as $roleid => $userids) {
640 foreach ($userids[0] as $assetid) {
641 $roles[$roleid][$roleid][] = $assetid;
642 $roles[$roleid][$roleid] = array_unique($roles[$roleid][$roleid]);
648 if (!empty($roles)) {
649 $o->openSection(translate(
'role_indirectly_assigned_section_'.$string_code_suffix));
656 return $write_access;
674 if (isset($_REQUEST[$prefix.
'_reassignee'])) {
675 $reassignee = array_get_index($_REQUEST[$prefix.
'_reassignee'],
'assetid', 0);
678 if (!$reassignee)
return;
680 $am = $GLOBALS[
'SQ_SYSTEM']->am;
682 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole(NULL, NULL, $asset->id, TRUE);
683 $reassign_assetids = array_get_index($_REQUEST, $prefix.
'_reassign', Array());
685 $role_vars = Array();
686 foreach ($roles as $roleid => $userids) {
687 foreach ($userids as $userid => $assetids) {
688 $changes = array_intersect($reassign_assetids, $assetids);
689 if (!empty($changes)) {
690 $role_vars[
'add'][$roleid][] = $reassignee;
691 $role_vars[
'delete'][$roleid][] = $userid;
696 if (!empty($reassign_assetids)) {
697 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
700 'assets' => $am->getAssetInfo($reassign_assetids, Array(), FALSE,
'type_code'),
701 'role_changes' => $role_vars,
702 'dependants_only' => TRUE,
705 $hh->queueHipo(
'hipo_job_edit_roles', $vars);