Beispiel #1
0
 public static function setForUser($_uid)
 {
     $tbl = claro_sql_get_main_tbl();
     $ssoCookieExpireTime = time() + get_conf('ssoCookiePeriodValidity', 3600);
     $ssoCookieValue = md5(time() . rand(100, 1000000));
     $sql = "UPDATE `{$tbl['sso']}`\n" . "SET cookie    = '" . $ssoCookieValue . "',\n" . "rec_time  = NOW()\n" . "WHERE user_id = " . (int) $_uid;
     $affectedRowCount = claro_sql_query_affected_rows($sql);
     if ($affectedRowCount < 1) {
         $sql = "INSERT INTO `{$tbl['sso']}`\n" . "SET cookie = '" . $ssoCookieValue . "',\n" . "rec_time = NOW(),\n" . "user_id = " . (int) $_uid;
         claro_sql_query($sql);
     }
     return setcookie(get_conf('ssoCookieName', 'clarolineSsoCookie'), $ssoCookieValue, $ssoCookieExpireTime, get_conf('ssoCookiePath', '/'), get_conf('ssoCookieDomain', 'sso.claroline.net'));
     // Note. $ssoCookieName, $ssoCookieValussoCookieExpireTime,
     //       $soCookiePath and $ssoCookieDomain are coming from
     //       claroline/inc/conf/auth.conf.php
 }
Beispiel #2
0
/**
 * records the cookie value of specific user during authentication
 *
 * @author Hugues Peeters <*****@*****.**>
 * @param int    $userId
 * @param string $cookie
 */
function record_sso_cookie($userId, $ssoCookie)
{
    $mainTblList = claro_sql_get_main_tbl();
    $tbl_sso = $mainTblList['sso'];
    $sql = "UPDATE `" . $tbl_sso . "`\n            SET cookie    = '" . $ssoCookie . "',\n                rec_time  = NOW()\n            WHERE user_id = " . (int) $userId;
    $affectedRowCount = claro_sql_query_affected_rows($sql);
    if ($affectedRowCount < 1) {
        $sql = "INSERT INTO `" . $tbl_sso . "`\n                SET cookie    = '" . $ssoCookie . "',\n                    rec_time  = NOW(),\n                    user_id   = " . (int) $userId;
        claro_sql_query($sql);
    }
}
Beispiel #3
0
/**
 * Update an local tool data
 *
 * @author Hugues Peeters <*****@*****.**>
 * @param int $toolId tool to update
 * @param string $name new name
 * @param string $url new url
 * @return bool true if it suceeds, false otherwise
 */
function set_local_course_tool($toolId, $name, $url)
{
    $tbl_cdb_names = claro_sql_get_course_tbl();
    $tbl_course_tool_list = $tbl_cdb_names['tool'];
    // check for "http://", if the user forgot "http://" or "ftp://" or ...
    // the link will not be correct
    if (!preg_match('/:\\/\\//', $url)) {
        // add "http://" as default protocol for url
        $url = "http://" . $url;
    }
    if ((int) $toolId != 0) {
        $sql = "UPDATE `" . $tbl_course_tool_list . "`\n                SET script_name = '" . claro_sql_escape($name) . "',\n                    script_url  = '" . claro_sql_escape($url) . "'\n                WHERE id        = " . (int) $toolId . "\n                AND   tool_id IS NULL";
        if (claro_sql_query_affected_rows($sql) > 0) {
            return true;
        }
    }
    return false;
}
Beispiel #4
0
/**
 * function delete_groups($groupIdList = 'ALL')
 * deletes groups and their datas.
 *
 * @param  mixed   $groupIdList - group(s) to delete. It can be a single id
 *                                (int) or a list of id (array). If no id is
 *                                given all the course group are deleted
 *
 * @return integer : number of groups deleted.
 * @throws claro_failure
 */
function delete_groups($groupIdList = 'ALL')
{
    global $eventNotifier;
    $tbl_c_names = claro_sql_get_course_tbl();
    $tbl_groups = $tbl_c_names['group_team'];
    $tbl_groupsUsers = $tbl_c_names['group_rel_team_user'];
    $tbl_courseCalendar = $tbl_c_names['calendar_event'];
    require_once get_module_path('CLWIKI') . '/lib/lib.createwiki.php';
    require_once dirname(__FILE__) . '/forum.lib.php';
    if (is_tool_activated_in_course(get_tool_id_from_module_label('CLWIKI'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLWIKI')) {
        delete_group_wikis($groupIdList);
    }
    if (is_tool_activated_in_course(get_tool_id_from_module_label('CLFRM'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLFRM')) {
        delete_group_forums($groupIdList);
    }
    /**
     * Check the data and notify eventmanager of the deletion
     */
    if (strtoupper($groupIdList) == 'ALL') {
        $sql_condition = '';
    } elseif (is_array($groupIdList)) {
        foreach ($groupIdList as $thisGroupId) {
            if (!is_int($thisGroupId)) {
                return false;
            }
        }
        $sql_condition = 'WHERE id IN (' . implode(' , ', $groupIdList) . ')';
    } else {
        if (settype($groupIdList, 'integer')) {
            $sql_condition = '  WHERE id = ' . (int) $groupIdList;
            $eventNotifier->notifyCourseEvent('group_deleted', claro_get_current_course_id(), claro_get_current_tool_id(), '0', $groupIdList, '0');
        } else {
            // TODO : perhaps a trigger erro is better
            return claro_failure::set_failure('CANT_SET_ID_GROUP_AS_INTEGER ' . __LINE__);
        }
    }
    /*
     * Search the groups data necessary to delete them
     */
    $sql_searchGroup = "SELECT `id` AS `id`,\n                               `secretDirectory` AS `directory`\n                        FROM `" . $tbl_groups . "`" . $sql_condition;
    $groupList = claro_sql_query_fetch_all_cols($sql_searchGroup);
    //notify event manager about the deletion for each group
    foreach ($groupList['id'] as $thisGroupId) {
        $eventNotifier->notifyCourseEvent('group_deleted', claro_get_current_course_id(), claro_get_current_tool_id(), '0', $thisGroupId, '0');
    }
    if (count($groupList['id']) > 0) {
        /*
         * Remove users, group(s) and group forum(s) from the course tables
         */
        $sql_deleteGroup = "DELETE FROM `" . $tbl_groups . "`\n                                   WHERE id IN (" . implode(' , ', $groupList['id']) . ")\n                                    # " . __FUNCTION__ . "\n                                    # " . __FILE__ . "\n                                    # " . __LINE__;
        $sql_cleanOutGroupUsers = "DELETE FROM `" . $tbl_groupsUsers . "`\n                                   WHERE team IN (" . implode(' , ', $groupList['id']) . ")\n                                    # " . __FUNCTION__ . "\n                                    # " . __FILE__ . "\n                                    # " . __LINE__;
        $sql_cleanOutGroupEvent = "DELETE FROM `" . $tbl_courseCalendar . "`\n                                    WHERE group_id IN (" . implode(' , ', $groupList['id']) . ")\n                                    # " . __FUNCTION__ . "\n                                    # " . __FILE__ . "\n                                    # " . __LINE__;
        // Deleting group record in table
        $deletedGroupNumber = claro_sql_query_affected_rows($sql_deleteGroup);
        // Delete all members of deleted group(s)
        claro_sql_query($sql_cleanOutGroupUsers);
        // Delete all calendar events for deleted group(s)
        claro_sql_query($sql_cleanOutGroupEvent);
        /**
         * Archive and delete the group files
         */
        // define repository for deleted element
        $groupGarbage = $GLOBALS['garbageRepositorySys'] . '/' . $GLOBALS['currentCourseRepository'] . '/group/';
        if (!file_exists($groupGarbage)) {
            claro_mkdir($groupGarbage, CLARO_FILE_PERMISSIONS, true);
        }
        foreach ($groupList['directory'] as $thisDirectory) {
            if (file_exists($GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/' . $thisDirectory)) {
                rename($GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/' . $thisDirectory, $groupGarbage . $thisDirectory);
            }
        }
        return $deletedGroupNumber;
    } else {
        return FALSE;
    }
}
Beispiel #5
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 #6
0
function claro_set_uid_recipient_of_request_admin($user_id, $state = true)
{
    $tbl = claro_sql_get_main_tbl();
    $sql = "REPLACE INTO `" . $tbl['user_property'] . "`\n            SET userId = " . (int) $user_id . ",\n                propertyId = 'adminContactForRequest',\n                propertyValue = " . (int) $state . ",\n                scope = 'contacts'\n              ";
    $result = claro_sql_query_affected_rows($sql);
    return $result;
}