public function export() { $postsList = $this->loadTopic($this->getTopicId()); $topicInfo = get_topic_settings($this->getTopicId()); $this->createPDF($topicInfo['topic_title']); $this->pdf->AddPage(); $htmlContent = '<p>' . "\n" . '<table cellspacing="0" cellpadding="2" border="1">' . "\n" . '<tbody>' . "\n" . '<tr>' . "\n" . '<th colspan="2" style="font-weight: bold; background-color: #EDF1E3; color: #669933; border-bottom: 1px solid #96BB7A;">' . claro_utf8_encode($topicInfo['topic_title']) . '</th>' . '</tr>' . "\n"; foreach ($postsList as $post) { $htmlContent .= '<tr>' . "\n" . '<td style="width: 150px; background-color: #EEEEEE;">' . "\n" . '<div style="font-weight: bold;">' . claro_utf8_encode($post['firstname'] . ' ' . $post['lastname'], get_conf('charset')) . '</div>' . "\n" . '<small>' . claro_html_localised_date(get_locale('dateTimeFormatLong'), datetime_to_timestamp($post['post_time'])) . '</small>' . "\n" . '</td>' . "\n" . '<td style="width: 354px;">' . claro_utf8_encode(claro_parse_user_text(strip_tags($post['post_text'])), get_conf('charset')) . '</td>' . "\n" . '</tr>' . "\n"; } $htmlContent .= '</tbody>' . "\n" . '</table>' . "\n" . '</p>'; //exit( claro_utf8_decode($htmlContent) ); $this->pdf->writeHTML($htmlContent, true, 0, true, 0); switch ($this->output) { case 'screen': $this->pdf->Output(claro_utf8_encode($topicInfo['topic_id'] . '_' . $topicInfo['topic_title'] . '.pdf'), 'D'); break; default: $path = get_conf('rootSys') . get_conf('tmpPathSys') . '/forum_export/'; claro_mkdir($path); $this->pdf->Output($path . claro_utf8_encode(replace_dangerous_char($topicInfo['topic_id'] . '_' . $topicInfo['topic_title']) . '.pdf'), 'F'); break; } return true; }
public function export() { $postsList = $this->loadTopic($this->getTopicId()); $topicInfo = get_topic_settings($this->getTopicId()); $css = $this->importCss(); $form = new PhpTemplate(get_module_path('CLFRM') . '/templates/forum_export.tpl.php'); $form->assign('forum_id', $topicInfo['forum_id']); $form->assign('topic_id', $topicInfo['topic_id']); $form->assign('notification_bloc', false); $form->assign('topic_subject', $topicInfo['topic_title']); $form->assign('postList', $postsList); $form->assign('claro_notifier', false); $form->assign('is_allowedToEdit', false); $form->assign('date', null); $out = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n" . '<html>' . "\n" . '<head>' . "\n" . '<meta http-equiv="Content-Type" content="text/HTML; charset=' . get_conf('charset') . '" />' . "\n" . '<style type="text/css">' . $css . '</style>' . "\n" . '<title>' . $topicInfo['topic_title'] . '</title>' . "\n" . '</head>' . "\n" . '<body><div id="forumExport">' . "\n"; $out .= $form->render(); $out .= '</div></body>' . "\n" . '</html>'; $path = get_conf('rootSys') . get_conf('tmpPathSys') . '/forum_export/'; $filename = $path . replace_dangerous_char(str_replace(' ', '_', $topicInfo['topic_title']) . '_' . $topicInfo['topic_id']) . '.html'; claro_mkdir($path); file_put_contents($filename, $out); switch ($this->output) { case 'screen': header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Length: ' . filesize($filename)); header('Content-Disposition: attachment; filename=' . basename($filename)); readfile($filename); claro_delete_file($filename); break; case 'file': break; } return true; }
/** * Upgrade course repository files and script to 1.8 */ function course_repository_upgrade_to_18($course_code) { global $currentCourseVersion, $currentcoursePathSys; $versionRequiredToProceed = '/^1.7/'; $tool = 'CLINDEX'; if (preg_match($versionRequiredToProceed, $currentCourseVersion)) { switch ($step = get_upgrade_status($tool, $course_code)) { case 1: if (is_writable($currentcoursePathSys)) { if (!is_dir($currentcoursePathSys)) { claro_mkdir($currentcoursePathSys); } if (!is_dir($currentcoursePathSys . '/chat')) { claro_mkdir($currentcoursePathSys . '/chat'); } if (!is_dir($currentcoursePathSys . '/modules')) { claro_mkdir($currentcoursePathSys . '/modules'); } if (!is_dir($currentcoursePathSys . '/scormPackages')) { claro_mkdir($currentcoursePathSys . '/scormPackages'); } $step = set_upgrade_status($tool, 2, $course_code); } else { log_message(sprintf('Repository %s not writable', $currentcoursePathSys)); return $step; } case 2: // build index.php of course $fd = fopen($currentcoursePathSys . '/index.php', 'w'); if (!$fd) { return $step; } // build index.php $string = '<?php ' . "\n" . 'header (\'Location: ' . $GLOBALS['urlAppend'] . '/claroline/course/index.php?cid=' . rawurlencode($course_code) . '\') ;' . "\n" . '?' . '>' . "\n"; if (!fwrite($fd, $string)) { return $step; } if (!fclose($fd)) { return $step; } $step = set_upgrade_status($tool, 0, $course_code); default: return $step; } } return false; }
/** * Handle user's profile picture modification * (based on $_REQUEST['delPicture'] and $_FILE['picture']. * * @return $feedback array (yes, it is kinda ugly) */ function user_handle_profile_picture($userData) { $feedback = array('success' => false, 'messages' => array(), 'pictureName' => ''); // Handle user picture if (!empty($_REQUEST['delPicture'])) { $picturePath = user_get_picture_path($userData); if ($picturePath) { claro_delete_file($picturePath); $feedback['success'] = true; $feedback['messages'][] = get_lang("User picture deleted"); } else { $feedback['messages'][] = get_lang("Cannot delete user picture"); } } if (isset($_FILES['picture']['name']) && $_FILES['picture']['size'] > 0) { $fileName = $_FILES['picture']['name']; $fileTmpName = $_FILES['picture']['tmp_name']; if (is_uploaded_file($fileTmpName)) { // Is it an picture ? if (is_image($fileName)) { // Does it meet the platform's requirements list($width, $height, $type, $attr) = getimagesize($fileTmpName); if ($width > 0 && $width <= get_conf('maxUserPictureWidth', 150) && $height > 0 && $height <= get_conf('maxUserPictureHeight', 200) && $_FILES['picture']['size'] <= get_conf('maxUserPictureSize', 100 * 1024)) { $uploadDir = user_get_private_folder_path($userData['user_id']); if (!file_exists($uploadDir)) { claro_mkdir($uploadDir, CLARO_FILE_PERMISSIONS, true); } // User's picture successfully treated if (false !== ($pictureName = treat_uploaded_file($_FILES['picture'], $uploadDir, '', 1000000000000.0))) { $feedback['success'] = true; $feedback['messages'][] = get_lang("User picture added"); $feedback['pictureName'] = $pictureName; } else { $feedback['messages'][] = get_lang("Cannot upload file"); } } else { $feedback['messages'][] = get_lang("Image is too big : max size %width%x%height%, %size% bytes", array('%width%' => get_conf('maxUserPictureWidth', 150), '%height%' => get_conf('maxUserPictureHeight', 200), '%size%' => get_conf('maxUserPictureHeight', 100 * 1024))); } } else { $feedback['messages'][] = get_lang("Invalid file format, use gif, jpg or png"); } } else { $feedback['messages'][] = get_lang('Upload failed'); } } return $feedback; }
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; }
protected static function initDriverList() { // load static drivers self::$drivers = array('claroline' => new ClarolineLocalAuthDriver(), 'disabled' => new UserDisabledAuthDriver(), 'temp' => new TemporaryAccountAuthDriver(), 'CAS' => new ClarolineLocalAuthDriver()); self::$driversAllowingLostPassword = array('claroline' => 'claroline', 'clarocrypt' => 'clarocrypt'); // load dynamic drivers if (!file_exists(get_path('rootSys') . 'platform/conf/extauth')) { FromKernel::uses('fileManage.lib'); claro_mkdir(get_path('rootSys') . 'platform/conf/extauth', CLARO_FILE_PERMISSIONS, true); } if (get_conf('claro_authDriversAutoDiscovery', true)) { $driversToLoad = array(); $it = new DirectoryIterator(get_path('rootSys') . 'platform/conf/extauth'); foreach ($it as $file) { if ($file->isFile() && substr($file->getFilename(), -9) == '.conf.php') { $driversToLoad[] = $file->getPathname(); } } sort($driversToLoad); foreach ($driversToLoad as $driverFile) { self::loadDriver($driverFile); } } else { if (file_exists(get_path('rootSys') . 'platform/conf/extauth/drivers.list')) { $authDriverList = file(get_path('rootSys') . 'platform/conf/extauth/drivers.list'); foreach ($authDriverList as $authDriver) { $authDriver = trim($authDriver); if (!empty($authDriver)) { self::loadDriver(ltrim(rtrim(get_path('rootSys') . 'platform/conf/extauth/' . $authDriver))); } } } } }
/** * save assignment to DB * * @author Sebastien Piraux <*****@*****.**> * @return mixed false or id of the record */ public function save() { // TODO method to validate data if ($this->id == -1) { // insert $sql = "INSERT INTO `" . $this->tblAssignment . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `def_submission_visibility` = '" . claro_sql_escape($this->defaultSubmissionVisibility) . "',\n `assignment_type` = '" . claro_sql_escape($this->assignmentType) . "',\n `authorized_content` = '" . claro_sql_escape($this->submissionType) . "',\n `allow_late_upload` = '" . claro_sql_escape($this->allowLateUpload) . "',\n `start_date` = FROM_UNIXTIME('" . claro_sql_escape($this->startDate) . "'),\n `end_date` = FROM_UNIXTIME('" . claro_sql_escape($this->endDate) . "'),\n `prefill_text` = '" . claro_sql_escape($this->autoFeedbackText) . "',\n `prefill_doc_path` = '" . claro_sql_escape($this->autoFeedbackFilename) . "',\n `prefill_submit` = '" . claro_sql_escape($this->autoFeedbackSubmitMethod) . "'"; // execute the creation query and get id of inserted assignment $insertedId = claro_sql_query_insert_id($sql); if ($insertedId) { $this->id = (int) $insertedId; $this->buildDirPaths(); // create the assignment directory if query was successfull and dir not already exists if (!is_dir($this->assigDirSys)) { claro_mkdir($this->assigDirSys, CLARO_FILE_PERMISSIONS, true); } return $this->id; } else { return false; } } else { if ($this->applyVisibilityChangeToOldSubmissions) { // get current assignment defaultSubmissionVisibility $sqlGetOldData = "SELECT `def_submission_visibility`\n FROM `" . $this->tblAssignment . "`\n WHERE `id` = '" . $this->id . "'"; $prevDefaultSubmissionVisibility = claro_sql_query_get_single_value($sqlGetOldData); // change visibility of all works only if defaultSubmissionVisibility has changed if ($this->_forceVisibilityChange || $this->defaultSubmissionVisibility != $prevDefaultSubmissionVisibility) { $this->updateAllSubmissionsVisibility($this->defaultSubmissionVisibility, true); } } // update, main query $sql = "UPDATE `" . $this->tblAssignment . "`\n SET `title` = '" . claro_sql_escape($this->title) . "',\n `description` = '" . claro_sql_escape($this->description) . "',\n `visibility` = '" . claro_sql_escape($this->visibility) . "',\n `def_submission_visibility` = '" . claro_sql_escape($this->defaultSubmissionVisibility) . "',\n `assignment_type` = '" . claro_sql_escape($this->assignmentType) . "',\n `authorized_content` = '" . claro_sql_escape($this->submissionType) . "',\n `allow_late_upload` = '" . claro_sql_escape($this->allowLateUpload) . "',\n `start_date` = FROM_UNIXTIME('" . claro_sql_escape($this->startDate) . "'),\n `end_date` = FROM_UNIXTIME('" . claro_sql_escape($this->endDate) . "'),\n `prefill_text` = '" . claro_sql_escape($this->autoFeedbackText) . "',\n `prefill_doc_path` = '" . claro_sql_escape($this->autoFeedbackFilename) . "',\n `prefill_submit` = '" . claro_sql_escape($this->autoFeedbackSubmitMethod) . "'\n WHERE `id` = '" . $this->id . "'"; // execute and return main query if (claro_sql_query($sql)) { return $this->id; } else { return false; } } }
if ($cmd == 'exExport' && get_conf('enableExerciseExportQTI')) { require_once '../export/qti2/qti2_export.php'; require_once get_path('incRepositorySys') . '/lib/fileManage.lib.php'; require_once get_path('incRepositorySys') . '/lib/file.lib.php'; require_once get_path('incRepositorySys') . '/lib/thirdparty/pclzip/pclzip.lib.php'; $question = new Qti2Question(); $question->load($quId); // contruction of XML flow $xml = $question->export(); // remove trailing slash if (substr($question->questionDirSys, -1) == '/') { $question->questionDirSys = substr($question->questionDirSys, 0, -1); } //save question xml file if (!file_exists($question->questionDirSys)) { claro_mkdir($question->questionDirSys, CLARO_FILE_PERMISSIONS); } if ($fp = @fopen($question->questionDirSys . "/question_" . $quId . ".xml", 'w')) { fwrite($fp, $xml); fclose($fp); } else { // interrupt process } // list of dirs to add in archive $filePathList[] = $question->questionDirSys; /* * BUILD THE ZIP ARCHIVE */ // build and send the zip if (sendZip($question->getTitle(), $filePathList, $question->questionDirSys)) { exit;
$wrkForm['wrkPrivFbk'] = ''; } // no need to check and/or upload the file if there is already an error if ($formCorrectlySent) { $wrkForm['filename'] = ''; if (isset($_FILES['wrkFile']['tmp_name']) && is_uploaded_file($_FILES['wrkFile']['tmp_name']) && $assignmentContent != "TEXT") { if ($_FILES['wrkFile']['size'] > $fileAllowedSize) { $dialogBox->error(get_lang('You didnt choose any file to send, or it is too big')); $formCorrectlySent = false; } else { $newFilename = $_FILES['wrkFile']['name'] . add_extension_for_uploaded_file($_FILES['wrkFile']); $newFilename = replace_dangerous_char($newFilename); $newFilename = get_secure_file_name($newFilename); $wrkForm['filename'] = $assignment->createUniqueFilename($newFilename); if (!is_dir($assignment->getAssigDirSys())) { claro_mkdir($assignment->getAssigDirSys(), CLARO_FILE_PERMISSIONS); } if (move_uploaded_file($_FILES['wrkFile']['tmp_name'], $assignment->getAssigDirSys() . $wrkForm['filename'])) { chmod($assignment->getAssigDirSys() . $wrkForm['filename'], CLARO_FILE_PERMISSIONS); } else { $dialogBox->error(get_lang('Cannot copy the file')); $formCorrectlySent = false; } // remove the previous file if there was one if (isset($_REQUEST['currentWrkUrl'])) { @unlink($assignment->getAssigDirSys() . $_REQUEST['currentWrkUrl']); } } } elseif ($assignmentContent == "FILE") { if (isset($_REQUEST['currentWrkUrl'])) { // if there was already a file and nothing was provided to replace it, reuse it
include_once get_path('incRepositorySys') . '/lib/statsUtils.lib.inc.php'; include_once get_path('incRepositorySys') . '/lib/thirdparty/pear/Lite.php'; include_once claro_get_conf_repository() . 'CLKCACHE.conf.php'; // right $is_allowedToCheckProblems = claro_is_platform_admin(); // Cache_lite setting & init $cache_options = array('cacheDir' => get_path('rootSys') . 'tmp/cache/campusProblem/', 'lifeTime' => get_conf('cache_lifeTime', 10), 'automaticCleaningFactor' => get_conf('cache_automaticCleaningFactor', 50)); if (claro_debug_mode()) { $cache_options['pearErrorMode'] = CACHE_LITE_ERROR_DIE; } if (claro_debug_mode()) { $cache_options['lifeTime'] = 3; } if (!file_exists($cache_options['cacheDir'])) { include_once get_path('incRepositorySys') . '/lib/fileManage.lib.php'; claro_mkdir($cache_options['cacheDir'], CLARO_FILE_PERMISSIONS, true); } $Cache_Lite = new Cache_Lite($cache_options); /** * DB tables definition */ $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_course = $tbl_mdb_names['course']; $tbl_rel_course_user = $tbl_mdb_names['rel_course_user']; $tbl_user = $tbl_mdb_names['user']; $tbl_tracking_event = $tbl_mdb_names['tracking_event']; $tbl_document = $tbl_cdb_names['document']; $toolNameList = claro_get_tool_name_list(); // used in strange cases, a course is unused if not used since $limitBeforeUnused // INTERVAL SQL expr. see http://www.mysql.com/doc/en/Date_and_time_functions.html
<?php // $Id: course_install.php 9706 2007-12-12 13:30:11Z mlaurent $ // vim: expandtab sw=4 ts=4 sts=4: if (count(get_included_files()) == 1) { die('The file ' . basename(__FILE__) . ' cannot be accessed directly, use include instead'); } $moduleWorkingDirectory = get_path('coursesRepositorySys') . $courseDirectory . '/chat'; if (!claro_mkdir($moduleWorkingDirectory, CLARO_FILE_PERMISSIONS, true)) { return claro_failure::set_failure(get_lang('Unable to create folder %folder', array('%folder' => $moduleWorkingDirectory))); }
/* * The code begin with STEP 2 * so it allows to return to STEP 1 * if STEP 2 unsucceds */ /*------------------------------------------------------------------------ STEP 2 ------------------------------------------------------------------------*/ if ('exMkDir' == $cmd) { $newDirName = replace_dangerous_char(trim($_REQUEST['newName'])); $cwd = secure_file_path($cwd); if (check_name_exist($baseWorkDir . $cwd . '/' . $newDirName)) { $dialogBox->error(get_lang('A file with this name already exists.')); $cmd = 'rqMkDir'; } else { claro_mkdir($baseWorkDir . $cwd . '/' . $newDirName, CLARO_FILE_PERMISSIONS); $comment = isset($_REQUEST['comment']) ? trim($_REQUEST['comment']) : ''; if (!empty($comment) && $courseContext) { update_db_info('update', $cwd . '/' . $newDirName, array('comment' => $comment)); } $dialogBox->success(get_lang("Directory created")); $eventNotifier->notifyCourseEvent("document_file_added", claro_get_current_course_id(), claro_get_current_tool_id(), $cwd . '/' . $newDirName, claro_get_current_group_id(), "0"); } } /*------------------------------------------------------------------------ STEP 1 ------------------------------------------------------------------------*/ if ('rqMkDir' == $cmd) { $dialogBox->title(get_lang('Create directory')); $form = '<form action="' . claro_htmlspecialchars($_SERVER['PHP_SELF']) . '" method="post">' . "\n" . claro_form_relay_context() . '<input type="hidden" name="cmd" value="exMkDir" />' . "\n" . '<input type="hidden" name="cwd" value="' . claro_htmlspecialchars($cwd) . '" />' . "\n" . '<label for="newName">' . get_lang('Directory name') . '</label> <span class="required">*</span><br />' . "\n" . '<input type="text" id="newName" name="newName" />' . "\n" . '<br />' . "\n"; if ($courseContext) {
/** * Prepare the temporary destination directory that'll be zipped and exported. * Existing SCORM, documents, as well as required or helper javascript files and XML schemas * are copied into the directory. * No manifest created yet. * * @return False on error, true otherwise. * @see createManifest * @author Thanos Kyritsis <*****@*****.**> * @author Amand Tihon <*****@*****.**> */ function prepare() { global $clarolineRepositorySys, $claro_stylesheet; global $langErrorCopyScormFiles, $langErrorCreatingDirectory, $langErrorCopyingScorm, $langErrorCopyAttachedFile; // (re)create fresh directory claro_delete_file($this->destDir); if ( !claro_mkdir($this->destDir, CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/common", CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/extend", CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/unique", CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/vocab", CLARO_FILE_PERMISSIONS, true) ) { $this->error[] = $langErrorCreatingDirectory . $this->destDir; return false; } // Copy usual files (.css, .js, .xsd, etc) if ( !claro_copy_file('modules/learnPath/export/APIWrapper.js', $this->destDir) || !claro_copy_file('template/default/CSS/bootstrap-custom.css', $this->destDir) || !claro_copy_file('modules/learnPath/export/XMLSchema.dtd', $this->destDir) || !claro_copy_file('modules/learnPath/export/adlcp_v1p3.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/adlnav_v1p3.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/adlseq_v1p3.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/datatypes.dtd', $this->destDir) || !claro_copy_file('modules/learnPath/export/ims_xml.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imscp_v1p1.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0auxresource.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0control.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0delivery.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0limit.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0objective.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0random.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0rollup.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0seqrule.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0util.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lom.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lomCustom.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lomLoose.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lomStrict.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/scores.js', $this->destDir) || !claro_copy_file('modules/learnPath/export/xml.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/common/anyElement.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/dataTypes.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/elementNames.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/elementTypes.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/rootElement.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/vocabTypes.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/vocabValues.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/extend/custom.xsd', $this->destDir . "/extend") || !claro_copy_file('modules/learnPath/export/extend/strict.xsd', $this->destDir . "/extend") || !claro_copy_file('modules/learnPath/export/unique/loose.xsd', $this->destDir . "/unique") || !claro_copy_file('modules/learnPath/export/unique/strict.xsd', $this->destDir . "/unique") || !claro_copy_file('modules/learnPath/export/vocab/custom.xsd', $this->destDir . "/vocab") || !claro_copy_file('modules/learnPath/export/vocab/loose.xsd', $this->destDir . "/vocab") || !claro_copy_file('modules/learnPath/export/vocab/strict.xsd', $this->destDir . "/vocab") ) { $this->error[] = $langErrorCopyScormFiles; return false; } // Copy SCORM package, if needed if ($this->fromScorm) { // Copy the scorm directory as OrigScorm/ if ( !claro_copy_file($this->srcDirScorm, $this->destDir) || !claro_rename_file($this->destDir . '/path_' . $this->id, $this->destDir . '/OrigScorm')) { $this->error[] = $langErrorCopyingScorm; return false; } } // Create destination directory for "pure" documents claro_mkdir($this->destDir . '/Documents', CLARO_FILE_PERMISSIONS, true); // And for exercises claro_mkdir($this->destDir . '/Exercises', CLARO_FILE_PERMISSIONS, true); // Copy documents into the created directory foreach ($this->resourceMap as $module) { if ($module['contentType'] == 'DOCUMENT') { $documentName = basename($module['path']); if (dirname($module['path']) != '/') { $destinationDir = $this->destDir . '/Documents' . dirname($module['path']) . '/'; } else { $destinationDir = $this->destDir . '/Documents/'; } if (!is_dir($destinationDir)) { claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true); } @copy($this->srcDirDocument . $module['path'], $destinationDir . $documentName); } elseif ($module['contentType'] == 'EXERCISE') { if (!$this->prepareQuiz($module['path'], $module['raw_to_pass'])) return false; } elseif ($module['contentType'] == 'MEDIA') { $documentName = basename($module['path']); $destinationDir = $this->destDir . '/Documents/'; if (!is_dir($destinationDir)) { claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true); } @copy($this->srcDirVideo . $module['path'], $destinationDir . $documentName); } } // Did we find an mp3 ? /* if ( $this->mp3Found) { if ( !claro_copy_file($clarolineRepositorySys . '/exercise/claroPlayer.swf', $this->destDir) ) { $this->error[] = $langErrorCopyAttachedFile . $clarolineRepositorySys . '/exercise/claroPlayer.swf'; // This is *NOT* a fatal error. // Do *NOT* return false. } } */ return true; }
/** * Create directories used by course. * * @param string $courseRepository path from $coursesRepositorySys to root of course * @param string $courseId sysId of course * @return boolean * @author Christophe Gesche <*****@*****.**> * @author Hugues Peeters <*****@*****.**> * @author Frederic Minne <*****@*****.**> */ function prepare_course_repository($courseRepository, $courseId) { if (!is_dir(get_path('coursesRepositorySys'))) { claro_mkdir(get_path('coursesRepositorySys'), CLARO_FILE_PERMISSIONS, true); } $courseDirPath = get_path('coursesRepositorySys') . $courseRepository; if (!is_writable(get_path('coursesRepositorySys'))) { return claro_failure::set_failure(get_lang('Folder %folder is not writable', array('%folder' => get_path('coursesRepositorySys')))); } $folderList = array($courseDirPath, $courseDirPath . '/document', $courseDirPath . '/group'); foreach ($folderList as $folder) { if (!claro_mkdir($folder, CLARO_FILE_PERMISSIONS, true)) { return claro_failure::set_failure(get_lang('Unable to create folder %folder', array('%folder' => $folder))); } } // build index.php of course $courseIndex = $courseDirPath . '/index.php'; $courseIndexContent = '<?php ' . "\n" . 'header (\'Location: ' . get_path('clarolineRepositoryWeb') . 'course/index.php?cid=' . claro_htmlspecialchars($courseId) . '\') ;' . "\n" . '?' . '>' . "\n"; if (!file_put_contents($courseIndex, $courseIndexContent)) { return claro_failure::set_failure(get_lang('Unable to create file %file', array('%file' => 'index.php'))); } $groupIndex = get_path('coursesRepositorySys') . $courseRepository . '/group/index.php'; $groupIndexContent = '<?php session_start(); ?' . '>'; if (!file_put_contents($groupIndex, $groupIndexContent)) { return claro_failure::set_failure(get_lang('Unable to create file %file', array('%file' => 'group/index.php'))); } return true; }
/** * Install a specific module to the platform * @param string $modulePath path to the module * @param bool $skipCheckDir skip checking if module directory already exists (default false) * @return array( backlog, int ) * backlog object containing the messages * int moduleId if the install process suceeded, false otherwise * @todo remove the need of the Backlog and use Exceptions instead */ function install_module($modulePath, $skipCheckDir = false, $registerModuleInCourses = false) { $backlog = new Backlog(); $moduleId = false; if (false === ($module_info = readModuleManifest($modulePath))) { claro_delete_file($modulePath); $backlog->failure(claro_failure::get_last_failure()); } else { //check if a module with the same LABEL is already installed, if yes, we cancel everything // TODO extract from install function should be tested BEFORE calling install_module if (!$skipCheckDir && check_name_exist(get_module_path($module_info['LABEL']) . '/')) { $backlog->failure(get_lang('Module %module is already installed on your platform', array('%module' => $module_info['LABEL']))); // claro_delete_file($modulePath); // TODO : add code to point on existing instance of tool. // TODO : how to overwrite . prupose uninstall ? } else { //3- Save the module information into DB if (false === ($moduleId = register_module_core($module_info))) { claro_delete_file($modulePath); $backlog->failure(claro_failure::get_last_failure()); $backlog->failure(get_lang('Module registration failed')); } else { //in case of tool type module, the dock can not be selected and must added also now if ('tool' == $module_info['TYPE']) { // TODO FIXME handle failure register_module_tool($moduleId, $module_info); } if (array_key_exists('DEFAULT_DOCK', $module_info)) { foreach ($module_info['DEFAULT_DOCK'] as $dock) { // TODO FIXME handle failure add_module_in_dock($moduleId, $dock); } } //4- Rename the module repository with label $currentPlace = realpath($modulePath) . '/'; $destPath = get_module_path($module_info['LABEL']); claro_mkdir(get_path('rootSys') . 'module/', CLARO_FILE_PERMISSIONS, true); if (!@rename($currentPlace, $destPath)) { $backlog->failure(get_lang("Error while renaming module folder") . ' from:' . $currentPlace . ' to:' . $destPath); } else { // force access rights on module root dir after rename() because some modules written on M$ Win$#!t are causing issues chmod($destPath, CLARO_FILE_PERMISSIONS); //5-Include the local 'install.sql' and 'install.php' file of the module if they exist if (isset($installSqlScript)) { unset($installSqlScript); } $installSqlScript = get_module_path($module_info['LABEL']) . '/setup/install.sql'; if (file_exists($installSqlScript)) { $sql = file_get_contents($installSqlScript); if (!empty($sql)) { $sql = str_replace('__CL_MAIN__', get_conf('mainTblPrefix'), $sql); if (claro_sql_multi_query($sql) === false) { $backlog->failure(get_lang('Sql installation query failed')); } else { $backlog->failure(get_lang('Sql installation query succeeded')); } } } // generate the conf if a def file exists if (file_exists(get_module_path($module_info['LABEL']) . '/conf/def/' . $module_info['LABEL'] . '.def.conf.inc.php')) { require_once dirname(__FILE__) . '/../config.lib.inc.php'; $config = new Config($module_info['LABEL']); list($confMessage, $status) = generate_conf($config); $backlog->info($confMessage); } // call install.php after initialising database in case it requires database to run if (isset($installPhpScript)) { unset($installPhpScript); } $installPhpScript = get_module_path($module_info['LABEL']) . '/setup/install.php'; if (file_exists($installPhpScript)) { language::load_translation(); language::load_locale_settings(); language::load_module_translation($module_info['LABEL']); load_module_config($module_info['LABEL']); // FIXME this is very dangerous !!!! require $installPhpScript; $backlog->info(get_lang('Module installation script called')); } $moduleInfo = get_module_info($moduleId); if ($registerModuleInCourses && $moduleInfo['type'] == 'tool' && $moduleId) { list($backlog2, $success2) = register_module_in_courses($moduleId); if ($success2) { $backlog->success(get_lang('Module installed in all courses')); } else { $backlog->append($backlog2); } } //6- cache file with the module's include must be renewed after installation of the module if (!generate_module_cache()) { $backlog->failure(get_lang('Module cache update failed')); } else { $backlog->success(get_lang('Module cache update succeeded')); } } } } } return array($backlog, $moduleId); }
// Create module, platform, tmp folders if (!file_exists(get_path('rootSys') . 'module/')) { claro_mkdir(get_path('rootSys') . 'module/', CLARO_FILE_PERMISSIONS, true); } if (!file_exists(get_path('rootSys') . 'platform/')) { claro_mkdir(get_path('rootSys') . 'platform/', CLARO_FILE_PERMISSIONS, true); } if (!file_exists(get_path('rootSys') . 'platform/conf/')) { claro_mkdir(get_path('rootSys') . 'platform/conf/', CLARO_FILE_PERMISSIONS, true); } if (!file_exists(get_path('rootSys') . 'tmp/')) { claro_mkdir(get_path('rootSys') . 'tmp/', CLARO_FILE_PERMISSIONS, true); } // Create folder to backup configuration files $backupRepositorySys = get_path('rootSys') . 'platform/bak.' . date('Y-z-B') . '/'; claro_mkdir($backupRepositorySys, CLARO_FILE_PERMISSIONS, true); $output = '<h3>Configuration file</h3>' . "\n"; $output .= '<ol>' . "\n"; /* * Generate configuration file from definition file */ $config_code_list = get_config_code_list(); $config_code_list = array_merge($config_code_list, array('CLANN', 'CLCAL', 'CLFRM', 'CLCHT', 'CLDOC', 'CLDSC', 'CLUSR', 'CLLNP', 'CLQWZ', 'CLWRK', 'CLWIKI')); if (is_array($config_code_list)) { // Build table with current values in configuration files $current_property_list = array(); foreach ($config_code_list as $config_code) { // new config object $config = new ConfigUpgrade($config_code); $config->load(); $this_property_list = $config->get_property_list();
/** * Main function to import an exercise. * * @param string $file path of the file * @param array $backlog_message * * @return the id of the created exercise or false if the operation failed */ function import_exercise($file, &$backlog) { global $exercise_info; global $element_pile; global $non_HTML_tag_to_avoid; global $record_item_body; // used to specify the question directory where files could be found in relation in any question global $questionTempDir; // get required table names $tbl_cdb_names = get_module_course_tbl(array('qwz_exercise', 'qwz_question'), claro_get_current_course_id()); $tbl_quiz_exercise = $tbl_cdb_names['qwz_exercise']; $tbl_quiz_question = $tbl_cdb_names['qwz_question']; // paths $baseWorkDir = get_path('rootSys') . get_conf('tmpPathSys') . 'upload/'; // create temp dir for upload if (!file_exists($baseWorkDir)) { claro_mkdir($baseWorkDir, CLARO_FILE_PERMISSIONS); } $uploadDir = claro_mkdir_tmp($baseWorkDir); // this function should return the dir name and not the full path ... $uploadPath = str_replace($baseWorkDir, '', $uploadDir); // set some default values for the new exercise $exercise_info = array(); $exercise_info['name'] = preg_replace('/.zip$/i', '', $file); $exercise_info['description'] = ''; $exercise_info['question'] = array(); // create parser and array to retrieve info from manifest $element_pile = array(); //pile to known the depth in which we are $module_info = array(); //array to store the info we need // if file is not a .zip, then we cancel all if (!preg_match('/.zip$/i', $_FILES['uploadedExercise']['name'])) { $backlog->failure(get_lang('You must upload a zip file')); return false; } //unzip the uploaded file in a tmp directory if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) { $backlog->failure(get_lang('Upload failed')); return false; } // find the different manifests for each question and parse them. $exerciseHandle = opendir($uploadDir); $question_number = 0; $file_found = false; // parse every subdirectory to search xml question files while (false !== ($file = readdir($exerciseHandle))) { if (is_dir($uploadDir . '/' . $file) && $file != "." && $file != "..") { //find each manifest for each question repository found $questionHandle = opendir($uploadDir . '/' . $file); while (false !== ($questionFile = readdir($questionHandle))) { if (preg_match('/.xml$/i', $questionFile)) { list($parsingBacklog, $success) = parse_file($uploadDir, $file, $questionFile); $backlog->append($parsingBacklog); $file_found = true; } } } elseif (preg_match('/.xml$/i', $file)) { list($parsingBacklog, $success) = parse_file($uploadDir, '', $file); $backlog->append($parsingBacklog); $file_found = true; } // else ignore file } if (!$file_found) { $backlog->failure(get_lang('No XML file found in the zip')); return false; } //--------------------- //add exercise in tool //--------------------- //1.create exercise $exercise = new Exercise(); $exercise->setTitle($exercise_info['name']); $exercise->setDescription($exercise_info['description']); if ($exercise->validate()) { $exercise_id = $exercise->save(); } else { $backlog->failure(get_lang('There is an error in exercise data of imported file.')); return false; } ksort($exercise_info['question'], SORT_NUMERIC); //For each question found... foreach ($exercise_info['question'] as $key => $question_array) { //2.create question $question = new Qti2Question(); $question->import($question_array); if ($question->validate()) { // I need to save the question after the answer because I need question id in answers $question_id = $question->save(); //3.create answers $question->setAnswer(); $question->answer->import($question_array); if ($question->answer->validate()) { $question->setGrade($question->answer->getGrade()); $question->save(); // save computed grade $question->answer->save(); $exercise->addQuestion($question_id); } else { $backlog->failure(get_lang('Invalid answer') . ' : ' . $key); } } else { $backlog->failure(get_lang('Invalid question') . ' : ' . $key); } } // delete the temp dir where the exercise was unzipped claro_delete_file($uploadDir); return $exercise_id; }
/** * set attachment value and move uploaded image to a temporary file * * @author Sebastien Piraux <*****@*****.**> */ public function setAttachment($file) { // remove the previous file if there was one $this->deleteAttachment(); $filename = $file['name'] . add_extension_for_uploaded_file($file); $filename = replace_dangerous_char($filename); $filename = get_secure_file_name($filename); // if creation we use tmp directory if ($this->id == -1) { $dir = $this->tmpQuestionDirSys; } else { $dir = $this->questionDirSys; } // be sure that directory exists if (!is_dir($dir)) { // create it if (!claro_mkdir($dir, CLARO_FILE_PERMISSIONS)) { claro_failure::set_failure('cannot_create_tmp_dir'); return false; } } // put file in directory if (move_uploaded_file($file['tmp_name'], $dir . $filename)) { chmod($dir . $filename, CLARO_FILE_PERMISSIONS); } else { claro_failure::set_failure('question_upload_failed'); return false; } $this->attachment = $filename; return true; }
public static function store($offset) { if (!file_exists(dirname(__FILE__) . '/../../../platform')) { claro_mkdir(dirname(__FILE__) . '/../../../platform', CLARO_FILE_PERMISSIONS, true); } file_put_contents(dirname(__FILE__) . self::$path, (int) $offset); }
/** * Create a new group * * @param string $groupName - name of the group * @param integer $maxMember - max user allowed for this group * @return integer : id of the new group * * @copyright (c) 2001-2011, Universite catholique de Louvain (UCL) */ function create_group($prefixGroupName, $maxMember) { require_once dirname(__FILE__) . '/forum.lib.php'; require_once dirname(__FILE__) . '/fileManage.lib.php'; $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_groups = $tbl_cdb_names['group_team']; // Check name of group $sql = "SELECT name FROM `" . $tbl_groups . "` WHERE name LIKE '" . claro_sql_escape($prefixGroupName) . "%'"; $existingGroupList = claro_sql_query_fetch_all_cols($sql); $existingGroupList = $existingGroupList['name']; $i = 1; do { $groupName = $prefixGroupName . str_pad($i, 4, ' ', STR_PAD_LEFT); $i++; if ($i - 2 > count($existingGroupList)) { die($groupName . 'infiniteloop'); } } while (in_array($groupName, $existingGroupList)); /** * Create a directory allowing group student to upload documents */ // Create a Unique ID path preventing other enter $globalPath = $GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/'; do { $groupRepository = str_replace(' ', '_', substr(uniqid(substr($groupName, 0, 19) . ' ', ''), 0, 30)); } while (check_name_exist($globalPath . $groupRepository)); claro_mkdir($globalPath . $groupRepository, CLARO_FILE_PERMISSIONS); /* * Insert a new group in the course group table and keep its ID */ $sql = "INSERT INTO `" . $tbl_groups . "`\n SET name = '" . $groupName . "',\n `maxStudent` = " . (is_null($maxMember) ? 'NULL' : "'" . (int) $maxMember . "'") . ",\n secretDirectory = '" . claro_sql_escape($groupRepository) . "'"; $createdGroupId = claro_sql_query_insert_id($sql); /* * Create a forum for the group in the forum table */ 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')) { create_forum($groupName . ' - ' . strtolower(get_lang('Forum')), '', 2, (int) GROUP_FORUMS_CATEGORY, '', $createdGroupId); } 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')) { require_once get_module_path('CLWIKI') . '/lib/lib.createwiki.php'; create_wiki($createdGroupId, $groupName . ' - Wiki'); } return $createdGroupId; }
/** * Prepare the temporary destination directory that'll be zipped and exported. * Existing SCORM, documents, as well as required or helper javascript files and XML schemas * are copied into the directory. * No manifest created yet. * * @return False on error, true otherwise. * @see createManifest * @author Thanos Kyritsis <*****@*****.**> * @author Amand Tihon <*****@*****.**> */ function prepare() { global $clarolineRepositorySys, $claro_stylesheet; global $langErrorCopyScormFiles, $langErrorCreatingDirectory, $langErrorCopyingScorm, $langErrorCopyAttachedFile; // (re)create fresh directory claro_delete_file($this->destDir); if (!claro_mkdir($this->destDir, CLARO_FILE_PERMISSIONS, true)) { $this->error[] = $langErrorCreatingDirectory . $this->destDir; return false; } // Copy usual files (.css, .js, .xsd, etc) if ( !claro_copy_file('modules/learnPath/export12/APIWrapper.js', $this->destDir) || !claro_copy_file('template/default/CSS/bootstrap-custom.css', $this->destDir) || !claro_copy_file('modules/learnPath/export12/scores.js', $this->destDir) || !claro_copy_file('modules/learnPath/export12/ims_xml.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export12/imscp_rootv1p1p2.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export12/imsmd_rootv1p2p1.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export12/adlcp_rootv1p2.xsd', $this->destDir)) { $this->error[] = $langErrorCopyScormFiles; return false; } // Copy SCORM package, if needed if ($this->fromScorm) { // Copy the scorm directory as OrigScorm/ if ( !claro_copy_file($this->srcDirScorm, $this->destDir) || !claro_rename_file($this->destDir . '/path_' . $this->id, $this->destDir . '/OrigScorm')) { $this->error[] = $langErrorCopyingScorm; return false; } } // Create destination directory for "pure" documents claro_mkdir($this->destDir . '/Documents', CLARO_FILE_PERMISSIONS, true); // And for exercises claro_mkdir($this->destDir . '/Exercises', CLARO_FILE_PERMISSIONS, true); // Copy documents into the created directory foreach ($this->resourceMap as $module) { if ($module['contentType'] == 'DOCUMENT') { $documentName = basename($module['path']); if (dirname($module['path']) != '/') { $destinationDir = $this->destDir . '/Documents' . dirname($module['path']) . '/'; } else { $destinationDir = $this->destDir . '/Documents/'; } if (!is_dir($destinationDir)) { claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true); } @copy($this->srcDirDocument . $module['path'], $destinationDir . $documentName); } elseif ($module['contentType'] == 'EXERCISE') { if (!$this->prepareQuiz($module['path'], $module['raw_to_pass'])) { return false; } } elseif ($module['contentType'] == 'MEDIA') { $documentName = basename($module['path']); $destinationDir = $this->destDir . '/Documents/'; if (!is_dir($destinationDir)) { claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true); } @copy($this->srcDirVideo . $module['path'], $destinationDir . $documentName); } } // Did we find an mp3 ? if ($this->mp3Found) { if (!claro_copy_file($clarolineRepositorySys . '/exercise/claroPlayer.swf', $this->destDir)) { $this->error[] = $langErrorCopyAttachedFile . $clarolineRepositorySys . '/exercise/claroPlayer.swf'; // This is *NOT* a fatal error. // Do *NOT* return false. } } return true; }
function claro_copy_file($sourcePath, $targetPath) { $fileName = my_basename($sourcePath); if (is_file($sourcePath)) { return copy($sourcePath, $targetPath . '/' . $fileName); } elseif (is_dir($sourcePath)) { // check to not copy the directory inside itself if (preg_match('|^' . $sourcePath . '/|', $targetPath . '/')) { return false; } if (!claro_mkdir($targetPath . '/' . $fileName, CLARO_FILE_PERMISSIONS)) { return false; } $dirHandle = opendir($sourcePath); if (!$dirHandle) { return false; } $copiableFileList = array(); while ($element = readdir($dirHandle)) { if ($element == '.' || $element == '..') { continue; } $copiableFileList[] = $sourcePath . '/' . $element; } closedir($dirHandle); if (count($copiableFileList) > 0) { foreach ($copiableFileList as $thisFile) { if (!claro_copy_file($thisFile, $targetPath . '/' . $fileName)) { return false; } } } return true; } // end elseif is_dir() }
/** * 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; } }
$dialogBox->error(Backlog_Reporter::report($summary, $details)); } } } elseif (array_key_exists('packageCandidatePath', $_REQUEST)) { // If the target is a zip file, it must be unpack // If it's a unziped package, We copye the content if (is_package_file($_REQUEST['packageCandidatePath'])) { pushClaroMessage(__LINE__ . 'packageCandidatePath is a package', 'dbg'); $modulePath = unzip_package($_REQUEST['packageCandidatePath']); pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg'); } elseif (file_exists($_REQUEST['packageCandidatePath'])) { // COPY THE FILE TO WORK REPOSITORY pushClaroMessage(__LINE__ . 'packageCandidatePath is a path', 'dbg'); claro_mkdir(get_package_path()); $modulePath = create_unexisting_directory(get_package_path() . basename($_REQUEST['packageCandidatePath'])); claro_mkdir($modulePath); pushClaroMessage(__LINE__ . 'create target' . $modulePath, 'dbg'); if (claro_copy_file($_REQUEST['packageCandidatePath'], $modulePath . '/')) { $modulePath .= '/' . basename($_REQUEST['packageCandidatePath']); $moduleInstallable = true; } else { $dialogBox->error(get_lang('Module catching failed. Check your path')); $moduleInstallable = false; } } } pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg'); // OK TO TRY TO INSTALL ? if ($moduleInstallable) { list($backlog, $module_id) = install_module($modulePath); $details = $backlog->output();
$coursesRepositoryAppend = ''; $coursesRepositorySys = $rootSys . $courseRepositoryForm; if (!file_exists($coursesRepositorySys)) { claro_mkdir($coursesRepositorySys, CLARO_FILE_PERMISSIONS, true); } $clarolineRepositoryAppend = 'claroline/'; $clarolineRepositorySys = $rootSys . $clarolineRepositoryAppend; $garbageRepositorySys = $rootSys . 'tmp/garbage'; if (!file_exists($garbageRepositorySys)) { claro_mkdir($garbageRepositorySys, CLARO_FILE_PERMISSIONS, true); } if (!file_exists($rootSys . 'platform/')) { claro_mkdir($rootSys . 'platform/', CLARO_FILE_PERMISSIONS, true); } if (!file_exists(claro_get_conf_repository())) { claro_mkdir(claro_get_conf_repository(), CLARO_FILE_PERMISSIONS, true); } ########################## WRITE claro_main.conf.php ################################## // extract the path to append to the url // if Claroline is not installed on the web root directory //$urlAppendPath = ereg_replace ("claroline/install/index.php", "", $_SERVER['PHP_SELF']); // here I want find something to get garbage out of documentRoot $configFilePath = claro_get_conf_repository() . $configFileName; $fd = @fopen($configFilePath, 'w'); if (!$fd) { $fileConfigCreationError = true; $display = DISP_RUN_INSTALL_NOT_COMPLETE; } else { // get value form installer form $form_value_list['platform_id'] = md5(realpath(__FILE__)); $form_value_list['rootWeb'] = $urlForm;
/** * build the rss file and place it in directory * * @param array $context context of claroline * @param string $calType : ics,xcs,rdf * @return string ical file path */ function buildICal($context, $calType = 'ics') { if (is_array($context) && count($context) > 0) { $iCalRepositorySys = get_path('rootSys') . get_conf('iCalRepositoryCache', 'tmp/cache/iCal/'); if (!file_exists($iCalRepositorySys)) { require_once dirname(__FILE__) . '/fileManage.lib.php'; claro_mkdir($iCalRepositorySys, CLARO_FILE_PERMISSIONS, true); if (!file_exists($iCalRepositorySys)) { claro_failure::set_failure('CANT_CREATE_ICAL_DIR'); } } $iCal = (object) new iCal('', 0, $iCalRepositorySys); // (ProgrammID, Method (1 = Publish | 0 = Request), Download Directory) $toolLabelList = ical_get_tool_compatible_list(); foreach ($toolLabelList as $toolLabel) { if (is_tool_activated_in_course(get_tool_id_from_module_label($toolLabel), $context[CLARO_CONTEXT_COURSE])) { if (!is_module_installed_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE])) { install_module_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE]); } $icalToolLibPath = get_module_path($toolLabel) . '/connector/ical.write.cnr.php'; $icalToolFuncName = $toolLabel . '_write_ical'; if (file_exists($icalToolLibPath)) { require_once $icalToolLibPath; if (function_exists($icalToolFuncName)) { $iCal = call_user_func($icalToolFuncName, $iCal, $context); } } } } $iCalFilePath = $iCalRepositorySys; if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) { $iCalFilePath .= $context[CLARO_CONTEXT_COURSE] . '.'; } if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) { $iCalFilePath .= 'g' . $context[CLARO_CONTEXT_GROUP] . '.'; } if ('ics' == $calType || get_conf('iCalGenStandard', true)) { $stdICalFilePath = $iCalFilePath . 'ics'; if (false !== ($fpICal = @fopen($stdICalFilePath, 'w'))) { fwrite($fpICal, $iCal->getOutput('ics')); fclose($fpICal); } } if ('xcs' == $calType || get_conf('iCalGenXml', true)) { $xmlICalFilePath = $iCalFilePath . 'xml'; if (false !== ($fpICal = @fopen($xmlICalFilePath, 'w'))) { fwrite($fpICal, $iCal->getOutput('xcs')); fclose($fpICal); } } if ('rdf' == $calType || get_conf('iCalGenRdf', false)) { $rdfICalFilePath = $iCalFilePath . 'rdf'; if (false !== ($fpICal = @fopen($rdfICalFilePath, 'w'))) { fwrite($fpICal, $iCal->getOutput('rdf')); fclose($fpICal); } } switch ($calType) { case 'xcs': return $xmlICalFilePath; break; case 'rdf': return $rdfICalFilePath; break; default: return $stdICalFilePath; break; } } return false; }
} else { // platform context $is_allowedToEdit = claro_is_platform_admin(); $pathSys = get_path('rootSys') . 'platform/document/'; $pathWeb = get_path('rootWeb') . 'platform/document/'; } /* * Libraries */ include_once $includePath . '/lib/fileUpload.lib.php'; include_once $includePath . '/lib/fileManage.lib.php'; /* * Init directory */ if (!file_exists($pathSys)) { claro_mkdir($pathSys); } /* * Init request vars */ if (!empty($_REQUEST['relativePath']) && $_REQUEST['relativePath'] != '/' && $_REQUEST['relativePath'] != '.') { $relativePath = str_replace('..', '', $_REQUEST['relativePath']) . '/'; } else { $relativePath = '/'; } /* * Handle upload */ if ($is_allowedToEdit && isset($_FILES['sentFile']['tmp_name']) && is_uploaded_file($_FILES['sentFile']['tmp_name'])) { $imgFile = $_FILES['sentFile']; $imgFile['name'] = replace_dangerous_char($imgFile['name'], 'strict');
/** * create a tmp directory * * @param string $dir * @param string $prefix * @param int $mode * @return string full pathname */ function claro_mkdir_tmp($dir, $prefix = 'tmp', $mode = 0777) { if (substr($dir, -1) != '/') { $dir .= '/'; } do { $path = $dir . $prefix . mt_rand(0, 9999999); } while (!claro_mkdir($path, $mode)); return $path; }
} // handle upload // if the post is done a second time, the claroformid mecanism // will set $_POST to NULL, so we need to check it if ($_SERVER['REQUEST_METHOD'] == 'POST' && !is_null($_POST)) { // arrays used to store inserted ids $insertedModule_id = array(); $insertedAsset_id = array(); $lpName = $langUnamedPath; // we need a new path_id for this learning path so we prepare a line in DB // this line will be removed if an error occurs $rankMax = 1 + intval(Database::get()->querySingle("SELECT MAX(`rank`) AS max\n FROM `lp_learnPath` WHERE `course_id` = ?d", $course_id)->max); $tempPathId = Database::get()->query("INSERT INTO `lp_learnPath`\n (`course_id`, `name`,`visible`,`rank`,`comment`)\n VALUES (?d, ?s, 0, ?d,'')", $course_id, $lpName, $rankMax)->lastInsertID; $baseWorkDir .= "path_" . $tempPathId; if (!is_dir($baseWorkDir)) { claro_mkdir($baseWorkDir, CLARO_FILE_PERMISSIONS); } // unzip package require_once "include/pclzip/pclzip.lib.php"; /* * Check if the file is valid (not to big and exists) */ if (!isset($_FILES['uploadedPackage']) || !is_uploaded_file($_FILES['uploadedPackage']['tmp_name'])) { $errorFound = true; array_push($errorMsgs, $langFileScormError); } elseif (!enough_size($_FILES['uploadedPackage']['size'], $baseWorkDir, $maxFilledSpace)) { $errorFound = true; array_push($errorMsgs, $langNoSpace); } elseif (preg_match("/.zip\$/i", $_FILES['uploadedPackage']['name'])) { array_push($okMsgs, $langOkFileReceived . basename($_FILES['uploadedPackage']['name'])); if (!function_exists('gzopen')) {
$dialogBox->success(get_lang("User picture deleted")); } else { $dialogBox->error(get_lang("Cannot delete user picture")); } } // Handle user picture if (isset($_FILES['picture']['name']) && $_FILES['picture']['size'] > 0) { $fileName = $_FILES['picture']['name']; $fileTmpName = $_FILES['picture']['tmp_name']; if (is_uploaded_file($fileTmpName)) { if (is_image($fileName)) { list($width, $height, $type, $attr) = getimagesize($fileTmpName); if ($width > 0 && $width <= get_conf('maxUserPictureWidth', 150) && $height > 0 && $height <= get_conf('maxUserPictureHeight', 200) && $_FILES['picture']['size'] <= get_conf('maxUserPictureSize', 100 * 1024)) { $uploadDir = user_get_private_folder_path($user_data['user_id']); if (!file_exists($uploadDir)) { claro_mkdir($uploadDir, CLARO_FILE_PERMISSIONS, true); } if (false !== ($pictureName = treat_uploaded_file($_FILES['picture'], $uploadDir, '', 1000000000000.0))) { // Update Database $user_data['picture'] = $pictureName; $dialogBox->success(get_lang("User picture added")); } else { // Handle Error $dialogBox->error(get_lang("Cannot upload file")); } } else { // Handle error $dialogBox->error(get_lang("Image is too big : max size %width%x%height%, %size% bytes", array('%width%' => get_conf('maxUserPictureWidth', 150), '%height%' => get_conf('maxUserPictureHeight', 200), '%size%' => get_conf('maxUserPictureHeight', 100 * 1024)))); } } else { // Handle error