Bladeren bron

[svn r14291] improve display of categories in course creation/editions forms

Eric Marguin 17 jaren geleden
bovenliggende
commit
9f0e0c61a6
4 gewijzigde bestanden met toevoegingen van 44 en 27 verwijderingen
  1. 5 10
      main/admin/course_add.php
  2. 4 9
      main/admin/course_edit.php
  3. 4 8
      main/create_course/add_course.php
  4. 31 0
      main/inc/lib/course.lib.php

+ 5 - 10
main/admin/course_add.php

@@ -1,5 +1,5 @@
 <?php
-// $Id: course_add.php 14101 2008-01-08 15:39:39Z elixir_inter $
+// $Id: course_add.php 14291 2008-02-14 08:17:23Z elixir_inter $
 /*
 ==============================================================================
 	Dokeos - elearning and course management software
@@ -44,6 +44,7 @@ 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');
@@ -55,14 +56,7 @@ $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAd
 ==============================================================================
 */
 
-// Get all course categories
-$table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
-$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
-$res = api_sql_query($sql, __FILE__, __LINE__);
-while ($cat = mysql_fetch_array($res))
-{
-	$categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
-}
+
 
 // Get all possible teachers
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);
@@ -82,7 +76,8 @@ $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
 $form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers);
 $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size=5');
 $form->add_textfield('title', get_lang('Title'),true, array ('size' => '60'));
-$form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
+$categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
+CourseManager::select_and_sort_categories($categories_select);
 $form->add_textfield('department_name', get_lang('CourseDepartment'),false, array ('size' => '60'));
 $form->add_textfield('department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
 $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));

+ 4 - 9
main/admin/course_edit.php

@@ -1,6 +1,6 @@
 <?php
 
-// $Id: course_edit.php 14101 2008-01-08 15:39:39Z elixir_inter $
+// $Id: course_edit.php 14291 2008-02-14 08:17:23Z elixir_inter $
 /*
 ==============================================================================
 	Dokeos - elearning and course management software
@@ -44,6 +44,7 @@ $this_section=SECTION_PLATFORM_ADMIN;
 api_protect_admin_script();
 include (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
 require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
+require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
 $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
 $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 $course_code = isset($_GET['course_code']) ? $_GET['course_code'] : $_POST['code'];
@@ -70,14 +71,7 @@ $interbreadcrumb[] = array ("url" => "course_list.php", "name" => get_lang('Admi
 */
 // Get all course categories
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);
-$table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
 
-$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
-$res = api_sql_query($sql, __FILE__, __LINE__);
-while ($cat = mysql_fetch_array($res))
-{
-	$categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
-}
 
 //Get the course infos
 $sql = "SELECT * FROM $course_table WHERE code='".mysql_real_escape_string($course_code)."'";
@@ -160,7 +154,8 @@ $renderer -> setElementTemplate($element_template, 'group');
 $form -> addGroup($group,'group',get_lang('CourseTeachers'),'</td><td width="50" align="center"><input type="button" onclick="moveItem(document.getElementById(\'platform_teachers\'), document.getElementById(\'course_teachers\'))" value=">>"><br><br><input type="button" onclick="moveItem(document.getElementById(\'course_teachers\'), document.getElementById(\'platform_teachers\'))" value="<<"></td><td>');
 
 $form->add_textfield( 'title', get_lang('Title'),true, array ('size' => '60'));
-$form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
+$categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
+CourseManager::select_and_sort_categories($categories_select);
 $form->add_textfield( 'department_name', get_lang('CourseDepartment'), false,array ('size' => '60'));
 $form->add_textfield( 'department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
 $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));

+ 4 - 8
main/create_course/add_course.php

@@ -1,5 +1,5 @@
 <?php
-// $Id: add_course.php 13755 2007-11-23 15:06:16Z elixir_inter $
+// $Id: add_course.php 14291 2008-02-14 08:17:23Z elixir_inter $
 /*
 ==============================================================================
 	Dokeos - elearning and course management software
@@ -46,6 +46,7 @@ include (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
 
 // include additional libraries
 include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
+include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
 include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
 include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
 include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
@@ -68,17 +69,12 @@ if (!api_is_allowed_to_create_course())
 $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
 $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
 
-$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
-$res = api_sql_query($sql, __FILE__, __LINE__);
-while ($cat = mysql_fetch_array($res))
-{
-	$categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
-}
 // Build the form
 $form = new FormValidator('add_course');
 $form->add_textfield('title',get_lang('Title'),true,array('size'=>'60'));
 $form->addElement('static',null,null,get_lang('Ex'));
-$form->addElement('select', 'category_code', get_lang('Fac'), $categories);
+$categories_select = $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
+CourseManager::select_and_sort_categories($categories_select);
 $form->addElement('static',null,null, get_lang('TargetFac'));
 $form->add_textfield('wanted_code', get_lang('Code'),false,array('size'=>'20','maxlength'=>20));
 $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);

+ 31 - 0
main/inc/lib/course.lib.php

@@ -1641,5 +1641,36 @@ class CourseManager
 		return $i_course_sort;
 	}
 	
+	/**
+	 * create recursively all categories as option of the select passed in paramater.
+	 * 
+	 * @param object $select_element the quickform select where the options will be added
+	 * @param string $category_selected_code the option value to select by default (used mainly for edition of courses)
+	 * @param string $parent_code the parent category of the categories added (default=null for root category)
+	 * @param string $padding the indent param (you shouldn't indicate something here)
+	 */
+	function select_and_sort_categories($select_element, $category_selected_code="", $parent_code=null , $padding="")
+	{
+		$table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
+		$sql = "SELECT code, name, auth_course_child, auth_cat_child
+				FROM ".$table_course_category." 
+				WHERE parent_id ".(is_null($parent_code) ? "IS NULL" : "='".Database::escape_string($parent_code)."'")."
+				ORDER BY tree_pos";
+		$res = api_sql_query($sql, __FILE__, __LINE__);
+		
+		$new_padding = $padding.str_repeat('-',3);
+		
+		while ($cat = Database::fetch_array($res))
+		{
+			$params = $cat['auth_course_child'] == 'TRUE' ? '' : 'disabled';
+			$params .= ($cat['code'] == $category_selected_code) ? ' selected' : '';
+			$select_element->addOption($padding.'('.$cat['code'].') '.$cat['name'], $cat['code'], $params);
+			if($cat['auth_cat_child'])
+			{
+				CourseManager::select_and_sort_categories($select_element, $cat['code'], $category_selected_code, $new_padding);
+			}
+		}
+}
+	
 } //end class CourseManager
 ?>