Example #1
0
$form->add_progress_bar();
if (strlen($_SESSION['oLP']->get_preview_image()) > 0) {
    $show_preview_image = '<img src=' . api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/learning_path/images/' . $_SESSION['oLP']->get_preview_image() . '>';
    $form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
    $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}
$label = $_SESSION['oLP']->get_preview_image() != '' ? get_lang('UpdateImage') : get_lang('AddImage');
$form->addElement('file', 'lp_preview_image', array($label, get_lang('ImageWillResizeMsg')));
$form->addRule('lp_preview_image', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
// Search terms (only if search is activated).
if (api_get_setting('search_enabled') === 'true') {
    $specific_fields = get_specific_field_list();
    foreach ($specific_fields as $specific_field) {
        $form->addElement('text', $specific_field['code'], $specific_field['name']);
        $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $_SESSION['oLP']->lp_id, 'tool_id' => '\'' . TOOL_LEARNPATH . '\'');
        $values = get_specific_field_values_list($filter, array('value'));
        if (!empty($values)) {
            $arr_str_values = array();
            foreach ($values as $value) {
                $arr_str_values[] = $value['value'];
            }
            $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
        }
    }
}
$defaults['lp_encoding'] = Security::remove_XSS($_SESSION['oLP']->encoding);
$defaults['lp_name'] = Security::remove_XSS($_SESSION['oLP']->get_name());
$defaults['lp_author'] = Security::remove_XSS($_SESSION['oLP']->get_author());
$defaults['hide_toc_frame'] = Security::remove_XSS($_SESSION['oLP']->get_hide_toc_frame());
$defaults['category_id'] = intval($_SESSION['oLP']->get_category_id());
$expired_on = $_SESSION['oLP']->expired_on;
 /**
  * Creates the form to create / edit an exercise
  * @param FormValidator $form
  */
 public function createForm($form, $type = 'full')
 {
     if (empty($type)) {
         $type = 'full';
     }
     // form title
     if (!empty($_GET['exerciseId'])) {
         $form_title = get_lang('ModifyExercise');
     } else {
         $form_title = get_lang('NewEx');
     }
     $form->addElement('header', $form_title);
     // Title.
     $form->addElement('text', 'exerciseTitle', get_lang('ExerciseName'), array('id' => 'exercise_title'));
     $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
     $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
     $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150');
     if (is_array($type)) {
         $editor_config = array_merge($editor_config, $type);
     }
     $form->addHtmlEditor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config);
     if ($type == 'full') {
         //Can't modify a DirectFeedback question
         if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) {
             // feedback type
             $radios_feedback = array();
             $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()'));
             if (api_get_setting('exercise.enable_quiz_scenario') == 'true') {
                 //Can't convert a question from one feedback to another if there is more than 1 question already added
                 if ($this->selectNbrQuestions() == 0) {
                     $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()'));
                 }
             }
             $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2'));
             $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions')), '');
             // Type of results display on the final page
             $radios_results_disabled = array();
             $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
             $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
             $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2'));
             //$radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ExamModeWithFinalScoreShowOnlyFinalScoreWithCategoriesIfAvailable'),  '3', array('id'=>'result_disabled_3','onclick' => 'check_results_disabled()'));
             $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
             // Type of questions disposition on page
             $radios = array();
             $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all'));
             $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one'));
             $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
         } else {
             // if is Directfeedback but has not questions we can allow to modify the question type
             if ($this->selectNbrQuestions() == 0) {
                 // feedback type
                 $radios_feedback = array();
                 $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()'));
                 if (api_get_setting('exercise.enable_quiz_scenario') == 'true') {
                     $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()'));
                 }
                 $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2'));
                 $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions')));
                 //$form->addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"');
                 $radios_results_disabled = array();
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                 $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
                 // Type of questions disposition on page
                 $radios = array();
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1');
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2');
                 $form->addGroup($radios, null, get_lang('ExerciseType'));
             } else {
                 //Show options freeze
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                 $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
                 $result_disable_group->freeze();
                 //we force the options to the DirectFeedback exercisetype
                 $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT);
                 $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE);
                 // Type of questions disposition on page
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all'));
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one'));
                 $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
                 $type_group->freeze();
             }
         }
         // number of random question
         $max = $this->id > 0 ? $this->selectNbrQuestions() : 10;
         $option = range(0, $max);
         $option[0] = get_lang('No');
         $option[-1] = get_lang('AllQuestionsShort');
         $form->addElement('select', 'randomQuestions', array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id' => 'randomQuestions'));
         // Random answers
         $radios_random_answers = array();
         $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1');
         $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0');
         $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), '');
         // Random by category
         $form->addElement('html', '<div class="clear">&nbsp;</div>');
         $radiocat = array();
         $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesShuffled'), '1');
         $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesSorted'), '2');
         $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('No'), '0');
         $radioCatGroup = $form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'), '');
         $form->addElement('html', '<div class="clear">&nbsp;</div>');
         // add the radio display the category name for student
         $radio_display_cat_name = array();
         $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1');
         $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0');
         $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');
         // Attempts
         $attempt_option = range(0, 10);
         $attempt_option[0] = get_lang('Infinite');
         $form->addElement('select', 'exerciseAttempts', get_lang('ExerciseAttempts'), $attempt_option, ['id' => 'exerciseAttempts']);
         // Exercise time limit
         $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
         $var = Exercise::selectTimeLimit();
         if ($this->start_time != '0000-00-00 00:00:00') {
             $form->addElement('html', '<div id="start_date_div" style="display:block;">');
         } else {
             $form->addElement('html', '<div id="start_date_div" style="display:none;">');
         }
         $form->addElement('date_time_picker', 'start_time');
         $form->addElement('html', '</div>');
         $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
         if ($this->end_time != '0000-00-00 00:00:00') {
             $form->addElement('html', '<div id="end_date_div" style="display:block;">');
         } else {
             $form->addElement('html', '<div id="end_date_div" style="display:none;">');
         }
         $form->addElement('date_time_picker', 'end_time');
         $form->addElement('html', '</div>');
         //$check_option=$this->selectType();
         $diplay = 'block';
         $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults'));
         $form->addElement('html', '<div class="clear">&nbsp;</div>');
         $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers'));
         $form->addElement('html', '<div id="divtimecontrol"  style="display:' . $diplay . ';">');
         //Timer control
         //$time_hours_option = range(0,12);
         //$time_minutes_option = range(0,59);
         $form->addElement('checkbox', 'enabletimercontrol', null, get_lang('EnableTimerControl'), array('onclick' => 'option_time_expired()', 'id' => 'enabletimercontrol', 'onload' => 'check_load_time()'));
         $expired_date = (int) $this->selectExpiredTime();
         if ($expired_date != '0') {
             $form->addElement('html', '<div id="timercontrol" style="display:block;">');
         } else {
             $form->addElement('html', '<div id="timercontrol" style="display:none;">');
         }
         $form->addText('enabletimercontroltotalminutes', get_lang('ExerciseTotalDurationInMinutes'), false, ['id' => 'enabletimercontroltotalminutes', 'cols-size' => [2, 2, 8]]);
         $form->addElement('html', '</div>');
         $form->addElement('text', 'pass_percentage', array(get_lang('PassPercentage'), null, '%'), array('id' => 'pass_percentage'));
         $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric');
         // add the text_when_finished textbox
         $form->addHtmlEditor('text_when_finished', get_lang('TextWhenFinished'), false, false, $editor_config);
         $defaults = array();
         if (api_get_setting('search.search_enabled') === 'true') {
             require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
             $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument'));
             $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage'));
             $specific_fields = get_specific_field_list();
             foreach ($specific_fields as $specific_field) {
                 $form->addElement('text', $specific_field['code'], $specific_field['name']);
                 $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\'' . TOOL_QUIZ . '\'');
                 $values = get_specific_field_values_list($filter, array('value'));
                 if (!empty($values)) {
                     $arr_str_values = array();
                     foreach ($values as $value) {
                         $arr_str_values[] = $value['value'];
                     }
                     $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
                 }
             }
             //$form->addElement ('html','</div>');
         }
         $form->addElement('html', '</div>');
         //End advanced setting
         $form->addElement('html', '</div>');
     }
     // submit
     if (isset($_GET['exerciseId'])) {
         $form->addButtonSave(get_lang('ModifyExercise'), 'submitExercise');
     } else {
         $form->addButtonUpdate(get_lang('ProcedToQuestions'), 'submitExercise');
     }
     $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required');
     if ($type == 'full') {
         // rules
         $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric');
         $form->addRule('start_time', get_lang('InvalidDate'), 'datetime');
         $form->addRule('end_time', get_lang('InvalidDate'), 'datetime');
     }
     // defaults
     if ($type == 'full') {
         if ($this->id > 0) {
             if ($this->random > $this->selectNbrQuestions()) {
                 $defaults['randomQuestions'] = $this->selectNbrQuestions();
             } else {
                 $defaults['randomQuestions'] = $this->random;
             }
             $defaults['randomAnswers'] = $this->selectRandomAnswers();
             $defaults['exerciseType'] = $this->selectType();
             $defaults['exerciseTitle'] = $this->get_formated_title();
             $defaults['exerciseDescription'] = $this->selectDescription();
             $defaults['exerciseAttempts'] = $this->selectAttempts();
             $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
             $defaults['results_disabled'] = $this->selectResultsDisabled();
             $defaults['propagate_neg'] = $this->selectPropagateNeg();
             $defaults['review_answers'] = $this->review_answers;
             $defaults['randomByCat'] = $this->selectRandomByCat();
             $defaults['text_when_finished'] = $this->selectTextWhenFinished();
             $defaults['display_category_name'] = $this->selectDisplayCategoryName();
             $defaults['pass_percentage'] = $this->selectPassPercentage();
             if ($this->start_time != '0000-00-00 00:00:00') {
                 $defaults['activate_start_date_check'] = 1;
             }
             if ($this->end_time != '0000-00-00 00:00:00') {
                 $defaults['activate_end_date_check'] = 1;
             }
             $defaults['start_time'] = $this->start_time != '0000-00-00 00:00:00' ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00');
             $defaults['end_time'] = $this->end_time != '0000-00-00 00:00:00' ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time() + 84600);
             // Get expired time
             if ($this->expired_time != '0') {
                 $defaults['enabletimercontrol'] = 1;
                 $defaults['enabletimercontroltotalminutes'] = $this->expired_time;
             } else {
                 $defaults['enabletimercontroltotalminutes'] = 0;
             }
         } else {
             $defaults['exerciseType'] = 2;
             $defaults['exerciseAttempts'] = 0;
             $defaults['randomQuestions'] = 0;
             $defaults['randomAnswers'] = 0;
             $defaults['exerciseDescription'] = '';
             $defaults['exerciseFeedbackType'] = 0;
             $defaults['results_disabled'] = 0;
             $defaults['randomByCat'] = 0;
             $defaults['text_when_finished'] = "";
             $defaults['start_time'] = date('Y-m-d 12:00:00');
             $defaults['display_category_name'] = 1;
             $defaults['end_time'] = date('Y-m-d 12:00:00', time() + 84600);
             $defaults['pass_percentage'] = '';
         }
     } else {
         $defaults['exerciseTitle'] = $this->selectTitle();
         $defaults['exerciseDescription'] = $this->selectDescription();
     }
     if (api_get_setting('search.search_enabled') === 'true') {
         $defaults['index_document'] = 'checked="checked"';
     }
     $form->setDefaults($defaults);
     // Freeze some elements.
     if ($this->id != 0 && $this->edit_exercise_in_lp == false) {
         $elementsToFreeze = array('randomQuestions', 'exerciseAttempts', 'propagate_neg', 'enabletimercontrol', 'review_answers');
         foreach ($elementsToFreeze as $elementName) {
             /** @var HTML_QuickForm_element $element */
             $element = $form->getElement($elementName);
             $element->freeze();
         }
         $radioCatGroup->freeze();
     }
 }
Example #3
0
 /**
  * @param int $linkId
  * @param $action
  * @param null $urlview
  * @param null $token
  * @return FormValidator
  */
 public static function getLinkForm($linkId, $action, $token = null)
 {
     $course_id = api_get_course_int_id();
     $session_id = api_get_session_id();
     $linkInfo = Link::get_link_info($linkId);
     $categoryId = isset($linkInfo['category_id']) ? $linkInfo['category_id'] : '';
     $lpId = isset($_GET['lp_id']) ? Security::remove_XSS($_GET['lp_id']) : null;
     $category = 0;
     $form = new FormValidator('link', 'post', api_get_self() . '?action=' . $action . '&category_id=' . $categoryId . '&' . api_get_cidreq() . '&id=' . $linkId . '&sec_token=' . $token);
     if ($action == 'addlink') {
         $form->addHeader(get_lang('LinkAdd'));
     } else {
         $form->addHeader(get_lang('LinkMod'));
     }
     $target_link = "_blank";
     $title = '';
     $category = '';
     $onhomepage = '';
     $description = '';
     if (!empty($linkInfo)) {
         $urllink = $linkInfo['url'];
         $title = $linkInfo['title'];
         $description = $linkInfo['description'];
         $category = $linkInfo['category_id'];
         if ($linkInfo['on_homepage'] != 0) {
             $onhomepage = 1;
         }
         $target_link = $linkInfo['target'];
     }
     $form->addHidden('id', $linkId);
     $form->addText('url', 'URL');
     $form->addRule('url', get_lang('GiveURL'), 'url');
     $form->addText('title', get_lang('LinkName'));
     $form->addTextarea('description', get_lang('Description'));
     $resultcategories = Link::getLinkCategories($course_id, $session_id);
     $options = ['0' => '--'];
     if (!empty($resultcategories)) {
         foreach ($resultcategories as $myrow) {
             $options[$myrow['id']] = $myrow['category_title'];
         }
     }
     $form->addSelect('category_id', get_lang('Category'), $options);
     $form->addCheckBox('on_homepage', null, get_lang('OnHomepage'));
     $targets = array('_self' => get_lang('LinkOpenSelf'), '_blank' => get_lang('LinkOpenBlank'), '_parent' => get_lang('LinkOpenParent'), '_top' => get_lang('LinkOpenTop'));
     $form->addSelect('target', array(get_lang('LinkTarget'), get_lang('AddTargetOfLinkOnHomepage')), $targets);
     $defaults = array('url' => empty($urllink) ? 'http://' : Security::remove_XSS($urllink), 'title' => Security::remove_XSS($title), 'category_id' => $category, 'on_homepage' => $onhomepage, 'description' => $description, 'target' => $target_link);
     if (api_get_setting('search_enabled') == 'true') {
         require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
         $specific_fields = get_specific_field_list();
         $form->addCheckBox('index_document', get_lang('SearchFeatureDoIndexLink'), get_lang('Yes'));
         foreach ($specific_fields as $specific_field) {
             $default_values = '';
             if ($action == 'editlink') {
                 $filter = array('field_id' => $specific_field['id'], 'ref_id' => intval($_GET['id']), 'tool_id' => '\'' . TOOL_LINK . '\'');
                 $values = get_specific_field_values_list($filter, array('value'));
                 if (!empty($values)) {
                     $arr_str_values = array();
                     foreach ($values as $value) {
                         $arr_str_values[] = $value['value'];
                     }
                     $default_values = implode(', ', $arr_str_values);
                 }
             }
             $form->addText($specific_field['name'], $specific_field['code']);
             $defaults[$specific_field['name']] = $default_values;
         }
     }
     $form->addHidden('lp_id', $lpId);
     $form->addButtonSave(get_lang('SaveLink'), 'submitLink');
     $form->setDefaults($defaults);
     return $form;
 }
    /**
     * Creates the form to create / edit an exercise
     * @param FormValidator $form the formvalidator instance (by reference)
     * @param string
     */
    public function createForm($form, $type = 'full')
    {
        if (empty($type)) {
            $type = 'full';
        }
        // form title
        if (!empty($_GET['exerciseId'])) {
            $form_title = get_lang('ModifyExercise');
        } else {
            $form_title = get_lang('NewEx');
        }
        $form->addElement('header', $form_title);
        // title
        $form->addElement('text', 'exerciseTitle', get_lang('ExerciseName'), array('class' => 'span6', 'id' => 'exercise_title'));
        $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150');
        if (is_array($type)) {
            $editor_config = array_merge($editor_config, $type);
        }
        $form->add_html_editor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config);
        $form->addElement('advanced_settings', '<a href="javascript://" onclick=" return advanced_parameters()">
                <span id="img_plus_and_minus">
                <div style="vertical-align:top;" >
                    ' . Display::return_icon('div_show.gif') . ' ' . addslashes(get_lang('AdvancedParameters')) . '</div>
                </span>
            </a>');
        $form->addElement('html', '<div id="options" style="">');
        // Model type
        $radio = array($form->createElement('radio', 'model_type', null, get_lang('Normal'), EXERCISE_MODEL_TYPE_NORMAL), $form->createElement('radio', 'model_type', null, get_lang('Committee'), EXERCISE_MODEL_TYPE_COMMITTEE));
        $form->addGroup($radio, null, get_lang('ModelType'), '');
        $modelType = $this->getModelType();
        $scoreTypeDisplay = 'display:none';
        if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) {
            $scoreTypeDisplay = null;
        }
        $form->addElement('html', '<div id="score_type" style="' . $scoreTypeDisplay . '">');
        // QuestionScoreType
        global $app;
        $em = $app['orm.em'];
        $types = $em->getRepository('Entity\\QuestionScore')->findAll();
        $options = array('0' => get_lang('SelectAnOption'));
        foreach ($types as $questionType) {
            $options[$questionType->getId()] = $questionType->getName();
        }
        $form->addElement('select', 'score_type_model', array(get_lang('QuestionScoreType')), $options, array('id' => 'score_type_model'));
        $form->addElement('html', '</div>');
        if ($type == 'full') {
            //Can't modify a DirectFeedback question
            if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) {
                // feedback type
                $radios_feedback = array();
                $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()'));
                if (api_get_setting('enable_quiz_scenario') == 'true') {
                    /* Can't convert a question from one feedback to another if there
                       is more than 1 question already added */
                    if ($this->selectNbrQuestions() == 0) {
                        $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()'));
                    }
                }
                $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2'));
                $form->addGroup($radios_feedback, null, get_lang('FeedbackType'), '');
                // question
                $radios = array($form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), ALL_ON_ONE_PAGE, array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all')), $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), ONE_PER_PAGE, array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one')));
                $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
                $radios_results_disabled = array();
                $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
            } else {
                // if is Directfeedback but has not questions we can allow to modify the question type
                if ($this->selectNbrQuestions() == 0) {
                    // feedback type
                    $radios_feedback = array();
                    $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()'));
                    if (api_get_setting('enable_quiz_scenario') == 'true') {
                        $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()'));
                    }
                    $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2'));
                    $form->addGroup($radios_feedback, null, get_lang('FeedbackType'));
                    // Exercise type
                    $radios = array($form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1'), $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2'), $form->createElement('radio', 'exerciseType', null, get_lang('Committee'), '3'));
                    $form->addGroup($radios, null, get_lang('ExerciseType'));
                    $radios_results_disabled = array();
                    $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                    $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                    $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                    $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
                } else {
                    //Show options freeze
                    $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                    $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                    $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                    $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
                    $result_disable_group->freeze();
                    $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all'));
                    $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one'));
                    $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
                    $type_group->freeze();
                    //we force the options to the DirectFeedback exercisetype
                    $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT);
                    $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE);
                }
            }
            $option = array(EX_Q_SELECTION_ORDERED => get_lang('OrderedByUser'), EX_Q_SELECTION_RANDOM => get_lang('Random'), 'per_categories' => '--------' . get_lang('UsingCategories') . '----------', EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED => get_lang('OrderedCategoriesAlphabeticallyWithQuestionsOrdered'), EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED => get_lang('RandomCategoriesWithQuestionsOrdered'), EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_RANDOM => get_lang('OrderedCategoriesAlphabeticallyWithRandomQuestions'), EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM => get_lang('RandomCategoriesWithRandomQuestions'), EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED => get_lang('OrderedCategoriesByParentWithQuestionsOrdered'), EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM => get_lang('OrderedCategoriesByParentWithQuestionsRandom'));
            $form->addElement('select', 'question_selection_type', array(get_lang('QuestionSelection')), $option, array('id' => 'questionSelection', 'onclick' => 'checkQuestionSelection()'));
            $displayMatrix = 'none';
            $displayRandom = 'none';
            $selectionType = $this->getQuestionSelectionType();
            switch ($selectionType) {
                case EX_Q_SELECTION_RANDOM:
                    $displayRandom = 'block';
                    break;
                case $selectionType >= EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED:
                    $displayMatrix = 'block';
                    break;
            }
            $form->addElement('html', '<div id="hidden_random" style="display:' . $displayRandom . '">');
            // Number of random question.
            $max = $this->id > 0 ? $this->selectNbrQuestions() : 10;
            $option = range(0, $max);
            $option[0] = get_lang('No');
            $option[-1] = get_lang('AllQuestionsShort');
            $form->addElement('select', 'randomQuestions', array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id' => 'randomQuestions'));
            $form->addElement('html', '</div>');
            $form->addElement('html', '<div id="hidden_matrix" style="display:' . $displayMatrix . '">');
            // Category selection.
            $cat = new Testcategory();
            $cat_form = $cat->returnCategoryForm($this);
            $form->addElement('label', null, $cat_form);
            $form->addElement('html', '</div>');
            // Category name.
            $radio_display_cat_name = array($form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'), $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0'));
            $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');
            // Random answers.
            $radios_random_answers = array($form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'), $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0'));
            $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), '');
            // Hide question title.
            $group = array($form->createElement('radio', 'hide_question_title', null, get_lang('Yes'), '1'), $form->createElement('radio', 'hide_question_title', null, get_lang('No'), '0'));
            $form->addGroup($group, null, get_lang('HideQuestionTitle'), '');
            // Attempts.
            $attempt_option = range(0, 10);
            $attempt_option[0] = get_lang('Infinite');
            $form->addElement('select', 'exerciseAttempts', get_lang('ExerciseAttempts'), $attempt_option, array('id' => 'exerciseAttempts'));
            // Exercise time limit.
            $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
            // Start time.
            if ($this->start_time != '0000-00-00 00:00:00') {
                $form->addElement('html', '<div id="start_date_div" style="display:block;">');
            } else {
                $form->addElement('html', '<div id="start_date_div" style="display:none;">');
            }
            $form->addElement('datepicker', 'start_time', '', array('form_name' => 'exercise_admin'), 5);
            $form->addElement('html', '</div>');
            // End time.
            $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
            if ($this->end_time != '0000-00-00 00:00:00') {
                $form->addElement('html', '<div id="end_date_div" style="display:block;">');
            } else {
                $form->addElement('html', '<div id="end_date_div" style="display:none;">');
            }
            $form->addElement('datepicker', 'end_time', '', array('form_name' => 'exercise_admin'), 5);
            $form->addElement('html', '</div>');
            // Propagate negative values.
            $display = 'block';
            $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults'));
            $form->addElement('html', '<div class="clear">&nbsp;</div>');
            $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers'));
            $form->addElement('html', '<div id="divtimecontrol"  style="display:' . $display . ';">');
            // Exercise timer.
            $form->addElement('checkbox', 'enabletimercontrol', null, get_lang('EnableTimerControl'), array('onclick' => 'option_time_expired()', 'id' => 'enabletimercontrol', 'onload' => 'check_load_time()'));
            $expired_date = (int) $this->selectExpiredTime();
            if ($expired_date != '0') {
                $form->addElement('html', '<div id="timercontrol" style="display:block;">');
            } else {
                $form->addElement('html', '<div id="timercontrol" style="display:none;">');
            }
            $form->addElement('text', 'enabletimercontroltotalminutes', get_lang('ExerciseTotalDurationInMinutes'), array('style' => 'width : 35px', 'id' => 'enabletimercontroltotalminutes'));
            $form->addElement('html', '</div>');
            // Pass percentage.
            $form->addElement('text', 'pass_percentage', array(get_lang('PassPercentage'), null, '%'), array('id' => 'pass_percentage'));
            $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric');
            $url = api_get_path(WEB_AJAX_PATH) . 'exercise.ajax.php?1=1';
            $js = '<script>

            function check() {
                var counter = 0;
                $("#global_category_id option:selected").each(function() {
                    var id = $(this).val();
                    var name = $(this).text();
                    if (id != "" ) {

                        $.ajax({
                            async: false,
                            url: "' . $url . '&a=exercise_category_exists&type=global",
                            data: "id="+id,
                            success: function(return_value) {
                                if (return_value == 0 ) {
                                    alert("' . addslashes(get_lang('CategoryDoesNotExists')) . '");
                                    // Deleting select option tag
                                    $("#global_category_id").find("option").remove();

                                    $(".holder li").each(function () {
                                        if ($(this).attr("rel") == id) {
                                            $(this).remove();
                                        }
                                    });
                                }
                            },
                        });
                    }
                    counter++;
                });
            }

            $(function() {
                $("#global_category_id").fcbkcomplete({
                    json_url: "' . $url . '&a=search_category_parent&type=global&",
                    maxitems: 1 ,
                    addontab: false,
                    input_min_size: 1,
                    cache: false,
                    complete_text:"' . get_lang('StartToType') . '",
                    firstselected: false,
                    onselect: check,
                    filter_selected: true,
                    newel: true
                });
            });

            </script>';
            $form->addElement('html', $js);
            $categoryJS = null;
            $globalCategoryId = $this->getGlobalCategoryId();
            if (!empty($globalCategoryId)) {
                $cat = new Testcategory($globalCategoryId);
                $trigger = '$("#global_category_id").trigger("addItem",[{ "title": "' . $cat->title . '", "value": "' . $globalCategoryId . '"}]);';
                $categoryJS .= '<script>$(function() { ' . $trigger . ' });</script>';
            }
            $form->addElement('html', $categoryJS);
            // Global category id.
            $form->addElement('select', 'global_category_id', array(get_lang('GlobalCategory')), array(), array('id' => 'global_category_id'));
            // Text when ending an exam
            $form->add_html_editor('text_when_finished', get_lang('TextWhenFinished'), false, false, $editor_config);
            // Exam end button.
            $group = array($form->createElement('radio', 'end_button', null, get_lang('ExerciseEndButtonCourseHome'), '0'), $form->createElement('radio', 'end_button', null, get_lang('ExerciseEndButtonExerciseHome'), '1'), $form->createElement('radio', 'end_button', null, get_lang('ExerciseEndButtonDisconnect'), '2'));
            $form->addGroup($group, null, get_lang('ExerciseEndButton'));
            $form->addElement('html', '<div class="clear">&nbsp;</div>');
            $defaults = array();
            if (api_get_setting('search_enabled') === 'true') {
                require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
                $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument'));
                $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage'));
                $specific_fields = get_specific_field_list();
                foreach ($specific_fields as $specific_field) {
                    $form->addElement('text', $specific_field['code'], $specific_field['name']);
                    $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\'' . TOOL_QUIZ . '\'');
                    $values = get_specific_field_values_list($filter, array('value'));
                    if (!empty($values)) {
                        $arr_str_values = array();
                        foreach ($values as $value) {
                            $arr_str_values[] = $value['value'];
                        }
                        $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
                    }
                }
            }
            if ($this->emailAlert) {
                // Text when ending an exam
                $form->add_html_editor('email_notification_template', array(get_lang('EmailNotificationTemplate'), get_lang('EmailNotificationTemplateDescription')), null, false, $editor_config);
            }
            // End advanced setting.
            $form->addElement('html', '</div>');
            $form->addElement('html', '</div>');
        }
        // Category selection.
        $cat = new Testcategory();
        $cat_form = $cat->returnCategoryForm($this);
        $form->addElement('html', $cat_form);
        // submit
        $text = isset($_GET['exerciseId']) ? get_lang('ModifyExercise') : get_lang('ProcedToQuestions');
        $form->addElement('style_submit_button', 'submitExercise', $text, 'class="save"');
        $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required');
        if ($type == 'full') {
            // rules
            $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric');
            $form->addRule('start_time', get_lang('InvalidDate'), 'date');
            $form->addRule('end_time', get_lang('InvalidDate'), 'date');
        }
        // defaults
        if ($type == 'full') {
            if ($this->id > 0) {
                if ($this->random > $this->selectNbrQuestions()) {
                    $defaults['randomQuestions'] = $this->selectNbrQuestions();
                } else {
                    $defaults['randomQuestions'] = $this->random;
                }
                $defaults['randomAnswers'] = $this->selectRandomAnswers();
                $defaults['exerciseType'] = $this->selectType();
                $defaults['exerciseTitle'] = $this->selectTitle();
                $defaults['exerciseDescription'] = $this->selectDescription();
                $defaults['exerciseAttempts'] = $this->selectAttempts();
                $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
                $defaults['results_disabled'] = $this->selectResultsDisabled();
                $defaults['propagate_neg'] = $this->selectPropagateNeg();
                $defaults['review_answers'] = $this->review_answers;
                $defaults['randomByCat'] = $this->selectRandomByCat();
                $defaults['text_when_finished'] = $this->selectTextWhenFinished();
                $defaults['display_category_name'] = $this->selectDisplayCategoryName();
                $defaults['pass_percentage'] = $this->selectPassPercentage();
                $defaults['end_button'] = $this->selectEndButton();
                $defaults['email_notification_template'] = $this->selectEmailNotificationTemplate();
                $defaults['model_type'] = $this->getModelType();
                $defaults['question_selection_type'] = $this->getQuestionSelectionType();
                $defaults['score_type_model'] = $this->getScoreTypeModel();
                //$defaults['global_category_id'] = $this->getScoreTypeModel();
                $defaults['hide_question_title'] = $this->getHideQuestionTitle();
                if ($this->start_time != '0000-00-00 00:00:00') {
                    $defaults['activate_start_date_check'] = 1;
                }
                if ($this->end_time != '0000-00-00 00:00:00') {
                    $defaults['activate_end_date_check'] = 1;
                }
                $defaults['start_time'] = $this->start_time != '0000-00-00 00:00:00' ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00');
                $defaults['end_time'] = $this->end_time != '0000-00-00 00:00:00' ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time() + 84600);
                //Get expired time
                if ($this->expired_time != '0') {
                    $defaults['enabletimercontrol'] = 1;
                    $defaults['enabletimercontroltotalminutes'] = $this->expired_time;
                } else {
                    $defaults['enabletimercontroltotalminutes'] = 0;
                }
            } else {
                $defaults['model_type'] = 1;
                $defaults['exerciseType'] = 2;
                $defaults['exerciseAttempts'] = 0;
                $defaults['randomQuestions'] = 0;
                $defaults['randomAnswers'] = 0;
                $defaults['exerciseDescription'] = '';
                $defaults['exerciseFeedbackType'] = 0;
                $defaults['results_disabled'] = 0;
                $defaults['randomByCat'] = 0;
                //
                $defaults['text_when_finished'] = "";
                //
                $defaults['start_time'] = date('Y-m-d 12:00:00');
                $defaults['display_category_name'] = 1;
                //
                $defaults['end_time'] = date('Y-m-d 12:00:00', time() + 84600);
                $defaults['pass_percentage'] = '';
                $defaults['end_button'] = $this->selectEndButton();
                $defaults['question_selection_type'] = 1;
                $defaults['hide_question_title'] = 0;
            }
        } else {
            $defaults['exerciseTitle'] = $this->selectTitle();
            $defaults['exerciseDescription'] = $this->selectDescription();
        }
        if (api_get_setting('search_enabled') === 'true') {
            $defaults['index_document'] = 'checked="checked"';
        }
        $form->setDefaults($defaults);
    }