/
AssignGroups.php
executable file
·327 lines (276 loc) · 13.7 KB
/
AssignGroups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
#[\AllowDynamicProperties]
class AssignGroups
{
public function popup_select(&$bean, $event, $arguments)
{
global $sugar_config;
//only process if action is Save (meaning a user has triggered this event and not the portal or automated process)
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'Save'
&& isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true
&& empty($bean->fetched_row['id']) && $bean->module_dir != "Users" && $bean->module_dir != "SugarFeed") {
//Upload an attachment to an Email Template and save. If user with multi groups - popup select option
//it will redirect to notes instead of EmailTemplate and relationship will fail...check below to avoid
if (!empty($_REQUEST['module']) && $_REQUEST['module'] != $bean->module_dir) {
return;
}
if (!empty($_REQUEST['securitygroup_list'])) {
require_once('modules/SecurityGroups/SecurityGroup.php');
$security_modules = SecurityGroup::getSecurityModules();
//sanity check
if (array_key_exists($bean->module_dir, $security_modules)) {
//add each group in securitygroup_list to new record
$rel_name = SecurityGroup::getLinkName($bean->module_dir, "SecurityGroups");
$bean->load_relationship($rel_name);
foreach ($_REQUEST['securitygroup_list'] as $group_id) {
$bean->$rel_name->add($group_id);
}
}
} elseif (!empty($_REQUEST['dup_checked'])) {
//well...ShowDuplicates doesn't pass through request vars unless they are defined in the module vardefs
//so we are screwed here...
global $current_language;
$ss_mod_strings = return_module_language($current_language, 'SecurityGroups');
unset($_SESSION['securitysuite_error']); //to be safe
$_SESSION['securitysuite_error'] = $ss_mod_strings['LBL_ERROR_DUPLICATE'];
}
} elseif (isset($sugar_config['securitysuite_user_popup']) && $sugar_config['securitysuite_user_popup'] == true
&& empty($bean->fetched_row['id']) && $bean->module_dir == "Users"
&& isset($_REQUEST['action']) && $_REQUEST['action'] != 'SaveSignature') { //Bug: 589
//$_REQUEST['return_module'] = $bean->module_dir;
//$_REQUEST['return_action'] = "DetailView";
//$_REQUEST['return_id'] = $bean->id;
//$_SESSION['securitygroups_popup_'.$bean->module_dir] = $bean->id;
if (!isset($_SESSION['securitygroups_popup'])) {
$_SESSION['securitygroups_popup'] = array();
}
$_SESSION['securitygroups_popup'][] = array(
'module' => $bean->module_dir,
'id' => $bean->id
);
}
}
public function popup_onload($event, $arguments)
{
if (!empty($_REQUEST['to_pdf']) || !empty($_REQUEST['sugar_body_only'])) {
return;
}
/** //test user popup
* //always have this loaded
* echo '<script type="text/javascript" src="modules/SecurityGroups/javascript/popup_relate.js"></script>';
*/
global $sugar_config;
$action = null;
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
} else {
LoggerManager::getLogger()->warn('Not defined action in request');
}
$module = null;
if (isset($_REQUEST['module'])) {
$module = $_REQUEST['module'];
} else {
LoggerManager::getLogger()->warn('Not defined module in request');
}
if (isset($action) && ($action == "Save" || $action == "SetTimezone")) {
return;
}
if ((
//(isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true)
//||
($module == "Users" && isset($sugar_config['securitysuite_user_popup']) && $sugar_config['securitysuite_user_popup'] == true)
)
//&& isset($_SESSION['securitygroups_popup_'.$module]) && !empty($_SESSION['securitygroups_popup_'.$module])
&& !empty($_SESSION['securitygroups_popup'])
) {
foreach ($_SESSION['securitygroups_popup'] as $popup_index => $popup) {
$record_id = $popup['id'];
$module = $popup['module'];
unset($_SESSION['securitygroups_popup'][$popup_index]);
require_once('modules/SecurityGroups/SecurityGroup.php');
if ($module == 'Users') {
$rel_name = "SecurityGroups";
} else {
$rel_name = SecurityGroup::getLinkName($module, "SecurityGroups");
}
//this only works if on the detail view of the record actually saved...
//so ajaxui breaks this as it stays on the parent
$auto_popup = <<<EOQ
<script type="text/javascript" language="javascript">
open_popup("SecurityGroups",600,400,"",true,true,{"call_back_function":"securitysuite_set_return_and_save_background","form_name":"DetailView","field_to_name_array":{"id":"subpanel_id"},"passthru_data":{"module":"$module","record":"$record_id","child_field":"$rel_name","return_url":"","link_field_name":"$rel_name","module_name":"$rel_name","refresh_page":"1"}},"MultiSelect",true);
</script>
EOQ;
echo $auto_popup;
}
unset($_SESSION['securitygroups_popup']);
}
}
public function mass_assign($event, $arguments)
{
$action = null;
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
} else {
LoggerManager::getLogger()->warn('Not defined action in request');
}
$module = null;
if (isset($_REQUEST['module'])) {
$module = $_REQUEST['module'];
} else {
LoggerManager::getLogger()->warn('Not defined module in request');
}
$no_mass_assign_list = array("Emails" => "Emails", "ACLRoles" => "ACLRoles"); //,"Users"=>"Users");
//check if security suite enabled
$action = strtolower($action);
if (isset($module) && ($action == "list" || $action == "index" || $action == "listview")
&& (!isset($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] != true)
&& !array_key_exists($module, $no_mass_assign_list)
) {
global $current_user;
if (is_admin($current_user) || ACLAction::getUserAccessLevel($current_user->id, "SecurityGroups", 'access') == ACL_ALLOW_ENABLED) {
require_once('modules/SecurityGroups/SecurityGroup.php');
$groupFocus = BeanFactory::newBean('SecurityGroups');
$security_modules = SecurityGroup::getSecurityModules();
//if(in_array($module,$security_modules)) {
if (array_key_exists($module, $security_modules)) {
global $app_strings;
global $current_language;
$current_module_strings = return_module_language($current_language, 'SecurityGroups');
$form_header = get_form_header($current_module_strings['LBL_MASS_ASSIGN'], '', false);
$groups = $groupFocus->get_list("name", "", 0, -99, -99);
$options = array("" => "");
foreach ($groups['list'] as $group) {
$options[$group->id] = $group->name;
}
$group_options = get_select_options_with_id($options, "");
$export_where = !empty($_SESSION['export_where']) ? $_SESSION['export_where'] : '';
$export_where_md5 = md5($export_where);
$mass_assign = <<<EOQ
<script type="text/javascript" language="javascript">
function confirm_massassign(del, start_string, end_string) {
if (del == 1) {
return confirm(start_string + sugarListView.get_num_selected_string() + end_string);
} else {
return confirm(start_string + sugarListView.get_num_selected_string() + end_string);
}
}
function send_massassign(mode, no_record_txt, start_string, end_string, del) {
if (!sugarListView.confirm_action(del, start_string, end_string))
return false;
if (document.MassAssign_SecurityGroups.massassign_group.selectedIndex == 0) {
alert("{$current_module_strings['LBL_SELECT_GROUP_ERROR']}");
return false;
}
if (document.MassUpdate.select_entire_list &&
document.MassUpdate.select_entire_list.value == 1)
mode = 'entire';
else if (document.MassUpdate.massall.checked == true)
mode = 'page';
else
mode = 'selected';
var ar = new Array();
if (del == 1) {
var deleteInput = document.createElement('input');
deleteInput.name = 'Delete';
deleteInput.type = 'hidden';
deleteInput.value = true;
document.MassAssign_SecurityGroups.appendChild(deleteInput);
}
switch (mode) {
case 'page':
document.MassAssign_SecurityGroups.uid.value = '';
for (wp = 0; wp < document.MassUpdate.elements.length; wp++) {
if (typeof document.MassUpdate.elements[wp].name != 'undefined'
&& document.MassUpdate.elements[wp].name == 'mass[]' && document.MassUpdate.elements[wp].checked) {
ar.push(document.MassUpdate.elements[wp].value);
}
}
document.MassAssign_SecurityGroups.uid.value = ar.join(',');
if (document.MassAssign_SecurityGroups.uid.value == '') {
alert(no_record_txt);
return false;
}
break;
case 'selected':
for (wp = 0; wp < document.MassUpdate.elements.length; wp++) {
if (typeof document.MassUpdate.elements[wp].name != 'undefined'
&& document.MassUpdate.elements[wp].name == 'mass[]'
&& document.MassUpdate.elements[wp].checked) {
ar.push(document.MassUpdate.elements[wp].value);
}
}
if (document.MassUpdate.uid.value != '') {
document.MassUpdate.uid.value += ',';
document.MassUpdate.uid.value += ar.join(',');
document.MassAssign_SecurityGroups.uid.value = document.MassUpdate.uid.value;
if (document.MassAssign_SecurityGroups.uid.value == '') {
alert(no_record_txt);
return false;
}
} else {
document.MassAssign_SecurityGroups.uid.value += ar.join(',');
if (document.MassAssign_SecurityGroups.uid.value == '') {
alert(no_record_txt);
return false;
}
}
break;
case 'entire':
var entireInput = document.createElement('input');
entireInput.name = 'entire';
entireInput.type = 'hidden';
entireInput.value = 'index';
document.MassAssign_SecurityGroups.appendChild(entireInput);
break;
}
document.MassAssign_SecurityGroups.submit();
return false;
}
</script>
<form action='index.php' method='post' name='MassAssign_SecurityGroups' id='MassAssign_SecurityGroups'>
<input type='hidden' name='action' value='MassAssign' />
<input type='hidden' name='module' value='SecurityGroups' />
<input type='hidden' name='return_action' value='{$action}' />
<input type='hidden' name='return_module' value='{$module}' />
<input type="hidden" name="export_where_md5" value="{$export_where_md5}">
<textarea style='display: none' name='uid'></textarea>
<div id='massassign_form'>$form_header
<table cellpadding='0' cellspacing='0' border='0' width='100%'>
<tr>
<td style='padding-bottom: 2px;' class='listViewButtons'>
<input type='submit' name='Assign' value='{$current_module_strings['LBL_ASSIGN']}' onclick="return send_massassign('selected', '{$app_strings['LBL_LISTVIEW_NO_SELECTED']}','{$current_module_strings['LBL_ASSIGN_CONFIRM']}','{$current_module_strings['LBL_CONFIRM_END']}',0);" class='button'>
<input type='submit' name='Remove' value='{$current_module_strings['LBL_REMOVE']}' onclick="return send_massassign('selected', '{$app_strings['LBL_LISTVIEW_NO_SELECTED']}','{$current_module_strings['LBL_REMOVE_CONFIRM']}','{$current_module_strings['LBL_CONFIRM_END']}',1);" class='button'>
</td></tr></table>
<table cellpadding='0' cellspacing='0' border='0' width='100%' class='tabForm' id='mass_update_table'>
<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td>{$current_module_strings['LBL_GROUP']}</td>
<td><select name='massassign_group' id="massassign_group" tabindex='1'>{$group_options}</select></td>
</tr>
</table></td></tr></table></div>
</form>
EOQ;
echo $mass_assign;
}
}
}
//if after a save...
if (!empty($_SESSION['securitysuite_error'])) {
$lbl_securitysuite_error = $_SESSION['securitysuite_error'];
unset($_SESSION['securitysuite_error']);
echo <<<EOQ
<script>
var oNewP = document.createElement("div");
oNewP.className = 'error';
var oText = document.createTextNode("{$lbl_securitysuite_error}");
oNewP.appendChild(oText);
var beforeMe = document.getElementsByTagName("div")[0];
document.body.insertBefore(oNewP, beforeMe);
</script>
EOQ;
}
}
}