Fixed Course category bug when renaming the category code see #3948

skala
Julio Montoya 13 years ago
parent 1576cc6ffb
commit b229bcf71c
  1. 4
      main/admin/course_add.php
  2. 84
      main/admin/course_category.php
  3. 9
      main/admin/course_edit.php
  4. 6
      main/admin/course_list.php

@ -18,7 +18,6 @@ api_protect_admin_script();
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tool_name = get_lang('AddCourse');
@ -62,8 +61,7 @@ $form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
// Code
$form->add_textfield('visual_code', get_lang('CourseCode'), false, array('size' => '20', 'maxlength' => 20));
$form->addElement('static', null, null, get_lang('OnlyLettersAndNumbers'));
$form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('size' => '20', 'maxlength' => 20));
$form->applyFilter('visual_code', 'api_strtoupper');
$form->applyFilter('visual_code', 'html_filter');

@ -18,16 +18,17 @@ $this_section=SECTION_PLATFORM_ADMIN;
require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
api_protect_admin_script();
$category=$_GET['category'];
$action=$_GET['action'];
$category = $_GET['category'];
$category = Database::escape_string($category);
$action = $_GET['action'];
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$errorMsg='';
if(!empty($action))
{
if(!empty($action)) {
if($action == 'delete')
{
deleteNode($_GET['id']);
@ -91,60 +92,43 @@ $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'
Display::display_header($tool_name);
//api_display_tool_title($tool_name);
if(!empty($category))
{
if(!empty($category)) {
$myquery = "SELECT * FROM $tbl_category WHERE code ='$category'";
$result = Database::query($myquery);
if(Database::num_rows($result)==0)
{
if(Database::num_rows($result)==0) {
$category = '';
}
}
if(empty($action))
{
$myquery="SELECT t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count,COUNT(DISTINCT t3.code) AS nbr_courses FROM $tbl_category t1 LEFT JOIN $tbl_category t2 ON t1.code=t2.parent_id LEFT JOIN $tbl_course t3 ON t3.category_code=t1.code WHERE t1.parent_id ".(empty($category)?"IS NULL":"='$category'")." GROUP BY t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count ORDER BY t1.tree_pos";
$result=Database::query($myquery);
if(empty($action)) {
$myquery = "SELECT t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count,COUNT(DISTINCT t3.code) AS nbr_courses
FROM $tbl_category t1 LEFT JOIN $tbl_category t2 ON t1.code=t2.parent_id LEFT JOIN $tbl_course t3 ON t3.category_code=t1.code
WHERE t1.parent_id ".(empty($category)?"IS NULL":"='$category'")."
GROUP BY t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count ORDER BY t1.tree_pos";
$result = Database::query($myquery);
$Categories=Database::store_result($result);
}
if($action == 'add' || $action == 'edit')
{
if($action == 'add' || $action == 'edit') {
?>
<div class="actions">
<a href="<?php echo api_get_self(); ?>?category=<?php echo Security::remove_XSS($category); ?>"><?php echo Display::return_icon('folder_up.png',get_lang("Back"),'','32'); if(!empty($category)) echo ' ('.Security::remove_XSS($category).')'; ?></a>
</div>
<?php
$form_title = ($action == 'add')?get_lang('AddACategory'):get_lang('EditNode');
if(!empty($category))
{
if(!empty($category)) {
$form_title .= ' '.get_lang('Into').' '.Security::remove_XSS($category);
}
$form = new FormValidator('course_category');
$form->addElement('header', '', $form_title);
$form->display();
?>
<form method="post" action="<?php echo api_get_self(); ?>?action=<?php echo Security::remove_XSS($action); ?>&category=<?php echo Security::remove_XSS($category); ?>&amp;id=<?php echo Security::remove_XSS($_GET['id']); ?>">
<input type="hidden" name="formSent" value="1" />
<table border="0" cellpadding="5" cellspacing="0">
<?php
if(!empty($errorMsg))
{
if(!empty($errorMsg)) {
?>
<tr>
<td colspan="2">
@ -191,14 +175,11 @@ if($action == 'add' || $action == 'edit')
</form>
<?php
}
else
{
} else {
?>
<div class="actions">
<?php
if(!empty($category) && empty($action))
{
if(!empty($category) && empty($action)) {
$myquery = "SELECT parent_id FROM $tbl_category WHERE code='$category'";
$result=Database::query($myquery);
$parent_id = 0;
@ -256,11 +237,6 @@ else
<?php
}
/*
==============================================================================
FOOTER
==============================================================================
*/
Display::display_footer();
/******** Functions ********/
@ -306,8 +282,7 @@ function addNode($code,$name,$canHaveCourses,$parent_id)
$result=Database::query("SELECT 1 FROM $tbl_category WHERE code='$code'");
if(Database::num_rows($result))
{
if (Database::num_rows($result)) {
return false;
}
@ -316,7 +291,8 @@ function addNode($code,$name,$canHaveCourses,$parent_id)
$row=Database::fetch_array($result);
$tree_pos=$row['maxTreePos']+1;
$code = generate_course_code($code);
Database::query("INSERT INTO $tbl_category(name,code,parent_id,tree_pos,children_count,auth_course_child) VALUES('$name','$code',".(empty($parent_id)?"NULL":"'$parent_id'").",'$tree_pos','0','$canHaveCourses')");
updateFils($parent_id);
@ -326,24 +302,23 @@ function addNode($code,$name,$canHaveCourses,$parent_id)
function editNode($code,$name,$canHaveCourses,$old_code)
{
global $tbl_category;
global $tbl_category, $tbl_course;
$canHaveCourses=$canHaveCourses?'TRUE':'FALSE';
$code = Database::escape_string($code);
$name = Database::escape_string($name);
$old_code = Database::escape_string($old_code);
if($code != $old_code)
{
if($code != $old_code) {
$result=Database::query("SELECT 1 FROM $tbl_category WHERE code='$code'");
if(Database::num_rows($result))
{
if(Database::num_rows($result)) {
return false;
}
}
Database::query("UPDATE $tbl_category SET name='$name',code='$code',auth_course_child='$canHaveCourses' WHERE code='$old_code'");
$code = generate_course_code($code);
Database::query("UPDATE $tbl_category SET name='$name', code='$code',auth_course_child='$canHaveCourses' WHERE code='$old_code'");
$sql = "UPDATE $tbl_course SET category_code = '$code' WHERE category_code = '$old_code' ";
Database::query($sql);
return true;
}
@ -399,5 +374,4 @@ function compterFils($pere,$cpt)
}
return ($cpt+1);
}
?>
}

@ -95,13 +95,12 @@ $form->add_textfield( 'title', get_lang('Title'),true, array ('size' => '60'));
$form->applyFilter('title','html_filter');
$form->applyFilter('title','trim');
// code
$form->add_textfield('visual_code', get_lang('CourseCode'));
$form->addElement('static', null, null, get_lang('OnlyLettersAndNumbers'));
$form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')));
$form->applyFilter('visual_code','strtoupper');
$form->applyFilter('visual_code','html_filter');
//$form->add_textfield('tutor_name', get_lang('CourseTitular'));
$form->addElement('select', 'tutor_name', get_lang('CourseTitular'), $platform_teachers, array('style'=>'width:350px'));
$form->addElement('select', 'tutor_name', get_lang('CourseTitular'), $platform_teachers, array('style'=>'width:350px','id'=>'tutor_name_id', 'class'=>'chzn-select'));
$form->applyFilter('tutor_name','html_filter');
//$form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size="4" style="width: 150px;"');
@ -115,7 +114,7 @@ $element_template = <<<EOT
<div class="label">
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}
</div>
<div class="formw" style="display:inline">
<div class="formw">
<table cellpadding="0" cellspacing="0">
<tr>
<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <td>{element}</td>
@ -132,7 +131,7 @@ $form -> addGroup($group,'group',get_lang('CourseTeachers'),'</td><td width="80"
'<input class="arrowl" style="width:30px;height:30px;padding-left:13px" type="button" onclick="moveItem(document.getElementById(\'course_teachers\'), document.getElementById(\'platform_teachers\'))" ></td><td>');
$categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories , array('style'=>'width:350px'));
$categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories , array('style'=>'width:350px','id'=>'category_code_id', 'class'=>'chzn-select'));
CourseManager::select_and_sort_categories($categories_select);
$form->add_textfield( 'department_name', get_lang('CourseDepartment'), false,array ('size' => '60'));

@ -66,7 +66,8 @@ function get_course_data($from, $number_of_items, $column, $direction) {
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$users_table = Database :: get_main_table(TABLE_MAIN_USER);
$course_users_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$sql = "SELECT code AS col0, visual_code AS col1, title AS col2, course_language AS col3, category_code AS col4, subscribe AS col5, unsubscribe AS col6, tutor_name as col7, code AS col8, visibility AS col9,directory as col10 FROM $course_table";
$sql = "SELECT code AS col0, visual_code AS col1, title AS col2, course_language AS col3, category_code AS col4, subscribe AS col5, unsubscribe AS col6, tutor_name as col7, code AS col8, visibility AS col9,directory as col10
FROM $course_table";
//$sql = "SELECT code AS col0, visual_code AS col1, title AS col2, course_language AS col3, category_code AS col4, subscribe AS col5, unsubscribe AS col6, code AS col7, tutor_name as col8, code AS col9, visibility AS col10,directory as col11 FROM $course_table";
global $_configuration;
@ -105,8 +106,7 @@ function get_course_data($from, $number_of_items, $column, $direction) {
$course[1] = '<nobr>'.get_course_visibility_icon($course[9]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[10].'/index.php">'.$course[1].'</a></nobr>';
$course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
$course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
//$course[7] = CourseManager :: is_virtual_course_from_system_code($course[7]) ? get_lang('Yes') : get_lang('No');
//$course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7], $course[8], $course[9]);
$course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7], $course[8]);
$courses[] = $course_rem;
}

Loading…
Cancel
Save