Browse Source

Merge branch '1.9.x' of github.com:chamilo/chamilo-lms into 1.9.x

Yannick Warnier 11 years ago
parent
commit
10c4b7c60f

+ 8 - 0
main/coursecopy/classes/Course.class.php

@@ -151,6 +151,10 @@ class Course
 							$title = $resource->title;
 							$description = $resource->description;
 							break;
+                        case RESOURCE_TEST_CATEGORY:
+                            $title = $resource->title;
+                            $description = $resource->description;
+                            break;
 						case RESOURCE_QUIZQUESTION:
 							$title = $resource->question;
 							$description = $resource->description;
@@ -298,6 +302,10 @@ class Course
 							}
 							break;
 
+                        case RESOURCE_TEST_CATEGORY:
+                            $resource->title = api_to_system_encoding($resource->title, $this->encoding);
+                            $resource->description = api_to_system_encoding($resource->description, $this->encoding);
+                            break;
 						case RESOURCE_SCORM:
 							$resource->title = api_to_system_encoding($resource->title, $this->encoding);
 							break;

+ 30 - 3
main/coursecopy/classes/CourseBuilder.class.php

@@ -15,6 +15,7 @@ require_once 'Forum.class.php';
 require_once 'ForumCategory.class.php';
 require_once 'Quiz.class.php';
 require_once 'QuizQuestion.class.php';
+require_once 'CourseCopyTestCategory.php';
 require_once 'CourseCopyLearnpath.class.php';
 require_once 'Survey.class.php';
 require_once 'SurveyQuestion.class.php';
@@ -47,6 +48,7 @@ class CourseBuilder
         'forum_topics',
         'glossary',
         'quizzes',
+        'test_category',
         'learnpaths',
         'links',
         'surveys',
@@ -469,8 +471,11 @@ class CourseBuilder
 
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
-
-            $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra);
+            // find the question category
+            // @todo : need to be adapted for multi category questions in 1.10
+            $question_category_id = Testcategory::getCategoryForQuestion($obj->id, $course_id);
+            // build the backup ressource question object
+            $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra, $question_category_id);
             $sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
             $db_result2 = Database::query($sql);
 
@@ -531,7 +536,10 @@ class CourseBuilder
 
                 // Avoid adding the same question twice
                 if (!isset($this->course->resources[$obj->id])) {
-                    $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra);
+                    // find the question category
+                    // @todo : need to be adapted for multi category questions in 1.10
+                    $question_category_id = Testcategory::getCategoryForQuestion($obj->id, $course_id);
+                    $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra, $question_category_id);
                     $sql = "SELECT * FROM $table_ans WHERE c_id = $course_id AND question_id = ".$obj->id;
                     $db_result2 = Database::query($sql);
                     if (Database::num_rows($db_result2)) {
@@ -601,6 +609,25 @@ class CourseBuilder
         }
     }
 
+    /**
+     * Build the test category
+     * $session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]
+     * @todo add course session
+     */
+    function build_test_category($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array())
+    {
+        $course_id = api_get_course_int_id();
+
+        // get all test category in course
+        $tab_test_categories_id = Testcategory::getCategoryListInfo("id", $course_id);
+        foreach ($tab_test_categories_id as $test_category_id)
+        {
+            $test_category = new Testcategory($test_category_id);
+            $copy_course_test_category = new CourseCopyTestcategory($test_category_id, $test_category->name, $test_category->description);
+            $this->course->add_resource($copy_course_test_category);
+        }
+    }
+
     /**
      * Build the Surveys
      */

+ 19 - 10
main/coursecopy/classes/CourseRecycler.class.php

@@ -49,6 +49,7 @@ class CourseRecycler
         $this->recycle_forums();
         $this->recycle_forum_categories();
         $this->recycle_quizzes();
+        $this->recycle_test_category();
         $this->recycle_surveys();
         $this->recycle_learnpaths();
         $this->recycle_cours_description();
@@ -362,16 +363,13 @@ class CourseRecycler
                     while ($obj = Database::fetch_object($db_result)) {
                         $orphan_ids[] = $obj->id;
                     }
-                    if (!empty($orphan_ids)) {
-                        $orphan_ids = implode(',', $orphan_ids);
-
-                        $sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND question_id IN(".$orphan_ids.")";
-                        Database::query($sql);
-                        $sql = "DELETE FROM ".$table_qui_ans." WHERE c_id = ".$this->course_id." AND question_id IN(".$orphan_ids.")";
-                        Database::query($sql);
-                        $sql = "DELETE FROM ".$table_qui_que." WHERE c_id = ".$this->course_id." AND id IN(".$orphan_ids.")";
-                        Database::query($sql);
-                    }
+                    $orphan_ids = implode(',', $orphan_ids);
+                    $sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND question_id IN(".$orphan_ids.")";
+                    Database::query($sql);
+                    $sql = "DELETE FROM ".$table_qui_ans." WHERE c_id = ".$this->course_id." AND question_id IN(".$orphan_ids.")";
+                    Database::query($sql);
+                    $sql = "DELETE FROM ".$table_qui_que." WHERE c_id = ".$this->course_id." AND id IN(".$orphan_ids.")";
+                    Database::query($sql);
                 }
                 // Also delete questions categories and options
                 $sql = "DELETE FROM $table_qui_que_rel_cat WHERE c_id = ".$this->course_id;
@@ -388,6 +386,17 @@ class CourseRecycler
         }
     }
 
+    /**
+     * Recycle tests categories
+     */
+    function recycle_test_category()
+    {
+        foreach ($this->course->resources[RESOURCE_TEST_CATEGORY] as $tab_test_cat) {
+            $obj_cat = new Testcategory($tab_test_cat->source_id);
+            $obj_cat->removeCategory();
+        }
+    }
+
     /**
      * Recycle surveys - removes everything
      */

+ 104 - 59
main/coursecopy/classes/CourseRestorer.class.php

@@ -30,10 +30,10 @@ require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'document.lib.php';
 
-define('FILE_SKIP', 1);
-define('FILE_RENAME', 2);
-define('FILE_OVERWRITE', 3);
-define('UTF8_CONVERT', false); //false by default
+define('FILE_SKIP',             1);
+define('FILE_RENAME',           2);
+define('FILE_OVERWRITE',        3);
+define('UTF8_CONVERT', 		false); //false by default
 
 /**
  * Class to restore items from a course object to a Chamilo-course
@@ -43,17 +43,16 @@ define('UTF8_CONVERT', false); //false by default
  */
 class CourseRestorer
 {
-    /**
-     * The course-object
-     */
-    /** @var Course */
+	/**
+	 * The course-object
+	 */
     public $course;
     public $destination_course_info;
 
-    /**
-     * What to do with files with same name (FILE_SKIP, FILE_RENAME or
-     * FILE_OVERWRITE)
-     */
+	/**
+	 * What to do with files with same name (FILE_SKIP, FILE_RENAME or
+	 * FILE_OVERWRITE)
+	 */
     public $file_option;
     public $set_tools_invisible_by_default;
     public $skip_content;
@@ -68,6 +67,7 @@ class CourseRestorer
        // 'forum_topics',
         'glossary',
         'quizzes',
+        'test_category',
         'links',
         'learnpaths',
         'surveys',
@@ -89,30 +89,29 @@ class CourseRestorer
 
 	/**
 	 * Create a new CourseRestorer
-     * @param   array   Course object as returned by other coursebuilder classes (see copy_course.php)
 	 */
     public function __construct($course)
     {
-        $this->course							= $course;
-        $course_info 							= api_get_course_info($this->course->code);
+		$this->course							= $course;
+		$course_info 							= api_get_course_info($this->course->code);
         if (!empty($course_info)) {
-            $this->course_origin_id 				= $course_info['real_id'];
+		    $this->course_origin_id 				= $course_info['real_id'];
         } else {
             $this->course_origin_id = null;
         }
-        $this->file_option 						= FILE_RENAME;
-        $this->set_tools_invisible_by_default 	= false;
-        $this->skip_content 					= array();
-    }
+		$this->file_option 						= FILE_RENAME;
+		$this->set_tools_invisible_by_default 	= false;
+		$this->skip_content 					= array();
+	}
 
-    /**
-     * Set the file-option
-     * @param constant $options What to do with files with same name (FILE_SKIP, FILE_RENAME or FILE_OVERWRITE). Default is to skip the copy of files that already exist
-     */
-    function set_file_option($option = FILE_SKIP)
+	/**
+	 * Set the file-option
+	 * @param constant $options What to do with files with same name (FILE_SKIP, FILE_RENAME or FILE_OVERWRITE)
+	 */
+    function set_file_option($option)
     {
-        $this->file_option = $option;
-    }
+		$this->file_option = $option;
+	}
     function set_add_text_in_items($status)
     {
         $this->add_text_in_items = $status;
@@ -122,13 +121,13 @@ class CourseRestorer
         $this->tool_copy_settings = $array;
     }
 
-    /**
-     * Restore a course.
-     * @param 	string 	The code of the Chamilo-course in
-     * @param	int		The session id
-     * @param	bool	Course settings are going to be restore.
-     * @param bool $respect_base_content
-     */
+	/**
+	 * Restore a course.
+	 * @param 	string 	The code of the Chamilo-course in
+	 * @param	int		The session id
+	 * @param	bool	Course settings are going to be restore?
+
+	 */
     public function restore(
         $destination_course_code = '',
         $session_id = 0,
@@ -146,7 +145,7 @@ class CourseRestorer
 		}
 		$this->destination_course_id = $course_info['real_id'];
 
-        // Getting first teacher (for the forums)
+        //Getting first teacher (for the forums)
         $teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['code']);
         $this->first_teacher_id = api_get_user_id();
 
@@ -1309,6 +1308,76 @@ class CourseRestorer
 	}
 
 	/**
+     * @todo : add session id when used for session
+     */
+    function restore_test_category($session_id, $respect_base_content, $destination_course_code)
+    {
+        $course_id = api_get_course_int_id();
+        // Let's restore the categories
+        $tab_test_category_id_old_new = array(); // used to build the quiz_question_rel_category table
+        if ($this->course->has_resources(RESOURCE_TEST_CATEGORY))
+        {
+            $resources = $this->course->resources;
+            foreach ($resources[RESOURCE_TEST_CATEGORY] as $id => $CourseCopyTestcategory )
+            {
+                $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
+                // check if this test_category already exist in the destination BDD
+                // do not Database::escape_string $title and $description, it will be done later
+                $title = $CourseCopyTestcategory->title;
+                $description = $CourseCopyTestcategory->description;
+
+                if (Testcategory::category_exists_with_title($title))
+                {
+                    switch ($this->file_option)
+                    {
+                        case FILE_SKIP:
+                            //Do nothing
+                            break;
+                        case FILE_RENAME:
+                            $new_title = $title."_";
+                            while (Testcategory::category_exists_with_title($new_title))
+                            {
+                                $new_title .= "_";
+                            }
+                            $test_category = new Testcategory(0, $new_title, $description);
+                            $new_id = $test_category->addCategoryInBDD();
+                            $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $new_id;
+                            break;
+                        case FILE_OVERWRITE:
+                            $id = Testcategory::get_category_id_for_title($title);
+                            $my_cat = new Testcategory($id);
+                            $my_cat->name = $title;
+                            $my_cat->modifyCategory();
+                            $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
+                            break;
+                    }
+                }
+                else
+                {
+                    // create a new test_category
+                    $test_category = new Testcategory(0, $title, $description);
+                    $new_id = $test_category->addCategoryInBDD();
+                    $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $new_id;
+                }
+                $this->course->resources[RESOURCE_TEST_CATEGORY][$id]->destination_id = $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id];
+            }
+        }
+        // lets check if quizzes-question are restored too, to redo the link between test_category and quizzes question for questions restored
+        // we can use the source_id field
+        // question source_id => category source_id
+        if ($this->course->has_resources(RESOURCE_QUIZQUESTION)) {
+            // check the category number of each question restored
+            foreach ($resources[RESOURCE_QUIZQUESTION] as $id => $CourseCopyQuestion) {
+                $new_quiz_question_id = $resources[RESOURCE_QUIZQUESTION][$id]->destination_id;
+                $question_category = $CourseCopyQuestion->question_category;
+                if ($question_category > 0) {
+                    Testcategory::add_category_for_question_id($tab_test_category_id_old_new[$question_category], $new_quiz_question_id, $course_id);
+                }
+            }
+        }
+    }
+
+    /**
 	 * Restore surveys
 	 */
     function restore_surveys()
@@ -2027,12 +2096,10 @@ class CourseRestorer
 
                 // check resources inside html from fckeditor tool and copy correct urls into recipient course
                 $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($obj->params['description'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
-                $id_work = $obj->params['id'];
                 $obj->params['id'] = null;
                 $obj->params['c_id'] = $this->destination_course_id;
 
                 $last_id = Database::insert($table_work, $obj->params);
-                
                 // re-create dir
                 // @todo check security against injection of dir in crafted course backup here!
                 $path = $obj->params['url'];
@@ -2044,28 +2111,6 @@ class CourseRestorer
                 }
 
                 if (is_numeric($last_id)) {
-                    $sql = 'SELECT *
-                            FROM '.$table_work_assignment.'
-                            WHERE  c_id = '.$this->course_origin_id.' AND
-                                   publication_id = '.$id_work;
-
-                    $result = Database::query($sql);
-                    $cant = Database::num_rows($result);
-                    if ($cant > 0) {                    
-                        $row = Database::fetch_assoc($result);
-                        $expires_date = $row['expires_on'];
-                        $end_date = $row['ends_on'];
-                        $add_to_calendar = $row['add_to_calendar'];
-                        $enable_calification = $row['enable_calification'];
-                        $sql_add_homework = "INSERT INTO $table_work_assignment SET
-                                                    c_id                 = $this->destination_course_id ,
-                                                    expires_on       		= '$expires_date',
-                                                    ends_on        	 	 = '$end_date',
-                                                    add_to_calendar  		= '$add_to_calendar',
-                                                    enable_qualification = '$enable_calification',
-                                                    publication_id 			= '$last_id'";
-                        Database::query($sql_add_homework);
-                    }
                     api_item_property_update($this->destination_course_info, 'work', $last_id,"DirectoryCreated", api_get_user_id());
                 }
             }

+ 1 - 0
main/coursecopy/classes/CourseSelectForm.class.php

@@ -27,6 +27,7 @@ class CourseSelectForm
 		$resource_titles[RESOURCE_FORUM]                = get_lang('Forums');
         $resource_titles[RESOURCE_FORUMCATEGORY]        = get_lang('ForumCategory');
 		$resource_titles[RESOURCE_QUIZ] 				= get_lang('Tests');
+        $resource_titles[RESOURCE_TEST_CATEGORY] 		= get_lang('QuestionCategory');
 		$resource_titles[RESOURCE_LEARNPATH]            = get_lang('ToolLearnpath');
 		$resource_titles[RESOURCE_SCORM]                = 'SCORM';
 		$resource_titles[RESOURCE_TOOL_INTRO]           = get_lang('ToolIntro');

+ 8 - 1
main/coursecopy/classes/QuizQuestion.class.php

@@ -59,6 +59,12 @@ class QuizQuestion extends Resource
     var $picture;
     var $extra;
 
+    /**
+     * @var int the question category if any, 0 by default
+     */
+
+    var $question_category;
+
     /**
      * Create a new QuizQuestion
      * @param string $question
@@ -67,7 +73,7 @@ class QuizQuestion extends Resource
      * @param int $type
      * @param int $position
      */
-    function QuizQuestion($id, $question, $description, $ponderation, $type, $position, $picture, $level, $extra) {
+    function QuizQuestion($id, $question, $description, $ponderation, $type, $position, $picture, $level, $extra, $question_category = 0) {
         parent::Resource($id, RESOURCE_QUIZQUESTION);
         $this->question = $question;
         $this->description = $description;
@@ -78,6 +84,7 @@ class QuizQuestion extends Resource
         $this->level = $level;
         $this->answers = array();
         $this->extra = $extra;
+        $this->question_category = $question_category;
     }
 
     /**

+ 3 - 0
main/coursecopy/classes/Resource.class.php

@@ -19,6 +19,7 @@ define('RESOURCE_FORUM', 'forum');
 define('RESOURCE_FORUMTOPIC', 'thread');
 define('RESOURCE_FORUMPOST', 'post');
 define('RESOURCE_QUIZ', 'quiz');
+define('RESOURCE_TEST_CATEGORY', 'test_category');
 define('RESOURCE_QUIZQUESTION', 'Exercise_Question');
 define('RESOURCE_TOOL_INTRO', 'Tool introduction');
 define('RESOURCE_LINKCATEGORY', 'Link_Category');
@@ -158,6 +159,8 @@ class Resource {
                 return TOOL_POST;
             case RESOURCE_QUIZ:
                 return TOOL_QUIZ;
+            case RESOURCE_TEST_CATEGORY:
+                return TOOL_TEST_CATEGORY;
             //case RESOURCE_QUIZQUESTION: //no corresponding global constant
             //	return TOOL_QUIZ_QUESTION;
             //case RESOURCE_TOOL_INTRO:

+ 79 - 11
main/exercice/testcategory.class.php

@@ -62,7 +62,13 @@ class Testcategory
 			$c_id = api_get_course_int_id();
 			$sql = "INSERT INTO $t_cattable VALUES ('$c_id', '', '$v_name', '$v_description')";
 			$res = Database::query($sql);
-			return true;
+//            $id_cat_added = Database::insert_id();
+            $new_id = Database::insert_id();
+            // add test_category in item_property table
+            $course_code = api_get_course_id();
+            $course_info = api_get_course_info($course_code);
+            api_item_property_update($course_info, TOOL_TEST_CATEGORY, $new_id, 'TestCategoryAdded', api_get_user_id());
+			return $new_id;
 		}
 		else {
 			return false;
@@ -70,25 +76,32 @@ class Testcategory
 	}
 
 	/**
-     * Removes the category with id=in_id from the database if no question use this category
-     * @todo I'm removing the $in_id parameter because it seems that you're using $this->id instead of $in_id after confirmation delete this
-     * jmontoya
+     * Removes the category from the database
+     * if there were question in this category, the link between question and category is removed
 	 */
-	//function removeCategory($in_id) {
     function removeCategory() {
 		$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
+        $tbl_question_rel_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
 		$v_id = Database::escape_string($this->id);
 		$sql = "DELETE FROM $t_cattable WHERE id=$v_id AND c_id=".api_get_course_int_id();
 		$res = Database::query($sql);
 		if (Database::affected_rows() <= 0) {
 			return false;
 		} else {
+            // remove link between question and category
+            $sql2 = "DELETE FROM $tbl_question_rel_cat WHERE category_id=$v_id AND c_id=".api_get_course_int_id();
+            Database::query($sql2);
+            // item_property update
+            $course_code = api_get_course_id();
+            $course_info = api_get_course_info($course_code);
+            api_item_property_update($course_info, TOOL_TEST_CATEGORY, $this->id, 'TestCategoryDeleted', api_get_user_id());
 			return true;
 		}
 	}
 
 
-	/** modify category name or description of category with id=in_id
+	/**
+     * modify category name or description of category with id=in_id
 	 */
 	//function modifyCategory($in_id, $in_name, $in_description) {
     function modifyCategory() {
@@ -102,16 +115,17 @@ class Testcategory
 			return false;
 		}
 		else {
+            // item_property update
+            $course_code = api_get_course_id();
+            $course_info = api_get_course_info($course_code);
+            api_item_property_update($course_info, TOOL_TEST_CATEGORY, $this->id, 'TestCategoryModified', api_get_user_id());
 			return true;
 		}
 	}
 
 	/**
      * Gets the number of question of category id=in_id
-     * @todo I'm removing the $in_id parameter because it seems that you're using $this->id instead of $in_id after confirmation delete this
-     * jmontoya
 	 */
-	//function getCategoryQuestionsNumber($in_id) {
 	function getCategoryQuestionsNumber() {
 		$t_reltable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
 		$in_id = Database::escape_string($this->id);
@@ -215,7 +229,7 @@ class Testcategory
 	}
 
 	/**
-	 * return the list of differents categories ID for a test
+	 * return the list of differents categories ID for a test in the current course
 	 * input : test_id
 	 * return : array of category id (integer)
 	 * hubert.borderiou 07-04-2011
@@ -331,7 +345,6 @@ class Testcategory
 	 */
 	function getQuestionsByCat($in_exerciceId) {
 		$tabres = array();
-		$TBL_EXERCICE = Database::get_course_table(TABLE_QUIZ_TEST);
 		$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
 		$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
         $in_exerciceId = intval($in_exerciceId);
@@ -513,4 +526,59 @@ class Testcategory
         }
         return null;
     }
+
+
+    /**
+     * Return true if a category already exists with the same name
+     * @param $in_name
+     */
+    public static function category_exists_with_title($in_name)
+    {
+        $tab_test_category = Testcategory::getCategoryListInfo("title");
+        foreach ($tab_test_category as $title)
+        {
+            if ($title == $in_name)
+            {
+                return true;
+}
+        }
+        return false;
+    }
+
+
+    /**
+     * Return the id of the test category with title = $in_title
+     * @param $in_title
+     * @param int $in_c_id
+     * @return int is id of test category
+     */
+    public static function get_category_id_for_title($in_title, $in_c_id = 0) {
+        $out_res = 0;
+        if ($in_c_id == 0) {
+            $in_c_id = api_get_course_int_id();
+        }
+        $tbl_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
+        $sql = "SELECT id FROM $tbl_cat WHERE c_id=$in_c_id AND title = '".Database::escape_string($in_title)."'";
+        $res = Database::query($sql);
+        if (Database::num_rows($res) > 0) {
+            $data = Database::fetch_array($res);
+            $out_res = $data['id'];
+        }
+        return $out_res;
+    }
+
+    /**
+     * Add a relation between question and category in table c_quiz_question_rel_category
+     * @param $in_category_id
+     * @param $in_question_id
+     */
+    public static function add_category_for_question_id($in_category_id, $in_question_id, $in_course_c_id) {
+        $tbl_reltable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
+        // if question doesn't have a category
+        // @todo change for 1.10 when a question can have several categories
+        if (Testcategory::getCategoryForQuestion($in_question_id, $in_course_c_id) == 0 && $in_question_id > 0 && $in_course_c_id > 0) {
+            $sql = "INSERT INTO $tbl_reltable VALUES (".intval($in_course_c_id).", ".intval($in_question_id).", ".intval($in_category_id).")";
+            $res = Database::query($sql);
+        }
+    }
 }

+ 1 - 10
main/exercice/tests_category.php

@@ -120,16 +120,13 @@ function delete_category_form($in_action) {
     if (isset($_GET['category_id']) && is_numeric($_GET['category_id'])) {
         $category_id = Security::remove_XSS($_GET['category_id']);
         $catobject = new Testcategory($category_id);
-        if ($catobject->getCategoryQuestionsNumber() == 0) {
             if ($catobject->removeCategory()) {
                 Display::display_confirmation_message(get_lang('DeleteCategoryDone'));
             } else {
                 Display::display_error_message(get_lang('CannotDeleteCategoryError'));
             }
-        } else {
-            Display::display_error_message(get_lang('CannotDeleteCategory'));
         }
-    } else {
+    else {
         Display::display_error_message(get_lang('CannotDeleteCategoryError'));
     }
     display_add_category();
@@ -208,16 +205,10 @@ function display_categories() {
         echo '</div>';
         echo '<div>';
         echo '<a href="' . api_get_self() . '?action=editcategory&amp;category_id=' . $row['id'] . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
-        if ($nb_question > 0) {
-            echo '<a href="javascript:void(0)" onclick="alert(\'' . protectJSDialogQuote(get_lang('CannotDeleteCategory')) . '\')">';
-            echo Display::return_icon('delete_na.png', get_lang('CannotDeleteCategory'), array(), ICON_SIZE_SMALL);
-            echo '</a>';
-        } else {
             $rowname = protectJSDialogQuote($row['title']);
             echo ' <a href="' . api_get_self() . '?action=deletecategory&amp;category_id=' . $row['id'] . '" ';
             echo 'onclick="return confirmDelete(\'' . protectJSDialogQuote(get_lang('DeleteCategoryAreYouSure') . '[' . $rowname) . '] ?\', \'id_cat' . $row['id'] . '\');">';
             echo Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
-        }
         echo '</div>';
     }
 }

+ 1 - 0
main/inc/lib/main_api.lib.php

@@ -101,6 +101,7 @@ define('TOOL_THREAD', 'thread');
 define('TOOL_POST', 'post');
 define('TOOL_DROPBOX', 'dropbox');
 define('TOOL_QUIZ', 'quiz');
+define('TOOL_TEST_CATEGORY', 'test_category');
 define('TOOL_USER', 'user');
 define('TOOL_GROUP', 'group');
 define('TOOL_BLOGS', 'blog_management'); // Smartblogs (Kevin Van Den Haute :: kevin@develop-it.be)