Adding a new constant (MAX_COURSE_LENGTH_CODE) in course.lib.php in order to use the same max value for the course code now is 40 like the field in the database see #4548

skala
Julio Montoya 13 years ago
parent 8e09a55c4f
commit 315a159f37
  1. 8
      main/admin/course_add.php
  2. 19
      main/create_course/add_course.php
  3. 7
      main/inc/lib/add_course.lib.inc.php
  4. 9
      main/inc/lib/course.lib.php

@ -46,10 +46,6 @@ while($obj = Database::fetch_object($res)) {
$teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
}
$dbnamelength = strlen($_configuration['db_prefix']);
// Ensure the database prefix + database name do not get over 40 characters.
$maxlength = 40 - $dbnamelength;
// Build the form.
$form = new FormValidator('update_course');
$form->addElement('header', '', $tool_name);
@ -60,11 +56,11 @@ $form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
// Code
$form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('size' => '20', 'maxlength' => 20));
$form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('class' => 'span3', 'maxlength' => MAX_COURSE_LENGTH_CODE));
$form->applyFilter('visual_code', 'api_strtoupper');
$form->applyFilter('visual_code', 'html_filter');
$form->addRule('visual_code', get_lang('Max'), 'maxlength', $maxlength);
$form->addRule('visual_code', get_lang('Max'), 'maxlength', MAX_COURSE_LENGTH_CODE);
//$form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers, array('style' => 'width:350px', 'class'=>'chzn-select', 'id'=>'tutor_id'));
//$form->applyFilter('tutor_id', 'html_filter');

@ -79,9 +79,9 @@ if (!api_is_allowed_to_create_course()) {
}
global $_configuration;
$dbnamelength = strlen($_configuration['db_prefix']);
//$dbnamelength = strlen($_configuration['db_prefix']);
// Ensure the database prefix + database name do not get over 40 characters.
$maxlength = 40 - $dbnamelength;
$maxlength = 40;
// Build the form.
$form = new FormValidator('add_course');
@ -98,8 +98,6 @@ $advanced = '<a href="javascript://" onclick=" return advanced_parameters()"><sp
$form -> addElement('advanced_settings',$advanced);
$form -> addElement('html','<div id="options" style="display:none">');
// Course category.
$categories_select = $form->addElement('select', 'category_code', array(get_lang('Fac'), get_lang('TargetFac')), array(), array('id'=> 'category_code','class'=>'chzn-select', 'style'=>'width:350px'));
$form->applyFilter('category_code', 'html_filter');
@ -107,10 +105,10 @@ $categories_select->addOption('-','');
CourseManager::select_and_sort_categories($categories_select);
// Course code.
$form->add_textfield('wanted_code', array(get_lang('Code'), get_lang('OnlyLettersAndNumbers')), '', array('size' => $maxlength, 'maxlength' => $maxlength));
// Course code
$form->add_textfield('wanted_code', array(get_lang('Code'), get_lang('OnlyLettersAndNumbers')), '', array('class' => 'span3', 'maxlength' => MAX_COURSE_LENGTH_CODE));
$form->applyFilter('wanted_code', 'html_filter');
$form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
$form->addRule('wanted_code', get_lang('Max'), 'maxlength', MAX_COURSE_LENGTH_CODE);
/*if ($course_validation_feature) {
$form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
@ -193,14 +191,12 @@ $values['tutor_name'] = api_get_person_name($_user['firstName'], $_user['lastNam
$form->setDefaults($values);
// Validate the form.
if ($form->validate()) {
$course_values = $form->exportValues();
$wanted_code = $course_values['wanted_code'];
$tutor_name = $course_values['tutor_name'];
//$tutor_name = $course_values['tutor_name'];
$category_code = $course_values['category_code'];
$title = $course_values['title'];
$course_language = $course_values['course_language'];
@ -214,7 +210,7 @@ if ($form->validate()) {
}
if ($wanted_code == '') {
$wanted_code = generate_course_code(api_substr($title, 0, $maxlength));
$wanted_code = generate_course_code(api_substr($title, 0, MAX_COURSE_LENGTH_CODE));
}
// Check whether the requested course code has already been occupied.
@ -232,7 +228,6 @@ if ($form->validate()) {
$params['title'] = $title;
$params['exemplary_content'] = $exemplary_content;
$params['wanted_code'] = $wanted_code;
//$params['tutor_name'] = $tutor_name;
$params['category_code'] = $category_code;
$params['course_language'] = $course_language;

@ -21,7 +21,7 @@ function generate_course_code($course_title, $encoding = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
}
return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper(api_transliterate($course_title, 'X', $encoding))), 0, 20);
return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper(api_transliterate($course_title, 'X', $encoding))), 0, MAX_COURSE_LENGTH_CODE);
}
/**
@ -36,10 +36,8 @@ function generate_course_code($course_title, $encoding = null) {
* @todo Eliminate the global variables.
*/
function define_course_keys($wanted_code, $prefix_for_all = '', $prefix_for_base_name = '', $prefix_for_path = '', $add_unique_prefix = false, $use_code_indepedent_keys = true) {
global $prefixAntiNumber, $_configuration;
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$wanted_code = generate_course_code($wanted_code);
$keys_course_code = $wanted_code;
if (!$use_code_indepedent_keys) {
@ -2565,7 +2563,7 @@ function register_course($params) {
$visual_code = $params['visual_code'];
$directory = $params['directory'];
$tutor_name = $params['tutor_name'];
$description = $params['description'];
//$description = $params['description'];
$category_code = $params['category_code'];
$course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting('platformLanguage');
@ -2729,7 +2727,6 @@ function register_course($params) {
$siteName = api_get_setting('siteName');
$recipient_email = api_get_setting('emailAdministrator');
$recipient_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'));
$urlsite = api_get_path(WEB_PATH);
$iname = api_get_setting('Institution');
$subject = get_lang('NewCourseCreatedIn').' '.$siteName.' - '.$iname;
$message = get_lang('Dear').' '.$recipient_name.",\n\n".get_lang('MessageOfNewCourseToAdmin').' '.$siteName.' - '.$iname."\n";

@ -71,6 +71,8 @@
require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
define('MAX_COURSE_LENGTH_CODE', 40);
/**
* Constants definition
*/
@ -137,13 +139,10 @@ class CourseManager {
if (empty($params['wanted_code'])) {
$params['wanted_code'] = $params['title'];
// Check whether the requested course code has already been occupied.
$dbnamelength = strlen($_configuration['db_prefix']);
// Ensure the database prefix + database name do not get over 40 characters.
$maxlength = 40 - $dbnamelength;
$params['wanted_code'] = generate_course_code(api_substr($params['title'], 0, $maxlength));
$params['wanted_code'] = generate_course_code(api_substr($params['title'], 0, MAX_COURSE_LENGTH_CODE));
}
// Create the course immediately
// Create the course keys
$keys = define_course_keys($params['wanted_code']);
$params['exemplary_content'] = isset($params['exemplary_content']) ? $params['exemplary_content'] : false;

Loading…
Cancel
Save