Beispiel #1
0
  Course / user relation initialisation
 ---------------------------------------------------------------------------*/
if ($uidReset || $cidReset) {
    if ($_uid && $_cid) {
        $_course_user_properties = claro_get_course_user_properties($_cid, $_uid, true);
        // would probably be less and less used because
        // claro_get_course_user_data($_cid,$_uid)
        // and claro_get_current_course_user_data() do the same job
        $_profileId = $_course_user_properties['privilege']['_profileId'];
        $is_courseMember = $_course_user_properties['privilege']['is_courseMember'];
        $is_courseTutor = $_course_user_properties['privilege']['is_courseTutor'];
        $is_courseAdmin = $_course_user_properties['privilege']['is_courseAdmin'];
        $_courseUser = claro_get_course_user_data($_cid, $_uid);
    } else {
        // course
        $_profileId = claro_get_profile_id('anonymous');
        $is_courseMember = false;
        $is_courseAdmin = false;
        $is_courseTutor = false;
        $_courseUser = null;
        // not used
    }
    $is_courseAllowed = (bool) ($_course['visibility'] && ($_course['access'] == 'public' || $_course['access'] == 'platform' && claro_is_user_authenticated()) || $is_courseMember || $is_platformAdmin);
    // here because it's a right and not a state
} else {
    $_profileId = !empty($_SESSION['_profileId']) ? $_SESSION['_profileId'] : false;
    $is_courseMember = !empty($_SESSION['is_courseMember']) ? $_SESSION['is_courseMember'] : false;
    $is_courseAdmin = !empty($_SESSION['is_courseAdmin']) ? $_SESSION['is_courseAdmin'] : false;
    $is_courseAllowed = !empty($_SESSION['is_courseAllowed']) ? $_SESSION['is_courseAllowed'] : false;
    $is_courseTutor = !empty($_SESSION['is_courseTutor']) ? $_SESSION['is_courseTutor'] : false;
    // not used !?!
Beispiel #2
0
/**
 * Fetch data and privileges of the given user in the given course
 *
 * U don't have enough of this function
 * use claro_get_course_user_data($cid,$uid,$ignoreCache=false)
 *  or claro_get_course_user_privilege($cid,$uid,$ignoreCache=false)
 *
 * @param string $cid course id
 * @param integer $uid user id
 * @param bool $ignoreCache true to for read in database instead of cache
 * @return array(data( array('role')), 'privilege'(array('_profileId','is_courseMember','is_courseTutor','is_courseAdmin')))
 * @see claro_get_course_user_data($cid,$uid,$ignoreCache=false)
 * @see claro_get_course_user_privilege($cid,$uid,$ignoreCache=false)
 * @author Christophe Gesche <*****@*****.**>
 */
function claro_get_course_user_properties($cid, $uid, $ignoreCache = false)
{
    $admin = claro_is_platform_admin();
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
    static $course_user_cache = null;
    static $course_user_data = null;
    static $course_user_privilege = array();
    if ($course_user_cache != array('uid' => $uid, 'cid' => $cid) || $ignoreCache) {
        $sql = "SELECT profile_id AS profileId,\n                       isCourseManager,\n                       isPending,\n                       tutor,\n                       role\n                FROM `" . $tbl_rel_course_user . "` `cours_user`\n                WHERE `user_id`  = '" . (int) $uid . "'\n                AND `code_cours` = '" . claro_sql_escape($cid) . "'";
        $cuData = claro_sql_query_get_single_row($sql);
        if (!empty($cuData)) {
            $course_user_data['role'] = $cuData['role'];
            // not used
            $course_user_privilege['_profileId'] = $cuData['profileId'];
            $course_user_privilege['is_coursePending'] = (bool) $cuData['isPending'];
            $course_user_privilege['is_courseMember'] = (bool) ($cuData['isPending'] == 0);
            $course_user_privilege['is_courseTutor'] = (bool) ($cuData['tutor'] == 1);
            $course_user_privilege['is_courseAdmin'] = (bool) ($cuData['isCourseManager'] == 1);
        } else {
            $course_user_privilege['_profileId'] = claro_get_profile_id('guest');
            $course_user_privilege['is_coursePending'] = false;
            $course_user_privilege['is_courseMember'] = false;
            $course_user_privilege['is_courseAdmin'] = false;
            $course_user_privilege['is_courseTutor'] = false;
            $course_user_data = null;
            // not used
        }
        $course_user_privilege['is_courseAdmin'] = (bool) ($course_user_privilege['is_courseAdmin'] || claro_is_platform_admin());
        $course_user_cache = array('uid' => $uid, 'cid' => $cid);
    }
    return array('data' => $course_user_data, 'privilege' => $course_user_privilege);
}
Beispiel #3
0
 /**
  * Get the list of user ids filtered
  * @param array $profileList list of profile labels
  * @param string $registeredBefore date yyyy-mm-dd hh:mm:ss
  * @param string $registeredAfter date yyyy-mm-dd hh:mm:ss
  * @return array of id => id
  */
 public function getFilteredUserIdList($profileList = array(), $registeredBefore = null, $registeredAfter = null)
 {
     $sqlCourseCode = $this->database->quote($this->course->courseId);
     $sqlDateFilterArray = array();
     if ($registeredAfter) {
         $sqlDateFilterArray[] = "`registration_date` >= " . $this->database->quote($registeredAfter);
     }
     if ($registeredBefore) {
         $sqlDateFilterArray[] = "`registration_date` <= " . $this->database->quote($registeredBefore);
     }
     if (count($sqlDateFilterArray) == 2) {
         $sqlDateFilter = "\n                AND\n                    (" . implode(' OR ', $sqlDateFilterArray) . ")\n            ";
     } elseif (count($sqlDateFilterArray) == 1) {
         $sqlDateFilter = "\n                AND\n                    {$sqlDateFilterArray[0]}\n            ";
     } else {
         $sqlDateFilter = "";
     }
     if (count($profileList)) {
         foreach ($profileList as $key => $value) {
             $profileList[$key] = claro_get_profile_id($value);
         }
         // profileId not in profileToKeep
         $sqlProfilesToDelete = "\n                AND \n                    `profile_id` IN (" . implode(',', $profileList) . ")\n            ";
     } else {
         $sqlProfilesToDelete = "";
     }
     $userList = $this->database->query("\n            SELECT\n                `user_id` AS `id`\n            FROM\n                `{$this->tables['rel_course_user']}`\n            WHERE\n                `code_cours` = {$sqlCourseCode}\n            {$sqlProfilesToDelete}\n            {$sqlDateFilter}\n\n        ");
     $userIdList = array();
     foreach ($userList as $user) {
         $userIdList[$user['id']] = $user['id'];
     }
     return $userIdList;
 }
Beispiel #4
0
/**
 * change the status of the user in a course
 * @author Hugues Peeters <*****@*****.**>
 *
 * @param $userId       integer user ID from the course_user table
 * @param $courseId     string course code from the cours table
 * @param $propertyList array should contain 'role', 'profileId', 'isCOurseManager', 'tutor'
 *
 * @return boolean TRUE if update succeed, FALSE otherwise.
 */
function user_set_course_properties($userId, $courseId, $propertyList)
{
    $tbl = claro_sql_get_main_tbl();
    $setList = array();
    if (array_key_exists('isCourseManager', $propertyList)) {
        if ($propertyList['isCourseManager']) {
            $propertyList['profileId'] = claro_get_profile_id('manager');
        }
    }
    if (array_key_exists('profileId', $propertyList)) {
        $setList[] = "profile_id = '" . (int) $propertyList['profileId'] . "'";
        if ($propertyList['profileId'] == claro_get_profile_id('manager')) {
            $propertyList['isCourseManager'] = 1;
        } else {
            $propertyList['isCourseManager'] = 0;
        }
    }
    if (array_key_exists('isCourseManager', $propertyList)) {
        if ($propertyList['isCourseManager']) {
            $setList[] = 'isCourseManager = 1';
        } else {
            $setList[] = 'isCourseManager = 0';
        }
    }
    if (array_key_exists('tutor', $propertyList)) {
        if ($propertyList['tutor']) {
            $setList[] = 'tutor = 1';
        } else {
            $setList[] = 'tutor = 0';
        }
    }
    if (array_key_exists('role', $propertyList)) {
        $setList[] = "role = '" . claro_sql_escape($propertyList['role']) . "'";
    }
    if (count($setList) > 0) {
        $sql = "UPDATE `" . $tbl['rel_course_user'] . "`\n                SET " . implode(', ', $setList) . "\n                WHERE   `user_id`    = " . (int) $userId . "\n                AND     `code_cours` = '" . claro_sql_escape($courseId) . "'";
        if (claro_sql_query_affected_rows($sql) > 0) {
            return true;
        } else {
            return false;
        }
    }
    return false;
}
Beispiel #5
0
/**
 * To create a record in the course table of main database.  Also handles
 * the categories links creation.
 *
 * @param string    $courseSysCode
 * @param string    $courseScreenCode
 * @param int       $sourceCourseId
 * @param string    $courseRepository
 * @param string    $courseDbName
 * @param string    $titular
 * @param string    $email
 * @param array     $categories
 * @param string    $intitule
 * @param string    $languageCourse
 * @param string    $uidCreator
 * @param bool      $visibility
 * @param string    $registration ('open', 'close' or 'validation')
 * @param string    $registrationKey
 * @return bool     success;
 * @author Christophe Gesche <*****@*****.**>
 */
function register_course($courseSysCode, $courseScreenCode, $sourceCourseId, $courseRepository, $courseDbName, $titular, $email, $categories, $intitule, $languageCourse = '', $uidCreator, $access, $registration, $registrationKey = '', $visibility = true, $extLinkName = '', $extLinkUrl = '', $publicationDate, $expirationDate, $status, $userLimit)
{
    global $versionDb, $clarolineVersion;
    $tblList = claro_sql_get_main_tbl();
    $tbl_course = $tblList['course'];
    $tbl_category = $tblList['category'];
    $tbl_rel_course_category = $tblList['rel_course_category'];
    // Needed parameters
    if ($courseSysCode == '') {
        return claro_failure::set_failure('courseSysCode is missing');
    }
    if ($courseScreenCode == '') {
        return claro_failure::set_failure('courseScreenCode is missing');
    }
    if ($courseDbName == '') {
        return claro_failure::set_failure('courseDbName is missing');
    }
    if ($courseRepository == '') {
        return claro_failure::set_failure('course Repository is missing');
    }
    if ($uidCreator == '') {
        return claro_failure::set_failure('uidCreator is missing');
    }
    if (!in_array($registration, array('open', 'close', 'validation'))) {
        return claro_failure::set_failure('wrong registration value');
    }
    // Optionnal settings
    $languageCourse = !empty($languageCourse) ? $languageCourse : 'english';
    $sourceCourseId = !is_null($sourceCourseId) && !empty($sourceCourseId) ? claro_sql_escape($sourceCourseId) : "NULL";
    $currentVersionFilePath = get_conf('rootSys') . 'platform/currentVersion.inc.php';
    file_exists($currentVersionFilePath) && (require $currentVersionFilePath);
    $defaultProfileId = claro_get_profile_id('user');
    // Insert course
    $sql = "INSERT INTO `" . $tbl_course . "` SET\n            code                 = '" . claro_sql_escape($courseSysCode) . "',\n            sourceCourseId       = " . $sourceCourseId . ",\n            dbName               = '" . claro_sql_escape($courseDbName) . "',\n            directory            = '" . claro_sql_escape($courseRepository) . "',\n            language             = '" . claro_sql_escape($languageCourse) . "',\n            intitule             = '" . claro_sql_escape($intitule) . "',\n            visibility           = '" . ($visibility ? 'VISIBLE' : 'INVISIBLE') . "',\n            access               = '" . claro_sql_escape($access) . "',\n            registration         = '" . claro_sql_escape($registration) . "',\n            registrationKey      = '" . claro_sql_escape($registrationKey) . "',\n            diskQuota            = NULL,\n            creationDate         = FROM_UNIXTIME(" . claro_sql_escape($publicationDate) . "),\n            expirationDate       = FROM_UNIXTIME(" . claro_sql_escape($expirationDate) . "),\n            status               = '" . claro_sql_escape($status) . "',\n            userLimit            = '" . (int) $userLimit . "',\n            versionDb            = '" . claro_sql_escape($versionDb) . "',\n            versionClaro         = '" . claro_sql_escape($clarolineVersion) . "',\n            lastEdit             = NOW(),\n            lastVisit            = NULL,\n            titulaires           = '" . claro_sql_escape($titular) . "',\n            email                = '" . claro_sql_escape($email) . "',\n            administrativeNumber = '" . claro_sql_escape($courseScreenCode) . "',\n            extLinkName          = '" . claro_sql_escape($extLinkName) . "',\n            extLinkUrl           = '" . claro_sql_escape($extLinkUrl) . "',\n            defaultProfileId     = " . $defaultProfileId;
    if (claro_sql_query($sql) == false) {
        return false;
    }
    $courseId = mysql_insert_id();
    // Insert categories
    if (link_course_categories($courseId, $categories) === false) {
        return false;
    }
    // Did we insert a session couse ?
    if (!is_null($sourceCourseId)) {
        // If yes, flag its source course
        $sql = "UPDATE `" . $tbl_course . "`\n                SET isSourceCourse = 1\n                WHERE cours_id = {$sourceCourseId}";
        if (claro_sql_query($sql) == false) {
            return false;
        }
    }
    return true;
}
Beispiel #6
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;
    }
}
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;
}
Beispiel #8
0
 public function load()
 {
     $this->_profileId = claro_get_profile_id('anonymous');
     $this->is_coursePending = false;
     $this->is_courseMember = false;
     $this->is_courseTutor = false;
     $this->is_courseAdmin = false;
 }
 /**
  * Subscribe a specific user to a specific course.  If this course is a session
  * course, the user will also be subscribed to the source course.
  * @return boolean TRUE  if it succeeds, FALSE otherwise
  */
 public function addUser()
 {
     if (!$this->isRegistrationAllowed()) {
         return false;
     }
     $userId = $this->userAuthProfile->getUserId();
     $courseCode = $this->course->courseId;
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_user = $tbl_mdb_names['user'];
     $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
     if (Claroline::getDatabase()->query("\n            SELECT\n                user_id\n            FROM\n                `{$tbl_user}`\n            WHERE\n                user_id = " . Claroline::getDatabase()->escape($userId))->numRows() == 0) {
         $this->status = self::STATUS_SYSTEM_ERROR;
         $this->errorMessage = get_lang('User not found');
         return false;
     } else {
         // Previously check if the user isn't already subscribed to the course
         $courseUserListResultSet = Claroline::getDatabase()->query("\n                SELECT\n                    count_user_enrol, count_class_enrol\n                FROM\n                    `{$tbl_rel_course_user}`\n                WHERE\n                    user_id = " . Claroline::getDatabase()->escape($userId) . "\n                AND\n                    code_cours = " . Claroline::getDatabase()->quote($courseCode));
         if ($courseUserListResultSet->numRows() > 0) {
             $course_user_list = $courseUserListResultSet->fetch(Mysql_ResultSet::FETCH_OBJECT);
             $count_user_enrol = (int) $course_user_list->count_user_enrol;
             $count_class_enrol = (int) $course_user_list->count_class_enrol;
             // Increment the count of registration by the user or class
             if (!$this->registerByClass) {
                 $count_user_enrol = 1;
             } else {
                 $count_class_enrol++;
             }
             if (!Claroline::getDatabase()->exec("\n                    UPDATE\n                        `{$tbl_rel_course_user}`\n                    SET\n                        `count_user_enrol` = " . $count_user_enrol . ",\n                        `count_class_enrol` = " . $count_class_enrol . "\n                    WHERE\n                        user_id = " . Claroline::getDatabase()->escape($userId) . "\n                    AND\n                        code_cours = " . Claroline::getDatabase()->quote($courseCode))) {
                 $this->status = self::STATUS_SYSTEM_ERROR;
                 $this->errorMessage = get_lang('Cannot register user in course');
                 return false;
             } else {
                 return true;
             }
         } else {
             // First registration to the course
             $count_user_enrol = 0;
             $count_class_enrol = 0;
             // If a validation is requested for this course: isPending is true
             // If the current user is course manager: isPending is false
             $isPending = !$this->admin && $this->isValidationRequired() ? true : false;
             if (!$this->registerByClass) {
                 $count_user_enrol = 1;
             } else {
                 $count_class_enrol = 1;
             }
             if ($this->admin) {
                 $profileId = claro_get_profile_id('manager');
             } elseif ($this->profileId) {
                 $profileId = $this->profileId;
             } else {
                 $profileId = claro_get_profile_id($this->getCourseProfile());
             }
             // if this course is a session course, enrol to the source course
             if ($this->course->sourceCourseId) {
                 $sourceCourseCode = $this->course->getSourceCourseCode();
                 // only enrol the user to the source course only if he is not already there
                 $sourceCourseUserListResultSet = Claroline::getDatabase()->query("\n                        SELECT\n                            count_user_enrol, count_class_enrol\n                        FROM\n                            `{$tbl_rel_course_user}`\n                        WHERE\n                            user_id = " . Claroline::getDatabase()->escape($userId) . "\n                        AND\n                            code_cours = " . Claroline::getDatabase()->quote($sourceCourseCode));
                 if ($sourceCourseUserListResultSet->numRows() == 0) {
                     if (!Claroline::getDatabase()->exec("INSERT INTO `" . $tbl_rel_course_user . "`\n                                SET code_cours      = " . Claroline::getDatabase()->quote($sourceCourseCode) . ",\n                                    user_id         = " . (int) $userId . ",\n                                    profile_id      = " . (int) $profileId . ",\n                                    isCourseManager = " . (int) ($this->admin ? 1 : 0) . ",\n                                    isPending       = " . (int) ($isPending ? 1 : 0) . ",\n                                    tutor           = " . (int) ($this->tutor ? 1 : 0) . ",\n                                    count_user_enrol = " . $count_user_enrol . ",\n                                    count_class_enrol = " . $count_class_enrol . ",\n                                    enrollment_date = NOW()")) {
                         $this->status = self::STATUS_SYSTEM_ERROR;
                         $this->errorMessage = get_lang('Cannot register user in source course');
                         return false;
                     }
                 }
             }
             // register user to new session course
             if (!Claroline::getDatabase()->exec("INSERT INTO `" . $tbl_rel_course_user . "`\n                        SET code_cours      = " . Claroline::getDatabase()->quote($courseCode) . ",\n                            user_id         = " . (int) $userId . ",\n                            profile_id      = " . (int) $profileId . ",\n                            isCourseManager = " . (int) ($this->admin ? 1 : 0) . ",\n                            isPending       = " . (int) ($isPending ? 1 : 0) . ",\n                            tutor           = " . (int) ($this->tutor ? 1 : 0) . ",\n                            count_user_enrol = " . $count_user_enrol . ",\n                            count_class_enrol = " . $count_class_enrol . ",\n                            enrollment_date = NOW()")) {
                 $this->status = self::STATUS_SYSTEM_ERROR;
                 $this->errorMessage = get_lang('Cannot register user in source course');
                 return false;
             } else {
                 return true;
             }
         }
     }
     // end else user register in the platform
 }
Beispiel #10
0
/**
 * Upgrade right (from main database) to 1.8
 * @return step value, 0 if succeed
 */
function upgrade_main_database_right_to_18()
{
    include_once $GLOBALS['includePath'] . '/lib/right/right_profile.lib.php';
    include_once $GLOBALS['includePath'] . '/../install/init_profile_right.lib.php';
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tool = 'RIGHT_18';
    switch ($step = get_upgrade_status($tool)) {
        case 1:
            // add right tables
            $sqlForUpdate[] = " CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_profile'] . "` (\n               `profile_id` int(11) NOT NULL auto_increment,\n               `type` enum('COURSE','PLATFORM') NOT NULL default 'COURSE',\n               `name` varchar(255) NOT NULL default '',\n               `label` varchar(50) NOT NULL default '',\n               `description` varchar(255) default '',\n               `courseManager` tinyint(4) default '0',\n               `mailingList` tinyint(4) default '0',\n               `userlistPublic` tinyint(4) default '0',\n               `groupTutor` tinyint(4) default '0',\n               `locked` tinyint(4) default '0',\n               `required` tinyint(4) default '0',\n               PRIMARY KEY  (`profile_id`),\n               KEY `type` (`type`)\n            )ENGINE=MyISAM ";
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_action'] . "` (\n               `id` int(11) NOT NULL auto_increment,\n               `name` varchar(255) NOT NULL default '',\n               `description` varchar(255) default '',\n               `tool_id` int(11) default NULL,\n               `rank` int(11) default '0',\n               `type` enum('COURSE','PLATFORM') NOT NULL default 'COURSE',\n               PRIMARY KEY  (`id`),\n               KEY `tool_id` (`tool_id`),\n               KEY `type` (`type`)\n             )ENGINE=MyISAM ";
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_rel_profile_action'] . "` (\n               `profile_id` int(11) NOT NULL,\n               `action_id` int(11) NOT NULL,\n               `courseId`  varchar(40) NOT NULL default '',\n               `value` tinyint(4) default '0',\n               PRIMARY KEY  (`profile_id`,`action_id`,`courseId`)\n             ) ENGINE=MyISAM ";
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
            unset($sqlForUpdate);
        case 2:
            create_required_profile();
            $step = set_upgrade_status($tool, $step + 1);
        case 3:
            // Init action/right
            $sql = " SELECT id\n                     FROM `" . $tbl_mdb_names['tool'] . "`";
            $result = claro_sql_query_fetch_all_cols($sql);
            $toolIdList = $result['id'];
            foreach ($toolIdList as $toolId) {
                // Manage right - Add read action
                $action = new RightToolAction();
                $action->setName('read');
                $action->setToolId($toolId);
                $action->save();
                // Manage right - Add edit action
                $action = new RightToolAction();
                $action->setName('edit');
                $action->setToolId($toolId);
                $action->save();
            }
            $step = set_upgrade_status($tool, $step + 1);
        case 4:
            init_default_right_profile();
            $step = set_upgrade_status($tool, $step + 1);
        case 5:
            // set profile_id in rel course_user
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['rel_course_user'] . "` SET `profile_id` = " . claro_get_profile_id(USER_PROFILE) . "\n                               WHERE `isCourseManager` = 0";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['rel_course_user'] . "` SET `profile_id` = " . claro_get_profile_id(MANAGER_PROFILE) . "\n                               WHERE `isCourseManager` = 1";
            // set default profile_id in course
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
            unset($sqlForUpdate);
        default:
            $step = set_upgrade_status($tool, 0);
            return $step;
    }
    return false;
}