Exemplo n.º 1
0
/**
 * 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.
 * 
 * Helper for Claro_CourseUserRegistration
 *
 * @param int $userId user ID from the course_user table
 * @param string $courseCode course code from the cours table
 * @param boolean $admin
 * @param boolean $tutor
 * @param int $class_id
 * @return boolean TRUE  if it succeeds, FALSE otherwise
 */
function user_add_to_course($userId, $courseCode, $admin = false, $tutor = false, $class_id = null)
{
    $courseObj = new Claro_Course($courseCode);
    $courseObj->load();
    $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $courseObj, null, null);
    if ($admin) {
        $courseRegistration->setCourseAdmin();
    }
    if ($tutor) {
        $courseRegistration->setCourseTutor();
    }
    if ($class_id) {
        $claroClass = new Claro_Class();
        $claroClass->load($class_id);
        $courseRegistration->setClass($claroClass);
    }
    $courseRegistration->ignoreRegistrationKeyCheck();
    if ($courseRegistration->addUser()) {
        return true;
    } else {
        // @todo should throw an exception here
        Console::error("Cannot register user {$userId} in course {$courseCode} [" . $courseRegistration->getStatus() . ":" . $courseRegistration->getErrorMessage() . "]");
        return false;
    }
}
Exemplo n.º 2
0
 public function mergeCourseUsers($uidToRemove, $uidToKeep, $courseId)
 {
     $moduleCourseTbl = get_module_course_tbl(array('wrk_submission'), $courseId);
     $sql = "UPDATE `{$moduleCourseTbl['wrk_submission']}`\n                SET   user_id = " . (int) $uidToKeep . "\n                WHERE user_id = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update wrk_submission from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 3
0
 public function mergeCourseUsers($uidToRemove, $uidToKeep, $courseId)
 {
     $tblList[] = 'lp_module';
     $tblList[] = 'lp_learnPath';
     $tblList[] = 'lp_rel_learnPath_module';
     $tblList[] = 'lp_asset';
     $tblList[] = 'lp_user_module_progress';
     $moduleCourseTbl = get_module_course_tbl($tblList, $courseId);
     // Update lp_user_module_progress
     $sql = "UPDATE `{$moduleCourseTbl['lp_user_module_progress']}`\n                SET   user_id = " . (int) $uidToKeep . "\n                WHERE user_id = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update lp_user_module_progress from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         return false;
     }
     return true;
 }
Exemplo n.º 4
0
 public static function getConfigFile()
 {
     $deprecated_config_file = self::root() . self::DEPRECATED_CONFIG_FILE;
     $credentials_cli_path = self::getCredentialsPath() . 'cli.json';
     if (file_exists($deprecated_config_file)) {
         Console::error("You are using deprecated `.hook-config` file." . PHP_EOL . "Do you want to upgrade it? (y/n)");
         $answer = Console::readline();
         if ($answer == "y") {
             self::createCredentialsDirectory();
             rename($deprecated_config_file, $credentials_cli_path);
         } else {
             static::$temp_config = json_decode(file_get_contents($deprecated_config_file), true);
             return $deprecated_config_file;
         }
     }
     return $credentials_cli_path;
 }
Exemplo n.º 5
0
 public function mergeCourseUsers($uidToRemove, $uidToKeep, $courseId)
 {
     $moduleCourseTbl = get_module_course_tbl(array('wiki_pages', 'wiki_pages_content'), $courseId);
     // Update wiki_pages
     $sql = "UPDATE `{$moduleCourseTbl['wiki_pages']}`\n                SET   owner_id = " . (int) $uidToKeep . "\n                WHERE owner_id = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update wiki_pages from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         return false;
     }
     // Update wiki_pages_content
     $sql = "UPDATE `{$moduleCourseTbl['wiki_pages_content']}`\n                SET   editor_id = " . (int) $uidToKeep . "\n                WHERE editor_id = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update wiki_pages_content from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
 public function authenticate()
 {
     $auth = new Claro_Ldap($this->extAuthOptionList['url'], $this->extAuthOptionList['port'], $this->extAuthOptionList['basedn']);
     try {
         $auth->connect();
         // no anonymous bind
         // user can search
         if ($this->userSelfBindAuth == 'true') {
             $searchdn = "{$this->userAttr}={$this->username}," . $this->extAuthOptionList['basedn'];
             $searchpw = $this->password;
             $auth->bind($searchdn, $searchpw);
         } elseif ($this->useBindDn) {
             $searchdn = $this->extAuthOptionList['binddn'];
             $searchpw = $this->extAuthOptionList['bindpw'];
             $auth->bind($searchdn, $searchpw);
         }
         // search user
         $user = $auth->getUser($this->username, $this->userFilter, $this->userAttr);
         if ($user) {
             if ($this->userSelfBindAuth == 'true') {
                 $binddn = "{$this->userAttr}={$this->username}," . $this->extAuthOptionList['basedn'];
             } else {
                 $binddn = $user->getDn();
             }
             if ($auth->authenticate($binddn, $this->password)) {
                 $this->user = $user;
                 return true;
             } else {
                 return false;
             }
         }
     } catch (Exception $e) {
         $this->setFailureMessage($e->getMessage());
         if (claro_debug_mode()) {
             Console::error($e->__toString());
         } else {
             Console::error($e->getMessage());
         }
         return false;
     }
 }
Exemplo n.º 7
0
 /**
  * Create the admin superuser.
  *
  * @return void
  */
 protected function createUser($options = array())
 {
     try {
         if (!is_null($options) && in_array('first', $options) && in_array('last', $options) && in_array('email', $options) && in_array('password', $options)) {
             User::create(['first_name' => $options['first'], 'last_name' => $options['last'], 'email' => $options['email'], 'password' => $options['password'], 'is_superuser' => true, 'key' => str_random(32)]);
         } else {
             $this->console->info('=====LETS CREATE AN ADMIN SUPERUSER=====');
             $firstName = $this->console->ask('What is the admin\'s first name?');
             $lastName = $this->console->ask('What is the admin\'s last name?');
             $email = $this->console->ask('What is the admin\'s email address?');
             $password = $this->console->secret('Choose a password, and make it strong.');
             User::create(['first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'password' => $password, 'is_superuser' => true, 'key' => str_random(21)]);
             $this->console->info('=====ADMIN SUPERUSER CREATED=====');
             $this->console->info('Nice! You can now login to your application with the superuser email and password.');
         }
     } catch (Exception $e) {
         $this->console->error('Whoops! Something went wrong trying to create your user.');
         $this->console->error('=====EXCEPTION START=====');
         $this->console->error($e);
         $this->console->error('=====EXCEPTION END=====');
     }
 }
Exemplo n.º 8
0
 public function mergeCourseUsers($uidToRemove, $uidToKeep, $courseId)
 {
     $error = false;
     $moduleCourseTbl = get_module_course_tbl(array('bb_posts', 'bb_topics', 'bb_priv_msgs', 'bb_rel_forum_userstonotify', 'bb_rel_topic_userstonotify'), $courseId);
     $userToKeepProp = user_get_properties($uidToKeep);
     $sql = "UPDATE `{$moduleCourseTbl['bb_posts']}`\n                SET     poster_id = " . (int) $uidToKeep . ",\n                        nom = '" . claro_sql_escape($userToKeepProp['lastname']) . "',\n                        prenom = '" . claro_sql_escape($userToKeepProp['firstname']) . "'\n                WHERE poster_id = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update bb_posts from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         $error = true;
         return !$error;
     }
     // Update topic poster, lastname & firstname
     $sql = "UPDATE `{$moduleCourseTbl['bb_topics']}`\n                SET topic_poster = " . (int) $uidToKeep . ",\n                nom = '" . claro_sql_escape($userToKeepProp['lastname']) . "',\n                prenom = '" . claro_sql_escape($userToKeepProp['firstname']) . "'\n                WHERE topic_poster = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         // echo mysql_error();
         Console::error("Cannot update bb_topics from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         $error = true;
         return !$error;
     }
     // Update private messages (from)
     $sql = "UPDATE `{$moduleCourseTbl['bb_priv_msgs']}`\n                SET from_userid = " . (int) $uidToKeep . "\n                WHERE from_userid = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update bb_priv_msgs:recipient from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         $error = true;
         return !$error;
     }
     // Update private messages (to)
     $sql = "UPDATE `{$moduleCourseTbl['bb_priv_msgs']}`\n                SET to_userid = " . (int) $uidToKeep . "\n                WHERE to_userid = " . (int) $uidToRemove;
     if (!claro_sql_query($sql)) {
         Console::error("Cannot update bb_priv_msgs:sender from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
         $error = true;
         return !$error;
     }
     // Update topic notification
     $sql = "SELECT `topic_id`\n                FROM `{$moduleCourseTbl['bb_rel_topic_userstonotify']}`\n                WHERE `user_id` = " . (int) $uidToRemove;
     $topicIds = claro_sql_query_fetch_all($sql);
     if (!empty($topicIds)) {
         foreach ($topicIds as $_topicId) {
             $topicId = $_topicId['topic_id'];
             $sql = "SELECT `notify_id`\n                        FROM `{$moduleCourseTbl['bb_rel_topic_userstonotify']}`\n                        WHERE `user_id` = " . (int) $uidToRemove . " AND `topic_id` = " . (int) $topicId . "\n                        LIMIT 1";
             $notify = claro_sql_query_get_single_row($sql);
             if (!empty($notify)) {
                 // Update notification for userToRemove to userToKeep
                 $sql = "UPDATE `{$moduleCourseTbl['bb_rel_topic_userstonotify']}`\n                            SET user_id = " . (int) $uidToKeep . "\n                            WHERE notify_id = " . (int) $notify['notify_id'];
                 if (!claro_sql_query($sql)) {
                     Console::error("Cannot update bb_rel_topic_userstonotify from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
                     $error = true;
                 }
             }
             // Delete the notification for userToRemove
             $sql = "DELETE FROM `{$moduleCourseTbl['bb_rel_topic_userstonotify']}` WHERE `user_id` = " . (int) $uidToRemove;
             if (!claro_sql_query($sql)) {
                 Console::error("Cannot delete bb_rel_topic_userstonotify from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
                 $error = true;
             }
         }
     }
     // Update forum notification
     $sql = "SELECT `forum_id`\n                FROM `{$moduleCourseTbl['bb_rel_forum_userstonotify']}`\n                WHERE `user_id` = " . (int) $uidToRemove;
     $forumIds = claro_sql_query_fetch_all($sql);
     if (!empty($forumIds)) {
         foreach ($forumIds as $_forumId) {
             $forumId = $_forumId['forum_id'];
             $sql = "SELECT `notify_id`\n                        FROM `{$moduleCourseTbl['bb_rel_forum_userstonotify']}`\n                        WHERE `user_id` = " . (int) $uidToRemove . " AND `forum_id` = " . (int) $forumId . "\n                        LIMIT 1";
             $notify = claro_sql_query_get_single_row($sql);
             if (!empty($notify)) {
                 // Update notification for userToRemove to userToKeep
                 $sql = "UPDATE `{$moduleCourseTbl['bb_rel_forum_userstonotify']}`\n                            SET user_id = " . (int) $uidToKeep . "\n                            WHERE notify_id = " . (int) $notify['notify_id'];
                 if (!claro_sql_query($sql)) {
                     Console::error("Cannot update bb_rel_forum_userstonotify from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
                     $error = true;
                 }
             }
             // Delete the notification for userToRemove
             $sql = "DELETE FROM `{$moduleCourseTbl['bb_rel_form_userstonotify']}` WHERE `user_id` = " . (int) $uidToRemove;
             if (!claro_sql_query($sql)) {
                 Console::error("Cannot delete bb_rel_forum_userstonotify from -{$uidToRemove} to +{$uidToKeep} in {$courseId}");
                 $error = true;
             }
         }
     }
     return !$error;
 }
Exemplo n.º 9
0
            Console::log("Class {$form_data['class_id']} enroled to course " . claro_get_current_course_id() . " by " . claro_get_current_user_id(), 'CLASS_SUBSCRIBE');
            $dialogBox->success(get_lang('Class has been enroled'));
        } else {
            Console::error("Class {$form_data['class_id']} cannot be enroled to course " . claro_get_current_course_id() . " by " . claro_get_current_user_id() . " : " . var_export($registration->getErrorLog(), true));
            $dialogBox->error(get_lang('Cannot enrol class'));
        }
        break;
        // Unenrol a class to the course
    // Unenrol a class to the course
    case 'exUnenrol':
        $registration = unregister_class_to_course($form_data['class_id'], claro_get_current_course_id());
        if (!$registration->hasError()) {
            Console::log("Class {$form_data['class_id']} removed from course " . claro_get_current_course_id() . " by " . claro_get_current_user_id(), 'CLASS_UNSUBSCRIBE');
            $dialogBox->success(get_lang('Class has been unenroled'));
        } else {
            Console::error("Class {$form_data['class_id']} cannot be removed from course " . claro_get_current_course_id() . " by " . claro_get_current_user_id() . " : " . var_export($registration->getErrorLog(), true));
            $dialogBox->error(get_lang('Cannot enrol class'));
        }
        break;
}
/*---------------------------------------------------------------------*/
/*----------------------FIND information SECTION-----------------------*/
/*---------------------------------------------------------------------*/
$classList = get_class_list_by_course(claro_get_current_course_id());
/*---------------------------------------------------------------------*/
/*----------------------DISPLAY SECTION--------------------------------*/
/*---------------------------------------------------------------------*/
// set bredcrump
$nameTools = get_lang('Enrol class');
ClaroBreadCrumbs::getInstance()->prepend(get_lang('Users'), 'user.php' . claro_url_relay_context('?'));
// javascript confirm pop up declaration for header
Exemplo n.º 10
0
        if ($userData['courseAdmin']) {
            $courseRegistration->setCourseAdmin();
        }
        if ($userData['profileId']) {
            $courseRegistration->setUserProfileIdInCourse($userData['profileId']);
        }
        if ($userData['courseTutor']) {
            $courseRegistration->setCourseTutor();
        }
        $courseRegistration->ignoreRegistrationKeyCheck();
        $courseRegistration->ignoreRegistrationKeyCheck();
        if ($courseRegistration->addUser()) {
            $courseRegSucceed = true;
        } else {
            // @todo should throw an exception here
            Console::error("Cannot register user {$userId} in course {$courseCode} [" . $courseRegistration->getStatus() . ":" . $courseRegistration->getErrorMessage() . "]");
            $courseRegSucceed = false;
        }
        Console::log("{$userId} enroled to course " . claro_get_current_course_id() . " by " . claro_get_current_user_id(), 'COURSE_SUBSCRIBE');
    } else {
        $courseRegSucceed = false;
    }
}
// end if $cmd == 'registration'
if ($cmd == 'applySearch') {
    // Search on username, official_code, ...
    $displayResultTable = true;
    if (!(empty($userData['lastname']) && empty($userData['firstname']) && empty($userData['email']) && empty($userData['username']) && empty($userData['officialCode']))) {
        $userList = user_search(array('lastname' => $userData['lastname'], 'firstname' => $userData['firstname'], 'email' => $userData['email'], 'officialCode' => $userData['officialCode'], 'username' => $userData['username']), claro_get_current_course_id(), true, false, !claro_is_platform_admin());
    } else {
        $userList = array();
Exemplo n.º 11
0
/**
 * delete a course of the plateform
 *
 * TODO detect failure with claro_failure
 *
 * @param string $cid
 *
 * @return boolean TRUE        if suceed
 *         boolean FALSE       otherwise.
 */
function delete_course($code, $sourceCourseId)
{
    global $eventNotifier;
    // Declare needed tables
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_course = $tbl_mdb_names['course'];
    $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
    $tbl_course_class = $tbl_mdb_names['rel_course_class'];
    $tbl_rel_course_category = $tbl_mdb_names['rel_course_category'];
    $tbl_rel_course_portlet = $tbl_mdb_names['rel_course_portlet'];
    $this_course = claro_get_course_data($code);
    if (!$this_course) {
        // This is bad !
        throw new Exception("Course not found");
    }
    $currentCourseId = trim($this_course['sysCode']);
    if (empty($currentCourseId)) {
        // This is bad !
        throw new Exception("Missing course id");
    }
    // Delete user registrations into this course
    $sql = 'DELETE FROM `' . $tbl_rel_course_user . '`
            WHERE code_cours="' . $currentCourseId . '"';
    claro_sql_query($sql);
    // Remove any recording in rel_cours_class
    $sql = "DELETE FROM `" . $tbl_course_class . "`\n            WHERE courseId ='" . claro_sql_escape($currentCourseId) . "'";
    claro_sql_query($sql);
    // Remove links between this course and categories
    $sql = "DELETE FROM `" . $tbl_rel_course_category . "`\n            WHERE courseId ='" . $this_course['id'] . "'";
    claro_sql_query($sql);
    // Remove links between this course and portlets
    $sql = "DELETE FROM `" . $tbl_rel_course_portlet . "`\n            WHERE courseId ='" . $this_course['id'] . "'";
    claro_sql_query($sql);
    // Delete the course inside the platform course registery
    $sql = 'DELETE FROM `' . $tbl_course . '`
            WHERE code= "' . claro_sql_escape($currentCourseId) . '"';
    claro_sql_query($sql);
    // Is it a session course ?
    if (!is_null($sourceCourseId)) {
        // Does the source course still have session courses ?
        $sql = "SELECT COUNT(cours_id) AS nbSessionCourses\n                FROM `" . $tbl_course . "`\n                WHERE sourceCourseId = " . (int) $sourceCourseId;
        $result = claro_sql_query_get_single_row($sql);
        if ($result['nbSessionCourses'] == 0) {
            $sql = "UPDATE `" . $tbl_course . "`\n                    SET isSourceCourse = 0\n                    WHERE cours_id = " . (int) $sourceCourseId;
            claro_sql_query($sql);
        }
    }
    // Delete course right
    RightCourseProfileToolRight::resetAllRightProfile($currentCourseId);
    // Delete course module tables
    // FIXME handle errors
    list($success, $log) = delete_all_modules_from_course($currentCourseId);
    // Notify the course deletion event
    $args['cid'] = $this_course['sysCode'];
    $args['tid'] = null;
    $args['rid'] = null;
    $args['gid'] = null;
    $args['uid'] = $GLOBALS['_uid'];
    $eventNotifier->notifyEvent("course_deleted", $args);
    if ($currentCourseId == $code) {
        $currentCourseDbName = trim($this_course['dbName']);
        $currentCourseDbNameGlu = trim($this_course['dbNameGlu']);
        $currentCoursePath = trim($this_course['path']);
        if (empty($currentCourseDbName)) {
            // This is bad !
            throw new Exception("Missing db name");
        }
        if (empty($currentCourseDbNameGlu)) {
            // This is bad !
            throw new Exception("Missing db name glu");
        }
        if (get_conf('singleDbEnabled')) {
            // SEARCH ALL TABLES RELATED TO THE CURRENT COURSE
            claro_sql_query("use " . get_conf('mainDbName'));
            $tbl_to_delete = claro_sql_get_course_tbl(claro_get_course_db_name_glued($currentCourseId));
            foreach ($tbl_to_delete as $tbl_name) {
                $sql = 'DROP TABLE IF EXISTS `' . $tbl_name . '`';
                claro_sql_query($sql);
            }
            // Underscores must be replaced because they are used as wildcards in LIKE sql statement
            $cleanCourseDbNameGlu = str_replace("_", "\\_", $currentCourseDbNameGlu);
            $sql = 'SHOW TABLES LIKE "' . $cleanCourseDbNameGlu . '%"';
            $result = claro_sql_query($sql);
            // DELETE ALL TABLES OF THE CURRENT COURSE
            $tblSurvivor = array();
            while (false !== ($courseTable = mysql_fetch_array($result, MYSQL_NUM))) {
                $tblSurvivor[] = $courseTable[0];
                //$tblSurvivor[$courseTable]='not deleted';
            }
            if (sizeof($tblSurvivor) > 0) {
                Claroline::getInstance()->log('DELETE_COURSE', array_merge(array('DELETED_COURSE_CODE' => $code, 'UNDELETED_TABLE_COUNTER' => sizeof($tblSurvivor)), $tblSurvivor));
            }
        } else {
            $sql = "DROP DATABASE `" . $currentCourseDbName . "`";
            claro_sql_query($sql);
        }
        // MOVE THE COURSE DIRECTORY INTO THE COURSE GARBAGE COLLECTOR
        if (!empty($currentCoursePath)) {
            if (file_exists(get_conf('coursesRepositorySys') . $currentCoursePath . '/')) {
                claro_mkdir(get_conf('garbageRepositorySys'), CLARO_FILE_PERMISSIONS, true);
                rename(get_conf('coursesRepositorySys') . $currentCoursePath . '/', get_conf('garbageRepositorySys', 'garbage') . '/' . $currentCoursePath . '_' . date('YmdHis'));
            } else {
                Console::warning("DELETE_COURSE : Course directory not found {$currentCoursePath} for course {$currentCourseId}");
            }
            Claroline::log('COURSE_DELETED', array('courseCode' => $currentCourseId, 'courseDbName' => $currentCourseDbName, 'courseDbNameGlu' => $currentCourseDbNameGlu, 'coursePath' => $currentCoursePath));
            return true;
        } else {
            Console::error("DELETE_COURSE : Try to delete a course repository with no folder name {$currentCourseId} !");
            return true;
        }
    } else {
        return false;
    }
}
Exemplo n.º 12
0
 protected function isCourseUnregistrationAllowed()
 {
     // Check if course available or option set to allow unregistration from unavailable course
     if (get_conf('crslist_UserCanUnregFromInactiveCourses', false)) {
         $isUserAllowedToUnenrol = true;
     } else {
         $curdate = claro_time();
         if (!in_array($this->course->status, array('enable', 'date'))) {
             $isUserAllowedToUnenrol = false;
             $this->status = self::STATUS_UNREGISTRATION_NOTAVAILABLE;
             $this->errorMessage = get_lang('This course currently does not allow to unenrol (status: %status)', array('%status' => $this->course->status));
         } elseif ($this->course->status == 'date' && !empty($this->course->publicationDate) && $this->course->publicationDate >= $curdate) {
             $isUserAllowedToUnenrol = false;
             $this->status = self::STATUS_UNREGISTRATION_NOTAVAILABLE;
             $this->errorMessage = get_lang('This course will be enabled on the %date', array('%date' => claro_date('d/m/Y', $this->course->publicationDate)));
         } elseif ($this->course->status == 'date' && !empty($this->course->expirationDate) && $this->course->expirationDate <= $curdate) {
             $isUserAllowedToUnenrol = false;
             $this->status = self::STATUS_UNREGISTRATION_NOTAVAILABLE;
             $this->errorMessage = get_lang('This course has been deactivated on the %date', array('%date' => claro_date('d/m/Y', $this->course->expirationDate)));
         } elseif ($this->course->status == 'date' && (empty($this->course->expirationDate) && empty($this->course->publicationDate))) {
             $isUserAllowedToUnenrol = false;
             $this->status = self::STATUS_SYSTEM_ERROR;
             $this->errorMessage = get_lang('This course is not available');
             Console::error("Invalid publication and expiration date for course " . $this->course->courseId);
         } else {
             $isUserAllowedToUnenrol = true;
         }
     }
     return $isUserAllowedToUnenrol;
 }
Exemplo n.º 13
0
 // (notice : it does not delete user from claroline main DB)
 if ('allStudent' == $req['user_id']) {
     // TODO : add a function to unenroll all users from a course
     $course = new Claro_Course(claro_get_current_course_id());
     $course->load();
     $claroCourseRegistration = new Claro_BatchCourseRegistration($course);
     $claroCourseRegistration->removeAllUsers($req['keepClasses']);
     $result = $claroCourseRegistration->getResult();
     if (!$result->hasError() || !$result->checkStatus(Claro_BatchRegistrationResult::STATUS_ERROR_DELETE_FAIL)) {
         $unregisterdUserCount = count($result->getDeletedUserList());
         if ($unregisterdUserCount) {
             Console::log("{$req['user_id']} ({$unregisterdUserCount}) removed by user " . claro_get_current_user_id(), 'COURSE_UNSUBSCRIBE');
         }
         $dialogBox->info(get_lang('%number student(s) unregistered from this course', array('%number' => $unregisterdUserCount)));
     } else {
         Console::error("Error while deleting all users from course " . claro_get_current_course_id() . " : " . var_export($result->getErrorLog(), true));
         $dialogBox->error(get_lang('An error occured') . ' : <ul><li>' . implode('</li><li>', $result->getErrorLog()) . '</li></ul>');
     }
 } elseif (0 < (int) $req['user_id']) {
     if ($forceUnenrolment) {
         $course = new Claro_Course(claro_get_current_course_id());
         $course->load();
         $userCourseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($req['user_id']), $course);
         if (claro_is_platform_admin()) {
             $userCourseRegistration->forceUnregistrationOfManager();
         }
         if (!$userCourseRegistration->forceRemoveUser(false, array())) {
             $dialogBox->error(get_lang('The user cannot be removed from the course'));
         } else {
             Console::log("{$req['user_id']} removed [forced] by admin " . claro_get_current_user_id(), 'COURSE_UNSUBSCRIBE');
             $dialogBox->success(get_lang('The user has been successfully unregistered from course'));
Exemplo n.º 14
0
 protected static function loadDriver($driverConfigPath)
 {
     if (!file_exists($driverConfigPath)) {
         if (claro_debug_mode()) {
             throw new Exception("Driver configuration {$driverConfigPath} not found");
         }
         Console::error("Driver configuration {$driverConfigPath} not found");
         return;
     }
     $driverConfig = array();
     include $driverConfigPath;
     if ($driverConfig['driver']['enabled'] == true) {
         $driverClass = $driverConfig['driver']['class'];
         // search for kernel drivers
         if (class_exists($driverClass)) {
             $driver = new $driverClass();
             $driver->setDriverOptions($driverConfig);
             self::$drivers[$driverConfig['driver']['authSourceName']] = $driver;
         } else {
             // load dynamic drivers
             if (!file_exists(get_path('rootSys') . 'platform/conf/extauth/drivers')) {
                 FromKernel::uses('fileManage.lib');
                 claro_mkdir(get_path('rootSys') . 'platform/conf/extauth/drivers', CLARO_FILE_PERMISSIONS, true);
             }
             $driverPath = get_path('rootSys') . 'platform/conf/extauth/drivers/' . strtolower($driverClass) . '.drv.php';
             if (file_exists($driverPath)) {
                 require_once $driverPath;
                 if (class_exists($driverClass)) {
                     $driver = new $driverClass();
                     $driver->setDriverOptions($driverConfig);
                     self::$drivers[$driverConfig['driver']['authSourceName']] = $driver;
                 } else {
                     if (claro_debug_mode()) {
                         throw new Exception("Driver class {$driverClass} not found");
                     }
                     Console::error("Driver class {$driverClass} not found");
                 }
             } else {
                 if (claro_debug_mode()) {
                     throw new Exception("Driver class {$driverClass} not found");
                 }
                 Console::error("Driver class {$driverClass} not found");
             }
         }
     }
     if (isset($driverConfig['driver']['lostPasswordAllowed']) && $driverConfig['driver']['lostPasswordAllowed'] == true) {
         self::$driversAllowingLostPassword[$driverConfig['driver']['authSourceName']] = $driverConfig['driver']['authSourceName'];
     }
 }
Exemplo n.º 15
0
 /**
  * Update the fields of the page
  * @access private
  * @param string sql SQL query
  * @return boolean true on success, false on failure
  */
 private function _updatePageFields($sql)
 {
     try {
         $res = $this->con->query($sql);
         if ($res->numRows()) {
             $page = $res->fetch();
             $this->_setPageId($page['id']);
             $this->setOwnerId($page['owner_id']);
             $this->setTitle($this->stripSlashesForWiki($page['title']));
             $this->_setLastVersionId($page['last_version']);
             $this->_setCurrentVersionId($page['last_version']);
             $this->setCreationTime($page['ctime']);
             $this->setLastEditTime($page['last_mtime']);
             $this->setEditorId($page['editor_id']);
             $this->setContent($this->stripSlashesForWiki($page['content']));
             $this->currentVersionId = isset($page['current_version']) ? $page['current_version'] : $page['last_version'];
             $this->currentVersionMtime = isset($page['current_mtime']) ? $page['current_mtime'] : $page['last_mtime'];
             return $this;
         } else {
             return null;
         }
     } catch (Exception $e) {
         $this->setError(PAGE_CANNOT_BE_UPDATED_ERROR . ' : ' . $e->getMessage(), PAGE_CANNOT_BE_UPDATED_ERRNO);
         Console::error("CLWIKI : " . PAGE_CANNOT_BE_UPDATED_ERROR . ' : ' . $e->getMessage(), PAGE_CANNOT_BE_UPDATED_ERRNO);
     }
 }
Exemplo n.º 16
0
 /**
  * 
  * @param Iterator $userList
  * @param string $overwriteAuthSourceWith change the auth source for existing users with the given one, set to null if you want to keep the original auth source (default:null)
  * @param bool $emptyPasswordForOverWrittenAuthSource empty (i.e. set to string value 'empty') users for which the auth source is changed
  * @return boolean false if empty list given
  */
 public function registerUserList($userList, $overwriteAuthSourceWith = null, $emptyPasswordForOverWrittenAuthSource = false)
 {
     if (!count($userList)) {
         return false;
     }
     foreach ($userList as $user) {
         try {
             $userFound = $this->getUserIfAlreadyExists($user);
             if (false !== $userFound) {
                 if ($userFound['email'] == $user->email) {
                     if ($overwriteAuthSourceWith && $userFound['authSource'] !== $overwriteAuthSourceWith) {
                         if ($emptyPasswordForOverWrittenAuthSource) {
                             $emptyPassword = "******";
                         } else {
                             $emptyPassword = '';
                         }
                         $this->database->exec("\n                            UPDATE\n                                `{$this->tables['user']}`\n                            SET\n                                `authSource` = " . $this->database->quote($overwriteAuthSourceWith) . "\n                                {$emptyPassword}\n                            WHERE\n                                user_id = " . Claroline::getDatabase()->escape($userFound['user_id']));
                         $this->userConvertedList[$userFound['username']] = $userFound['user_id'];
                         Console::info("Change authSource to {$overwriteAuthSourceWith} for user " . var_export($userFound, true));
                     } else {
                         // user already there, nothing to be done
                         $this->userAlreadyThere[$userFound['username']] = $userFound['user_id'];
                     }
                     $this->userSuccessList[$userFound['username']] = $userFound['user_id'];
                 } else {
                     if ($userFound['authSource'] !== $overwriteAuthSourceWith) {
                         // disable old account by changing the username
                         $this->database->exec("\n                            UPDATE\n                                `{$this->tables['user']}`\n                            SET\n                                `authSource` = 'disabled',\n                                `username` = CONCAT('*EPC*', username )\n                            WHERE\n                                user_id = " . Claroline::getDatabase()->escape($userFound['user_id']));
                         $this->userDisabledList[$userFound['username']] = $userFound['user_id'];
                         Console::info("Disable account for user " . var_export($userFound, true) . " : conflict with ldap account " . var_export($user, true));
                         $this->insertUserAsNew($user);
                     } else {
                         // this is the same user and we trust the authentication source over the user list data
                         Console::info('User already there with same authsource but different email : trust authsource [' . var_export($userFound, true) . ']');
                         $this->userAlreadyThere[$userFound['username']] = $userFound['user_id'];
                         $this->userSuccessList[$userFound['username']] = $userFound['user_id'];
                     }
                 }
             } else {
                 $this->insertUserAsNew($user);
             }
         } catch (Exception $e) {
             $this->userFailureList[] = $user;
             Console::error("Cannot add user {$user->username} : EXCEPTION '{$e->getMessage()}' with stack {$e->getTraceAsString()}");
         }
     }
     Console::info("Add user to platform from EPC : converted=" . count($this->userConvertedList) . " disabled=" . count($this->userDisabledList) . " inserted=" . count($this->userInsertedList) . " alreadythere=" . count($this->userAlreadyThere) . " failed=" . count($this->userFailureList));
     if (count($this->userInsertedList)) {
         Console::info("Add user to platform from EPC : userid created " . implode(',', $this->userInsertedList));
     }
     return true;
 }
Exemplo n.º 17
0
 protected function mergeModuleUsers($uidToRemove, $uidToKeep)
 {
     $courseModuleList = get_module_label_list();
     foreach ($courseModuleList as $courseModule) {
         $moduleMergeUserPath = get_module_path($courseModule['label']) . '/connector/mergeuser.cnr.php';
         if (file_exists($moduleMergeUserPath)) {
             require_once $moduleMergeUserPath;
             $moduleMergeClass = $courseModule['label'] . '_MergeUser';
             if (class_exists($moduleMergeClass)) {
                 $moduleMerge = new $moduleMergeClass();
                 if (method_exists($moduleMerge, 'mergeUsers')) {
                     try {
                         if (!$moduleMerge->mergeUsers($uidToRemove, $uidToKeep)) {
                             $this->hasError = true;
                         }
                     } catch (Exception $e) {
                         Console::error($e->getMessage());
                         $this->hasError = true;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 18
0
    if ($login && $password) {
        // reinitalize all session variables
        session_unset();
        $claro_loginRequested = true;
        try {
            $currentUser = AuthManager::authenticate($login, $password);
            if ($currentUser) {
                $_uid = (int) $currentUser->userId;
                $uidReset = true;
                $claro_loginSucceeded = true;
            } else {
                $_uid = null;
                $claro_loginSucceeded = false;
            }
        } catch (Exception $e) {
            Console::error("Cannot authenticate user : " . $e->__toString());
            $_uid = null;
            $claro_loginSucceeded = false;
        }
    } else {
        $claro_loginRequested = false;
    }
}
/*---------------------------------------------------------------------------
  User initialisation
 ---------------------------------------------------------------------------*/
if (!empty($_uid)) {
    try {
        /*if (!$currentUser)
          {
              $currentUser = Claro_CurrentUser::getInstance($_uid);
Exemplo n.º 19
0
/**
 * Check if the authentication fassword for the given user
 *
 * @author Frederic Minne <*****@*****.**>
 *
 * @param string $password
 * @param string $login
 * @return boolean
 *
 */
function user_check_authentication($password, $login)
{
    try {
        if (false !== AuthManager::authenticate($login, $password)) {
            return true;
        } else {
            return false;
        }
    } catch (Exception $e) {
        Console::error("Cannot authentified user : " . $e->__toString());
        return false;
    }
}