/**
  * @param FormValidator $form
  *
  * @return array
  */
 public static function setForm(FormValidator &$form, $sessionId = 0)
 {
     $categoriesList = SessionManager::get_all_session_category();
     $userInfo = api_get_user_info();
     $categoriesOptions = array('0' => get_lang('None'));
     if ($categoriesList != false) {
         foreach ($categoriesList as $categoryItem) {
             $categoriesOptions[$categoryItem['id']] = $categoryItem['name'];
         }
     }
     // Database Table Definitions
     $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
     $form->addElement('text', 'name', get_lang('SessionName'), array('maxlength' => 50));
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     $form->addRule('name', get_lang('SessionNameAlreadyExists'), 'callback', 'check_session_name');
     if (!api_is_platform_admin() && api_is_teacher()) {
         $form->addElement('select', 'coach_username', get_lang('CoachName'), [api_get_user_id() => $userInfo['complete_name']], array('id' => 'coach_username', 'class' => 'chzn-select', 'style' => 'width:370px;'));
     } else {
         $sql = "SELECT COUNT(1) FROM {$tbl_user} WHERE status = 1";
         $rs = Database::query($sql);
         $countUsers = Database::result($rs, 0, 0);
         if (intval($countUsers) < 50) {
             $orderClause = "ORDER BY ";
             $orderClause .= api_sort_by_first_name() ? "firstname, lastname, username" : "lastname, firstname, username";
             $sql = "SELECT user_id, lastname, firstname, username\n                        FROM {$tbl_user}\n                        WHERE status = '1' " . $orderClause;
             if (api_is_multiple_url_enabled()) {
                 $userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
                 $accessUrlId = api_get_current_access_url_id();
                 if ($accessUrlId != -1) {
                     $sql = "SELECT user.user_id, username, lastname, firstname\n                        FROM {$tbl_user} user\n                        INNER JOIN {$userRelAccessUrlTable} url_user\n                        ON (url_user.user_id = user.user_id)\n                        WHERE\n                            access_url_id = {$accessUrlId} AND\n                            status = 1 " . $orderClause;
                 }
             }
             $result = Database::query($sql);
             $coachesList = Database::store_result($result);
             $coachesOptions = array();
             foreach ($coachesList as $coachItem) {
                 $coachesOptions[$coachItem['user_id']] = api_get_person_name($coachItem['firstname'], $coachItem['lastname']) . ' (' . $coachItem['username'] . ')';
             }
             $form->addElement('select', 'coach_username', get_lang('CoachName'), $coachesOptions);
         } else {
             $form->addElement('select_ajax', 'coach_username', get_lang('CoachName'), null, ['url' => api_get_path(WEB_AJAX_PATH) . 'session.ajax.php?a=search_general_coach', 'width' => '100%']);
         }
     }
     $form->addRule('coach_username', get_lang('ThisFieldIsRequired'), 'required');
     $form->addHtml('<div id="ajax_list_coachs"></div>');
     $form->addButtonAdvancedSettings('advanced_params');
     $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
     $form->addSelect('session_category', get_lang('SessionCategory'), $categoriesOptions, array('id' => 'session_category', 'class' => 'chzn-select', 'style' => 'width:370px;'));
     $form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Minimal'));
     $form->addElement('checkbox', 'show_description', null, get_lang('ShowDescription'));
     $visibilityGroup = array();
     $visibilityGroup[] = $form->createElement('select', 'session_visibility', null, array(SESSION_VISIBLE_READ_ONLY => get_lang('SessionReadOnly'), SESSION_VISIBLE => get_lang('SessionAccessible'), SESSION_INVISIBLE => api_ucfirst(get_lang('SessionNotAccessible'))));
     $form->addGroup($visibilityGroup, 'visibility_group', get_lang('SessionVisibility'), null, false);
     $options = [0 => get_lang('ByDuration'), 1 => get_lang('ByDates')];
     $form->addSelect('access', get_lang('Access'), $options, array('onchange' => 'accessSwitcher()', 'id' => 'access'));
     $form->addElement('html', '<div id="duration" style="display:none">');
     $form->addElement('number', 'duration', array(get_lang('SessionDurationTitle'), get_lang('SessionDurationDescription')), array('maxlength' => 50));
     $form->addElement('html', '</div>');
     $form->addElement('html', '<div id="date_fields" style="display:none">');
     // Dates
     $form->addDateTimePicker('access_start_date', array(get_lang('SessionStartDate'), get_lang('SessionStartDateComment')), array('id' => 'access_start_date'));
     $form->addDateTimePicker('access_end_date', array(get_lang('SessionEndDate'), get_lang('SessionEndDateComment')), array('id' => 'access_end_date'));
     $form->addRule(array('access_start_date', 'access_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '< allow_empty');
     $form->addDateTimePicker('display_start_date', array(get_lang('SessionDisplayStartDate'), get_lang('SessionDisplayStartDateComment')), array('id' => 'display_start_date'));
     $form->addDateTimePicker('display_end_date', array(get_lang('SessionDisplayEndDate'), get_lang('SessionDisplayEndDateComment')), array('id' => 'display_end_date'));
     $form->addRule(array('display_start_date', 'display_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '< allow_empty');
     $form->addDateTimePicker('coach_access_start_date', array(get_lang('SessionCoachStartDate'), get_lang('SessionCoachStartDateComment')), array('id' => 'coach_access_start_date'));
     $form->addDateTimePicker('coach_access_end_date', array(get_lang('SessionCoachEndDate'), get_lang('SessionCoachEndDateComment')), array('id' => 'coach_access_end_date'));
     $form->addRule(array('coach_access_start_date', 'coach_access_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '< allow_empty');
     $form->addElement('html', '</div>');
     $form->addCheckBox('send_subscription_notification', [get_lang('SendSubscriptionNotification'), get_lang('SendAnEmailWhenAUserBeingSubscribed')]);
     // Extra fields
     $extra_field = new ExtraField('session');
     $extra = $extra_field->addElements($form, $sessionId);
     $form->addElement('html', '</div>');
     $js = $extra['jquery_ready_content'];
     return ['js' => $js];
 }
Example #2
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
  */
 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();
             }
         }
         if (true) {
             $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'));
             $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'), '');
         } else {
             // 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->addCheckBox('save_correct_answers', null, get_lang('Save the correct answers for the next attempt'));
         $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>');
         //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['save_correct_answers'] = $this->selectSaveCorrectAnswers();
             $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['question_selection_type'] = $this->getQuestionSelectionType();
             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'] = '';
             $defaults['end_button'] = $this->selectEndButton();
             $defaults['question_selection_type'] = 1;
             $defaults['hide_question_title'] = 0;
             $defaults['on_success_message'] = null;
             $defaults['on_failed_message'] = null;
         }
     } 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 #4
0
}
$form->addHtmlEditor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
$defaults['title'] = $work_item['title'];
$defaults["description"] = $work_item['description'];
$defaults['qualification'] = $work_item['qualification'];
if ($is_allowed_to_edit && !empty($item_id)) {
    // Get qualification from parent_id that will allow the validation qualification over
    $sql = "SELECT qualification FROM {$work_table}\n            WHERE c_id = {$course_id} AND id ='{$work_id}' ";
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    $qualification_over = $row['qualification'];
    if (!empty($qualification_over) && intval($qualification_over) > 0) {
        $form->addText('qualification', array(get_lang('Qualification'), " / " . $qualification_over), false, 'size="10"');
        $form->addElement('hidden', 'qualification_over', $qualification_over);
    }
    $form->addCheckBox('send_email', null, get_lang('SendMailToStudent'));
    // Check if user to qualify has some DRHs
    $drhList = UserManager::getDrhListFromUser($work_item['user_id']);
    if (!empty($drhList)) {
        $form->addCheckBox('send_to_drh_users', null, get_lang('SendMailToHR'));
    }
}
$form->addElement('hidden', 'active', 1);
$form->addElement('hidden', 'accepted', 1);
$form->addElement('hidden', 'item_to_edit', $item_id);
$form->addElement('hidden', 'sec_token', $token);
$text = get_lang('UpdateWork');
$class = 'save';
// fix the Ok button when we see the tool in the learn path
$form->addButtonUpdate($text);
$form->setDefaults($defaults);
Example #5
0
 $form->addHeader(get_lang('EditIcon'));
 $form->addHtml('<div class="col-md-7">');
 $form->addText('name', get_lang('Name'));
 $form->addText('link', get_lang('Links'));
 $allowed_picture_types = array('jpg', 'jpeg', 'png');
 $form->addFile('icon', get_lang('CustomIcon'));
 $form->addRule('icon', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
 $form->addSelect('target', get_lang('LinkTarget'), ['_self' => get_lang('LinkOpenSelf'), '_blank' => get_lang('LinkOpenBlank')]);
 $form->addSelect('visibility', get_lang('Visibility'), array(1 => get_lang('Visible'), 0 => get_lang('Invisible')));
 $form->addTextarea('description', get_lang('Description'), array('rows' => '3', 'cols' => '40'));
 $form->addButtonUpdate(get_lang('Update'));
 $form->addHtml('</div>');
 $form->addHtml('<div class="col-md-5">');
 if (isset($tool['custom_icon']) && !empty($tool['custom_icon'])) {
     $form->addLabel(get_lang('CurrentIcon'), Display::img(CourseHome::getCustomWebIconPath() . $tool['custom_icon']));
     $form->addCheckBox('delete_icon', null, get_lang('DeletePicture'));
 }
 $form->addHtml('</div>');
 $form->setDefaults($tool);
 $content = $form->returnForm();
 if ($form->validate()) {
     $data = $form->getSubmitValues();
     CourseHome::updateTool($id, $data);
     Display::addFlash(Display::return_message(get_lang('Updated')));
     if (isset($data['delete_icon'])) {
         CourseHome::deleteIcon($id);
     }
     $currentUrlReturn = api_get_self() . '?' . api_get_cidreq();
     header('Location: ' . $currentUrlReturn);
     exit;
 }
Example #6
0
        $currencySelect->setSelected($currencyValue);
    }
}
$currencyForm->addButtonSave(get_lang('Save'));
$paypalForm = new FormValidator('paypal');
if ($paypalForm->validate()) {
    $paypalFormValues = $paypalForm->getSubmitValues();
    $plugin->savePaypalParams($paypalFormValues);
    Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
    header('Location:' . api_get_self());
    exit;
}
$paypalForm->addText('username', $plugin->get_lang('ApiUsername'), false, ['cols-size' => [3, 8, 1]]);
$paypalForm->addText('password', $plugin->get_lang('ApiPassword'), false, ['cols-size' => [3, 8, 1]]);
$paypalForm->addText('signature', $plugin->get_lang('ApiSignature'), false, ['cols-size' => [3, 8, 1]]);
$paypalForm->addCheckBox('sandbox', null, $plugin->get_lang('Sandbox'));
$paypalForm->addButtonSave(get_lang('Save'));
$paypalForm->setDefaults($plugin->getPaypalParams());
// Platform Commissions
$commissionForm = new FormValidator('commissions');
if ($commissionForm->validate()) {
    $commissionFormValues = $commissionForm->getSubmitValues();
    $plugin->updateCommission($commissionFormValues);
    Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
    header('Location:' . api_get_self());
    exit;
}
$commissionForm->addElement('number', 'commission', [$plugin->get_lang('Commission'), null, '%'], ['step' => 1, 'cols-size' => [3, 7, 1], 'min' => 0, 'max' => 100]);
$commissionForm->addButtonSave(get_lang('Save'));
$commissionForm->setDefaults($plugin->getPlatformCommission());
$transferForm = new FormValidator('transfer_account');
            $defaultBeneficiaries[] = $courseCoach->getId();
        }
    }
    $currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']);
    if (!empty($currentBeneficiaries)) {
        $defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
    }
    $currencyIso = $sessionItem['currency'];
    $formDefaults = ['product_type' => get_lang('Session'), 'i' => $session->getId(), 't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION, 'name' => $sessionItem['session_name'], 'visible' => $sessionItem['visible'], 'price' => $sessionItem['price'], 'beneficiaries' => $defaultBeneficiaries];
} else {
    api_not_allowed(true);
}
$form = new FormValidator('beneficiaries');
$form->addText('product_type', $plugin->get_lang('ProductType'), false);
$form->addText('name', get_lang('Name'), false);
$visibleCheckbox = $form->addCheckBox('visible', $plugin->get_lang('VisibleInCatalog'), $plugin->get_lang('ShowOnCourseCatalog'));
$form->addElement('number', 'price', [$plugin->get_lang('Price'), null, $currencyIso], ['step' => 0.01]);
$beneficiariesSelect = $form->addSelect('beneficiaries', $plugin->get_lang('Beneficiaries'), null, ['multiple' => 'multiple']);
if ($editingCourse) {
    $beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers'));
} elseif ($editingSession) {
    $beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach'));
    $beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach'));
}
$form->addHidden('t', null);
$form->addHidden('i', null);
$form->addButtonSave(get_lang('Save'));
$form->freeze(['product_type', 'name']);
if ($form->validate()) {
    $formValues = $form->exportValues();
    $productItem = $plugin->getItemByProduct($formValues['i'], $formValues['t']);