function createThumbnail($srcFile, $thumbHeight, $thumbWidth) { $srcPath = $this->documentRootDir . '/' . $srcFile; if (!function_exists('gd_info')) { return $srcPath; } $type = img_get_extension($srcFile); if (!file_exists($this->thumbnailDirectory)) { claro_mkdir($this->thumbnailDirectory, CLARO_FILE_PERMISSIONS, true); } if (!img_is_type_supported($type)) { return false; } switch ($type) { case 'png': $image = @imagecreatefrompng($srcPath); break; case 'jpg': case 'jpeg': $image = @imagecreatefromjpeg($srcPath); break; case 'gif': $image = @imagecreatefromgif($srcPath); break; case 'bmp': $image = @imagecreatefromwbmp($srcPath); break; default: return false; } // image loading failed use srcPath instead if (!$image) { Console::warning("Failed to create GD image from {$srcPath}"); return $srcPath; } $oldWidth = imageSX($image); $oldHeight = imageSY($image); $thumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $oldWidth, $oldHeight); $thumbName = md5($srcFile) . '_' . $thumbWidth . 'x' . $thumbHeight . '.jpg'; $thumbPath = $this->thumbnailDirectory . '/' . $thumbName; imagejpeg($thumbnail, $thumbPath); imagedestroy($image); imagedestroy($thumbnail); return $thumbPath; }
/** * Run the garbage collector */ public function run() { if (is_dir($this->path)) { // control that path is not in a system folder if (strpos($this->path, get_path('coursesRepositorySys')) !== false) { Console::warning("GC directory {$this->path} located in platform course folder : ABORT!"); return; } if (strpos($this->path, get_path('clarolineRepositorySys')) !== false) { Console::warning("GC directory {$this->path} located in platform main folder : ABORT!"); return; } if (strpos($this->path, get_path('rootSys') . '/web') !== false) { Console::warning("GC directory {$this->path} located in platform web folder : ABORT!"); return; } if (strpos($this->path, get_path('rootSys') . '/module') !== false) { Console::warning("GC directory {$this->path} located in platform modules dir : ABORT!"); return; } Console::debug('GC Called in ' . $this->path); // Delete archive files older than one hour $directoryIterator = new RecursiveDirectoryIterator($this->path); //$directoryIterator->setFlags(FilesystemIterator::SKIP_DOTS); $tempDirectoryFiles = new RecursiveIteratorIterator($directoryIterator); foreach ($tempDirectoryFiles as $tempDirectoryFile) { if ($tempDirectoryFile->isReadable() && $tempDirectoryFile->isWritable()) { if ($tempDirectoryFile->getMTime() < $this->expire) { if (!$tempDirectoryFile->isDir()) { Console::debug('Unlink ' . $tempDirectoryFile->getPathName() . " mtime: " . $tempDirectoryFile->getMTime() . "; expire: " . $this->expire); @unlink($tempDirectoryFile->getPathName()); } elseif ($tempDirectoryFile->isDir() && $this->isEmpty($tempDirectoryFile->getPathName())) { Console::debug('Rmdir ' . $tempDirectoryFile->getPathName() . " mtime: " . $tempDirectoryFile->getMTime() . "; expire: " . $this->expire); @rmdir($tempDirectoryFile->getPathName()); } } } } } else { Console::warning("GC directory {$this->path} is not a folder folder : ABORT!"); } }
/** * 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; } }
/** * Remove a list of users given their user id from the cours * @param array $userIdList list of user ids to add * @param Claro_Class $class execute class unregistration instead of individual registration if given (default:null) * @param bool $keepTrackingData tracking data will be deleted if set to false (default:true, i.e. keep data) * @param array $moduleDataToPurge list of module_label => (purgeTracking => bool, purgeData => bool) * @param bool $unregisterFromSourceIfLastSession remove users that are in no other session course from the source course if any * @return boolean */ public function removeUserIdListFromCourse($userIdList, $class = null, $keepTrackingData = true, $moduleDataToPurge = array(), $unregisterFromSourceIfLastSession = true) { if (!count($userIdList)) { return false; } $classMode = is_null($class) ? false : true; $courseCode = $this->course->courseId; $sqlCourseCode = $this->database->quote($courseCode); if ($classMode && !$class->isRegisteredToCourse($courseCode)) { $this->result->addError(get_lang("Class not registered to course")); $this->result->setStatus(Claro_BatchRegistrationResult::STATUS_ERROR_NOTHING_TO_DO); return false; } // update user registration counts $cntToChange = $classMode ? 'count_class_enrol' : 'count_user_enrol'; $this->database->exec("\n UPDATE\n `{$this->tableNames['rel_course_user']}`\n SET\n `{$cntToChange}` = `{$cntToChange}` - 1\n WHERE\n `code_cours` = {$sqlCourseCode}\n AND\n `{$cntToChange}` > 0\n AND\n `user_id` IN (" . implode(',', $userIdList) . ")\n "); // get the user ids to remove $userListToRemove = $this->database->query("\n SELECT \n `user_id`\n FROM\n `{$this->tableNames['rel_course_user']}`\n WHERE\n `count_class_enrol` <= 0\n AND\n `count_user_enrol` <= 0\n AND\n `code_cours` = {$sqlCourseCode}\n "); if ($userListToRemove->numRows()) { $userIdListToRemove = array(); foreach ($userListToRemove as $user) { $userIdListToRemove[] = $user['user_id']; } $sqlList = array(); $sqlList[] = "DELETE FROM `{$this->tableNames['bb_rel_topic_userstonotify']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ")"; $sqlList[] = "DELETE FROM `{$this->tableNames['userinfo_content']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ")"; $sqlList[] = "UPDATE `{$this->tableNames['group_team']}` SET `tutor` = NULL WHERE `tutor` IN (" . implode(',', $userIdListToRemove) . ")"; $sqlList[] = "DELETE FROM `{$this->tableNames['group_rel_team_user']}` WHERE user IN (" . implode(',', $userIdListToRemove) . ")"; if (!$keepTrackingData) { $sqlList[] = "DELETE FROM `{$this->tableNames['tracking_event']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ")"; } $sqlList[] = "DELETE FROM `{$this->tableNames['rel_course_user']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ") AND `code_cours` = {$sqlCourseCode}"; foreach ($sqlList as $sql) { $this->database->exec($sql); } if (!empty($moduleDataToPurge)) { foreach ($moduleDataToPurge as $moduleData) { $connectorPath = get_module_path($moduleData['label']) . '/connector/adminuser.cnr.php'; if (file_exists($connectorPath)) { require_once $connectorPath; $connectorClass = $moduleData['label'] . '_AdminUser'; if (class_exist($connectorClass)) { $connector = new $connectorClass($this->database); if ($moduleData['purgeTracking']) { $connector->purgeUserListCourseTrackingData($userIdListToRemove, $this->course->courseId); } if ($moduleData['purgeResources']) { $connector->purgeUserListCourseResources($userIdListToRemove, $this->course->courseId); } } else { Console::warning("Class {$connectorClass} not found"); } } else { Console::warning("No user delete connector found for module {$moduleData['label']}"); } } } $this->result->addDeleted($userIdListToRemove); if ($this->course->isSourceCourse()) { $sessionCourseIterator = $this->course->getChildren(); foreach ($sessionCourseIterator as $sessionCourse) { $batchReg = new self($sessionCourse, $this->database); $batchReg->removeUserIdListFromCourse($userIdListToRemove, $class, $keepTrackingData, $moduleDataToPurge, $unregisterFromSourceIfLastSession); $this->result->mergeResult($batchReg->getResult()); } } if ($this->course->hasSourceCourse() && $unregisterFromSourceIfLastSession) { $sourceCourse = $this->course->getSourceCourse(); $sessionCourseIterator = $sourceCourse->getChildren(); $foundSessionWithClass = false; if ($classMode) { foreach ($sessionCourseIterator as $sessionCourse) { if ($sessionCourse->courseId != $this->course->courseId && $class->isRegisteredToCourse($sessionCourse->courseId)) { $foundSessionWithClass = true; } } if (!$foundSessionWithClass) { $batchReg = new self($sourceCourse, $this->database); $batchReg->removeUserIdListFromCourse($userIdListToRemove, $class, $keepTrackingData, $moduleDataToPurge, $unregisterFromSourceIfLastSession); } } else { // get userids registered in other sessions than the current one $sessionList = $sourceCourse->getChildrenList(); if (count($sessionList)) { $userIdListToRemoveFromSource = array(); $sessionIdList = array_keys($sessionList); $sqlCourseCode = $this->database->quote($this->course->courseId); $usersInOtherSessions = $this->database->query("\n SELECT\n user_id\n FROM\n `{$this->tableNames['rel_course_user']}`\n WHERE\n user_id IN (" . implode(',', $userIdListToRemove) . ")\n AND\n code_cours IN ('" . implode("','", $sessionIdList) . "')\n AND\n code_cours != {$sqlCourseCode}\n "); // loop on $userIdList and keep only those who are not in another session and inject them in $userIdListToRemoveFromSource $usersInOtherSessionsList = array(); foreach ($usersInOtherSessions as $userNotToRemove) { $usersInOtherSessionsList[$userNotToRemove['user_id']] = $userNotToRemove['user_id']; } foreach ($userListToRemove as $userIdToRemove) { if (!isset($usersInOtherSessionsList[$userIdToRemove['user_id']])) { $userIdListToRemoveFromSource[] = $userIdToRemove['user_id']; } } if (count($userIdListToRemoveFromSource)) { $batchReg = new self($sourceCourse, $this->database); $batchReg->removeUserIdListFromCourse($userIdListToRemoveFromSource, $class, $keepTrackingData, $moduleDataToPurge, $unregisterFromSourceIfLastSession); $this->result->mergeResult($batchReg->getResult()); } } } } } else { $this->result->setStatus(Claro_BatchRegistrationResult::STATUS_ERROR_NOTHING_TO_DO); $this->result->addError(get_lang("No user to delete")); } return !$this->result->hasError(); }
if (is_array($moduleList)) { foreach ($moduleList as $moduleId => $moduleLabel) { $portletPath = get_module_path($moduleLabel) . '/connector/desktop.cnr.php'; if (file_exists($portletPath)) { require_once $portletPath; $className = "{$moduleLabel}_Portlet"; // Load portlet from database $portletInDB = $portletList->loadPortlet($className); // If it's not in DB, add it if (!$portletInDB) { if (class_exists($className)) { $portlet = new $className($portletInDB['label']); if ($portlet->getLabel()) { $portletList->addPortlet($portlet->getLabel(), $portlet->getName()); } else { Console::warning("Portlet {$className} has no label !"); } } } load_module_config($moduleLabel); Language::load_module_translation($moduleLabel); } } } } catch (Exception $e) { $dialogBox->error(get_lang('Cannot load portlets')); pushClaroMessage($e->__toString()); } // Generate Output from Portlet $outPortlet = ''; $portletList = $portletList->loadAll(true);
/** * Indexes all the directories and subdirectories * contented in a given directory * * @param dirPath (string) - directory path of the one to index * @param mode (string) - ALL, FILE, DIR : specify what will be listed * @return an array containing the path of all the subdirectories */ function index_dir($dirPath, $mode = 'ALL') { $files = array(); if (is_dir($dirPath)) { $fh = opendir($dirPath); while (($fileName = readdir($fh)) !== false) { // loop through the files, skipping . and .., and recursing if necessary if ($fileName == '.' || $fileName == '..' || $fileName == 'CVS') { continue; } $filePath = $dirPath . '/' . $fileName; if (is_dir($filePath)) { if ($mode != 'FILE') { array_push($files, $filePath); } // mode == DIR or ALL : store dirname $files = array_merge($files, index_dir($filePath, $mode)); } elseif ($mode != 'DIR') { // mode == FILE or ALL : store filename array_push($files, $filePath); } } closedir($fh); } else { // false if the function was called with an invalid non-directory argument Console::warning($dirPath . 'not a dir'); $files = false; } return $files; }
/** * Get the authentication profile for the given user id * @param int $userId * @return AuthProfile */ public static function getUserAuthProfile($userId) { if ($userId != claro_get_current_user_id()) { $user = new Claro_User($userId); $user->loadFromDatabase(); } else { $user = Claro_CurrentUser::getInstance(); } $authSource = $user->authSource; if (!$authSource) { throw new Exception("Cannot find user authentication source for user {$userId}"); } try { $profileOptions = AuthDriverManager::getDriver($authSource)->getAuthProfileOptions(); } catch (Exception $e) { if (claro_is_platform_admin() || claro_is_in_a_course() && claro_is_course_manager() && $userId != claro_get_current_user_id()) { Console::warning("Cannot find user authentication source for user {$userId}, use claroline default options instead"); $profileOptions = AuthDriverManager::getDriver('claroline')->getAuthProfileOptions(); } else { throw $e; } } $authProfile = new AuthProfile($userId, $authSource); $authProfile->setAuthDriverOptions($profileOptions); if (claro_debug_mode()) { pushClaroMessage(var_export($profileOptions, true), 'debug'); } return $authProfile; }
/** * 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; }