From 4f0bcda3b9caaf00df8fdc02b042e90de2bab2cf Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 12 Jul 2016 14:51:05 -0500 Subject: [PATCH] Fix course creationg in other language - refs #8324 --- main/admin/course_add.php | 8 ++ main/create_course/add_course.php | 7 ++ main/inc/lib/add_course.lib.inc.php | 106 ++++++++---------- .../main/inc/lib/add_course.lib.inc.test.php | 5 - 4 files changed, 60 insertions(+), 66 deletions(-) diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 2994777e98..4d46c442a5 100755 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -200,6 +200,14 @@ if ($form->validate()) { $course['gradebook_model_id'] = isset($course['gradebook_model_id']) ? $course['gradebook_model_id'] : null; // Fixing category code $course['course_category'] = isset($course['category_code']) ? $course['category_code'] : ''; + + include_once api_get_path(SYS_CODE_PATH) . 'lang/english/trad4all.inc.php'; + $file_to_include = api_get_path(SYS_CODE_PATH) . 'lang/' . $course['course_language'] . '/trad4all.inc.php'; + + if (file_exists($file_to_include)) { + include $file_to_include; + } + $course_info = CourseManager::create_course($course); header('Location: course_list.php'.($course_info===false?'?action=show_msg&warn='.api_get_last_failure():'')); diff --git a/main/create_course/add_course.php b/main/create_course/add_course.php index 65cd4830e4..3516518914 100755 --- a/main/create_course/add_course.php +++ b/main/create_course/add_course.php @@ -293,6 +293,13 @@ if ($form->validate()) { $params['course_language'] = $course_language; $params['gradebook_model_id'] = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null; + include_once api_get_path(SYS_CODE_PATH) . 'lang/english/trad4all.inc.php'; + $file_to_include = api_get_path(SYS_CODE_PATH) . 'lang/' . $course_language . '/trad4all.inc.php'; + + if (file_exists($file_to_include)) { + include $file_to_include; + } + $course_info = CourseManager::create_course($params); if (!empty($course_info)) { diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index ecbda3cc60..c3295371a8 100755 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -394,21 +394,6 @@ class AddCourse return $pictures; } - /** - * Function to convert a string from the language files to a string ready - * to insert into the database (escapes single quotes) - * @author Bart Mollet (bart.mollet@hogent.be) - * @param string $string The string to convert - * @return string The string converted to insert into the database - * @assert ('a\'b') === 'ab' - */ - public static function lang2db($string) - { - $string = str_replace("\\'", "'", $string); - $string = Database::escape_string($string); - return $string; - } - /** * Fills the course database with some required content and example content. * @param int Course (int) ID @@ -452,13 +437,6 @@ class AddCourse TABLE_MAIN_GRADEBOOK_LINK ); - include_once api_get_path(SYS_CODE_PATH) . 'lang/english/trad4all.inc.php'; - $file_to_include = api_get_path(SYS_CODE_PATH) . 'lang/' . $language . '/trad4all.inc.php'; - - if (file_exists($file_to_include)) { - include_once $file_to_include; - } - $visible_for_all = 1; $visible_for_course_admin = 0; $visible_for_platform_admin = 2; @@ -686,21 +664,28 @@ class AddCourse /* Course homepage tools for platform admin only */ /* Group tool */ - - Database::query( - "INSERT INTO $TABLEGROUPCATEGORIES (c_id, id, title , description, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order, doc_state,calendar_state, work_state ,announcements_state, forum_state, wiki_state, chat_state) - VALUES ($course_id, '2', '" . self::lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0', 1, 1 ,1 ,1 ,1, 1, 1);" - ); - - /* Example Material */ - global $language_interface; - $language_interface = !empty($language_interface) ? $language_interface : api_get_setting( - 'platformLanguage' + Database::insert( + $TABLEGROUPCATEGORIES, + [ + 'c_id' => $course_id, + 'id' => 2, + 'title' => get_lang('DefaultGroupCategory'), + 'description' => '', + 'max_student' => 8, + 'self_reg_allowed' => 0, + 'self_unreg_allowed' => 0, + 'groups_per_user' => 0, + 'display_order' => 0, + 'doc_state' => 1, + 'calendar_state' => 1, + 'work_state' => 1, + 'announcements_state' => 1, + 'forum_state' => 1, + 'wiki_state' => 1, + 'chat_state' => 1 + ] ); - // Example material should be in the same language as the course is. - $language_interface_original = $language_interface; - $language_interface = $language; $now = api_get_utc_datetime(); $files = [ @@ -996,7 +981,7 @@ class AddCourse /* Introduction text */ $intro_text = '

Mr. Chamilo -

' . self::lang2db(get_lang('IntroductionText')) . '

+

' . get_lang('IntroductionText') . '

'; $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro(); @@ -1120,8 +1105,6 @@ class AddCourse //Installing plugins in course $app_plugin = new AppPlugin(); $app_plugin->install_course_plugins($course_id); - - $language_interface = $language_interface_original; return true; } @@ -1298,30 +1281,31 @@ class AddCourse $course_id = 0; if ($ok_to_register_course) { - // Here we must add 2 fields. - $sql = "INSERT INTO " . $TABLECOURSE . " SET - code = '".Database:: escape_string($code)."', - directory = '".Database:: escape_string($directory)."', - course_language = '".Database:: escape_string($course_language)."', - title = '".Database:: escape_string($title)."', - description = '".self::lang2db(get_lang('CourseDescription'))."', - category_code = '".Database:: escape_string($category_code)."', - visibility = '" . $visibility . "', - show_score = '1', - disk_quota = '" . intval($disk_quota) . "', - creation_date = '$time', - expiration_date = '" . $expiration_date . "', - last_edit = '$time', - last_visit = NULL, - tutor_name = '" . Database:: escape_string($tutor_name) . "', - department_name = '" . Database:: escape_string($department_name) . "', - department_url = '" . Database:: escape_string($department_url) . "', - subscribe = '" . intval($subscribe) . "', - unsubscribe = '" . intval($unsubscribe) . "', - visual_code = '" . Database:: escape_string($visual_code) . "'"; - Database::query($sql); - $course_id = Database::insert_id(); + $course_id = Database::insert( + $TABLECOURSE, + [ + 'code' => $code, + 'directory' => $directory, + 'course_language' => $course_language, + 'title' => $title, + 'description' => get_lang('CourseDescription'), + 'category_code' => $category_code, + 'visibility' => $visibility, + 'show_score' => 1, + 'disk_quota' => intval($disk_quota), + 'creation_date' => $time, + 'expiration_date' => $expiration_date, + 'last_edit' => $time, + 'last_visit' => NULL, + 'tutor_name' => $tutor_name, + 'department_name' => $department_name, + 'department_url' => $department_url, + 'subscribe' => intval($subscribe), + 'unsubscribe' => intval($unsubscribe), + 'visual_code' => $visual_code + ] + ); if ($course_id) { $sort = api_max_sort_value('0', api_get_user_id()); diff --git a/tests/main/inc/lib/add_course.lib.inc.test.php b/tests/main/inc/lib/add_course.lib.inc.test.php index 79eea6f3fc..cb6cdc4d41 100755 --- a/tests/main/inc/lib/add_course.lib.inc.test.php +++ b/tests/main/inc/lib/add_course.lib.inc.test.php @@ -91,11 +91,6 @@ class TestAddCourse extends UnitTestCase { $this->assertTrue($res); } */ - function TestLang2db(){ - $string = 'test'; - $res = AddCourse::lang2db($string); - $this->assertTrue($res); - } function TestFillDbCourse(){ global $_configuration, $_user;