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(); } }
/** * 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(); } }
/** * 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 = intval($_GET['category_id']); $objcat = new TestCategory($category_id); $form = new FormValidator('note', 'post', api_get_self() . '?action=' . $action . '&category_id=' . $category_id . '&' . api_get_cidreq()); // 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' => 'TestQuestionDescription', '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::addFlash(Display::return_message(get_lang('MofidfyCategoryDone'))); } else { Display::addFlash(Display::return_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)); return $form->returnForm(); } } else { Display::addFlash(Display::return_message(get_lang('CannotEditCategory'), 'error')); } }