Jelajahi Sumber

Replace global $_course with api_get_course_info()

Julio Montoya 9 tahun lalu
induk
melakukan
b3a020a62f

+ 6 - 2
main/document/create_audio.php

@@ -357,7 +357,10 @@ function downloadMP3_google($filepath, $dir)
 		echo '<script>window.location.href="'.$location.'"</script>';
 		return;
 	}
-    global $_course, $_user;
+
+	$_course = api_get_course_info();
+	$_user = api_get_user_info();
+
 	$clean_title=trim($_POST['title']);
 	$clean_text=trim($_POST['text']);
 	if(empty($clean_title) || empty($clean_text)){
@@ -464,7 +467,8 @@ function downloadMP3_pediaphon($filepath, $dir)
 		echo '<script>window.location.href="'.$location.'"</script>';
 		return;
 	}
-    global $_course, $_user;
+	$_course = api_get_course_info();
+	$_user = api_get_user_info();
 	$clean_title=trim($_POST['title']);
 	$clean_title= Database::escape_string($clean_title);
 	$clean_text=trim($_POST['text']);

+ 2 - 1
main/exercice/export/aiken/aiken_import.inc.php

@@ -58,7 +58,8 @@ function aiken_display_form($msg = '') {
  * @return bool True on success, false on failure
  */
 function get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath) {
-    global $_course, $_user;
+    $_course = api_get_course_info();
+    $_user = api_get_user_info();
     //Check if the file is valid (not to big and exists)
     if (!isset ($_FILES['userFile']) || !is_uploaded_file($_FILES['userFile']['tmp_name'])) {
         // upload failed

+ 1 - 1
main/exercice/hotpotatoes.lib.php

@@ -140,7 +140,7 @@ function ReadFileCont($full_file_path)
 function WriteFileCont($full_file_path, $content)
 {
     // Check if this is not an attack, trying to get into other directories or something like that.
-    global $_course;
+    $_course = api_get_course_info();
     if (Security::check_abs_path(dirname($full_file_path).'/', api_get_path(SYS_COURSE_PATH).$_course['path'].'/')) {
         // Check if this is not an attack, trying to upload a php file or something like that.
         if (basename($full_file_path) != Security::filter_filename(basename($full_file_path))) {

+ 1 - 1
main/gradebook/lib/gradebook_result.class.php

@@ -284,7 +284,7 @@ class GradeBookResult
      */
     public function exportCompleteReportDOC($data)
     {
-        global $_course;
+        $_course = api_get_course_info();
         $filename = 'gb_results_'.$_course['code'].'_'.gmdate('YmdGis');
         $filepath = api_get_path(SYS_ARCHIVE_PATH).$filename;
         //build the results

+ 1 - 1
main/inc/lib/online.inc.php

@@ -20,7 +20,7 @@
 use ChamiloSession as Session;
 
 function LoginCheck($uid) {
-	global $_course, $_configuration;
+	$_course = api_get_course_info();
 	$uid = (int) $uid;
 	$online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
     if (!empty($uid)) {

+ 1 - 1
main/inc/lib/text.lib.php

@@ -732,7 +732,7 @@ function _text_parse_tool($input) {
  * @author Patrick Cool <patrick.cool@UGent.be> Ghent University
  */
 function latex_gif_renderer($latex_code) {
-    global $_course;
+    $_course = api_get_course_info();
 
     // Setting the paths and filenames
     $mimetex_path = api_get_path(LIBRARY_PATH).'mimetex/';

+ 12 - 9
main/inc/lib/thematic.lib.php

@@ -276,7 +276,7 @@ class Thematic
      */
     public function thematic_save()
     {
-        global $_course;
+        $_course = api_get_course_info();
         // definition database table
         $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
 
@@ -676,7 +676,7 @@ class Thematic
      */
     public function thematic_advance_save()
     {
-        global $_course;
+        $_course = api_get_course_info();
 
         // definition database table
         $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
@@ -724,7 +724,7 @@ class Thematic
      */
     public function thematic_advance_destroy($thematic_advance_id)
     {
-        global $_course;
+        $_course = api_get_course_info();
         $course_id = api_get_course_int_id();
 
         // definition database table
@@ -836,7 +836,7 @@ class Thematic
      */
     public function thematic_plan_save()
     {
-        global $_course;
+        $_course = api_get_course_info();
         // definition database table
         $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
 
@@ -923,7 +923,7 @@ class Thematic
      */
     public function thematic_plan_destroy($thematic_id, $description_type)
     {
-        global $_course;
+        $_course = api_get_course_info();
         // definition database table
         $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
 
@@ -940,7 +940,10 @@ class Thematic
 
         // delete
         $sql = "DELETE FROM $tbl_thematic_plan
-                WHERE c_id = $course_id AND thematic_id = $thematic_id AND description_type = $description_type ";
+                WHERE
+                    c_id = $course_id AND
+                    thematic_id = $thematic_id AND
+                    description_type = $description_type ";
         $result = Database::query($sql);
         $affected_rows = Database::affected_rows($result);
         if ($affected_rows) {
@@ -996,10 +999,10 @@ class Thematic
      */
     public function update_done_thematic_advances($thematic_advance_id)
     {
-        global $_course;
-        $thematic_data         = $this->get_thematic_list(null, api_get_course_id());
+        $_course = api_get_course_info();
+        $thematic_data = $this->get_thematic_list(null, api_get_course_id());
         $thematic_advance_data = $this->get_thematic_advance_list(null, api_get_course_id(), true);
-        $tbl_thematic_advance  = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
+        $tbl_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
 
         $affected_rows = 0;
         $user_id       = api_get_user_id();

+ 1 - 1
main/lang/dutch/trad4all.inc.php

@@ -5503,4 +5503,4 @@ $List = "Lijst";
 $CourseDescriptions = "Cursus beschrijvingen";
 $GlossaryTermUpdated = "Termen aangepast";
 $DeleteAllGlossaryTerms = "Verwijder alle termen";
-?>
+?>

+ 2 - 2
main/lang/english/trad4all.inc.php

@@ -5832,7 +5832,7 @@ $Item = "Item";
 $ConfigureDashboardPlugin = "Configure Dashboard Plugin";
 $EditBlocks = "Edit blocks";
 $Never = "Never";
-$YourAccountIsActiveYouCanLoginAndCheckYourCourses = "Dear user, 
+$YourAccountIsActiveYouCanLoginAndCheckYourCourses = "Dear user,
 
 Your account has now been activated on the platform. Please login and enjoy your courses.";
 $SessionFields = "Session fields";
@@ -7472,4 +7472,4 @@ $AddAttachment = "Add attachment";
 $FieldTypeOnlyLetters = "Text only letters";
 $FieldTypeAlphanumeric = "Text only alphanumeric characters";
 $OnlyLetters = "Only letters";
-?>
+?>

+ 10 - 7
main/newscorm/learnpath.class.php

@@ -492,6 +492,7 @@ class learnpath
             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();
         $parent = intval($parent);
         $previous = intval($previous);
         $id = intval($id);
@@ -633,7 +634,6 @@ class learnpath
             // Upload audio.
             if (!empty($_FILES['mp3']['name'])) {
                 // Create the audio folder if it does not exist yet.
-                global $_course;
                 $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
                 if (!is_dir($filepath . 'audio')) {
                     mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
@@ -1246,6 +1246,8 @@ class learnpath
         $url = ''
     ) {
         $course_id = api_get_course_int_id();
+        $_course = api_get_course_info();
+
         if ($this->debug > 0) {
             error_log('New LP - In learnpath::edit_item()', 0);
         }
@@ -1263,7 +1265,6 @@ class learnpath
         $audio_update_sql = '';
         if (is_array($audio) && !empty ($audio['tmp_name']) && $audio['error'] === 0) {
             // Create the audio folder if it does not exist yet.
-            global $_course;
             $filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
             if (!is_dir($filepath . 'audio')) {
                 mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
@@ -2172,7 +2173,7 @@ class learnpath
     public function get_mediaplayer($autostart = 'true')
     {
         $course_id = api_get_course_int_id();
-        global $_course;
+        $_course = api_get_course_info();
         $tbl_lp_item 		= Database :: get_course_table(TABLE_LP_ITEM);
         $tbl_lp_item_view 	= Database :: get_course_table(TABLE_LP_ITEM_VIEW);
 
@@ -5441,10 +5442,12 @@ class learnpath
     public function overview()
     {
         $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
+        $_course = api_get_course_info();
+
         if ($this->debug > 0) {
             error_log('New LP - In learnpath::overview()', 0);
         }
-        global $_course;
+
         $_SESSION['gradebook'] = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
         $return = '';
 
@@ -6265,7 +6268,7 @@ class learnpath
      */
     public function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
     {
-        global $_course; // It is temporary.
+        $_course = api_get_course_info();
         $course_id = api_get_course_int_id();
         $return = '';
         $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
@@ -7302,8 +7305,9 @@ class learnpath
     public function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
     {
         $course_id = api_get_course_int_id();
+        $_course = api_get_course_info();
         $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
-        $tbl_doc 	 = Database :: get_course_table(TABLE_DOCUMENT);
+        $tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
 
         $no_display_edit_textarea = false;
 
@@ -7556,7 +7560,6 @@ class learnpath
                                 $relative_path = $relative_path . '/';
                             }
                         } else {
-                            global $_course;
                             $result = $this->generate_lp_folder($_course);
                             $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
                             $relative_prefix = '../../';

+ 1 - 1
main/newscorm/lp_admin_view.php

@@ -34,6 +34,7 @@ $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
 $isStudentView  = isset($_REQUEST['isStudentView']) ? (int) $_REQUEST['isStudentView'] : null;
 $learnpath_id   = (int) $_REQUEST['lp_id'];
 $submit			= isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
+$_course = api_get_course_info();
 
 /* MAIN CODE */
 
@@ -110,7 +111,6 @@ if (isset($_POST['save_audio'])) {
             $lp_item_id = str_ireplace('mp3file', '', $key);
 
             // Create the audio folder if it does not exist yet.
-            global $_course;
             DocumentManager::createDefaultAudioFolder($_course);
 
             // Check if file already exits into document/audio/

+ 4 - 3
main/newscorm/openoffice_document.class.php

@@ -44,7 +44,7 @@ abstract class OpenofficeDocument extends learnpath
      */
     public function convert_document($file, $action_after_conversion = 'make_lp')
     {
-        global $_course;
+        $_course = api_get_course_info();
         $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME);
         // Create the directory
         $result = $this->generate_lp_folder($_course, $this->file_name);
@@ -219,8 +219,9 @@ abstract class OpenofficeDocument extends learnpath
      * @param string $convertedTitle
      * @return bool
      */
-    function convertCopyDocument($originalPath, $convertedPath, $convertedTitle){
-        global $_course;
+    function convertCopyDocument($originalPath, $convertedPath, $convertedTitle)
+    {
+        $_course = api_get_course_info();
         $ids = array();
         $originalPathInfo = pathinfo($originalPath);
         $convertedPathInfo = pathinfo($convertedPath);

+ 4 - 3
main/newscorm/openoffice_presentation.class.php

@@ -33,7 +33,7 @@ class OpenofficePresentation extends OpenofficeDocument
 
     public function make_lp($files = array())
     {
-        global $_course;
+        $_course = api_get_course_info();
         $previous = 0;
         $i = 0;
 
@@ -217,9 +217,10 @@ class OpenofficePresentation extends OpenofficeDocument
 
     function add_docs_to_visio($files = array())
     {
-        global $_course;
+        $_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).
+            // '||' is used as separator between slide name (with accents) and file name (without accents).
+            list($slide_name,$file_name) = explode('||',$file);
             $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset);
             $slide_name = str_replace('&rsquo;', '\'', $slide_name);
             $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset);

+ 49 - 16
main/newscorm/openoffice_text.class.php

@@ -44,9 +44,9 @@ class OpenofficeText extends OpenofficeDocument {
      * @param	array	The files that will compose the generated learning path. Unused so far.
      * @return	boolean	False if file does not exit. Nothing otherwise.
      */
-    function make_lp($files = array()) {
-
-        global $_course;
+    function make_lp($files = array())
+    {
+        $_course = api_get_course_info();
         // We get a content where ||page_break|| indicates where the page is broken.
         if (!file_exists($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html')) { return false; }
         $content = file_get_contents($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html');
@@ -77,7 +77,7 @@ class OpenofficeText extends OpenofficeDocument {
         $my_style = api_get_setting('stylesheets');
         if (empty($my_style)) { $my_style = 'chamilo'; }
         $style_to_import = "<style type=\"text/css\">\r\n";
-        $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/default.css";'."\n";        
+        $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/default.css";'."\n";
         $style_to_import .= "</style>\r\n";
         $header = preg_replace("|</head>|i", "\r\n$style_to_import\r\n\\0", $header);
 
@@ -98,10 +98,9 @@ class OpenofficeText extends OpenofficeDocument {
      * @param	string	Content
      * @return	void
      */
-    function dealPerChapter($header, $content) {
-
-        global $_course;
-
+    function dealPerChapter($header, $content)
+    {
+        $_course = api_get_course_info();
         $content = str_replace('||page_break||', '', $content);
 
         // Get all the h1.
@@ -116,14 +115,12 @@ class OpenofficeText extends OpenofficeDocument {
                 $matches[1][$new_index] = $matches_temp[1][$i];
                 $new_index++;
             }
-
         }
 
         // Add intro item.
         $intro_content = substr($content, 0, strpos($content, $matches[0][0]));
         $items_to_create[get_lang('Introduction')] = $intro_content;
 
-
         for ($i = 0; $i < count($matches[0]); $i++) {
 
             if (empty($matches[1][$i]))
@@ -154,13 +151,31 @@ class OpenofficeText extends OpenofficeDocument {
             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());
+                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 = strip_tags(nl2br($item_title));
                 $slide_name = str_replace(array("\r\n", "\r", "\n"), '', $slide_name);
                 $slide_name = html_entity_decode($slide_name);
-                $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
+                $previous = learnpath::add_item(
+                    0,
+                    $previous,
+                    'document',
+                    $document_id,
+                    $slide_name,
+                    ''
+                );
                 if ($this->first_item == 0) {
                     $this->first_item = $previous;
                 }
@@ -174,8 +189,9 @@ class OpenofficeText extends OpenofficeDocument {
      * @param	string	Page body
      * @return	void
      */
-    function dealPerPage($header, $body) {
-        global $_course;
+    function dealPerPage($header, $body)
+    {
+        $_course = api_get_course_info();
         // Split document to pages.
         $pages = explode('||page_break||', $body);
 
@@ -192,14 +208,31 @@ class OpenofficeText extends OpenofficeDocument {
             fwrite($handle, $page_content);
             fclose($handle);
 
-            $document_id = add_document($_course, $this->created_dir.$html_file, 'file', filesize($this->base_work_dir.$this->created_dir.$html_file), $html_file);
+            $document_id = 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());
+                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;

+ 11 - 10
main/newscorm/openoffice_text_document.class.php

@@ -40,9 +40,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument {
      * @param	array	The files that will compose the generated learning path. Unused so far.
      * @return	boolean	False if file does not exit. Nothing otherwise.
      */
-    public function make_lp($files = array()) {
-
-        global $_course;
+    public function make_lp($files = array())
+    {
+        $_course = api_get_course_info();
         // We get a content where ||page_break|| indicates where the page is broken.
         if (!file_exists($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html')) { return false; }
         $content = file_get_contents($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html');
@@ -73,7 +73,7 @@ class OpenOfficeTextDocument extends OpenofficeDocument {
         $my_style = api_get_setting('stylesheets');
         if (empty($my_style)) { $my_style = 'chamilo'; }
         $style_to_import = "<style type=\"text/css\">\r\n";
-        $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/default.css";'."\n";        
+        $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/default.css";'."\n";
         $style_to_import .= "</style>\r\n";
         $header = preg_replace("|</head>|i", "\r\n$style_to_import\r\n\\0", $header);
 
@@ -94,9 +94,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument {
      * @param	string	Content
      * @return	void
      */
-    function dealPerChapter($header, $content) {
-
-        global $_course;
+    function dealPerChapter($header, $content)
+    {
+        $_course = api_get_course_info();
 
         $content = str_replace('||page_break||', '', $content);
 
@@ -166,8 +166,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument {
      * @param	string	Page body
      * @return	void
      */
-    function dealPerPage($header, $body) {
-        global $_course;
+    function dealPerPage($header, $body)
+    {
+        $_course = api_get_course_info();
         // Split document to pages.
         $pages = explode('||page_break||', $body);
 
@@ -293,7 +294,7 @@ class OpenOfficeTextDocument extends OpenofficeDocument {
             if (!$defined_width) {
 
                 $image_size = api_getimagesize($this->base_work_dir.$this->created_dir.'/'.$image);
-                $img_width  = $image_size['width']; 
+                $img_width  = $image_size['width'];
                 $img_height = $image_size['height'];
 
                 $new_width = $max_width - 10;