本文整理汇总了PHP中api_get_navigator函数的典型用法代码示例。如果您正苦于以下问题:PHP api_get_navigator函数的具体用法?PHP api_get_navigator怎么用?PHP api_get_navigator使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_get_navigator函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listing
/**
* It's used for listing course description,
* render to listing view
* @param boolean true for listing history (optional)
* @param array message for showing by action['edit','add','destroy'] (optional)
*/
public function listing($history = false, $messages = array())
{
$course_description = new CourseDescription();
$session_id = api_get_session_id();
$course_description->set_session_id($session_id);
$data = array();
$course_description_data = $course_description->get_description_data();
$data['descriptions'] = isset($course_description_data['descriptions']) ? $course_description_data['descriptions'] : '';
$data['default_description_titles'] = $course_description->get_default_description_title();
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
$data['default_description_icon'] = $course_description->get_default_description_icon();
$data['messages'] = $messages;
$browser = api_get_navigator();
if (!is_array($data['descriptions'])) {
$data['descriptions'] = array($data['descriptions']);
}
foreach ($data['descriptions'] as $description) {
if (!empty($description['content']) && strpos($description['content'], '<iframe') !== false && $browser['name'] == 'Chrome') {
header("X-XSS-Protection: 0");
}
}
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('listing');
$this->view->render();
}
示例2: set_css_files
/**
* Set theme, include CSS files
*/
public function set_css_files()
{
global $disable_js_and_css_files;
$css = array();
$this->theme = api_get_visual_theme();
if (!empty($this->preview_theme)) {
$this->theme = $this->preview_theme;
}
//Base CSS
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'base.css');
//Default CSS responsive design
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'bootstrap-responsive.css');
//Extra CSS files
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css';
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css';
if (api_is_global_chat_enabled()) {
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/chat/css/chat.css';
}
$css[] = api_get_path(WEB_CSS_PATH).'font_awesome/css/font-awesome.css';
$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/mediaelementplayer.css';
//THEME CSS STYLE
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'responsive.css');
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/default.css');
if ($this->show_learnpath) {
$css[] = api_get_path(WEB_CSS_PATH).$this->theme.'/learnpath.css';
// if we have a SCORM file in theme, don't use default_scorm.css file
if (is_file(api_get_path(SYS_CSS_PATH).$this->theme.'/scorm.css')) {
$css[] = api_get_path(WEB_CSS_PATH).$this->theme.'/scorm.css';
} else {
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH).'default_scorm.css');
}
}
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) {
//hack in order to fix the actions buttons
$css_file_to_string .= '<style>
.td_actions a {
float:left;
width:100%;
}
.forum_message_left a {
float:left;
width:100%;
}
</style>';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$css_file_to_string .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } '."\n";
}
if (!$disable_js_and_css_files) {
$this->assign('css_file_to_string', $css_file_to_string);
$style_print = api_get_css(api_get_cdn_path(api_get_path(WEB_CSS_PATH).$this->theme.'/print.css'), 'print');
$this->assign('css_style_print', $style_print);
}
// Logo
$logo = return_logo($this->theme);
$this->assign('logo', $logo);
}
示例3: 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));
}
示例4: search_widget_normal_form
/**
* Build the normal form.
*
* First, natural way.
*/
function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op)
{
$thesaurus_icon = Display::return_icon('thesaurus.gif', get_lang('SearchAdvancedOptions'), array('id' => 'thesaurus-icon'));
$advanced_options = '<a id="tags-toggle" href="#">' . get_lang('SearchAdvancedOptions') . '</a>';
$display_thesaurus = $show_thesaurus == true ? 'block' : 'none';
$help = '<h3>' . get_lang('SearchKeywordsHelpTitle') . '</h3>' . get_lang('SearchKeywordsHelpComment');
$mode = !empty($_REQUEST['mode']) ? htmlentities($_REQUEST['mode']) : 'gallery';
$type = !empty($_REQUEST['type']) ? htmlentities($_REQUEST['type']) : 'normal';
/**
* POST avoid long urls, but we are using GET because
* SortableTableFromArray pagination is done with simple links, so now we
* could not send a form in pagination
*/
if (isset($_GET['action']) && strcmp(trim($_GET['action']), 'search') === 0) {
$action = 'index.php';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$submit_button1 = '<input type="submit" id="submit" value="' . get_lang('Search') . '" />';
$submit_button2 = '<input class="lower-submit" type="submit" value="' . get_lang('Search') . '" />';
$reset_button = '<input type="submit" id="tags-clean" value="' . get_lang('SearchResetKeywords') . '" />';
} else {
$submit_button1 = '<button class="search" type="submit" id="submit" value="' . get_lang("Search") . '" /> ' . get_lang('Search') . '</button>';
$submit_button2 = '<button class="search" type="submit" value="' . get_lang('Search') . '" />' . get_lang('Search') . '</button>';
$reset_button = '<button class="save" type="submit" id="tags-clean" value="' . get_lang('SearchResetKeywords') . '" />' . get_lang('SearchResetKeywords') . '</button> ';
}
$query = isset($_REQUEST['query']) ? Security::remove_XSS($_REQUEST['query']) : null;
$form = '<form id="chamilo_search" action="' . $action . '" method="GET">
<input type="text" id="query" name="query" size="40" value="' . $query . '" />
<input type="hidden" name="mode" value="' . $mode . '"/>
<input type="hidden" name="type" value="' . $type . '"/>
<input type="hidden" name="tablename_page_nr" value="1" />
' . $submit_button1 . '
<br /><br />';
$list = get_specific_field_list();
if (!empty($list)) {
$form .= '<span class="search-links-box">' . $advanced_options . ' </span>
<div id="tags" class="tags" style="display:' . $display_thesaurus . ';">
<div class="search-help-box">' . $help . '</div>
<table>
<tr>';
$form .= format_specific_fields_selects($sf_terms, $op);
$or_checked = '';
$and_checked = '';
if ($op == 'or') {
$or_checked = 'checked="checked"';
} else {
if ($op == 'and') {
$and_checked = 'checked="checked"';
}
}
$form .= '</tr>
<tr>
<td id="operator-select">
' . get_lang('SearchCombineSearchWith') . ':<br />
<input type="radio" class="search-operator" name="operator" value="or" ' . $or_checked . '>' . api_strtoupper(get_lang('Or')) . '</input>
<input type="radio" class="search-operator" name="operator" value="and" ' . $and_checked . '>' . api_strtoupper(get_lang('And')) . '</input>
</td>
<td></td>
<td>
<br />
' . $reset_button . '
' . $submit_button2 . '
</td>
</tr>
</table>
</div>';
}
$form .= '</form>
<br style="clear: both;"/>';
return $form;
}
示例5: api_get_self
$toolbar .= "<a class=\"btn btn-default\" href=\"" . api_get_self() . "?" . api_get_cidreq() . "&intro_cmdDel=1\" onclick=\"javascript:\n if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)) . "')) return false;\"><em class=\"fa fa-trash-o\"></em></a>";
}
$toolbar .= "</div>";
// Fix for chrome XSS filter for videos in iframes - BT#7930
$browser = api_get_navigator();
if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
header('X-XSS-Protection: 0');
}
}
}
$introduction_section .= '<div class="col-md-12">';
if ($intro_dispDefault) {
if (!empty($intro_content)) {
$introduction_section .= '<div class="page-course">';
$introduction_section .= $intro_content;
$introduction_section .= '</div>';
} else {
if (api_is_allowed_to_edit()) {
$introduction_section .= '<div class="help-course">';
$introduction_section .= get_lang('AddCustomCourseIntro') . ' ' . $textIntro;
$introduction_section .= '</div>';
}
}
}
$introduction_section .= $toolbar;
$introduction_section .= '</div>';
$introduction_section .= '</div>';
$browser = api_get_navigator();
if (strpos($introduction_section, '<iframe') !== false && $browser['name'] == 'Chrome') {
header("X-XSS-Protection: 0");
}
示例6: setCssCustomFiles
/**
* Prepare custom CSS to be added at the very end of the <head> section
* @return void
* @see setCssFiles() for the mainstream CSS files
*/
public function setCssCustomFiles()
{
global $disable_js_and_css_files;
// Base CSS
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH) . 'base.css');
if ($this->show_learnpath) {
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH) . 'scorm.css');
if (is_file(api_get_path(SYS_CSS_PATH) . 'themes/' . $this->theme . '/learnpath.css')) {
$css[] = api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/learnpath.css';
}
}
$css[] = api_get_cdn_path(api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/default.css');
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) {
//hack in order to fix the actions buttons
$css_file_to_string .= '<style>
.td_actions a {
float:left;
width:100%;
}
.forum_message_left a {
float:left;
width:100%;
}
</style>';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$css_file_to_string .= 'img, div { behavior: url(' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/iepngfix/iepngfix.htc) } ' . "\n";
}
if (!$disable_js_and_css_files) {
$this->assign('css_custom_file_to_string', $css_file_to_string);
$style_print = '';
if (is_readable(api_get_path(SYS_CSS_PATH) . $this->theme . '/print.css')) {
$style_print = api_get_css(api_get_cdn_path(api_get_path(WEB_CSS_PATH) . $this->theme . '/print.css'), 'print');
}
$this->assign('css_style_print', $style_print);
}
// Logo
$logo = return_logo($this->theme);
$this->assign('logo', $logo);
$this->assign('show_media_element', 1);
}
示例7: createAnswersForm
/**
* function which redefines Question::createAnswersForm
* @param the FormValidator
*/
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['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];
//------------- D�but
$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;
} else {
$defaults['pts'] = 0;
}
$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->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', 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');
$navigator_info = api_get_navigator();
global $text, $class;
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
//.........这里部分代码省略.........
示例8: api_get_path
if (!empty($msgErr)) {
Display::display_normal_message($msgErr);
//main API
}
$hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidreq() . '&hotspotadmin=' . $modifyAnswers . '&exerciseId=' . $exerciseId;
?>
<form method="post" action="<?php
echo $hotspot_admin_url;
?>
" id="frm_exercise" name="frm_exercise">
<table border="0" cellpadding="0" cellspacing="2" width="100%">
<tr>
<td colspan="2" valign="bottom">
<?php
$navigator_info = api_get_navigator();
//ie6 fix
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
?>
<?php
if ($answerType == HOT_SPOT_DELINEATION) {
?>
<input type="submit" class="btn minus" name="lessAnswers" value="<?php
echo get_lang('LessOAR');
?>
" >
<input type="submit" class="btn plus" name="moreOARAnswers" value="<?php
echo get_lang('MoreOAR');
?>
" />
<?php
示例9: createAnswersForm
/**
* function which redefines Question::createAnswersForm
* @param FormValidator instance
*/
public 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 = $this->exercise;
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
' . get_lang('Number') . '
</th>
<th width="10px">
' . get_lang('True') . '
</th>
<th width="50%">
' . 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>';
$form->addElement('label', get_lang('Answers') . '<br />' . Display::return_icon('fill_field.png'), $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');
$boxes_names = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_answers; ++$i) {
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer[' . $i . ']'] = $answer->answer[$answer_id];
$defaults['comment[' . $i . ']'] = $answer->comment[$answer_id];
$defaults['weighting[' . $i . ']'] = Text::float_format($answer->weighting[$answer_id], 1);
$defaults['correct[' . $i . ']'] = $answer->correct[$answer_id];
} 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 . ']';
if ($obj_ex->fastEdition) {
$form->addElement('textarea', 'answer[' . $i . ']', null, $this->textareaSettings);
} else {
$form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement('textarea', 'comment[' . $i . ']', null, $this->textareaSettings);
} else {
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
}
//only 1 answer the all deal ...
//$form->addElement('text', 'weighting['.$i.']',null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="10"');
$form->addElement('html', '</tr>');
}
$form->addElement('html', '</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'), array('class' => "span1", 'value' => '10'));
$navigator_info = api_get_navigator();
//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', $this->submitText, 'class="' . $this->submitClass . '"');
} else {
$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', $this->submitText, 'class="' . $this->submitClass . '"');
// setting the save button here and not in the question class.php
//.........这里部分代码省略.........
示例10: createAnswersForm
//.........这里部分代码省略.........
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->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
}
$form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", '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->addElement('html', '<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->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_END) {
// feedback
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', $editor_config);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
}
//$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple');
$form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0', 'readonly' => 'readonly'));
$form->addElement('html', '</tr>');
//}
$form->addElement('html', '</table>');
$form->addElement('html', '<br />');
$navigator_info = api_get_navigator();
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$form->addElement('submit', 'moreAnswers', get_lang('PlusAnswer'), 'class="btn plus"');
$form->addElement('submit', 'lessAnswers', get_lang('LessAnswer'), 'class="btn minus"');
$form->addElement('submit', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
} 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', $this->submitText, 'class="' . $this->submitClass . '"');
}
}
$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 {
$form->setDefaults($defaults);
}
$form->addElement('hidden', 'nb_answers');
$form->setConstants(array('nb_answers' => $nb_answers));
}
示例11: createAnswersForm
/**
* Redefines Question::createAnswersForm
* @param the formvalidator instance
*/
function createAnswersForm($form)
{
$defaults = array();
$navigator_info = api_get_navigator();
$nb_matches = $nb_options = 2;
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) {
$a_matches = $a_options = array();
$nb_matches = $nb_options = 0;
foreach ($answer->answer as $i => $answer_item) {
if ($answer->isCorrect($i)) {
$nb_matches++;
$defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
$defaults['weighting[' . $nb_matches . ']'] = Text::float_format($answer->selectWeighting($i), 1);
$correct_answer_id = $answer->correct[$i];
$defaults['matches[' . $nb_matches . ']'] = $answer->getCorrectAnswerPosition($correct_answer_id);
} 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');
}
}
$a_matches = array();
for ($i = 1; $i <= $nb_options; ++$i) {
// fill the array with A, B, C.....
$a_matches[$i] = chr(64 + $i);
}
$form->addElement('hidden', 'nb_matches', $nb_matches);
$form->addElement('hidden', 'nb_options', $nb_options);
// DISPLAY MATCHES
$html = '<table class="data_table">
<tr>
<th width="10px">
' . get_lang('Number') . '
</th>
<th width="40%">
' . get_lang('Answer') . '
</th>
<th width="40%">
' . get_lang('MatchesTo') . '
</th>
<th width="50px">
' . get_lang('Weighting') . '
</th>
</tr>';
$form->addElement('label', get_lang('MakeCorrespond') . '<br /> ' . Display::return_icon('fill_field.png'), $html);
if ($nb_matches < 1) {
$nb_matches = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_matches; ++$i) {
$form->addElement('html', '<tr><td>');
$group = array();
$puce = $form->createElement('text', null, null, 'value="' . $i . '"');
$puce->freeze();
$group[] = $puce;
$group[] = $form->createElement('text', 'answer[' . $i . ']', null, 'size="60" style="margin-left: 0em;"');
$group[] = $form->createElement('select', 'matches[' . $i . ']', null, $a_matches);
$group[] = $form->createElement('text', 'weighting[' . $i . ']', null, array('class' => 'span1', 'value' => 10));
$form->addGroup($group, null, null, '</td><td>');
$form->addElement('html', '</td></tr>');
}
$form->addElement('html', '</table></div></div>');
$group = array();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$group[] = $form->createElement('submit', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
$group[] = $form->createElement('submit', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
} else {
$group[] = $form->createElement('style_submit_button', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
$group[] = $form->createElement('style_submit_button', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
//.........这里部分代码省略.........
示例12: setCssFiles
/**
* Set theme, include CSS files
*/
private function setCssFiles()
{
global $disable_js_and_css_files;
$css = array();
$this->theme = api_get_visual_theme();
if (isset($_POST['style']) && api_is_platform_admin()) {
$this->preview_theme = $_POST['style'];
}
if (!empty($this->preview_theme)) {
$this->theme = $this->preview_theme;
}
$this->app['theme'] = $this->theme;
$cssPath = api_get_path(WEB_CSS_PATH);
// Loads only 1 css file
if ($this->app['assetic.enabled']) {
$css[] = api_get_path(WEB_PUBLIC_PATH) . 'css/' . $this->theme . '/style.css';
} else {
// Bootstrap
$css[] = api_get_cdn_path(api_get_path(WEB_LIBRARY_PATH) . 'javascript/bootstrap/css/bootstrap.css');
//$css[] = api_get_cdn_path(api_get_path(WEB_LIBRARY_PATH).'javascript/bootstrap/css/bootstrap-theme.css');
// Base CSS.
$css[] = api_get_cdn_path($cssPath . 'base.css');
// Default theme CSS.
$css[] = api_get_cdn_path($cssPath . $this->theme . '/default.css');
// Extra CSS files.
if ($this->show_learnpath) {
//$css[] = $cssPath.$this->theme.'/learnpath.css';
//$css[] = $cssPath.$this->theme.'/scorm.css';
}
if (api_is_global_chat_enabled()) {
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chat/css/chat.css';
}
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-ui/css/' . $this->jquery_ui_theme . '/jquery-ui-custom.css';
//$css[] = api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/default.css';
}
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/font-awesome/css/font-awesome.css';
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css';
$css[] = api_get_path(WEB_LIBRARY_PATH) . 'javascript/chosen/chosen.css';
$css_file_to_string = null;
foreach ($css as $file) {
$css_file_to_string .= api_get_css($file);
}
// @todo move this somewhere else. Special fix when using tablets in order to see the text near icons
if (SHOW_TEXT_NEAR_ICONS == true) {
//hack in order to fix the actions buttons
$css_file_to_string .= '<style>
.td_actions a {
float:left;
width:100%;
}
.forum_message_left a {
float:left;
width:100%;
}
</style>';
}
$navigator_info = api_get_navigator();
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
$css_file_to_string .= 'img, div { behavior: url(' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/iepngfix/iepngfix.htc) } ' . "\n";
}
if (!$disable_js_and_css_files) {
$this->assign('css_file_to_string', $css_file_to_string);
$style_print = api_get_css(api_get_cdn_path($cssPath . $this->theme . '/print.css'), 'print');
$this->assign('css_style_print', $style_print);
}
}
示例13: createAnswersForm
//.........这里部分代码省略.........
$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 (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer[' . $i . ']'] = $answer->answer[$answer_id];
$defaults['comment[' . $i . ']'] = $answer->comment[$answer_id];
$correct = $answer->correct[$answer_id];
$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 . ']';
if ($obj_ex->fastEdition) {
$form->addElement('textarea', 'answer[' . $i . ']', null, $this->textareaSettings);
} else {
$form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
if ($obj_ex->fastEdition) {
$form->addElement('textarea', 'comment[' . $i . ']', null, $this->textareaSettings);
} else {
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
}
$form->addElement('html', '</tr>');
}
$form->addElement('html', '</table>');
$form->addElement('html', '<br />');
$form->addElement('html', '<table><tr><td></td><td>' . get_lang('Correct') . '</td><td>' . get_lang('Wrong') . '</td><td>' . get_lang('DoubtScore') . '</td></tr>');
$renderer->setElementTemplate('<tr><td><span class="form_required">*</span>' . get_lang('Score') . ' </td><td>{element} <br /><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --></td>', 'option[1]');
$renderer->setElementTemplate('<td>{element} <br /><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --></td>', 'option[2]');
$renderer->setElementTemplate('<td>{element} <br /><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --></td>', 'option[3]');
// 3 scores
$form->addElement('text', 'option[1]', get_lang('Correct'), array('class' => 'span1', 'value' => '1'));
$form->addElement('text', 'option[2]', get_lang('Wrong'), array('class' => 'span1', 'value' => '-0.5'));
$form->addElement('text', 'option[3]', get_lang('DoubtScore'), array('class' => 'span1', 'value' => '0'));
$form->addRule('option[1]', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('option[2]', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('option[3]', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html', '</tr><table>');
$form->addElement('hidden', 'options_count', 3);
$form->addElement('html', '</table><br /><br />');
//Extra values True, false, Dont known
if (!empty($this->extra)) {
$scores = explode(':', $this->extra);
if (!empty($scores)) {
for ($i = 1; $i <= 3; $i++) {
$defaults['option[' . $i . ']'] = $scores[$i - 1];
}
}
}
//$form -> add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
$navigator_info = api_get_navigator();
if ($obj_ex->edit_exercise_in_lp == true) {
//ie6 fix
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', $this->submitText, 'class="' . $this->submitClass . '"');
} 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', $this->submitText, 'class="' . $this->submitClass . '"');
}
}
$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));
}
示例14: createAnswersForm
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
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);
$obj_ex = $_SESSION['objExercise'];
$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>';
// show column comment when feedback is enable
$html .= '<th>
' . get_lang('Comment') . '
</th>';
$html .= '<th width="50px">
' . get_lang('Weighting') . '
</th>
</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;
}
}
$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) {
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;
$defaults['weighting[2]'] = -5;
}
$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" style="margin-left: 0em;"');
$boxes_names[] = 'correct[' . $i . ']';
$form->addElement('html_editor', 'answer[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html_editor', 'comment[' . $i . ']', null, 'style="vertical-align:middle"', array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addElement('text', 'weighting[' . $i . ']', null, array('class' => "span1", 'value' => '0'));
$form->addElement('html', '</tr>');
}
$form->addElement('html', '</table>');
$form->addElement('html', '<br />');
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
$navigator_info = api_get_navigator();
global $text, $class;
if ($obj_ex->edit_exercise_in_lp == true) {
//ie6 fix
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} ', 'lessAnswers');
$renderer->setElementTemplate('{element} ', 'submitQuestion');
$renderer->setElementTemplate('{element} ', 'moreAnswers');
//.........这里部分代码省略.........