17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
55 public static function execute($settings, &$state)
59 if (empty($settings[
'roleid']))
return FALSE;
61 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'roleid'])) {
66 $roleid = array_get_index($settings,
'roleid', 0);
67 $role_action = array_get_index($settings,
'role_action',
'add');
68 $current_user = array_get_index($settings,
'use_current_user', FALSE);
69 $userids = array_get_index($settings,
'userid', Array());
70 $cascade = array_get_index($settings,
'cascade', FALSE);
71 $cascade_to_dependents = array_get_index($settings,
'cascade_to_dependents', FALSE);
72 $delete_all_before_adding = array_get_index($settings,
'delete_all_before_adding', FALSE);
74 if (!is_array($userids)) $userids = Array ($userids);
77 $userids = array_merge($userids, Array($GLOBALS[
'SQ_SYSTEM']->user->id));
80 if (empty($state[
'asset'])) {
82 if (empty($state[
'assetid'])) {
85 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
89 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
91 $major = $am->getAsset($settings[
'roleid']);
92 $minor =& $state[
'asset'];
95 switch ($role_action) {
97 $role_vars[
'add'][$roleid] = $userids;
101 $role_vars[
'delete'][$roleid] = 0;
105 if($delete_all_before_adding) {
106 $current_roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($state[
'assetid']);
107 if(!empty($current_roles)) {
108 $GLOBALS[
'SQ_SYSTEM']->am->deleteRole($state[
'assetid'], $roleid);
112 if (!empty($role_vars)) {
113 if ($cascade || $cascade_to_dependents) {
114 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
117 $state[
'asset']->
id => Array(
118 'type_code' => $state[
'asset']->
type(),
121 'role_changes' => $role_vars,
124 if (!$cascade) $vars[
'dependants_only'] = 1;
125 $errors = $hh->freestyleHIPO(
'hipo_job_edit_roles', $vars);
126 $result = empty($errors);
128 if (!empty($role_vars[
'add'])) {
129 foreach ($role_vars[
'add'] as $roleid => $userids) {
130 foreach ($userids as $userid) {
131 if (!$GLOBALS[
'SQ_SYSTEM']->am->setRole($state[
'assetid'], $roleid, $userid)) {
139 if ($result && !empty($role_vars[
'delete'])) {
140 foreach ($role_vars as $roleid => $null) {
141 if (!$GLOBALS[
'SQ_SYSTEM']->am->deleteRole($state[
'assetid'], $roleid)) {
155 'assetid' => $state[
'asset']->
id,
157 'userids' => $userids,
158 'cascade' => $cascade,
159 'cascade_to_dependents' => $cascade_to_dependents,
176 public static function getInterface($settings, $prefix, $write_access=FALSE)
179 $selected_roleid = array_get_index($settings,
'roleid', 0);
180 $role_action = array_get_index($settings,
'role_action',
'add');
181 $selected_userids = array_get_index($settings,
'userid', Array());
182 $current_user = array_get_index($settings,
'use_current_user', FALSE);
183 $cascade = array_get_index($settings,
'cascade', FALSE);
184 $cascade_to_dependents = array_get_index($settings,
'cascade_to_dependents', FALSE);
185 $delete_all_before_adding = array_get_index($settings,
'delete_all_before_adding', FALSE);
188 if ($selected_roleid && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($selected_roleid)) {
189 $selected_roleid = 0;
194 asset_finder($prefix.
'[role]', $selected_roleid, Array(
'role' =>
'I'));
196 if ($selected_roleid) {
197 $selected_role_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($selected_roleid, Array(), TRUE,
'name');
198 echo
'<b>'.$selected_role_info[$selected_roleid].
' (#'.$selected_roleid.
')</b>';
200 echo
'<b>['.translate(
'trigger_set_role_no_role_selected').
']</b>';
203 $role_select_role_part = ob_get_contents();
208 multiple_asset_finder($prefix.
'[user_assetid]', $selected_userids, Array(
'user' =>
'D',
'user_group' =>
'D'));
209 echo
'<i>AND / OR</i><br>';
210 echo check_box($prefix.
'[use_current_user]', 1, $current_user);
211 label(translate(
'trigger_set_role_user_firing_trigger'), $prefix.
'[use_current_user]');
214 if ($selected_userids || $current_user) {
215 if($selected_userids) {
216 $selected_assetname = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($selected_userids, Array(), TRUE,
'name');
218 foreach ($selected_assetname as $assetid => $asset_name) {
219 echo
'<li><b>'.$asset_name.
' (#'.$assetid.
')</b></li>';
224 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($current_user ?
'tick' :
'cross').
'.gif" alt="'.($current_user ? translate(
'yes') : translate(
'no')).
'" /> ';
225 echo translate(
'trigger_set_role_user_firing_trigger');
229 echo
'<b>['.translate(
'trigger_set_role_no_users_selected').
']</b>';
232 $role_select_user_part = ob_get_contents();
237 check_box($prefix.
'[cascade]',
'1', $cascade);
238 label(translate(
'cascade_roles_option'), $prefix.
'[cascade]');
240 check_box($prefix.
'[cascade_to_dependents]',
'1', $cascade_to_dependents);
241 label(translate(
'cascade_roles_to_dependents'), $prefix.
'[cascade_to_dependents]');
243 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade ?
'tick' :
'cross').
'.gif" alt="'.($cascade ? translate(
'yes') : translate(
'no')).
'" /> ';
244 echo translate(
'cascade_roles_option');
247 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade_to_dependents ?
'tick' :
'cross').
'.gif" alt="'.($cascade_to_dependents ? translate(
'yes') : translate(
'no')).
'" /> ';
248 echo translate(
'cascade_roles_to_dependents');
250 $role_cascade_part = ob_get_contents();
255 check_box($prefix.
'[delete_all_before_adding]',
'1', $delete_all_before_adding);
256 label(translate(
'delete_all_before_adding'), $prefix.
'[delete_all_before_adding]');
259 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($delete_all_before_adding ?
'tick' :
'cross').
'.gif" alt="'.($delete_all_before_adding ? translate(
'yes') : translate(
'no')).
'" /> ';
260 echo translate(
'delete_all_before_adding');
262 $role_delete_all_part = ob_get_contents();
265 $contents =
''.translate(
'select_a_role').
'<br />'.
266 $role_select_role_part.
'<br />'.
267 '<br />'.translate(
'select_users_for_role').
'<br />'.
268 $role_select_user_part.
'<br />'.
269 $role_cascade_part.
'<br />'.
270 $role_delete_all_part;
290 $link_type_list = get_link_type_names();
293 if (!empty($request_data[
'role'][
'assetid'])) {
294 $selected_roleid = $request_data[
'role'][
'assetid'];
296 return translate(
'no_roles_set');
299 $raw_userids = $request_data[
'user_assetid'];
301 foreach ($raw_userids as $user) {
302 if (!empty($user[
'assetid'])) {
303 $userids[] = $user[
'assetid'];
306 $settings[
'use_current_user'] = array_get_index($request_data,
'use_current_user', FALSE);
308 if (empty($userids) && !$settings[
'use_current_user']) {
309 return translate(
'select_users_for_role');
313 $settings[
'role_action'] = array_get_index($request_data,
'role_action',
'add');
314 $settings[
'roleid'] = $selected_roleid;
315 $settings[
'userid'] = $userids;
316 $settings[
'cascade'] = array_get_index($request_data,
'cascade', FALSE);
317 $settings[
'delete_all_before_adding'] = array_get_index($request_data,
'delete_all_before_adding', FALSE);
318 if ($settings[
'cascade']) {
319 $settings[
'cascade_to_dependents'] = TRUE;
321 $settings[
'cascade_to_dependents'] = array_get_index($request_data,
'cascade_to_dependents', FALSE);
338 public static function getLocks($settings, &$state)
341 $state[
'assetid'] => Array(
'all'),