Julio Montoya 13 years ago
parent
commit
1e4979966c

+ 18 - 14
main/admin/course_add.php

@@ -15,6 +15,7 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
+
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
 require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
@@ -129,12 +130,12 @@ $form->setDefaults($values);
 
 // Validate the form.
 if ($form->validate()) {
-    $course = $form->exportValues();
-    $code = $course['visual_code'];
-    $tutor_name = $teachers[$course['tutor_id']];
-    $teacher_id = $course['tutor_id'];
+    $course          = $form->exportValues();
+    $code            = $course['visual_code'];
+    $tutor_name      = $teachers[$course['tutor_id']];
+    $teacher_id      = $course['tutor_id'];
     $course_teachers = $course['course_teachers'];
-    $test = false;
+    $test            = false;
 
     // The course tutor has been selected in the teachers list so we must remove him to avoid double records in the database.
     foreach ($course_teachers as $key => $value){
@@ -143,13 +144,14 @@ if ($form->validate()) {
             break;
         }
     }
-    $title = $course['title'];
-    $category = $course['category_code'];
-    $department_name = $course['department_name'];
-    $department_url = $course['department_url'];
-    $course_language = $course['course_language'];
-    $exemplary_content = empty($course['exemplary_content']) ? false : true;
-    $disk_quota = $course['disk_quota'];
+    
+    $title              = $course['title'];
+    $category           = $course['category_code'];
+    $department_name    = $course['department_name'];
+    $department_url     = $course['department_url'];
+    $course_language    = $course['course_language'];
+    $exemplary_content  = empty($course['exemplary_content']) ? false : true;
+    $disk_quota         = $course['disk_quota'];
     if (stripos($department_url, 'http://') === false && stripos($department_url, 'https://') === false) {
         $department_url = 'http://'.$department_url;
     }
@@ -157,14 +159,16 @@ if ($form->validate()) {
         $code = generate_course_code(api_substr($title, 0, $maxlength));
     }
     $keys = define_course_keys($code, '', $_configuration['db_prefix']);
+    
     if (count($keys)) {
         $current_course_code 		= $keys['currentCourseCode'];
         $current_course_id 			= $keys['currentCourseId'];                
         $current_course_repository 	= $keys['currentCourseRepository'];
+        
+        //@todo is not set $firstExpirationDelay
         $expiration_date 			= time() + $firstExpirationDelay;
         
         prepare_course_repository($current_course_repository, $current_course_id);
-        //update_Db_course($current_course_db_name);
         $pictures_array = fill_course_repository($current_course_repository, $exemplary_content);        
         $course_id = register_course($current_course_id, $current_course_code, $current_course_repository, '', $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date, $course_teachers);
         fill_Db_course($course_id, $current_course_repository, $course_language, $pictures_array, $exemplary_content);
@@ -172,7 +176,7 @@ if ($form->validate()) {
         $sql = "UPDATE $table_course SET disk_quota = '".$disk_quota."', visibility = '".Database::escape_string($course['visibility'])."', subscribe = '".Database::escape_string($course['subscribe'])."', unsubscribe='".Database::escape_string($course['unsubscribe'])."' WHERE code = '".$current_course_id."'";
         Database::query($sql);
         header('Location: course_list.php');
-        exit ();
+        exit;
     }
 }
 

+ 4 - 4
main/admin/filler.php

@@ -1,4 +1,4 @@
-<?php // $Id: index.php 22269 2009-07-21 15:06:15Z juliomontoya $
+<?php
 /* For licensing terms, see /license.txt */
 /**
 *	Index of the admin tools
@@ -9,17 +9,17 @@
 $language_file=array('admin','tracking');
 
 // resetting the course id
-$cidReset=true;
+$cidReset = true;
 
 // including some necessary chamilo files
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'security.lib.php';
 
 // setting the section (for the tabs)
-$this_section=SECTION_PLATFORM_ADMIN;
+$this_section = SECTION_PLATFORM_ADMIN;
 
 // Access restrictions
 api_protect_admin_script(true);
+
 $nameTools = get_lang('PlatformAdmin');
 
 // setting breadcrumbs

+ 119 - 21
main/inc/lib/add_course.lib.inc.php

@@ -35,21 +35,19 @@ function create_course($wanted_code, $title, $tutor_name, $category_code, $cours
     $keys = define_course_keys($wanted_code, '', $db_prefix);
 
     if (count($keys)) {
-        $visual_code = $keys['currentCourseCode'];
-        $code = $keys['currentCourseId'];
-        $db_name = $keys['currentCourseDbName'];
-        $directory = $keys['currentCourseRepository'];
-        $expiration_date = time() + $first_expiration_delay;
-
-        prepare_course_repository($directory, $code);
-        update_Db_course($db_name);
-        fill_course_repository($directory, $fill_with_exemplary_content);
-        fill_Db_course($db_name, $directory, $course_language, $fill_with_exemplary_content);
-        register_course($code, $visual_code, $directory, $db_name, $tutor_name, $category_code, $title, $course_language, $course_admin_id, $expiration_date);
-
-        return $code;
+        
+        $current_course_code        = $keys['currentCourseCode'];
+        $current_course_id          = $keys['currentCourseId'];                
+        $current_course_repository  = $keys['currentCourseRepository'];
+        
+        $expiration_date = time() + $first_expiration_delay;        
+        
+        prepare_course_repository($current_course_repository, $current_course_id);
+        $pictures_array = fill_course_repository($current_course_repository, $fill_with_exemplary_content);        
+        $course_id = register_course($current_course_id, $current_course_code, $current_course_repository, '', $tutor_name, $category, $title, $course_language, $course_admin_id, $expiration_date);
+        fill_Db_course($course_id, $current_course_repository, $course_language, $pictures_array, $fill_with_exemplary_content);      
+        return $course_id;
     }
-
     return false;
 }
 
@@ -216,6 +214,106 @@ function prepare_course_repository($course_repository, $course_code) {
     return 0;
 };
 
+function get_course_tables() {
+    $tables = array();
+    
+    $tables[]= 'tool';    
+    $tables[]= 'tool_intro';
+
+    // Group tool
+    $tables[]= 'group_info';
+    $tables[]= 'group_category';
+    $tables[]= 'group_rel_user';
+    $tables[]= 'group_rel_tutor';
+
+    $tables[]= 'item_property';
+
+    $tables[]= 'userinfo_content';
+    $tables[]= 'userinfo_def';    
+    $tables[]= 'course_description';
+    $tables[]= 'calendar_event';
+    $tables[]= 'calendar_event_repeat';
+    $tables[]= 'calendar_event_repeat_not';
+    $tables[]= 'calendar_event_attachment';
+    $tables[]= 'announcement';
+    $tables[]= 'announcement_attachment';
+    $tables[]= 'resource';
+    $tables[]= 'student_publication';
+    $tables[]= 'student_publication_assignment';
+    $tables[]= 'document';
+    $tables[]= 'forum_category';
+    $tables[]= 'forum_forum';
+    $tables[]= 'forum_thread';
+    $tables[]= 'forum_post';
+    $tables[]= 'forum_mailcue';
+    $tables[]= 'forum_attachment';
+    $tables[]= 'forum_notification';
+    $tables[]= 'forum_thread_qualify';
+    $tables[]= 'forum_thread_qualify_log';
+    $tables[]= 'link';
+    $tables[]= 'link_category';
+    $tables[]= 'online_connected';
+    $tables[]= 'online_link';
+    $tables[]= 'chat_connected';
+    $tables[]= 'quiz';
+    $tables[]= 'quiz_rel_question';
+    $tables[]= 'quiz_question';
+    $tables[]= 'quiz_answer';
+    $tables[]= 'quiz_question_option';    
+    $tables[]= 'quiz_question_category';
+    $tables[]= 'quiz_question_rel_category';
+    $tables[]= 'dropbox_post';
+    $tables[]= 'dropbox_file';
+    $tables[]= 'dropbox_person';
+    $tables[]= 'dropbox_category';
+    $tables[]= 'dropbox_feedback';
+    $tables[]= 'lp';
+    $tables[]= 'lp_item';
+    $tables[]= 'lp_view';
+    $tables[]= 'lp_item_view';
+    $tables[]= 'lp_iv_interaction';
+    $tables[]= 'lp_iv_objective';
+    $tables[]= 'blog';
+    $tables[]= 'blog_comment';
+    $tables[]= 'blog_post';
+    $tables[]= 'blog_rating';
+    $tables[]= 'blog_rel_user';
+    $tables[]= 'blog_task';
+    $tables[]= 'blog_task_rel_user';
+    $tables[]= 'blog_attachment';
+    $tables[]= 'permission_group';
+    $tables[]= 'permission_user';
+    $tables[]= 'permission_task';
+    $tables[]= 'role';
+    $tables[]= 'role_group';
+    $tables[]= 'role_permissions';
+    $tables[]= 'role_user';
+    $tables[]= 'survey';
+    $tables[]= 'survey_question';
+    $tables[]= 'survey_question_option';
+    $tables[]= 'survey_invitation';
+    $tables[]= 'survey_answer';
+    $tables[]= 'survey_group';
+    $tables[]= 'wiki';
+    $tables[]= 'wiki_conf';
+    $tables[]= 'wiki_discuss';
+    $tables[]= 'wiki_mailcue';
+    //$tables[]= 'audiorecorder';
+    $tables[]= 'course_setting';
+    $tables[]= 'glossary';
+    $tables[]= 'notebook';
+    $tables[]= 'attendance';
+    $tables[]= 'attendance_sheet';
+    $tables[]= 'attendance_calendar';
+    $tables[]= 'attendance_result';
+    $tables[]= 'attendance_sheet_log';
+    $tables[]= 'thematic';
+    $tables[]= 'thematic_plan';
+    $tables[]= 'thematic_advance';
+    
+    return $tables;
+    
+}
 /**
  * Creates all the necessary tables for a new course.
  */
@@ -352,7 +450,7 @@ function update_Db_course($course_db_name = null) {
     $TABLEWIKIMAILCUE           = $course_db_name . 'wiki_mailcue';
 
     // audiorecorder
-    $TABLEAUDIORECORDER         = $course_db_name . 'audiorecorder';
+    //$TABLEAUDIORECORDER         = $course_db_name . 'audiorecorder';
 
     // Course settings
     $TABLESETTING               = $course_db_name . 'course_setting';
@@ -2391,10 +2489,10 @@ function fill_Db_course($course_id, $course_repository, $language, $default_docu
         -----------------------------------------------------------
         */
 
-        Database::query("INSERT INTO $TABLETOOLAGENDA  VALUES ($course_id, NULL, '".lang2db(get_lang('AgendaCreationTitle')) . "', '".lang2db(get_lang('AgendaCreationContenu')) . "', now(), now(), NULL, 0)");
+        Database::query("INSERT INTO $TABLETOOLAGENDA  VALUES ($course_id, NULL, '".lang2db(get_lang('AgendaCreationTitle')) . "', '".lang2db(get_lang('AgendaCreationContenu')) . "', now(), now(), NULL, 0, 0)");
         // We need to add the item properties too!
         $insert_id = Database :: insert_id();
-        $sql = "INSERT INTO $TABLEITEMPROPERTY  ($course_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_CALENDAR_EVENT . "',1,NOW(),NOW(),$insert_id,'AgendaAdded',1,0,NULL,1)";
+        $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id, '" . TOOL_CALENDAR_EVENT . "',1,NOW(),NOW(),$insert_id,'AgendaAdded',1,0,NULL,1)";
         Database::query($sql);
 
         /*
@@ -2462,7 +2560,7 @@ function fill_Db_course($course_id, $course_repository, $language, $default_docu
         Database::query("INSERT INTO $TABLEQUIZANSWERSLIST  VALUES ($course_id,  '4', '1', '".lang2db(get_lang('Contradiction')) . "', '1', '".lang2db(get_lang('NotFalse')) . "', '5', '4','','','','')");
         $html=Database::escape_string('<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="110" valign="top" align="left"><img src="'.api_get_path(WEB_CODE_PATH).'default_course_document/images/mr_dokeos/thinking.jpg"></td><td valign="top" align="left">'.get_lang('Antique').'</td></tr></table>');
 
-        Database::query('INSERT INTO `'.$TABLEQUIZ . '` (c_id, title, description, type, random, random_answers, active, results_disabled ) 
+        Database::query('INSERT INTO '.$TABLEQUIZ . ' (c_id, title, description, type, random, random_answers, active, results_disabled ) 
         				VALUES ('.$course_id.', "'.lang2db(get_lang('ExerciceEx')) . '", "'.$html.'", "1", "0", "0", "1", "0")');
         Database::query("INSERT INTO $TABLEQUIZQUESTIONLIST  (c_id, id, question, description, ponderation, position, type, picture, level) 
         				VALUES ( '.$course_id.', '1', '".lang2db(get_lang('SocraticIrony')) . "', '".lang2db(get_lang('ManyAnswers')) . "', '10', '1', '2','',1)");
@@ -2479,11 +2577,11 @@ function fill_Db_course($course_id, $course_repository, $language, $default_docu
         Database::query("INSERT INTO $TABLEITEMPROPERTY  (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) 
         				VALUES ($course_id, 'forum_category',1,NOW(),NOW(),$insert_id,'ForumCategoryAdded',1,0,NULL,1)");
 
-        Database::query("INSERT INTO `$TABLEFORUMS` (c_id, forum_title, forum_comment, forum_threads,forum_posts,forum_last_post,forum_category, allow_anonymous, allow_edit,allow_attachments, allow_new_threads,default_view,forum_of_group,forum_group_public_private, forum_order,locked,session_id ) 
+        Database::query("INSERT INTO $TABLEFORUMS (c_id, forum_title, forum_comment, forum_threads,forum_posts,forum_last_post,forum_category, allow_anonymous, allow_edit,allow_attachments, allow_new_threads,default_view,forum_of_group,forum_group_public_private, forum_order,locked,session_id ) 
         				VALUES ($course_id, '".lang2db(get_lang('ExampleForum'))."', '', 0, 0, 0, 1, 0, 1, '0', 1, 'flat','0', 'public', 1, 0,0)");
         $insert_id = Database :: insert_id();
         Database::query("INSERT INTO $TABLEITEMPROPERTY  (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) 
-        				 VALUES ('$course_id, " . TOOL_FORUM . "',1,NOW(),NOW(),$insert_id,'ForumAdded',1,0,NULL,1)");
+        				 VALUES ($course_id, '".TOOL_FORUM."', 1,NOW(),NOW(),$insert_id,'ForumAdded',1,0,NULL,1)");
 
         Database::query("INSERT INTO $TABLEFORUMTHREADS (c_id, thread_id, thread_title, forum_id, thread_replies, thread_poster_id, thread_poster_name, thread_views, thread_last_post, thread_date, locked, thread_qualify_max) 
         				VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', 1, 0, 1, '', 0, 1, NOW(), 0, 10)");
@@ -2491,7 +2589,7 @@ function fill_Db_course($course_id, $course_repository, $language, $default_docu
         Database::query("INSERT INTO $TABLEITEMPROPERTY  (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) 
         				VALUES ($course_id, 'forum_thread',1,NOW(),NOW(),$insert_id,'ForumThreadAdded',1,0,NULL,1)");
 
-        Database::query("INSERT INTO `$TABLEFORUMPOSTS` VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', '".lang2db(get_lang('ExampleThreadContent'))."', 1, 1, 1, '', NOW(), 0, 0, 1)");
+        Database::query("INSERT INTO $TABLEFORUMPOSTS VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', '".lang2db(get_lang('ExampleThreadContent'))."', 1, 1, 1, '', NOW(), 0, 0, 1)");
 
     }
     

+ 55 - 47
main/inc/lib/course.lib.php

@@ -1498,32 +1498,34 @@ class CourseManager {
     public static function delete_course($code) {
         global $_configuration;
 
-        $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
-        $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
-        $table_course_class = Database::get_main_table(TABLE_MAIN_COURSE_CLASS);
-        $user_role_table = Database::get_main_table(MAIN_USER_ROLE_TABLE);
-        $location_table = Database::get_main_table(MAIN_LOCATION_TABLE);
-        $role_right_location_table = Database::get_main_table(MAIN_ROLE_RIGHT_LOCATION_TABLE);
-        $table_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-        $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-        $table_course_survey = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY);
-        $table_course_survey_question = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
-        $table_course_survey_question_option = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
+        $table_course                       = Database::get_main_table(TABLE_MAIN_COURSE);
+        $table_course_user                  = Database::get_main_table(TABLE_MAIN_COURSE_USER);
+        $table_course_class                 = Database::get_main_table(TABLE_MAIN_COURSE_CLASS);
+        $user_role_table                    = Database::get_main_table(MAIN_USER_ROLE_TABLE);
+        $location_table                     = Database::get_main_table(MAIN_LOCATION_TABLE);
+        $role_right_location_table          = Database::get_main_table(MAIN_ROLE_RIGHT_LOCATION_TABLE);
+        $table_session_course               = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+        $table_session_course_user          = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+        $table_course_survey                = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY);
+        $table_course_survey_question       = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
+        $table_course_survey_question_option= Database::get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
         $stats = false;
-        if (Database::get_statistic_database() != ''){
+        
+        if (Database::get_statistic_database() != '') {
             $stats = true;
-            $table_stats_hotpots = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
-            $table_stats_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
-            $table_stats_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
-            $table_stats_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
-            $table_stats_lastaccess = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
-            $table_stats_course_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
-            $table_stats_online = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
-            $table_stats_default = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
-            $table_stats_downloads = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
-            $table_stats_links = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
-            $table_stats_uploads = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_UPLOADS);
+            $table_stats_hotpots        = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
+            $table_stats_attempt        = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
+            $table_stats_exercises      = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+            $table_stats_access         = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
+            $table_stats_lastaccess     = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
+            $table_stats_course_access  = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
+            $table_stats_online         = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
+            $table_stats_default        = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
+            $table_stats_downloads      = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
+            $table_stats_links          = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
+            $table_stats_uploads        = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_UPLOADS);
         }
+
         $code = Database::escape_string($code);
         $sql = "SELECT * FROM $table_course WHERE code='".$code."'";
         $res = Database::query($sql);
@@ -1586,24 +1588,22 @@ class CourseManager {
                 $sql = "DELETE FROM $table_course WHERE code='".$virtual_course['code']."'";
                 Database::query($sql);
             }
+
             $sql = "SELECT * FROM $table_course WHERE code='".$code."'";
             $res = Database::query($sql);
             $course = Database::fetch_array($res);
-            if (!$_configuration['single_database']) {
-                $sql = "DROP DATABASE IF EXISTS ".$course['db_name'];
-                Database::query($sql);
-            } else {
-                //TODO Clean the following code as currently it would probably delete another course
-                //similarly named, by mistake...
-                $db_pattern = $_configuration['table_prefix'].$course['db_name'].$_configuration['db_glue'];
-                $sql = "SHOW TABLES LIKE '$db_pattern%'";
-                $result = Database::query($sql);
-                while (list ($courseTable) = Database::fetch_array($result)) {
-                    Database::query("DROP TABLE $courseTable");
+            $course_tables = get_course_tables();
+            
+            //Cleaning c_x tables
+            if (!empty($course['id'])) {
+                foreach($course_tables as $table) {
+                    $table = Database::get_course_table($table);
+                    $sql = "DELETE FROM $table WHERE c_id = {$course['id']} ";               
+                    Database::query($sql);
                 }
             }
             $course_dir = api_get_path(SYS_COURSE_PATH).$course['directory'];
-            $archive_dir = api_get_path(SYS_ARCHIVE_PATH).$course['directory'].'_'.time();
+            $archive_dir = api_get_path(SYS_ARCHIVE_PATH).$course['directory'].'_'.time();            
             if (is_dir($course_dir)) {
                 rename($course_dir, $archive_dir);
             }
@@ -1728,23 +1728,31 @@ class CourseManager {
             return;
         }
         $sql_dump = '';
-        $course_code = Database::escape_string($course_code);
-        $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
+        $course_code    = Database::escape_string($course_code);
+        $table_course   = Database::get_main_table(TABLE_MAIN_COURSE);
         $sql = "SELECT * FROM $table_course WHERE code = '$course_code'";
         $res = Database::query($sql);
         $course = Database::fetch_array($res);
-        $sql = "SHOW TABLES FROM ".$course['db_name'];
-        $res = Database::query($sql);
-        while ($table = Database::fetch_array($res)) {
-            $sql = "SELECT * FROM ".$course['db_name'].".".$table[0]."";
-            $res3 = Database::query($sql);
-            while ($row = Database::fetch_array($res3)) {
-                foreach ($row as $key => $value) {
-                    $row[$key] = $key."='".addslashes($row[$key])."'";
-                }
-                $sql_dump .= "\nINSERT INTO $table[0] SET ".implode(', ', $row).';';
+        
+        $course_tables = get_course_tables();
+        
+        if (!empty($course['id'])) {
+            //Cleaning c_x tables
+            foreach($course_tables as $table) {
+                $table = Database::get_course_table($table);
+                $sql = "SELECT * FROM $table WHERE c_id = {$course['id']} ";               
+                $res_table = Database::query($sql);
+                
+                while ($row = Database::fetch_array($res_table, 'ASSOC')) {
+                    $row_to_save = array();
+                    foreach ($row as $key => $value) {
+                        $row_to_save[$key] = $key."='".Database::escape_string($row[$key])."'";
+                    }                
+                    $sql_dump .= "\nINSERT INTO $table SET ".implode(', ', $row_to_save).';';
+                }                
             }
         }
+        
         if (is_dir(api_get_path(SYS_COURSE_PATH).$course['directory'])) {
             $file_name = api_get_path(SYS_COURSE_PATH).$course['directory'].'/mysql_dump.sql';
             $handle = fopen($file_name, 'a+');

+ 0 - 1
tests/datafiller/fill_courses.php

@@ -9,7 +9,6 @@
  */
 //require_once '../../main/inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
-require_once api_get_path(LIBRARY_PATH).'database.lib.php';
 /**
  * Loads the data and injects it into the Chamilo database, using the Chamilo
  * internal functions.

+ 1 - 2
tests/datafiller/fill_users.php

@@ -7,8 +7,7 @@
 /**
  * Initialisation section
  */
-//require_once '../../main/inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+
 /**
  * Loads the data and injects it into the Chamilo database, using the Chamilo
  * internal functions.