diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 922575a98b..56b197ac53 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -412,7 +412,7 @@ function handle_uploaded_document( ); // Redo visibility - api_set_default_visibility(TOOL_DOCUMENT, $documentId); + api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo); } else { // There might be cases where the file exists on disk but there is no registration of that in the database // In this case, and if we are in overwrite mode, overwrite and create the db record @@ -445,7 +445,7 @@ function handle_uploaded_document( ); // Redo visibility - api_set_default_visibility(TOOL_DOCUMENT, $documentId); + api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo); } } @@ -492,7 +492,7 @@ function handle_uploaded_document( ); // Redo visibility - api_set_default_visibility(TOOL_DOCUMENT, $documentId); + api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo); } // If the file is in a folder, we need to update all parent folders item_property_update_on_folder($courseInfo, $uploadPath, $userId); @@ -569,7 +569,7 @@ function handle_uploaded_document( ); // Redo visibility - api_set_default_visibility(TOOL_DOCUMENT, $documentId); + api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo); } // If the file is in a folder, we need to update all parent folders @@ -631,7 +631,7 @@ function handle_uploaded_document( $sessionId ); // Redo visibility - api_set_default_visibility(TOOL_DOCUMENT, $documentId); + api_set_default_visibility(TOOL_DOCUMENT, $documentId, null, $courseInfo); } // If the file is in a folder, we need to update all parent folders @@ -1237,7 +1237,7 @@ function add_document( Database::query($sql); if ($save_visibility) { - api_set_default_visibility($documentId, TOOL_DOCUMENT, $group_id); + api_set_default_visibility($documentId, TOOL_DOCUMENT, $group_id, $_course); } return $documentId; diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index aaca56f572..a667ddeca9 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -488,12 +488,12 @@ class learnpath $prerequisites = 0, $max_time_allowed = 0 ) { - $course_id = api_get_course_int_id(); + $course_id = $this->course_info['real_id']; if ($this->debug > 0) { error_log('New LP - In learnpath::add_item(' . $parent . ',' . $previous . ',' . $type . ',' . $id . ',' . $title . ')', 0); } $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM); - $_course = api_get_course_info(); + $_course = $this->course_info; $parent = intval($parent); $previous = intval($previous); $id = intval($id); @@ -567,7 +567,7 @@ class learnpath $max_score = Database :: result($rsQuiz, 0, 0); // Disabling the exercise if we add it inside a LP - $exercise = new Exercise(); + $exercise = new Exercise($course_id); $exercise->read($id); $exercise->disable(); $exercise->save(); @@ -710,7 +710,7 @@ class learnpath * @return integer The new learnpath ID on success, 0 on failure */ public static function add_lp( - $course, + $courseCode, $name, $description = '', $learnpath = 'guess', @@ -721,7 +721,15 @@ class learnpath $categoryId = 0 ) { global $charset; - $course_id = api_get_course_int_id(); + + if (!empty($courseCode)) { + $courseInfo = api_get_course_info($courseCode); + $course_id = $courseInfo['real_id']; + } else { + $course_id = api_get_course_int_id(); + $courseInfo = api_get_course_info(); + } + $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN); // Check course code exists. // Check lp_name doesn't exist, otherwise append something. @@ -819,16 +827,15 @@ class learnpath $sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id"; Database::query($sql); - $course_info = api_get_course_info(); // Insert into item_property. api_item_property_update( - $course_info, + $courseInfo, TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id() ); - api_set_default_visibility($id, TOOL_LEARNPATH); + api_set_default_visibility($id, TOOL_LEARNPATH, 0, $courseInfo); return $id; } break; @@ -985,14 +992,17 @@ class learnpath /** * Static admin function allowing removal of a learnpath - * @param string Course code + * @param array $courseInfo * @param integer Learnpath ID * @param string Whether to delete data or keep it (default: 'keep', others: 'remove') * @return boolean True on success, false on failure (might change that to return number of elements deleted) */ - public function delete($course = null, $id = null, $delete = 'keep') + public function delete($courseInfo = null, $id = null, $delete = 'keep') { $course_id = api_get_course_int_id(); + if (!empty($courseInfo)) { + $course_id = isset($courseInfo['real_id']) ? $courseInfo['real_id'] : $course_id; + } // TODO: Implement a way of getting this to work when the current object is not set. // In clear: implement this in the item class as well (abstract class) and use the given ID in queries. @@ -3219,7 +3229,7 @@ class learnpath return $html; } - /** + /** * Returns an HTML-formatted string ready to display with teacher buttons * in LP view menu * @return string HTML TOC ready to display @@ -5623,13 +5633,13 @@ class learnpath $edit_icon .= ''; if ( - !in_array($arrLP[$i]['item_type'], ['forum', 'thread']) + !in_array($arrLP[$i]['item_type'], ['forum', 'thread']) ) { if ( - $this->items[$arrLP[$i]['id']]->getForumThread( - $this->course_int_id, - $this->lp_session_id - ) + $this->items[$arrLP[$i]['id']]->getForumThread( + $this->course_int_id, + $this->lp_session_id + ) ) { $forumIcon = Display::url( Display::return_icon('forum.png', get_lang('CreateForum'), [], ICON_SIZE_TINY), @@ -5638,10 +5648,10 @@ class learnpath ); } else { $forumIconUrl = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([ - 'action' => 'create_forum', - 'id' => $arrLP[$i]['id'], - 'lp_id' => $this->lp_id - ]); + 'action' => 'create_forum', + 'id' => $arrLP[$i]['id'], + 'lp_id' => $this->lp_id + ]); $forumIcon = Display::url( Display::return_icon('forum.png', get_lang('CreateForum'), [], ICON_SIZE_TINY), $forumIconUrl, @@ -5670,7 +5680,7 @@ class learnpath } if ($update_audio != 'true') { $row = $move_icon . ' ' . $icon . - Display::span($title_cut) . + Display::span($title_cut) . Display::tag( 'div', "
$audio $edit_icon $forumIcon $prerequisities_icon $move_item_icon $audio_icon $delete_icon
", @@ -5908,14 +5918,24 @@ class learnpath /** * Create a new document //still needs some finetuning - * @param array $_course + * @param array $courseInfo + * @param string $content + * @param string $title + * @param string $extension + * * @return string */ - public function create_document($_course) + public function create_document($courseInfo, $content = '', $title = '', $extension = 'html') { - $course_id = api_get_course_int_id(); + if (!empty($courseInfo)) { + $course_id = $courseInfo['real_id']; + } else { + $course_id = api_get_course_int_id(); + } + global $charset; - $dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; + $postDir = isset($_POST['dir']) ? $_POST['dir'] : ''; + $dir = isset ($_GET['dir']) ? $_GET['dir'] : $postDir; // Please, do not modify this dirname formatting. // Please, do not modify this dirname formatting. if (strstr($dir, '..')) $dir = '/'; @@ -5926,35 +5946,43 @@ class learnpath if ($dir[strlen($dir) - 1] != '/') $dir .= '/'; - $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir; + $filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document' . $dir; if (empty($_POST['dir']) && empty($_GET['dir'])) { //Generates folder - $result = $this->generate_lp_folder($_course); - $dir = $result['dir']; - $filepath = $result['filepath']; + $result = $this->generate_lp_folder($courseInfo); + $dir = $result['dir']; + $filepath = $result['filepath']; } if (!is_dir($filepath)) { - $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/'; + $filepath = api_get_path(SYS_COURSE_PATH) . $courseInfo['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'])); + + $originalTitle = !empty($title) ? $title : $_POST['title']; + if (!empty($title)) { + $title = api_replace_dangerous_char(stripslashes($title)); + } else { + $title = api_replace_dangerous_char(stripslashes($_POST['title'])); + } + $title = disable_dangerous_file($title); $filename = $title; - $content = $_POST['content_lp']; + + $content = isset($content) ? $content : $_POST['content_lp']; $tmp_filename = $filename; $i = 0; - while (file_exists($filepath . $tmp_filename . '.html')) + while (file_exists($filepath . $tmp_filename . '.'.$extension)) $tmp_filename = $filename . '_' . ++ $i; - $filename = $tmp_filename . '.html'; + $filename = $tmp_filename . '.'.$extension; $content = stripslashes($content); $content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH).'courses/', $content); @@ -5962,9 +5990,9 @@ class learnpath // 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); + $content = preg_replace("|(flashvars=\"file=)([^:/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $courseInfo['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); + $content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "$1" . api_get_path(REL_COURSE_PATH) . $courseInfo['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('', '', $content); @@ -5977,7 +6005,7 @@ class learnpath $save_file_path = $dir.$filename; $document_id = add_document( - $_course, + $courseInfo, $save_file_path, 'file', $file_size, @@ -5986,7 +6014,7 @@ class learnpath if ($document_id) { api_item_property_update( - $_course, + $courseInfo, TOOL_DOCUMENT, $document_id, 'DocumentAdded', @@ -5999,7 +6027,7 @@ class learnpath ); $new_comment = (isset($_POST['comment'])) ? trim($_POST['comment']) : ''; - $new_title = (isset($_POST['title'])) ? trim($_POST['title']) : ''; + $new_title = $originalTitle; if ($new_comment || $new_title) { $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT); @@ -6009,8 +6037,9 @@ class learnpath 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); + $sql = "UPDATE " . $tbl_doc ." SET " . substr($ct, 1)." + WHERE c_id = ".$course_id." AND id = " . $document_id; + Database::query($sql); } } return $document_id; @@ -6251,6 +6280,7 @@ class learnpath // Get all the docs. $documents = $this->get_documents(true); + // Get all the exercises. $exercises = $this->get_exercises(); @@ -8551,7 +8581,7 @@ class learnpath $return .= '
  • '; $return .= ''; $return .= '' . - get_lang('NewExercise') . ''; + get_lang('NewExercise') . ''; $return .= '
  • '; // Display hotpotatoes @@ -8624,7 +8654,7 @@ class learnpath } $linksHtmlCode = - '