function addDefaultRoles($defaultRoles = array()) { global $db; foreach ($defaultRoles as $roleName => $role) { $ACLField = new ACLField(); $role1 = new ACLRole(); $role1->name = $roleName; $role1->description = $roleName . " Role"; $role1_id = $role1->save(); foreach ($role as $category => $actions) { foreach ($actions as $name => $access_override) { if ($name == 'fields') { foreach ($access_override as $field_id => $access) { $ACLField->setAccessControl($category, $role1_id, $field_id, $access); } } else { $queryACL = "SELECT id FROM acl_actions where category='{$category}' and name='{$name}'"; $result = $db->query($queryACL); $actionId = $db->fetchByAssoc($result); if (isset($actionId['id']) && !empty($actionId['id'])) { $role1->setAction($role1_id, $actionId['id'], $access_override); } } } } } }
foreach ($role_actions as $module) { foreach ($module as $type) { foreach ($type as $act) { $role->setAction($role->id, $act['id'], $act['aclaccess']); } } } // duplicate field ACL $fields = ACLField::getACLFieldsByRole($_REQUEST['isduplicate']); foreach ($fields as $field) { ACLField::setAccessControl($field['category'], $role->id, $field['name'], $field['aclaccess']); } } } else { ob_clean(); $flc_module = 'All'; foreach ($_POST as $name => $value) { if (substr_count($name, 'act_guid') > 0) { $name = str_replace('act_guid', '', $name); $role->setAction($role->id, $name, $value); } if (substr_count($name, 'flc_guid') > 0) { $flc_module = $_REQUEST['flc_module']; $name = str_replace('flc_guid', '', $name); ACLField::setAccessControl($flc_module, $role->id, $name, $value); } } echo "result = {role_id:'{$role->id}', module:'{$flc_module}'}"; sugar_cleanup(true); } header("Location: index.php?module=ACLRoles&action=DetailView&record=" . $role->id);