commit
0d5680a858
@ -0,0 +1,421 @@ |
||||
<?php |
||||
// $Id: testcategory.class.php 2010-12-06 hubert.borderiou |
||||
|
||||
if(!class_exists('Testcategory')): |
||||
|
||||
class Testcategory { |
||||
public $id; |
||||
public $name; |
||||
public $description; |
||||
|
||||
/** |
||||
* Constructor of the class Category |
||||
* @author - Hubert Borderiou |
||||
If you give an in_id and no in_name, you get info concerning the category of id=in_id |
||||
otherwise, you've got an category objet avec your in_id, in_name, in_descr |
||||
*/ |
||||
function Testcategory($in_id=0, $in_name, $in_description="") { |
||||
if ($in_id != 0 && $in_name == "") { |
||||
$tmpobj = new Testcategory(); |
||||
$tmpobj->getCategory($in_id); |
||||
$this->id = $tmpobj->id; |
||||
$this->name = $tmpobj->name; |
||||
$this->description = $tmpobj->description; |
||||
} |
||||
else { |
||||
$this->id = $in_id; |
||||
$this->name = $in_name; |
||||
$this->description = $in_description; |
||||
} |
||||
} |
||||
|
||||
/** return the Testcategory object with id=in_id |
||||
*/ |
||||
function getCategory($in_id) { |
||||
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
||||
$in_id = Database::escape_string($in_id); |
||||
$sql = "SELECT * FROM $t_cattable WHERE id=$in_id AND c_id=".api_get_course_int_id(); |
||||
$res = Database::query($sql); |
||||
$numrows = Database::num_rows($res); |
||||
if ($numrows > 0) { |
||||
$row = Database::fetch_array($res); |
||||
$this->id = $row['id']; |
||||
$this->name = $row['name']; |
||||
$this->description = $row['description']; |
||||
} |
||||
} |
||||
|
||||
/** add Testcategory in the database if name doesn't already exists |
||||
*/ |
||||
function addCategoryInBDD() { |
||||
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
||||
$v_name = $this->name; |
||||
$v_name = Database::escape_string($v_name); |
||||
$v_description = $this->description; |
||||
$v_description = Database::escape_string($v_description); |
||||
// check if name already exists |
||||
$sql_verif = "SELECT count(*) AS nb FROM $t_cattable WHERE name = '$v_name' AND c_id=".api_get_course_int_id(); |
||||
$result_verif = Database::query($sql_verif, __FILE__, __LINE__); |
||||
$data_verif = Database::fetch_array($result_verif); |
||||
// lets add in BDD if not the same name |
||||
if ($data_verif['nb'] <= 0) { |
||||
$c_id = api_get_course_int_id(); |
||||
$sql = "INSERT INTO $t_cattable VALUES ('$c_id', '', '$v_name', '$v_description')"; |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
return true; |
||||
} |
||||
else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** remove catagory with id=in_id from the database if no question use this category |
||||
*/ |
||||
function removeCategory($in_id) { |
||||
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_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 { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** modify category name or description of category with id=in_id |
||||
*/ |
||||
function modifyCategory($in_id, $in_name, $in_description) { |
||||
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
||||
$v_id = Database::escape_string($this->id); |
||||
$v_name = Database::escape_string($this->name); |
||||
$v_description = Database::escape_string($this->description); |
||||
$sql = "UPDATE $t_cattable SET name='$v_name', description='$v_description' WHERE id='$v_id' AND c_id=".api_get_course_int_id(); |
||||
$res = Database::query($sql); |
||||
if (Database::affected_rows() <= 0) { |
||||
return false; |
||||
} |
||||
else { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
/** get number of question of category id=in_id |
||||
*/ |
||||
function getCategoryQuestionsNumber($in_id) { |
||||
$t_reltable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
||||
$in_id = Database::escape_string($this->id); |
||||
$sql = "SELECT count(*) AS nb FROM $t_reltable WHERE category_id=$in_id AND c_id=".api_get_course_int_id(); |
||||
$res = Database::query($sql, __FILE__, __LINE__); |
||||
$row = Database::fetch_array($res); |
||||
return $row['nb']; |
||||
} |
||||
|
||||
|
||||
function display($in_color="#E0EBF5") { |
||||
echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>"; |
||||
print_r($this); |
||||
echo "</textarea>"; |
||||
} |
||||
|
||||
|
||||
|
||||
/** return an array of all Category objects in the database |
||||
If in_field=="" Return an array of all category objects in the database |
||||
Otherwise, return an array of all in_field value in the database (in_field = id or name or description) |
||||
*/ |
||||
public function getCategoryListInfo($in_field="", $in_courseid="") { |
||||
if (empty($in_courseid) || $in_courseid=="") { |
||||
$in_courseid = api_get_course_int_id(); |
||||
} |
||||
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
||||
$in_field = Database::escape_string($in_field); |
||||
$tabres = array(); |
||||
if ($in_field=="") { |
||||
$sql = "SELECT * FROM $t_cattable WHERE c_id=$in_courseid ORDER BY name ASC"; |
||||
$res = Database::query($sql); |
||||
while ($row = Database::fetch_array($res)) { |
||||
$tmpcat = new Testcategory($row['id'], $row['name'], $row['description']); |
||||
$tabres[] = $tmpcat; |
||||
} |
||||
} |
||||
else { |
||||
$sql = "SELECT $in_field FROM $t_cattable WHERE c_id=$in_courseid ORDER BY $in_field ASC"; |
||||
$res = Database::query($sql); |
||||
while ($row = Database::fetch_array($res)) { |
||||
$tabres[] = $row[$in_field]; |
||||
} |
||||
} |
||||
return $tabres; |
||||
} |
||||
|
||||
|
||||
/** |
||||
Return the testcategory id for question with question_id = $in_questionid |
||||
In this version, a question has only 1 testcategory. |
||||
Return the testcategory id, 0 if none |
||||
*/ |
||||
public static function getCategoryForQuestion($in_questionid, $in_courseid="") { |
||||
$result = 0; // result |
||||
if (empty($in_courseid) || $in_courseid=="") { |
||||
$in_courseid = api_get_course_int_id(); |
||||
} |
||||
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
||||
$question_id = Database::escape_string($in_questionid); |
||||
$sql = "SELECT category_id FROM $t_cattable WHERE question_id='$question_id' AND c_id=$in_courseid"; |
||||
$res = Database::query($sql); |
||||
$data = Database::fetch_array($res); |
||||
if (Database::num_rows($res) > 0) { |
||||
$result = $data['category_id']; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* true if question id has a category |
||||
*/ |
||||
public static function isQuestionHasCategory($in_questionid) { |
||||
if (Testcategory::getCategoryForQuestion($in_questionid) > 0) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
/** |
||||
Return the category name for question with question_id = $in_questionid |
||||
In this version, a question has only 1 category. |
||||
Return the category id, "" if none |
||||
*/ |
||||
function getCategoryNameForQuestion($in_questionid, $in_courseid="") { |
||||
if (empty($in_courseid) || $in_courseid=="") { |
||||
$in_courseid = api_get_course_int_id(); |
||||
} |
||||
$catid = Testcategory::getCategoryForQuestion($in_questionid, $in_courseid); |
||||
$result = ""; // result |
||||
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
||||
$catid = Database::escape_string($catid); |
||||
$sql = "SELECT name FROM $t_cattable WHERE id='$catid' AND c_id=$in_courseid"; |
||||
$res = Database::query($sql); |
||||
$data = Database::fetch_array($res); |
||||
if (Database::num_rows($res) > 0) { |
||||
$result = $data['name']; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* return the list of differents categories ID for a test |
||||
* input : test_id |
||||
* return : array of category id (integer) |
||||
* hubert.borderiou 07-04-2011 |
||||
*/ |
||||
public static function getListOfCategoriesIDForTest($in_testid) { |
||||
// parcourir les questions d'un test, recup les categories uniques dans un tableau |
||||
$tabcat = array(); |
||||
$quiz = new Exercise(); |
||||
$quiz->read($in_testid); |
||||
$tabQuestionList = $quiz->selectQuestionList(); |
||||
for ($i=0; $i < count($tabQuestionList); $i++) { |
||||
if (!in_array(Testcategory::getCategoryForQuestion($tabQuestionList[$i]), $tabcat)) { |
||||
$tabcat[] = Testcategory::getCategoryForQuestion($tabQuestionList[$i]); |
||||
} |
||||
} |
||||
return $tabcat; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* return the list of differents categories NAME for a test |
||||
* input : test_id |
||||
* return : array of string |
||||
* hubert.borderiou 07-04-2011 |
||||
*/ |
||||
public static function getListOfCategoriesNameForTest($in_testid) { |
||||
$tabcatName = array(); |
||||
$tabcatID = getListOfCategoriesNameForTest($in_testid); |
||||
for ($i=0; $i < count($tabcatID); $i++) { |
||||
$cat = new Testcategory($tabcatID[$i]); |
||||
$tabcatName[] = $cat->name; |
||||
} |
||||
return $tabcatName; |
||||
} |
||||
|
||||
/** |
||||
* return the number of differents categories for a test |
||||
* input : test_id |
||||
* return : integer |
||||
* hubert.borderiou 07-04-2011 |
||||
*/ |
||||
public static function getNumberOfCategoriesForTest($in_testid) { |
||||
return count(Testcategory::getListOfCategoriesIDForTest($in_testid)); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* return the number of question of a category id in a test |
||||
* input : test_id, category_id |
||||
* return : integer |
||||
* hubert.borderiou 07-04-2011 |
||||
*/ |
||||
public static function getNumberOfQuestionsInCategoryForTest($in_testid, $in_categoryid) { |
||||
$nbCatResult = 0; |
||||
$quiz = new Exercise(); |
||||
$quiz->read($in_testid); |
||||
$tabQuestionList = $quiz->selectQuestionList(); |
||||
for ($i=0; $i < count($tabQuestionList); $i++) { |
||||
if (Testcategory::getCategoryForQuestion($tabQuestionList[$i]) == $in_categoryid) { |
||||
$nbCatResult++; |
||||
} |
||||
} |
||||
return $nbCatResult; |
||||
} |
||||
|
||||
/** |
||||
* return the number of question for a test using random by category |
||||
* input : test_id, number of random question (min 1) |
||||
* hubert.borderiou 07-04-2011 |
||||
* question witout categories are not counted |
||||
*/ |
||||
public static function getNumberOfQuestionRandomByCategory($in_testid, $in_nbrandom) { |
||||
$nbquestionresult = 0; |
||||
$tabcatid = Testcategory::getListOfCategoriesIDForTest($in_testid); |
||||
for ($i=0; $i < count($tabcatid); $i++) { |
||||
if ($tabcatid[$i] > 0) { // 0 = no category for this questio |
||||
$nbQuestionInThisCat = Testcategory::getNumberOfQuestionsInCategoryForTest($in_testid, $tabcatid[$i]); |
||||
if ($nbQuestionInThisCat > $in_nbrandom) { |
||||
$nbquestionresult += $in_nbrandom; |
||||
} |
||||
else { |
||||
$nbquestionresult += $nbQuestionInThisCat; |
||||
} |
||||
} |
||||
} |
||||
return $nbquestionresult; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Return an array (id=>name) |
||||
* tabresult[0] = get_lang('NoCategory'); |
||||
* |
||||
*/ |
||||
function getCategoriesIdAndName($in_courseid="") { |
||||
if (empty($in_courseid) || $in_courseid=="") { |
||||
$in_courseid = api_get_course_int_id(); |
||||
} |
||||
$tabcatobject = Testcategory::getCategoryListInfo("", $in_courseid); |
||||
$tabresult = array("0"=>get_lang('NoCategory')); |
||||
for ($i=0; $i < count($tabcatobject); $i++) { |
||||
$tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name; |
||||
} |
||||
return $tabresult; |
||||
} |
||||
|
||||
/** |
||||
* return an array of question_id for each category |
||||
* tabres[0] = array of question id with category id = 0 (i.e. no category) |
||||
* tabres[24] = array of question id with category id = 24 |
||||
* In this version, a question has 0 or 1 category |
||||
*/ |
||||
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); |
||||
$sql = "SELECT qrc.question_id, qrc.category_id FROM $TBL_QUESTION_REL_CATEGORY qrc, $TBL_EXERCICE_QUESTION eq WHERE exercice_id=$in_exerciceId AND eq.question_id=qrc.question_id AND eq.c_id=".api_get_course_int_id()." AND eq.c_id=qrc.c_id ORDER BY category_id, question_id"; |
||||
$res = Database::query($sql); |
||||
while ($data = Database::fetch_array($res)) { |
||||
if (!is_array($tabres[$data['category_id']])) { |
||||
$tabres[$data['category_id']] = array(); |
||||
} |
||||
$tabres[$data['category_id']][] = $data['question_id']; |
||||
} |
||||
return $tabres; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* return a tab of $in_number random elements of $in_tab |
||||
*/ |
||||
function getNElementsFromArray($in_tab, $in_number) { |
||||
$tabres = $in_tab; |
||||
shuffle($tabres); |
||||
if ($in_number < count($tabres)) { |
||||
$tabres = array_slice($tabres, 0, $in_number); |
||||
} |
||||
return $tabres; |
||||
} |
||||
|
||||
/** |
||||
* display the category |
||||
*/ |
||||
function displayCategoryAndTitle($in_questionID) { |
||||
if (Testcategory::getCategoryNameForQuestion($in_questionID) != "") { |
||||
echo "<div id=\"question_title\" class=\"sectiontitle\" style='font-size:110%; margin-top:20px; padding-top:10px'>"; |
||||
echo "<div style='font-size:110%;font-weight:normal; margin-bottom:5px; padding:0px 10px 5px 10px;'>"; |
||||
echo get_lang('Category').": ".Testcategory::getCategoryNameForQuestion($in_questionID); |
||||
echo "</div>"; |
||||
echo "</div>"; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Display signs [+] and/or (>0) after question title if question has options |
||||
* scoreAlwaysPositive and/or uncheckedMayScore |
||||
*/ |
||||
function displayQuestionOption($in_objQuestion) { |
||||
if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) { |
||||
echo "<span style='font-size:75%'> (>0)</span>"; |
||||
} |
||||
if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) { |
||||
echo "<span style='font-size:75%'> [+]</span>"; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* sortTabByBracketLabel ($tabCategoryQuestions) |
||||
* key of $tabCategoryQuestions are the categopy id (0 for not in a category) |
||||
* value is the array of question id of this category |
||||
* Sort question by Category |
||||
*/ |
||||
function sortTabByBracketLabel($in_tab) { |
||||
$tabResult = array(); |
||||
$tabCatName = array(); // tab of category name |
||||
while (list($cat_id, $tabquestion) = each($in_tab)) { |
||||
$catTitle = new Testcategory($cat_id); |
||||
$tabCatName[$cat_id] = $catTitle->name; |
||||
} |
||||
reset($in_tab); |
||||
// sort table by value, keeping keys as they are |
||||
asort($tabCatName); |
||||
// keys of $tabCatName are keys order for $in_tab |
||||
while (list($key, $val) = each($tabCatName)) { |
||||
$tabResult[$key] = $in_tab[$key]; |
||||
} |
||||
return $tabResult; |
||||
} |
||||
|
||||
/** |
||||
* return total score for test exe_id for all question in the category $in_cat_id for user |
||||
* If no question for this category, return "" |
||||
*/ |
||||
public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id) { |
||||
$tbl_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
||||
$tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
||||
$query = "SELECT DISTINCT marks, exe_id, user_id, ta.question_id, category_id FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc WHERE ta.question_id=qrc.question_id AND qrc.category_id=$in_cat_id AND exe_id=$in_exe_id AND user_id=$in_user_id"; |
||||
$res = Database::query($query); |
||||
$totalcatscore = ""; |
||||
while ($data = Database::fetch_array($res)) { |
||||
$totalcatscore += $data['marks']; |
||||
} |
||||
return $totalcatscore; |
||||
} |
||||
} |
||||
endif; |
||||
?> |
@ -0,0 +1,274 @@ |
||||
<?php |
||||
/** |
||||
hubert.borderiou |
||||
Manage tests category page |
||||
*/ |
||||
|
||||
$htmlHeadXtra[] = ' |
||||
<script type="text/javascript"> |
||||
function confirmDelete(in_txt, in_id) { |
||||
var oldbgcolor = document.getElementById(in_id).style.backgroundColor; |
||||
document.getElementById(in_id).style.backgroundColor="#AAFFB0"; |
||||
if (confirm(in_txt)) { |
||||
return true; |
||||
} |
||||
else { |
||||
document.getElementById(in_id).style.backgroundColor = oldbgcolor; |
||||
return false; |
||||
} |
||||
} |
||||
</script> |
||||
'; |
||||
|
||||
// name of the language file that needs to be included |
||||
$language_file='exercice'; |
||||
$nameTools= ""; |
||||
|
||||
include('question.class.php'); |
||||
include('testcategory.class.php'); |
||||
include('../inc/global.inc.php'); |
||||
include('exercise.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); |
||||
|
||||
$this_section=SECTION_COURSES; |
||||
|
||||
if(!api_is_allowed_to_edit()) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
// breadcrumbs |
||||
$interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices')); |
||||
Display::display_header(get_lang('Category')); |
||||
|
||||
// Action handling: add, edit and remove |
||||
if (isset($_GET['action']) && $_GET['action'] == 'addcategory') |
||||
{ |
||||
add_category_form(Security::remove_XSS($_GET['action'])); |
||||
} |
||||
else if (isset($_GET['action']) && $_GET['action'] == 'editcategory') { |
||||
edit_category_form(Security::remove_XSS($_GET['action'])); |
||||
} |
||||
else if (isset($_GET['action']) && $_GET['action'] == 'deletecategory') { |
||||
delete_category_form(Security::remove_XSS($_GET['action'])); |
||||
} |
||||
else { |
||||
display_add_category(); |
||||
display_categories(); |
||||
} |
||||
|
||||
Display::display_footer(); |
||||
|
||||
// ********************************************************************************** |
||||
// ****** FUNCTIONS ******************** |
||||
// ********************************************************************************** |
||||
|
||||
// ------------------------------------------------------------------------ |
||||
// form to edit a category |
||||
// ------------------------------------------------------------------------ |
||||
function edit_category_form($in_action) { |
||||
|
||||
if (isset($_GET['category_id']) && is_numeric($_GET['category_id'])) { |
||||
$category_id = Security::remove_XSS($_GET['category_id']); |
||||
$objcat = new Testcategory($category_id); |
||||
// -------------------- |
||||
// initiate the object |
||||
// -------------------- |
||||
$form = new FormValidator('note','post', api_get_self().'?action='.$in_action.'&category_id='.$category_id); |
||||
// -------------------- |
||||
// settting the form elements |
||||
// -------------------- |
||||
$form->addElement('header', '', get_lang('EditCategory')); |
||||
$form->addElement('hidden', 'category_id'); |
||||
$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('ModifyCategory'), 'class="add"'); |
||||
// -------------------- |
||||
// setting the defaults |
||||
// -------------------- |
||||
$defaults = array(); |
||||
$defaults["category_id"] = $objcat->id; |
||||
$defaults["category_name"] = $objcat->name; |
||||
$defaults["category_description"] = $objcat->description; |
||||
$form->setDefaults($defaults); |
||||
// -------------------- |
||||
// setting the rules |
||||
// -------------------- |
||||
$form->addRule('category_name', '<div class="required">'.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', '<div class="required">'.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 '<div class="actions">'; |
||||
echo '<a href="exercice.php?'.api_get_cidreq().'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'),'',32).'</a>'; |
||||
echo '<a href="'.api_get_self().'?action=addcategory">'.Display::return_icon('question_category.gif').'</a>'; |
||||
echo '</div>'; |
||||
echo "<br/>"; |
||||
} |
||||
|
||||
|
||||
// ------------------------------------------------------------------------ |
||||
// 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 '<div class="sectiontitle" id="id_cat'.$row['id'].'">'; |
||||
echo "<span style='float:right'>".$nb_question.get_lang('NbCategory')."</span>"; |
||||
echo $row['name']; |
||||
echo '</div>'; |
||||
echo '<div class="sectioncomment">'; |
||||
echo $row['description']; |
||||
echo '</div>'; |
||||
echo '<div>'; |
||||
echo '<a href="'.api_get_self().'?action=editcategory&category_id='.$row['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>'; |
||||
if ($nb_question > 0) { |
||||
echo '<a href="javascript:void(0)" onclick="alert(\''.protectJSDialogQuote(get_lang('CannotDeleteCategory')).'\')">'; |
||||
echo Display::return_icon('delete_na.gif', get_lang('CannotDeleteCategory')); |
||||
echo '</a>'; |
||||
} |
||||
else { |
||||
$rowname = protectJSDialogQuote($row['name']); |
||||
echo '<a href="'.api_get_self().'?action=deletecategory&category_id='.$row['id'].'" '; |
||||
echo 'onclick="return confirmDelete(\''.protectJSDialogQuote(get_lang('DeleteCategoryAreYouSure').'['.$rowname).'] ?\', \'id_cat'.$row['id'].'\');">'; |
||||
echo Display::return_icon('delete.gif', get_lang('Delete')).'</a>'; |
||||
} |
||||
echo '</div>'; |
||||
} |
||||
} |
||||
|
||||
|
||||
// ------------------------------------------------------------------------ |
||||
// display goback to category list page link |
||||
// ------------------------------------------------------------------------ |
||||
function display_goback() { |
||||
echo '<div class="actions">'; |
||||
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', '', 32).' '.get_lang('BackToCategoryList').'</a>'; |
||||
echo '</div>'; |
||||
} |
||||
|
||||
// ------------------------------------------------------------------------ |
||||
// 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; |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,10 @@ |
||||
<?php |
||||
$config['ToolbarSets']['Normal'] = array( |
||||
array('Style','FontFormat','FontName','FontSize'), |
||||
'/', |
||||
array('Bold','Italic','Underline'), |
||||
array('SpecialChar', 'mimetex'), |
||||
array('OrderedList','UnorderedList','-','Outdent','Indent','-','TextColor','BGColor'), |
||||
array('JustifyLeft','JustifyCenter','JustifyRight','-','Source') |
||||
); |
||||
?> |
Loading…
Reference in new issue