17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
68 public static function paintConfig(&$o, $class, $write_access)
71 $o->openField(translate(
'permissions_threshold'));
74 text_box($class.
'[SQ_HIPO_PERMISSIONS_THRESHOLD]', SQ_HIPO_PERMISSIONS_THRESHOLD, 5);
75 echo
' '.translate(
'assets');
76 $o->note(translate(
'hipo_value_divided_by_permission'));
78 echo SQ_HIPO_PERMISSIONS_THRESHOLD;
79 echo
' '.translate(
'assets');
96 'SQ_HIPO_PERMISSIONS_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
110 return parent::getCodeName().
'-'.md5(serialize($this->_running_vars[
'permission_changes']));
123 return translate(
'hipo_name_edit_permissions');
139 'name' => translate(
'hipo_updating_permissions'),
140 'function_call' => Array(
141 'process_function' =>
'processPermissions',
143 'running_mode' =>
'server',
145 'allow_cancel' =>
true,
165 if (SQ_HIPO_PERMISSIONS_THRESHOLD == 0)
return 0;
166 if (!isset($this->_running_vars[
'todo_assetids'])) {
169 return (($this->_running_vars[
'total_changes']) / (SQ_HIPO_PERMISSIONS_THRESHOLD / count($this->_running_vars[
'permission_changes'])) * 100);
182 while (!empty($this->_running_vars[
'todo_assetids'])) {
200 if (empty($this->_running_vars[
'permission_changes'])) {
201 trigger_localised_error(
'HIPO0014', E_USER_WARNING);
205 $this->_running_vars[
'done_changes'] = 0;
206 $this->_running_vars[
'total_changes'] = 0;
208 if (empty($this->_running_vars[
'permission_changes'])) {
210 $this->_running_vars[
'todo_assetids'] = Array();
211 }
else if (empty($this->_running_vars[
'permission_screen_assetid'])) {
212 $this->_running_vars[
'todo_assetids'] = Array();
213 foreach ($this->_running_vars[
'permission_changes'] as $perm_change) {
214 $assetids = $perm_change[
'assetids'];
215 foreach ($assetids as $assetid) {
216 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
218 if (empty($asset_info)) {
219 trigger_localised_error(
'HIPO0013', E_USER_WARNING, $assetid);
223 if ((!array_get_index($perm_change,
'cascades', TRUE)) || array_get_index($perm_change,
'dependants_only')) {
224 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
226 $child_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
230 $child_assets[$assetid] = Array (
232 'type_code' => $asset_info[$assetid][
'type_code'],
236 $child_assets = array_reverse($child_assets, TRUE);
239 foreach ($child_assets as $child_assetid => $child_asset) {
240 $type_code = $child_asset[0][
'type_code'];
242 $this_todo =& $this->_running_vars[
'todo_assetids'][$child_assetid];
243 $this_todo[
'type_code'] = $type_code;
244 $this_todo[
'permission_changes'][] = $perm_change;
245 $this->_running_vars[
'total_changes']++;
252 foreach ($this->_running_vars[
'permission_changes'] as $perm_change) {
253 if (!((!array_get_index($perm_change,
'cascades', TRUE)) || array_get_index($perm_change,
'dependants_only'))) {
258 $assetid = $this->_running_vars[
'permission_screen_assetid'];
259 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
260 if (empty($asset_info)) {
261 trigger_localised_error(
'HIPO0013', E_USER_WARNING, $assetid);
266 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid);
268 $children = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($assetid);
272 $todo_assetids = Array(
274 'type_code' => $asset_info[$assetid][
'type_code'],
277 foreach($children as $todo_assetid => $info) {
278 if (!isset($todo_assetids[$todo_assetid])) {
279 $todo_assetids[$todo_assetid][
'type_code'] = $info[0][
'type_code'];
282 unset($dep_children);
285 $this->_running_vars[
'todo_assetids'] = $todo_assetids;
286 $this->_running_vars[
'total_changes'] = count($todo_assetids);
289 return parent::prepare();
305 if (!empty($this->_running_vars[
'todo_assetids'])) {
306 reset($this->_running_vars[
'todo_assetids']);
307 $assetid = key($this->_running_vars[
'todo_assetids']);
308 $asset_type = $this->_running_vars[
'todo_assetids'][$assetid][
'type_code'];
309 $perm_changes = empty($this->_running_vars[
'permission_screen_assetid']) ? $this->_running_vars[
'todo_assetids'][$assetid][
'permission_changes'] : $this->_running_vars[
'permission_changes'];
310 unset($this->_running_vars[
'todo_assetids'][$assetid]);
311 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
313 if (!is_null($asset) ) {
315 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($assetid,
'permissions')) {
316 if ($asset->adminAccess(
'permissions')) {
317 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
318 $this->_running_vars[
'done_changes']++;
320 foreach ($perm_changes as $set_data) {
321 $perm = $set_data[
'permission'];
322 $perm_name = permission_type_name($perm);
324 if ($set_data[
'userid']) {
327 $user_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($set_data[
'userid']),
'user',
false);
330 if (empty($user_info)) {
331 $user_name =
'Unknown User';
333 $user_name = $user_info[$set_data[
'userid']][
'name'];
336 $user_name =
'General Public';
338 if ($set_data[
'previous_access'] === null) {
341 $current = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset->id, $perm, !(
bool)$set_data[
'granted'], FALSE, FALSE, TRUE, TRUE);
342 if (isset($current[$set_data[
'userid']])) {
343 $new_access = ($set_data[
'granted']) ? translate(
'grant') : translate(
'revoke');
344 $current_access = ($current[$set_data[
'userid']]) ? translate(
'granted') : translate(
'revoked');
345 $this->
_addError(translate(
'hipo_cannot_modify_permission', $new_access, $perm_name, $user_name, $asset->name, $current_access),
true);
350 $current = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset->id, $perm, null,
false,
false,
true);
351 if (!isset($current[$set_data[
'userid']])) {
353 }
else if ($current[$set_data[
'userid']] != $set_data[
'previous_access']) {
354 $new_access = ($set_data[
'previous_access']) ? translate(
'grant') : translate(
'revoke');
355 $current_access = ($set_data[
'previous_access']) ? translate(
'revoked') : translate(
'granted');
356 $this->
_addError(translate(
'hipo_cannot_modify_permission', $new_access, $perm_name, $user_name, $asset->name, $current_access),
true);
362 switch ($set_data[
'granted']) {
365 $step_data[
'message'] = htmlentities(
'Removing '.$perm_name.
' permission from "'.$asset->name.
'" (#'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
366 $GLOBALS[
'SQ_SYSTEM']->am->deletePermission($asset->id, $set_data[
'userid'], $perm);
373 $step_data[
'message'] = htmlentities(($set_data[
'granted'] ?
'Apply' :
'Deny').
'ing '.$perm_name.
' permission to "'.$asset->name.
'" (#'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
374 $GLOBALS[
'SQ_SYSTEM']->am->setPermission($asset->id, $set_data[
'userid'], $perm, $set_data[
'granted'], $set_data[
'cascades']);
381 if (count($perm_changes) > 1) {
382 $step_data[
'message'] = htmlentities(
'Making '.count($perm_changes).
' permission changes to '.$asset->name.
' (Id: #'.$asset->id.
')', ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
383 }
else if (count($perm_changes) == 0) {
384 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
386 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($assetid,
'permissions');
387 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
392 trigger_localised_error(
'SYS0111', E_USER_WARNING, $asset->name);
396 trigger_localised_error(
'SYS0100', E_USER_WARNING, $asset->name);
399 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
400 $this->
_addError(translate(
'hipo_skipping_permission', $assetid));
405 if (empty($this->_running_vars[
'todo_assetids'])) {
406 $step_data[
'percent_done'] = 100;
407 $step_data[
'complete'] = TRUE;
409 $step_data[
'percent_done'] = ($this->_running_vars[
'done_changes'] / $this->_running_vars[
'total_changes']) * 100;
410 $step_data[
'complete'] = FALSE;