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; } } '; $nameTools = ""; require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; if (!api_is_allowed_to_edit()) { api_not_allowed(true); } $category = new TestCategory(); $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); // breadcrumbs $interbreadcrumb[] = array( "url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises'), ); Display::display_header(get_lang('Category')); // Action handling: add, edit and remove if (isset($_GET['action']) && $_GET['action'] == 'addcategory') { add_category_form($_GET['action']); display_add_category(); } else if (isset($_GET['action']) && $_GET['action'] == 'editcategory') { edit_category_form($_GET['action']); } else if (isset($_GET['action']) && $_GET['action'] == 'deletecategory') { delete_category_form($_GET['action']); display_add_category(); } else { display_add_category(); } echo $category->displayCategories($courseId, $sessionId); Display::display_footer(); /** * Form to edit a category * @todo move to TestCategory.class.php * @param string $action */ function edit_category_form($action) { $action = Security::remove_XSS($action); if (isset($_GET['category_id']) && is_numeric($_GET['category_id'])) { $category_id = Security::remove_XSS($_GET['category_id']); $objcat = new TestCategory($category_id); $form = new FormValidator( 'note', 'post', api_get_self().'?action='.$action.'&category_id='.$category_id ); // Setting 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->addHtmlEditor( 'category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Height' => '200') ); $form->addButtonSave(get_lang('ModifyCategory'), 'SubmitNote'); // 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', 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(); } else { display_goback(); $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } } else { Display::display_error_message(get_lang('CannotEditCategory')); } } // process to delete a category function delete_category_form($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->removeCategory()) { Display::display_confirmation_message(get_lang('DeleteCategoryDone')); } else { Display::display_error_message(get_lang('CannotDeleteCategoryError')); } } else { Display::display_error_message(get_lang('CannotDeleteCategoryError')); } } /** * form to add a category * @todo move to TestCategory.class.php * @param string $action */ function add_category_form($action) { $action = Security::remove_XSS($action); // initiate the object $form = new FormValidator('note', 'post', api_get_self() . '?action=' . $action); // Setting the form elements $form->addElement('header', get_lang('AddACategory')); $form->addElement('text', 'category_name', get_lang('CategoryName'), array('size' => '95')); $form->addHtmlEditor( 'category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Height' => '200') ); $form->addButtonCreate(get_lang('AddTestCategory'), 'SubmitNote'); // 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(); } else { display_goback(); $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } } // Display add category button function display_add_category() { echo '