17 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
19 require_once SQ_SYSTEM_ROOT.
'/core/attributes/parameter_map/parameter_map.inc';
55 public static function execute($settings, &$state)
58 if (!isset($settings[
'permission']))
return FALSE;
60 $parameter_map_value = array_get_index($settings,
'user_map', serialize(Array()));
62 $userid = $atr_parameter_map->getParameterValue(
'user');
64 if (!empty($userid)) {
66 $user_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($userid, Array(
'user',
'user_group'), FALSE);
67 if (empty($user_info))
return FALSE;
70 $userid = $settings[
'userid'];
74 if (empty($userid))
return FALSE;
76 if (empty($state[
'assetid']))
return FALSE;
77 $granted = array_get_index($settings,
'granted', TRUE);
78 $dependant_only = array_get_index($settings,
'dependants_only', FALSE);
79 $dependant_parents = array_get_index($settings,
'dependant_parents', FALSE);
80 $cascade_to_new = array_get_index($settings,
'cascade_to_new', TRUE);
83 $mute_error = array_get_index($settings,
'mute_error', FALSE);
87 $target_assets = Array();
88 if ($dependant_parents) {
90 $target_assets = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($state[
'assetid'],
'', TRUE, FALSE);
91 if (!empty($target_assets)) {
93 $target_assets = array_flip($target_assets);
94 foreach ($target_assets as $assetid => $null) {
95 $target_assets[$assetid] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
99 $target_assets[$state[
'assetid']] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
103 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
104 $hipo_assets = Array();
105 foreach ($target_assets as $assetid => $asset) {
106 $hipo_assets[] = $assetid;
108 $vars[
'permission_changes'] = Array(
110 'permission' => $settings[
'permission'],
111 'granted' => $granted,
113 'previous_access' => NULL,
114 'dependants_only' => $dependant_only,
115 'cascades' => $cascade_to_new,
116 'assetids' => $hipo_assets,
119 $vars[
'dependants_only'] = $dependant_only;
121 $status_errors = $hh->freestyleHipo(
'hipo_job_edit_permissions', $vars);
122 if (!$mute_error && !empty($status_errors))
return FALSE;
125 'assetid' => $state[
'assetid'],
127 'permission' => $settings[
'permission'],
128 'granted' => $granted,
129 'cascades' => $cascade_to_new,
145 public static function getInterface($settings, $prefix, $write_access=FALSE)
147 $current_schemaid = array_get_index($settings,
'schemaid', 0);
148 $action = array_get_index($settings,
'action', 1);
149 $granted = array_get_index($settings,
'granted', 1);
150 $permission = array_get_index($settings,
'permission', SQ_PERMISSION_READ);
151 $userid = array_get_index($settings,
'userid', 0);
152 $dependants_only = array_get_index($settings,
'dependants_only', FALSE);
153 $dependant_parents = array_get_index($settings,
'dependant_parents', FALSE);
154 $cascade_to_new = array_get_index($settings,
'cascade_to_new', TRUE);
159 $new_prefix = str_replace(array(
'[',
']'),
'_', $prefix);
160 hidden_field($prefix.
'[new_prefix]', $new_prefix);
164 combo_box($prefix.
'[granted]',
166 '1' => translate(
'grant'),
167 '0' => translate(
'deny'),
168 '-1' => translate(
'delete'),
176 echo translate(
'grant');
179 echo translate(
'deny');
182 echo translate(
'delete');
192 combo_box($prefix.
'[permission]', $permissions, FALSE, $permission);
194 echo
'<b>'.$permissions[$permission].
'</b>';
196 echo
' '.translate(
'access_for').
' ';
211 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($userid);
213 if (is_null($user)) {
214 echo
'<b>['.translate(
'trigger_no_user_selected').
']</b>';
216 echo
'<b>'.$user->name.
'</b>';
220 $parameter_map_value = array_get_index($settings,
'user_map', serialize(Array()));
224 $atr_parameter_map->setParameter(
'user',
'Userid or Groupid');
225 echo $atr_parameter_map->paint($new_prefix.
'_parameter_map', !$write_access);
230 check_box($prefix.
'[dependants_only]', 1, $dependants_only);
231 echo translate(
'trigger_set_permission_dependants_only');
233 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($dependants_only ?
'tick' :
'cross').
'.gif" alt="'.($dependants_only ? translate(
'yes') : translate(
'no')).
'" /> ';
234 echo translate(
'trigger_set_permission_dependants_only');
240 check_box($prefix.
'[dependant_parents]', 1, $dependant_parents);
241 echo translate(
'trigger_set_permission_dependant_parents');
244 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($dependant_parents ?
'tick' :
'cross').
'.gif" alt="'.($dependant_parents ? translate(
'yes') : translate(
'no')).
'" /> ';
245 echo translate(
'trigger_set_permission_dependant_parents');
251 check_box($prefix.
'[cascade_to_new]', 1, $cascade_to_new);
252 echo translate(
'cascade_permission_to_new_children');
255 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade_to_new ?
'tick' :
'cross').
'.gif" alt="'.($cascade_to_new ? translate(
'yes') : translate(
'no')).
'" /> ';
256 echo translate(
'cascade_permission_to_new_children');
259 return ob_get_clean();
277 $new_prefix = str_replace(array(
'[',
']'),
'_', array_get_index($request_data,
'new_prefix',
''));
280 $permission = array_get_index($request_data,
'permission', FALSE);
281 if (!$permission)
return 'Permission not specified';
284 if (isset($valid_permissions[$permission])) {
285 $settings[
'permission'] = $permission;
287 return 'Specified permission is invalid';
291 $granted = array_get_index($request_data,
'granted', FALSE);
292 if ($granted < -1 || $granted > 1) {
293 return 'Access parameter is invalid';
295 $settings[
'granted'] = $granted;
298 $user_data = array_get_index($request_data,
'userid', FALSE);
299 $userid = $user_data[
'assetid'];
301 if (!empty($userid)) {
302 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($userid);
303 if (is_null($user)) {
304 return 'Specified user is not a valid asset';
307 $settings[
'userid'] = $userid;
310 $atr_parameter_map->process($new_prefix.
'_parameter_map');
311 $settings[
'user_map'] = $atr_parameter_map->value;
316 $user_map = unserialize($settings[
'user_map']);
317 if (empty($settings[
'userid']) && (empty($user_map))) {
318 return 'No user or group id provided';
322 $dependants_only = array_get_index($request_data,
'dependants_only', FALSE);
323 $settings[
'dependants_only'] = ($dependants_only ==
'1') ? TRUE : FALSE;
326 $dependant_parents = array_get_index($request_data,
'dependant_parents', FALSE);
327 $settings[
'dependant_parents'] = ($dependant_parents ==
'1') ? TRUE : FALSE;
330 $cascade_to_new = array_get_index($request_data,
'cascade_to_new', FALSE);
331 $settings[
'cascade_to_new'] = ($cascade_to_new ==
'1') ? TRUE : FALSE;
347 SQ_PERMISSION_READ =>
'read',
348 SQ_PERMISSION_WRITE =>
'write',
349 SQ_PERMISSION_ADMIN =>
'admin',
364 public static function getLocks($settings, &$state)
366 return Array($state[
'assetid'] => Array(
'permissions'));
383 $settings[
'userid'] = $value;