Example #1
0
/**
 * 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;
    }
}
Example #2
0
//=================================
$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;