pull/2487/head
Alex Aragon 9 years ago
commit a420befff2
  1. 8
      main/admin/course_add.php
  2. 7
      main/create_course/add_course.php
  3. 106
      main/inc/lib/add_course.lib.inc.php
  4. 2
      main/work/work_list_all.php
  5. 5
      tests/main/inc/lib/add_course.lib.inc.test.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():''));

@ -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)) {

@ -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 = '<p style="text-align: center;">
<img src="' . api_get_path(REL_CODE_PATH) . 'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" />
<h2>' . self::lang2db(get_lang('IntroductionText')) . '</h2>
<h2>' . get_lang('IntroductionText') . '</h2>
</p>';
$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());

@ -174,7 +174,7 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !$isDrhOfC
$count = get_count_work($workId);
if ($count > 0) {
$display_output .= '<a class="btn-toolbar" href="downloadfolder.inc.php?id='.$workId.'&'.api_get_cidreq().'">'.
Display::return_icon('save_pack.png', get_lang('DownloadPackageTasks'), null, ICON_SIZE_MEDIUM).' '.get_lang('DownloadPackageTasks').'</a>';
Display::return_icon('save_pack.png', get_lang('DownloadTasksPackage'), null, ICON_SIZE_MEDIUM).' '.get_lang('DownloadTasksPackage').'</a>';
}
$actionsLeft .= $display_output;
$url = api_get_path(WEB_CODE_PATH).'work/upload_corrections.php?'.api_get_cidreq().'&id='.$workId;

@ -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;

Loading…
Cancel
Save