/** * insert or update course data * * @return boolean success */ public function save() { if (empty($this->courseId)) { // Insert $keys = define_course_keys($this->officialCode, '', get_conf('dbNamePrefix')); $courseSysCode = trim($keys['currentCourseId']); $courseDbName = trim($keys['currentCourseDbName']); $courseDirectory = trim($keys['currentCourseRepository']); if (empty($courseSysCode) || empty($courseDbName) || empty($courseDirectory)) { throw new Exception("Error missing data for course {$this->officialCode}"); } if (!$this->useExpirationDate) { $this->expirationDate = 'NULL'; } // Session courses are created without categories links: // so we duplicate the source course's categories links /*if ( !is_null($this->sourceCourseId) && !empty($this->sourceCourseId) ) { $sourceCourse = new claroCourse(); $sourceCourse->load(claroCourse::getCodeFromId($this->sourceCourseId)); $this->categories = $sourceCourse->categories; }*/ if (!is_null($this->sourceCourseId) && !empty($this->sourceCourseId)) { $sourceCourse = new claroCourse(); $sourceCourse->load(claroCourse::getCodeFromId($this->sourceCourseId)); if ($sourceCourse->sourceCourseId) { throw new Exception('You cannot create a course session from another course session'); } } if (prepare_course_repository($courseDirectory, $courseSysCode) && register_course($courseSysCode, $this->officialCode, $this->sourceCourseId, $courseDirectory, $courseDbName, $this->titular, $this->email, $this->categories, $this->title, $this->language, $GLOBALS['_uid'], $this->access, $this->registration, $this->registrationKey, $this->visibility, $this->departmentName, $this->extLinkUrl, $this->publicationDate, $this->expirationDate, $this->status, $this->userLimit) && install_course_database($courseDbName) && install_course_tools($courseDbName, $this->language, $courseDirectory)) { $courseObj = new Claro_Course($courseSysCode); $courseObj->load(); $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($GLOBALS['_uid']), $courseObj, null, null); $courseRegistration->ignoreRegistrationKeyCheck(); $courseRegistration->ignoreCategoryRegistrationCheck(); $courseRegistration->setCourseAdmin(); $courseRegistration->setCourseTutor(); $courseRegistration->forceSuperUser(); if ($courseRegistration->addUser()) { // Set course id $this->courseId = $courseSysCode; // Notify event manager $args['courseSysCode'] = $courseSysCode; $args['courseDbName'] = $courseDbName; $args['courseDirectory'] = $courseDirectory; $args['courseCategory'] = $this->categories; $GLOBALS['eventNotifier']->notifyEvent("course_created", $args); return true; } else { $this->backlog->failure($courseRegistration->getErrorMessage()); return false; } } else { $lastFailure = claro_failure::get_last_failure(); $this->backlog->failure('Error : ' . $lastFailure); return false; } } else { // Update $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_course_properties = $tbl_cdb_names['course_properties']; if (!$this->useExpirationDate) { $this->expirationDate = null; } $sqlExpirationDate = is_null($this->expirationDate) ? 'NULL' : 'FROM_UNIXTIME(' . claro_sql_escape($this->expirationDate) . ')'; $sqlCreationDate = is_null($this->publicationDate) ? 'NULL' : 'FROM_UNIXTIME(' . claro_sql_escape($this->publicationDate) . ')'; $sql = "UPDATE `" . $tbl_course . "`\n SET `intitule` = '" . claro_sql_escape($this->title) . "',\n `titulaires` = '" . claro_sql_escape($this->titular) . "',\n `administrativeNumber` = '" . claro_sql_escape($this->officialCode) . "',\n `language` = '" . claro_sql_escape($this->language) . "',\n `extLinkName` = '" . claro_sql_escape($this->departmentName) . "',\n `extLinkUrl` = '" . claro_sql_escape($this->extLinkUrl) . "',\n `email` = '" . claro_sql_escape($this->email) . "',\n `visibility` = '" . ($this->visibility ? 'visible' : 'invisible') . "',\n `access` = '" . claro_sql_escape($this->access) . "',\n `registration` = '" . claro_sql_escape($this->registration) . "',\n `registrationKey` = '" . claro_sql_escape($this->registrationKey) . "',\n `lastEdit` = NOW(),\n `creationDate` = " . $sqlCreationDate . ",\n `expirationDate` = " . $sqlExpirationDate . ",\n `status` = '" . claro_sql_escape($this->status) . "',\n `userLimit` = '" . (int) $this->userLimit . "'\n WHERE code='" . claro_sql_escape($this->courseId) . "'"; // Handle categories // 1/ Remove all links in database $this->unlinkCategories(); // 2/ Link new categories selection $this->linkCategories($this->categories); // If it's a source course, do the same for all its session courses if ($this->isSourceCourse) { $sql2 = "SELECT cours_id FROM `" . $tbl_course . "`\n WHERE sourceCourseId = " . $this->id; $sessionCourses = claro_sql_query_fetch_all_rows($sql2); foreach ($sessionCourses as $sessionCourse) { unlink_course_categories($sessionCourse['cours_id']); link_course_categories($sessionCourse['cours_id'], $this->categories); } } return claro_sql_query($sql); } }
/** * unsubscribe a specific user from a specific course * * * @param int $user_id user ID from the course_user table * @param mixed (string or array) $courseCodeList course sys code * @param boolean $force true possible to remove a course admin from course * (default false) * @param boolean $deleteTrackingData (default false) * * @return boolean TRUE if unsubscribtion succeed * boolean FALSE otherwise. */ function user_remove_from_course($userId, $courseCodeList = array(), $force = false, $delTrackData = false, $class_id = null) { if (!is_array($courseCodeList)) { $courseCodeList = array($courseCodeList); } if ($class_id) { $claroClass = new Claro_Class(); $claroClass->load($class_id); } else { $claroClass = null; } $allWorksWell = true; foreach ($courseCodeList as $courseCode) { $course = new Claro_Course($courseCode); $course->load(); $userCourseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $course); if ($force) { $userCourseRegistration->forceUnregistrationOfManager(); } if (!is_null($claroClass)) { $userCourseRegistration->setClass($claroClass); } $keepTrackingData = !$delTrackData; if (!$userCourseRegistration->removeUser($keepTrackingData, array())) { Console::warning("Cannot remove user {$userId} from {$courseCode}"); $allWorksWell = false; } } return $allWorksWell; }
$dialogBox->error(get_lang('Unable to remove your registration to the course')); break; } } $displayMode = DISPLAY_MESSAGE_SCREEN; } // end if ($cmd == 'exUnreg') /*---------------------------------------------------------------------------- Subscribe to a course ----------------------------------------------------------------------------*/ if ($cmd == 'exReg') { $registrationKey = isset($_REQUEST['registrationKey']) ? $_REQUEST['registrationKey'] : null; $categoryId = isset($_REQUEST['categoryId']) ? $_REQUEST['categoryId'] : null; $courseObj = new Claro_Course($courseCode); $courseObj->load(); $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $courseObj, $registrationKey, $categoryId); if (!empty($classId)) { $claroClass = new Claro_Class(); $claroClass->load($classId); $courseRegistration->setClass($claroClass); } if ($courseRegistration->addUser()) { $claroline->log('COURSE_SUBSCRIBE', array('user' => $userId, 'course' => $courseCode)); $displayMode = DISPLAY_MESSAGE_SCREEN; if (claro_get_current_user_id() != $uidToEdit) { // Message for admin $dialogBox->success(get_lang('The user has been enroled to the course')); } else { $dialogBox->success(get_lang('You\'ve been enroled on the course')); } $properties = array();
$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')); } } else { // delete user from course user list if (user_remove_from_course($req['user_id'], claro_get_current_course_id(), false, false, null)) { Console::log("{$req['user_id']} removed by user " . claro_get_current_user_id(), 'COURSE_UNSUBSCRIBE'); $dialogBox->success(get_lang('The user has been successfully unregistered from course')); } else {
foreach ($errorMsgList as $errorMsg) { $dialogBox->error($errorMsg); } } } if (!$userId && $validUserData && count($userList) == 0) { $userData['language'] = null; $userId = user_create($userData); if ($userId) { user_send_registration_mail($userId, $userData, claro_get_current_course_id()); } } if ($userId) { $courseObj = new Claro_Course(claro_get_current_course_id()); $courseObj->load(); $courseRegistration = new Claro_CourseUserRegistration(AuthProfileManager::getUserAuthProfile($userId), $courseObj, null, null); 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
/** * Display form to edit or add user to the platform. * * @param $userId int */ function user_html_form($userId = null) { // If the user exists (given user id) if (!empty($userId)) { // Get user's general informations $userData = user_get_properties($userId); // Get user's skype account $userData['skype'] = get_user_property($userId, 'skype'); // Get user's picture $picturePath = user_get_picture_path($userData); if ($picturePath && file_exists($picturePath)) { $pictureUrl = user_get_picture_url($userData); } else { $pictureUrl = ''; } // Get current language $currentLanguage = !empty($userData['language']) ? $userData['language'] : language::current_language(); // A few javascript $htmlHeadXtra[] = '<script type="text/javascript"> function confirmation (name) { if (confirm("' . clean_str_for_javascript(get_lang('Are you sure to delete')) . '"+ name + "?")) {return true;} else {return false;} } $(document).ready(function(){ $("#delete").click(function(){ return confirmation("' . $userData['firstname'] . " " . $userData['lastname'] . '"); }).attr("href","adminuserdeleted.php?uidToEdit=' . $userId . '&cmd=exDelete"); }); </script>'; } else { // Initialize user's data $userData = user_initialise(); // No user's picture $pictureUrl = ''; // Prefered language $currentLanguage = language::current_language(); } // Editable fields if (empty($userId) || claro_is_platform_admin()) { $editableFields = array('name', 'official_code', 'login', 'password', 'email', 'phone', 'language', 'picture', 'skype'); if (claro_is_platform_admin()) { $editableFields[] = 'authSource'; } } else { $editableFields = AuthProfileManager::getUserAuthProfile($userId)->getEditableProfileFields(); // get_conf('profile_editable'); // pushClaroMessage(var_export($editableFields,true), 'debug'); } if (!empty($_SERVER['HTTP_REFERER'])) { $cancelUrl = $_SERVER['HTTP_REFERER']; } else { $cancelUrl = $_SERVER['PHP_SELF']; } // Hack to prevent autocompletion of password fields from browser $htmlHeadXtra[] = '<script type="text/javascript"> $(document).ready( function() { $("#password").val(""); } ); </script>'; $template = new CoreTemplate('user_form.tpl.php'); $template->assign('formAction', $_SERVER['PHP_SELF']); $template->assign('relayContext', claro_form_relay_context()); $template->assign('cancelUrl', claro_htmlspecialchars(Url::Contextualize($cancelUrl))); $template->assign('editableFields', $editableFields); $template->assign('data', $userData); $template->assign('pictureUrl', $pictureUrl); $template->assign('currentLanguage', $currentLanguage); $template->assign('languages', get_language_to_display_list()); return $template->render(); }