/** * static addActions($category, $type='module') * Adds all default actions for a category/type * * @param STRING $category - the category (e.g module name - Accounts, Contacts) * @param STRING $type - the type (e.g. 'module', 'field') */ function addActions($category, $type = 'module') { global $ACLActions; $db = DBManagerFactory::getInstance(); if (isset($ACLActions[$type])) { foreach ($ACLActions[$type]['actions'] as $action_name => $action_def) { $action = new ACLAction(); $query = "SELECT * FROM " . $action->table_name . " WHERE name='{$action_name}' AND category = '{$category}' AND acltype='{$type}' AND deleted=0 "; $result = $db->query($query); //only add if an action with that name and category don't exist $row = $db->fetchByAssoc($result); if ($row == null) { $action->name = $action_name; $action->category = $category; $action->aclaccess = $action_def['default']; $action->acltype = $type; $action->modified_user_id = 1; $action->created_by = 1; $action->save(); } } } else { sugar_die("FAILED TO ADD: {$category} : {$name} - TYPE {$type} NOT DEFINED IN modules/ACLActions/actiondefs.php"); } }
$testmodules = array('Accounts', 'Contacts', 'Users'); foreach ($testmodules as $module) { foreach ($actions as $cur_action) { $action = new ACLAction(); $action->name = $cur_action; $action->category = $module; if (isset($default_owner[$cur_action])) { $action->access = ACL_ALLOW_OWNER; } else { if (isset($default_deny[$cur_action])) { $action->access = ACL_ALLOW_NONE; } else { $action->access = ACL_ALLOW_ALL; } } $action->save(); } } $action_results = ACLAction::getUserActions('will_id', true); echo 'Actions Test no roles for will -access to all modules -owner delete and no import or export<br>'; foreach ($action_results as $category_name => $category) { foreach ($category as $action_name => $action) { _pp($category_name . ':' . $action_name . ':' . acl_translate($action['access'])); } } echo 'Create a role for Peon Users<br>'; $aclrole = new ACLRole(); $aclrole->name = 'Peon User'; $aclrole->description = 'The Peon Role For All Peons'; $aclrole->user_id = 'will_id'; $aclrole->save();