'.get_lang('ThisFieldIsRequired'), 'required');
+ // --------------------
+ // The validation or display
+ // --------------------
+ if ($form->validate())
+ {
+ $check = Security::check_token('post');
+ if ($check) {
+ $values = $form->exportValues();
+ $v_id = Security::remove_XSS($values['category_id']);
+ $v_name = Security::remove_XSS($values['category_name'], COURSEMANAGER);
+ $v_description = Security::remove_XSS($values['category_description'], COURSEMANAGER);
+ $objcat = new Testcategory($v_id, $v_name, $v_description);
+ if ($objcat->modifyCategory()) {
+ Display::display_confirmation_message(get_lang('MofidfyCategoryDone'));
+ }
+ else {
+ Display::display_confirmation_message(get_lang('ModifyCategoryError'));
+ }
+ }
+ Security::clear_token();
+ display_add_category();
+ display_categories();
+ }
+ else
+ {
+ display_goback();
+ $token = Security::get_token();
+ $form->addElement('hidden','sec_token');
+ $form->setConstants(array('sec_token' => $token));
+ $form->display();
+ display_categories();
+ }
+ }
+ else {
+ Display::display_error_message(get_lang('CannotEditCategory'));
+ }
+}
+
+// ------------------------------------------------------------------------
+// process to delete a category
+// ------------------------------------------------------------------------
+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 {
+ Display::display_error_message(get_lang('CannotDeleteCategoryError'));
+ }
+ display_add_category();
+ display_categories();
+}
+
+// ------------------------------------------------------------------------
+// form to add a category
+// ------------------------------------------------------------------------
+function add_category_form($in_action) {
+ // initiate the object
+ $form = new FormValidator('note','post', api_get_self().'?action='.$in_action);
+ // settting the form elements
+ $form->addElement('header', '', get_lang('AddACategory'));
+ $form->addElement('text', 'category_name', get_lang('CategoryName'),array('size'=>'95'));
+ $form->addElement('html_editor', 'category_description', get_lang('CategoryDescription'), null, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
+ $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddTestCategory'), 'class="add"');
+ // setting the rules
+ $form->addRule('category_name', '
'.get_lang('ThisFieldIsRequired'), 'required');
+ // The validation or display
+ if ($form->validate())
+ {
+ $check = Security::check_token('post');
+ if ($check) {
+ $values = $form->exportValues();
+ $v_name = Security::remove_XSS($values['category_name'], COURSEMANAGER);
+ $v_description = Security::remove_XSS($values['category_description'], COURSEMANAGER);
+ $objcat = new Testcategory(0, $v_name, $v_description);
+ if ($objcat->addCategoryInBDD()) {
+ Display::display_confirmation_message(get_lang('AddCategoryDone'));
+ }
+ else {
+ Display::display_confirmation_message(get_lang('AddCategoryNameAlreadyExists'));
+ }
+ }
+ Security::clear_token();
+ display_add_category();
+ display_categories();
+ }
+ else
+ {
+ display_goback();
+ $token = Security::get_token();
+ $form->addElement('hidden','sec_token');
+ $form->setConstants(array('sec_token' => $token));
+ $form->display();
+ display_categories();
+ }
+}
+
+
+// ------------------------------------------------------------------------
+// Display add category button
+// ------------------------------------------------------------------------
+function display_add_category() {
+ echo '
';
+ echo "
";
+}
+
+
+// ------------------------------------------------------------------------
+// Display category list
+// ------------------------------------------------------------------------
+function display_categories() {
+ $t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
+ $sql = "SELECT * FROM $t_cattable ORDER BY name";
+ $res = Database::query($sql, __FILE__, __LINE__);
+ while ($row = Database::fetch_array($res)) {
+ // le titre avec le nombre de questions qui sont dans cette catégorie
+ $tmpobj = new Testcategory($row['id']);
+ $nb_question = $tmpobj->getCategoryQuestionsNumber();
+ echo '
';
+ echo "".$nb_question.get_lang('NbCategory')."";
+ echo $row['name'];
+ echo '
';
+ echo '';
+ echo '
';
+ }
+}
+
+
+// ------------------------------------------------------------------------
+// display goback to category list page link
+// ------------------------------------------------------------------------
+function display_goback() {
+ echo '
';
+}
+
+// ------------------------------------------------------------------------
+// To allowed " in javascript dialog box without bad surprises
+// replace " with two '
+// ------------------------------------------------------------------------
+function protectJSDialogQuote($in_txt) {
+ $res = $in_txt;
+ $res = str_replace("'", "\'", $res);
+ $res = str_replace('"', "\'\'", $res); // super astuce pour afficher les " dans les boite de dialogue
+ return $res;
+}
+
+?>
\ No newline at end of file
diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php
index 7e01d1757a..93a32b9b99 100644
--- a/main/inc/lib/add_course.lib.inc.php
+++ b/main/inc/lib/add_course.lib.inc.php
@@ -297,6 +297,9 @@ function update_Db_course($course_db_name = null) {
$TABLEQUIZQUESTIONLIST = $course_db_name . 'quiz_question';
$TABLEQUIZANSWERSLIST = $course_db_name . 'quiz_answer';
$TABLEQUIZQUESTIONOPTION = $course_db_name . 'quiz_question_option';
+
+ $table_quiz_question_category = $course_db_name . 'quiz_question_category';
+ $table_quiz_question_rel_category = $course_db_name . 'quiz_question_rel_category';
// Dropbox
$TABLETOOLDROPBOXPOST = $course_db_name . 'dropbox_post';
@@ -646,6 +649,7 @@ function update_Db_course($course_db_name = null) {
session_id smallint default 0,
propagate_neg INT NOT NULL DEFAULT 0,
review_answers INT NOT NULL DEFAULT 0,
+ random_by_category INT NOT NULL DEFAULT 0,
PRIMARY KEY (c_id, id)
)" . $charset_clause;
Database::query($sql);
@@ -693,8 +697,6 @@ function update_Db_course($course_db_name = null) {
)" . $charset_clause;
Database::query($sql);
-
-
// Exercise tool - answer options
$sql = "
CREATE TABLE `".$TABLEQUIZQUESTIONOPTION . "` (
@@ -718,7 +720,28 @@ function update_Db_course($course_db_name = null) {
PRIMARY KEY (c_id, question_id,exercice_id)
)" . $charset_clause;
Database::query($sql);
-
+
+
+
+ $sql = "CREATE TABLE `".$table_quiz_question_category . "` (
+ $add_to_all_tables
+ id int NOT NULL AUTO_INCREMENT,
+ name varchar(255) NOT NULL,
+ description text NOT NULL,
+ PRIMARY KEY (c_id,id)
+ )" . $charset_clause;
+ Database::query($sql);
+
+
+ $sql = "CREATE TABLE `".$table_quiz_question_rel_category . "` (
+ $add_to_all_tables
+ question_id int NOT NULL,
+ category_id int NOT NULL,
+ PRIMARY KEY (c_id,question_id)
+ )" . $charset_clause;
+ Database::query($sql);
+
+
/* Course description */
$sql = "
diff --git a/main/inc/lib/database.constants.inc.php b/main/inc/lib/database.constants.inc.php
index 1a414b1cae..205eae0181 100644
--- a/main/inc/lib/database.constants.inc.php
+++ b/main/inc/lib/database.constants.inc.php
@@ -15,6 +15,7 @@
*/
//See #3910 defines the default prefix for the single course database
+// Modified by hubert.borderiou 2011-10-21 Add course category
define('DB_COURSE_PREFIX', 'c_');
// Main database tables
@@ -195,6 +196,8 @@ define('TABLE_QUIZ_TEST', 'quiz');
define('TABLE_QUIZ_ANSWER', 'quiz_answer');
define('TABLE_QUIZ_TEST_QUESTION', 'quiz_rel_question');
define('TABLE_QUIZ_QUESTION_OPTION','quiz_question_option');
+define('TABLE_QUIZ_QUESTION_CATEGORY', 'quiz_question_category');
+define('TABLE_QUIZ_QUESTION_REL_CATEGORY', 'quiz_question_rel_category');
// Linked resource table
//@todo table exists?
diff --git a/main/inc/lib/fckeditor/toolbars/default/test_category.php b/main/inc/lib/fckeditor/toolbars/default/test_category.php
new file mode 100644
index 0000000000..1ba97aa396
--- /dev/null
+++ b/main/inc/lib/fckeditor/toolbars/default/test_category.php
@@ -0,0 +1,10 @@
+
diff --git a/main/install/migrate-db-1.8.8-1.9.0-pre.sql b/main/install/migrate-db-1.8.8-1.9.0-pre.sql
index 1bc65b49ab..3406f6813a 100755
--- a/main/install/migrate-db-1.8.8-1.9.0-pre.sql
+++ b/main/install/migrate-db-1.8.8-1.9.0-pre.sql
@@ -128,4 +128,5 @@ INSERT INTO course_setting(variable,value,category) VALUES ('course_grading_mode
ALTER TABLE quiz ADD COLUMN review_answers INT NOT NULL DEFAULT 0;
ALTER TABLE student_publication ADD COLUMN contains_file INTEGER NOT NULL DEFAULT 1;
ALTER TABLE student_publication ADD COLUMN allow_text_assignment INTEGER NOT NULL DEFAULT 0;
+ALTER TABLE quiz ADD COLUMN random_by_category INT NOT NULL DEFAULT 0;