SuiteCRM-Core/modules/SecurityGroups/AssignGroups.php
Clemente Raposo 601c0c039b Squashed 'public/legacy/' changes from 92c30d9960..ee41ae127f
ee41ae127f SuiteCRM 7.13.3 Release
710b977fe9 Fix #10009 - Cannot configure Module Menu Filters on PHP8+
096b87c982 Fix #9153 - Adding dynamicenum case option for export
0cf566c131 Fix #8897 - Adding missing relationship for SurveyResponses module
c25ec3546c Fix #9470 - Set fdow in Calendar popup date selector
1d8ee63779 Fix #9326 - Adding decimal and float case option for export to use user-defined decimal separator
8ecc413cea Fix #9476 - Mass assign security groups only assigns selected on current page
8c8dacb256 Fix #9542 - added checks for count methods
c7eeca8db8 Fix #7759, #8273 - Double compose button in subpanels
e022f2e094 Fix #9621 - Workflows Calculate Field Actions don't translate dynamicenum fields
461f50a089 Fix #9764 - Add extra To addresses to CC field
4cf46d154d Fix salesagility#9768 - Do not convert link URLs in TinyMCE
c5ad471977 Fix #9783 - Compose view quick search
45c5c2a8d0 Fix #9780 - Popup does not show after creating a user
637c15e048 Fix #9812 - Decimal number calculations workflows
c025ca0659 Fix #9817 - Typo
a8cc7d8d5c Fix #9828 - $mod_strings not in scope for line 395 of the same file
41ef82116b Fix #9849 - allowed_preview is defined twice in the array
646d655e8e Fix #9875 SugarFeed shows 0 seconds ago and negative interval for certain datetime formats
f2fa7c3940 Fix #9902 - Workflow - Some Date calculations fail with certain formats
e28458a79d Fix #9930 - Recurrent calendar items
7a9c5f2490 Fix #9602 - ProspectLists save function has a duplication issue
b3e757172a Fix #9963 - Upgrade league/oauth2-server to latest version
6e61173aa3 Fix #9974 - External Providers saving with no type
1b0b5d6007 Fix #9974 - inbound emails saving with no type

git-subtree-dir: public/legacy
git-subtree-split: ee41ae127ff74a9182c42af4e1c63db32e2f1fec
2023-05-08 12:35:02 +01:00

321 lines
13 KiB
PHP
Executable file

<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
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 (in_array($bean->module_dir, array_keys($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 (in_array($module, array_keys($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;
}
}
break;
case 'entire':
var entireInput = document.createElement('input');
entireInput.name = 'entire';
entireInput.type = 'hidden';
entireInput.value = 'index';
document.MassAssign_SecurityGroups.appendChild(entireInput);
//confirm(no_record_txt);
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;
}
}
}