Example #1
0
/**
 * Get course/profile right
 *
 * @param integer $profileId profile identifier
 * @param integer $courseId course identifier
 * @return array ['tool_id']['action_name'] value
 */
function claro_get_course_profile_right($profileId = null, $courseId = null)
{
    $courseProfileRightList = null;
    static $cachedProfileId = null;
    static $cachedCourseId = null;
    static $cachedCourseProfileRightList = null;
    // load courseId
    if (is_null($courseId)) {
        if (claro_is_in_a_course()) {
            $courseId = claro_get_current_course_id();
        } else {
            return false;
        }
    }
    // load profile id
    if (is_null($profileId)) {
        if (!empty($GLOBALS['_profileId'])) {
            $profileId = $GLOBALS['_profileId'];
        } else {
            return false;
        }
    }
    if (!empty($cachedCourseProfileRightList) && $cachedProfileId == $profileId && $cachedCourseId == $courseId) {
        $courseProfileRightList = $cachedCourseProfileRightList;
    }
    if (empty($courseProfileRightList)) {
        $profile = new RightProfile();
        if ($profile->load($profileId)) {
            $courseProfileToolRight = new RightCourseProfileToolRight();
            $courseProfileToolRight->setCourseId($courseId);
            $courseProfileToolRight->load($profile);
            $courseProfileRightList = $courseProfileToolRight->getToolActionList();
            // cache for the next time ...
            $cachedProfileId = $profileId;
            $cachedCourseId = $courseId;
            $cachedCourseProfileRightList = $courseProfileRightList;
        } else {
            return false;
        }
    }
    return $courseProfileRightList;
}
Example #2
0
    $profileNameList = claro_get_all_profile_name_list();
    $display_profile_list = array_keys($profileNameList);
    $display_profile_url_param = 'all';
}
//=================================
// Display section
//=================================
// define bredcrumb
ClaroBreadCrumbs::getInstance()->prepend(get_lang('Course profile list'), 'profile_list.php');
$out = '';
// Set display right
$profileRightHtml = new RightProfileToolRightHtml();
$profileRightHtml->addUrlParam('display_profile', $display_profile_url_param);
$profileFoundCount = 0;
foreach ($display_profile_list as $profileId) {
    $profile = new RightProfile();
    if ($profile->load($profileId)) {
        $profileRight = new RightCourseProfileToolRight();
        $profileRight->setCourseId(claro_get_current_course_id());
        $profileRight->load($profile);
        $profileRightHtml->addRightProfileToolRight($profileRight);
        $profileFoundCount++;
    }
}
if ($profileFoundCount == 0) {
    $dialogBox->error(get_lang('Profile not found'));
    $out .= $dialogBox->render();
} else {
    if ($profileFoundCount == 1) {
        // display tool title
        $out .= claro_html_tool_title(array('mainTitle' => get_lang('Manage Right'), 'subTitle' => $profile->getName()));
Example #3
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;
}
Example #4
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 #5
0
if (!claro_is_user_authenticated()) {
    claro_disp_auth_form();
}
if (!claro_is_platform_admin()) {
    claro_die(get_lang('Not allowed'));
}
$error_list = array();
define('DISPLAY_LIST', __LINE__);
define('DISPLAY_FORM', __LINE__);
$display = DISPLAY_LIST;
// Main script
$cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : null;
$profile_id = isset($_REQUEST['profile_id']) ? (int) $_REQUEST['profile_id'] : null;
$dialogBox = new DialogBox();
if ($cmd) {
    $profile = new RightProfile();
    if (!empty($profile_id)) {
        // load profile
        if (!$profile->load($profile_id)) {
            $cmd = '';
            $profile_id = null;
            $display = DISPLAY_LIST;
        }
    }
    if ($cmd == 'exSave') {
        if ($profile->validateForm()) {
            $profile->save();
        } else {
            // get error message
            $message = '';
            if (!empty($profile_id)) {