17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
41 $perms = Array(
'Read' => SQ_PERMISSION_READ,
'Write' => SQ_PERMISSION_WRITE,
'Administrator' => SQ_PERMISSION_ADMIN);
45 foreach ($perms as $title => $perm) {
46 $permissions = $GLOBALS[
'SQ_SYSTEM']->am->getAssetPermissionByCascade($owner->id, $perm, NULL, $cascades);
48 foreach ($permissions as $userid => $perm_info) {
49 $granted = $perm_info[
'granted'];
50 if (!isset($direct[$perm][$granted])) {
51 $direct[$perm][$granted] = Array();
53 $direct[$perm][$granted][] = $perm_info[
'userid'];
56 if (!empty($direct[$perm])) ksort($direct[$perm]);
60 if (empty($direct))
return FALSE;
65 <table
class=
"sq-backend-table">
67 <td
class=
"sq-backend-table-header">
68 <?php echo translate(
'user'); ?>
70 <td
class=
"sq-backend-table-header">
71 <?php echo translate(
'permissions'); ?>
73 <td
class=
"sq-backend-table-header" align=
"right">
74 <?php echo translate(
'access'); ?>
80 foreach ($perms as $title => $perm) {
81 if (!empty($direct[$perm])) {
82 foreach ($direct[$perm] as $granted => $userids) {
83 foreach ($userids as $userid) {
85 $user_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($userid), Array(
'user',
'user_group'), FALSE);
86 if (empty($user_info))
continue;
90 <td
class=
"sq-backend-table-cell">
92 echo get_asset_tag_line($userid);
95 <td
class=
"sq-backend-table-cell">
96 <?php echo $title.
' Permission'?>
98 <td
class=
"sq-backend-table-cell" align=
"right">
99 <span style=
"color: <?php echo (($granted == '0') ? 'red' : 'green'); ?>; font-weight:bold;"><?php echo (($granted ==
'0') ? translate(
'denied') : translate(
'granted')) ?></span>
130 function paintPermissions(&$owner, &$o, &$ei, $keywords=NULL)
133 $perms = Array(
'read' => SQ_PERMISSION_READ,
'write' => SQ_PERMISSION_WRITE,
'admin' => SQ_PERMISSION_ADMIN);
135 $admin_access = $owner->
adminAccess(
'permissions');
136 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
139 foreach ($perms as $title => $perm) {
140 $o->
openSection(translate(
'permission_section', translate($title)));
142 $permissions = $GLOBALS[
'SQ_SYSTEM']->am->getAssetPermissionByCascade($owner->id, $perm);
145 foreach ($permissions as $perm_info) {
146 $granted = $perm_info[
'granted'];
147 $userid = $perm_info[
'userid'];
149 if (!isset($direct[$granted])) {
150 $direct[$granted] = Array();
152 $direct[$granted][$userid] = $perm_info;
162 if (!empty($direct)) {
163 foreach ($direct as $granted => $perm_details) {
165 <table
class=
"sq-backend-table">
167 <td
class=
"sq-backend-table-header">
168 <span style=
"color: <?php echo (($granted == '0') ? 'red' : 'green'); ?>"><?php echo (($granted ==
'0') ? translate(
'denied') : translate(
'granted')) ?></span>
170 <td align=
"center" width=
"100" class=
"sq-backend-table-header" style=
"font-weight: bold;"><?php echo translate(
'cascade_question'); ?></td>
173 ?><td align=
"center" width=
"100" class=
"sq-backend-table-header" style=
"font-weight: bold;"><?php echo translate(
'delete_question'); ?></td><?php
179 foreach ($perm_details as $userid => $perm_detail) {
182 <td
class=
"sq-backend-table-cell">
184 echo get_asset_tag_line($userid);
187 <td align=
"center" width=
"100" class=
"sq-backend-table-cell">
190 check_box($prefix.
'_permissions['.$perm.
'][cascades]['.rawurlencode($userid).
']', 1, $perm_detail[
'cascades']);
192 ?><img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo ($perm_detail['cascades'] ? 'tick' : 'cross'); ?>.gif" width=
"15" height=
"15" /><?php
198 ?><td align=
"center" width=
"100" class=
"sq-backend-table-cell"><?php
199 check_box($prefix.
'_permissions['.$perm.
'][delete]['.rawurlencode($userid).
']');
213 echo translate(
'no_access_permissions_set', strtolower($title));
225 <table cellspacing=
"0">
228 if (!in_array($public_userid, array_get_index($direct, 0, Array())) && !in_array($public_userid, array_get_index($direct, 1, Array()))) {
233 combo_box($prefix.
'_permissions['.$perm.
'][public_access][granted]', Array(
'' =>
'',
'1' => translate(
'grant'),
'0' => translate(
'deny')), FALSE,
'');
234 echo
' '.translate(
'public_permission');
244 combo_box($prefix.
'_permissions['.$perm.
'][new][granted]', Array(
'' =>
'',
'1' => translate(
'grant'),
'0' => translate(
'deny')), FALSE,
'');
245 echo
' '.translate(
'specific_permission');
249 <td><?php multiple_asset_finder($prefix.
'_permissions['.$perm.
'][new][userid]', Array(), Array(
'user' =>
'D',
'user_group' =>
'D')); ?></td>
254 $o->
openField(translate(
'cascade_question'),
'new_line');
255 check_box($prefix.
'_permissions['.$perm.
'][new][cascades]', 1, TRUE);
256 ?> Automatically cascade
this permission to
new children<?php
265 $kiddies = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($owner->id);
266 if (count($kiddies)) {
267 $o->
openSection(translate(
'cascade_permission_changes'));
269 $o->
note(translate(
'cascade_permissions_note', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), count($kiddies)));
272 check_box($prefix.
'_permissions[cascade_changes]',
'1', TRUE);
273 label(translate(
'cascade_permissions'), $prefix.
'_permissions[cascade_changes]');
277 $o->
openSection(translate(
'manually_cascade_permissions'));
279 $o->
note(translate(
'manually_cascade_permissions_note', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), count($kiddies)));
282 check_box($prefix.
'_permissions[manual_cascade]');
283 label(translate(
'manually_cascade_permissions_option'), $prefix.
'_permissions[manual_cascade]');
292 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_permission');
294 if (!empty($fp_jobs)) {
295 $o->
openField(translate(
'scheduled_future_permission_change'),
'new_line');
297 <table
class=
"sq-backend-table">
299 <td
class=
"sq-backend-table-header"><?php echo translate(
'action'); ?></td>
300 <td
class=
"sq-backend-table-header"><?php echo translate(
'permission'); ?></td>
301 <td
class=
"sq-backend-table-header">
302 <span style=
"color:green"><?php echo translate(
'granted'); ?></span>
304 <td
class=
"sq-backend-table-header">
305 <span style=
"color:red"><?php echo translate(
'denied'); ?></span>
307 <td
class=
"sq-backend-table-header"><?php echo translate(
'when'); ?></td>
308 <td align=
"center" class=
"sq-backend-table-header" style=
"text-align: center;"><?php echo translate(
'cascade_question'); ?></td>
309 <td align=
"center" class=
"sq-backend-table-header" style=
"text-align: center;"><?php echo translate(
'update_all_question'); ?></td>
313 <td align=
"center" class=
"sq-backend-table-header" style=
"text-align: center;"><?php echo translate(
'delete_question'); ?></td>
320 $sorted_fp_jobs = _sortCronJobsByDate($fp_jobs);
322 foreach ($sorted_fp_jobs as $fp_job) {
325 <td
class=
"sq-backend-table-cell">
326 <?php echo $fp_job->actionName(); ?>
328 <td
class=
"sq-backend-table-cell">
329 <?php echo $fp_job->permissionName(); ?>
331 <td
class=
"sq-backend-table-cell">
333 $granted_userids = $fp_job->getGrantedUsers(TRUE);
334 foreach ($granted_userids as $userid) {
335 echo get_asset_tag_line($userid);
340 <td
class=
"sq-backend-table-cell">
342 $denied_userids = $fp_job->getGrantedUsers(FALSE);
343 foreach ($denied_userids as $userid) {
344 echo get_asset_tag_line($userid);
349 <td
class=
"sq-backend-table-cell">
350 <?php echo $fp_job->readableWhen(); ?>
352 <td align=
"center" class=
"sq-backend-table-cell">
354 if ($fp_job->attr(
'cascade_to_new')) {
355 echo translate(
'yes');
357 echo translate(
'no');
361 <td align=
"center" class=
"sq-backend-table-cell">
363 if ($fp_job->attr(
'dependants_only')) {
364 echo translate(
'no');
366 echo translate(
'yes');
372 <td align=
"center" class=
"sq-backend-table-cell">
374 if ($fp_job->canDelete()) {
375 check_box($prefix.
'_remove_fp[]', $fp_job->id);
390 }
else if (!$admin_access){
392 echo translate(
'no_future_permissions_set');
397 $o->
openField(translate(
'add_new_future_permission'),
'new_line');
398 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
399 $cron_epoc = (int)$cron_mgr->attr(
'epoch');
400 $cron_refresh = (int)$cron_mgr->attr(
'refresh_time');
401 if ($cron_epoc > 0 && $cron_refresh > 0) {
402 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
403 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_permission');
405 $edit_fns = $fp->getEditFns();
406 $edit_fns->paintInLineBackend($fp, $o, $prefix.
'_new_fp');
409 $o->
note(translate(
'cron_manager_next_run', $cron_mgr->readableRefreshTime(), readable_datetime($cron_mgr->timeOfNextRun())));
411 $print_commit_button = TRUE;
413 echo translate(
'cron_manager_not_configured');
416 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cron_mgr);
422 return $admin_access;
437 function processPermissions(&$owner, &$o, &$ei)
441 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
445 $admin_access = $owner->
adminAccess(
'permissions');
447 if (!$admin_access)
return FALSE;
449 $permission_vars = Array();
451 if (!isset($_POST[$prefix.
'_permissions'])) {
455 $cascade_changes = !empty($_POST[$prefix.
'_permissions'][
'cascade_changes']);
457 $perms = Array(
'Administrator' => SQ_PERMISSION_ADMIN,
'Write' => SQ_PERMISSION_WRITE,
'Read' => SQ_PERMISSION_READ);
458 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
461 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
462 if (!is_null($cron_mgr)) {
463 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_permission');
465 if (!empty($_POST[$prefix.
'_remove_fp'])) {
467 if (!empty($fp_jobs)) {
469 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($cron_mgr->id,
'links')) {
470 for ($i = 0; $i < count($fp_jobs); $i++) {
471 if (in_array($fp_jobs[$i]->
id, $_POST[$prefix.
'_remove_fp'])) {
472 $cron_mgr->removeJob($fp_jobs[$i]);
476 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($cron_mgr->id,
'links');
479 trigger_localised_error(
'SYS0232', E_USER_NOTICE);
489 $edit_fns = $fp->getEditFns();
490 if ($fp->setAssetToUpdate($owner) && $edit_fns->processInLineBackend($fp, $o, $prefix.
'_new_fp')) {
491 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
492 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
493 if ($cron_mgr->addJob($fp, $GLOBALS[
'SQ_SYSTEM']->user)) {
494 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
496 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
498 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
507 foreach ($perms as $title => $perm) {
513 $post_data = $_POST[$prefix.
'_permissions'][$perm];
516 if (isset($post_data[
'public_access'][
'granted']) && $post_data[
'public_access'][
'granted'] !=
'') {
517 $permission_vars[] = Array(
518 'permission' => $perm,
519 'assetids' => Array($owner->id),
520 'granted' => (
int)$post_data[
'public_access'][
'granted'],
521 'userid' => $public_userid,
522 'cascades' => (
int)isset($post_data[
'new'][
'cascades']),
523 'previous_access' => NULL,
524 'dependants_only' => !($cascade_changes && isset($post_data[
'new'][
'cascades'])),
529 if (!empty($post_data[
'new'])) {
530 foreach ($post_data[
'new'][
'userid'] as $entry) {
531 if (!empty($entry[
'assetid'])) {
532 if (!isset($post_data[
'new'][
'granted']) || $post_data[
'new'][
'granted'] ==
'') {
533 trigger_localised_error(
'SYS0269', E_USER_NOTICE);
536 $permission_vars[] = Array(
537 'permission' => $perm,
538 'assetids' => Array($owner->id),
539 'granted' => (
int)$post_data[
'new'][
'granted'],
540 'userid' => $entry[
'assetid'],
541 'cascades' => (
int)isset($post_data[
'new'][
'cascades']),
542 'previous_access' => NULL,
543 'dependants_only' => !($cascade_changes && isset($post_data[
'new'][
'cascades'])),
551 if (!empty($post_data[
'delete'])) {
552 foreach ($post_data[
'delete'] as $userid => $on) {
553 $userid = rawurldecode($userid);
554 $current_access = $GLOBALS[
'SQ_SYSTEM']->am->getAssetPermissionByCascade($owner->id, $perm, $userid);
555 $current_access = $current_access[0];
556 $permission_vars[] = Array(
557 'permission' => $perm,
558 'assetids' => Array($owner->id),
561 'previous_access' => $current_access[
'granted'],
562 'dependants_only' => !($cascade_changes && $current_access[
'cascades']),
568 $perm_infos = $GLOBALS[
'SQ_SYSTEM']->am->getAssetPermissionByCascade($owner->id, $perm);
569 foreach ($perm_infos as $perm_info) {
570 $userid = $perm_info[
'userid'];
571 $cascades = isset($post_data[
'cascades'][rawurlencode($userid)]);
572 if ((
boolean)$cascades != (
boolean)$perm_info[
'cascades']) {
574 $permission_vars[] = Array(
575 'permission' => $perm,
576 'assetids' => Array($owner->id),
577 'granted' => $perm_info[
'granted'],
579 'previous_access' => NULL,
580 'cascades' => $cascades,
581 'dependants_only' => 1,
586 if (!empty($_POST[$prefix.
'_permissions'][
'manual_cascade'])) {
587 $current = $GLOBALS[
'SQ_SYSTEM']->am->getAssetPermissionByCascade($owner->id, $perm, NULL, TRUE);
588 foreach ($current as $perm_info) {
589 $permission_vars[] = Array(
590 'permission' => $perm,
591 'granted' => $perm_info[
'granted'],
592 'userid' => $perm_info[
'userid'],
593 'assetids' => Array($owner->id),
594 'previous_access' => NULL,
602 if (!empty($permission_vars)) {
603 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
605 'permission_changes' => $permission_vars,
606 'permission_screen_assetid' => $owner->id,
608 $hh->queueHipo(
'hipo_job_edit_permissions', $vars);
622 function _sortCronJobsByDate($cron_jobs) {
624 $assetid_date_arr = Array();
625 foreach ($cron_jobs as $cron_job) {
626 $assetid_date_arr[$cron_job->id] = $cron_job->attr(
'when');
629 asort($assetid_date_arr);
632 $sorted_cron_jobs = Array();
633 foreach ($assetid_date_arr as $assetid => $date) {
636 foreach ($cron_jobs as $cron_job) {
637 if ($assetid == $cron_job->id) {
638 $matched = $cron_job;
642 $sorted_cron_jobs[] = $matched;
645 return $sorted_cron_jobs;