/** * {@inheritdoc} */ public function upload($fp, $dst, $name, $tmpname) { $this->setConnectorFromPlugin(); // upload file by elfinder. $result = parent::upload($fp, $dst, $name, $tmpname); $name = $result['name']; $filtered = \URLify::filter($result['name'], 80); if (strcmp($name, $filtered) != 0) { /*$arg = array('target' => $file['hash'], 'name' => $filtered); $elFinder->exec('rename', $arg);*/ $this->rename($result['hash'], $filtered); } $realPath = $this->realpath($result['hash']); if (!empty($realPath)) { // Getting file info //$info = $elFinder->exec('file', array('target' => $file['hash'])); /** @var elFinderVolumeLocalFileSystem $volume */ //$volume = $info['volume']; //$root = $volume->root(); //var/www/chamilogits/data/courses/NEWONE/document $realPathRoot = $this->getCourseDocumentSysPath(); // Removing course path $realPath = str_replace($realPathRoot, '/', $realPath); \FileManager::add_document($this->connector->course, $realPath, 'file', intval($result['size']), $result['name']); } return $result; }
function add_audio() { $course_info = api_get_course_info(); $filepath = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/'; if (!is_dir($filepath . 'audio')) { mkdir($filepath . 'audio', api_get_permissions_for_new_directories()); $audio_id = FileManager::add_document($course_info, '/audio', 'folder', 0, 'audio'); api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id()); api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id()); } $key = 'file'; if (!isset($_FILES[$key]['name']) || !isset($_FILES[$key]['tmp_name'])) { return false; } $result = DocumentManager::upload_document($_FILES, '/audio', null, null, 0, 'rename', false, false); $file_path = null; if ($result) { $file_path = basename($result['path']); // Store the mp3 file in the lp_item table. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $sql_insert_audio = "UPDATE {$tbl_lp_item} SET audio = '" . Database::escape_string($file_path) . "'\n WHERE c_id = {$course_info['real_id']} AND id = '" . Database::escape_string($this->db_id) . "'"; Database::query($sql_insert_audio); } return $file_path; }
/** * Replace urls inside content html from a copy course * @param string content html * @param string origin course code * @param string destination course directory * @return string new content html with replaced urls or return false if content is not a string */ static function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory, $origin_course_path_from_zip = null, $origin_course_info_path = null) { if (empty($content_html)) { return false; } $orig_source_html = DocumentManager::get_resources_from_source_html($content_html); $orig_course_info = api_get_course_info($origin_course_code); //Course does not exist in the current DB probably this cames from a zip file? if (empty($orig_course_info)) { if (!empty($origin_course_path_from_zip)) { $orig_course_path = $origin_course_path_from_zip . '/'; $orig_course_info_path = $origin_course_info_path; } } else { $orig_course_path = api_get_path(SYS_PATH) . 'courses/' . $orig_course_info['path'] . '/'; $orig_course_info_path = $orig_course_info['path']; } $destination_course_code = CourseManager::get_course_id_from_path($destination_course_directory); $destination_course_info = api_get_course_info($destination_course_code); $dest_course_path = api_get_path(SYS_COURSE_PATH) . $destination_course_directory . '/'; $user_id = api_get_user_id(); if (!empty($orig_source_html)) { foreach ($orig_source_html as $source) { // get information about source url $real_orig_url = $source[0]; // url $scope_url = $source[1]; // scope (local, remote) $type_url = $source[2]; // tyle (rel, abs, url) // Get path and query from origin url $orig_parse_url = parse_url($real_orig_url); $real_orig_path = isset($orig_parse_url['path']) ? $orig_parse_url['path'] : null; $real_orig_query = isset($orig_parse_url['query']) ? $orig_parse_url['query'] : null; // Replace origin course code by destination course code from origin url query $dest_url_query = ''; if (!empty($real_orig_query)) { $dest_url_query = '?' . $real_orig_query; if (strpos($dest_url_query, $origin_course_code) !== false) { $dest_url_query = str_replace($origin_course_code, $destination_course_code, $dest_url_query); } } if ($scope_url == 'local') { if ($type_url == 'abs' || $type_url == 'rel') { $document_file = strstr($real_orig_path, 'document'); if (strpos($real_orig_path, $document_file) !== false) { $origin_filepath = $orig_course_path . $document_file; $destination_filepath = $dest_course_path . $document_file; // copy origin file inside destination course if (file_exists($origin_filepath)) { $filepath_dir = dirname($destination_filepath); if (!is_dir($filepath_dir)) { $perm = api_get_permissions_for_new_directories(); $result = @mkdir($filepath_dir, $perm, true); if ($result) { $filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $filepath_dir); //Add to item properties to the new folder $doc_id = FileManager::add_document($destination_course_info, $filepath_to_add, 'folder', 0, basename($filepath_to_add)); api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null); } } if (!file_exists($destination_filepath)) { $result = @copy($origin_filepath, $destination_filepath); if ($result) { $filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $destination_filepath); $size = filesize($destination_filepath); //Add to item properties to the file $doc_id = FileManager::add_document($destination_course_info, $filepath_to_add, 'file', $size, basename($filepath_to_add)); api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null); } } } // Replace origin course path by destination course path if (strpos($content_html, $real_orig_url) !== false) { //$origin_course_code $url_course_path = str_replace($orig_course_info_path . '/' . $document_file, '', $real_orig_path); $destination_url = $url_course_path . $destination_course_directory . '/' . $document_file . $dest_url_query; //If the course code doesn't exist in the path? what we do? Nothing! see BT#1985 if (strpos($real_orig_path, $origin_course_code) === false) { $url_course_path = $real_orig_path; $destination_url = $real_orig_path; } $content_html = str_replace($real_orig_url, $destination_url, $content_html); } } // replace origin course code by destination course code from origin url if (strpos($real_orig_url, '?') === 0) { $dest_url = str_replace($origin_course_code, $destination_course_code, $real_orig_url); $content_html = str_replace($real_orig_url, $dest_url, $content_html); } } else { if ($type_url == 'url') { } } } } } return $content_html; }
if (!$_FILES['userFile']['size']) { $dialogBox .= get_lang('SendFileError') . '<br />' . get_lang('Notice') . ' : ' . get_lang('MaxFileSize') . ' ' . ini_get('upload_max_filesize'); } else { $unzip = 0; if (preg_match('/\\.zip$/i', $_FILES['userFile']['name'])) { //if it's a zip, allow zip upload $unzip = 1; } if ($finish == 0) { // Generate new test folder if on first step of file upload. $filename = api_replace_dangerous_char(trim($_FILES['userFile']['name']), 'strict'); $fld = GenerateHpFolder($document_sys_path . $uploadPath . '/'); //$doc_id = FileManager::add_document($_course, '/HotPotatoes_files/'.$fld, 'folder', 0, $fld); //api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id()); @mkdir($document_sys_path . $uploadPath . '/' . $fld, api_get_permissions_for_new_directories()); $doc_id = FileManager::add_document($_course, '/HotPotatoes_files/' . $fld, 'folder', 0, $fld); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id()); } else { // It is not the first step... get the filename directly from the system params. $filename = $_FILES['userFile']['name']; } $allow_output_on_success = false; if (FileManager::handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath . '/' . $fld, api_get_user_id(), null, null, $unzip, '', $allow_output_on_success)) { if ($finish == 2) { $imgparams = $_POST['imgparams']; $checked = CheckImageName($imgparams, $filename); if ($checked) { $imgcount = $imgcount - 1; } else { $dialogBox .= $filename . ' ' . get_lang('NameNotEqual'); FileManager::my_delete($document_sys_path . $uploadPath . '/' . $fld . '/' . $filename);
/** * This function save a post into a file mp3 from pediaphon services * * @param $filepath * @param $dir * @author Juan Carlos Raña Trabado <*****@*****.**> * @version january 2011, chamilo 1.8.8 */ function downloadMP3_pediaphon($filepath, $dir) { $location = 'create_audio.php?' . api_get_cidreq() . '&id=' . Security::remove_XSS($_POST['document_id']) . '&dt2a=pediaphon'; //security if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) { echo '<script>window.location.href="' . $location . '"</script>'; return; } global $_user; $_course = api_get_course_info(); $clean_title = trim($_POST['title']); $clean_title = Database::escape_string($clean_title); $clean_text = trim($_POST['text']); $clean_voices = Security::remove_XSS($_POST['voices']); if (empty($clean_title) || empty($clean_text) || empty($clean_voices)) { echo '<script>window.location.href="' . $location . '"</script>'; return; } $clean_title = Security::remove_XSS($clean_title); $clean_title = Database::escape_string($clean_title); $clean_title = str_replace(' ', '_', $clean_title); //compound file names $clean_text = Security::remove_XSS($clean_text); $clean_lang = Security::remove_XSS($_POST['lang']); $clean_speed = Security::remove_XSS($_POST['speed']); $extension = 'mp3'; $audio_filename = $clean_title . '.' . $extension; $audio_title = str_replace('_', ' ', $clean_title); //prevent duplicates if (file_exists($filepath . '/' . $clean_title . '.' . $extension)) { $i = 1; while (file_exists($filepath . '/' . $clean_title . '_' . $i . '.' . $extension)) { $i++; } $audio_filename = $clean_title . '_' . $i . '.' . $extension; $audio_title = $clean_title . '_' . $i . '.' . $extension; $audio_title = str_replace('_', ' ', $audio_title); } $documentPath = $filepath . '/' . $audio_filename; //prev for a fine unicode, borrowed from main api TODO:clean // Safe replacements for some non-letter characters (whitout blank spaces) $search = array("", "\t", "\n", "\r", "\v", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%'); $replace = array('', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); $filename = $clean_text; // Encoding detection. $encoding = api_detect_encoding($filename); // Converting html-entities into encoded characters. $filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding); // Transliteration to ASCII letters, they are not dangerous for filesystems. $filename = api_transliterate($filename, 'x', $encoding); // Replacing remaining dangerous non-letter characters. $clean_text = str_replace($search, $replace, $filename); //adding the file if ($clean_lang == 'de') { $url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi'; $find_t2v = '/http\\:\\/\\/www\\.pediaphon\\.org\\/\\~bischoff\\/radiopedia\\/mp3\\/(.*)\\.mp3\\"/'; } else { $url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_' . $clean_lang . '.cgi'; //en, es, fr $find_t2v = '/http\\:\\/\\/www\\.pediaphon\\.org\\/\\~bischoff\\/radiopedia\\/mp3\\/' . $clean_lang . '\\/(.*)\\.mp3\\"/'; } $data = "stimme=" . $clean_voices . "&inputtext=" . $clean_text . "&speed=" . $clean_speed . "&go=go"; $opts = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", "Content-Length: " . strlen($data) . "\r\n", 'content' => $data)); $context = stream_context_create($opts); $previous_returntext2voice = file_get_contents($url_pediaphon, false, $context); //clean file contents $search_source = preg_match($find_t2v, $previous_returntext2voice, $hits); $souce_end = substr($hits[0], 0, -1); $returntext2voice = file_get_contents($souce_end); //make a temporal file for get the file size $tmpfname = tempnam("/tmp", "CTF"); $handle = fopen($tmpfname, "w"); fwrite($handle, $returntext2voice); fclose($handle); // Check if there is enough space in the course to save the file if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) { unlink($tmpfname); die(get_lang('UplNotEnoughSpace')); } //erase temporal file unlink($tmpfname); //save file file_put_contents($documentPath, $returntext2voice); //add document to database $current_session_id = api_get_session_id(); $groupId = $_SESSION['_gid']; $file_size = filesize($documentPath); $relativeUrlPath = $dir; $doc_id = FileManager::add_document($_course, $relativeUrlPath . $audio_filename, 'file', filesize($documentPath), $audio_title); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id); Display::display_confirmation_message(get_lang('DocumentCreated')); //return to location echo '<script>window.location.href="' . $location . '"</script>'; }
/** * Manages page splitting * @param string Page header * @param string Page body * @return void */ function dealPerPage($header, $body) { $_course = api_get_course_info(); // Split document to pages. $pages = explode('||page_break||', $body); $first_item = 0; foreach ($pages as $key => $page_content) { // For every pages, we create a new file. $key += 1; $page_content = $this->format_page_content($header, $page_content, $this->base_work_dir . $this->created_dir); $html_file = $this->created_dir . '-' . $key . '.html'; $handle = fopen($this->base_work_dir . $this->created_dir . '/' . $html_file, 'w+'); fwrite($handle, $page_content); fclose($handle); $document_id = FileManager::add_document($_course, $this->created_dir . $html_file, 'file', filesize($this->base_work_dir . $this->created_dir . $html_file), $html_file); $slide_name = ''; if ($document_id) { // Put the document in item_property update. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_SESSION['_uid'], 0, 0, null, null, api_get_session_id()); $infos = pathinfo($this->filepath); $slide_name = 'Page ' . str_repeat('0', 2 - strlen($key)) . $key; $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, ''); if ($this->first_item == 0) { $this->first_item = $previous; } // Code for text indexing. if (api_get_setting('search_enabled') == 'true') { if (isset($_POST['index_document']) && $_POST['index_document']) { //Display::display_normal_message(print_r($_POST)); $di = new ChamiloIndexer(); isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : ($lang = 'english'); $di->connectDb(null, null, $lang); $ic_slide = new IndexableChunk(); $ic_slide->addValue('title', $slide_name); $specific_fields = get_specific_field_list(); $all_specific_terms = ''; foreach ($specific_fields as $specific_field) { if (isset($_REQUEST[$specific_field['code']])) { $sterms = trim($_REQUEST[$specific_field['code']]); $all_specific_terms .= ' ' . $sterms; if (!empty($sterms)) { $sterms = explode(',', $sterms); foreach ($sterms as $sterm) { $ic_slide->addTerm(trim($sterm), $specific_field['code']); } } } } $page_content = $all_specific_terms . ' ' . $page_content; $ic_slide->addValue('content', $page_content); // Add a comment to say terms separated by commas. $courseid = api_get_course_id(); $ic_slide->addCourseId($courseid); $ic_slide->addToolId(TOOL_LEARNPATH); $lp_id = $this->lp_id; $xapian_data = array(SE_COURSE_ID => $courseid, SE_TOOL_ID => TOOL_LEARNPATH, SE_DATA => array('lp_id' => $lp_id, 'lp_item' => $previous, 'document_id' => $document_id), SE_USER => (int) api_get_user_id()); $ic_slide->xapian_data = serialize($xapian_data); $di->addChunk($ic_slide); // Index and return search engine document id. $did = $di->index(); if ($did) { // Save it to db. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did) VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)'; $sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did); Database::query($sql); } } } } } }
/** * Exports a picture to another question * * @author - Olivier Brouckaert * @param integer $questionId - ID of the target question * @return boolean - true if copied, otherwise false */ public function exportPicture($questionId, $course_info) { $course_id = $course_info['real_id']; $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $destination_path = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/images'; $source_path = api_get_path(SYS_COURSE_PATH) . $this->course['path'] . '/document/images'; // if the question has got an ID and if the picture exists if ($this->id && !empty($this->picture)) { $picture = explode('.', $this->picture); $extension = $picture[sizeof($picture) - 1]; $picture = 'quiz-' . $questionId . '.' . $extension; $result = @copy($source_path . '/' . $this->picture, $destination_path . '/' . $picture) ? true : false; //If copy was correct then add to the database if ($result) { $sql = "UPDATE {$TBL_QUESTIONS} SET picture='" . Database::escape_string($picture) . "'\n WHERE c_id = {$course_id} AND iid='" . intval($questionId) . "'"; Database::query($sql); $document_id = FileManager::add_document($course_info, '/images/' . $picture, 'file', filesize($destination_path . '/' . $picture), $picture); if ($document_id) { return api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id()); } } return $result; } return false; }
/** * Create a new document //still needs some finetuning * @param array $_course * @return string */ public function create_document($_course) { $course_id = api_get_course_int_id(); global $charset; $dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting. if (strstr($dir, '..')) { $dir = '/'; } if ($dir[0] == '.') { $dir = substr($dir, 1); } if ($dir[0] != '/') { $dir = '/' . $dir; } if ($dir[strlen($dir) - 1] != '/') { $dir .= '/'; } $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir; if (empty($_POST['dir']) && empty($_GET['dir'])) { //Generates folder $result = $this->generate_lp_folder($_course); $dir = $result['dir']; $filepath = $result['filepath']; } if (!is_dir($filepath)) { $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/'; $dir = '/'; } // stripslashes() before calling api_replace_dangerous_char() because $_POST['title'] // is already escaped twice when it gets here. $title = api_replace_dangerous_char(stripslashes($_POST['title'])); $title = FileManager::disable_dangerous_file($title); $filename = $title; $content = $_POST['content_lp']; $tmp_filename = $filename; $i = 0; while (file_exists($filepath . $tmp_filename . '.html')) { $tmp_filename = $filename . '_' . ++$i; } $filename = $tmp_filename . '.html'; $content = stripslashes($content); $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content); // Change the path of mp3 to absolute. // The first regexp deals with ../../../ urls. $content = preg_replace("|(flashvars=\"file=)(\\.+/)+|", "\$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content); // The second regexp deals with audio/ urls. $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "\$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content); // For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please). $content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content); if (!file_exists($filepath . $filename)) { if ($fp = @fopen($filepath . $filename, 'w')) { fputs($fp, $content); fclose($fp); $file_size = filesize($filepath . $filename); $save_file_path = $dir . $filename; $document_id = FileManager::add_document($_course, $save_file_path, 'file', $file_size, $tmp_filename); if ($document_id) { api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id()); $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; $new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; if ($new_comment || $new_title) { $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); $ct = ''; if ($new_comment) { $ct .= ", comment='" . Database::escape_string($new_comment) . "'"; } if ($new_title) { $ct .= ", title='" . Database::escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . "' "; } $sql_update = "UPDATE " . $tbl_doc . " SET " . substr($ct, 1) . " WHERE c_id = " . $course_id . " AND id = " . $document_id; Database::query($sql_update); } } return $document_id; } } }
} if (count($lp_items_to_remove_audio) > 0) { $sql = "UPDATE {$tbl_lp_item} SET audio = '' WHERE c_id = {$course_id} AND id IN (" . $in . ")"; $result = Database::query($sql); } // Uploading the audio files. foreach ($_FILES as $key => $value) { if (substr($key, 0, 7) == 'mp3file' and !empty($_FILES[$key]['tmp_name'])) { // The id of the learning path item. $lp_item_id = str_ireplace('mp3file', '', $key); // Create the audio folder if it does not exist yet. $_course = api_get_course_info(); $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/'; if (!is_dir($filepath . 'audio')) { mkdir($filepath . 'audio', api_get_permissions_for_new_directories()); $audio_id = FileManager::add_document($_course, '/audio', 'folder', 0, 'audio'); api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id()); } // Check if file already exits into document/audio/ $file_name = $_FILES[$key]['name']; $file_name = stripslashes($file_name); // Add extension to files without one (if possible). $file_name = FileManager::add_ext_on_mime($file_name, $_FILES[$key]['type']); $clean_name = api_replace_dangerous_char($file_name); // No "dangerous" files. $clean_name = FileManager::disable_dangerous_file($clean_name); $check_file_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/audio/' . $clean_name; // If the file exists we generate a new name. if (file_exists($check_file_path)) { $filename_components = explode('.', $clean_name); // Gettting the extension of the file.
function add_docs_to_visio($files = array()) { $_course = api_get_course_info(); foreach ($files as $file) { list($slide_name, $file_name) = explode('||', $file); // '||' is used as separator between slide name (with accents) and file name (without accents). $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset); $slide_name = str_replace('’', '\'', $slide_name); $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset); $slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding()); $did = FileManager::add_document($_course, $this->created_dir . '/' . urlencode($file_name), 'file', filesize($this->base_work_dir . $this->created_dir . '/' . $file_name), $slide_name); if ($did) { api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, null, null, null, api_get_session_id()); } } }
/** * Function export last wiki page version to document area * @author Juan Carlos Raña <*****@*****.**> */ function export2doc($doc_id) { $_course = api_get_course_info(); $groupId = api_get_group_id(); $session_id = api_get_session_id(); $data = get_wiki_data($doc_id); if (empty($data)) { return false; } $wikiTitle = $data['title']; $wikiContents = $data['content']; $template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{LANGUAGE}" lang="{LANGUAGE}"> <head> <title>{TITLE}</title> <meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" /> <style type="text/css" media="screen, projection"> /*<![CDATA[*/ {CSS} /*]]>*/ </style> {ASCIIMATHML_SCRIPT}</head> <body dir="{TEXT_DIRECTION}"> {CONTENT} </body> </html>'; $css_file = api_get_path(TO_SYS, WEB_CSS_PATH) . api_get_setting('stylesheets') . '/default.css'; if (file_exists($css_file)) { $css = @file_get_contents($css_file); } else { $css = ''; } // Fixing some bugs in css files. $root_rel = api_get_path(REL_PATH); $css_path = 'main/css/'; $theme = api_get_setting('stylesheets') . '/'; $css = str_replace('behavior:url("/main/css/csshover3.htc");', '', $css); $css = str_replace('main/', $root_rel . 'main/', $css); $css = str_replace('images/', $root_rel . $css_path . $theme . 'images/', $css); $css = str_replace('../../img/', $root_rel . 'main/img/', $css); $asciimathmal_script = Text::api_contains_asciimathml($wikiContents) || Text::api_contains_asciisvg($wikiContents) ? '<script src="' . api_get_path(TO_REL, SCRIPT_ASCIIMATHML) . '" type="text/javascript"></script>' . "\n" : ''; $template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}', '{ASCIIMATHML_SCRIPT}'), array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css, $asciimathmal_script), $template); if (0 != $groupId) { $groupPart = '_group' . $groupId; // and add groupId to put the same document title in different groups $group_properties = GroupManager::get_group_properties($groupId); $groupPath = $group_properties['directory']; } else { $groupPart = ''; $groupPath = ''; } $exportDir = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/document' . $groupPath; $exportFile = api_replace_dangerous_char($wikiTitle, 'strict') . $groupPart; //$clean_wikiContents = trim(preg_replace("/\[\[|\]\]/", " ", $wikiContents)); //$array_clean_wikiContents= explode('|', $clean_wikiContents); $wikiContents = trim(preg_replace("/\\[[\\[]?([^\\]|]*)[|]?([^|\\]]*)\\][\\]]?/", "\$1", $wikiContents)); //TODO: put link instead of title $wikiContents = str_replace('{CONTENT}', $wikiContents, $template); // replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents if (api_strpos($wikiContents, '../../courses/') !== false) { $web_course_path = api_get_path(WEB_COURSE_PATH); $wikiContents = str_replace('../../courses/', $web_course_path, $wikiContents); } $doc_id = 0; $i = 1; while (file_exists($exportDir . '/' . $exportFile . '_' . $i . '.html')) { $i++; } //only export last version, but in new export new version in document area $wikiFileName = $exportFile . '_' . $i . '.html'; $exportPath = $exportDir . '/' . $wikiFileName; file_put_contents($exportPath, $wikiContents); $doc_id = FileManager::add_document($_course, $groupPath . '/' . $wikiFileName, 'file', filesize($exportPath), $wikiTitle); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId); return $doc_id; // TODO: link to go document area }
} } if ($is_our_server) { if (api_get_setting('service_visio', 'active') == 'true') { //check encryption key $string1 = $_GET['course_code'] . $_GET['user_id'] . gmdate('Ymd') . $_configuration['security_key']; $string2 = $_GET['course_code'] . $_GET['user_id'] . (gmdate('Ymd') - 1) . $_configuration['security_key']; if (md5($string1) == $_GET['checker'] or md5($string2) == $_GET['checker']) { $course_info = api_get_course_info($_GET['course_code']); $target = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/audio/'; $basename = basename($_FILES['file']['name']); $target = $target . $basename; if (!move_uploaded_file($_FILES['file']['tmp_name'], $target)) { error_log(__FILE__ . ':' . __LINE__ . ': File upload to ' . $target . ' failed', 0); } else { $id = FileManager::add_document($course_info, '/audio/' . $basename, 'file', filesize($target), $basename); if ($id !== false) { $res = api_item_property_update($course_info, TOOL_DOCUMENT, $id, 'DocumentAdded', $_GET['user_id']); if ($res === false) { error_log(__FILE__ . ':' . __LINE__ . ': Something went wrong with item properties update of ' . $target, 0); } else { //make sound invisible? //$res = api_item_property_update($course_info,TOOL_DOCUMENT,$id,'invisible',$_GET['user_id']); } } else { error_log(__FILE__ . ':' . __LINE__ . ': Could not create document record for document ' . $target, 0); } } } else { error_log(__FILE__ . ':' . __LINE__ . ': Attempting to save file but hash check did not suceed (hacking attempt?)', 0); }
/** * changes the exercise sound file * * @author - Olivier Brouckaert * @param - string $sound - exercise sound file * @param - string $delete - ask to delete the file */ public function updateSound($sound, $delete) { global $audioPath, $documentPath; $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); if ($sound['size'] && (strstr($sound['type'], 'audio') || strstr($sound['type'], 'video'))) { $this->sound = $sound['name']; if (@move_uploaded_file($sound['tmp_name'], $audioPath . '/' . $this->sound)) { $query = "SELECT 1 FROM {$TBL_DOCUMENT} WHERE c_id = " . $this->course_id . " AND path='" . str_replace($documentPath, '', $audioPath) . '/' . $this->sound . "'"; $result = Database::query($query); if (!Database::num_rows($result)) { $id = FileManager::add_document($this->course, str_replace($documentPath, '', $audioPath) . '/' . $this->sound, 'file', $sound['size'], $sound['name']); api_item_property_update($this->course, TOOL_DOCUMENT, $id, 'DocumentAdded', api_get_user_id()); FileManager::item_property_update_on_folder($this->course, str_replace($documentPath, '', $audioPath), api_get_user_id()); } } } elseif ($delete && is_file($audioPath . '/' . $this->sound)) { $this->sound = ''; } }
$title_to_save = str_replace('_', ' ', $title_to_save); } $documentPath = $saveDir . '/' . $webcamname_to_save; //read content $content = file_get_contents('php://input'); if (!$content) { print "ERROR: Failed to read data\n"; exit; } //make a temporal file for get the file size $tmpfname = tempnam("/tmp", "CTF"); $handle = fopen($tmpfname, "w"); fwrite($handle, $content); fclose($handle); // Check if there is enough space in the course to save the file if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) { unlink($tmpfname); die(get_lang('UplNotEnoughSpace')); } //erase temporal file unlink($tmpfname); //add to disk $fh = fopen($documentPath, 'w') or die("can't open file"); fwrite($fh, $content); fclose($fh); //add document to database $doc_id = FileManager::add_document($_course, $webcamdir . '/' . $webcamname_to_save, 'file', filesize($documentPath), $title_to_save); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id); /// $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $documentPath; print "{$url}\n";
} elseif ($currentTool == 'document/editpaint') { $documentPath = $saveDir . '/' . $paintFileName; //add new document to disk file_put_contents($documentPath, $contents); //check path if (!isset($_SESSION['paint_file'])) { api_not_allowed(); die; } if ($_SESSION['paint_file'] == $paintFileName) { $document_id = DocumentManager::get_document_id($_course, $relativeUrlPath . '/' . $paintFileName); FileManager::update_existing_document($_course, $document_id, filesize($documentPath), null); api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], $groupId, null, null, null, $current_session_id); } else { //add a new document $doc_id = FileManager::add_document($_course, $relativeUrlPath . '/' . $paintFileName, 'file', filesize($documentPath), $title); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id); } } //delete temporal file $temp_file_2delete = $_SESSION['temp_realpath_image']; unlink($temp_file_2delete); //Clean sessions and return to Chamilo file list unset($_SESSION['paint_dir']); unset($_SESSION['paint_file']); unset($_SESSION['whereami']); unset($_SESSION['temp_realpath_image']); if (!isset($_SESSION['exit_pixlr'])) { $location = api_get_path(WEB_CODE_PATH) . 'document/document.php'; echo '<script>window.parent.location.href="' . $location . '"</script>'; api_not_allowed(true);
// Disabled by Ivan Tcholakov. //$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content); fputs($fp, $content); fclose($fp); $filepath = $document_data['absolute_parent_path']; if (!is_dir($filepath . 'css')) { mkdir($filepath . 'css', api_get_permissions_for_new_directories()); $doc_id = FileManager::add_document($_course, $dir . 'css', 'folder', 0, 'css'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id(), null, null, null, null, $current_session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, $current_session_id); } if (!is_file($filepath . 'css/frames.css')) { $platform_theme = api_get_setting('stylesheets'); if (file_exists(api_get_path(SYS_CSS_PATH) . 'themes/' . $platform_theme . '/frames.css')) { copy(api_get_path(SYS_CSS_PATH) . 'themes/' . $platform_theme . '/frames.css', $filepath . 'css/frames.css'); $doc_id = FileManager::add_document($_course, $dir . 'css/frames.css', 'file', filesize($filepath . 'css/frames.css'), 'frames.css'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, $current_session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, $current_session_id); } } // "WHAT'S NEW" notification: update table item_property $document_id = DocumentManager::get_document_id($_course, $file); if ($document_id) { FileManager::update_existing_document($_course, $document_id, $file_size, $read_only_flag); api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', api_get_user_id(), null, null, null, null, $current_session_id); // Update parent folders FileManager::item_property_update_on_folder($_course, $dir, api_get_user_id()); header('Location: document.php?id=' . $document_data['parent_id']); exit; } else { $msgError = get_lang('Impossible');
$basename_chat = 'messages-' . $date_now . '_gid-' . $group_id; } else { if (!empty($session_id)) { $basename_chat = 'messages-' . $date_now . '_sid-' . $session_id; } else { $basename_chat = 'messages-' . $date_now; } } if ($reset && $isMaster) { $i = 1; while (file_exists($chat_path . $basename_chat . '-' . $i . '.log.html')) { $i++; } @rename($chat_path . $basename_chat . '.log.html', $chat_path . $basename_chat . '-' . $i . '.log.html'); @fclose(fopen($chat_path . $basename_chat . '.log.html', 'w')); $doc_id = FileManager::add_document($_course, $basepath_chat . '/' . $basename_chat . '-' . $i . '.log.html', 'file', filesize($chat_path . $basename_chat . '-' . $i . '.log.html'), $basename_chat . '-' . $i . '.log.html'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $group_id, null, null, null, $session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], $group_id, null, null, null, $session_id); FileManager::item_property_update_on_folder($_course, $basepath_chat, $_user['user_id']); $doc_id = DocumentManager::get_document_id($_course, $basepath_chat . '/' . $basename_chat . '.log.html'); FileManager::update_existing_document($_course, $doc_id, 0); } $remove = 0; $content = array(); if (file_exists($chat_path . $basename_chat . '.log.html')) { $content = file($chat_path . $basename_chat . '.log.html'); $nbr_lines = sizeof($content); $remove = $nbr_lines - 100; } if ($remove < 0) { $remove = 0;
/** * Restore documents * @param int session id * */ function restore_documents($session_id = 0, $respect_base_content = false, $destination_course_code = '') { $perm = api_get_permissions_for_new_directories(); $course_info = api_get_course_info($destination_course_code); if ($this->course->has_resources(RESOURCE_DOCUMENT)) { $table = Database::get_course_table(TABLE_DOCUMENT); $resources = $this->course->resources; foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { $path = api_get_path(SYS_COURSE_PATH) . $this->course->destination_path . '/'; //$dirs = explode('/', dirname($document->path)); if (empty($document->item_properties[0]['id_session'])) { $my_session_id = 0; } else { $my_session_id = $session_id; } if ($document->file_type == FOLDER) { $visibility = $document->item_properties[0]['visibility']; if (!empty($document->title)) { $title = $document->title; } else { $title = basename($document->path); } $new = substr($document->path, 8); if (!is_dir($path . 'document' . $new)) { $created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0, $path . 'document', $new, $title, $visibility); } } elseif ($document->file_type == DOCUMENT) { //Checking if folder exists in the database otherwise we created it $dir_to_create = dirname($document->path); if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') { if (is_dir($path . dirname($document->path))) { $sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr(dirname($document->path), 9)) . "'"; $res = Database::query($sql); if (Database::num_rows($res) == 0) { //continue; $visibility = $document->item_properties[0]['visibility']; $new = '/' . substr(dirname($document->path), 9); $title = str_replace('/', '', $new); // This code fixes the possibility for a file without a directory entry to be $document_id = FileManager::add_document($course_info, $new, 'folder', 0, $title, null, null, false); api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'FolderCreated', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } } else { //$created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0 , $path.'document', $new, $title, $visibility, true); } } if (file_exists($path . $document->path)) { switch ($this->file_option) { case FILE_OVERWRITE: $origin_path = $this->course->backup_path . '/' . $document->path; if (file_exists($origin_path)) { copy($origin_path, $path . $document->path); $sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'"; $res = Database::query($sql); $count = Database::num_rows($res); if ($count == 0) { $sql = "INSERT INTO {$table} SET\n \t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "',\n \t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n \t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n \t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n \t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n \t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n \t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } else { $obj = Database::fetch_object($res); $sql = "UPDATE " . $table . " SET\n path \t\t= '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'\n WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'"; Database::query($sql); api_item_property_update($course_info, TOOL_DOCUMENT, $obj->id, 'default', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } } //Replace old course code with the new destination code $file_info = pathinfo($path . $document->path); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($path . $document->path); if (UTF8_CONVERT) { $content = utf8_encode($content); } $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $result = file_put_contents($path . $document->path, $content); } $sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path='/" . substr($document->path, 9) . "'"; $res = Database::query($sql); $obj = Database::fetch_object($res); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; $sql = "UPDATE " . $table . " SET comment = '" . self::DBUTF8escapestring($document->comment) . "', title='" . self::DBUTF8escapestring($document->title) . "', size='" . $document->size . "'\n\t\t\t\t\t\t\t\t\t\tWHERE c_id = " . $this->destination_course_id . " AND id = '" . $obj->id . "'"; Database::query($sql); break; case FILE_SKIP: $sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path='/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'"; $res = Database::query($sql); $obj = Database::fetch_object($res); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; break; case FILE_RENAME: $i = 1; $ext = explode('.', basename($document->path)); if (count($ext) > 1) { $ext = array_pop($ext); $file_name_no_ext = substr($document->path, 0, -(strlen($ext) + 1)); $ext = '.' . $ext; } else { $ext = ''; $file_name_no_ext = $document->path; } $new_file_name = $file_name_no_ext . '_' . $i . $ext; $file_exists = file_exists($path . $new_file_name); while ($file_exists) { $i++; $new_file_name = $file_name_no_ext . '_' . $i . $ext; $file_exists = file_exists($path . $new_file_name); } if (!empty($session_id)) { $document_path = explode('/', $document->path, 3); $course_path = $path; // "/var/www/wiener/courses/" $orig_base_folder = $document_path[1]; $orig_base_path = $course_path . $document_path[0] . '/' . $document_path[1]; if (is_dir($orig_base_path)) { $new_base_foldername = $orig_base_folder; // e.g: "carpeta1" $new_base_path = $orig_base_path; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1" if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { unset($_SESSION['new_base_foldername']); unset($_SESSION['orig_base_foldername']); unset($_SESSION['new_base_path']); } $folder_exists = file_exists($new_base_path); if ($folder_exists) { $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session $x = ''; while ($folder_exists) { $x = $x + 1; $new_base_foldername = $document_path[1] . '_' . $x; $new_base_path = $orig_base_path . '_' . $x; if ($_SESSION['new_base_foldername'] == $new_base_foldername) { break; } $folder_exists = file_exists($new_base_path); } $_SESSION['new_base_foldername'] = $new_base_foldername; $_SESSION['new_base_path'] = $new_base_path; } if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { $new_base_foldername = $_SESSION['new_base_foldername']; $new_base_path = $_SESSION['new_base_path']; } $dest_document_path = $new_base_path . '/' . $document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" //$dest_filename = basename($dest_document_path); // e.g: "collaborative.png" $base_path_document = $course_path . $document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" $path_title = '/' . $new_base_foldername . '/' . $document_path[2]; api_copy_folder_course_session($basedir_dest_path, $base_path_document, $session_id, $course_info, $document, $this->course_origin_id); if (file_exists($course_path . $document->path)) { copy($course_path . $document->path, $dest_document_path); } //Replace old course code with the new destination code see BT#1985 if (file_exists($dest_document_path)) { $file_info = pathinfo($dest_document_path); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($dest_document_path); if (UTF8_CONVERT) { $content = utf8_encode($content); } $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $result = file_put_contents($dest_document_path, $content); } } $sql = "INSERT INTO {$table} SET\n\t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '{$path_title}',\n\t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring(basename($path_title)) . "' ,\n\t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } else { if (file_exists($path . $document->path)) { copy($path . $document->path, $path . $new_file_name); } //Replace old course code with the new destination code see BT#1985 if (file_exists($path . $new_file_name)) { $file_info = pathinfo($path . $new_file_name); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($path . $new_file_name); if (UTF8_CONVERT) { $content = utf8_encode($content); } $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $result = file_put_contents($path . $new_file_name, $content); } } $sql = "INSERT INTO " . $table . " SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($new_file_name, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } } else { copy($this->course->backup_path . '/' . $document->path, $path . $new_file_name); //Replace old course code with the new destination code see BT#1985 if (file_exists($path . $new_file_name)) { $file_info = pathinfo($path . $new_file_name); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($path . $new_file_name); if (UTF8_CONVERT) { $content = utf8_encode($content); } $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $result = file_put_contents($path . $new_file_name, $content); } } $sql = "INSERT INTO " . $table . " SET\n\t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($new_file_name, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } break; } // end switch } else { // end if file exists //make sure the source file actually exists if (is_file($this->course->backup_path . '/' . $document->path) && is_readable($this->course->backup_path . '/' . $document->path) && is_dir(dirname($path . $document->path)) && is_writeable(dirname($path . $document->path))) { //echo 'Copying'; copy($this->course->backup_path . '/' . $document->path, $path . $document->path); //Replace old course code with the new destination code see BT#1985 if (file_exists($path . $document->path)) { $file_info = pathinfo($path . $document->path); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($path . $document->path); if (UTF8_CONVERT) { $content = utf8_encode($content); } $content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']); $result = file_put_contents($path . $document->path, $content); } } $sql = "INSERT INTO " . $table . " SET\n\t\t\t\t\t\t\t c_id = " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t path = '/" . substr($document->path, 9) . "',\n\t\t\t\t\t\t\t comment = '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t title = '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t filetype='" . $document->file_type . "',\n\t\t\t\t\t\t\t size= '" . $document->size . "',\n\t\t\t\t\t\t\t session_id = '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id); } else { //echo 'not Copying'; if (is_file($this->course->backup_path . '/' . $document->path) && is_readable($this->course->backup_path . '/' . $document->path)) { error_log('Course copy generated an ignoreable error while trying to copy ' . $this->course->backup_path . '/' . $document->path . ': file not found'); } if (!is_dir(dirname($path . $document->path))) { error_log('Course copy generated an ignoreable error while trying to copy to ' . dirname($path . $document->path) . ': directory not found'); } if (!is_writeable(dirname($path . $document->path))) { error_log('Course copy generated an ignoreable error while trying to copy to ' . dirname($path . $document->path) . ': directory not writeable'); } } } // end file doesn't exist } else { /*$sql = "SELECT id FROM ".$table." WHERE path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; $res = Database::query($sql); if( Database::num_rows($res)> 0) { $obj = Database::fetch_object($res); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; } else { $sql = "INSERT INTO ".$table." SET path = '/".self::DBUTF8escapestring(substr($document->path, 9))."', comment = '".self::DBUTF8escapestring($document->comment)."', title = '".self::DBUTF8escapestring($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."'"; Database::query($sql); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); }*/ } // end folder } // end for each // Delete sessions for the copy the new folder in session unset($_SESSION['new_base_foldername']); unset($_SESSION['orig_base_foldername']); unset($_SESSION['new_base_path']); } }
function check_and_create_resource_directory($repository_path, $resource_directory, $resource_directory_name) { global $permissions_for_new_directories; $resource_directory_full_path = substr($repository_path, 0, strlen($repository_path) - 1) . $resource_directory . '/'; if (!is_dir($resource_directory_full_path)) { if (@mkdir($resource_directory_full_path, $permissions_for_new_directories)) { // While we are in a course: Registering the newly created folder in the course's database. if (api_is_in_course()) { global $_user; $_course = api_get_course_info(); global $group_properties, $to_group_id; $group_directory = !empty($group_properties['directory']) ? $group_properties['directory'] : ''; $doc_id = FileManager::add_document($_course, $group_directory . $resource_directory, 'folder', 0, $resource_directory_name); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id); } return true; } return false; } return true; }
if (!is_dir($filepath . 'css')) { mkdir($filepath . 'css', api_get_permissions_for_new_directories()); $doc_id = FileManager::add_document($_course, $dir . 'css', 'folder', 0, 'css'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id); } if (!is_file($filepath . 'css/frames.css')) { // Make a copy of the current css for the new document copy(api_get_path(SYS_CSS_PATH) . 'themes/' . api_get_setting('stylesheets') . '/frames.css', $filepath . 'css/frames.css'); $doc_id = FileManager::add_document($_course, $dir . 'css/frames.css', 'file', filesize($filepath . 'css/frames.css'), 'frames.css'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], null, null, null, null, $current_session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id); } $file_size = filesize($filepath . $filename . '.' . $extension); $save_file_path = $dir . $filename . '.' . $extension; $document_id = FileManager::add_document($_course, $save_file_path, 'file', $file_size, $title, null, $readonly); if ($document_id) { api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id); // Update parent folders FileManager::item_property_update_on_folder($_course, $dir, $_user['user_id']); $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; $new_comment = Database::escape_string($new_comment); $new_title = isset($_POST['title']) ? trim($_POST['title']) : ''; $new_title = htmlspecialchars($new_title); $new_title = Database::escape_string($new_title); if ($new_comment || $new_title) { $ct = ''; if ($new_comment) { $ct .= ", comment='{$new_comment}'"; } if ($new_title) {
$message = str_replace($emoticon_text203, $emoticon_img203, $message); $message = str_replace($emoticon_text204, $emoticon_img204, $message); $timeNow = date('d/m/y H:i:s'); $basename_chat = ''; if (!empty($group_id)) { $basename_chat = 'messages-' . $date_now . '_gid-' . $group_id; } elseif (!empty($session_id)) { $basename_chat = 'messages-' . $date_now . '_sid-' . $session_id; } else { $basename_chat = 'messages-' . $date_now; } if (!api_is_anonymous()) { if (!empty($message)) { $message = Text::make_clickable($message); if (!file_exists($chat_path . $basename_chat . '.log.html')) { $doc_id = FileManager::add_document($_course, $basepath_chat . '/' . $basename_chat . '.log.html', 'file', 0, $basename_chat . '.log.html'); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $group_id, null, null, null, $session_id); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], $group_id, null, null, null, $session_id); FileManager::item_property_update_on_folder($_course, $basepath_chat, $_user['user_id']); } else { $doc_id = DocumentManager::get_document_id($_course, $basepath_chat . '/' . $basename_chat . '.log.html'); } $fp = fopen($chat_path . $basename_chat . '.log.html', 'a'); if ($isMaster) { $photo = '<img src="' . api_get_path(WEB_IMG_PATH) . 'teachers.gif" alt="' . get_lang('Teacher') . '" width="11" height="11" align="top" title="' . get_lang('Teacher') . '" />'; fputs($fp, '<span style="color:#999; font-size: smaller;">[' . $timeNow . ']</span>' . $photo . ' <span id="chat_login_name"><b>' . api_get_person_name($firstname, $lastname) . '</b></span> : <i>' . $message . '</i><br />' . "\n"); } else { $photo = '<img src="' . api_get_path(WEB_IMG_PATH) . 'students.gif" alt="' . get_lang('Student') . '" width="11" height="11" align="top" title="' . get_lang('Student') . '" />'; fputs($fp, '<span style="color:#999; font-size: smaller;">[' . $timeNow . ']</span>' . $photo . ' <b>' . api_get_person_name($firstname, $lastname) . '</b> : <i>' . $message . '</i><br />' . "\n"); } fclose($fp);