Fixing course_category update code see BT#6195

1.9.x
Julio Montoya 12 years ago
parent 1a265c496d
commit e1c9888aa7
  1. 12
      main/admin/course_category.php
  2. 19
      main/inc/lib/course_category.lib.php

@ -90,8 +90,12 @@ if ($action == 'add' || $action == 'edit') {
$form->addElement('text', 'name', get_lang("CategoryName"));
$form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required');
$form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required');
$form->addElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE');
$form->addElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE');
$group = array(
$form->createElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE'),
$form->createElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE')
);
$form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
if (!empty($categoryInfo)) {
$class = "save";
$text = get_lang('CategoryMod');
@ -117,7 +121,7 @@ if ($action == 'add' || $action == 'edit') {
);
}
if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'FALSE') {
if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
echo Display::url(
Display::return_icon('new_folder.png', get_lang("AddACategory"), '', ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.$category
@ -126,7 +130,7 @@ if ($action == 'add' || $action == 'edit') {
echo '</div>';
if (!empty($parentInfo)) {
echo Display::page_subheader($parentInfo['name']);
echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
}
echo listCategories($category);
}

@ -150,7 +150,7 @@ function deleteNode($node)
$node = Database::escape_string($node);
$result = Database::query("SELECT parent_id,tree_pos FROM $tbl_category WHERE code='$node'");
$result = Database::query("SELECT parent_id, tree_pos FROM $tbl_category WHERE code='$node'");
if ($row = Database::fetch_array($result)) {
if (!empty($row['parent_id'])) {
@ -187,19 +187,18 @@ function editNode($code, $name, $canHaveCourses, $old_code)
$old_code = Database::escape_string($old_code);
$canHaveCourses = Database::escape_string($canHaveCourses);
if ($code != $old_code) {
$sql = "SELECT 1 FROM $tbl_category WHERE code='$code'";
$result = Database::query($sql);
if (Database::num_rows($result)) {
return false;
}
}
$code = generate_course_code($code);
// Updating category
$sql = "UPDATE $tbl_category SET name='$name', code='$code', auth_course_child = '$canHaveCourses'
WHERE code='$old_code'";
WHERE code = '$old_code'";
Database::query($sql);
// Updating children
$sql = "UPDATE $tbl_category SET parent_id = '$code'
WHERE parent_id = '$old_code'";
Database::query($sql);
// Updating course category
$sql = "UPDATE $tbl_course SET category_code = '$code' WHERE category_code = '$old_code' ";
Database::query($sql);
return true;

Loading…
Cancel
Save