$form->freeze('openid'); } $form->applyFilter('openid', 'trim'); }*/ // PHONE $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20)); if (api_get_setting('profile', 'phone') !== 'true') { $form->freeze('phone'); } $form->applyFilter('phone', 'stripslashes'); $form->applyFilter('phone', 'trim'); $form->applyFilter('phone', 'html_filter'); // PICTURE if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') { $form->addElement('file', 'picture', $user_data['picture_uri'] != '' ? get_lang('UpdateImage') : get_lang('AddImage'), array('id' => 'picture_form', 'class' => 'picture-form')); $form->addHtml('' . '<div class="form-group">' . '<label for="cropImage" id="labelCropImage" class="col-sm-2 control-label"></label>' . '<div class="col-sm-8">' . '<div id="cropImage" class="cropCanvas">' . '<img id="previewImage" >' . '</div>' . '<div>' . '<button class="btn btn-primary hidden" name="cropButton" id="cropButton"><em class="fa fa-crop"></em> ' . get_lang('CropYourPicture') . '</button>' . '</div>' . '</div>' . '</div>' . ''); $form->addHidden('cropResult', ''); $form->add_progress_bar(); if (!empty($user_data['picture_uri'])) { $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage')); } $allowed_picture_types = api_get_supported_image_extensions(); $form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(', ', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types); } // LANGUAGE $form->addElement('select_language', 'language', get_lang('Language')); if (api_get_setting('profile', 'language') !== 'true') { $form->freeze('language'); } //THEME if (is_profile_editable() && api_get_setting('profile.user_selected_theme') == 'true') {
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ function createAnswersForm($form) { $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2; $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); $obj_ex = Session::read('objExercise'); $html = '<table class="table table-striped table-hover">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th width="10">' . get_lang('Number') . '</th>'; $html .= '<th width="10">' . get_lang('True') . '</th>'; $html .= '<th width="50%">' . get_lang('Comment') . '</th>'; $html .= '<th width="50%">' . get_lang('Answer') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; $answer = false; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $form->addElement('hidden', 'nb_answers'); $boxes_names = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_answers; ++$i) { $form->addHtml('<tr>'); if (is_object($answer)) { $defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1); $defaults['correct[' . $i . ']'] = $answer->correct[$i]; } else { $defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2'); $defaults['comment[1]'] = get_lang('DefaultMultipleComment2'); $defaults['correct[1]'] = true; $defaults['weighting[1]'] = 10; $defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1'); $defaults['comment[2]'] = get_lang('DefaultMultipleComment1'); $defaults['correct[2]'] = false; } $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox" style="margin-left: 0em;"'); $boxes_names[] = 'correct[' . $i . ']'; $form->addElement('html_editor', 'answer[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addHtml('</tr>'); } $form->addElement('html', '</tbody></table>'); $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required'); //only 1 answer the all deal ... $form->addText('weighting[1]', get_lang('Score'), false, ['value' => 10]); global $text; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { // setting the save button here and not in the question class.php $buttonGroup = [$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true), $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true), $form->addButtonSave($text, 'submitQuestion', true)]; $form->addGroup($buttonGroup); } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(array('nb_answers' => $nb_answers)); }
/** * @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]; }
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { // Getting the exercise list $obj_ex = Session::read('objExercise'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); //this line defines how many questions by default appear when creating a choice question // The previous default value was 2. See task #1759. $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4; $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); /* Types of Feedback $feedback_option[0]=get_lang('Feedback'); $feedback_option[1]=get_lang('DirectFeedback'); $feedback_option[2]=get_lang('NoFeedback'); */ $feedback_title = ''; if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { //Scenario $comment_title = '<th width="20%">' . get_lang('Comment') . '</th>'; $feedback_title = '<th width="20%">' . get_lang('Scenario') . '</th>'; } else { $comment_title = '<th width="40%">' . get_lang('Comment') . '</th>'; } $html = '<table class="table table-striped table-hover"> <thead> <tr style="text-align: center;"> <th width="5%">' . get_lang('Number') . '</th> <th width="5%"> ' . get_lang('True') . '</th> <th width="40%">' . get_lang('Answer') . '</th> ' . $comment_title . ' ' . $feedback_title . ' <th width="10%">' . get_lang('Weighting') . '</th> </tr> </thead> <tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $form->addElement('hidden', 'nb_answers'); //Feedback SELECT $question_list = $obj_ex->selectQuestionList(); $select_question = array(); $select_question[0] = get_lang('SelectTargetQuestion'); if (is_array($question_list)) { foreach ($question_list as $key => $questionid) { //To avoid warning messages if (!is_numeric($questionid)) { continue; } $question = Question::read($questionid); $select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20); } } $select_question[-1] = get_lang('ExitTest'); $list = new LearnpathList(api_get_user_id()); $flat_list = $list->get_flat_list(); $select_lp_id = array(); $select_lp_id[0] = get_lang('SelectTargetLP'); foreach ($flat_list as $id => $details) { $select_lp_id[$id] = cut($details['lp_name'], 20); } $temp_scenario = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_answers; ++$i) { $form->addHtml('<tr>'); if (isset($answer) && is_object($answer)) { if ($answer->correct[$i]) { $correct = $i; } $defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1); $item_list = explode('@@', $answer->destination[$i]); $try = isset($item_list[0]) ? $item_list[0] : ''; $lp = isset($item_list[1]) ? $item_list[1] : ''; $list_dest = isset($item_list[2]) ? $item_list[2] : ''; $url = isset($item_list[3]) ? $item_list[3] : ''; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } else { $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1'); $defaults['weighting[1]'] = 10; $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2'); $defaults['weighting[2]'] = 0; $temp_scenario['destination' . $i] = array('0'); $temp_scenario['lp' . $i] = array('0'); } $defaults['scenario'] = $temp_scenario; $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, ' value = "' . $i . '"'); $answer_number->freeze(); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox"'); $form->addHtmlEditor('answer[' . $i . ']', null, null, true, $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config); // Direct feedback //Adding extra feedback fields $group = array(); $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain')); $group['lp' . $i] = $form->createElement('select', 'lp' . $i, get_lang('SeeTheory') . ': ', $select_lp_id); $group['destination' . $i] = $form->createElement('select', 'destination' . $i, get_lang('GoToQuestion') . ': ', $select_question); $group['url' . $i] = $form->createElement('text', 'url' . $i, get_lang('Other') . ': ', array('class' => 'col-md-2', 'placeholder' => get_lang('Other'))); $form->addGroup($group, 'scenario'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario'); } else { $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config); } $form->addText('weighting[' . $i . ']', null, null, array('value' => '0')); $form->addHtml('</tr>'); } $form->addHtml('</tbody>'); $form->addHtml('</table>'); global $text; $buttonGroup = []; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($buttonGroup); } // We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { // Default sample content. $form->setDefaults($defaults); } else { $form->setDefaults(array('correct' => 1)); } } $form->setConstants(array('nb_answers' => $nb_answers)); }
$result = Database::query($sql); $numberofpages = Database::num_rows($result) + 1; // Displaying the form with the questions if (isset($_GET['show'])) { $show = (int) $_GET['show'] + 1; } else { $show = 0; } $url = api_get_self() . '?survey_id=' . Security::remove_XSS($survey_id) . '&show=' . $show; $form = new FormValidator('question', 'post', $url); if (is_array($questions) && count($questions) > 0) { foreach ($questions as $key => &$question) { $ch_type = 'ch_' . $question['type']; /** @var survey_question $display */ $display = new $ch_type(); $form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">'); $form->addHtml($question['survey_question']); $display->render($form, $question); $form->addHtml('</div></div>'); } } if ($show < $numberofpages || !$_GET['show'] && count($questions) > 0) { if ($show == 0) { $form->addButton('next_survey_page', get_lang('StartSurvey'), 'arrow-right', 'success', 'large'); } else { $form->addButton('next_survey_page', get_lang('NextQuestion'), 'arrow-right'); } } if ($show >= $numberofpages && $_GET['show'] || isset($_GET['show']) && count($questions) == 0) { if ($questions_exists == false) { echo '<p>' . get_lang('ThereAreNotQuestionsForthisSurvey') . '</p>';
/** * @return string */ public function displayLoginForm() { $form = new FormValidator('formLogin', 'POST', null, null, null, FormValidator::LAYOUT_BOX_NO_LABEL); $form->addText('login', get_lang('UserName'), true, array('id' => 'login', 'autofocus' => 'autofocus', 'icon' => 'user fa-fw', 'placeholder' => get_lang('UserName'))); $form->addElement('password', 'password', get_lang('Pass'), array('id' => 'password', 'icon' => 'lock fa-fw', 'placeholder' => get_lang('Pass'))); // Captcha $captcha = api_get_setting('allow_captcha'); $allowCaptcha = $captcha == 'true'; if ($allowCaptcha) { $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null; if ($useCaptcha) { $ajax = api_get_path(WEB_AJAX_PATH) . 'form.ajax.php?a=get_captcha'; $options = array('width' => 250, 'height' => 90, 'callback' => $ajax . '&var=' . basename(__FILE__, '.php'), 'sessionVar' => basename(__FILE__, '.php'), 'imageOptions' => array('font_size' => 20, 'font_path' => api_get_path(SYS_FONTS_PATH) . 'opensans/', 'font_file' => 'OpenSans-Regular.ttf')); // Minimum options using all defaults (including defaults for Image_Text): //$options = array('callback' => 'qfcaptcha_image.php'); $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options); $form->addHtml(get_lang('ClickOnTheImageForANewOne')); $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee')); $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client'); $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question); } } $form->addButton('submitAuth', get_lang('LoginEnter'), null, 'primary', null, 'btn-block'); $html = $form->returnForm(); if (api_get_setting('openid_authentication') == 'true') { include_once 'main/auth/openid/login.php'; $html .= '<div>' . openid_form() . '</div>'; } return $html; }
/** * @return string */ public static function getWallForm() { $form = new FormValidator('social_wall_main', 'post', api_get_path(WEB_CODE_PATH) . 'social/profile.php', null, array('enctype' => 'multipart/form-data')); $form->addTextarea('social_wall_new_msg_main', null, ['placeholder' => get_lang('SocialWallWhatAreYouThinkingAbout'), 'style' => 'width : 100%']); $form->addHtml('<div class="form-group "><div class="url_preview col-md-9 panel-body"></div></div>'); $form->addButtonSend(get_lang('Post')); $form->addHidden('url_content', ''); $html = Display::panel($form->returnForm(), get_lang('SocialWall')); return $html; }
$includeSessions = $plugin->get('include_sessions') === 'true'; $nameFilter = null; $minFilter = 0; $maxFilter = 0; $form = new FormValidator('search_filter_form', 'get', null, null, [], FormValidator::LAYOUT_INLINE); if ($form->validate()) { $formValues = $form->getSubmitValues(); $nameFilter = isset($formValues['name']) ? $formValues['name'] : null; $minFilter = isset($formValues['min']) ? $formValues['min'] : 0; $maxFilter = isset($formValues['max']) ? $formValues['max'] : 0; } $form->addHeader($plugin->get_lang('SearchFilter')); $form->addText('name', get_lang('SessionName'), false); $form->addElement('number', 'min', $plugin->get_lang('MinimumPrice'), ['step' => '0.01', 'min' => '0']); $form->addElement('number', 'max', $plugin->get_lang('MaximumPrice'), ['step' => '0.01', 'min' => '0']); $form->addHtml('<hr>'); $form->addButtonFilter(get_lang('Search')); $courseList = $plugin->getCatalogCourseList($nameFilter, $minFilter, $maxFilter); //View if (api_is_platform_admin()) { $interbreadcrumb[] = ['url' => 'configuration.php', 'name' => $plugin->get_lang('AvailableCoursesConfiguration')]; $interbreadcrumb[] = ['url' => 'paymentsetup.php', 'name' => $plugin->get_lang('PaymentsConfiguration')]; } else { $interbreadcrumb[] = ['url' => 'course_panel.php', 'name' => get_lang('TabsDashboard')]; } $templateName = $plugin->get_lang('CourseListOnSale'); $tpl = new Template($templateName); $tpl->assign('search_filter_form', $form->returnForm()); $tpl->assign('showing_courses', true); $tpl->assign('courses', $courseList); $tpl->assign('sessions_are_included', $includeSessions);
Export::arrayToCsv($listToExport, $archiveFile); case 'xls': Export::arrayToXls($listToExport, $archiveFile); break; } } else { Display::addFlash(Display::return_message(get_lang('ThereAreNotSelectedCoursesOrCoursesListIsEmpty'))); } } Display::display_header($tool_name); $form = new FormValidator('export', 'post', api_get_self()); $form->addHeader($tool_name); $form->addHidden('formSent', 1); $form->addElement('radio', 'select_type', get_lang('Option'), get_lang('ExportAllCoursesList'), '1', ['onclick' => "javascript: if(this.checked){document.getElementById('div-course-list').style.display='none';}"]); $form->addElement('radio', 'select_type', '', get_lang('ExportSelectedCoursesFromCoursesList'), '2', ['onclick' => "javascript: if(this.checked){document.getElementById('div-course-list').style.display='block';}"]); if (!empty($course_list)) { $form->addHtml('<div id="div-course-list" style="display:none">'); $coursesInList = []; foreach ($course_list as $course) { $coursesInList[$course['code']] = $course['title'] . ' (' . $course['code'] . ')'; } $form->addSelect('course_code', get_lang('WhichCoursesToExport'), $coursesInList, ['multiple' => 'multiple']); $form->addHtml('</div>'); } $form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV', 'csv', null); $form->addElement('radio', 'file_type', '', 'XLS', 'xls', null); $form->addElement('radio', 'file_type', null, 'XML', 'xml', null, array('id' => 'file_type_xml')); $form->setDefaults(['select_type' => '1', 'file_type' => 'csv']); $form->addButtonExport(get_lang('ExportCourses')); $form->display(); Display::display_footer();
/** * Function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { $defaults = array(); $nb_matches = $nb_options = 2; $matches = array(); $answer = null; if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); $nb_options = $form->getSubmitValue('nb_options'); if (isset($_POST['lessMatches'])) { $nb_matches--; } if (isset($_POST['moreMatches'])) { $nb_matches++; } if (isset($_POST['lessOptions'])) { $nb_options--; } if (isset($_POST['moreOptions'])) { $nb_options++; } } else { if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0) { $nb_matches = $nb_options = 0; for ($i = 1; $i <= $answer->nbrAnswers; $i++) { if ($answer->isCorrect($i)) { $nb_matches++; $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i); $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1); $answerInfo = $answer->getAnswerByAutoId($answer->correct[$i]); $defaults['matches[' . $nb_matches . ']'] = isset($answerInfo['answer']) ? $answerInfo['answer'] : ''; } else { $nb_options++; $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i); } } } } else { $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2'); $defaults['matches[2]'] = '2'; $defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } } for ($i = 1; $i <= $nb_matches; ++$i) { $matches[$i] = $i; } $form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES $html = '<table class="table table-striped table-hover"> <thead> <tr> <th width="85%">' . get_lang('Answer') . '</th> <th width="15%">' . get_lang('MatchesTo') . '</th> <th width="10">' . get_lang('Weighting') . '</th> </tr> </thead> <tbody>'; $form->addHeader(get_lang('MakeCorrespond')); $form->addHtml($html); if ($nb_matches < 1) { $nb_matches = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_matches; ++$i) { $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]"); $form->addHtml('<tr>'); $form->addText("answer[{$i}]", null); $form->addSelect("matches[{$i}]", null, $matches); $form->addText("weighting[{$i}]", null, true, ['value' => 10, 'style' => 'width: 60px;']); $form->addHtml('</tr>'); } $form->addHtml('</tbody></table>'); $renderer->setElementTemplate('<div class="form-group"><div class="col-sm-offset-2">{element}', 'lessMatches'); $renderer->setElementTemplate('{element}</div></div>', 'moreMatches'); global $text; $group = [$form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true), $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true), $form->addButtonSave($text, 'submitQuestion', true)]; $form->addGroup($group); if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(['nb_matches' => $nb_matches, 'nb_options' => $nb_options]); }
$selectedSale = isset($_GET['sale']) ? intval($_GET['sale']) : 0; $searchTerm = ''; $form = new FormValidator('search', 'get'); if ($form->validate()) { $selectedFilterType = $form->getSubmitValue('filter_type'); $selectedStatus = $form->getSubmitValue('status'); $searchTerm = $form->getSubmitValue('user'); if ($selectedStatus === false) { $selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING; } if ($selectedFilterType === false) { $selectedFilterType = '0'; } } $form->addRadio('filter_type', get_lang('Filter'), [$plugin->get_lang('ByStatus'), $plugin->get_lang('ByUser')]); $form->addHtml('<div id="report-by-status" ' . ($selectedFilterType !== '0' ? 'style="display:none"' : '') . '>'); $form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses); $form->addHtml('</div>'); $form->addHtml('<div id="report-by-user" ' . ($selectedFilterType !== '1' ? 'style="display:none"' : '') . '>'); $form->addText('user', get_lang('UserName'), false); $form->addHtml('</div>'); $form->addButtonFilter(get_lang('Search')); $form->setDefaults(['filter_type' => $selectedFilterType, 'status' => $selectedStatus]); switch ($selectedFilterType) { case '0': $sales = $plugin->getSaleListByStatus($selectedStatus); break; case '1': $sales = $plugin->getSaleListByUser($searchTerm); break; }
Display::addFlash(Display::return_message(get_lang('Updated'))); CourseHome::deleteIcon($id); header('Location: ' . $currentUrl); exit; break; case 'edit_icon': $tool = CourseHome::getTool($id); if (empty($tool)) { api_not_allowed(true); } $interbreadcrumb[] = array('url' => api_get_self() . '?' . api_get_cidreq(), 'name' => get_lang('CustomizeIcons')); $toolName = $tool['name']; $currentUrl = api_get_self() . '?action=edit_icon&id=' . $id . '&' . api_get_cidreq(); $form = new FormValidator('icon_edit', 'post', $currentUrl); $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')); }
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759. $nb_answers += isset($_POST['lessAnswers']) ? -1 : isset($_POST['moreAnswers']) ? 1 : 0; $course_id = api_get_course_int_id(); $obj_ex = $_SESSION['objExercise']; $renderer =& $form->defaultRenderer(); $defaults = array(); $html = '<table class="table table-striped table-hover">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th>' . get_lang('Number') . '</th>'; $html .= '<th>' . get_lang('True') . '</th>'; $html .= '<th>' . get_lang('False') . '</th>'; $html .= '<th>' . get_lang('Answer') . '</th>'; // show column comment when feedback is enable if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) { $html .= '<th>' . get_lang('Comment') . '</th>'; } $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $correct = 0; $answer = null; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $form->addElement('hidden', 'nb_answers'); $boxes_names = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } // Can be more options $option_data = Question::readQuestionOption($this->id, $course_id); for ($i = 1; $i <= $nb_answers; ++$i) { $form->addHtml('<tr>'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); if (is_object($answer)) { $defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $correct = $answer->correct[$i]; $defaults['correct[' . $i . ']'] = $correct; $j = 1; if (!empty($option_data)) { foreach ($option_data as $id => $data) { $form->addElement('radio', 'correct[' . $i . ']', null, null, $id); $j++; if ($j == 3) { break; } } } } else { $form->addElement('radio', 'correct[' . $i . ']', null, null, 1); $form->addElement('radio', 'correct[' . $i . ']', null, null, 2); $defaults['answer[' . $i . ']'] = ''; $defaults['comment[' . $i . ']'] = ''; $defaults['correct[' . $i . ']'] = ''; } $boxes_names[] = 'correct[' . $i . ']'; $form->addHtmlEditor("answer[{$i}]", get_lang('ThisFieldIsRequired'), true, true, ['ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100']); // show comment when feedback is enable if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) { $form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); } $form->addHtml('</tr>'); } $form->addHtml('</tbody></table>'); $correctInputTemplate = '<div class="form-group">'; $correctInputTemplate .= '<label class="col-sm-2 control-label">'; $correctInputTemplate .= '<span class="form_required">*</span>' . get_lang('Score'); $correctInputTemplate .= '</label>'; $correctInputTemplate .= '<div class="col-sm-8">'; $correctInputTemplate .= '<table>'; $correctInputTemplate .= '<tr>'; $correctInputTemplate .= '<td>'; $correctInputTemplate .= get_lang('Correct') . '{element}'; $correctInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->'; $correctInputTemplate .= '</td>'; $wrongInputTemplate = '<td>'; $wrongInputTemplate .= get_lang('Wrong') . '{element}'; $wrongInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->'; $wrongInputTemplate .= '</td>'; $doubtScoreInputTemplate = '<td>' . get_lang('DoubtScore') . '<br>{element}'; $doubtScoreInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->'; $doubtScoreInputTemplate .= '</td>'; $doubtScoreInputTemplate .= '</tr>'; $doubtScoreInputTemplate .= '</table>'; $doubtScoreInputTemplate .= '</div>'; $doubtScoreInputTemplate .= '</div>'; $renderer->setElementTemplate($correctInputTemplate, 'option[1]'); $renderer->setElementTemplate($wrongInputTemplate, 'option[2]'); $renderer->setElementTemplate($doubtScoreInputTemplate, 'option[3]'); // 3 scores $form->addElement('text', 'option[1]', get_lang('Correct'), array('class' => 'span1', 'value' => '1')); $form->addElement('text', 'option[2]', get_lang('Wrong'), array('class' => 'span1', 'value' => '-0.5')); $form->addElement('text', 'option[3]', get_lang('DoubtScore'), array('class' => 'span1', 'value' => '0')); $form->addRule('option[1]', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('option[2]', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('option[3]', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('hidden', 'options_count', 3); // Extra values True, false, Dont known if (!empty($this->extra)) { $scores = explode(':', $this->extra); if (!empty($scores)) { for ($i = 1; $i <= 3; $i++) { $defaults['option[' . $i . ']'] = $scores[$i - 1]; } } } global $text; if ($obj_ex->edit_exercise_in_lp == true) { // setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($buttonGroup); } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { //if ($this -> isContent == 1) { $form->setDefaults($defaults); //} } $form->setConstants(array('nb_answers' => $nb_answers)); }
/** * this function displays the form to upload a new item to the dropbox. * * @author Patrick Cool <*****@*****.**>, Ghent University * @version march 2006 */ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategory, $view) { $course_info = api_get_course_info(); $_user = api_get_user_info(); $is_courseAdmin = api_is_course_admin(); $is_courseTutor = api_is_course_tutor(); $origin = isset($_GET['origin']) ? $_GET['origin'] : null; $token = Security::get_token(); $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); $form = new FormValidator('sent_form', 'post', api_get_self() . '?view_received_category=' . $viewReceivedCategory . '&view_sent_category=' . $viewSentCategory . '&view=' . $view . '&' . api_get_cidreq(), null, array('enctype' => 'multipart/form-data', 'onsubmit' => 'javascript: return checkForm(this);')); $form->addElement('header', get_lang('UploadNewFile')); $form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize')); $form->addElement('hidden', 'dropbox_unid', $dropbox_unid); $form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'origin', $origin); $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);')); if (dropbox_cnf('allowOverwrite')) { $form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite')); } // List of all users in this course and all virtual courses combined with it if (api_get_session_id()) { $complete_user_list_for_dropbox = array(); if (api_get_setting('dropbox.dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) { $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id(), null, null, 0); } $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id()); $generalCoachList = array(); $courseCoachList = array(); foreach ($complete_user_list2 as $coach) { if ($coach['type'] == 'general_coach') { $generalCoachList[] = $coach; } else { $courseCoachList[] = $coach; } } $hideCourseCoach = api_get_setting('dropbox_hide_course_coach'); if ($hideCourseCoach == 'false') { $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $courseCoachList); } $hideGeneralCoach = api_get_setting('dropbox_hide_general_coach'); if ($hideGeneralCoach == 'false') { $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $generalCoachList); } } else { if (api_get_setting('dropbox.dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) { $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id()); } else { $complete_user_list_for_dropbox = CourseManager::getTeacherListFromCourse($course_info['real_id'], false); } } if (!empty($complete_user_list_for_dropbox)) { foreach ($complete_user_list_for_dropbox as $k => $e) { $complete_user_list_for_dropbox[$k] = $e + array('lastcommafirst' => api_get_person_name($e['firstname'], $e['lastname'])); } $complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst'); } /* Create the options inside the select box: List all selected users their user id as value and a name string as display */ $current_user_id = ''; $options = array(); $userGroup = new UserGroup(); foreach ($complete_user_list_for_dropbox as $current_user) { if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin || dropbox_cnf('allowStudentToStudent') || $current_user['status'] != 5 || $current_user['is_tutor'] == 1) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself. if ($current_user['user_id'] == $current_user_id) { continue; } $userId = $current_user['user_id']; $userInfo = api_get_user_info($userId); if ($userInfo['status'] != INVITEE) { $groupNameListToString = ''; if (!empty($groups)) { $groupNameList = array_column($groups, 'name'); $groupNameListToString = ' - [' . implode(', ', $groupNameList) . ']'; } $groups = $userGroup->getUserGroupListByUser($userId); $full_name = $userInfo['complete_name'] . $groupNameListToString; $current_user_id = $current_user['user_id']; $options['user_' . $current_user_id] = $full_name; } } } /* * Show groups */ if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin) && dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')) { $complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId')); if (count($complete_group_list_for_dropbox) > 0) { foreach ($complete_group_list_for_dropbox as $current_group) { if ($current_group['number_of_members'] > 0) { $options['group_' . $current_group['id']] = 'G: ' . $current_group['name'] . ' - ' . $current_group['number_of_members'] . ' ' . get_lang('Users'); } } } } if (dropbox_cnf('allowJustUpload')) { $options['user_' . $_user['user_id']] = get_lang('JustUploadInSelect'); } $form->addSelect('recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10')); $form->addButtonUpload(get_lang('Upload'), 'submitWork'); $headers = array(get_lang('Upload'), get_lang('Upload') . ' (' . get_lang('Simple') . ')'); $multipleForm = new FormValidator('sent_multiple', 'post', '#', null, array('enctype' => 'multipart/form-data', 'id' => 'fileupload')); $multipleForm->addSelect('recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10', 'id' => 'recipient_form')); $url = api_get_path(WEB_AJAX_PATH) . 'dropbox.ajax.php?' . api_get_cidreq() . '&a=upload_file&id='; $multipleForm->addHtml('<div id="multiple_form" style="display:none">'); $multipleForm->addMultipleUpload($url); $multipleForm->addHtml('</div>'); echo Display::tabs($headers, array($multipleForm->returnForm(), $form->returnForm()), 'tabs'); }
if ($formSequence->validate()) { $values = $formSequence->exportValues(); $sequence = new Sequence(); $sequence->setName($values['name']); $em->persist($sequence); $em->flush(); header('Location: ' . api_get_self()); exit; } $selectSequence = new FormValidator(''); $selectSequence->addHidden('sequence_type', 'session'); $em = Database::getManager(); $sequenceList = $em->getRepository('ChamiloCoreBundle:Sequence')->findAll(); $selectSequence->addSelect('sequence', get_lang('Sequence'), $sequenceList, ['id' => 'sequence_id', 'cols-size' => [3, 7, 2]]); $form = new FormValidator(''); $form->addHtml("<div class='col-md-6'>"); $form->addHidden('sequence_type', 'session'); $form->addSelect('sessions', get_lang('Sessions'), $sessionList, ['id' => 'item', 'cols-size' => [4, 7, 1]]); $form->addButtonNext(get_lang('UseAsReference'), 'use_as_reference', ['cols-size' => [4, 7, 1]]); $form->addHtml("</div>"); $form->addHtml("<div class='col-md-6'>"); $form->addSelect('requirements', get_lang('Requirements'), $sessionList, ['id' => 'requirements', 'cols-size' => [3, 7, 2]]); $form->addButtonCreate(get_lang('SetAsRequirement'), 'set_requirement', false, ['cols-size' => [3, 7, 2]]); $form->addHtml("</div>"); $formSave = new FormValidator(''); $formSave->addHidden('sequence_type', 'session'); $formSave->addButton('save_resource', get_lang('SaveSettings'), 'floppy-o', 'success', null, null, ['cols-size' => [1, 10, 1]]); $tpl->assign('create_sequence', $formSequence->returnForm()); $tpl->assign('select_sequence', $selectSequence->returnForm()); $tpl->assign('configure_sequence', $form->returnForm()); $tpl->assign('save_sequence', $formSave->returnForm());
function generate_settings_form($settings, $settings_by_access_list) { global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list; $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $form = new FormValidator('settings', 'post', 'settings.php?category=' . Security::remove_XSS($_GET['category'])); $form->addElement('hidden', 'search_field', !empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null); $url_id = api_get_current_access_url_id(); if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) { $group = array(); $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll')); $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll')); $form->addGroup($group, 'buttons_in_action_right'); } $default_values = array(); $url_info = api_get_access_url($url_id); $i = 0; foreach ($settings as $row) { if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; } if (!empty($_configuration['multiple_access_urls'])) { if (api_is_global_platform_admin()) { if ($row['access_url_locked'] == 0) { if ($url_id == 1) { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "0" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</a></div>'); } else { $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "1" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</a></div>'); } } else { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</div>'); } else { $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</div>'); } } } } } $hideme = array(); $hide_element = false; if ($_configuration['access_url'] != 1) { if ($row['access_url_changeable'] == 0) { // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element. $hide_element = true; $hideme = array('disabled'); } elseif ($url_info['active'] == 1) { // We show the elements. if (empty($row['variable'])) { $row['variable'] = 0; } if (empty($row['subkey'])) { $row['subkey'] = 0; } if (empty($row['category'])) { $row['category'] = 0; } if (is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])) { // We are sure that the other site have a selected value. if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') { $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value']; } } // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site. } } switch ($row['type']) { case 'textfield': if (in_array($row['variable'], $convert_byte_to_mega_list)) { $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('maxlength' => '8')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1); } elseif ($row['variable'] == 'account_valid_duration') { $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; // For platform character set selection: Conversion of the textfield to a select box with valid values. } elseif ($row['variable'] == 'platform_charset') { continue; } else { $hideme['class'] = 'col-md-4'; $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; } break; case 'textarea': if ($row['variable'] == 'header_extra_content') { $file = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt'; $value = ''; if (file_exists($file)) { $value = file_get_contents($file); } $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme); $default_values[$row['variable']] = $value; } elseif ($row['variable'] == 'footer_extra_content') { $file = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt'; $value = ''; if (file_exists($file)) { $value = file_get_contents($file); } $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme); $default_values[$row['variable']] = $value; } else { $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme); $default_values[$row['variable']] = $row['selected_value']; } break; case 'radio': $values = api_get_settings_options($row['variable']); $group = array(); if (is_array($values)) { foreach ($values as $key => $value) { $element =& $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']); if ($hide_element) { $element->freeze(); } $group[] = $element; } } $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false); $default_values[$row['variable']] = $row['selected_value']; break; case 'checkbox': // 1. We collect all the options of this variable. $sql = "SELECT * FROM {$table_settings_current}\n WHERE variable='" . $row['variable'] . "' AND access_url = 1"; $result = Database::query($sql); $group = array(); while ($rowkeys = Database::fetch_array($result)) { // Profile tab option should be hidden when the social tool is enabled. if (api_get_setting('social.allow_social_tool') == 'true') { if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; } } // Hiding the gradebook option. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; } $element =& $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext'])); if ($row['access_url_changeable'] == 1) { // 2. We look into the DB if there is a setting for a specific access_url. $access_url = $_configuration['access_url']; if (empty($access_url)) { $access_url = 1; } $sql = "SELECT selected_value FROM {$table_settings_current}\n WHERE\n variable='" . $rowkeys['variable'] . "' AND\n subkey='" . $rowkeys['subkey'] . "' AND\n subkeytext='" . $rowkeys['subkeytext'] . "' AND\n access_url = {$access_url}"; $result_access = Database::query($sql); $row_access = Database::fetch_array($result_access); if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) { $element->setChecked(true); } } else { if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) { $element->setChecked(true); } } if ($hide_element) { $element->freeze(); } $group[] = $element; } $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), ''); break; case 'link': $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue') . ' : ' . $row['selected_value'], $hideme); break; case 'select': /* * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed. * The functions being called must be added to the file settings.lib.php. */ $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_' . $row['variable']), $hideme); $default_values[$row['variable']] = $row['selected_value']; break; case 'custom': break; } switch ($row['variable']) { case 'pdf_export_watermark_enable': $url = PDF::get_watermark(null); if ($url != false) { $delete_url = '<a href="?delete_watermark">' . get_lang('DelImage') . ' ' . Display::return_icon('delete.png', get_lang('DelImage')) . '</a>'; $form->addElement('html', '<div style="max-height:100px; max-width:100px; margin-left:162px; margin-bottom:10px; clear:both;"><img src="' . $url . '" style="margin-bottom:10px;" />' . $delete_url . '</div>'); } $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark')); $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif'); $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types); break; case 'timezone_value': $timezone = $row['selected_value']; if (empty($timezone)) { $timezone = _api_get_timezone(); } $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time())); break; } } // end for if (!empty($settings)) { $form->setDefaults($default_values); } $form->addHtml('<div class="bottom_actions">'); $form->addButtonSave(get_lang('SaveSettings')); $form->addHtml('</div>'); return $form; }
/** * function which redifines Question::createAnswersForm * @param FormValidator $form * @param the answers number to display */ function createAnswersForm($form) { // getting the exercise list $obj_ex = Session::read('objExercise'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); //this line define how many question by default appear when creating a choice question $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3; // The previous default value was 2. See task #1759. $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); /* Types of Feedback $feedback_option[0]=get_lang('Feedback'); $feedback_option[1]=get_lang('DirectFeedback'); $feedback_option[2]=get_lang('NoFeedback'); */ $feedback_title = ''; $comment_title = ''; if ($obj_ex->selectFeedbackType() == 1) { $editor_config['Width'] = '250'; $editor_config['Height'] = '110'; $comment_title = '<th width="50%" >' . get_lang('Comment') . '</th>'; $feedback_title = '<th width="50%" >' . get_lang('Scenario') . '</th>'; } else { $comment_title = '<th width="50%">' . get_lang('Comment') . '</th>'; } $html = '<table class="table table-striped table-hover">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th>' . get_lang('Number') . '</th>'; $html .= '<th>' . get_lang('True') . '</th>'; $html .= '<th width="50%">' . get_lang('Answer') . '</th>'; $html .= $comment_title . $feedback_title; $html .= '<th>' . get_lang('Weighting') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; $answer = false; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $temp_scenario = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : false; if ($editQuestion) { //fixing $nb_answers $new_list = array(); $count = 1; if (isset($_POST['lessAnswers'])) { $lessFromSession = Session::read('less_answer'); if (!isset($lessFromSession)) { Session::write('less_answer', $this->id); $nb_answers--; } } for ($k = 1; $k <= $nb_answers; ++$k) { if ($answer->position[$k] != '666') { $new_list[$count] = $count; $count++; } } } else { for ($k = 1; $k <= $nb_answers; ++$k) { $new_list[$k] = $k; } } $i = 1; //for ($k = 1 ; $k <= $real_nb_answers; $k++) { foreach ($new_list as $key) { $i = $key; $form->addElement('html', '<tr>'); if (is_object($answer)) { if ($answer->position[$i] == 666) { //we set nothing } else { if ($answer->correct[$i]) { $correct = $i; } $answer_result = $answer->answer[$i]; $weight_result = float_format($answer->weighting[$i], 1); if ($nb_answers == $i) { $weight_result = '0'; } $defaults['answer[' . $i . ']'] = $answer_result; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = $weight_result; $item_list = explode('@@', $answer->destination[$i]); $try = $item_list[0]; $lp = $item_list[1]; $list_dest = $item_list[2]; $url = $item_list[3]; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } } $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config); $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config); $form->addElement('text', 'weighting[' . $i . ']', null, array('style' => 'width: 60px;', 'value' => '0')); $form->addElement('html', '</tr>'); $i++; } if (empty($this->id)) { $form->addElement('hidden', 'new_question', 1); } //Adding the "I don't know" question answer //if (empty($this -> id)) { $i = 666; $form->addHtml('<tr>'); $defaults['answer[' . $i . ']'] = get_lang('DontKnow'); $defaults['weighting[' . $i . ']'] = 0; $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="-"'); $answer_number->freeze(); $form->addElement('hidden', 'position[' . $i . ']', '666'); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config); //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); $form->addText("weighting[{$i}]", null, false, ['style' => 'width: 60px;', 'value' => 0, 'readonly' => 'readonly']); $form->addHTml('</tr>'); $form->addHtml('</tbody></table>'); $buttonGroup = []; global $text, $class; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($buttonGroup); } //We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { $form->setDefaults($defaults); } $form->addElement('hidden', 'nb_answers'); $form->setConstants(array('nb_answers' => $nb_answers)); }
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { $defaults = array(); $nb_matches = $nb_options = 2; $matches = array(); $answer = null; $counter = 1; if (isset($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0) { for ($i = 1; $i <= $answer->nbrAnswers; $i++) { $correct = $answer->isCorrect($i); if (empty($correct)) { $matches[$answer->selectAutoId($i)] = chr(64 + $counter); $counter++; } } } } if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); $nb_options = $form->getSubmitValue('nb_options'); if (isset($_POST['lessOptions'])) { $nb_matches--; $nb_options--; } if (isset($_POST['moreOptions'])) { $nb_matches++; $nb_options++; } } else { if (!empty($this->id)) { if (count($answer->nbrAnswers) > 0) { $nb_matches = $nb_options = 0; for ($i = 1; $i <= $answer->nbrAnswers; $i++) { if ($answer->isCorrect($i)) { $nb_matches++; $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i); $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1); $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i]; } else { $nb_options++; $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i); } } } } else { $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2'); $defaults['matches[2]'] = '2'; $defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } } if (empty($matches)) { for ($i = 1; $i <= $nb_options; ++$i) { // fill the array with A, B, C..... $matches[$i] = chr(64 + $i); } } else { for ($i = $counter; $i <= $nb_options; ++$i) { // fill the array with A, B, C..... $matches[$i] = chr(64 + $i); } } $form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES $html = '<table class="table table-striped table-hover"> <thead> <tr> <th width="5%">' . get_lang('Number') . '</th> <th width="70%">' . get_lang('Answer') . '</th> <th width="15%">' . get_lang('MatchesTo') . '</th> <th width="10%">' . get_lang('Weighting') . '</th> </tr> </thead> <tbody>'; $form->addHeader(get_lang('MakeCorrespond')); $form->addHtml($html); if ($nb_matches < 1) { $nb_matches = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_matches; ++$i) { $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]"); $form->addHtml('<tr>'); $form->addHtml("<td>{$i}</td>"); $form->addText("answer[{$i}]", null); $form->addSelect("matches[{$i}]", null, $matches); $form->addText("weighting[{$i}]", null, true, ['value' => 10]); $form->addHtml('</tr>'); } $form->addHtml('</tbody></table>'); $group = array(); $form->addGroup($group); // DISPLAY OPTIONS $html = '<table class="table table-striped table-hover"> <thead> <tr> <th width="15%">' . get_lang('Number') . '</th> <th width="85%">' . get_lang('Answer') . '</th> </tr> </thead> <tbody>'; $form->addHtml($html); if ($nb_options < 1) { $nb_options = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_options; ++$i) { $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "option[{$i}]"); $form->addHtml('<tr>'); $form->addHtml('<td>' . chr(64 + $i) . '</td>'); $form->addText("option[{$i}]", null); $form->addHtml('</tr>'); } $form->addHtml('</table>'); $group = array(); global $text; // setting the save button here and not in the question class.php $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true); $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true); $group[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($group); if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options)); }
/** * This function displays the user report which is basically nothing more * than a one-page display of all the questions * of the survey that is filled with the answers of the person who filled the survey. * * @return string html code of the one-page survey with the answers of the selected user * @author Patrick Cool <*****@*****.**>, Ghent University * @version February 2007 - Updated March 2008 */ public static function display_user_report($people_filled, $survey_data) { // Database table definitions $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER); // Actions bar echo '<div class="actions">'; echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?survey_id=' . intval($_GET['survey_id']) . '&' . api_get_cidreq() . '">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('ReportingOverview'), '', ICON_SIZE_MEDIUM) . '</a>'; if (isset($_GET['user'])) { if (api_is_allowed_to_edit()) { // The delete link echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=deleteuserreport&survey_id=' . intval($_GET['survey_id']) . '&user='******'user']) . '&' . api_get_cidreq() . '" >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_MEDIUM) . '</a>'; } // Export the user report echo '<a href="javascript: void(0);" onclick="document.form1a.submit();">' . Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM) . '</a> '; echo '<a href="javascript: void(0);" onclick="document.form1b.submit();">' . Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM) . '</a> '; echo '<form id="form1a" name="form1a" method="post" action="' . api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . intval($_GET['survey_id']) . '&user_id=' . Security::remove_XSS($_GET['user']) . '&' . api_get_cidreq() . '">'; echo '<input type="hidden" name="export_report" value="export_report">'; echo '<input type="hidden" name="export_format" value="csv">'; echo '</form>'; echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . intval($_GET['survey_id']) . '&user_id=' . Security::remove_XSS($_GET['user']) . '&' . api_get_cidreq() . '">'; echo '<input type="hidden" name="export_report" value="export_report">'; echo '<input type="hidden" name="export_format" value="xls">'; echo '</form>'; echo '<form id="form2" name="form2" method="post" action="' . api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . intval($_GET['survey_id']) . '&' . api_get_cidreq() . '">'; } echo '</div>'; // Step 1: selection of the user echo "<script>\n function jumpMenu(targ,selObj,restore) {\n eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");\n if (restore) selObj.selectedIndex=0;\n }\n\t\t</script>"; echo get_lang('SelectUserWhoFilledSurvey') . '<br />'; echo '<select name="user" onchange="jumpMenu(\'parent\',this,0)">'; echo '<option value="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . Security::remove_XSS($_GET['survey_id']) . '">' . get_lang('SelectUser') . '</option>'; foreach ($people_filled as $key => &$person) { if ($survey_data['anonymous'] == 0) { $name = api_get_person_name($person['firstname'], $person['lastname']); $id = $person['user_id']; if ($id == '') { $id = $person['invited_user']; $name = $person['invited_user']; } } else { $name = get_lang('Anonymous') . ' ' . ($key + 1); $id = $person; } echo '<option value="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . Security::remove_XSS($_GET['survey_id']) . '&user='******'" '; if (isset($_GET['user']) && $_GET['user'] == $id) { echo 'selected="selected"'; } echo '>' . $name . '</option>'; } echo '</select>'; $course_id = api_get_course_int_id(); // Step 2: displaying the survey and the answer of the selected users if (isset($_GET['user'])) { Display::display_normal_message(get_lang('AllQuestionsOnOnePage'), false); // Getting all the questions and options $sql = "SELECT\n\t\t\t survey_question.question_id,\n\t\t\t survey_question.survey_id,\n\t\t\t survey_question.survey_question,\n\t\t\t survey_question.display,\n\t\t\t survey_question.max_value,\n\t\t\t survey_question.sort,\n\t\t\t survey_question.type,\n survey_question_option.question_option_id,\n survey_question_option.option_text,\n survey_question_option.sort as option_sort\n\t\t\t\t\tFROM {$table_survey_question} survey_question\n\t\t\t\t\tLEFT JOIN {$table_survey_question_option} survey_question_option\n\t\t\t\t\tON\n\t\t\t\t\t survey_question.question_id = survey_question_option.question_id AND\n\t\t\t\t\t survey_question_option.c_id = {$course_id}\n\t\t\t\t\tWHERE\n\t\t\t\t\t survey_question.survey_id = '" . Database::escape_string($_GET['survey_id']) . "' AND\n survey_question.c_id = {$course_id}\n\t\t\t\t\tORDER BY survey_question.sort, survey_question_option.sort ASC"; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { if ($row['type'] != 'pagebreak') { $questions[$row['sort']]['question_id'] = $row['question_id']; $questions[$row['sort']]['survey_id'] = $row['survey_id']; $questions[$row['sort']]['survey_question'] = $row['survey_question']; $questions[$row['sort']]['display'] = $row['display']; $questions[$row['sort']]['type'] = $row['type']; $questions[$row['sort']]['maximum_score'] = $row['max_value']; $questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text']; } } // Getting all the answers of the user $sql = "SELECT * FROM {$table_survey_answer}\n\t\t\t WHERE\n c_id = {$course_id} AND\n survey_id = '" . intval($_GET['survey_id']) . "' AND\n user = '******'user']) . "'"; $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $answers[$row['question_id']][] = $row['option_id']; $all_answers[$row['question_id']][] = $row; } // Displaying all the questions foreach ($questions as &$question) { // If the question type is a scoring then we have to format the answers differently switch ($question['type']) { case 'score': $finalAnswer = array(); if (is_array($question) && is_array($all_answers)) { foreach ($all_answers[$question['question_id']] as $key => &$answer_array) { $finalAnswer[$answer_array['option_id']] = $answer_array['value']; } } break; case 'multipleresponse': $finalAnswer = isset($answers[$question['question_id']]) ? $answers[$question['question_id']] : ''; break; default: $finalAnswer = ''; if (isset($all_answers[$question['question_id']])) { $finalAnswer = $all_answers[$question['question_id']][0]['option_id']; } break; } $ch_type = 'ch_' . $question['type']; /** @var survey_question $display */ $display = new $ch_type(); $url = api_get_self(); $form = new FormValidator('question', 'post', $url); $form->addHtml('<div class="survey_question_wrapper"><div class="survey_question">'); $form->addHtml($question['survey_question']); $display->render($form, $question, $finalAnswer); $form->addHtml('</div></div>'); $form->display(); } } }
$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', 'id' => 'selectBox']); if ($editingCourse) { $teachersOptions = api_unique_multidim_array($teachersOptions, 'value'); $beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers')); } elseif ($editingSession) { $courseCoachesOptions = api_unique_multidim_array($courseCoachesOptions, 'value'); $beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach')); $beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach')); } if ($commissionsEnable === 'true') { $platformCommission = $plugin->getPlatformCommission(); $form->addHtml('' . '<div class="form-group">' . '<label for="sliders" class="col-sm-2 control-label">' . get_plugin_lang('Commissions', 'BuyCoursesPlugin') . '</label>' . '<div class="col-sm-8">' . Display::return_message(sprintf($plugin->get_lang('TheActualPlatformCommissionIsX'), $platformCommission['commission'] . '%'), 'info', false) . '<div class="" id="panelSliders"></div>' . '</div>' . '</div>'); $form->addHidden('commissions', ''); } $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']); if (isset($formValues['visible'])) { if (!empty($productItem)) { $plugin->updateItem(['price' => floatval($formValues['price'])], $formValues['i'], $formValues['t']); } else { $itemId = $plugin->registerItem(['currency_id' => $currency['id'], 'product_type' => $formValues['t'], 'product_id' => intval($formValues['i']), 'price' => floatval($_POST['price'])]); $productItem['id'] = $itemId;