function init_default_right_profile() { require_once get_conf('includePath') . '/lib/right/profileToolRight.class.php'; $tbl_mdb_names = claro_sql_get_tbl(array('course_tool', 'right_profile', 'right_rel_profile_action', 'right_action')); $sql = " SELECT `id` as `toolId`\n FROM `" . $tbl_mdb_names['course_tool'] . "`"; $result = claro_sql_query_fetch_all_cols($sql); $toolList = $result['toolId']; /** * Initialise anonymous profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(ANONYMOUS_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'user'); $profileAction->save(); /** * Initialise guest profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(GUEST_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'user'); $profileAction->save(); /** * Initialise user profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(USER_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'user'); $profileAction->save(); /** * Initialise manager profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(MANAGER_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'manager'); $profileAction->save(); return true; }
/** * Store all unique info about a tool during install * @param integer $moduleId * @param array $moduleToolData, data from manifest * @return int tool id or false */ function register_module_tool($moduleId, $module_info) { $tbl = claro_sql_get_tbl('course_tool'); if (is_array($module_info)) { $icon = array_key_exists('ICON', $module_info) ? "'" . claro_sql_escape($module_info['ICON']) . "'" : 'NULL'; if (!isset($module_info['ENTRY'])) { $module_info['ENTRY'] = 'entry.php'; } // find max rank in the course_tool table $sql = "SELECT MAX(def_rank) AS maxrank FROM `" . $tbl['course_tool'] . "`"; $maxresult = claro_sql_query_get_single_row($sql); // insert the new course tool $sql = "INSERT INTO `" . $tbl['course_tool'] . "`\n SET\n claro_label = '" . claro_sql_escape($module_info['LABEL']) . "',\n script_url = '" . claro_sql_escape($module_info['ENTRY']) . "',\n icon = " . $icon . ",\n def_access = 'ALL',\n def_rank = (" . (int) $maxresult['maxrank'] . "+1),\n add_in_course = 'AUTOMATIC',\n access_manager = 'COURSE_ADMIN' "; $tool_id = claro_sql_query_insert_id($sql); // Init action/right // Manage right - Add read action $action = new RightToolAction(); $action->setName('read'); $action->setToolId($tool_id); $action->save(); // Manage right - Add edit action $action = new RightToolAction(); $action->setName('edit'); $action->setToolId($tool_id); $action->save(); // Init all profile/right $profileList = array_keys(claro_get_all_profile_name_list()); foreach ($profileList as $profileId) { $profile = new RightProfile(); $profile->load($profileId); $profileRight = new RightProfileToolRight(); $profileRight->load($profile); if (claro_get_profile_id('manager') == $profileId) { $profileRight->setToolRight($tool_id, 'manager'); } else { $profileRight->setToolRight($tool_id, 'user'); } $profileRight->save(); } return $tool_id; } else { return false; } }
$profile_id = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : null; $tool_id = isset($_REQUEST['tool_id']) ? $_REQUEST['tool_id'] : null; $right_value = isset($_REQUEST['right_value']) ? $_REQUEST['right_value'] : null; $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : null; $display_profile = isset($_REQUEST['display_profile']) ? $_REQUEST['display_profile'] : null; if (!empty($profile_id)) { // load profile $profile = new RightProfile(); if ($profile->load($profile_id)) { // load profile tool right $profileRight = new RightProfileToolRight(); $profileRight->load($profile); // update tool right if ($cmd == 'set_right' && !empty($tool_id)) { $profileRight->setToolRight($tool_id, $right_value); $profileRight->save(); } } else { $profile_id = null; } } //--------------------------------- // Build list of profile to display //--------------------------------- $display_profile_list = array(); $display_profile_url_param = null; if (!empty($display_profile)) { if (is_numeric($display_profile)) { $display_profile_list[] = $display_profile; $display_profile_url_param = $display_profile; }