Esempio n. 1
0
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'));
    }
}
 /**
  * Edit category
  *
  * @param Application $app
  * @param $id
  * @return Response
  */
 public function editCategoryAction(Application $app, $id)
 {
     $extraJS = array();
     //@todo improve this JS includes should be added using twig
     $extraJS[] = '<link href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
     $extraJS[] = '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript"></script>';
     $app['extraJS'] = $extraJS;
     $objcat = new \Testcategory($id);
     if (!empty($objcat->c_id) || empty($objcat->id)) {
         $app->abort(401);
     }
     $url = $app['url_generator']->generate('admin_category_edit', array('id' => $id));
     $form = new \FormValidator('edit', 'post', $url);
     $objcat->getForm($form, 'edit');
     $message = null;
     if ($form->validate()) {
         $values = $form->getSubmitValues();
         $objcat = new \Testcategory($id, $values['category_name'], $values['category_description'], $values['parent_id'], 'global');
         if ($objcat->modifyCategory()) {
             $message = \Display::return_message(get_lang('MofidfyCategoryDone'), 'confirmation');
         } else {
             $message = \Display::return_message(get_lang('ModifyCategoryError'), 'warning');
         }
         $url = $app['url_generator']->generate('admin_questions');
         return $app->redirect($url);
     }
     $app['template']->assign('message', $message);
     $app['template']->assign('form', $form->toHtml());
     $response = $app['template']->render_template('admin/questionmanager/edit_category.tpl');
     return new Response($response, 200, array());
 }
 /**
  * Edit category
  * @Route("/edit_category")
  * @Method({"GET"})
  * @param $id
  * @return Response
  */
 public function editCategoryAction($id)
 {
     $objcat = new \Testcategory($id);
     if (!empty($objcat->c_id) || empty($objcat->id)) {
         $this->abort(401);
     }
     $url = $this->generateUrl('editCategoryAction', array('id' => $id));
     $form = new \FormValidator('edit', 'post', $url);
     $objcat->getForm($form, 'edit');
     $message = null;
     if ($form->validate()) {
         $values = $form->getSubmitValues();
         $objcat = new \Testcategory($id, $values['category_name'], $values['category_description'], $values['parent_id'], 'global');
         if ($objcat->modifyCategory()) {
             $this->addFlash('confirmation', get_lang('MofidfyCategoryDone'));
         } else {
             $this->addFlash('warning', get_lang('ModifyCategoryError'));
         }
         $url = $this->generateUrl('admin_questions');
         return $this->redirect($url);
     }
     $this->getTemplate()->assign('message', $message);
     $this->getTemplate()->assign('form', $form->toHtml());
     $response = $this->renderTemplate('edit_category.tpl');
     return new Response($response, 200, array());
 }
 /**
  * @todo : add session id when used for session
  */
 public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
 {
     $course_id = api_get_course_int_id();
     // Let's restore the categories
     $tab_test_category_id_old_new = array();
     // used to build the quiz_question_rel_category table
     if ($this->course->has_resources(RESOURCE_TEST_CATEGORY)) {
         $resources = $this->course->resources;
         foreach ($resources[RESOURCE_TEST_CATEGORY] as $id => $CourseCopyTestcategory) {
             $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
             // check if this test_category already exist in the destination BDD
             // do not Database::escape_string $title and $description, it will be done later
             $title = $CourseCopyTestcategory->title;
             $description = $CourseCopyTestcategory->description;
             if (Testcategory::category_exists_with_title($title)) {
                 switch ($this->file_option) {
                     case FILE_SKIP:
                         //Do nothing
                         break;
                     case FILE_RENAME:
                         $new_title = $title . "_";
                         while (Testcategory::category_exists_with_title($new_title)) {
                             $new_title .= "_";
                         }
                         $test_category = new Testcategory(0, $new_title, $description);
                         $new_id = $test_category->addCategoryInBDD();
                         $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $new_id;
                         break;
                     case FILE_OVERWRITE:
                         $id = Testcategory::get_category_id_for_title($title);
                         $my_cat = new Testcategory($id);
                         $my_cat->name = $title;
                         $my_cat->modifyCategory();
                         $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
                         break;
                 }
             } else {
                 // create a new test_category
                 $test_category = new Testcategory(0, $title, $description);
                 $new_id = $test_category->addCategoryInBDD();
                 $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $new_id;
             }
             $this->course->resources[RESOURCE_TEST_CATEGORY][$id]->destination_id = $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id];
         }
     }
     // lets check if quizzes-question are restored too, to redo the link between test_category and quizzes question for questions restored
     // we can use the source_id field
     // question source_id => category source_id
     if ($this->course->has_resources(RESOURCE_QUIZQUESTION)) {
         // check the category number of each question restored
         if (!empty($resources[RESOURCE_QUIZQUESTION])) {
             foreach ($resources[RESOURCE_QUIZQUESTION] as $id => $CourseCopyQuestion) {
                 $new_quiz_question_id = $resources[RESOURCE_QUIZQUESTION][$id]->destination_id;
                 $question_category = $CourseCopyQuestion->question_category;
                 if ($question_category > 0) {
                     Testcategory::add_category_for_question_id($tab_test_category_id_old_new[$question_category], $new_quiz_question_id, $course_id);
                 }
             }
         }
     }
 }
Esempio n. 5
0
/**
 * @todo move to testcategory.class.php
 * @param string $in_action
 */
function edit_category_form($in_action)
{
    $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() . '?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->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, 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', 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'));
    }
}