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. 27
      main/create_course/add_course.php
  3. 11
      main/inc/lib/add_course.lib.inc.php
  4. 15
      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,25 +210,24 @@ 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.
if (!$course_validation_feature) {
$course_code_ok = !CourseManager::course_code_exists($wanted_code);
} else {
$course_code_ok = !CourseRequestManager::course_code_exists($wanted_code);
}
if ($course_code_ok) {
if (!$course_validation_feature) {
if (!$course_validation_feature) {
$params = array();
$params['title'] = $title;
$params['exemplary_content'] = $exemplary_content;
$params['wanted_code'] = $wanted_code;
//$params['tutor_name'] = $tutor_name;
$params['wanted_code'] = $wanted_code;
$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) {
@ -52,7 +50,7 @@ function define_course_keys($wanted_code, $prefix_for_all = '', $prefix_for_base
$unique_prefix = '';
}
$keys = array ();
$keys = array();
$final_suffix = array('CourseId' => '', 'CourseDb' => '', 'CourseDir' => '');
$limit_numb_try = 100;
$keys_are_unique = false;
@ -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');
@ -2728,8 +2726,7 @@ function register_course($params) {
if ($send_mail_to_admin == 'true') {
$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);
$recipient_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'));
$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
*/
@ -136,14 +138,11 @@ 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));
// Check whether the requested course code has already been occupied.
$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;
@ -633,8 +632,8 @@ class CourseManager {
* with the same code OR visual_code (visualcode), false otherwise
*/
public static function course_code_exists($wanted_course_code) {
$wanted_course_code = Database::escape_string($wanted_course_code);
$result = Database::fetch_array(Database::query("SELECT COUNT(*) as number FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."WHERE code = '$wanted_course_code' OR visual_code = '$wanted_course_code'"));
$wanted_course_code = Database::escape_string($wanted_course_code);
$result = Database::fetch_array(Database::query("SELECT COUNT(*) as number FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code = '$wanted_course_code' OR visual_code = '$wanted_course_code'"));
return $result['number'] > 0;
}

Loading…
Cancel
Save