本文整理汇总了PHP中FormValidator::defaultRenderer方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::defaultRenderer方法的具体用法?PHP FormValidator::defaultRenderer怎么用?PHP FormValidator::defaultRenderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormValidator
的用法示例。
在下文中一共展示了FormValidator::defaultRenderer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: createAnswersForm
//.........这里部分代码省略.........
//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));
}
示例3: FormValidator
/**
* add a form for set WCAG content (replace FCK)
* @version 1.1
*/
function &prepare_admin_form($xhtml, &$form)
{
$values = WCAG_Rendering::extract_data($xhtml);
if ($form == null) {
$form = new FormValidator('waiForm');
}
$form->addElement('textarea', 'text', get_lang('WCAGContent'));
$file =& $form->addElement('text', 'imagefile', get_lang('WCAGImage'));
$form->addElement('text', 'imageLabel', get_lang('WCAGLabel'));
$form->addElement('text', 'link', get_lang('WCAGLink'));
$form->addElement('text', 'linkLabel', get_lang('WCAGLinkLabel'));
$form->setDefaults($values);
$renderer =& $form->defaultRenderer();
$element_template = '<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}<br />
<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element}<br />';
$renderer->setElementTemplate($element_template);
return $form;
}
示例4: array
echo '<br />';
echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick' => "showfck('" . $name . "', '" . $marksname . "');"));
echo '<br />';
echo '<div id="feedback_' . $name . '" style="width:100%">';
$comnt = trim(Event::get_comments($id, $questionId));
if (empty($comnt)) {
echo '<br />';
} else {
echo '<div id="question_feedback">' . $comnt . '</div>';
}
echo '</div>';
echo '<div id="' . $name . '" style="display:none">';
$arrid[] = $questionId;
$feedback_form = new FormValidator('frmcomments' . $questionId, 'post', '');
$feedback_form->addElement('html', '<br>');
$renderer =& $feedback_form->defaultRenderer();
$renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
$renderer->setCustomElementTemplate('<div align="left">{element}</div>');
$comnt = Event::get_comments($id, $questionId);
$default = array('comments_' . $questionId => $comnt);
if ($useAdvancedEditor) {
$feedback_form->addElement('html_editor', 'comments_' . $questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
} else {
$feedback_form->addElement('textarea', 'comments_' . $questionId);
}
$feedback_form->addElement('html', '<br>');
$feedback_form->setDefaults($default);
$feedback_form->display();
echo '</div>';
} else {
$comnt = Event::get_comments($id, $questionId);
示例5: createAnswersForm
/**
* 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
//.........这里部分代码省略.........
示例6: pathinfo
//.........这里部分代码省略.........
}
/* foreach($arrHide as $key => $value){
$select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
if($key==$s_selected_position && $action == 'add'){
$select_prerequisites -> setSelected(0);
}
elseif($key==$id_prerequisite && $action == 'edit'){
$select_prerequisites -> setSelected($id_prerequisite);
}
}
*/
if (!$no_display_add) {
if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
if (isset($_POST['content'])) {
$content = stripslashes($_POST['content']);
} elseif (is_array($extra_info)) {
//If it's an html document or a text file
if (!$no_display_edit_textarea) {
$content = $this->display_document($extra_info['path'], false, false);
}
} elseif (is_numeric($extra_info)) {
$content = $this->display_document($extra_info, false, false);
} else {
$content = '';
}
if (!$no_display_edit_textarea) {
// We need to claculate here some specific settings for the online editor.
// The calculated settings work for documents in the Documents tool
// (on the root or in subfolders).
// For documents in native scorm packages it is unclear whether the
// online editor should be activated or not.
$relative_path = $extra_info['dir'];
if ($relative_path == 'n/') {
// A new document, it is in the root of the repository.
$relative_path = '';
$relative_prefix = '';
} else {
// The document already exists. Whe have to determine its relative path towards the repository root.
$relative_path = explode('/', $relative_path);
$cnt = count($relative_path) - 2;
if ($cnt < 0) {
$cnt = 0;
}
$relative_prefix = str_repeat('../', $cnt);
$relative_path = array_slice($relative_path, 1, $cnt);
$relative_path = implode('/', $relative_path);
if (strlen($relative_path) > 0) {
$relative_path = $relative_path . '/';
}
}
$editor_config = array('ToolbarSet' => api_is_allowed_to_edit() ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '700', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/', 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path);
if ($_GET['action'] == 'add_item') {
$class = 'save';
$text = get_lang('Validate');
} else {
if ($_GET['action'] == 'edit_item') {
$class = 'save';
$text = get_lang('SaveDocument');
}
}
$form->addElement('html', '<div style="float:right;margin-top:-55px">');
$form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
$form->addElement('html', '</div>');
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('{label}{element}', 'content_lp');
//$form->addElement('html', '<div');
$form->addElement('html_editor', 'content_lp', '', null, $editor_config);
//$form->addElement('html', '</div>');
$defaults["content_lp"] = $content;
}
} elseif (is_numeric($extra_info)) {
$form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
$return = $this->display_document($extra_info, true, true, true);
$form->addElement('html', $return);
}
}
}
// Add template to content
if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
$defaults["content_lp"] = $valcontent;
$defaults["title"] = $valtitle;
}
if ($action == 'move') {
$form->addElement('hidden', 'title', $item_title);
$form->addElement('hidden', 'description', $item_description);
}
if (is_numeric($extra_info)) {
$form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save" style="float:right"');
$form->addElement('hidden', 'path', $extra_info);
} elseif (is_array($extra_info)) {
$form->addElement('html', '<div style="float:right;margin-top:-55px">');
$form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
$form->addElement('hidden', 'path', $extra_info['path']);
$form->addElement('html', '</div>');
}
$form->addElement('hidden', 'type', TOOL_DOCUMENT);
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
return $form->return_form();
}
示例7: createAnswersForm
/**
* 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>');
//.........这里部分代码省略.........
示例8: createAnswersForm
//.........这里部分代码省略.........
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 = $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;
} 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" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $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' => 'span2', '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->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
}
$form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0'));
$form->addElement('html', '</tr>');
}
$form->addElement('html', '</table>');
$form->addElement('html', '<br />');
$navigator_info = api_get_navigator();
global $text, $class;
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
$form->addElement('submit', 'submitQuestion', $text, 'class="' . $class . '"');
} else {
//setting the save button here and not in the question class.php
$form->addElement('style_submit_button', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
$form->addElement('style_submit_button', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
$form->addElement('style_submit_button', 'submitQuestion', $text, 'class="' . $class . '"');
}
}
$renderer->setElementTemplate('{element} ', 'submitQuestion');
$renderer->setElementTemplate('{element} ', 'lessAnswers');
$renderer->setElementTemplate('{element} ', 'moreAnswers');
$form->addElement('html', '</div></div>');
// 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));
}
示例9: Answer
<?php
$id = $_REQUEST['question'];
$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 FormValidator('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"/>
示例10: createAnswersForm
/**
* 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]);
}
示例11: handle_search
/**
* Search options
* TODO: support for multiple site. aka $_configuration['access_url'] == 1
* @author Marco Villegas <marvil07@gmail.com>
*/
function handle_search()
{
global $SettingsStored, $_configuration;
$search_enabled = api_get_setting('search_enabled');
$settings = api_get_settings('Search');
if ($search_enabled !== 'true' || count($settings) < 1) {
Display::display_error_message(get_lang('SearchFeatureNotEnabledComment'));
return;
}
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$form = new FormValidator('search-options', 'post', api_get_self() . '?category=Search');
$renderer =& $form->defaultRenderer();
$renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>' . "\n");
$renderer->setElementTemplate('<div class="sectioncomment">{label}</div>' . "\n" . '<div class="sectionvalue">{element}</div>' . "\n");
//search_show_unlinked_results
$form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle'));
$form->addElement('label', null, get_lang('SearchShowUnlinkedResultsComment'));
$values = get_settings_options('search_show_unlinked_results');
$group = array();
foreach ($values as $key => $value) {
$element =& $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
$group[] = $element;
}
$form->addGroup($group, 'search_show_unlinked_results', get_lang('SearchShowUnlinkedResultsComment'), '<br />', false);
$default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results');
//search_prefilter_prefix
$form->addElement('header', null, get_lang('SearchPrefilterPrefix'));
$form->addElement('label', null, get_lang('SearchPrefilterPrefixComment'));
$specific_fields = get_specific_field_list();
$sf_values = array();
foreach ($specific_fields as $sf) {
$sf_values[$sf['code']] = $sf['name'];
}
$group = array();
$form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
$default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
//$form->addRule('search_show_unlinked_results', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('style_submit_button', 'search-options-save', get_lang('Ok'));
$form->setDefaults($default_values);
if ($form->validate()) {
$formvalues = $form->exportValues();
$r = api_set_settings_category('Search', 'false', $_configuration['access_url']);
// Save the settings
foreach ($formvalues as $key => $value) {
$result = api_set_setting($key, $value, null, null);
}
Display::display_normal_message($SettingsStored);
} else {
echo '<div id="search-options-form">';
$form->display();
echo '</div>';
}
}
示例12: display_item_form
//.........这里部分代码省略.........
$defaults['title'] = !empty($item_title) ? api_html_entity_decode($item_title, ENT_QUOTES, $charset) : '';
$defaults['description'] = $item_description;
$form->addElement('header', $title);
//$arrHide = array($id);
$arrHide[0]['value'] = Security::remove_XSS($this->name);
$arrHide[0]['padding'] = 20;
$charset = api_get_system_encoding();
if ($item_type != 'module' && $item_type != 'dokeos_module') {
for ($i = 0; $i < count($arrLP); $i++) {
if ($action != 'add') {
if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
$arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
if ($parent == $arrLP[$i]['id']) {
$s_selected_parent = $arrHide[$arrLP[$i]['id']];
}
}
} else {
if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
$arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
if ($parent == $arrLP[$i]['id']) {
$s_selected_parent = $arrHide[$arrLP[$i]['id']];
}
}
}
}
if ($action != 'move') {
$form->addElement('text', 'title', get_lang('Title'));
$form->applyFilter('title', 'html_filter');
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
} else {
$form->addElement('hidden', 'title');
}
$parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', array('id' => 'idParent', 'onchange' => "javascript: load_cbo(this.value);"));
foreach ($arrHide as $key => $value) {
$parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
}
if (!empty($s_selected_parent)) {
$parent_select->setSelected($s_selected_parent);
}
}
if (is_array($arrLP)) {
reset($arrLP);
}
$arrHide = array();
// POSITION
for ($i = 0; $i < count($arrLP); $i++) {
if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
//this is the same!
if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
$s_selected_position = $arrLP[$i]['id'];
} elseif ($action == 'add') {
$s_selected_position = $arrLP[$i]['id'];
}
$arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
}
}
$position = $form->addElement('select', 'previous', get_lang('Position'), '', array('id' => 'previous'));
$padding = isset($value['padding']) ? $value['padding'] : 0;
$position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
foreach ($arrHide as $key => $value) {
$position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
}
if (!empty($s_selected_position)) {
$position->setSelected($s_selected_position);
}
if (is_array($arrLP)) {
reset($arrLP);
}
$form->addButtonSave(get_lang('SaveSection'), 'submit_button');
if ($item_type == 'module' || $item_type == 'dokeos_module') {
$form->addElement('hidden', 'parent', '0');
}
//fix in order to use the tab
if ($item_type == 'chapter') {
$form->addElement('hidden', 'type', 'chapter');
}
$extension = null;
if (!empty($item_path)) {
$extension = pathinfo($item_path, PATHINFO_EXTENSION);
}
//assets can't be modified
//$item_type == 'asset' ||
if ($item_type == 'sco' && ($extension == 'html' || $extension == 'htm')) {
if ($item_type == 'sco') {
$form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
}
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
$editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true);
$form->addHtmlEditor('content_lp', '', false, false, $editor_config);
$content_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . $item_path_fck;
$defaults['content_lp'] = file_get_contents($content_path);
}
$form->addElement('hidden', 'type', 'dokeos_' . $item_type);
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
return $form->return_form();
}
示例13: createAnswersForm
/**
* function which redefines Question::createAnswersForm
* @param FormValidator $form
*/
public function createAnswersForm($form)
{
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
// The previous default value was 2. See task #1759.
$nb_answers += isset($_POST['lessAnswers']) ? -1 : isset($_POST['moreAnswers']) ? 1 : 0;
$course_id = api_get_course_int_id();
$obj_ex = $_SESSION['objExercise'];
$renderer =& $form->defaultRenderer();
$defaults = array();
$html = '<table class="table table-striped table-hover">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>' . get_lang('Number') . '</th>';
$html .= '<th>' . get_lang('True') . '</th>';
$html .= '<th>' . get_lang('False') . '</th>';
$html .= '<th>' . get_lang('Answer') . '</th>';
// show column comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$html .= '<th>' . get_lang('Comment') . '</th>';
}
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$form->addHeader(get_lang('Answers'));
$form->addHtml($html);
$correct = 0;
$answer = null;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form->addElement('hidden', 'nb_answers');
$boxes_names = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
// Can be more options
$option_data = Question::readQuestionOption($this->id, $course_id);
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addHtml('<tr>');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze();
if (is_object($answer)) {
$defaults['answer[' . $i . ']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i];
$correct = $answer->correct[$i];
$defaults['correct[' . $i . ']'] = $correct;
$j = 1;
if (!empty($option_data)) {
foreach ($option_data as $id => $data) {
$form->addElement('radio', 'correct[' . $i . ']', null, null, $id);
$j++;
if ($j == 3) {
break;
}
}
}
} else {
$form->addElement('radio', 'correct[' . $i . ']', null, null, 1);
$form->addElement('radio', 'correct[' . $i . ']', null, null, 2);
$defaults['answer[' . $i . ']'] = '';
$defaults['comment[' . $i . ']'] = '';
$defaults['correct[' . $i . ']'] = '';
}
$boxes_names[] = 'correct[' . $i . ']';
$form->addHtmlEditor("answer[{$i}]", get_lang('ThisFieldIsRequired'), true, true, ['ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100']);
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
$form->addHtml('</tr>');
}
$form->addHtml('</tbody></table>');
$correctInputTemplate = '<div class="form-group">';
$correctInputTemplate .= '<label class="col-sm-2 control-label">';
$correctInputTemplate .= '<span class="form_required">*</span>' . get_lang('Score');
$correctInputTemplate .= '</label>';
$correctInputTemplate .= '<div class="col-sm-8">';
$correctInputTemplate .= '<table>';
$correctInputTemplate .= '<tr>';
$correctInputTemplate .= '<td>';
$correctInputTemplate .= get_lang('Correct') . '{element}';
$correctInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
$correctInputTemplate .= '</td>';
$wrongInputTemplate = '<td>';
$wrongInputTemplate .= get_lang('Wrong') . '{element}';
$wrongInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
$wrongInputTemplate .= '</td>';
//.........这里部分代码省略.........
示例14: display_document_form
//.........这里部分代码省略.........
if ($value['id'] == $id) {
$id_prerequisite = $value['prerequisite'];
break;
}
}
}
$arrHide = array();
for ($i = 0; $i < count($arrLP); $i++) {
if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
$s_selected_position = $arrLP[$i]['id'];
} elseif ($action == 'add') {
$s_selected_position = $arrLP[$i]['id'];
}
$arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
}
}
if (!$no_display_add) {
if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
if (isset($_POST['content'])) {
$content = stripslashes($_POST['content']);
} elseif (is_array($extra_info)) {
//If it's an html document or a text file
if (!$no_display_edit_textarea) {
$content = $this->display_document($extra_info['path'], false, false);
}
} elseif (is_numeric($extra_info)) {
$content = $this->display_document($extra_info, false, false);
} else {
$content = '';
}
if (!$no_display_edit_textarea) {
// We need to calculate here some specific settings for the online editor.
// The calculated settings work for documents in the Documents tool
// (on the root or in subfolders).
// For documents in native scorm packages it is unclear whether the
// online editor should be activated or not.
// A new document, it is in the root of the repository.
$relative_path = '';
$relative_prefix = '';
if (is_array($extra_info) && $extra_info != 'new') {
// The document already exists. Whe have to determine its relative path towards the repository root.
$relative_path = explode('/', $extra_info['dir']);
$cnt = count($relative_path) - 2;
if ($cnt < 0) {
$cnt = 0;
}
$relative_prefix = str_repeat('../', $cnt);
$relative_path = array_slice($relative_path, 1, $cnt);
$relative_path = implode('/', $relative_path);
if (strlen($relative_path) > 0) {
$relative_path = $relative_path . '/';
}
} else {
$_course = api_get_course_info();
$result = $this->generate_lp_folder($_course);
$relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
$relative_prefix = '../../';
}
$editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path);
if ($_GET['action'] == 'add_item') {
$class = 'add';
$text = get_lang('LPCreateDocument');
} else {
if ($_GET['action'] == 'edit_item') {
$class = 'save';
$text = get_lang('SaveDocument');
}
}
$form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<br /> {label}<br />{element}', 'content_lp');
$form->addElement('html', '<div>');
$form->addElement('html_editor', 'content_lp', '', null, $editor_config);
$form->addElement('html', '</div>');
$defaults['content_lp'] = $content;
}
} elseif (is_numeric($extra_info)) {
$form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
$return = $this->display_document($extra_info, true, true, true);
$form->addElement('html', $return);
}
}
}
if ($action == 'move') {
$form->addElement('hidden', 'title', $item_title);
$form->addElement('hidden', 'description', $item_description);
}
if (is_numeric($extra_info)) {
$form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
$form->addElement('hidden', 'path', $extra_info);
} elseif (is_array($extra_info)) {
$form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
$form->addElement('hidden', 'path', $extra_info['path']);
}
$form->addElement('hidden', 'type', TOOL_DOCUMENT);
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
return $form->return_form();
}
示例15: array
$renderersetCustomElementTemplate->setCustomElementTemplate('<tr><td>{element}</td></tr>');
$form->addElement('html', $option1);
$form->addElement('checkbox', 'left', null, get_lang('Yes'));
$form->addElement('button', 'submit', get_lang('Confirm'), array('class' => 'btn btn-primary'));
$formHtml = $form->return_form();
if ($form->validate()) {
$result = $form->getSubmitValues();
if (isset($result['left']) && $result['left']) {
$_SESSION['before_login_accepted'] = 1;
header('Location: ' . $urlOption1);
exit;
}
}
$form2 = new FormValidator('form');
if (!empty($option2) && !empty($urlOption2)) {
$renderer =& $form2->defaultRenderer();
$renderer->setHeaderTemplate('');
$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
$renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
$form2->addElement('html', $option2);
$form2->addElement('checkbox', 'right', null, get_lang('Yes'));
$form2->addElement('button', 'submit', get_lang('Send'));
$formHtml2 = $form2->return_form();
if ($form2->validate()) {
$result = $form2->getSubmitValues();
if (isset($result['right']) && $result['right']) {
header('Location: ' . $urlOption2);
exit;
}
}
}