// 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']);
function add_category_form($in_action, $type = 'simple') { $in_action = Security::remove_XSS($in_action); // Initiate the object $form = new FormValidator('note', 'post', api_get_self() . '?' . api_get_cidreq() . '&action=' . $in_action . "&type=" . $type); // Setting the form elements $form->addElement('header', get_lang('AddACategory')); $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); $form->addElement('select', 'parent_id', get_lang('Parent'), array(), array('id' => 'parent_id')); $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->getSubmitValues(); $parent_id = isset($values['parent_id']) && isset($values['parent_id'][0]) ? $values['parent_id'][0] : null; $objcat = new Testcategory(0, $values['category_name'], $values['category_description'], $parent_id, $type, api_get_course_int_id()); if ($objcat->addCategoryInBDD()) { Display::display_confirmation_message(get_lang('AddCategoryDone')); } else { Display::display_confirmation_message(get_lang('AddCategoryNameAlreadyExists')); } } Security::clear_token(); display_add_category($type); display_categories($type); } else { display_goback($type); $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } }