17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
38 function paintInlineRoles(&$owner, &$o, &$ei)
40 $prefix = $owner->getPrefix();
42 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($owner->id);
44 if (empty($roles))
return FALSE;
46 $o->openSection(translate(
'roles'));
47 $o->openField(
' ');
49 <table
class=
"sq-backend-table">
50 <td
class=
"sq-backend-table-header"><?php echo translate(
'roles'); ?></td>
51 <td
class=
"sq-backend-table-header"><?php echo translate(
'users'); ?></td>
52 <td
class=
"sq-backend-table-header"><?php echo translate(
'global'); ?></td>
54 foreach ($roles as $roleid => $userids) {
56 if (in_array(0, $userids)) {
57 $userids = array_diff($userids, Array(0));
61 $userid_count = count($userids);
64 <td
class=
"sq-backend-table-cell-alt" rowspan=
"<?php echo $userid_count; ?>">
65 <?php echo get_asset_tag_line($roleid); ?>
67 <td
class=
"sq-backend-table-cell-alt">
69 if (!empty($userids)) {
70 echo get_asset_tag_line(array_shift($userids));
74 <td
class=
"sq-backend-table-cell-alt" rowspan=
"<?php echo $userid_count; ?>">
75 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo ($global_role) ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
79 foreach ($userids as $userid) {
82 <td
class=
"sq-backend-table-cell-alt">
83 <?php echo get_asset_tag_line($userid); ?>
110 function paintRoles(&$owner, &$o, &$ei, $keywords=NULL)
112 $root = $ei->findScreen(
'static_screen_roles');
113 if (is_null($root))
return FALSE;
115 $prefix = $owner->getPrefix();
116 $admin_access = $owner->adminAccess(
'roles');
118 foreach ($root->section as $section) {
121 if (is_null($keywords)) {
123 if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || (
int)$section->attributes()->limbo_access == 0)) {
128 $section_access = $ei->_getAccess($owner, $section, $prefix);
129 if (!($section_access & SQ_EI_READ)) {
133 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower(str_replace(
' ',
'_', $section->attributes()->name))])) {
137 $o->openSection(array_get_index($section->attributes(),
'display_name', $section->attributes()->name));
139 if (!($num_fields = count($section->children()))) {
143 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'0' && SQ_CONF_ENABLE_ROLES_WF_SYSTEM ==
'0') {
146 echo translate(
'roles_system_disabled');
151 return $admin_access;
154 foreach ($section->field as $field) {
156 $field_access = $ei->_getAccess($owner, $field, $prefix);
157 if (!($field_access & SQ_EI_READ)) {
162 if (!empty($field->display_name)) {
163 $field_name = (string) $field->display_name;
166 $o->openField($field_name);
167 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower($field->attributes()->code)])) {
170 switch (strtolower($field->attributes()->code)) {
171 case 'roles_current' :
172 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($owner->id);
174 echo translate(
'no_roles_set');
177 <table
class=
"sq-backend-table">
178 <td
class=
"sq-backend-table-header"><?php echo translate(
'roles'); ?></td>
179 <td
class=
"sq-backend-table-header"><?php echo translate(
'users'); ?></td>
181 if (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1') {
183 <td
class=
"sq-backend-table-header"><?php echo translate(
'global'); ?></td>
187 foreach ($roles as $roleid => $ids) {
189 foreach ($ids as $row => $userid) {
190 if ($GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($userid, Array(
'user',
'user_group'), FALSE)) {
191 $userids[] = $userid;
194 $global_role = FALSE;
195 if (in_array(0, $userids)) {
196 $userids = array_diff($userids, Array(0));
202 <td
class=
"sq-backend-table-cell-alt">
203 <?php echo asset_finder($prefix.
'_role_'.$roleid, $roleid, Array(
'role' =>
'I')); ?>
205 <td
class=
"sq-backend-table-cell-alt">
206 <?php echo multiple_asset_finder($prefix.
'_userids_'.$roleid, $userids, Array(
'user' =>
'D',
'user_group' =>
'D')); ?>
209 if (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1') {
211 <td
class=
"sq-backend-table-cell-alt">
212 <?php echo check_box($prefix.
'_globally_assign_'.$roleid, 1, $global_role); ?>
220 $userid_count = count($userids);
223 <td
class=
"sq-backend-table-cell-alt" rowspan=
"<?php echo $userid_count; ?>">
224 <?php echo get_asset_tag_line($roleid); ?>
226 <td
class=
"sq-backend-table-cell-alt">
228 if (!empty($userids)) {
229 echo get_asset_tag_line(array_shift($userids));
234 if (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1') {
236 <td
class=
"sq-backend-table-cell-alt" rowspan=
"<?php echo $userid_count; ?>">
237 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo ($global_role) ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
244 foreach ($userids as $userid) {
247 <td
class=
"sq-backend-table-cell-alt">
248 <?php echo get_asset_tag_line($userid); ?>
261 echo
'<p>'.translate(
'select_a_role').
'<br />';
262 echo asset_finder($prefix.
'_role_new', 0, Array(
'role' =>
'I')).
'</p>';
263 echo
'<p>'.translate(
'select_users_for_role').
'<br />';
264 echo multiple_asset_finder($prefix.
'_userids_new', Array(), Array(
'user' =>
'D',
'user_group' =>
'D')).
'</p>';
265 if (SQ_CONF_ENABLE_GLOBAL_ROLES ==
'1') {
266 echo check_box($prefix.
'_globally_assign_new').translate(
'allow_global_assignment');
271 if (!empty($field->note)) {
272 $o->note((
string) $field->note);
275 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
276 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][strtolower($field->attributes()->code)]] = ob_get_contents();
286 $kiddies = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($owner->id);
287 if (count($kiddies)) {
288 $o->openSection(translate(
'cascade_roles'));
289 $o->openField(translate(
'note'));
290 $o->note(translate(
'cascade_roles_note', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), count($kiddies)));
292 $o->openField(
' ');
293 check_box($prefix.
'_cascade_roles', TRUE, TRUE);
294 label(translate(
'cascade_roles_option'), $prefix.
'_roles[cascade_changes]');
298 $o->openSection(translate(
'manually_cascade_roles'));
299 $o->openField(translate(
'note'));
300 $o->note(translate(
'manually_cascade_roles_note', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), count($kiddies)));
302 $o->openField(
' ');
303 check_box($prefix.
'_manually_cascade_roles', TRUE);
304 label(translate(
'manually_cascade_roles_option'), $prefix.
'_roles[manual_cascade]');
310 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower(str_replace(
' ',
'_', $section->attributes()->name))])) {
311 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'sections'][strtolower(str_replace(
' ',
'_', $section->attributes()->name))]] = ob_get_contents();
317 return $admin_access;
332 function processRoles(&$owner, &$o, &$ei)
334 if (!$owner->adminAccess(
'roles'))
return FALSE;
335 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($owner->id);
336 $current_roles = Array();
337 foreach ($roles as $roleid => $ids) {
338 foreach ($ids as $row => $userid) {
339 $current_roles[$roleid][] = $userid;
342 $new_roles = array_get_index($_REQUEST, $owner->getPrefix().
'_roles', Array());
344 $prefix = $owner->getPrefix();
346 $role_vars = Array();
347 foreach ($current_roles as $roleid => $userids) {
348 $currently_global = FALSE;
349 if (in_array(0, $userids)) {
350 $userids = array_diff($userids, Array(0));
351 $currently_global = TRUE;
354 $tmp = array_get_index($_REQUEST, $prefix.
'_role_'.$roleid, Array());
355 $roleid_new = array_get_index($tmp,
'assetid', 0);
356 $tmp = array_get_index($_REQUEST, $prefix.
'_userids_'.$roleid, Array());
358 $userids_new = Array();
359 $userids_keep = Array();
361 foreach ($tmp as $tmp_values) {
362 if ($tmp_values[
'assetid']) {
363 if (!in_array($tmp_values[
'assetid'], $userids)) {
364 $userids_new[] = $tmp_values[
'assetid'];
366 $userids_keep[] = $tmp_values[
'assetid'];
372 $role_vars[
'delete'][$roleid] = $userids;
373 }
else if ($roleid_new != $roleid) {
374 $role_vars[
'delete'][$roleid] = $userids;
375 $role_vars[
'add'][$roleid_new] = array_merge($userids_new, $userids_keep);
377 $roles_diff = array_diff($userids, $userids_keep);
378 if (!empty($roles_diff)) {
379 $role_vars[
'delete'][$roleid] = $roles_diff;
381 if (!empty($userids_new)) {
382 $role_vars[
'add'][$roleid] = $userids_new;
386 $globally_assigned = array_get_index($_REQUEST, $prefix.
'_globally_assign_'.$roleid, FALSE);
387 if (!$globally_assigned && $currently_global) {
388 $role_vars[
'delete'][$roleid][] = 0;
389 }
else if ($globally_assigned && !$currently_global) {
390 $role_vars[
'add'][$roleid][] = 0;
394 $roleid_new = array_get_index($_REQUEST, $prefix.
'_role_new', FALSE);
395 $globally_assign_new = array_get_index($_REQUEST, $prefix.
'_globally_assign_new', FALSE);
396 if ($roleid_new[
'assetid']) {
397 $userids_new = array_get_index($_REQUEST, $prefix.
'_userids_new', Array());
398 foreach ($userids_new as $userid_new) {
399 if ($userid_new[
'assetid']) {
400 $role_vars[
'add'][$roleid_new[
'assetid']][] = $userid_new[
'assetid'];
403 if ($globally_assign_new) {
404 $role_vars[
'add'][$roleid_new[
'assetid']][] = 0;
408 $cascade = array_get_index($_REQUEST, $prefix.
'_cascade_roles', FALSE);
409 $manually_cascade = array_get_index($_REQUEST, $prefix.
'_manually_cascade_roles', FALSE);
411 if ($manually_cascade) {
412 foreach ($current_roles as $roleid => $userids) {
413 if (isset($role_vars[
'add'][$roleid])) {
414 $role_vars[
'add'][$roleid] += $userids;
416 $role_vars[
'add'][$roleid] = $userids;
421 if (empty($role_vars[
'add']) && empty($role_vars[
'delete']) && !$manually_cascade) {
425 if (!empty($role_vars)) {
426 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
430 'type_code' => $owner->type(),
433 'role_changes' => $role_vars,
436 if (!$cascade) $vars[
'dependants_only'] = 1;
438 $hh->queueHipo(
'hipo_job_edit_roles', $vars);