Exemplo n.º 1
0
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;
}
Exemplo n.º 2
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;
    }
}
Exemplo n.º 3
0
/**
 * Get information about a module
 * @param string $claroLabel module label
 * @param string $dataName
 * @param boolean $ignoreCache
 * @return mixed
 */
function get_module_data($claroLabel, $dataName = null, $ignoreCache = false)
{
    static $cachedModuleDataList = null;
    if (is_null($cachedModuleDataList)) {
        $cachedModuleDataList = array();
    }
    if ($ignoreCache || !array_key_exists($claroLabel, $cachedModuleDataList)) {
        $tbl = claro_sql_get_tbl(array('module', 'course_tool'));
        $sql = "SELECT M.`label`      AS label,\n                   M.`id`             AS id,\n                   M.`name`           AS moduleName,\n                   M.`activation`     AS activation,\n                   M.`type`           AS type,\n                   M.`script_url`     AS entry,\n                   CT.`icon`          AS icon,\n                   CT.`def_rank`      AS rank,\n                   CT.`add_in_course` AS add_in_course,\n                   CT.`access_manager` AS access_manager\n\n        FROM `" . $tbl['module'] . "` AS M\n        LEFT JOIN `" . $tbl['course_tool'] . "` AS CT\n            ON CT.`claro_label`= M.label\n        WHERE  M.`label` = '" . claro_sql_escape($claroLabel) . "'";
        $cachedModuleDataList[$claroLabel] = claro_sql_query_get_single_row($sql);
    }
    if (!is_null($dataName)) {
        return $cachedModuleDataList[$claroLabel][$dataName];
    } else {
        return $cachedModuleDataList[$claroLabel];
    }
}
Exemplo n.º 4
0
/**
 * Set or redefine an extended data for users.
 *
 * @param integer $propertyId
 * @param string $contextScope
 * @return claro_sql result
 */
function delete_userInfoExtraDefinition($propertyId, $contextScope)
{
    $tbl = claro_sql_get_tbl('property_definition');
    $sql = "DELETE FROM `" . $tbl['property_definition'] . "`\n            WHERE propertyId = '" . claro_sql_escape($propertyId) . "'\n            AND  contextScope = '" . claro_sql_escape($contextScope) . "'";
    return claro_sql_query($sql);
}