/** * Returns a Form validator Obj * @param string $url * @param string $action add, edit * * @return FormValidator */ public function return_form($url, $action) { $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->addHtmlEditor('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->addButtonSave(get_lang('Modify'), 'submit'); } else { $form->addButtonCreate(get_lang('Add'), 'submit'); } // 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; }
/** * Function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { $defaults = array(); $nb_matches = $nb_options = 2; $matches = array(); $answer = null; if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); $nb_options = $form->getSubmitValue('nb_options'); if (isset($_POST['lessMatches'])) { $nb_matches--; } if (isset($_POST['moreMatches'])) { $nb_matches++; } if (isset($_POST['lessOptions'])) { $nb_options--; } if (isset($_POST['moreOptions'])) { $nb_options++; } } else { if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0) { $nb_matches = $nb_options = 0; for ($i = 1; $i <= $answer->nbrAnswers; $i++) { if ($answer->isCorrect($i)) { $nb_matches++; $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i); $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1); $answerInfo = $answer->getAnswerByAutoId($answer->correct[$i]); $defaults['matches[' . $nb_matches . ']'] = isset($answerInfo['answer']) ? $answerInfo['answer'] : ''; } else { $nb_options++; $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i); } } } } else { $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2'); $defaults['matches[2]'] = '2'; $defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } } for ($i = 1; $i <= $nb_matches; ++$i) { $matches[$i] = $i; } $form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES $html = '<table class="table table-striped table-hover"> <thead> <tr> <th width="85%">' . get_lang('Answer') . '</th> <th width="15%">' . get_lang('MatchesTo') . '</th> <th width="10">' . get_lang('Weighting') . '</th> </tr> </thead> <tbody>'; $form->addHeader(get_lang('MakeCorrespond')); $form->addHtml($html); if ($nb_matches < 1) { $nb_matches = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_matches; ++$i) { $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]"); $form->addHtml('<tr>'); $form->addText("answer[{$i}]", null); $form->addSelect("matches[{$i}]", null, $matches); $form->addText("weighting[{$i}]", null, true, ['value' => 10, 'style' => 'width: 60px;']); $form->addHtml('</tr>'); } $form->addHtml('</tbody></table>'); $renderer->setElementTemplate('<div class="form-group"><div class="col-sm-offset-2">{element}', 'lessMatches'); $renderer->setElementTemplate('{element}</div></div>', 'moreMatches'); global $text; $group = [$form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true), $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true), $form->addButtonSave($text, 'submitQuestion', true)]; $form->addGroup($group); if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(['nb_matches' => $nb_matches, 'nb_options' => $nb_options]); }
//Group Parentship $groups = array(); $groups[0] = get_lang('NoParentship'); $groups = $groups + GroupPortalManager::get_groups_list($group_id); $group_data['parent_group'] = GroupPortalManager::get_parent_group($group_id); $form->addElement('select', 'parent_group', get_lang('GroupParentship'), $groups, array()); // Status $status = array(); $status[GROUP_PERMISSION_OPEN] = get_lang('Open'); $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed'); $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status); // Set default values $defaults['status'] = GROUP_PERMISSION_OPEN; $form->setDefaults($defaults); // Submit button $form->addButtonCreate(get_lang('Add')); // Validate form if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); $picture_element = $form->getElement('picture'); $picture = $picture_element->getValue(); $picture_uri = ''; $name = $values['name']; $description = $values['description']; $url = $values['url']; $status = intval($values['visibility']); $picture = $_FILES['picture']; $parent_group_id = intval($values['parent_group']); $group_id = GroupPortalManager::add($name, $description, $url, $status);
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); $obj_ex = Session::read('objExercise'); /* Mise en variable de Affichage "Reponses" et son icone, "N�", "Vrai", "Reponse" */ $html = '<table class="data_table"> <tr> <th width="10px"> ' . get_lang('Number') . ' </th> <th width="10px"> ' . get_lang('True') . ' </th> <th width="50%"> ' . get_lang('Answer') . ' </th>'; $html .= '<th>' . get_lang('Comment') . '</th>'; $html .= '</tr>'; $form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html); $defaults = array(); $correct = 0; $answer = false; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } #le nombre de r�ponses est bien enregistr� sous la forme int(nb) /* Ajout mise en forme nb reponse */ $form->addElement('hidden', 'nb_answers'); $boxes_names = array(); /* V�rification : Cr�action d'au moins une r�ponse */ if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } //D�but affichage score global dans la modification d'une question $scoreA = "0"; //par reponse $scoreG = "0"; //Global /* boucle pour sauvegarder les donn�es dans le tableau defaults */ for ($i = 1; $i <= $nb_answers; ++$i) { /* si la reponse est de type objet */ if (is_object($answer)) { $defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['correct[' . $i . ']'] = $answer->correct[$i]; // start $scoreA = $answer->weighting[$i]; } if ($scoreA > 0) { $scoreG = $scoreG + $scoreA; } //------------- Fin //------------- Debut si un des scores par reponse est egal � 0 : la coche vaut 1 (coch�) if ($scoreA == 0) { $defaults['pts'] = 1; } $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); //$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"'); $boxes_names[] = 'correct[' . $i . ']'; $form->addHtmlEditor('answer[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addHtmlEditor('comment[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addElement('html', '</tr>'); } //--------- Mise en variable du score global lors d'une modification de la question/r�ponse $defaults['weighting[1]'] = round($scoreG); $form->addElement('html', '</div></div></table>'); //$form -> addElement ('html', '<br />'); $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required'); //only 1 answer the all deal ... $form->addElement('text', 'weighting[1]', get_lang('Score')); global $pts; //--------- Creation coche pour ne pas prendre en compte les n�gatifs $form->addElement('checkbox', 'pts', '', get_lang('NoNegativeScore')); $form->addElement('html', '<br />'); // Affiche un message si le score n'est pas renseign� $form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required'); global $text, $class; if ($obj_ex->edit_exercise_in_lp == true) { $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers'); $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers'); $form->addButtonSave($text, 'submitQuestion'); // setting the save button here and not in the question class.php } $renderer->setElementTemplate('{element} ', 'lessAnswers'); $renderer->setElementTemplate('{element} ', 'submitQuestion'); $renderer->setElementTemplate('{element}', 'moreAnswers'); $form->addElement('html', '</div></div>'); $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(array('nb_answers' => $nb_answers)); }
$form->addElement('text', 'code', get_lang("CategoryCode")); $form->addElement('text', 'name', get_lang("CategoryName")); $form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required'); $form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required'); $group = array($form->createElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE'), $form->createElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE')); $form->addGroup($group, null, get_lang("AllowCoursesInCategory")); if (!empty($categoryInfo)) { $class = "save"; $text = get_lang('Save'); $form->setDefaults($categoryInfo); $form->addButtonSave($text); } else { $class = "add"; $text = get_lang('AddCategory'); $form->setDefaults(array('auth_course_child' => 'TRUE')); $form->addButtonCreate($text); } $form->display(); } elseif (api_get_multiple_access_url() && api_get_current_access_url_id() != 1) { // If multiple URLs and not main URL, prevent edition and inform user Display::display_warning_message(get_lang('CourseCategoriesAreGlobal')); } } else { // If multiple URLs and not main URL, prevent deletion and inform user if ($action == 'delete' && api_get_multiple_access_url() && api_get_current_access_url_id() != 1) { Display::display_warning_message(get_lang('CourseCategoriesAreGlobal')); } echo '<div class="actions">'; $link = null; if (!empty($parentInfo)) { $parentCode = $parentInfo['parent_id'];
/** * @param $url * @param $action * @return FormValidator */ public function return_item_form($url, $action) { $form = new FormValidator('item_form', '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']) : ''; $parent_id = isset($_GET['parent_id']) ? intval($_GET['parent_id']) : ''; $form->addElement('hidden', 'parent_id', $parent_id); $form->addElement('hidden', 'id', $id); $form->addElement('text', 'headline', get_lang('Name')); //@todo fix this $form->addElement('text', 'start_date', get_lang('StartDate'), array('size' => '70')); $form->addElement('text', 'end_date', get_lang('EndDate'), array('size' => '70')); $form->addElement('textarea', 'text', get_lang('TimelineItemText')); $form->addElement('text', 'media', get_lang('TimelineItemMedia'), array('size' => '70')); $form->addElement('text', 'media_caption', get_lang('TimelineItemMediaCaption'), array('size' => '70')); $form->addElement('text', 'media_credit', get_lang('TimelineItemMediaCredit'), array('size' => '70')); $form->addElement('text', 'title_slide', get_lang('TimelineItemTitleSlide'), array('size' => '70')); $form->addRule('headline', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('start_date', get_lang('ThisFieldIsRequired'), 'required'); //$form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Careers','Width' => '100%', 'Height' => '250')); if ($action == 'edit') { // Setting the defaults $defaults = $this->get($id); $form->addButtonSave(get_lang('Modify'), 'submit'); } else { $form->addButtonCreate(get_lang('Add'), 'submit'); } /*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('headline', get_lang('ThisFieldIsRequired'), 'required'); return $form; }
/** * @param string $url * @param string $action * @return FormValidator */ public function return_form($url, $action) { $form = new FormValidator($this->type . '_field', 'post', $url); $form->addElement('hidden', 'type', $this->type); $id = isset($_GET['id']) ? intval($_GET['id']) : null; $form->addElement('hidden', 'id', $id); // Setting the form elements $header = get_lang('Add'); $defaults = array(); if ($action == 'edit') { $header = get_lang('Modify'); // Setting the defaults $defaults = $this->get($id); } $form->addElement('header', $header); $form->addElement('text', 'display_text', get_lang('Name'), array('class' => 'span5')); // Field type $types = self::get_field_types(); $form->addElement('select', 'field_type', get_lang('FieldType'), $types, array('id' => 'field_type')); $form->addElement('label', get_lang('Example'), '<div id="example">-</div>'); $form->addElement('text', 'variable', get_lang('FieldLabel'), array('class' => 'span5')); $form->addElement('text', 'field_options', get_lang('FieldPossibleValues'), array('id' => 'field_options', 'class' => 'span6')); $fieldWithOptions = array(ExtraField::FIELD_TYPE_RADIO, ExtraField::FIELD_TYPE_SELECT_MULTIPLE, ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_TAG, ExtraField::FIELD_TYPE_DOUBLE_SELECT); if ($action == 'edit') { if (in_array($defaults['field_type'], $fieldWithOptions)) { $url = Display::url(get_lang('EditExtraFieldOptions'), 'extra_field_options.php?type=' . $this->type . '&field_id=' . $id); $form->addElement('label', null, $url); if ($defaults['field_type'] == ExtraField::FIELD_TYPE_SELECT) { $urlWorkFlow = Display::url(get_lang('EditExtraFieldWorkFlow'), 'extra_field_workflow.php?type=' . $this->type . '&field_id=' . $id); $form->addElement('label', null, $urlWorkFlow); } $form->freeze('field_options'); } } $form->addElement('text', 'default_value', get_lang('FieldDefaultValue'), array('id' => 'default_value')); $group = array(); $group[] = $form->createElement('radio', 'visible', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'visible', null, get_lang('No'), 0); $form->addGroup($group, '', get_lang('Visible'), '', false); $group = array(); $group[] = $form->createElement('radio', 'changeable', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'changeable', null, get_lang('No'), 0); $form->addGroup($group, '', get_lang('FieldChangeability'), '', false); $group = array(); $group[] = $form->createElement('radio', 'filter', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'filter', null, get_lang('No'), 0); $form->addGroup($group, '', get_lang('FieldFilter'), '', false); /* Enable this when field_loggeable is introduced as a table field (2.0) $group = array(); $group[] = $form->createElement('radio', 'field_loggeable', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'field_loggeable', null, get_lang('No'), 0); $form->addGroup($group, '', get_lang('FieldLoggeable'), '', false); */ $form->addElement('text', 'field_order', get_lang('FieldOrder'), array('class' => 'span1')); if ($action == 'edit') { $option = new ExtraFieldOption($this->type); if ($defaults['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) { $form->freeze('field_options'); } $defaults['field_options'] = $option->get_field_options_by_field_to_string($id); $form->addButtonUpdate(get_lang('Modify')); } else { $defaults['visible'] = 0; $defaults['changeable'] = 0; $defaults['filter'] = 0; $form->addButtonCreate(get_lang('Add')); } /*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('display_text', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('field_type', get_lang('ThisFieldIsRequired'), 'required'); return $form; }
/** * Returns a Form validator Obj * @todo the form should be auto generated * @param string $url * @param string $action add, edit * * @return FormValidator 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->addHtmlEditor('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); $form->addElement('text', 'components[' . $i . '][acronym]', null); $form->addElement('text', 'components[' . $i . '][title]', null); $form->addElement('hidden', 'components[' . $i . '][id]', null); $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"> <!-- BEGIN required --><span class="form_required">*</span> <!-- END required --> {element} <!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --> % = '; $template_acronym = ' <!-- BEGIN required --><span class="form_required">*</span> <!-- END 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) . ')"> <img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="plus-' . ($counter + 1) . '" src="../img/icons/22/add.png" alt="' . get_lang('Add') . '" title="' . get_lang('Add') . '"></img> </a> <a href="javascript:minItem(' . $counter . ')"> <img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="min-' . $counter . '" src="../img/delete.png" alt="' . get_lang('Delete') . '" title="' . get_lang('Delete') . '"></img> </a> </div></p></div>'; $renderer->setElementTemplate($template_title, 'components[' . $i . '][title]'); $renderer->setElementTemplate($template_percentage, 'components[' . $i . '][percentage]'); $renderer->setElementTemplate($template_acronym, 'components[' . $i . '][acronym]'); 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', '', get_lang('AllMustWeight100')); if ($action == 'edit') { $form->addButtonUpdate(get_lang('Modify')); } else { $form->addButtonCreate(get_lang('Add')); } 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; }
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { $defaults = array(); $nb_matches = $nb_options = 2; $matches = array(); $answer = null; $counter = 1; if (isset($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0) { for ($i = 1; $i <= $answer->nbrAnswers; $i++) { $correct = $answer->isCorrect($i); if (empty($correct)) { $matches[$answer->selectAutoId($i)] = chr(64 + $counter); $counter++; } } } } if ($form->isSubmitted()) { $nb_matches = $form->getSubmitValue('nb_matches'); $nb_options = $form->getSubmitValue('nb_options'); if (isset($_POST['lessOptions'])) { $nb_matches--; $nb_options--; } if (isset($_POST['moreOptions'])) { $nb_matches++; $nb_options++; } } else { if (!empty($this->id)) { if (count($answer->nbrAnswers) > 0) { $nb_matches = $nb_options = 0; for ($i = 1; $i <= $answer->nbrAnswers; $i++) { if ($answer->isCorrect($i)) { $nb_matches++; $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i); $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1); $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i]; } else { $nb_options++; $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i); } } } } else { $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1'); $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2'); $defaults['matches[2]'] = '2'; $defaults['option[1]'] = get_lang('DefaultMatchingOptA'); $defaults['option[2]'] = get_lang('DefaultMatchingOptB'); } } if (empty($matches)) { for ($i = 1; $i <= $nb_options; ++$i) { // fill the array with A, B, C..... $matches[$i] = chr(64 + $i); } } else { for ($i = $counter; $i <= $nb_options; ++$i) { // fill the array with A, B, C..... $matches[$i] = chr(64 + $i); } } $form->addElement('hidden', 'nb_matches', $nb_matches); $form->addElement('hidden', 'nb_options', $nb_options); // DISPLAY MATCHES $html = '<table class="table table-striped table-hover"> <thead> <tr> <th width="5%">' . get_lang('Number') . '</th> <th width="70%">' . get_lang('Answer') . '</th> <th width="15%">' . get_lang('MatchesTo') . '</th> <th width="10%">' . get_lang('Weighting') . '</th> </tr> </thead> <tbody>'; $form->addHeader(get_lang('MakeCorrespond')); $form->addHtml($html); if ($nb_matches < 1) { $nb_matches = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_matches; ++$i) { $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]"); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]"); $form->addHtml('<tr>'); $form->addHtml("<td>{$i}</td>"); $form->addText("answer[{$i}]", null); $form->addSelect("matches[{$i}]", null, $matches); $form->addText("weighting[{$i}]", null, true, ['value' => 10]); $form->addHtml('</tr>'); } $form->addHtml('</tbody></table>'); $group = array(); $form->addGroup($group); // DISPLAY OPTIONS $html = '<table class="table table-striped table-hover"> <thead> <tr> <th width="15%">' . get_lang('Number') . '</th> <th width="85%">' . get_lang('Answer') . '</th> </tr> </thead> <tbody>'; $form->addHtml($html); if ($nb_options < 1) { $nb_options = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_options; ++$i) { $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "option[{$i}]"); $form->addHtml('<tr>'); $form->addHtml('<td>' . chr(64 + $i) . '</td>'); $form->addText("option[{$i}]", null); $form->addHtml('</tr>'); } $form->addHtml('</table>'); $group = array(); global $text; // setting the save button here and not in the question class.php $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true); $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true); $group[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($group); if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options)); }
$viewFromSession = Session::read('glossary_view'); if (!isset($viewFromSession)) { // Default option Session::write('glossary_view', 'table'); } } if (api_is_allowed_to_edit(null, true)) { switch ($action) { case 'addglossary': $form = new FormValidator('glossary', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&' . api_get_cidreq()); // Setting the form elements $form->addElement('header', '', get_lang('TermAddNew')); $form->addElement('text', 'glossary_title', get_lang('TermName'), array('size' => '80', 'id' => 'glossary_title')); //$form->applyFilter('glossary_title', 'html_filter'); $form->addHtmlEditor('glossary_comment', get_lang('TermDefinition'), false, false, array('ToolbarSet' => 'Glossary', 'Height' => '300')); $form->addButtonCreate(get_lang('TermAddButton'), 'SubmitGlossary'); // setting the rules $form->addRule('glossary_title', get_lang('ThisFieldIsRequired'), 'required'); // The validation or display if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); GlossaryManager::save_glossary($values); } Security::clear_token(); GlossaryManager::display_glossary(); } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token));
// Form title $form->addElement('header', get_lang('AddLpToStart')); // Title $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('autofocus' => 'autofocus')); $form->applyFilter('lp_name', 'html_filter'); $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('hidden', 'post_time', time()); $form->addElement('hidden', 'action', 'add_lp'); $form->addButtonAdvancedSettings('advanced_params'); $form->addElement('html', '<div id="advanced_params_options" style="display:none">'); $items = learnpath::getCategoryFromCourseIntoSelect(api_get_course_int_id(), true); $form->addElement('select', 'category_id', get_lang('Category'), $items); // Start date $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()')); $form->addElement('html', '<div id="start_date_div" style="display:block;">'); $form->addElement('DatePicker', 'publicated_on', get_lang('PublicationDate')); $form->addElement('html', '</div>'); //End date $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()')); $form->addElement('html', '<div id="end_date_div" style="display:none;">'); $form->addElement('DatePicker', 'expired_on', get_lang('ExpirationDate')); $form->addElement('html', '</div>'); $form->addElement('html', '</div>'); $defaults['activate_start_date_check'] = 1; $defaults['publicated_on'] = date('Y-m-d 08:00:00'); $defaults['expired_on'] = date('Y-m-d 08:00:00', time() + 86400); $form->setDefaults($defaults); $form->addButtonCreate(get_lang('CreateLearningPath')); $form->display(); // Footer Display::display_footer();
/** * 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 show_skill_form($gradebook_id, $url, $header = null) { $form = new FormValidator('gradebook_add_skill', 'POST', $url); // Setting the form elements if (!isset($header)) { $header = get_lang('Add'); } $form->addElement('header', '', $header); $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $form->addElement('hidden', 'id', $id); $skill = new Skill(); $skills = $skill->get_all(); $clean_skill_list = array(); foreach ($skills as $skill) { $clean_skill_list[$skill['id']] = $skill['name']; } $form->addElement('select', 'skill', get_lang('Skills'), $clean_skill_list, array('multiple' => 'multiple')); $selected_skills = self::get_skills_by_gradebook($gradebook_id); $clean_selected_skills = array(); if (!empty($selected_skills)) { foreach ($selected_skills as $skill) { $clean_selected_skills[] = $skill['id']; } } $form->addButtonCreate(get_lang('Add'), 'submit'); $form->setDefaults(array('skill' => $clean_selected_skills)); return $form; }
} } } } $form->addElement('html', '</div>'); } } $form->addElement('html', '</div><br />'); if (isset($_GET['survey_id']) && $_GET['action'] == 'edit') { $class = 'save'; $text = get_lang('ModifySurvey'); $form->addButtonUpdate(get_lang('ModifySurvey'), 'submit_survey'); } else { $class = 'add'; $text = get_lang('CreateSurvey'); $form->addButtonCreate(get_lang('CreateSurvey'), 'submit_survey'); } // Setting the rules if ($_GET['action'] == 'add') { $form->addRule('survey_code', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('survey_code', '', 'maxlength', 20); } $form->addRule('survey_title', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('start_date', get_lang('InvalidDate'), 'date'); $form->addRule('end_date', get_lang('InvalidDate'), 'date'); $form->addRule(array('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte'); // Setting the default values $form->setDefaults($defaults); // The validation or display if ($form->validate()) { // Exporting the values
$prev = '000'; } elseif ($group_id < 100) { $prev = '00'; } elseif ($group_id < 1000) { $prev = '0'; } else { $prev = ''; } } $defaults['group_' . $group_number . '_name'] = get_lang('GroupSingle') . ' ' . $prev . $group_id++; $form->addGroup($group_el, 'group_' . $group_number, null, '</td><td>', false); } $defaults['action'] = 'create_groups'; $defaults['number_of_groups'] = intval($_POST['number_of_groups']); $form->setDefaults($defaults); $form->addButtonCreate(get_lang('CreateGroup'), 'submit'); $form->display(); } } else { /* * Show form to generate new groups */ $create_groups_form = new FormValidator('create_groups', 'post', api_get_self() . '?' . api_get_cidreq()); $create_groups_form->addElement('header', $nameTools); /* $group_el = array (); $group_el[] = $create_groups_form->createElement('text', 'number_of_groups', array(get_lang('Create'), '1')); $group_el[] = $create_groups_form->addButtonCreate(get_lang('ProceedToCreateGroup'), 'submit', true); $create_groups_form->addGroup($group_el, 'create_groups', get_lang('NumberOfGroupsToCreate'), ' ', false); */ $create_groups_form->addText('number_of_groups', get_lang('NumberOfGroupsToCreate'), null, array('value' => '1')); $create_groups_form->addButton('submit', get_lang('ProceedToCreateGroup'), 'plus', 'primary');
$form->addRule('english_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('text', 'isocode', get_lang('ISOCode'), 'class="input_titles"'); $form->addRule('isocode', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('static', null, ' ', '<i>en, es, fr</i>'); $form->addElement('checkbox', 'sub_language_is_visible', '', get_lang('Visibility')); $form->addButtonCreate(get_lang('CreateSubLanguage'), 'SubmitAddNewLanguage'); //$values['original_name'] = $language_details['original_name'].'...'; -> cannot be used because of quickform filtering (freeze) $values['english_name'] = $language_details['english_name'] . '2'; $values['isocode'] = $language_details['isocode']; $form->setDefaults($values); $form->display(); } else { if (isset($_GET['action']) && $_GET['action'] == 'deletesublanguage') { $text = $language_name; $form = new FormValidator('deletesublanguage', 'post', 'sub_language_add.php?id=' . Security::remove_XSS($_GET['id']) . '&sub_language_id=' . Security::remove_XSS($_GET['sub_language_id'])); $class = 'minus'; $form->addElement('header', '', $text); $form->addElement('static', '', get_lang('OriginalName'), $original_name); $form->addElement('static', '', get_lang('EnglishName'), $english_name); $form->addElement('static', '', get_lang('PlatformCharsetTitle'), $isocode); $form->addButtonCreate(get_lang('DeleteSubLanguage'), 'SubmitAddDeleteLanguage'); $form->display(); } if (isset($_GET['action']) && $_GET['action'] == 'definenewsublanguage') { Display::display_normal_message(get_lang('TheSubLanguageForThisLanguageHasBeenAdded')); } } /** * Footer */ Display::display_footer();
$sequence = new Sequence(); $sequence->setName($values['name']); $em->persist($sequence); $em->flush(); header('Location: ' . api_get_self()); exit; } $selectSequence = new FormValidator(''); $selectSequence->addHidden('sequence_type', 'session'); $em = Database::getManager(); $sequenceList = $em->getRepository('ChamiloCoreBundle:Sequence')->findAll(); $selectSequence->addSelect('sequence', get_lang('Sequence'), $sequenceList, ['id' => 'sequence_id', 'cols-size' => [3, 7, 2]]); $form = new FormValidator(''); $form->addHtml("<div class='col-md-6'>"); $form->addHidden('sequence_type', 'session'); $form->addSelect('sessions', get_lang('Sessions'), $sessionList, ['id' => 'item', 'cols-size' => [4, 7, 1]]); $form->addButtonNext(get_lang('UseAsReference'), 'use_as_reference', ['cols-size' => [4, 7, 1]]); $form->addHtml("</div>"); $form->addHtml("<div class='col-md-6'>"); $form->addSelect('requirements', get_lang('Requirements'), $sessionList, ['id' => 'requirements', 'cols-size' => [3, 7, 2]]); $form->addButtonCreate(get_lang('SetAsRequirement'), 'set_requirement', false, ['cols-size' => [3, 7, 2]]); $form->addHtml("</div>"); $formSave = new FormValidator(''); $formSave->addHidden('sequence_type', 'session'); $formSave->addButton('save_resource', get_lang('SaveSettings'), 'floppy-o', 'success', null, null, ['cols-size' => [1, 10, 1]]); $tpl->assign('create_sequence', $formSequence->returnForm()); $tpl->assign('select_sequence', $selectSequence->returnForm()); $tpl->assign('configure_sequence', $form->returnForm()); $tpl->assign('save_sequence', $formSave->returnForm()); $layout = $tpl->get_template('admin/resource_sequence.tpl'); $tpl->display($layout);
header('Location: access_urls.php'); exit; } $url_data = UrlManager::get_url_data_from_id($url_id); $form->addElement('hidden', 'id', $url_data['id']); $form->setDefaults($url_data); $submit_name = get_lang('AddUrl'); } if (!api_is_multiple_url_enabled()) { header('Location: index.php'); exit; } $tool_name = get_lang('AddUrl'); $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin')); $interbreadcrumb[] = array("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs')); Display::display_header($tool_name); if (isset($_GET['action'])) { switch ($_GET['action']) { case 'show_message': Display::display_normal_message(stripslashes($_GET['message'])); break; } } // URL Images $form->addElement('file', 'url_image_1', 'URL Image 1 (PNG)'); $form->addElement('file', 'url_image_2', 'URL Image 2 (PNG)'); $form->addElement('file', 'url_image_3', 'URL Image 3 (PNG)'); // Submit button $form->addButtonCreate($submit_name); $form->display(); Display::display_footer();
$form->addElement('hidden', 'field_id', (int) $_REQUEST['field_id']); $form->addElement('text', 'field_name', get_lang('FieldName')); $form->applyFilter('field_name', 'html_filter'); $form->applyFilter('field_name', 'trim'); $form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('field_name', get_lang('OnlyLettersAndNumbersAllowed'), 'username'); $form->addRule('field_name', '', 'maxlength', 20); // Set default values (only not empty when editing) $defaults = array(); if (is_numeric($_REQUEST['field_id'])) { $form_information = get_specific_field_list(array('id' => (int) $_GET['field_id'])); $defaults['field_name'] = $form_information[0]['name']; } $form->setDefaults($defaults); // Submit button $form->addButtonCreate(get_lang('Add'), 'submit'); // Validate form if ($form->validate()) { $field = $form->exportValues(); $field_name = $field['field_name']; if (is_numeric($field['field_id']) && $field['field_id'] != 0 && !empty($field['field_id'])) { edit_specific_field($field['field_id'], $field['field_name']); $message = get_lang('FieldEdited'); } else { $field_id = add_specific_field($field_name); $message = get_lang('FieldAdded'); } header('Location: specific_fields.php?message=' . $message); //exit (); } // Display form
/** * function which redifines Question::createAnswersForm * @param FormValidator $form * @param the answers number to display */ function createAnswersForm($form) { // getting the exercise list $obj_ex = Session::read('objExercise'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); //this line define how many question by default appear when creating a choice question $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3; // The previous default value was 2. See task #1759. $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); /* Types of Feedback $feedback_option[0]=get_lang('Feedback'); $feedback_option[1]=get_lang('DirectFeedback'); $feedback_option[2]=get_lang('NoFeedback'); */ $feedback_title = ''; $comment_title = ''; if ($obj_ex->selectFeedbackType() == 1) { $editor_config['Width'] = '250'; $editor_config['Height'] = '110'; $comment_title = '<th width="50%" >' . get_lang('Comment') . '</th>'; $feedback_title = '<th width="50%" >' . get_lang('Scenario') . '</th>'; } else { $comment_title = '<th width="50%">' . get_lang('Comment') . '</th>'; } $html = '<table class="table table-striped table-hover">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th>' . get_lang('Number') . '</th>'; $html .= '<th>' . get_lang('True') . '</th>'; $html .= '<th width="50%">' . get_lang('Answer') . '</th>'; $html .= $comment_title . $feedback_title; $html .= '<th>' . get_lang('Weighting') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; $answer = false; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $temp_scenario = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : false; if ($editQuestion) { //fixing $nb_answers $new_list = array(); $count = 1; if (isset($_POST['lessAnswers'])) { $lessFromSession = Session::read('less_answer'); if (!isset($lessFromSession)) { Session::write('less_answer', $this->id); $nb_answers--; } } for ($k = 1; $k <= $nb_answers; ++$k) { if ($answer->position[$k] != '666') { $new_list[$count] = $count; $count++; } } } else { for ($k = 1; $k <= $nb_answers; ++$k) { $new_list[$k] = $k; } } $i = 1; //for ($k = 1 ; $k <= $real_nb_answers; $k++) { foreach ($new_list as $key) { $i = $key; $form->addElement('html', '<tr>'); if (is_object($answer)) { if ($answer->position[$i] == 666) { //we set nothing } else { if ($answer->correct[$i]) { $correct = $i; } $answer_result = $answer->answer[$i]; $weight_result = float_format($answer->weighting[$i], 1); if ($nb_answers == $i) { $weight_result = '0'; } $defaults['answer[' . $i . ']'] = $answer_result; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = $weight_result; $item_list = explode('@@', $answer->destination[$i]); $try = $item_list[0]; $lp = $item_list[1]; $list_dest = $item_list[2]; $url = $item_list[3]; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } } $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config); $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config); $form->addElement('text', 'weighting[' . $i . ']', null, array('style' => 'width: 60px;', 'value' => '0')); $form->addElement('html', '</tr>'); $i++; } if (empty($this->id)) { $form->addElement('hidden', 'new_question', 1); } //Adding the "I don't know" question answer //if (empty($this -> id)) { $i = 666; $form->addHtml('<tr>'); $defaults['answer[' . $i . ']'] = get_lang('DontKnow'); $defaults['weighting[' . $i . ']'] = 0; $defaults['scenario'] = $temp_scenario; $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="-"'); $answer_number->freeze(); $form->addElement('hidden', 'position[' . $i . ']', '666'); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"'); $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config); //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple'); $form->addText("weighting[{$i}]", null, false, ['style' => 'width: 60px;', 'value' => 0, 'readonly' => 'readonly']); $form->addHTml('</tr>'); $form->addHtml('</tbody></table>'); $buttonGroup = []; global $text, $class; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($buttonGroup); } //We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { $form->setDefaults($defaults); } $form->addElement('hidden', 'nb_answers'); $form->setConstants(array('nb_answers' => $nb_answers)); }
//session id $session_id = api_get_session_id(); // the exercises $tbl_exercises = Database::get_course_table(TABLE_QUIZ_TEST); $course_id = api_get_course_int_id(); $sql = "SELECT id,title,type,description, results_disabled FROM {$tbl_exercises} WHERE c_id = {$course_id} AND active<>'-1' AND session_id=" . $session_id . " ORDER BY title ASC"; $result = Database::query($sql); $exercises['-'] = '-' . get_lang('SelectExercise') . '-'; while ($row = Database::fetch_array($result)) { $exercises[$row['id']] = cut($row['title'], EXERCISE_MAX_NAME_SIZE); } $form->addElement('select', 'exercise', get_lang('Exercise'), $exercises); // generate default content $form->addElement('checkbox', 'is_content', null, get_lang('GenerateDefaultContent'), array('checked' => true)); // the submit button $form->addButtonCreate(get_lang('CreateQuestion'), 'SubmitCreateQuestion'); // setting the rules $form->addRule('exercise', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('exercise', get_lang('YouHaveToSelectATest'), 'numeric'); $form->registerRule('validquestiontype', 'callback', 'check_question_type'); $form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype'); if ($form->validate()) { $values = $form->exportValues(); $answer_type = $values['question_type_hidden']; // check feedback_type from current exercise for type of question delineation $exercise_id = intval($values['exercise']); $sql = "SELECT feedback_type FROM {$tbl_exercises} WHERE c_id = {$course_id} AND id = '{$exercise_id}'"; $rs_feedback_type = Database::query($sql); $row_feedback_type = Database::fetch_row($rs_feedback_type); $feedback_type = $row_feedback_type[0]; // if question type does not belong to self-evaluation (immediate feedback) it'll send an error
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ public function createAnswersForm($form) { // Getting the exercise list $obj_ex = Session::read('objExercise'); $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125'); //this line defines how many questions by default appear when creating a choice question // The previous default value was 2. See task #1759. $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4; $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); /* Types of Feedback $feedback_option[0]=get_lang('Feedback'); $feedback_option[1]=get_lang('DirectFeedback'); $feedback_option[2]=get_lang('NoFeedback'); */ $feedback_title = ''; if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { //Scenario $comment_title = '<th width="20%">' . get_lang('Comment') . '</th>'; $feedback_title = '<th width="20%">' . get_lang('Scenario') . '</th>'; } else { $comment_title = '<th width="40%">' . get_lang('Comment') . '</th>'; } $html = '<table class="table table-striped table-hover"> <thead> <tr style="text-align: center;"> <th width="5%">' . get_lang('Number') . '</th> <th width="5%"> ' . get_lang('True') . '</th> <th width="40%">' . get_lang('Answer') . '</th> ' . $comment_title . ' ' . $feedback_title . ' <th width="10%">' . get_lang('Weighting') . '</th> </tr> </thead> <tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $form->addElement('hidden', 'nb_answers'); //Feedback SELECT $question_list = $obj_ex->selectQuestionList(); $select_question = array(); $select_question[0] = get_lang('SelectTargetQuestion'); if (is_array($question_list)) { foreach ($question_list as $key => $questionid) { //To avoid warning messages if (!is_numeric($questionid)) { continue; } $question = Question::read($questionid); $select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20); } } $select_question[-1] = get_lang('ExitTest'); $list = new LearnpathList(api_get_user_id()); $flat_list = $list->get_flat_list(); $select_lp_id = array(); $select_lp_id[0] = get_lang('SelectTargetLP'); foreach ($flat_list as $id => $details) { $select_lp_id[$id] = cut($details['lp_name'], 20); } $temp_scenario = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_answers; ++$i) { $form->addHtml('<tr>'); if (isset($answer) && is_object($answer)) { if ($answer->correct[$i]) { $correct = $i; } $defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1); $item_list = explode('@@', $answer->destination[$i]); $try = isset($item_list[0]) ? $item_list[0] : ''; $lp = isset($item_list[1]) ? $item_list[1] : ''; $list_dest = isset($item_list[2]) ? $item_list[2] : ''; $url = isset($item_list[3]) ? $item_list[3] : ''; if ($try == 0) { $try_result = 0; } else { $try_result = 1; } if ($url == 0) { $url_result = ''; } else { $url_result = $url; } $temp_scenario['url' . $i] = $url_result; $temp_scenario['try' . $i] = $try_result; $temp_scenario['lp' . $i] = $lp; $temp_scenario['destination' . $i] = $list_dest; } else { $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1'); $defaults['weighting[1]'] = 10; $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2'); $defaults['weighting[2]'] = 0; $temp_scenario['destination' . $i] = array('0'); $temp_scenario['lp' . $i] = array('0'); } $defaults['scenario'] = $temp_scenario; $renderer = $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, ' value = "' . $i . '"'); $answer_number->freeze(); $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox"'); $form->addHtmlEditor('answer[' . $i . ']', null, null, true, $editor_config); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config); // Direct feedback //Adding extra feedback fields $group = array(); $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain')); $group['lp' . $i] = $form->createElement('select', 'lp' . $i, get_lang('SeeTheory') . ': ', $select_lp_id); $group['destination' . $i] = $form->createElement('select', 'destination' . $i, get_lang('GoToQuestion') . ': ', $select_question); $group['url' . $i] = $form->createElement('text', 'url' . $i, get_lang('Other') . ': ', array('class' => 'col-md-2', 'placeholder' => get_lang('Other'))); $form->addGroup($group, 'scenario'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario'); } else { $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config); } $form->addText('weighting[' . $i . ']', null, null, array('value' => '0')); $form->addHtml('</tr>'); } $form->addHtml('</tbody>'); $form->addHtml('</table>'); global $text; $buttonGroup = []; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { //setting the save button here and not in the question class.php $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true); $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true); $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true); $form->addGroup($buttonGroup); } // We check the first radio button to be sure a radio button will be check if ($correct == 0) { $correct = 1; } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { // Default sample content. $form->setDefaults($defaults); } else { $form->setDefaults(array('correct' => 1)); } } $form->setConstants(array('nb_answers' => $nb_answers)); }
$label = '/ (' . get_lang('HomeDirectory') . ')'; } else { $path_parts = explode('/', str_replace($group_dir, '', $folder)); $label = cut($label, 80); $label = str_repeat(' ', count($path_parts) - 2) . ' — ' . $label; } $parent_select->addOption($label, $folder); if ($selected != '') { $parent_select->setSelected($folder); } } } } $form->addHidden('dirValue', ''); if ($is_certificate_mode) { $form->addButtonCreate(get_lang('CreateCertificate')); } else { $form->addButtonCreate(get_lang('CreateDoc')); } $form->setDefaults($defaults); // If form validates -> save the new document if ($form->validate()) { $values = $form->exportValues(); $readonly = isset($values['readonly']) ? 1 : 0; $values['title'] = trim($values['title']); if (!empty($values['dirValue'])) { $dir = $values['dirValue']; } if ($dir[strlen($dir) - 1] != '/') { $dir .= '/'; }
/** * Creates form that asks for the directory name. * @return string html-output text for the form */ public static function create_dir_form($dirId) { global $document_id; $form = new FormValidator('create_dir_form', 'post', api_get_self() . '?' . api_get_cidreq()); $form->addElement('hidden', 'create_dir', 1); $form->addElement('hidden', 'dir_id', intval($document_id)); $form->addElement('hidden', 'id', intval($dirId)); $form->addElement('header', get_lang('CreateDir')); $form->addText('dirname', get_lang('NewDir'), array('autofocus' => 'autofocus')); $form->addButtonCreate(get_lang('CreateFolder')); return $form->returnForm(); }
/** * function which redefines Question::createAnswersForm * @param FormValidator $form */ function createAnswersForm($form) { $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2; $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0); $obj_ex = Session::read('objExercise'); $html = '<table class="table table-striped table-hover">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th width="10">' . get_lang('Number') . '</th>'; $html .= '<th width="10">' . get_lang('True') . '</th>'; $html .= '<th width="50%">' . get_lang('Comment') . '</th>'; $html .= '<th width="50%">' . get_lang('Answer') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $form->addHeader(get_lang('Answers')); $form->addHtml($html); $defaults = array(); $correct = 0; $answer = false; if (!empty($this->id)) { $answer = new Answer($this->id); $answer->read(); if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) { $nb_answers = $answer->nbrAnswers; } } $form->addElement('hidden', 'nb_answers'); $boxes_names = array(); if ($nb_answers < 1) { $nb_answers = 1; Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer')); } for ($i = 1; $i <= $nb_answers; ++$i) { $form->addHtml('<tr>'); if (is_object($answer)) { $defaults['answer[' . $i . ']'] = $answer->answer[$i]; $defaults['comment[' . $i . ']'] = $answer->comment[$i]; $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1); $defaults['correct[' . $i . ']'] = $answer->correct[$i]; } else { $defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2'); $defaults['comment[1]'] = get_lang('DefaultMultipleComment2'); $defaults['correct[1]'] = true; $defaults['weighting[1]'] = 10; $defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1'); $defaults['comment[2]'] = get_lang('DefaultMultipleComment1'); $defaults['correct[2]'] = false; } $renderer =& $form->defaultRenderer(); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']'); $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']'); $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"'); $answer_number->freeze(); $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox" style="margin-left: 0em;"'); $boxes_names[] = 'correct[' . $i . ']'; $form->addElement('html_editor', 'answer[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100')); $form->addHtml('</tr>'); } $form->addElement('html', '</tbody></table>'); $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required'); //only 1 answer the all deal ... $form->addText('weighting[1]', get_lang('Score'), false, ['value' => 10]); global $text; //ie6 fix if ($obj_ex->edit_exercise_in_lp == true) { // setting the save button here and not in the question class.php $buttonGroup = [$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true), $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true), $form->addButtonSave($text, 'submitQuestion', true)]; $form->addGroup($buttonGroup); } $defaults['correct'] = $correct; if (!empty($this->id)) { $form->setDefaults($defaults); } else { if ($this->isContent == 1) { $form->setDefaults($defaults); } } $form->setConstants(array('nb_answers' => $nb_answers)); }
/** * form to add a category * @todo move to TestCategory.class.php * @param string $action */ function add_category_form($action) { $action = Security::remove_XSS($action); // initiate the object $form = new FormValidator('note', 'post', api_get_self() . '?action=' . $action); // Setting the form elements $form->addElement('header', get_lang('AddACategory')); $form->addElement('text', 'category_name', get_lang('CategoryName'), array('size' => '95')); $form->addHtmlEditor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Height' => '200')); $form->addButtonCreate(get_lang('AddTestCategory'), 'SubmitNote'); // setting the rules $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); // The validation or display if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); $v_name = Security::remove_XSS($values['category_name'], COURSEMANAGER); $v_description = Security::remove_XSS($values['category_description'], COURSEMANAGER); $objcat = new TestCategory(0, $v_name, $v_description); if ($objcat->addCategoryInBDD()) { Display::display_confirmation_message(get_lang('AddCategoryDone')); } else { Display::display_confirmation_message(get_lang('AddCategoryNameAlreadyExists')); } } Security::clear_token(); } else { display_goback(); $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } }
$defaults['date_time'] = date('Y-m-d H:i', api_strtotime(api_get_local_time())); $form->addElement('checkbox', 'repeat', null, get_lang('RepeatDate'), array('onclick' => "javascript: if(this.checked){document.getElementById('repeat-date-attendance').style.display='block';}else{document.getElementById('repeat-date-attendance').style.display='none';}")); $defaults['repeat'] = isset($repeat) ? $repeat : null; if ($defaults['repeat']) { $form->addElement('html', '<div id="repeat-date-attendance" style="display:block">'); } else { $form->addElement('html', '<div id="repeat-date-attendance" style="display:none">'); } $a_repeat_type = array('daily' => get_lang('RepeatDaily'), 'weekly' => get_lang('RepeatWeekly'), 'monthlyByDate' => get_lang('RepeatMonthlyByDate')); $form->addElement('select', 'repeat_type', get_lang('RepeatType'), $a_repeat_type); $form->addElement('date_picker', 'end_date_time', get_lang('RepeatEnd'), array('form_name' => 'attendance_calendar_add')); $defaults['end_date_time'] = date('Y-m-d'); $form->addElement('html', '</div>'); $defaults['repeat_type'] = 'weekly'; $form->addSelect('groups', get_lang('Group'), $groupIdList); $form->addButtonCreate(get_lang('Save')); $form->setDefaults($defaults); $form->display(); } else { // Calendar list $groupList = GroupManager::get_group_list(); $groupIdList = array('--'); foreach ($groupList as $group) { $groupIdList[$group['id']] = $group['name']; } echo Display::page_subheader(get_lang('CalendarList')); echo '<div class="attendance-calendar-list">'; if (!empty($attendance_calendar)) { foreach ($attendance_calendar as $calendar) { echo '<div class="attendance-calendar-row">'; if (isset($action) && $action == 'calendar_edit' && (isset($calendar_id) && $calendar_id == $calendar['id'])) {
/** * @param FormValidator $form * @param string $type * @param array $data */ public function setForm($form, $type = 'add', $data = array()) { switch ($type) { case 'add': $header = get_lang('Add'); break; case 'edit': $header = get_lang('Edit'); break; } $form->addElement('header', $header); //Name $form->addElement('text', 'name', get_lang('Name'), array('maxlength' => 255)); $form->applyFilter('name', 'html_filter'); $form->applyFilter('name', 'trim'); $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('name', '', 'maxlength', 255); // Description $form->addElement('textarea', 'description', get_lang('Description'), array('cols' => 58)); $form->applyFilter('description', 'html_filter'); $form->applyFilter('description', 'trim'); if ($this->showGroupTypeSetting) { $form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup')); } // url $form->addElement('text', 'url', get_lang('Url')); $form->applyFilter('url', 'html_filter'); $form->applyFilter('url', 'trim'); // Picture $allowed_picture_types = $this->getAllowedPictureExtensions(); $form->addElement('file', 'picture', get_lang('AddPicture')); $form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types); if (isset($data['picture']) && strlen($data['picture']) > 0) { $picture = $this->get_picture_group($data['id'], $data['picture'], 80); $img = '<img src="' . $picture['file'] . '" />'; $form->addElement('label', null, $img); $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage')); } $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $this->getGroupStatusList()); $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>'); // Setting the form elements if ($type == 'add') { $form->addButtonCreate($header); } else { $form->addButtonUpdate($header); } }
/** * This function displays the form that is used to add a forum category. * * @param array $inputvalues * @param int $lp_id * @return void HTML * * @author Patrick Cool <*****@*****.**>, Ghent University * @author Juan Carlos Raña Trabado (return to lp_id) * * @version may 2011, Chamilo 1.8.8 */ function show_add_forum_form($inputvalues = array(), $lp_id) { $_course = api_get_course_info(); // Initialize the object. $form = new FormValidator('forumcategory', 'post', 'index.php?' . api_get_cidreq()); // The header for the form if (!empty($inputvalues)) { $form_title = get_lang('EditForum'); } else { $form_title = get_lang('AddForum'); } $session_header = Session::read('session_name'); $form->addElement('header', $form_title . $session_header); // We have a hidden field if we are editing. if (!empty($inputvalues) && is_array($inputvalues)) { $my_forum_id = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null; $form->addElement('hidden', 'forum_id', $my_forum_id); } $lp_id = intval($lp_id); // hidden field if from learning path $form->addElement('hidden', 'lp_id', $lp_id); // The title of the forum $form->addElement('text', 'forum_title', get_lang('Title'), array('autofocus')); // The comment of the forum. $form->addHtmlEditor('forum_comment', get_lang('Description'), null, null, array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')); // Dropdown list: Forum categories $forum_categories = get_forum_categories(); foreach ($forum_categories as $key => $value) { $forum_categories_titles[$value['cat_id']] = $value['cat_title']; } $form->addElement('select', 'forum_category', get_lang('InForumCategory'), $forum_categories_titles); $form->applyFilter('forum_category', 'html_filter'); if ($_course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD) { // This is for horizontal $group = array(); $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('No'), 0); $form->addGroup($group, 'allow_anonymous_group', get_lang('AllowAnonymousPosts'), ' '); } $form->addButtonAdvancedSettings('advanced_params'); $form->addElement('html', '<div id="advanced_params_options" style="display:none">'); $group = array(); $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('No'), 0); $form->addGroup($group, 'students_can_edit_group', get_lang('StudentsCanEdit'), ' '); $group = array(); $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Approval'), 1); $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Direct'), 0); $group = array(); $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('No'), 0); $group = array(); $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('No'), 0); $form->addGroup($group, 'allow_new_threads_group', get_lang('AllowNewThreads'), ' '); $group = array(); $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Flat'), 'flat'); $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Threaded'), 'threaded'); $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Nested'), 'nested'); $form->addGroup($group, 'default_view_type_group', get_lang('DefaultViewType'), ' '); // Drop down list: Groups $groups = GroupManager::get_group_list(); $groups_titles[0] = get_lang('NotAGroupForum'); foreach ($groups as $key => $value) { $groups_titles[$value['id']] = $value['name']; } $form->addElement('select', 'group_forum', get_lang('ForGroup'), $groups_titles); // Public or private group forum $group = array(); $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Public'), 'public'); $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Private'), 'private'); $form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'), ''); // Forum image $form->add_progress_bar(); if (isset($inputvalues['forum_image']) && strlen($inputvalues['forum_image']) > 0) { $image_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/forum/images/' . $inputvalues['forum_image']; $image_size = api_getimagesize($image_path); $img_attributes = ''; if (!empty($image_size)) { if ($image_size['width'] > 100 || $image_size['height'] > 100) { //limit display width and height to 100px $img_attributes = 'width="100" height="100"'; } $show_preview_image = '<img src="' . $image_path . '" ' . $img_attributes . '>'; $form->addElement('label', get_lang('PreviewImage'), $show_preview_image); $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage')); } } $forum_image = isset($inputvalues['forum_image']) ? $inputvalues['forum_image'] : ''; $form->addElement('file', 'picture', $forum_image != '' ? get_lang('UpdateImage') : get_lang('AddImage')); $form->addRule('picture', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif')); $form->addElement('html', '</div>'); // The OK button if (isset($_GET['id']) && $_GET['action'] == 'edit') { $form->addButtonUpdate(get_lang('ModifyForum'), 'SubmitForum'); } else { $form->addButtonCreate(get_lang('CreateForum'), 'SubmitForum'); } // setting the rules $form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required'); $defaultSettingAllowNewThreads = api_get_default_tool_setting('forum', 'allow_new_threads', 0); // Settings the defaults if (empty($inputvalues) || !is_array($inputvalues)) { $defaults['allow_anonymous_group']['allow_anonymous'] = 0; $defaults['students_can_edit_group']['students_can_edit'] = 0; $defaults['approval_direct_group']['approval_direct'] = 0; $defaults['allow_attachments_group']['allow_attachments'] = 1; $defaults['allow_new_threads_group']['allow_new_threads'] = $defaultSettingAllowNewThreads; $defaults['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view'); $defaults['public_private_group_forum_group']['public_private_group_forum'] = 'public'; if (isset($_GET['forumcategory'])) { $defaults['forum_category'] = Security::remove_XSS($_GET['forumcategory']); } } else { // the default values when editing = the data in the table $defaults['forum_id'] = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null; $defaults['forum_title'] = prepare4display(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null); $defaults['forum_comment'] = prepare4display(isset($inputvalues['forum_comment']) ? $inputvalues['forum_comment'] : null); $defaults['forum_category'] = isset($inputvalues['forum_category']) ? $inputvalues['forum_category'] : null; $defaults['allow_anonymous_group']['allow_anonymous'] = isset($inputvalues['allow_anonymous']) ? $inputvalues['allow_anonymous'] : null; $defaults['students_can_edit_group']['students_can_edit'] = isset($inputvalues['allow_edit']) ? $inputvalues['allow_edit'] : null; $defaults['approval_direct_group']['approval_direct'] = isset($inputvalues['approval_direct_post']) ? $inputvalues['approval_direct_post'] : null; $defaults['allow_attachments_group']['allow_attachments'] = isset($inputvalues['allow_attachments']) ? $inputvalues['allow_attachments'] : null; $defaults['allow_new_threads_group']['allow_new_threads'] = isset($inputvalues['allow_new_threads']) ? $inputvalues['allow_new_threads'] : $defaultSettingAllowNewThreads; $defaults['default_view_type_group']['default_view_type'] = isset($inputvalues['default_view']) ? $inputvalues['default_view'] : null; $defaults['public_private_group_forum_group']['public_private_group_forum'] = isset($inputvalues['forum_group_public_private']) ? $inputvalues['forum_group_public_private'] : null; $defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null; } $form->setDefaults($defaults); // Validation or display if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); $return_message = store_forum($values); Display::display_confirmation_message($return_message); } Security::clear_token(); } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } }
*/ /** * Code */ // Resetting the course id. $cidReset = true; // Including some necessary dokeos files. //require_once '../inc/global.inc.php'; // Setting the section (for the tabs). $this_section = SECTION_PLATFORM_ADMIN; // Access restrictions. api_protect_admin_script(); // Setting breadcrumbs. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'class_list.php', 'name' => get_lang('Classes')); // Setting the name of the tool. $tool_name = get_lang("AddClasses"); $form = new FormValidator('add_class'); $form->addText('name', get_lang('ClassName')); $form->addButtonCreate(get_lang('Ok')); if ($form->validate()) { $values = $form->exportValues(); ClassManager::create_class($values['name']); header('Location: class_list.php'); } // Displaying the header. Display::display_header($tool_name); // Displaying the form. $form->display(); // Displaying the footer. Display::display_footer();
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { api_not_allowed(); } if (!empty($_GET['isStudentView'])) { NotebookManager::display_notes(); exit; } $_SESSION['notebook_view'] = 'creation_date'; // Initiate the object $form = new FormValidator('note', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action'])); // Setting the form elements $form->addElement('header', '', get_lang('NoteAddNew')); $form->addElement('text', 'note_title', get_lang('NoteTitle'), array('size' => '95', 'id' => 'note_title')); //$form->applyFilter('note_title', 'html_filter'); $form->addElement('html_editor', 'note_comment', get_lang('NoteComment'), null, api_is_allowed_to_edit() ? array('ToolbarSet' => 'Notebook', 'Width' => '100%', 'Height' => '300') : array('ToolbarSet' => 'NotebookStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student')); $form->addButtonCreate(get_lang('AddNote'), 'SubmitNote'); // Setting the rules $form->addRule('note_title', get_lang('ThisFieldIsRequired'), 'required'); // The validation or display if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); $res = NotebookManager::save_note($values); if ($res) { Display::display_confirmation_message(get_lang('NoteAdded')); } } Security::clear_token(); NotebookManager::display_notes(); } else {