/** * Create a form validator based on an array of form data: * * array( * 'name' => 'zombie_report_parameters', //optional * 'method' => 'GET', //optional * 'items' => array( * array( * 'name' => 'ceiling', * 'label' => 'Ceiling', //optional * 'type' => 'date', * 'default' => date() //optional * ), * array( * 'name' => 'active_only', * 'label' => 'ActiveOnly', * 'type' => 'checkbox', * 'default' => true * ), * array( * 'name' => 'submit_button', * 'type' => 'style_submit_button', * 'value' => get_lang('Search'), * 'attributes' => array('class' => 'search') * ) * ) * ); * * @param array $form_data * * @return FormValidator */ public static function create($form_data) { if (empty($form_data)) { return null; } $form_name = isset($form_data['name']) ? $form_data['name'] : 'form'; $form_method = isset($form_data['method']) ? $form_data['method'] : 'POST'; $form_action = isset($form_data['action']) ? $form_data['action'] : ''; $form_target = isset($form_data['target']) ? $form_data['target'] : ''; $form_attributes = isset($form_data['attributes']) ? $form_data['attributes'] : null; $form_track_submit = isset($form_data['track_submit']) ? $form_data['track_submit'] : true; $result = new FormValidator($form_name, $form_method, $form_action, $form_target, $form_attributes, $form_track_submit); $defaults = array(); foreach ($form_data['items'] as $item) { $name = $item['name']; $type = isset($item['type']) ? $item['type'] : 'text'; $label = isset($item['label']) ? $item['label'] : ''; if ($type == 'wysiwyg') { $element = $result->add_html_editor($name, $label); } else { $element = $result->addElement($type, $name, $label); } if (isset($item['attributes'])) { $attributes = $item['attributes']; $element->setAttributes($attributes); } if (isset($item['value'])) { $value = $item['value']; $element->setValue($value); } if (isset($item['default'])) { $defaults[$name] = $item['default']; } if (isset($item['rules'])) { $rules = $item['rules']; foreach ($rules as $rule) { $message = $rule['message']; $type = $rule['type']; $format = isset($rule['format']) ? $rule['format'] : null; $validation = isset($rule['validation']) ? $rule['validation'] : 'server'; $force = isset($rule['force']) ? $rule['force'] : false; $result->addRule($name, $message, $type, $format, $validation, $reset, $force); } } } $result->setDefaults($defaults); return $result; }
/** * Returns a Form validator Obj * @todo the form should be auto generated * @param string url * @param string action add, edit * @return obj form validator obj */ public function return_form($url, $action) { $oFCKeditor = new FCKeditor('description'); $oFCKeditor->ToolbarSet = 'careers'; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '200'; $oFCKeditor->Value = ''; $oFCKeditor->CreateHtml(); $form = new FormValidator('career', 'post', $url); // Setting the form elements $header = get_lang('Add'); if ($action == 'edit') { $header = get_lang('Modify'); } $form->addElement('header', $header); $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $form->addElement('hidden', 'id', $id); $form->addElement('text', 'name', get_lang('Name'), array('size' => '70')); $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers', 'Width' => '100%', 'Height' => '250')); $status_list = $this->get_status_list(); $form->addElement('select', 'status', get_lang('Status'), $status_list); if ($action == 'edit') { $form->addElement('text', 'created_at', get_lang('CreatedAt')); $form->freeze('created_at'); } if ($action == 'edit') { $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); } else { $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"'); } // Setting the defaults $defaults = $this->get($id); if (!empty($defaults['created_at'])) { $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']); } if (!empty($defaults['updated_at'])) { $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']); } $form->setDefaults($defaults); // Setting the rules $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); return $form; }
/** * Creates the form to create / edit a question * A subclass can redifine this function to add fields... * * @param \FormValidator $form the formvalidator instance (by reference) * @param array $fck_config */ public function createForm(&$form, $fck_config = array()) { $maxCategories = 1; $url = api_get_path(WEB_AJAX_PATH) . 'exercise.ajax.php?1=1'; $js = null; if ($this->type != MEDIA_QUESTION) { $js = '<script> function check() { var counter = 0; $("#category_id option:selected").each(function() { var id = $(this).val(); var name = $(this).text(); if (id != "" ) { // if a media question was selected $("#parent_id option:selected").each(function() { var questionId = $(this).val(); if (questionId != 0) { if (counter >= 1) { alert("' . addslashes(get_lang('YouCantAddAnotherCategory')) . '"); $("#category_id").trigger("removeItem",[{ "value" : id}]); return; } } }); $.ajax({ async: false, url: "' . $url . '&a=exercise_category_exists", data: "id="+id, success: function(return_value) { if (return_value == 0 ) { alert("' . addslashes(get_lang('CategoryDoesNotExists')) . '"); // Deleting select option tag $("#category_id").find("option").remove(); $(".holder li").each(function () { if ($(this).attr("rel") == id) { $(this).remove(); } }); } }, }); } counter++; }); } $(function() { $("#category_id").fcbkcomplete({ json_url: "' . $url . '&a=search_category_parent&type=all&filter_by_global=' . $this->exercise->getGlobalCategoryId() . '", maxitems: "' . $maxCategories . '", addontab: false, input_min_size: 1, cache: false, complete_text:"' . get_lang('StartToType') . '", firstselected: false, onselect: check, filter_selected: true, newel: true }); // Change select media $("#parent_id").change(function(){ $("#parent_id option:selected").each(function() { var questionId = $(this).val(); if (questionId != 0) { $.ajax({ async: false, dataType: "json", url: "' . $url . '&a=get_categories_by_media&questionId=' . $this->id . '&exerciseId=' . $this->exercise->id . '", data: "mediaId="+questionId, success: function(data) { if (data != -1) { var all = $("#category_id").trigger("selectAll"); all.each(function(index, value) { var selected = $(value).find("option:selected"); selected.each(function( indexSelect, valueSelect) { valueToRemove = $(valueSelect).val(); $("#category_id").trigger("removeItem",[{ "value" : valueToRemove}]); }); }); if (data != 0) { $("#category_id").trigger("addItem",[{"title": data.title, "value": data.value}]); } } }, }); } else { // Removes all items var all = $("#category_id").trigger("selectAll"); all.each(function(index, value) { var selected = $(value).find("option:selected"); selected.each(function( indexSelect, valueSelect) { valueToRemove = $(valueSelect).val(); $("#category_id").trigger("removeItem", [{ "value" : valueToRemove}]); }); }); } }); }); }); // hub 13-12-2010 function visiblerDevisibler(in_id) { if (document.getElementById(in_id)) { if (document.getElementById(in_id).style.display == "none") { document.getElementById(in_id).style.display = "block"; if (document.getElementById(in_id+"Img")) { document.getElementById(in_id+"Img").html = "' . addslashes(Display::return_icon('div_hide.gif')) . '"; } } else { document.getElementById(in_id).style.display = "none"; if (document.getElementById(in_id+"Img")) { document.getElementById(in_id+"Img").html = "dsdsds' . addslashes(Display::return_icon('div_show.gif')) . '"; } } } } </script>'; $form->addElement('html', $js); } // question name $form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6')); $form->addRule('questionName', get_lang('GiveQuestion'), 'required'); // Default content. $isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null; // Question type $answerType = isset($_REQUEST['answerType']) ? intval($_REQUEST['answerType']) : $this->selectType(); $form->addElement('hidden', 'answerType', $answerType); // html editor $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150'); if (is_array($fck_config)) { $editor_config = array_merge($editor_config, $fck_config); } if (!api_is_allowed_to_edit(null, true)) { $editor_config['UserStatus'] = 'student'; } $form->add_html_editor('questionDescription', get_lang('QuestionDescription'), false, false, $editor_config); // hidden values $my_id = isset($_REQUEST['myid']) ? intval($_REQUEST['myid']) : null; $form->addElement('hidden', 'myid', $my_id); if ($this->type != MEDIA_QUESTION) { if ($this->exercise->fastEdition == false) { // Advanced parameters $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="advanced_params_options" style="display:none;">'); } // Level (difficulty). $select_level = Question::get_default_levels(); $form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level); // Media question. $course_medias = Question::prepare_course_media_select(api_get_course_int_id()); $form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias, array('id' => 'parent_id')); // Categories. $categoryJS = null; if (!empty($this->category_list)) { $trigger = ''; foreach ($this->category_list as $category_id) { if (!empty($category_id)) { $cat = new Testcategory($category_id); if ($cat->id) { $trigger .= '$("#category_id").trigger("addItem",[{"title": "' . $cat->parent_path . '", "value": "' . $cat->id . '"}]);'; } } } $categoryJS .= '<script>$(function() { ' . $trigger . ' });</script>'; } $form->addElement('html', $categoryJS); $form->addElement('select', 'questionCategory', get_lang('Category'), array(), array('id' => 'category_id')); // Extra fields. (Injecting question extra fields!) $extraFields = new ExtraField('question'); $extraFields->addElements($form, $this->id); if ($this->exercise->fastEdition == false) { $form->addElement('html', '</div>'); } } // @todo why we need this condition?? if ($this->setDefaultQuestionValues) { switch ($answerType) { case 1: $this->question = get_lang('DefaultUniqueQuestion'); break; case 2: $this->question = get_lang('DefaultMultipleQuestion'); break; case 3: $this->question = get_lang('DefaultFillBlankQuestion'); break; case 4: $this->question = get_lang('DefaultMathingQuestion'); break; case 5: $this->question = get_lang('DefaultOpenQuestion'); break; case 9: $this->question = get_lang('DefaultMultipleQuestion'); break; } } // default values $defaults = array(); $defaults['questionName'] = $this->question; $defaults['questionDescription'] = $this->description; $defaults['questionLevel'] = $this->level; $defaults['questionCategory'] = $this->category_list; $defaults['parent_id'] = $this->parent_id; if (!empty($_REQUEST['myid'])) { $form->setDefaults($defaults); } else { if ($isContent == 1) { $form->setDefaults($defaults); } } if ($this->setDefaultValues) { $form->setDefaults($defaults); } }
$param_gradebook = ''; if (isset($_SESSION['gradebook'])) { $param_gradebook = '&gradebook=' . Security::remove_XSS($_SESSION['gradebook']); } if (!$error) { $token = Security::get_token(); } $attendance_weight = floatval($attendance_weight); // display form $form = new FormValidator('attendance_edit', 'POST', 'index.php?action=attendance_edit&' . api_get_cidreq() . '&attendance_id=' . $attendance_id . $param_gradebook); $form->addElement('header', '', get_lang('Edit')); $form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'attendance_id', $attendance_id); $form->add_textfield('title', get_lang('Title'), true, array('size' => '50')); $form->applyFilter('title', 'html_filter'); $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200')); // Adavanced Parameters if (Gradebook::is_active()) { if (!empty($attendance_qualify_title) || !empty($attendance_weight)) { $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="id_qualify_options" style="display:block">'); $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), array('checked' => 'true', 'onclick' => 'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}')); $form->addElement('html', '<div id="options_field" style="display:block">'); } else { $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="id_qualify_options" style="display:none">'); $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'); $form->addElement('html', '<div id="options_field" style="display:none">'); } load_gradebook_select_in_tool($form); $form->addElement('text', 'attendance_qualify_title', get_lang('TitleColumnGradebook'));
} else { $form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">'); } if (count($attendance_select) > 1) { $form->addElement('select', 'attendance_select', get_lang('Attendances'), $attendance_select, array('id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)')); } else { $form->addElement('label', get_lang('Attendances'), '<strong><em>' . get_lang('ThereAreNoAttendancesInsideCourse') . '</em></strong>'); } $form->addElement('html', '<div id="div_datetime_attendance">'); if (!empty($calendar_select)) { $form->addElement('select', 'start_date_by_attendance', get_lang('StartDate'), $calendar_select, array('id' => 'start_date_select_calendar')); } $form->addElement('html', '</div>'); $form->addElement('html', '</div>'); $form->add_textfield('duration_in_hours', get_lang('DurationInHours'), false, array('size' => '3', 'id' => 'duration_in_hours_element', 'autofocus' => 'autofocus')); $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarStartExpanded' => 'false', 'ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150')); //$form->addElement('textarea', 'content', get_lang('Content')); if ($action == 'thematic_advance_add') { $form->addElement('style_submit_button', null, get_lang('Save'), 'id="add_button" class="save"'); } else { $form->addElement('style_submit_button', null, get_lang('Save'), 'id="update_button" class="save"'); } //$form->addElement('html', '<a href="#" id="save_button" onclick="save();">Save</a>'); $attendance_select_item_id = null; if (count($attendance_select) > 1) { $i = 1; foreach ($attendance_select as $key => $attendance_select_item) { if ($i == 2) { $attendance_select_item_id = $key; break; }
function add_category_form($in_action, $type = 'simple') { $in_action = Security::remove_XSS($in_action); // Initiate the object $form = new FormValidator('note', 'post', api_get_self() . '?' . api_get_cidreq() . '&action=' . $in_action . "&type=" . $type); // Setting the form elements $form->addElement('header', get_lang('AddACategory')); $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); $form->addElement('select', 'parent_id', get_lang('Parent'), array(), array('id' => 'parent_id')); $form->addElement('style_submit_button', 'SubmitNote', get_lang('AddTestCategory'), 'class="add"'); // Setting the rules $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); // The validation or display if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->getSubmitValues(); $parent_id = isset($values['parent_id']) && isset($values['parent_id'][0]) ? $values['parent_id'][0] : null; $objcat = new Testcategory(0, $values['category_name'], $values['category_description'], $parent_id, $type, api_get_course_int_id()); if ($objcat->addCategoryInBDD()) { Display::display_confirmation_message(get_lang('AddCategoryDone')); } else { Display::display_confirmation_message(get_lang('AddCategoryNameAlreadyExists')); } } Security::clear_token(); display_add_category($type); display_categories($type); } else { display_goback($type); $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } }
} break; case 'create_dir': case 'add': //$check = Security::check_token('post'); //show them the form for the directory name if ($is_allowed_to_edit && in_array($action, array('create_dir', 'add'))) { //create the form that asks for the directory name $form = new FormValidator('form1', 'post', api_get_self() . '?action=create_dir&' . api_get_cidreq()); $form->addElement('header', get_lang('CreateAssignment') . $token); $form->addElement('hidden', 'action', 'add'); $form->addElement('hidden', 'curdirpath', Security::remove_XSS($curdirpath)); // $form->addElement('hidden', 'sec_token', $token); $form->addElement('text', 'new_dir', get_lang('AssignmentName')); $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required'); $form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); $form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();"><span id="plus">' . Display::return_icon('div_show.gif', get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')) . ' ' . get_lang('AdvancedParameters') . '</span></a>'); $form->addElement('html', '<div id="options" style="display: none;">'); //QualificationOfAssignment $form->addElement('text', 'qualification_value', get_lang('QualificationNumeric')); if (Gradebook::is_active()) { $form->addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), array('id' => 'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}")); } else { //QualificationOfAssignment //$form->addElement('hidden', 'qualification_value',0); $form->addElement('hidden', 'make_calification', false); } $form->addElement('html', '<div id="option1" style="display: none;">'); //Loading gradebook select load_gradebook_select_in_tool($form); $form->addElement('text', 'weight', get_lang('WeightInTheGradebook'));
$form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20)); if (api_get_setting('registration', 'phone') == 'true') { $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required'); } // LANGUAGE if (api_get_setting('registration', 'language') == 'true') { $form->addElement('select_language', 'language', get_lang('Language')); } // STUDENT/TEACHER if (api_get_setting('allow_registration_as_teacher') != 'false') { $form->addElement('radio', 'status', get_lang('Profile'), get_lang('RegStudent'), STUDENT); $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER); } // EXTENDED FIELDS if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true') { $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')); } if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true') { $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')); } if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'myteach') == 'true') { $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')); } if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true') { $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')); } if (api_get_setting('extended_profile') == 'true') { if (api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true' && api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') == 'true') { $form->addRule('competences', get_lang('ThisFieldIsRequired'), 'required'); } if (api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true' && api_get_setting('extendedprofile_registrationrequired', 'mydiplomas') == 'true') {
echo '<a href="' . api_get_self() . '">' . Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) { // Action handling: Editing a note // Initialize the object $form = new FormValidator('career', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&id=' . Security::remove_XSS($_GET['id'])); // Setting the form elements $form->addElement('header', '', get_lang('Modify')); $form->addElement('hidden', 'id', intval($_GET['id'])); $form->addElement('text', 'name', get_lang('Name'), array('size' => '70')); $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250')); $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); // Setting the defaults $defaults = $usergroup->get($_GET['id']); $form->setDefaults($defaults); // Setting the rules. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); // The validation or display. if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); $res = $usergroup->update($values); if ($res) { Display::display_confirmation_message(get_lang('Updated')); } else {
/** * Creates the form to create / edit an exercise * @param FormValidator $form */ public function createForm($form, $type = 'full') { global $id; if (empty($type)) { $type = 'full'; } // form title if (!empty($_GET['exerciseId'])) { $form_title = get_lang('ModifyExercise'); } else { $form_title = get_lang('NewEx'); } $form->addElement('header', $form_title); // Title. $form->addElement('text', 'exerciseTitle', get_lang('ExerciseName'), array('class' => 'span6', 'id' => 'exercise_title')); $form->addElement('advanced_settings', '<a href="javascript://" onclick=" return show_media()"> <span id="media_icon"> <img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />' . addslashes(api_htmlentities(get_lang('ExerciseDescription'))) . ' </span> </a> '); $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150'); if (is_array($type)) { $editor_config = array_merge($editor_config, $type); } $form->addElement('html', '<div class="HideFCKEditor" id="HiddenFCKexerciseDescription" >'); $form->add_html_editor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config); $form->addElement('html', '</div>'); $form->addElement('advanced_settings', '<a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" > <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> ' . addslashes(api_htmlentities(get_lang('AdvancedParameters'))) . '</div></span></a>'); // Random questions // style="" and not "display:none" to avoid #4029 Random and number of attempt menu empty $form->addElement('html', '<div id="options" style="">'); if ($type == 'full') { //Can't modify a DirectFeedback question if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) { // feedback type $radios_feedback = array(); $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()')); if (api_get_setting('enable_quiz_scenario') == 'true') { //Can't convert a question from one feedback to another if there is more than 1 question already added if ($this->selectNbrQuestions() == 0) { $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()')); } } $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2')); $form->addGroup($radios_feedback, null, 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('enable_quiz_scenario') == 'true') { $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()')); } $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2')); $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions'))); //$form->addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"'); $radios_results_disabled = array(); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()')); $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); // Type of questions disposition on page $radios = array(); $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1'); $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2'); $form->addGroup($radios, null, get_lang('ExerciseType')); } else { //Show options freeze $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()')); $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); $result_disable_group->freeze(); //we force the options to the DirectFeedback exercisetype $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT); $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE); // Type of questions disposition on page $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all')); $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one')); $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage'), ''); $type_group->freeze(); } } // number of random question $max = $this->id > 0 ? $this->selectNbrQuestions() : 10; $option = range(0, $max); $option[0] = get_lang('No'); $option[-1] = get_lang('AllQuestionsShort'); $form->addElement('select', 'randomQuestions', array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id' => 'randomQuestions', 'class' => 'chzn-select')); //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'), ''); //randow by category $form->addElement('html', '<div class="clear"> </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"> </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, array('id' => 'exerciseAttempts', 'class' => 'chzn-select')); // Exercice time limit $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()')); $var = Exercise::selectTimeLimit(); if ($this->start_time != '0000-00-00 00:00:00') { $form->addElement('html', '<div id="start_date_div" style="display:block;">'); } else { $form->addElement('html', '<div id="start_date_div" style="display:none;">'); } $form->addElement('date_time_picker', 'start_time'); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()')); if ($this->end_time != '0000-00-00 00:00:00') { $form->addElement('html', '<div id="end_date_div" style="display:block;">'); } else { $form->addElement('html', '<div id="end_date_div" style="display:none;">'); } $form->addElement('date_time_picker', 'end_time'); $form->addElement('html', '</div>'); //$check_option=$this->selectType(); $diplay = 'block'; $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults')); $form->addElement('html', '<div class="clear"> </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->addElement('text', 'enabletimercontroltotalminutes', get_lang('ExerciseTotalDurationInMinutes'), array('style' => 'width : 35px', 'id' => 'enabletimercontroltotalminutes')); $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->add_html_editor('text_when_finished', get_lang('TextWhenFinished'), false, false, $editor_config); $defaults = array(); if (api_get_setting('search_enabled') === 'true') { require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument')); $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage')); $specific_fields = get_specific_field_list(); foreach ($specific_fields as $specific_field) { $form->addElement('text', $specific_field['code'], $specific_field['name']); $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\'' . TOOL_QUIZ . '\''); $values = get_specific_field_values_list($filter, array('value')); if (!empty($values)) { $arr_str_values = array(); foreach ($values as $value) { $arr_str_values[] = $value['value']; } $defaults[$specific_field['code']] = implode(', ', $arr_str_values); } } //$form->addElement ('html','</div>'); } $form->addElement('html', '</div>'); //End advanced setting $form->addElement('html', '</div>'); } // submit $text = isset($_GET['exerciseId']) ? get_lang('ModifyExercise') : get_lang('ProcedToQuestions'); $form->addElement('style_submit_button', 'submitExercise', $text, 'class="save"'); $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required'); if ($type == 'full') { // rules $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric'); $form->addRule('start_time', get_lang('InvalidDate'), 'datetime'); $form->addRule('end_time', get_lang('InvalidDate'), 'datetime'); } // defaults if ($type == 'full') { if ($this->id > 0) { if ($this->random > $this->selectNbrQuestions()) { $defaults['randomQuestions'] = $this->selectNbrQuestions(); } else { $defaults['randomQuestions'] = $this->random; } $defaults['randomAnswers'] = $this->selectRandomAnswers(); $defaults['exerciseType'] = $this->selectType(); $defaults['exerciseTitle'] = $this->get_formated_title(); $defaults['exerciseDescription'] = $this->selectDescription(); $defaults['exerciseAttempts'] = $this->selectAttempts(); $defaults['exerciseFeedbackType'] = $this->selectFeedbackType(); $defaults['results_disabled'] = $this->selectResultsDisabled(); $defaults['propagate_neg'] = $this->selectPropagateNeg(); $defaults['review_answers'] = $this->review_answers; $defaults['randomByCat'] = $this->selectRandomByCat(); // $defaults['text_when_finished'] = $this->selectTextWhenFinished(); // $defaults['display_category_name'] = $this->selectDisplayCategoryName(); // $defaults['pass_percentage'] = $this->selectPassPercentage(); if ($this->start_time != '0000-00-00 00:00:00') { $defaults['activate_start_date_check'] = 1; } if ($this->end_time != '0000-00-00 00:00:00') { $defaults['activate_end_date_check'] = 1; } $defaults['start_time'] = $this->start_time != '0000-00-00 00:00:00' ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00'); $defaults['end_time'] = $this->end_time != '0000-00-00 00:00:00' ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time() + 84600); //Get expired time if ($this->expired_time != '0') { $defaults['enabletimercontrol'] = 1; $defaults['enabletimercontroltotalminutes'] = $this->expired_time; } else { $defaults['enabletimercontroltotalminutes'] = 0; } } else { $defaults['exerciseType'] = 2; $defaults['exerciseAttempts'] = 0; $defaults['randomQuestions'] = 0; $defaults['randomAnswers'] = 0; $defaults['exerciseDescription'] = ''; $defaults['exerciseFeedbackType'] = 0; $defaults['results_disabled'] = 0; $defaults['randomByCat'] = 0; // $defaults['text_when_finished'] = ""; // $defaults['start_time'] = date('Y-m-d 12:00:00'); $defaults['display_category_name'] = 1; // $defaults['end_time'] = date('Y-m-d 12:00:00', time() + 84600); $defaults['pass_percentage'] = ''; } } else { $defaults['exerciseTitle'] = $this->selectTitle(); $defaults['exerciseDescription'] = $this->selectDescription(); } if (api_get_setting('search_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(); //$form->freeze(); } }
/** * * @param $url * @param string * @return \FormValidator */ private function getForm($url, $tool) { $toolbar_set = 'IntroductionTool'; $width = '100%'; $height = '300'; $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height); $form = new \FormValidator('form', 'post', $url); $form->add_html_editor('content', null, null, false, $editor_config); if ($tool == 'course_homepage') { $form->addElement('label', get_lang('YouCanUseAllTheseTags'), '((' . implode(')) <br /> ((', \CourseHome::availableTools()) . '))'); } $form->addElement('button', 'submit', get_lang('SaveIntroText')); return $form; }
/** * Creates the form to create / edit a question * A subclass can redifine this function to add fields... * @param FormValidator $form the formvalidator instance (by reference) */ function createForm(&$form, $fck_config = 0) { echo '<style> .media { display:none;} </style>'; echo '<script> // hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700 function FCKeditor_OnComplete( editorInstance ) { if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) { HideFCKEditorByInstanceName (editorInstance.Name); } } function HideFCKEditorByInstanceName ( editorInstanceName ) { if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" ) { document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media"; } } function show_media(){ var my_display = document.getElementById(\'HiddenFCKquestionDescription\').style.display; if(my_display== \'none\' || my_display == \'\') { document.getElementById(\'HiddenFCKquestionDescription\').style.display = \'block\'; document.getElementById(\'media_icon\').innerHTML=\' <img style="vertical-align: middle;" src="../img/looknfeelna.png" alt="" /> ' . get_lang('EnrichQuestion') . '\'; } else { document.getElementById(\'HiddenFCKquestionDescription\').style.display = \'none\'; document.getElementById(\'media_icon\').innerHTML=\' <img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" /> ' . get_lang('EnrichQuestion') . '\'; } } // hub 13-12-2010 function visiblerDevisibler(in_id) { if (document.getElementById(in_id)) { if (document.getElementById(in_id).style.display == "none") { document.getElementById(in_id).style.display = "block"; if (document.getElementById(in_id+"Img")) { document.getElementById(in_id+"Img").src = "../img/div_hide.gif"; } } else { document.getElementById(in_id).style.display = "none"; if (document.getElementById(in_id+"Img")) { document.getElementById(in_id+"Img").src = "../img/div_show.gif"; } } } } </script>'; // question name $form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6')); $form->addRule('questionName', get_lang('GiveQuestion'), 'required'); // default content $isContent = isset($_REQUEST['isContent']) ? intval($_REQUEST['isContent']) : null; // Question type $answerType = isset($_REQUEST['answerType']) ? intval($_REQUEST['answerType']) : null; $form->addElement('hidden', 'answerType', $answerType); // html editor $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150'); if (is_array($fck_config)) { $editor_config = array_merge($editor_config, $fck_config); } if (!api_is_allowed_to_edit(null, true)) { $editor_config['UserStatus'] = 'student'; } $form->addElement('advanced_settings', ' <a href="javascript://" onclick=" return show_media()"><span id="media_icon"><img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" /> ' . get_lang('EnrichQuestion') . '</span></a> '); $form->addElement('html', '<div class="HideFCKEditor" id="HiddenFCKquestionDescription" >'); $form->add_html_editor('questionDescription', get_lang('QuestionDescription'), false, false, $editor_config); $form->addElement('html', '</div>'); // hidden values $my_id = isset($_REQUEST['myid']) ? intval($_REQUEST['myid']) : null; $form->addElement('hidden', 'myid', $my_id); if ($this->type != MEDIA_QUESTION) { // Advanced parameters $form->addElement('advanced_settings', '<a href="javascript:void(0)" onclick="visiblerDevisibler(\'id_advancedOption\')"><img id="id_advancedOptionImg" style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> ' . get_lang("AdvancedParameters") . '</a>'); $form->addElement('html', '<div id="id_advancedOption" style="display:none;">'); $select_level = Question::get_default_levels(); $form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level); // Categories //$category_list = Testcategory::getCategoriesIdAndName(); //$form->addElement('select', 'questionCategory', get_lang('Category'), $category_list, array('multiple' => 'multiple')); // Categories $tabCat = Testcategory::getCategoriesIdAndName(); $form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat); //Medias //$course_medias = Question::prepare_course_media_select(api_get_course_int_id()); //$form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias); $form->addElement('html', '</div>'); } if (!isset($_GET['fromExercise'])) { switch ($answerType) { case 1: $this->question = get_lang('DefaultUniqueQuestion'); break; case 2: $this->question = get_lang('DefaultMultipleQuestion'); break; case 3: $this->question = get_lang('DefaultFillBlankQuestion'); break; case 4: $this->question = get_lang('DefaultMathingQuestion'); break; case 5: $this->question = get_lang('DefaultOpenQuestion'); break; case 9: $this->question = get_lang('DefaultMultipleQuestion'); break; } } // default values $defaults = array(); $defaults['questionName'] = $this->question; $defaults['questionDescription'] = $this->description; $defaults['questionLevel'] = $this->level; $defaults['questionCategory'] = $this->category; //$defaults['questionCategory'] = $this->category_list; //$defaults['parent_id'] = $this->parent_id; //Came from he question pool if (isset($_GET['fromExercise'])) { $form->setDefaults($defaults); } if (!empty($_REQUEST['myid'])) { $form->setDefaults($defaults); } else { if ($isContent == 1) { $form->setDefaults($defaults); } } }
} //THEME if (is_profile_editable() && api_get_setting('user_selected_theme') == 'true') { $form->addElement('select_theme', 'theme', get_lang('Theme')); if (api_get_setting('profile', 'theme') !== 'true') { $form->freeze('theme'); } $form->applyFilter('theme', 'trim'); } // EXTENDED PROFILE this make the page very slow! if (api_get_setting('extended_profile') == 'true') { $width_extended_profile = 500; //$form->addElement('html', '<a href="javascript: void(0);" onclick="javascript: show_extend();"> show_extend_profile</a>'); //$form->addElement('static', null, '<em>'.get_lang('OptionalTextFields').'</em>'); // MY COMPETENCES $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130')); // MY DIPLOMAS $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130')); // WHAT I AM ABLE TO TEACH $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130')); // MY PRODUCTIONS $form->addElement('file', 'production', get_lang('MyProductions')); if ($production_list = UserManager::build_production_list(api_get_user_id(), '', true)) { $form->addElement('static', 'productions_list', null, $production_list); } // MY PERSONAL OPEN AREA $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '350')); $form->applyFilter(array('competences', 'diplomas', 'teach', 'openarea'), 'stripslashes'); $form->applyFilter(array('competences', 'diplomas', 'teach'), 'trim'); // openarea is untrimmed for maximum openness }
/** * @param FormValidator $form * @param array $row */ public function setForm($form, $row = array()) { $toolBar = api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400') : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student'); $form->add_html_editor('content', get_lang('Content'), false, false, $toolBar); //$content $form->addElement('text', 'comment', get_lang('Comments')); $progress = array('', 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); $form->addElement('select', 'progress', get_lang('Progress'), $progress); if ((api_is_allowed_to_edit(false, true) || api_is_platform_admin()) && isset($row['reflink']) && $row['reflink'] != 'index') { /* $advanced = '<a href="javascript://" onclick="advanced_parameters()" > <div id="plus_minus"> '. Display::return_icon( 'div_show.gif', get_lang('Show'), array('style'=>'vertical-align:middle') ).' '.get_lang('AdvancedParameters').'</div></a>'; */ $form->addElement('advanced_settings', 'settings', get_lang('AdvancedParameters')); $form->addElement('html', '<div id="settings_options" style="display:none">'); $form->add_html_editor('task', get_lang('DescriptionOfTheTask'), false, false, array('ToolbarSet' => 'wiki_task', 'Width' => '100%', 'Height' => '200')); $form->addElement('label', null, get_lang('AddFeedback')); $form->addElement('textarea', 'feedback1', get_lang('Feedback1')); $form->addElement('select', 'fprogress1', get_lang('FProgress'), $progress); $form->addElement('textarea', 'feedback2', get_lang('Feedback2')); $form->addElement('select', 'fprogress2', get_lang('FProgress'), $progress); $form->addElement('textarea', 'feedback3', get_lang('Feedback3')); $form->addElement('select', 'fprogress3', get_lang('FProgress'), $progress); $form->addElement('checkbox', 'initstartdate', null, get_lang('StartDate'), array('id' => 'start_date_toggle')); $style = "display:block"; $row['initstartdate'] = 1; if ($row['startdate_assig'] == '0000-00-00 00:00:00') { $style = "display:none"; $row['initstartdate'] = null; } $form->addElement('html', '<div id="start_date" style="' . $style . '">'); $form->addElement('datepicker', 'startdate_assig'); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'initenddate', null, get_lang('EndDate'), array('id' => 'end_date_toggle')); $style = "display:block"; $row['initenddate'] = 1; if ($row['enddate_assig'] == '0000-00-00 00:00:00') { $style = "display:none"; $row['initenddate'] = null; } $form->addElement('html', '<div id="end_date" style="' . $style . '">'); $form->addElement('datepicker', 'enddate_assig'); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'delayedsubmit', null, get_lang('AllowLaterSends')); $form->addElement('text', 'max_text', get_lang('NMaxWords')); $form->addElement('text', 'max_version', get_lang('NMaxVersion')); $form->addElement('checkbox', 'assignment', null, get_lang('CreateAssignmentPage')); $form->addElement('html', '</div>'); } $form->addElement('hidden', 'page_id'); $form->addElement('hidden', 'reflink'); // $form->addElement('hidden', 'assignment'); $form->addElement('hidden', 'version'); $form->addElement('hidden', 'wpost_id', api_get_unique_id()); }
/** * Creates the form to create / edit an exercise * @param FormValidator $form the formvalidator instance (by reference) * @param string */ public function createForm($form, $type = 'full') { if (empty($type)) { $type = 'full'; } // form title if (!empty($_GET['exerciseId'])) { $form_title = get_lang('ModifyExercise'); } else { $form_title = get_lang('NewEx'); } $form->addElement('header', $form_title); // title $form->addElement('text', 'exerciseTitle', get_lang('ExerciseName'), array('class' => 'span6', 'id' => 'exercise_title')); $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150'); if (is_array($type)) { $editor_config = array_merge($editor_config, $type); } $form->add_html_editor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config); $form->addElement('advanced_settings', '<a href="javascript://" onclick=" return advanced_parameters()"> <span id="img_plus_and_minus"> <div style="vertical-align:top;" > ' . Display::return_icon('div_show.gif') . ' ' . addslashes(get_lang('AdvancedParameters')) . '</div> </span> </a>'); $form->addElement('html', '<div id="options" style="">'); // Model type $radio = array($form->createElement('radio', 'model_type', null, get_lang('Normal'), EXERCISE_MODEL_TYPE_NORMAL), $form->createElement('radio', 'model_type', null, get_lang('Committee'), EXERCISE_MODEL_TYPE_COMMITTEE)); $form->addGroup($radio, null, get_lang('ModelType'), ''); $modelType = $this->getModelType(); $scoreTypeDisplay = 'display:none'; if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) { $scoreTypeDisplay = null; } $form->addElement('html', '<div id="score_type" style="' . $scoreTypeDisplay . '">'); // QuestionScoreType global $app; $em = $app['orm.em']; $types = $em->getRepository('Entity\\QuestionScore')->findAll(); $options = array('0' => get_lang('SelectAnOption')); foreach ($types as $questionType) { $options[$questionType->getId()] = $questionType->getName(); } $form->addElement('select', 'score_type_model', array(get_lang('QuestionScoreType')), $options, array('id' => 'score_type_model')); $form->addElement('html', '</div>'); if ($type == 'full') { //Can't modify a DirectFeedback question if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) { // feedback type $radios_feedback = array(); $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()')); if (api_get_setting('enable_quiz_scenario') == 'true') { /* Can't convert a question from one feedback to another if there is more than 1 question already added */ if ($this->selectNbrQuestions() == 0) { $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()')); } } $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2')); $form->addGroup($radios_feedback, null, get_lang('FeedbackType'), ''); // question $radios = array($form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), ALL_ON_ONE_PAGE, array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all')), $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), ONE_PER_PAGE, array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one'))); $form->addGroup($radios, null, get_lang('QuestionsPerPage'), ''); $radios_results_disabled = array(); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()')); $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); } else { // if is Directfeedback but has not questions we can allow to modify the question type if ($this->selectNbrQuestions() == 0) { // feedback type $radios_feedback = array(); $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()')); if (api_get_setting('enable_quiz_scenario') == 'true') { $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()')); } $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2')); $form->addGroup($radios_feedback, null, get_lang('FeedbackType')); // Exercise type $radios = array($form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1'), $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2'), $form->createElement('radio', 'exerciseType', null, get_lang('Committee'), '3')); $form->addGroup($radios, null, get_lang('ExerciseType')); $radios_results_disabled = array(); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()')); $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); } else { //Show options freeze $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()')); $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()')); $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); $result_disable_group->freeze(); $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all')); $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one')); $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage'), ''); $type_group->freeze(); //we force the options to the DirectFeedback exercisetype $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT); $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE); } } $option = array(EX_Q_SELECTION_ORDERED => get_lang('OrderedByUser'), EX_Q_SELECTION_RANDOM => get_lang('Random'), 'per_categories' => '--------' . get_lang('UsingCategories') . '----------', EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED => get_lang('OrderedCategoriesAlphabeticallyWithQuestionsOrdered'), EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED => get_lang('RandomCategoriesWithQuestionsOrdered'), EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_RANDOM => get_lang('OrderedCategoriesAlphabeticallyWithRandomQuestions'), EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM => get_lang('RandomCategoriesWithRandomQuestions'), EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED => get_lang('OrderedCategoriesByParentWithQuestionsOrdered'), EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM => get_lang('OrderedCategoriesByParentWithQuestionsRandom')); $form->addElement('select', 'question_selection_type', array(get_lang('QuestionSelection')), $option, array('id' => 'questionSelection', 'onclick' => 'checkQuestionSelection()')); $displayMatrix = 'none'; $displayRandom = 'none'; $selectionType = $this->getQuestionSelectionType(); switch ($selectionType) { case EX_Q_SELECTION_RANDOM: $displayRandom = 'block'; break; case $selectionType >= EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED: $displayMatrix = 'block'; break; } $form->addElement('html', '<div id="hidden_random" style="display:' . $displayRandom . '">'); // Number of random question. $max = $this->id > 0 ? $this->selectNbrQuestions() : 10; $option = range(0, $max); $option[0] = get_lang('No'); $option[-1] = get_lang('AllQuestionsShort'); $form->addElement('select', 'randomQuestions', array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id' => 'randomQuestions')); $form->addElement('html', '</div>'); $form->addElement('html', '<div id="hidden_matrix" style="display:' . $displayMatrix . '">'); // Category selection. $cat = new Testcategory(); $cat_form = $cat->returnCategoryForm($this); $form->addElement('label', null, $cat_form); $form->addElement('html', '</div>'); // Category name. $radio_display_cat_name = array($form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'), $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0')); $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), ''); // Random answers. $radios_random_answers = array($form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'), $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0')); $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), ''); // Hide question title. $group = array($form->createElement('radio', 'hide_question_title', null, get_lang('Yes'), '1'), $form->createElement('radio', 'hide_question_title', null, get_lang('No'), '0')); $form->addGroup($group, null, get_lang('HideQuestionTitle'), ''); // Attempts. $attempt_option = range(0, 10); $attempt_option[0] = get_lang('Infinite'); $form->addElement('select', 'exerciseAttempts', get_lang('ExerciseAttempts'), $attempt_option, array('id' => 'exerciseAttempts')); // Exercise time limit. $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()')); // Start time. if ($this->start_time != '0000-00-00 00:00:00') { $form->addElement('html', '<div id="start_date_div" style="display:block;">'); } else { $form->addElement('html', '<div id="start_date_div" style="display:none;">'); } $form->addElement('datepicker', 'start_time', '', array('form_name' => 'exercise_admin'), 5); $form->addElement('html', '</div>'); // End time. $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()')); if ($this->end_time != '0000-00-00 00:00:00') { $form->addElement('html', '<div id="end_date_div" style="display:block;">'); } else { $form->addElement('html', '<div id="end_date_div" style="display:none;">'); } $form->addElement('datepicker', 'end_time', '', array('form_name' => 'exercise_admin'), 5); $form->addElement('html', '</div>'); // Propagate negative values. $display = 'block'; $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults')); $form->addElement('html', '<div class="clear"> </div>'); $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers')); $form->addElement('html', '<div id="divtimecontrol" style="display:' . $display . ';">'); // Exercise timer. $form->addElement('checkbox', 'enabletimercontrol', null, get_lang('EnableTimerControl'), array('onclick' => 'option_time_expired()', 'id' => 'enabletimercontrol', 'onload' => 'check_load_time()')); $expired_date = (int) $this->selectExpiredTime(); if ($expired_date != '0') { $form->addElement('html', '<div id="timercontrol" style="display:block;">'); } else { $form->addElement('html', '<div id="timercontrol" style="display:none;">'); } $form->addElement('text', 'enabletimercontroltotalminutes', get_lang('ExerciseTotalDurationInMinutes'), array('style' => 'width : 35px', 'id' => 'enabletimercontroltotalminutes')); $form->addElement('html', '</div>'); // Pass percentage. $form->addElement('text', 'pass_percentage', array(get_lang('PassPercentage'), null, '%'), array('id' => 'pass_percentage')); $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric'); $url = api_get_path(WEB_AJAX_PATH) . 'exercise.ajax.php?1=1'; $js = '<script> function check() { var counter = 0; $("#global_category_id option:selected").each(function() { var id = $(this).val(); var name = $(this).text(); if (id != "" ) { $.ajax({ async: false, url: "' . $url . '&a=exercise_category_exists&type=global", data: "id="+id, success: function(return_value) { if (return_value == 0 ) { alert("' . addslashes(get_lang('CategoryDoesNotExists')) . '"); // Deleting select option tag $("#global_category_id").find("option").remove(); $(".holder li").each(function () { if ($(this).attr("rel") == id) { $(this).remove(); } }); } }, }); } counter++; }); } $(function() { $("#global_category_id").fcbkcomplete({ json_url: "' . $url . '&a=search_category_parent&type=global&", maxitems: 1 , addontab: false, input_min_size: 1, cache: false, complete_text:"' . get_lang('StartToType') . '", firstselected: false, onselect: check, filter_selected: true, newel: true }); }); </script>'; $form->addElement('html', $js); $categoryJS = null; $globalCategoryId = $this->getGlobalCategoryId(); if (!empty($globalCategoryId)) { $cat = new Testcategory($globalCategoryId); $trigger = '$("#global_category_id").trigger("addItem",[{ "title": "' . $cat->title . '", "value": "' . $globalCategoryId . '"}]);'; $categoryJS .= '<script>$(function() { ' . $trigger . ' });</script>'; } $form->addElement('html', $categoryJS); // Global category id. $form->addElement('select', 'global_category_id', array(get_lang('GlobalCategory')), array(), array('id' => 'global_category_id')); // Text when ending an exam $form->add_html_editor('text_when_finished', get_lang('TextWhenFinished'), false, false, $editor_config); // Exam end button. $group = array($form->createElement('radio', 'end_button', null, get_lang('ExerciseEndButtonCourseHome'), '0'), $form->createElement('radio', 'end_button', null, get_lang('ExerciseEndButtonExerciseHome'), '1'), $form->createElement('radio', 'end_button', null, get_lang('ExerciseEndButtonDisconnect'), '2')); $form->addGroup($group, null, get_lang('ExerciseEndButton')); $form->addElement('html', '<div class="clear"> </div>'); $defaults = array(); if (api_get_setting('search_enabled') === 'true') { require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument')); $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage')); $specific_fields = get_specific_field_list(); foreach ($specific_fields as $specific_field) { $form->addElement('text', $specific_field['code'], $specific_field['name']); $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\'' . TOOL_QUIZ . '\''); $values = get_specific_field_values_list($filter, array('value')); if (!empty($values)) { $arr_str_values = array(); foreach ($values as $value) { $arr_str_values[] = $value['value']; } $defaults[$specific_field['code']] = implode(', ', $arr_str_values); } } } if ($this->emailAlert) { // Text when ending an exam $form->add_html_editor('email_notification_template', array(get_lang('EmailNotificationTemplate'), get_lang('EmailNotificationTemplateDescription')), null, false, $editor_config); } // End advanced setting. $form->addElement('html', '</div>'); $form->addElement('html', '</div>'); } // Category selection. $cat = new Testcategory(); $cat_form = $cat->returnCategoryForm($this); $form->addElement('html', $cat_form); // submit $text = isset($_GET['exerciseId']) ? get_lang('ModifyExercise') : get_lang('ProcedToQuestions'); $form->addElement('style_submit_button', 'submitExercise', $text, 'class="save"'); $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required'); if ($type == 'full') { // rules $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric'); $form->addRule('start_time', get_lang('InvalidDate'), 'date'); $form->addRule('end_time', get_lang('InvalidDate'), 'date'); } // defaults if ($type == 'full') { if ($this->id > 0) { if ($this->random > $this->selectNbrQuestions()) { $defaults['randomQuestions'] = $this->selectNbrQuestions(); } else { $defaults['randomQuestions'] = $this->random; } $defaults['randomAnswers'] = $this->selectRandomAnswers(); $defaults['exerciseType'] = $this->selectType(); $defaults['exerciseTitle'] = $this->selectTitle(); $defaults['exerciseDescription'] = $this->selectDescription(); $defaults['exerciseAttempts'] = $this->selectAttempts(); $defaults['exerciseFeedbackType'] = $this->selectFeedbackType(); $defaults['results_disabled'] = $this->selectResultsDisabled(); $defaults['propagate_neg'] = $this->selectPropagateNeg(); $defaults['review_answers'] = $this->review_answers; $defaults['randomByCat'] = $this->selectRandomByCat(); $defaults['text_when_finished'] = $this->selectTextWhenFinished(); $defaults['display_category_name'] = $this->selectDisplayCategoryName(); $defaults['pass_percentage'] = $this->selectPassPercentage(); $defaults['end_button'] = $this->selectEndButton(); $defaults['email_notification_template'] = $this->selectEmailNotificationTemplate(); $defaults['model_type'] = $this->getModelType(); $defaults['question_selection_type'] = $this->getQuestionSelectionType(); $defaults['score_type_model'] = $this->getScoreTypeModel(); //$defaults['global_category_id'] = $this->getScoreTypeModel(); $defaults['hide_question_title'] = $this->getHideQuestionTitle(); if ($this->start_time != '0000-00-00 00:00:00') { $defaults['activate_start_date_check'] = 1; } if ($this->end_time != '0000-00-00 00:00:00') { $defaults['activate_end_date_check'] = 1; } $defaults['start_time'] = $this->start_time != '0000-00-00 00:00:00' ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00'); $defaults['end_time'] = $this->end_time != '0000-00-00 00:00:00' ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time() + 84600); //Get expired time if ($this->expired_time != '0') { $defaults['enabletimercontrol'] = 1; $defaults['enabletimercontroltotalminutes'] = $this->expired_time; } else { $defaults['enabletimercontroltotalminutes'] = 0; } } else { $defaults['model_type'] = 1; $defaults['exerciseType'] = 2; $defaults['exerciseAttempts'] = 0; $defaults['randomQuestions'] = 0; $defaults['randomAnswers'] = 0; $defaults['exerciseDescription'] = ''; $defaults['exerciseFeedbackType'] = 0; $defaults['results_disabled'] = 0; $defaults['randomByCat'] = 0; // $defaults['text_when_finished'] = ""; // $defaults['start_time'] = date('Y-m-d 12:00:00'); $defaults['display_category_name'] = 1; // $defaults['end_time'] = date('Y-m-d 12:00:00', time() + 84600); $defaults['pass_percentage'] = ''; $defaults['end_button'] = $this->selectEndButton(); $defaults['question_selection_type'] = 1; $defaults['hide_question_title'] = 0; } } else { $defaults['exerciseTitle'] = $this->selectTitle(); $defaults['exerciseDescription'] = $this->selectDescription(); } if (api_get_setting('search_enabled') === 'true') { $defaults['index_document'] = 'checked="checked"'; } $form->setDefaults($defaults); }
/** * @param FormValidator $form * @param array $defaults * @return FormValidator */ function getFormWork($form, $defaults = array()) { if (!empty($defaults)) { if (isset($defaults['submit'])) { unset($defaults['submit']); } } // Create the form that asks for the directory name $form->addElement('text', 'new_dir', get_lang('AssignmentName')); $form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required'); $form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar()); $form->addElement( 'advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();"> <span id="plus">'. Display::return_icon( 'div_show.gif', get_lang('AdvancedParameters'), array('style' => 'vertical-align:center') ). ' '.get_lang('AdvancedParameters'). '</span></a>' ); if (!empty($defaults) && (isset($defaults['enableEndDate']) || isset($defaults['enableExpiryDate']))) { $form->addElement('html', '<div id="options" style="display: block;">'); } else { $form->addElement('html', '<div id="options" style="display: none;">'); } // QualificationOfAssignment $form->addElement('text', 'qualification', get_lang('QualificationNumeric')); if ((api_get_session_id() != 0 && Gradebook::is_active()) || api_get_session_id() == 0) { $form->addElement( 'checkbox', 'make_calification', null, get_lang('MakeQualifiable'), array( 'id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked) { document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}" ) ); } else { // QualificationOfAssignment $form->addElement('hidden', 'make_calification', false); } if (!empty($defaults) && isset($defaults['category_id'])) { $form->addElement('html', '<div id=\'option1\' style="display:block">'); } else { $form->addElement('html', '<div id=\'option1\' style="display:none">'); } // Loading Gradebook select load_gradebook_select_in_tool($form); $form->addElement('text', 'weight', get_lang('WeightInTheGradebook')); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'enableExpiryDate', null, get_lang('EnableExpiryDate'), 'id="expiry_date"'); if (isset($defaults['enableExpiryDate']) && $defaults['enableExpiryDate']) { $form->addElement('html', '<div id="option2" style="display: block;">'); } else { $form->addElement('html', '<div id="option2" style="display: none;">'); } $currentDate = substr(api_get_local_time(), 0, 10); if (!isset($defaults['expires_on'])) { $date = substr($currentDate, 0, 10); $defaults['expires_on'] = $date.' 23:59'; } if (!isset($defaults['ends_on'])) { $date = substr($currentDate, 0, 10); $defaults['ends_on'] = $date.' 23:59'; } $form->addElement('date_time_picker', 'expires_on', get_lang('ExpiresAt')); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'id="end_date"'); if (isset($defaults['enableEndDate']) && $defaults['enableEndDate']) { $form->addElement('html', '<div id="option3" style="display: block;">'); } else { $form->addElement('html', '<div id="option3" style="display: none;">'); } $form->addElement('date_time_picker', 'ends_on', get_lang('EndsAt')); $form->addElement('html', '</div>'); $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar')); $form->addElement('select', 'allow_text_assignment', get_lang('DocumentType'), getUploadDocumentType()); $form->addElement('html', '</div>'); if (isset($defaults['enableExpiryDate']) && isset($defaults['enableEndDate'])) { $form->addRule(array('expires_on', 'ends_on'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); } if (!empty($defaults)) { $form->setDefaults($defaults); } return $form; }
/** * Returns an HTML form (generated by FormValidator) of the plugin settings * @return string FormValidator-generated form */ public function get_settings_form() { $result = new FormValidator($this->get_name()); $defaults = array(); foreach ($this->fields as $name => $type) { $value = $this->get($name); $defaults[$name] = $value; $type = isset($type) ? $type : 'text'; $help = null; if ($this->get_lang_plugin_exists($name . '_help')) { $help = $this->get_lang($name . '_help'); } switch ($type) { case 'html': $result->addElement('html', $this->get_lang($name)); break; case 'wysiwyg': $result->add_html_editor($name, $this->get_lang($name)); break; case 'text': $result->addElement($type, $name, array($this->get_lang($name), $help)); break; case 'boolean': $group = array(); $group[] = $result->createElement('radio', $name, '', get_lang('Yes'), 'true'); $group[] = $result->createElement('radio', $name, '', get_lang('No'), 'false'); $result->addGroup($group, null, array($this->get_lang($name), $help)); break; } } $result->setDefaults($defaults); $result->addElement('style_submit_button', 'submit_button', $this->get_lang('Save')); return $result; }
/** * Display the list of student publications, taking into account the user status * * @param $origin - typically empty or 'learnpath' */ function display_student_publications_list($id, $my_folder_data, $work_parents, $origin, $add_in_where_query = '', $userList = array()) { global $gradebook; $_course = api_get_course_info(); // Database table names $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $user_table = Database::get_main_table(TABLE_MAIN_USER); $work_assigment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $course_id = api_get_course_int_id(); $course_info = api_get_course_info(api_get_course_id()); $sort_params = array(); if (isset($_GET['column'])) { $sort_params[] = 'column=' . Security::remove_XSS($_GET['column']); } if (isset($_GET['page_nr'])) { $sort_params[] = 'page_nr=' . Security::remove_XSS($_GET['page_nr']); } if (isset($_GET['per_page'])) { $sort_params[] = 'per_page=' . Security::remove_XSS($_GET['per_page']); } if (isset($_GET['direction'])) { $sort_params[] = 'direction=' . Security::remove_XSS($_GET['direction']); } $sort_params = implode('&', $sort_params); $my_params = $sort_params; $origin = Security::remove_XSS($origin); $qualification_exists = false; if (!empty($my_folder_data['qualification']) && intval($my_folder_data['qualification']) > 0) { $qualification_exists = true; } $edit_dir = isset($_GET['edit_dir']) ? intval($_GET['edit_dir']) : ''; $table_header = array(); $table_has_actions_column = false; $table_header[] = array(get_lang('Type'), false, 'style="width:40px"'); $table_header[] = array(get_lang('Title'), true); if (!empty($id)) { $table_header[] = array(get_lang('FirstName'), true); $table_header[] = array(get_lang('LastName'), true); } $table_header[] = array(get_lang('HandOutDateLimit'), true, 'style="width:200px"'); if ($is_allowed_to_edit) { $table_header[] = array(get_lang('HandedOut'), false); $table_header[] = array(get_lang('Actions'), false, 'style="width:90px"', array('class' => 'td_actions')); $table_has_actions_column = true; if ($qualification_exists) { $table_header[] = array(get_lang('Qualification'), true); } } else { // All users if ($course_info['show_score'] == 0) { $table_header[] = array(get_lang('Others'), false); } } $table_data = array(); // List of all folders if no id was provided $group_id = api_get_group_id(); if (is_array($work_parents)) { foreach ($work_parents as $work_parent) { $sql_select_directory = "SELECT\n\t\t\t title,\n\t\t\t url,\n\t\t\t prop.insert_date,\n\t\t\t prop.lastedit_date,\n\t\t\t work.id, author,\n\t\t\t has_properties,\n\t\t\t view_properties,\n\t\t\t description,\n\t\t\t qualification,\n\t\t\t weight,\n\t\t\t allow_text_assignment\n FROM " . $iprop_table . " prop INNER JOIN " . $work_table . " work ON (prop.ref=work.id AND prop.c_id = {$course_id})\n WHERE active IN (0, 1) AND "; if (!empty($group_id)) { $sql_select_directory .= " work.post_group_id = '" . $group_id . "' "; // set to select only messages posted by the user's group } else { $sql_select_directory .= " work.post_group_id = '0' "; } $sql_select_directory .= " AND " . " work.c_id = {$course_id} AND " . " work.id = " . $work_parent->id . " AND " . " work.filetype = 'folder' AND " . " prop.tool='work' {$condition_session}"; $result = Database::query($sql_select_directory); $row = Database::fetch_array($result, 'ASSOC'); if (!$row) { // the folder belongs to another session continue; } $direc_date = $row['lastedit_date']; //directory's date $author = $row['author']; //directory's author $view_properties = $row['view_properties']; $is_assignment = $row['has_properties']; $id2 = $row['id']; //work id $locked = api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION); // form edit directory if (!empty($row['has_properties'])) { $sql = Database::query('SELECT * FROM ' . $work_assigment . ' WHERE c_id = ' . $course_id . ' AND id = "' . $row['has_properties'] . '" LIMIT 1'); $homework = Database::fetch_array($sql); } // save original value for later $utc_expiry_time = $homework['expires_on']; if ($is_allowed_to_edit && $locked == false) { if (!empty($edit_dir) && $edit_dir == $id2) { $form_folder = new FormValidator('edit_dir', 'post', api_get_self() . '?origin=' . $origin . '&gradebook=' . $gradebook . '&edit_dir=' . $id2); $form_folder->addElement('text', 'dir_name', get_lang('Title')); $form_folder->addElement('hidden', 'work_id', $id2); $form_folder->addRule('dir_name', get_lang('ThisFieldIsRequired'), 'required'); $my_title = !empty($row['title']) ? $row['title'] : basename($row['url']); $defaults = array('dir_name' => Security::remove_XSS($my_title), 'description' => Security::remove_XSS($row['description'])); $form_folder->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'work', 'Width' => '80%', 'Height' => '200')); $there_is_a_end_date = false; $form_folder->addElement('advanced_settings', 'work', get_lang('AdvancedParameters')); $form_folder->addElement('html', '<div id="work_options" style="display: none;">'); if (empty($default)) { $default = api_get_local_time(); } $parts = explode(' ', $default); list($d_year, $d_month, $d_day) = explode('-', $parts[0]); list($d_hour, $d_minute) = explode(':', $parts[1]); $qualification_input[] = $form_folder->createElement('text', 'qualification'); $form_folder->addGroup($qualification_input, 'qualification', get_lang('QualificationNumeric')); if (Gradebook::is_active()) { $link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $id2); $form_folder->addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"'); if (!empty($link_info)) { $form_folder->addElement('html', '<div id=\'option3\' style="display:block">'); } else { $form_folder->addElement('html', '<div id=\'option3\' style="display:none">'); } //Loading gradebook select load_gradebook_select_in_tool($form_folder); $weight_input2[] = $form_folder->createElement('text', 'weight'); $form_folder->addGroup($weight_input2, 'weight', get_lang('WeightInTheGradebook'), 'size="10"'); $form_folder->addElement('html', '</div>'); $defaults['weight[weight]'] = $link_info['weight']; if (!empty($link_info)) { $defaults['category_id'] = $link_info['category_id']; $defaults['make_calification'] = 1; } } else { $defaults['category_id'] = ''; } if ($homework['expires_on'] != '0000-00-00 00:00:00') { $homework['expires_on'] = api_get_local_time($homework['expires_on']); $there_is_a_expire_date = true; $defaults['enableExpiryDate'] = true; $form_folder->addElement('checkbox', 'enableExpiryDate', null, get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"'); $form_folder->addElement('html', '<div id=\'option1\' style="display:block">'); $form_folder->addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt')); $form_folder->addElement('html', '</div>'); } else { $homework['expires_on'] = api_get_local_time(); $expires_date_array = convert_date_to_array(api_get_local_time(), 'expires'); $defaults = array_merge($defaults, $expires_date_array); $there_is_a_expire_date = false; $form_folder->addElement('checkbox', 'enableExpiryDate', null, get_lang('EnableExpiryDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display = \'block\';}else{document.getElementById(\'option1\').style.display = \'none\';}"'); $form_folder->addElement('html', '<div id=\'option1\' style="display:none">'); $form_folder->addGroup(create_group_date_select(), 'expires', get_lang('ExpiresAt')); $form_folder->addElement('html', '</div>'); } if ($homework['ends_on'] != '0000-00-00 00:00:00') { $homework['ends_on'] = api_get_local_time($homework['ends_on']); $there_is_a_end_date = true; $defaults['enableEndDate'] = true; $form_folder->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"'); $form_folder->addElement('html', '<div id=\'option2\' style="display:block">'); $form_folder->addGroup(create_group_date_select(), 'ends', get_lang('EndsAt')); $form_folder->addElement('html', '</div>'); $form_folder->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); } else { $homework['ends_on'] = api_get_local_time(); $expires_date_array = convert_date_to_array(api_get_local_time(), 'ends'); $defaults = array_merge($defaults, $expires_date_array); $there_is_a_end_date = false; $form_folder->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display = \'block\';}else{document.getElementById(\'option2\').style.display = \'none\';}"'); $form_folder->addElement('html', '<div id=\'option2\' style="display:none">'); $form_folder->addGroup(create_group_date_select(), 'ends', get_lang('EndsAt')); $form_folder->addElement('html', '</div>'); $form_folder->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); } if ($there_is_a_expire_date && $there_is_a_end_date) { $form_folder->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate'); } $form_folder->addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments')); $form_folder->addElement('html', '</div>'); $form_folder->addElement('style_submit_button', 'submit', get_lang('ModifyDirectory'), 'class="save"'); if ($there_is_a_end_date) { $end_date_array = convert_date_to_array($homework['ends_on'], 'ends'); $defaults = array_merge($defaults, $end_date_array); } if ($there_is_a_expire_date) { $expires_date_array = convert_date_to_array($homework['expires_on'], 'expires'); $defaults = array_merge($defaults, $expires_date_array); } if (!empty($row['qualification'])) { $defaults = array_merge($defaults, array('qualification[qualification]' => $row['qualification'])); } $defaults['allow_text_assignment'] = $row['allow_text_assignment']; $form_folder->setDefaults($defaults); $display_edit_form = true; if ($form_folder->validate()) { if ($_POST['enableExpiryDate'] == '1') { $there_is_a_expire_date = true; } else { $there_is_a_expire_date = false; } if ($_POST['enableEndDate'] == '1') { $there_is_a_end_date = true; } else { $there_is_a_end_date = false; } $values = $form_folder->exportValues(); $work_id = $values['work_id']; $dir_name = replace_dangerous_char($values['dir_name']); $dir_name = disable_dangerous_file($dir_name); $edit_check = false; $work_data = get_work_data_by_id($work_id); if (!empty($work_data)) { $edit_check = true; } else { $edit_check = true; } if ($edit_check) { $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA); $expires_query = ' SET expires_on = ' . "'" . ($there_is_a_expire_date ? api_get_utc_datetime(get_date_from_group('expires')) : '0000-00-00 00:00:00') . "'"; Database::query('UPDATE ' . $work_assigment . $expires_query . ' WHERE c_id = ' . $course_id . ' AND id = ' . "'" . $row['has_properties'] . "'"); $sql_add_publication = "UPDATE " . $work_table . " SET has_properties = '" . $row['has_properties'] . "', view_properties=1 WHERE c_id = {$course_id} AND id ='" . $row['id'] . "'"; Database::query($sql_add_publication); $ends_query = ' SET ends_on = ' . "'" . ($there_is_a_end_date ? api_get_utc_datetime(get_date_from_group('ends')) : '0000-00-00 00:00:00') . "'"; Database::query('UPDATE ' . $work_assigment . $ends_query . ' WHERE c_id = ' . $course_id . ' AND id = ' . "'" . $row['has_properties'] . "'"); $sql_add_publication = "UPDATE " . $work_table . " SET has_properties = '" . $row['has_properties'] . "', view_properties=1 WHERE c_id = {$course_id} AND id ='" . $row['id'] . "'"; Database::query($sql_add_publication); $qualification_value = isset($_POST['qualification']['qualification']) && !empty($_POST['qualification']['qualification']) ? intval($_POST['qualification']['qualification']) : 0; $enable_qualification = !empty($qualification_value) ? 1 : 0; $sql_add_publication = "UPDATE " . $work_assigment . " SET enable_qualification = '" . $enable_qualification . "' WHERE c_id = {$course_id} AND publication_id ='" . $row['id'] . "'"; Database::query($sql_add_publication); $sql = 'UPDATE ' . $work_table . ' SET allow_text_assignment = ' . "'" . intval($_POST['allow_text_assignment']) . "'" . ' , title = ' . "'" . Database::escape_string($_POST['dir_name']) . "'" . ', description = ' . "'" . Database::escape_string($_POST['description']) . "'" . ', qualification = ' . "'" . Database::escape_string($_POST['qualification']['qualification']) . "'" . ', weight = ' . "'" . Database::escape_string($_POST['weight']['weight']) . "'" . ' WHERE c_id = ' . $course_id . ' AND id = ' . $row['id']; Database::query($sql); require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be/gradebookitem.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be/evaluation.class.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be/abstractlink.class.php'; $link_info = is_resource_in_course_gradebook(api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], api_get_session_id()); $link_id = null; if (!empty($link_info)) { $link_id = $link_info['id']; } if (isset($_POST['make_calification']) && $_POST['make_calification'] == 1 && !empty($_POST['category_id'])) { if (empty($link_id)) { add_resource_to_course_gradebook($_POST['category_id'], api_get_course_id(), LINK_STUDENTPUBLICATION, $row['id'], $_POST['dir_name'], (double) $_POST['weight']['weight'], (double) $_POST['qualification']['qualification'], $_POST['description'], 1, api_get_session_id(), $link_id); } else { update_resource_from_course_gradebook($link_id, api_get_course_id(), $_POST['weight']['weight']); } } else { //Delete everything of the gradebook remove_resource_from_course_gradebook($link_id); } update_dir_name($work_data, $dir_name, $values['dir_name']); $dir = $dir_name; $display_edit_form = false; // gets calendar_id from student_publication_assigment $sql = "SELECT add_to_calendar FROM {$work_assigment} WHERE c_id = {$course_id} AND publication_id ='" . $row['id'] . "'"; $res = Database::query($sql); $calendar_id = Database::fetch_row($res); $dir_name = sprintf(get_lang('HandingOverOfTaskX'), $dir_name); $end_date = $row['insert_date']; if ($_POST['enableExpiryDate'] == '1') { $end_date = Database::escape_string(api_get_utc_datetime(get_date_from_group('expires'))); } // update from agenda if it exists if (!empty($calendar_id[0])) { $sql = "UPDATE " . $TABLEAGENDA . "\n\t\t\t\t\t\t\t\t\t\tSET title='" . $values['dir_name'] . "',\n\t\t\t\t\t\t\t\t\t\t\tcontent = '" . Database::escape_string($_POST['description']) . "',\n\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $end_date . "',\n\t\t\t\t\t\t\t\t\t\t\tend_date = '" . $end_date . "'\n\t\t\t\t\t\t\t\t\t\tWHERE c_id = {$course_id} AND id='" . $calendar_id[0] . "'"; Database::query($sql); } Display::display_confirmation_message(get_lang('FolderEdited')); } else { Display::display_warning_message(get_lang('FileExists')); } } } } $work_data = get_work_data_by_id($work_parent->id); $action = ''; $row = array(); $class = ''; $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); if (api_is_allowed_to_edit()) { $cant_files = get_count_work($work_data['id']); } else { $isSubscribed = userIsSubscribedToWork(api_get_user_id(), $work_data['id'], $course_id); if ($isSubscribed == false) { continue; } $cant_files = get_count_work($work_data['id'], api_get_user_id()); } $text_file = get_lang('FilesUpload'); if ($cant_files == 1) { $text_file = api_strtolower(get_lang('FileUpload')); } $icon = Display::return_icon('work.png', get_lang('Assignment'), array(), ICON_SIZE_SMALL); if (!empty($display_edit_form) && !empty($edit_dir) && $edit_dir == $id2) { $row[] = $icon; $row[] = '<span class="invisible" style="display:none">' . $dir . '</span>' . $form_folder->toHtml(); // form to edit the directory's name } else { $row[] = '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin=' . $origin . '&gradebook=' . $gradebook . '">' . $icon . '</a>'; $add_to_name = ''; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; $link_info = is_resource_in_course_gradebook(api_get_course_id(), 3, $id2, api_get_session_id()); $link_id = $link_info['id']; $count = 0; if ($link_info !== false) { $gradebook_data = get_resource_from_course_gradebook($link_id); $count = $gradebook_data['weight']; } if ($count > 0) { $add_to_name = Display::label(get_lang('IncludedInEvaluation'), 'info'); } else { $add_to_name = ''; } $work_title = !empty($work_data['title']) ? $work_data['title'] : basename($work_data['url']); // Work name if ($cant_files > 0) { $zip = '<a href="downloadfolder.inc.php?id=' . $work_data['id'] . '">' . Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'), ICON_SIZE_SMALL) . '</a>'; } $link = 'work_list.php'; if (api_is_allowed_to_edit()) { $link = 'work_list_all.php'; } $url = $zip . '<a href="' . api_get_path(WEB_CODE_PATH) . 'work/' . $link . '?' . api_get_cidreq() . '&origin=' . $origin . '&gradebook=' . Security::remove_XSS($_GET['gradebook']) . '&id=' . $work_data['id'] . '"' . $class . '>' . $work_title . '</a> ' . $add_to_name . '<br />' . $cant_files . ' ' . $text_file . $dirtext; $row[] = $url; } if ($count_files != 0) { $row[] = ''; } if (!empty($homework)) { // use original utc value saved previously to avoid doubling the utc-to-local conversion ($homework['expires_on'] might have been tainted) $row[] = !empty($utc_expiry_time) && $utc_expiry_time != '0000-00-00 00:00:00' ? api_get_local_time($utc_expiry_time) : '-'; } else { $row[] = '-'; } if (!$is_allowed_to_edit) { if ($course_info['show_score'] == 0) { $url = api_get_path(WEB_CODE_PATH) . 'work/work_list_others.php?' . api_get_cidreq() . '&id=' . $work_parent->id; $row[] = Display::url(Display::return_icon('group.png', get_lang('Others')), $url); } } if ($origin != 'learnpath') { if ($is_allowed_to_edit) { $cant_files_per_user = getUniqueStudentAttempts($work_data['id'], $group_id, $course_id, api_get_session_id(), null, $userList); $row[] = $cant_files_per_user . '/' . count($userList); if (api_resource_is_locked_by_gradebook($id2, LINK_STUDENTPUBLICATION)) { $action .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); $action .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); } else { $action .= '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&origin=' . $origin . '&gradebook=' . $gradebook . '&edit_dir=' . $id2 . '">' . Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL) . '</a>'; $action .= ' <a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin=' . $origin . '&gradebook=' . $gradebook . '&delete_dir=' . $id2 . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('DirDelete') . '" >' . Display::return_icon('delete.png', get_lang('DirDelete'), '', ICON_SIZE_SMALL) . '</a>'; } $row[] = $action; } else { $row[] = ''; } } //$row[] = $direc_date_local; $row[] = $work_data['title']; $table_data[] = $row; } } $sorting_options = array(); $sorting_options['column'] = 1; // Here we change the way how the columns are going to be sorted // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" $column_order = array(); $i = 0; foreach ($table_header as $item) { $column_order[$i] = $i; $i++; } if (empty($my_folder_data)) { $column_order[1] = 5; } else { $column_order[2] = 2; } // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide $column_show = array(); $column_show[] = 1; // type 0 $column_show[] = 1; // title 1 if (!empty($my_folder_data)) { $column_show[] = 1; // 2 $column_show[] = 1; // 3 if ($qualification_exists) { $column_show[] = 1; // 4 } } $column_show[] = 1; //date if ($table_has_actions_column) { $column_show[] = 1; // modify } $column_show[] = 1; //real date in correct format $column_show[] = 0; //real date in correct format $paging_options = array(); if (isset($_GET['curdirpath'])) { $my_params = array('curdirpath' => Security::remove_XSS($_GET['curdirpath'])); } $my_params = array('id' => isset($_GET['id']) ? $_GET['id'] : null); if (isset($_GET['edit_dir'])) { $my_params = array('edit_dir' => intval($_GET['edit_dir'])); } $my_params['origin'] = $origin; Display::display_sortable_config_table('work', $table_header, $table_data, $sorting_options, $paging_options, $my_params, $column_show, $column_order); }
} } if (is_array($editor_config)) { if (!isset($editor_config['ToolbarSet'])) { $editor_config['ToolbarSet'] = $toolbar_set; } if (!isset($editor_config['Width'])) { $editor_config['Width'] = $width; } if (!isset($editor_config['Height'])) { $editor_config['Height'] = $height; } } else { $editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height); } $form->add_html_editor('intro_content', null, null, false, $editor_config); $form->addElement('style_submit_button', 'intro_cmdUpdate', get_lang('SaveIntroText'), 'class="save"'); /* INTRODUCTION MICRO MODULE - COMMANDS SECTION (IF ALLOWED) */ $course_id = api_get_course_int_id(); if ($intro_editAllowed) { /* Replace command */ if ($intro_cmdUpdate) { if ($form->validate()) { $form_values = $form->exportValues(); $intro_content = Security::remove_XSS(stripslashes(api_html_entity_decode($form_values['intro_content'])), COURSEMANAGERLOWSECURITY); if (!empty($intro_content)) { $sql = "REPLACE {$TBL_INTRODUCTION}\n SET\n c_id = {$course_id}, id='" . Database::escape_string($moduleId) . "',\n intro_text='" . Database::escape_string($intro_content) . "',\n session_id='" . intval($session_id) . "'\n "; Database::query($sql); $introduction_section .= Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false); } else { // got to the delete command
/** * Code */ // Language file that needs to be included $language_file = 'help'; //require_once '../inc/global.inc.php'; $help_name = isset($_GET['open']) ? Security::remove_XSS($_GET['open']) : null; Display::display_header(get_lang('Faq')); if (api_is_platform_admin()) { echo ' <a href="faq.php?edit=true"><img src="' . api_get_path(WEB_IMG_PATH) . 'edit.png" /></a>'; } echo Display::page_header(get_lang('Faq')); $faq_file = 'faq.html'; if (!empty($_GET['edit']) && $_GET['edit'] == 'true' && api_is_platform_admin()) { $form = new FormValidator('set_faq', 'post', 'faq.php?edit=true'); $form->add_html_editor('faq_content', null, false, false, array('ToolbarSet' => 'FAQ', 'Width' => '100%', 'Height' => '300')); $form->addElement('style_submit_button', 'faq_submit', get_lang('Ok')); $faq_content = @(string) file_get_contents(api_get_path(SYS_PATH) . 'home/faq.html'); $faq_content = api_to_system_encoding($faq_content, api_detect_encoding(strip_tags($faq_content))); $form->setDefaults(array('faq_content' => $faq_content)); if ($form->validate()) { $content = $form->getSubmitValue('faq_content'); $fpath = api_get_path(SYS_PATH) . 'home/' . $faq_file; if (is_file($fpath) && is_writeable($fpath)) { $fp = fopen(api_get_path(SYS_PATH) . 'home/' . $faq_file, 'w'); fwrite($fp, $content); fclose($fp); } else { Display::display_warning_message(get_lang('WarningFaqFileNonWriteable')); } echo $content;
$form_title = get_lang('EditNews'); } $form = new FormValidator('system_announcement'); $form->addElement('header', '', $form_title); $form->add_textfield('title', get_lang('Title'), true, array('class' => 'span4')); $language_list = api_get_languages(); $language_list_with_keys = array(); $language_list_with_keys['all'] = get_lang('All'); for ($i = 0; $i < count($language_list['name']); $i++) { $language_list_with_keys[$language_list['folder'][$i]] = $language_list['name'][$i]; } $form->addElement('select', 'lang', get_lang('Language'), $language_list_with_keys); if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { $form->addElement('textarea', 'content', get_lang('Content')); } else { $form->add_html_editor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'PortalNews', 'Width' => '100%', 'Height' => '300')); } $form->addDateRangePicker('range', get_lang('StartTimeWindow'), true, array('id' => 'date_range')); $group = array(); $group[] = $form->createElement('checkbox', 'visible_teacher', null, get_lang('Teacher')); $group[] = $form->createElement('checkbox', 'visible_student', null, get_lang('Student')); $group[] = $form->createElement('checkbox', 'visible_guest', null, get_lang('Guest')); $form->addGroup($group, null, get_lang('Visible'), ''); $form->addElement('hidden', 'id'); $group_list = GroupPortalManager::get_groups_list(); $group_list[0] = get_lang('All'); $form->addElement('select', 'group', get_lang('AnnouncementForGroup'), $group_list); $values['group'] = isset($values['group']) ? $values['group'] : '0'; $form->addElement('checkbox', 'send_mail', null, get_lang('SendMail')); if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') { $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
$html .= '<option value="' . $english_name . '">' . $value . '</option>'; } } $html .= '</select></td></tr>'; $form->addElement('html', $html); } if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { //TODO: review these lines // Print WCAG-specific HTML editor $html = '<tr><td>'; $html .= WCAG_Rendering::create_xhtml($open); $html .= '</td></tr>'; $form->addElement('html', $html); } else { $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open); $form->add_html_editor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400')); } $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"'); $form->setDefaults($default); $form->display(); break; default: // When no action applies, default page to update campus homepage ?> <table border="0" cellpadding="5" cellspacing="0" width="100%"> <tr> <td width="70%" valign="top"> <div class="actions"> <a href="<?php echo api_get_self(); ?>
function manage_form($default, $select_from_user_list = null, $sent_to = null) { $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null; $param_f = isset($_GET['f']) ? Security::remove_XSS($_GET['f']) : ''; $form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data')); if (empty($group_id)) { if (isset($select_from_user_list)) { $form->add_textfield('id_text_name', get_lang('SendMessageTo'), true, array('class' => 'span4', 'id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off')); $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" > </div>'); $form->addElement('hidden', 'user_list', 0, array('id' => 'user_list')); } else { if (!empty($sent_to)) { $form->addElement('html', $sent_to); } if (empty($default['users'])) { //fb select $form->addElement('select', 'users', get_lang('SendMessageTo'), array(), array('id' => 'users')); } else { $form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user')); } } } else { $usergroup = new UserGroup(); $group_info = $usergroup->get($group_id); $form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name'])); $form->addElement('hidden', 'group_id', $group_id); $form->addElement('hidden', 'parent_id', $message_id); } $form->add_textfield('title', get_lang('Subject'), true, array('class' => 'span4')); $form->add_html_editor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '95%', 'Height' => '250')); if (isset($_GET['re_id'])) { $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']); $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title']; $form->addElement('hidden', 're_id', intval($_GET['re_id'])); $form->addElement('hidden', 'save_form', 'save_form'); //adding reply mail $user_reply_info = UserManager::get_user_info_by_id($message_reply_info['user_sender_id']); $default['content'] = '<br />' . sprintf(get_lang('XWroteY'), api_get_person_name($user_reply_info['firstname'], $user_reply_info['lastname']), Security::filter_terms($message_reply_info['content'])); } if (empty($group_id)) { $form->addElement('advanced_settings', get_lang('FilesAttachment') . '<span id="filepaths"> <div id="filepath_1"> <input type="file" name="attach_1"/><br /> ' . get_lang('Description') . ' <input type="text" name="legend[]" /><br /><br /> </div> </span>'); $form->addElement('advanced_settings', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span> (' . sprintf(get_lang('MaximunFileSizeX'), Text::format_file_size(api_get_setting('message_max_upload_filesize'))) . ')'); } $form->addElement('style_submit_button', 'compose', api_xml_http_response_encode(get_lang('SendMessage')), 'class="save"'); $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>'); if (!empty($group_id) && !empty($message_id)) { $message_info = MessageManager::get_message_by_id($message_id); $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title']; } $form->setDefaults($default); $html = ''; if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $user_list = $default['users']; $file_comments = $_POST['legend']; $title = $default['title']; $content = $default['content']; $group_id = isset($default['group_id']) ? $default['group_id'] : null; $parent_id = $default['parent_id']; if (is_array($user_list) && count($user_list) > 0) { //all is well, send the message foreach ($user_list as $user) { $res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id, null, null, api_get_user_id()); if ($res) { if (is_string($res)) { $html .= Display::return_message($res, 'error'); } else { $user_info = api_get_user_info($user); $html .= Display::return_message(get_lang('MessageSentTo') . " <b>" . $user_info['complete_name'] . "</b>", 'confirmation', false); } } } } else { Display::display_error_message('ErrorSendingMessage'); } } Security::clear_token(); } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $html .= $form->return_form(); } return $html; }
/** * */ function show_form_send_ticket() { global $types, $plugin; echo '<div class="divTicket">'; //Category List $categoryList = array(); foreach ($types as $type) { $categoryList[$type['category_id']] = $type['name'] . ": " . $type['description']; } //End Category List //Status List $statusList = array(); $statusAttributes = array( 'style' => 'display: none;', 'id' => 'status_id', 'for' => 'status_id' ); $statusList[NEWTCK] = $plugin->get_lang('StatusNew'); if (api_is_platform_admin()) { $statusAttributes = array( 'id' => 'status_id', 'for' => 'status_id', 'style' => 'width: 562px;' ); $statusList[PENDING] = $plugin->get_lang('StatusPending'); $statusList[UNCONFIRMED] = $plugin->get_lang('StatusUnconfirmed'); $statusList[CLOSE] = $plugin->get_lang('StatusClose'); $statusList[REENVIADO] = $plugin->get_lang('StatusForwarded'); } //End Status List //Source List $sourceList = array(); $sourceAttributes = array( 'style' => 'display: none;', 'id' => 'source_id', 'for' => 'source_id' ); $sourceList[SRC_PLATFORM] = $plugin->get_lang('SrcPlatform'); if (api_is_platform_admin()) { $sourceAttributes = array( 'id' => 'source_id', 'for' => 'source_id', 'style' => 'width: 562px;' ); $sourceList[SRC_EMAIL] = $plugin->get_lang('SrcEmail'); $sourceList[SRC_PHONE] = $plugin->get_lang('SrcPhone'); $sourceList[SRC_PRESC] = $plugin->get_lang('SrcPresential'); } //End Source List //Priority List $priorityList = array(); $priorityList[NORMAL] = $plugin->get_lang('PriorityNormal'); $priorityList[HIGH] = $plugin->get_lang('PriorityHigh'); $priorityList[LOW] = $plugin->get_lang('PriorityLow'); //End Priority List $form = new FormValidator('send_ticket', 'POST', api_get_self(), "", array( 'enctype' => 'multipart/form-data', 'onsubmit' => 'return validate()', 'class' => 'span8 offset1 form-horizontal' ) ); $form->addElement( 'hidden', 'user_id_request', '', array( 'id' => 'user_id_request' ) ); $form->addElement( 'hidden', 'project_id', '', array( 'id' => 'project_id' ) ); $form->addElement( 'hidden', 'other_area', '', array( 'id' => 'other_area' ) ); $form->addElement( 'hidden', 'email', '', array( 'id' => 'email' ) ); $form->addElement( 'select', 'category_id', get_lang('Category'), $categoryList, array( 'onchange' => 'changeType()', 'id' => 'category_id', 'for' => 'category_id', 'style' => 'width: 562px;' ) ); $form->addElement( 'html', Display::div( '', array( 'id' => 'user_request' ) ) ); $form->addElement( 'select', 'status_id', get_lang('Status'), $statusList, $statusAttributes ); $form->addElement( 'select', 'source_id', $plugin->get_lang('Source'), $sourceList, $sourceAttributes ); $form->addElement( 'text', 'subject', get_lang('Subject'), array( 'id' => 'subject', 'style' => 'width: 550px;' ) ); $form->addElement( 'text', 'personal_email', $plugin->get_lang('PersonalEmail'), array( 'id' => 'personal_email', 'style' => 'width: 550px;' ) ); $form->add_html_editor( 'content', get_lang('Message'), false, false, array( 'ToolbarSet' => 'Profile', 'Width' => '600', 'Height' => '250' ) ); $form->addElement( 'text', 'phone', get_lang('Phone') . ' (' . $plugin->get_lang('Optional') . ')', array( 'id' => 'phone' ) ); $form->addElement( 'select', 'priority_id', $plugin->get_lang('Priority'), $priorityList, array( 'id' => 'priority_id', 'for' => 'priority_id' ) ); $form->addElement('html', '<span id="filepaths">'); $form->addElement('html', '<div id="filepath_1">'); $form->addElement('file', 'attach_1', get_lang('FilesAttachment')); $form->addElement('html', '</div>'); $form->addElement('html', '</span>'); $form->addElement('html', '<div class="controls">'); $form->addElement('html', '<span id="link-more-attach" >'); $form->addElement('html', '<span class="label label-info" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</span>'); $form->addElement('html', '</span>'); $form->addElement('html', '(' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))) . ')'); $form->addElement('html', '<br/>'); $form->addElement( 'button', 'compose', get_lang('SendMessage'), array( 'class' => 'save', 'id' => 'btnsubmit' ) ); $form->display(); }
/** * @param FormValidator $form * @param array $extraData * @param string $form_name * @param bool $admin_permissions * @param int $user_id * @param array $extra * @param int $itemId * * @return array */ public function set_extra_fields_in_form($form, $extraData, $form_name, $admin_permissions = false, $user_id = null, $extra = array(), $itemId = null) { $user_id = intval($user_id); $type = $this->type; // User extra fields if ($type == 'user') { $extra = UserManager::get_extra_fields(0, 50, 5, 'ASC', true, null, true); } $jquery_ready_content = null; if (!empty($extra)) { foreach ($extra as $field_details) { // Getting default value id if is set $defaultValueId = null; if (isset($field_details['options']) && !empty($field_details['options'])) { $valueToFind = null; if (isset($field_details['field_default_value'])) { $valueToFind = $field_details['field_default_value']; } // If a value is found we override the default value if (isset($extraData['extra_' . $field_details['field_variable']])) { $valueToFind = $extraData['extra_' . $field_details['field_variable']]; } foreach ($field_details['options'] as $option) { if ($option['option_value'] == $valueToFind) { $defaultValueId = $option['id']; } } } if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { continue; } } switch ($field_details['field_type']) { case ExtraField::FIELD_TYPE_TEXT: $form->addElement('text', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('class' => 'span4')); $form->applyFilter('extra_' . $field_details['field_variable'], 'stripslashes'); $form->applyFilter('extra_' . $field_details['field_variable'], 'trim'); if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_TEXTAREA: $form->add_html_editor('extra_' . $field_details['field_variable'], $field_details['field_display_text'], false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130')); $form->applyFilter('extra_' . $field_details['field_variable'], 'stripslashes'); $form->applyFilter('extra_' . $field_details['field_variable'], 'trim'); if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_RADIO: $group = array(); if (isset($field_details['options']) && !empty($field_details['options'])) { foreach ($field_details['options'] as $option_details) { $options[$option_details['option_value']] = $option_details['option_display_text']; $group[] = $form->createElement('radio', 'extra_' . $field_details['field_variable'], $option_details['option_value'], $option_details['option_display_text'] . '<br />', $option_details['option_value']); } } $form->addGroup($group, 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], ''); if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_CHECKBOX: $group = array(); if (isset($field_details['options']) && !empty($field_details['options'])) { foreach ($field_details['options'] as $option_details) { $options[$option_details['option_value']] = $option_details['option_display_text']; $group[] = $form->createElement('checkbox', 'extra_' . $field_details['field_variable'], $option_details['option_value'], $option_details['option_display_text'] . '<br />', $option_details['option_value']); } } else { // We assume that is a switch on/off with 1 and 0 as values $group[] = $form->createElement('checkbox', 'extra_' . $field_details['field_variable'], null, 'Yes <br />', null); } $form->addGroup($group, 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], ''); if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_SELECT: $get_lang_variables = false; if (in_array($field_details['field_variable'], array('mail_notify_message', 'mail_notify_invitation', 'mail_notify_group_message'))) { $get_lang_variables = true; } // Get extra field workflow $userInfo = api_get_user_info(); $addOptions = array(); $optionsExists = Database::getManager()->getRepository('ChamiloCoreBundle:ExtraFieldOptionRelFieldOption')->findOneBy(array('fieldId' => $field_details['id'])); if ($optionsExists) { if (isset($userInfo['status']) && !empty($userInfo['status'])) { $fieldWorkFlow = Database::getManager()->getRepository('ChamiloCoreBundle:ExtraFieldOptionRelFieldOption')->findBy(array('fieldId' => $field_details['id'], 'relatedFieldOptionId' => $defaultValueId, 'roleId' => $userInfo['status'])); foreach ($fieldWorkFlow as $item) { $addOptions[] = $item->getFieldOptionId(); } } } $options = array(); if (empty($defaultValueId)) { $options[''] = get_lang('SelectAnOption'); } $optionList = array(); if (!empty($field_details['options'])) { foreach ($field_details['options'] as $option_details) { $optionList[$option_details['id']] = $option_details; if ($get_lang_variables) { $options[$option_details['option_value']] = get_lang($option_details['option_display_text']); } else { if ($optionsExists) { // Adding always the default value if ($option_details['id'] == $defaultValueId) { $options[$option_details['option_value']] = $option_details['option_display_text']; } else { if (isset($addOptions) && !empty($addOptions)) { // Parsing filters if (in_array($option_details['id'], $addOptions)) { $options[$option_details['option_value']] = $option_details['option_display_text']; } } } } else { // Normal behaviour $options[$option_details['option_value']] = $option_details['option_display_text']; } } } if (isset($optionList[$defaultValueId])) { if (isset($optionList[$defaultValueId]['option_value']) && $optionList[$defaultValueId]['option_value'] == 'aprobada') { if (api_is_question_manager() == false) { $form->freeze(); } } } // Setting priority message if (isset($optionList[$defaultValueId]) && isset($optionList[$defaultValueId]['priority'])) { if (!empty($optionList[$defaultValueId]['priority'])) { $priorityId = $optionList[$defaultValueId]['priority']; $option = new ExtraFieldOption($this->type); $messageType = $option->getPriorityMessageType($priorityId); $form->addElement('label', null, Display::return_message($optionList[$defaultValueId]['priority_message'], $messageType)); } } } if ($get_lang_variables) { $field_details['field_display_text'] = get_lang($field_details['field_display_text']); } // chzn-select doesn't work for sessions?? $form->addElement('select', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], $options, array('id' => 'extra_' . $field_details['field_variable'])); if ($optionsExists && $field_details['field_loggeable'] && !empty($defaultValueId)) { $form->addElement('textarea', 'extra_' . $field_details['field_variable'] . '_comment', $field_details['field_display_text'] . ' ' . get_lang('Comment')); $em = Database::getManager(); $extraFieldValue = new ExtraFieldValue($this->type); $repo = $em->getRepository($extraFieldValue->entityName); $repoLog = $em->getRepository('Gedmo\\Loggable\\Entity\\LogEntry'); $newEntity = $repo->findOneBy(array($this->handlerEntityId => $itemId, 'fieldId' => $field_details['id'])); // @todo move this in a function inside the class if ($newEntity) { $logs = $repoLog->getLogEntries($newEntity); if (!empty($logs)) { $html = '<b>' . get_lang('LatestChanges') . '</b><br /><br />'; $table = new HTML_Table(array('class' => 'data_table')); $table->setHeaderContents(0, 0, get_lang('Value')); $table->setHeaderContents(0, 1, get_lang('Comment')); $table->setHeaderContents(0, 2, get_lang('ModifyDate')); $table->setHeaderContents(0, 3, get_lang('Username')); $row = 1; foreach ($logs as $log) { $column = 0; $data = $log->getData(); $fieldValue = isset($data['fieldValue']) ? $data['fieldValue'] : null; $comment = isset($data['comment']) ? $data['comment'] : null; $table->setCellContents($row, $column, $fieldValue); $column++; $table->setCellContents($row, $column, $comment); $column++; $table->setCellContents($row, $column, api_get_local_time($log->getLoggedAt()->format('Y-m-d H:i:s'))); $column++; $table->setCellContents($row, $column, $log->getUsername()); $row++; } $form->addElement('label', null, $html . $table->toHtml()); } } } if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_SELECT_MULTIPLE: $options = array(); foreach ($field_details['options'] as $option_id => $option_details) { $options[$option_details['option_value']] = $option_details['option_display_text']; } $form->addElement('select', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], $options, array('multiple' => 'multiple')); if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_DATE: $form->addElement('datepickerdate', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('form_name' => $form_name)); $form->_elements[$form->_elementIndex['extra_' . $field_details['field_variable']]]->setLocalOption('minYear', 1900); $defaults['extra_' . $field_details['field_variable']] = date('Y-m-d 12:00:00'); if (!isset($form->_defaultValues['extra_' . $field_details['field_variable']])) { $form->setDefaults($defaults); } if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } $form->applyFilter('theme', 'trim'); break; case ExtraField::FIELD_TYPE_DATETIME: $form->addElement('datepicker', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('form_name' => $form_name)); $form->_elements[$form->_elementIndex['extra_' . $field_details['field_variable']]]->setLocalOption('minYear', 1900); $defaults['extra_' . $field_details['field_variable']] = date('Y-m-d 12:00:00'); if (!isset($form->_defaultValues['extra_' . $field_details['field_variable']])) { $form->setDefaults($defaults); } if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } $form->applyFilter('theme', 'trim'); break; case ExtraField::FIELD_TYPE_DOUBLE_SELECT: $first_select_id = 'first_extra_' . $field_details['field_variable']; $url = api_get_path(WEB_AJAX_PATH) . 'extra_field.ajax.php?1=1'; $jquery_ready_content .= ' $("#' . $first_select_id . '").on("change", function() { var id = $(this).val(); if (id) { $.ajax({ url: "' . $url . '&a=get_second_select_options", dataType: "json", data: "type=' . $type . '&field_id=' . $field_details['id'] . '&option_value_id="+id, success: function(data) { $("#second_extra_' . $field_details['field_variable'] . '").empty(); $.each(data, function(index, value) { $("#second_extra_' . $field_details['field_variable'] . '").append($("<option/>", { value: index, text: value })); }); }, }); } else { $("#second_extra_' . $field_details['field_variable'] . '").empty(); } });'; $first_id = null; $second_id = null; if (!empty($extraData)) { $first_id = $extraData['extra_' . $field_details['field_variable']]['extra_' . $field_details['field_variable']]; $second_id = $extraData['extra_' . $field_details['field_variable']]['extra_' . $field_details['field_variable'] . '_second']; } $options = ExtraField::extra_field_double_select_convert_array_to_ordered_array($field_details['options']); $values = array('' => get_lang('Select')); $second_values = array(); if (!empty($options)) { foreach ($options as $option) { foreach ($option as $sub_option) { if ($sub_option['option_value'] == '0') { $values[$sub_option['id']] = $sub_option['option_display_text']; } else { if ($first_id === $sub_option['option_value']) { $second_values[$sub_option['id']] = $sub_option['option_display_text']; } } } } } $group = array(); $group[] = $form->createElement('select', 'extra_' . $field_details['field_variable'], null, $values, array('id' => $first_select_id)); $group[] = $form->createElement('select', 'extra_' . $field_details['field_variable'] . '_second', null, $second_values, array('id' => 'second_extra_' . $field_details['field_variable'])); $form->addGroup($group, 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], ' '); if (!$admin_permissions) { if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } } break; case ExtraField::FIELD_TYPE_DIVIDER: $form->addElement('static', $field_details['field_variable'], '<br /><strong>' . $field_details['field_display_text'] . '</strong>'); break; case ExtraField::FIELD_TYPE_TAG: $field_variable = $field_details['field_variable']; $field_id = $field_details['id']; if ($this->type == 'user') { // The magic should be here $user_tags = UserManager::get_user_tags($user_id, $field_details['id']); $tag_list = ''; if (is_array($user_tags) && count($user_tags) > 0) { foreach ($user_tags as $tag) { $tag_list .= '<option value="' . $tag['tag'] . '" class="selected">' . $tag['tag'] . '</option>'; } } $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?'; } else { $extraFieldValue = new ExtraFieldValue($this->type); $tags = array(); if (!empty($itemId)) { $tags = $extraFieldValue->getAllValuesByItemAndField($itemId, $field_id); } $tag_list = ''; if (is_array($tags) && count($tags) > 0) { $extraFieldOption = new ExtraFieldOption($this->type); foreach ($tags as $tag) { $option = $extraFieldOption->get($tag['field_value']); $tag_list .= '<option value="' . $option['id'] . '" class="selected">' . $option['option_display_text'] . '</option>'; } } $url = api_get_path(WEB_AJAX_PATH) . 'extra_field.ajax.php'; } $form->addElement('hidden', 'extra_' . $field_details['field_variable'] . '__persist__', 1); $multiSelect = '<select id="extra_' . $field_details['field_variable'] . '" name="extra_' . $field_details['field_variable'] . '"> ' . $tag_list . ' </select>'; $form->addElement('label', $field_details['field_display_text'], $multiSelect); $complete_text = get_lang('StartToType'); //if cache is set to true the jquery will be called 1 time $jquery_ready_content .= <<<EOF \$("#extra_{$field_variable}").fcbkcomplete({ json_url: "{$url}?a=search_tags&field_id={$field_id}&type={$this->type}", cache: false, filter_case: true, filter_hide: true, complete_text:"{$complete_text}", firstselected: false, filter_selected: true, newel: true }); EOF; $jquery_ready_content = null; break; case ExtraField::FIELD_TYPE_TIMEZONE: $form->addElement('select', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], api_get_timezones(), ''); if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } break; case ExtraField::FIELD_TYPE_SOCIAL_PROFILE: // get the social network's favicon $icon_path = UserManager::get_favicon_from_url($extraData['extra_' . $field_details['field_variable']], $field_details['field_default_value']); // special hack for hi5 $leftpad = '1.7'; $top = '0.4'; $domain = parse_url($icon_path, PHP_URL_HOST); if ($domain == 'www.hi5.com' or $domain == 'hi5.com') { $leftpad = '3'; $top = '0'; } // print the input field $form->addElement('text', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('size' => 60, 'style' => 'background-image: url(\'' . $icon_path . '\'); background-repeat: no-repeat; background-position: 0.4em ' . $top . 'em; padding-left: ' . $leftpad . 'em; ')); $form->applyFilter('extra_' . $field_details['field_variable'], 'stripslashes'); $form->applyFilter('extra_' . $field_details['field_variable'], 'trim'); if ($field_details['field_visible'] == 0) { $form->freeze('extra_' . $field_details['field_variable']); } break; } } } $return = array(); $return['jquery_ready_content'] = $jquery_ready_content; return $return; }
} } } } $form->setDefaults($default); if (isset($_POST['send'])) { Security::clear_token(); } $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->addElement('header', get_lang('DisplayTermsConditions')); if (isset($_POST['language'])) { $form->addElement('static', Security::remove_XSS($_POST['language'])); $form->addElement('hidden', 'language', Security::remove_XSS($_POST['language'])); $form->add_html_editor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250')); $form->addElement('radio', 'type', '', get_lang('HTMLText'), '0'); $form->addElement('radio', 'type', '', get_lang('PageLink'), '1'); $form->addElement('textarea', 'changes', get_lang('ExplainChanges'), array('width' => '20')); $preview = LegalManager::show_last_condition($term_preview); if ($term_preview['type'] != -1) { $form->addElement('label', get_lang('Preview'), $preview); } // Submit & preview button $navigator_info = api_get_navigator(); //ie6 fix if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') { $buttons = '<div class="row" align="center"> <div class="formw"> <input type="submit" name="back" value="' . get_lang('Back') . '"/> <input type="submit" name="preview" value="' . get_lang('Preview') . '"/>
$objQuestionTmp = Question::read($id); echo "<tr><td><b>" . get_lang('Question') . " : </b>"; echo $objQuestionTmp->selectTitle(); echo "</td></tr>"; echo " <br><tr><td><b><br>" . get_lang('Answer') . " : </b></td></tr>"; $objAnswerTmp = new Answer($id); $num = $objAnswerTmp->selectNbrAnswers(); $objAnswerTmp->read(); for ($i = 1; $i <= $num; $i++) { echo "<tr><td width='10%'> "; $ans = $objAnswerTmp->answer[$i]; $form = new FormValidator('feedbackform', 'post', api_get_self() . "?" . api_get_cidreq() . "&modifyQuestion=" . $modifyQuestion . "&newQuestion=" . $newQuestion); $obj_registration_form = new HTML_QuickForm('frmRegistration', 'POST'); $renderer =& $obj_registration_form->defaultRenderer(); $renderer->setElementTemplate('<tr> <td align="left" style="" valign="top" width=30%>{label} <!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required --> </td> <td align="left" width=70%>{element} <!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error --> </td> </tr>'); $form->add_html_editor('Feedback', $i . '.' . $ans, false, false, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '600', 'Height' => '200')); $form->display(); echo "</td>"; } ?> <form name="frm" action="javascript: void(0);" method="post"> Click Ok to finish <input type="submit" value="Ok" /> </form>
/** * Returns an HTML form (generated by FormValidator) of the plugin settings * @return string FormValidator-generated form */ public function get_settings_form() { $result = new FormValidator($this->get_name()); $defaults = array(); $checkboxGroup = array(); $checkboxCollection = array(); if ($checkboxNames = array_keys($this->fields, 'checkbox')) { $pluginInfoCollection = api_get_settings('Plugins'); foreach ($pluginInfoCollection as $pluginInfo) { if (array_search($pluginInfo['title'], $checkboxNames) !== false) { $checkboxCollection[$pluginInfo['title']] = $pluginInfo; } } } foreach ($this->fields as $name => $type) { $value = $this->get($name); $defaults[$name] = $value; $type = isset($type) ? $type : 'text'; $help = null; if ($this->get_lang_plugin_exists($name.'_help')) { $help = $this->get_lang($name.'_help'); if ($name === "show_main_menu_tab") { $pluginName = strtolower(str_replace('Plugin', '', get_class($this))); $pluginUrl = api_get_path(WEB_PATH)."plugin/$pluginName/index.php"; $pluginUrl = "<a href=$pluginUrl>$pluginUrl</a>"; $help = sprintf($help, $pluginUrl); } } switch ($type) { case 'html': $result->addElement('html', $this->get_lang($name)); break; case 'wysiwyg': $result->add_html_editor($name, $this->get_lang($name)); break; case 'text': $result->addElement($type, $name, array($this->get_lang($name), $help)); break; case 'boolean': $group = array(); $group[] = $result->createElement('radio', $name, '', get_lang('Yes'), 'true'); $group[] = $result->createElement('radio', $name, '', get_lang('No'), 'false'); $result->addGroup($group, null, array($this->get_lang($name), $help)); break; case 'checkbox': $selectedValue = null; if (isset($checkboxCollection[$name])) { if ($checkboxCollection[$name]['selected_value'] === 'true') { $selectedValue = 'checked'; } } $element = $result->createElement( $type, $name, '', $this->get_lang($name), $selectedValue ); $element->_attributes['value'] = 'true'; $checkboxGroup[] = $element; break; } } if (!empty($checkboxGroup)) { $result->addGroup($checkboxGroup, null, array($this->get_lang('sms_types'), $help)); } $result->setDefaults($defaults); $result->addElement('style_submit_button', 'submit_button', $this->get_lang('Save')); return $result; }
return !file_exists($filepath . $filename . '.html'); } // Add group to the form if ($is_certificate_mode) { $form->addElement('text', 'title', get_lang('CertificateName'), array('id' => 'document_title')); } else { $form->addElement('text', 'title', get_lang('Title'), array('id' => 'document_title')); } // Show read-only box only in groups if (!empty($groupId)) { $group[] = $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly')); } $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('title', get_lang('FileExists'), 'callback', 'document_exists'); $current_session_id = api_get_session_id(); $form->add_html_editor('content', '', false, false, $html_editor_config); // Comment-field $folders = DocumentManager::get_all_document_folders($_course, $groupId, $is_allowed_to_edit); // If we are not in the certificates creation, display a folder chooser for the // new document created if (!$is_certificate_mode && !is_my_shared_folder($_user['user_id'], $dir, $current_session_id)) { $folders = DocumentManager::get_all_document_folders($_course, $groupId, $is_allowed_to_edit); $parent_select = $form->addElement('select', 'curdirpath', array(null, get_lang('DestinationDirectory'))); // Following two conditions copied from document.inc.php::build_directory_selector() $folder_titles = array(); if (is_array($folders)) { $escaped_folders = array(); foreach ($folders as $key => &$val) { //Hide some folders if ($val == '/HotPotatoes_files' || $val == '/certificates' || basename($val) == 'css') { continue;
/** * Returns a Form validator Obj * @param string url * @param string action add, edit * @return obj form validator obj */ public function return_form($url, $action) { $form = new FormValidator('grades', 'post', $url); // Setting the form elements $header = get_lang('Add'); if ($action == 'edit') { $header = get_lang('Modify'); } $form->addElement('header', $header); $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $form->addElement('hidden', 'id', $id); $form->addElement('text', 'name', get_lang('Name'), array('size' => '70')); $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers', 'Width' => '100%', 'Height' => '250')); $form->addElement('label', get_lang('Components')); //Get components $nr_items = 2; $max = 10; // Setting the defaults $defaults = $this->get($id); $components = $this->get_components($defaults['id']); if ($action == 'edit') { if (!empty($components)) { $nr_items = count($components) - 1; } } $form->addElement('hidden', 'maxvalue', '100'); $form->addElement('hidden', 'minvalue', '0'); $renderer =& $form->defaultRenderer(); $component_array = array(); for ($i = 0; $i <= $max; $i++) { $counter = $i; $form->addElement('text', 'components[' . $i . '][percentage]', null, array('class' => 'span1')); $form->addElement('text', 'components[' . $i . '][acronym]', null, array('class' => 'span1', 'placeholder' => get_lang('Acronym'))); $form->addElement('text', 'components[' . $i . '][title]', null, array('class' => 'span2', 'placeholder' => get_lang('Title'))); $form->addElement('text', 'components[' . $i . '][prefix]', null, array('class' => 'span1', 'placeholder' => get_lang('Prefix'))); $options = array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $form->addElement('select', 'components[' . $i . '][count_elements]', null, $options); $options = array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $form->addElement('select', 'components[' . $i . '][exclusions]', null, $options); $form->addElement('hidden', 'components[' . $i . '][id]'); $template_percentage = '<div id=' . $i . ' style="display: ' . ($i <= $nr_items ? 'inline' : 'none') . ';" class="control-group"> <p> <label class="control-label">{label}</label> <div class="controls"> {element} <!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --> % = '; $template_acronym = ' <!-- BEGIN required --> {element} {label} <!-- BEGIN error --><span class="form_error">{error}</span> <!-- END error -->'; $template_title = ' {element} <!-- BEGIN error --> <span class="form_error">{error}</span><!-- END error --> <a href="javascript:plusItem(' . ($counter + 1) . ')"> ' . Display::return_icon('add.png', get_lang('Add'), array('style' => 'display: ' . ($counter >= $nr_items ? 'inline' : 'none'), 'id' => 'plus-' . ($counter + 1))) . ' </a> <a href="javascript:minItem(' . $counter . ')"> ' . Display::return_icon('delete.png', get_lang('Delete'), array('style' => 'display: ' . ($counter >= $nr_items ? 'inline' : 'none'), 'id' => 'min-' . $counter)) . ' </a> </div></p></div>'; $renderer->setElementTemplate($template_acronym, 'components[' . $i . '][title]'); $renderer->setElementTemplate($template_percentage, 'components[' . $i . '][percentage]'); $renderer->setElementTemplate($template_acronym, 'components[' . $i . '][acronym]'); $renderer->setElementTemplate($template_acronym, 'components[' . $i . '][prefix]'); $renderer->setElementTemplate($template_title, 'components[' . $i . '][exclusions]'); $renderer->setElementTemplate($template_acronym, 'components[' . $i . '][count_elements]'); if ($i == 0) { $form->addRule('components[' . $i . '][percentage]', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('components[' . $i . '][title]', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('components[' . $i . '][acronym]', get_lang('ThisFieldIsRequired'), 'required'); } $form->addRule('components[' . $i . '][percentage]', get_lang('OnlyNumbers'), 'numeric'); $form->addRule(array('components[' . $i . '][percentage]', 'maxvalue'), get_lang('Over100'), 'compare', '<='); $form->addRule(array('components[' . $i . '][percentage]', 'minvalue'), get_lang('UnderMin'), 'compare', '>='); $component_array[] = 'components[' . $i . '][percentage]'; } //New rule added in the formvalidator compare_fields that filters a group of fields in order to compare with the wanted value $form->addRule($component_array, get_lang('AllMustWeight100'), 'compare_fields', '==@100'); $form->addElement('label', null, get_lang('AllMustWeight100')); if ($action == 'edit') { $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); } else { $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"'); } if (!empty($components)) { $counter = 0; foreach ($components as $component) { foreach ($component as $key => $value) { $defaults['components[' . $counter . '][' . $key . ']'] = $value; } $counter++; } } $form->setDefaults($defaults); // Setting the rules $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); return $form; }