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; } } function check() { $("#parent_id option:selected").each(function() { var id = $(this).val(); var name = $(this).text(); if (id != "" ) { $.ajax({ async: false, url: "'.$url.'&a=exercise_category_exists", data: "id="+id, success: function(return_value) { if (return_value == 0 ) { alert("'.get_lang('CategoryDoesNotExists').'"); //Deleting select option tag $("#parent_id").find("option").remove(); $(".holder li").each(function () { if ($(this).attr("rel") == id) { $(this).remove(); } }); } } }); } }); } $(function() { $("#parent_id").fcbkcomplete({ json_url: "'.$url.'&a=search_category_parent", maxitems: 1, addontab: false, input_min_size: 1, cache: false, complete_text:"'.get_lang('StartToType').'", firstselected: false, onselect: check, filter_selected: true, newel: true }); }); '; $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; // 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($_GET['action'], $type); } else if (isset($_GET['action']) && $_GET['action'] == 'addcategoryglobal') { add_category_form($_GET['action'], $type); } else if (isset($_GET['action']) && $_GET['action'] == 'editcategory') { edit_category_form($_GET['action'], $type); } else if (isset($_GET['action']) && $_GET['action'] == 'deletecategory') { delete_category_form($_GET['action'], $type); } else { display_add_category($type); display_categories($type); } Display::display_footer(); // FUNCTIONS // form to edit a category function edit_category_form($in_action, $type = 'simple') { $in_action = Security::remove_XSS($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().'?'.api_get_cidreq().'&action='.$in_action.'&category_id='.$category_id."&type=".$type); $objcat->getForm($form, 'edit'); // The validation or display if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->getSubmitValues(); $v_id = $values['category_id']; $v_name = $values['category_name']; $v_description = $values['category_description']; $parent_id = isset($values['parent_id']) ? $values['parent_id'] : null; $visibility = isset($values['visibility']) ? $values['visibility'] : 1; $objcat = new Testcategory($v_id, $v_name, $v_description, $parent_id, $type, null, $visibility); if ($objcat->modifyCategory()) { Display::display_confirmation_message(get_lang('MofidfyCategoryDone')); } else { Display::display_confirmation_message(get_lang('ModifyCategoryError')); } } 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(); display_categories($type); } } else { Display::display_error_message(get_lang('CannotEditCategory')); } } // process to delete a category function delete_category_form($in_action, $type = 'simple') { $in_action = Security::remove_XSS($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($type); display_categories($type); } // Form to add a category 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(); } } // Display add category button function display_add_category($type) { echo '