本文整理汇总了PHP中FormValidator::setConstants方法的典型用法代码示例。如果您正苦于以下问题:PHP FormValidator::setConstants方法的具体用法?PHP FormValidator::setConstants怎么用?PHP FormValidator::setConstants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormValidator
的用法示例。
在下文中一共展示了FormValidator::setConstants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: header
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('SignatureFormula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
}
else {
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('SignatureFormula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}*/
Security::clear_token();
$tok = Security::get_token();
header('Location: group_list.php?action=show_message&message=' . urlencode(get_lang('GroupAdded')) . '&sec_token=' . $tok);
exit;
}
} else {
if (isset($_POST['submit'])) {
Security::clear_token();
}
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
}
// Display form
Display::display_header($tool_name);
if (!empty($message)) {
Display::display_normal_message(stripslashes($message));
}
$form->display();
// Footer
Display::display_footer();
示例2: manage_form
function manage_form($default, $select_from_user_list = null, $sent_to = null)
{
$group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
$message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
$param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null;
$form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data'));
if (empty($group_id)) {
if (isset($select_from_user_list)) {
$form->addText('id_text_name', get_lang('SendMessageTo'), true, array('id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off'));
$form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" > </div>');
$form->addElement('hidden', 'user_list', 0, array('id' => 'user_list'));
} else {
if (!empty($sent_to)) {
$form->addLabel(get_lang('SendMessageTo'), $sent_to);
}
if (empty($default['users'])) {
//fb select
$form->addElement('select_ajax', 'users', get_lang('SendMessageTo'), array(), ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users']);
} else {
$form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user'));
}
}
} else {
$userGroup = new UserGroup();
$group_info = $userGroup->get($group_id);
$form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name']));
$form->addElement('hidden', 'group_id', $group_id);
$form->addElement('hidden', 'parent_id', $message_id);
}
$form->addText('title', get_lang('Subject'), true);
$form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250'));
if (isset($_GET['re_id'])) {
$message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
$default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title'];
$form->addElement('hidden', 're_id', intval($_GET['re_id']));
$form->addElement('hidden', 'save_form', 'save_form');
//adding reply mail
$user_reply_info = api_get_user_info($message_reply_info['user_sender_id']);
$default['content'] = '<p><br/></p>' . sprintf(get_lang('XWroteY'), $user_reply_info['complete_name'], Security::filter_terms($message_reply_info['content']));
}
if (empty($group_id)) {
$form->addElement('label', '', '<div id="filepaths" class="form-group">
<div id="filepath_1">
<label>' . get_lang('FilesAttachment') . '</label>
<input type="file" name="attach_1"/>
<label>' . get_lang('Description') . '</label>
<input id="file-descrtiption" type="text" name="legend[]" class="form-control"/>
</div>
</div>');
$form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span> (' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message.message_max_upload_filesize'))) . ')');
}
$form->addButtonSend(get_lang('SendMessage'), 'compose');
$form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
if (!empty($group_id) && !empty($message_id)) {
$message_info = MessageManager::get_message_by_id($message_id);
$default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title'];
}
$form->setDefaults($default);
$html = '';
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$user_list = $default['users'];
$file_comments = $_POST['legend'];
$title = $default['title'];
$content = $default['content'];
$group_id = isset($default['group_id']) ? $default['group_id'] : null;
$parent_id = isset($default['parent_id']) ? $default['parent_id'] : null;
if (is_array($user_list) && count($user_list) > 0) {
//all is well, send the message
foreach ($user_list as $user) {
$res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id);
if ($res) {
$html .= MessageManager::display_success_message($user);
}
}
} else {
Display::display_error_message('ErrorSendingMessage');
}
}
Security::clear_token();
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$html .= $form->returnForm();
}
return $html;
}
示例3: add_category_form
/**
* form to add a category
* @todo move to TestCategory.class.php
* @param string $action
*/
function add_category_form($action)
{
$action = Security::remove_XSS($action);
// initiate the object
$form = new FormValidator('note', 'post', api_get_self() . '?action=' . $action);
// Setting the form elements
$form->addElement('header', get_lang('AddACategory'));
$form->addElement('text', 'category_name', get_lang('CategoryName'), array('size' => '95'));
$form->addHtmlEditor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Height' => '200'));
$form->addButtonCreate(get_lang('AddTestCategory'), 'SubmitNote');
// setting the rules
$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$v_name = Security::remove_XSS($values['category_name'], COURSEMANAGER);
$v_description = Security::remove_XSS($values['category_description'], COURSEMANAGER);
$objcat = new TestCategory(0, $v_name, $v_description);
if ($objcat->addCategoryInBDD()) {
Display::display_confirmation_message(get_lang('AddCategoryDone'));
} else {
Display::display_confirmation_message(get_lang('AddCategoryNameAlreadyExists'));
}
}
Security::clear_token();
} else {
display_goback();
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}
示例4: createAnswersForm
//.........这里部分代码省略.........
<th width="10px">
' . get_lang('True') . '
</th>
<th width="50%">
' . get_lang('Answer') . '
</th>';
$html .= '<th>' . get_lang('Comment') . '</th>';
$html .= '</tr>';
$form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
$defaults = array();
$correct = 0;
$answer = false;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
#le nombre de r�ponses est bien enregistr� sous la forme int(nb)
/* Ajout mise en forme nb reponse */
$form->addElement('hidden', 'nb_answers');
$boxes_names = array();
/* V�rification : Cr�action d'au moins une r�ponse */
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
//D�but affichage score global dans la modification d'une question
$scoreA = "0";
//par reponse
$scoreG = "0";
//Global
/* boucle pour sauvegarder les donn�es dans le tableau defaults */
for ($i = 1; $i <= $nb_answers; ++$i) {
/* si la reponse est de type objet */
if (is_object($answer)) {
$defaults['answer[' . $i . ']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i];
$defaults['correct[' . $i . ']'] = $answer->correct[$i];
// start
$scoreA = $answer->weighting[$i];
}
if ($scoreA > 0) {
$scoreG = $scoreG + $scoreA;
}
//------------- Fin
//------------- Debut si un des scores par reponse est egal � 0 : la coche vaut 1 (coch�)
if ($scoreA == 0) {
$defaults['pts'] = 1;
}
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
//$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze();
$form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"');
$boxes_names[] = 'correct[' . $i . ']';
$form->addHtmlEditor('answer[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addHtmlEditor('comment[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addElement('html', '</tr>');
}
//--------- Mise en variable du score global lors d'une modification de la question/r�ponse
$defaults['weighting[1]'] = round($scoreG);
$form->addElement('html', '</div></div></table>');
//$form -> addElement ('html', '<br />');
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
//only 1 answer the all deal ...
$form->addElement('text', 'weighting[1]', get_lang('Score'));
global $pts;
//--------- Creation coche pour ne pas prendre en compte les n�gatifs
$form->addElement('checkbox', 'pts', '', get_lang('NoNegativeScore'));
$form->addElement('html', '<br />');
// Affiche un message si le score n'est pas renseign�
$form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required');
global $text, $class;
if ($obj_ex->edit_exercise_in_lp == true) {
$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers');
$form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers');
$form->addButtonSave($text, 'submitQuestion');
// setting the save button here and not in the question class.php
}
$renderer->setElementTemplate('{element} ', 'lessAnswers');
$renderer->setElementTemplate('{element} ', 'submitQuestion');
$renderer->setElementTemplate('{element}', 'moreAnswers');
$form->addElement('html', '</div></div>');
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
示例5: add_category_form
function add_category_form($in_action, $type = 'simple')
{
$in_action = Security::remove_XSS($in_action);
// Initiate the object
$form = new FormValidator('note', 'post', api_get_self() . '?' . api_get_cidreq() . '&action=' . $in_action . "&type=" . $type);
// Setting the form elements
$form->addElement('header', get_lang('AddACategory'));
$form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6'));
$form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
$form->addElement('select', 'parent_id', get_lang('Parent'), array(), array('id' => 'parent_id'));
$form->addElement('style_submit_button', 'SubmitNote', get_lang('AddTestCategory'), 'class="add"');
// Setting the rules
$form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->getSubmitValues();
$parent_id = isset($values['parent_id']) && isset($values['parent_id'][0]) ? $values['parent_id'][0] : null;
$objcat = new Testcategory(0, $values['category_name'], $values['category_description'], $parent_id, $type, api_get_course_int_id());
if ($objcat->addCategoryInBDD()) {
Display::display_confirmation_message(get_lang('AddCategoryDone'));
} else {
Display::display_confirmation_message(get_lang('AddCategoryNameAlreadyExists'));
}
}
Security::clear_token();
display_add_category($type);
display_categories($type);
} else {
display_goback($type);
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}
示例6: 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));
}
示例7: show_add_post_form
/**
* This function displays the form that is used to add a post. This can be a new thread or a reply.
* @param array $current_forum
* @param array $forum_setting
* @param string $action is the parameter that determines if we are
* 1. newthread: adding a new thread (both empty) => No I-frame
* 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled)
* 3. replymessage: Replying to a message ($action =replymessage) => I-frame with the complete thread (if enabled) (I first thought to put and I-frame with the message only)
* 4. quote: Quoting a message ($action= quotemessage) => I-frame with the complete thread (if enabled). The message will be in the reply. (I first thought not to put an I-frame here)
* @return void HMTL
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function show_add_post_form($current_forum, $forum_setting, $action = '', $id = '', $form_values = '')
{
$_user = api_get_user_info();
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
// Initialize the object.
$myThread = isset($_GET['thread']) ? $_GET['thread'] : '';
$my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
$my_post = isset($_GET['post']) ? $_GET['post'] : '';
$my_gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
$form = new FormValidator('thread', 'post', api_get_self() . '?' . http_build_query(['forum' => intval($my_forum), 'gradebook' => $my_gradebook, 'thread' => intval($myThread), 'post' => intval($my_post), 'action' => $action]) . '&' . api_get_cidreq());
$form->setConstants(array('forum' => '5'));
// Setting the form elements.
$form->addElement('hidden', 'forum_id', intval($my_forum));
$form->addElement('hidden', 'thread_id', intval($myThread));
$form->addElement('hidden', 'gradebook', $my_gradebook);
// If anonymous posts are allowed we also display a form to allow the user to put his name or username in.
if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) {
$form->addElement('text', 'poster_name', get_lang('Name'));
$form->applyFilter('poster_name', 'html_filter');
}
$form->addElement('text', 'post_title', get_lang('Title'));
$form->addHtmlEditor('post_text', get_lang('Text'), true, null, api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Forum', 'Width' => '100%', 'Height' => '300') : array('ToolbarSet' => 'ForumStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student'));
$form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
$iframe = null;
$myThread = Security::remove_XSS($myThread);
if ($forum_setting['show_thread_iframe_on_reply'] && $action != 'newthread' && !empty($myThread)) {
$iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?" . api_get_cidreq() . "&forum=" . Security::remove_XSS($my_forum) . "&thread=" . $myThread . "#" . Security::remove_XSS($my_post) . "\" width=\"100%\"></iframe>";
}
if (!empty($iframe)) {
$form->addElement('label', get_lang('Thread'), $iframe);
}
$form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
$form->addElement('html', '<div id="advanced_params_options" style="display:none">');
if ((api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && !$myThread) {
// Thread qualify
if (Gradebook::is_active()) {
//Loading gradebook select
GradebookUtils::load_gradebook_select_in_tool($form);
$form->addElement('checkbox', 'thread_qualify_gradebook', '', get_lang('QualifyThreadGradebook'), 'onclick="javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
} else {
$form->addElement('hidden', 'thread_qualify_gradebook', false);
}
$form->addElement('html', '<div id="options_field" style="display:none">');
$form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'));
$form->applyFilter('numeric_calification', 'html_filter');
$form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'));
$form->applyFilter('calification_notebook_title', 'html_filter');
$form->addElement('text', 'weight_calification', get_lang('QualifyWeight'), array('value' => '0.00', 'onfocus' => "javascript: this.select();"));
$form->applyFilter('weight_calification', 'html_filter');
$group = array();
$group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('No'), 0);
$form->addGroup($group, '', [get_lang('ForumThreadPeerScoring'), get_lang('ForumThreadPeerScoringComment')], ' ');
$form->addElement('html', '</div>');
}
if ($forum_setting['allow_post_notification'] && isset($_user['user_id'])) {
$form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail') . ' (' . $_user['mail'] . ')');
}
if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $action == 'newthread') {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
$values = $form->exportValues();
}
$form->addElement('html', '</div>');
if (in_array($action, ['quote', 'replymessage'])) {
$form->addFile('user_upload[]', get_lang('Attachment'));
$form->addButton('add_attachment', get_lang('AddAttachment'), 'paperclip', 'default', 'default', null, ['id' => 'reply-add-attachment']);
} else {
$form->addFile('user_upload', get_lang('Attachment'));
}
// Setting the class and text of the form title and submit button.
if ($action == 'quote') {
$form->addButtonCreate(get_lang('QuoteMessage'), 'SubmitPost');
} elseif ($action == 'replythread') {
$form->addButtonCreate(get_lang('ReplyToThread'), 'SubmitPost');
} elseif ($action == 'replymessage') {
$form->addButtonCreate(get_lang('ReplyToMessage'), 'SubmitPost');
} else {
$form->addButtonCreate(get_lang('CreateThread'), 'SubmitPost');
}
if (!empty($form_values)) {
$defaults['post_title'] = prepare4display($form_values['post_title']);
$defaults['post_text'] = prepare4display($form_values['post_text']);
$defaults['post_notification'] = strval(intval($form_values['post_notification']));
$defaults['thread_sticky'] = strval(intval($form_values['thread_sticky']));
$defaults['thread_peer_qualify'] = intval($form_values['thread_peer_qualify']);
//.........这里部分代码省略.........
示例8: 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));
}
示例9: createAnswersForm
//.........这里部分代码省略.........
$defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
$defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
} else {
$nb_options++;
$defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
}
}
}
} else {
$defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
$defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
$defaults['matches[2]'] = '2';
$defaults['option[1]'] = get_lang('DefaultMatchingOptA');
$defaults['option[2]'] = get_lang('DefaultMatchingOptB');
}
}
if (empty($matches)) {
for ($i = 1; $i <= $nb_options; ++$i) {
// fill the array with A, B, C.....
$matches[$i] = chr(64 + $i);
}
} else {
for ($i = $counter; $i <= $nb_options; ++$i) {
// fill the array with A, B, C.....
$matches[$i] = chr(64 + $i);
}
}
$form->addElement('hidden', 'nb_matches', $nb_matches);
$form->addElement('hidden', 'nb_options', $nb_options);
// DISPLAY MATCHES
$html = '<table class="table table-striped table-hover">
<thead>
<tr>
<th width="5%">' . get_lang('Number') . '</th>
<th width="70%">' . get_lang('Answer') . '</th>
<th width="15%">' . get_lang('MatchesTo') . '</th>
<th width="10%">' . get_lang('Weighting') . '</th>
</tr>
</thead>
<tbody>';
$form->addHeader(get_lang('MakeCorrespond'));
$form->addHtml($html);
if ($nb_matches < 1) {
$nb_matches = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_matches; ++$i) {
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
$form->addHtml('<tr>');
$form->addHtml("<td>{$i}</td>");
$form->addText("answer[{$i}]", null);
$form->addSelect("matches[{$i}]", null, $matches);
$form->addText("weighting[{$i}]", null, true, ['value' => 10]);
$form->addHtml('</tr>');
}
$form->addHtml('</tbody></table>');
$group = array();
$form->addGroup($group);
// DISPLAY OPTIONS
$html = '<table class="table table-striped table-hover">
<thead>
<tr>
<th width="15%">' . get_lang('Number') . '</th>
<th width="85%">' . get_lang('Answer') . '</th>
</tr>
</thead>
<tbody>';
$form->addHtml($html);
if ($nb_options < 1) {
$nb_options = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_options; ++$i) {
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "option[{$i}]");
$form->addHtml('<tr>');
$form->addHtml('<td>' . chr(64 + $i) . '</td>');
$form->addText("option[{$i}]", null);
$form->addHtml('</tr>');
}
$form->addHtml('</table>');
$group = array();
global $text;
// setting the save button here and not in the question class.php
$group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true);
$group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true);
$group[] = $form->addButtonSave($text, 'submitQuestion', true);
$form->addGroup($group);
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options));
}
示例10: createAnswersForm
/**
* function which redefines Question::createAnswersForm
* @param FormValidator $form
*/
function createAnswersForm($form)
{
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 2;
$nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
$obj_ex = Session::read('objExercise');
$html = '<table class="table table-striped table-hover">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th width="10">' . get_lang('Number') . '</th>';
$html .= '<th width="10">' . get_lang('True') . '</th>';
$html .= '<th width="50%">' . get_lang('Comment') . '</th>';
$html .= '<th width="50%">' . get_lang('Answer') . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$form->addHeader(get_lang('Answers'));
$form->addHtml($html);
$defaults = array();
$correct = 0;
$answer = false;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$form->addElement('hidden', 'nb_answers');
$boxes_names = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addHtml('<tr>');
if (is_object($answer)) {
$defaults['answer[' . $i . ']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i];
$defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
$defaults['correct[' . $i . ']'] = $answer->correct[$i];
} else {
$defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
$defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
$defaults['correct[1]'] = true;
$defaults['weighting[1]'] = 10;
$defaults['answer[2]'] = get_lang('DefaultMultipleAnswer1');
$defaults['comment[2]'] = get_lang('DefaultMultipleComment1');
$defaults['correct[2]'] = false;
}
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze();
$form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox" style="margin-left: 0em;"');
$boxes_names[] = 'correct[' . $i . ']';
$form->addElement('html_editor', 'answer[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
$form->addHtml('</tr>');
}
$form->addElement('html', '</tbody></table>');
$form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
//only 1 answer the all deal ...
$form->addText('weighting[1]', get_lang('Score'), false, ['value' => 10]);
global $text;
//ie6 fix
if ($obj_ex->edit_exercise_in_lp == true) {
// setting the save button here and not in the question class.php
$buttonGroup = [$form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true), $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true), $form->addButtonSave($text, 'submitQuestion', true)];
$form->addGroup($buttonGroup);
}
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
示例11: add_edit_template
//.........这里部分代码省略.........
$title = get_lang('AddTemplate');
} else {
$title = get_lang('EditTemplate');
}
$form->addElement('header', '', $title);
// Setting the form elements: the title of the template.
$form->addText('title', get_lang('Title'), false);
// Setting the form elements: the content of the template (wysiwyg editor).
$form->addHtmlEditor('template_text', get_lang('Text'), false, false, array('ToolbarSet' => 'AdminTemplates', 'Width' => '100%', 'Height' => '400'));
// Setting the form elements: the form to upload an image to be used with the template.
$form->addElement('file', 'template_image', get_lang('Image'), '');
// Setting the form elements: a little bit information about the template image.
$form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
// Getting all the information of the template when editing a template.
if ($_GET['action'] == 'edit') {
// Database table definition.
$table_system_template = Database::get_main_table('system_template');
$sql = "SELECT * FROM {$table_system_template} WHERE id = " . intval($_GET['id']) . "";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$defaults['template_id'] = intval($_GET['id']);
$defaults['template_text'] = $row['content'];
// Forcing get_lang().
$defaults['title'] = get_lang($row['title']);
// Adding an extra field: a hidden field with the id of the template we are editing.
$form->addElement('hidden', 'template_id');
// Adding an extra field: a preview of the image that is currently used.
if (!empty($row['image'])) {
$form->addElement('static', 'template_image_preview', '', '<img src="' . api_get_path(WEB_APP_PATH) . 'home/default_platform_document/template_thumb/' . $row['image'] . '" alt="' . get_lang('TemplatePreview') . '"/>');
} else {
$form->addElement('static', 'template_image_preview', '', '<img src="' . api_get_path(WEB_APP_PATH) . 'home/default_platform_document/template_thumb/noimage.gif" alt="' . get_lang('NoTemplatePreview') . '"/>');
}
// Setting the information of the template that we are editing.
$form->setDefaults($defaults);
}
// Setting the form elements: the submit button.
$form->addButtonSave(get_lang('Ok'), 'submit');
// Setting the rules: the required fields.
$form->addRule('template_image', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('template_text', get_lang('ThisFieldIsRequired'), 'required');
// if the form validates (complies to all rules) we save the information, else we display the form again (with error message if needed)
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
// Exporting the values.
$values = $form->exportValues();
// Upload the file.
if (!empty($_FILES['template_image']['name'])) {
$upload_ok = process_uploaded_file($_FILES['template_image']);
if ($upload_ok) {
// Try to add an extension to the file if it hasn't one.
$new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
// The upload directory.
$upload_dir = api_get_path(SYS_APP_PATH) . 'home/default_platform_document/template_thumb/';
// Create the directory if it does not exist.
if (!is_dir($upload_dir)) {
mkdir($upload_dir, api_get_permissions_for_new_directories());
}
// Resize the preview image to max default and upload.
$temp = new Image($_FILES['template_image']['tmp_name']);
$picture_info = $temp->get_image_info();
$max_width_for_picture = 100;
if ($picture_info['width'] > $max_width_for_picture) {
$temp->resize($max_width_for_picture);
}
$temp->send_image($upload_dir . $new_file_name);
}
}
// Store the information in the database (as insert or as update).
$table_system_template = Database::get_main_table('system_template');
if ($_GET['action'] == 'add') {
$content_template = Security::remove_XSS($values['template_text'], COURSEMANAGERLOWSECURITY);
$params = ['title' => $values['title'], 'content' => $content_template, 'image' => $new_file_name];
Database::insert($table_system_template, $params);
// Display a feedback message.
Display::display_confirmation_message(get_lang('TemplateAdded'));
echo '<a href="settings.php?category=Templates&action=add">' . Display::return_icon('new_template.png', get_lang('AddTemplate'), '', ICON_SIZE_MEDIUM) . '</a>';
} else {
$content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>' . Database::escape_string($values['template_text']) . '</body>';
$sql = "UPDATE {$table_system_template} set title = '" . Database::escape_string($values['title']) . "', content = '" . $content_template . "'";
if (!empty($new_file_name)) {
$sql .= ", image = '" . Database::escape_string($new_file_name) . "'";
}
$sql .= " WHERE id = " . intval($_GET['id']) . "";
Database::query($sql);
// Display a feedback message.
Display::display_confirmation_message(get_lang('TemplateEdited'));
}
}
Security::clear_token();
display_templates();
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
// Display the form.
$form->display();
}
}
示例12: 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]);
}
示例13: createAnswersForm
//.........这里部分代码省略.........
$option_data = Question::readQuestionOption($this->id, $course_id);
for ($i = 1; $i <= $nb_answers; ++$i) {
$form->addHtml('<tr>');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
$answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
$answer_number->freeze();
if (is_object($answer)) {
$defaults['answer[' . $i . ']'] = $answer->answer[$i];
$defaults['comment[' . $i . ']'] = $answer->comment[$i];
$correct = $answer->correct[$i];
$defaults['correct[' . $i . ']'] = $correct;
$j = 1;
if (!empty($option_data)) {
foreach ($option_data as $id => $data) {
$form->addElement('radio', 'correct[' . $i . ']', null, null, $id);
$j++;
if ($j == 3) {
break;
}
}
}
} else {
$form->addElement('radio', 'correct[' . $i . ']', null, null, 1);
$form->addElement('radio', 'correct[' . $i . ']', null, null, 2);
$defaults['answer[' . $i . ']'] = '';
$defaults['comment[' . $i . ']'] = '';
$defaults['correct[' . $i . ']'] = '';
}
$boxes_names[] = 'correct[' . $i . ']';
$form->addHtmlEditor("answer[{$i}]", get_lang('ThisFieldIsRequired'), true, true, ['ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100']);
// show comment when feedback is enable
if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
$form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
}
$form->addHtml('</tr>');
}
$form->addHtml('</tbody></table>');
$correctInputTemplate = '<div class="form-group">';
$correctInputTemplate .= '<label class="col-sm-2 control-label">';
$correctInputTemplate .= '<span class="form_required">*</span>' . get_lang('Score');
$correctInputTemplate .= '</label>';
$correctInputTemplate .= '<div class="col-sm-8">';
$correctInputTemplate .= '<table>';
$correctInputTemplate .= '<tr>';
$correctInputTemplate .= '<td>';
$correctInputTemplate .= get_lang('Correct') . '{element}';
$correctInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
$correctInputTemplate .= '</td>';
$wrongInputTemplate = '<td>';
$wrongInputTemplate .= get_lang('Wrong') . '{element}';
$wrongInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
$wrongInputTemplate .= '</td>';
$doubtScoreInputTemplate = '<td>' . get_lang('DoubtScore') . '<br>{element}';
$doubtScoreInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
$doubtScoreInputTemplate .= '</td>';
$doubtScoreInputTemplate .= '</tr>';
$doubtScoreInputTemplate .= '</table>';
$doubtScoreInputTemplate .= '</div>';
$doubtScoreInputTemplate .= '</div>';
$renderer->setElementTemplate($correctInputTemplate, 'option[1]');
$renderer->setElementTemplate($wrongInputTemplate, 'option[2]');
$renderer->setElementTemplate($doubtScoreInputTemplate, 'option[3]');
// 3 scores
$form->addElement('text', 'option[1]', get_lang('Correct'), array('class' => 'span1', 'value' => '1'));
$form->addElement('text', 'option[2]', get_lang('Wrong'), array('class' => 'span1', 'value' => '-0.5'));
$form->addElement('text', 'option[3]', get_lang('DoubtScore'), array('class' => 'span1', 'value' => '0'));
$form->addRule('option[1]', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('option[2]', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('option[3]', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'options_count', 3);
// Extra values True, false, Dont known
if (!empty($this->extra)) {
$scores = explode(':', $this->extra);
if (!empty($scores)) {
for ($i = 1; $i <= 3; $i++) {
$defaults['option[' . $i . ']'] = $scores[$i - 1];
}
}
}
global $text;
if ($obj_ex->edit_exercise_in_lp == true) {
// setting the save button here and not in the question class.php
$buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
$buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
$buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
$form->addGroup($buttonGroup);
}
$defaults['correct'] = $correct;
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
//if ($this -> isContent == 1) {
$form->setDefaults($defaults);
//}
}
$form->setConstants(array('nb_answers' => $nb_answers));
}
示例14: show_add_post_form
/**
* This function displays the form that is used to add a post. This can be a new thread or a reply.
* @param $action is the parameter that determines if we are
* 1. newthread: adding a new thread (both empty) => No I-frame
* 2. replythread: Replying to a thread ($action = replythread) => I-frame with the complete thread (if enabled)
* 3. replymessage: Replying to a message ($action =replymessage) => I-frame with the complete thread (if enabled) (I first thought to put and I-frame with the message only)
* 4. quote: Quoting a message ($action= quotemessage) => I-frame with the complete thread (if enabled). The message will be in the reply. (I first thought not to put an I-frame here)
* @return void HMTL
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8
*/
function show_add_post_form($action = '', $id = '', $form_values = '')
{
global $forum_setting;
global $current_forum;
global $_user;
global $origin;
$gradebook = Security::remove_XSS($_GET['gradebook']);
// Setting the class and text of the form title and submit button.
if ($_GET['action'] == 'quote') {
$class = 'save';
$text = get_lang('QuoteMessage');
} elseif ($_GET['action'] == 'replythread') {
$class = 'save';
$text = get_lang('ReplyToThread');
} elseif ($_GET['action'] == 'replymessage') {
$class = 'save';
$text = get_lang('ReplyToMessage');
} else {
$class = 'add';
$text = get_lang('CreateThread');
}
// Initialize the object.
$my_thread = isset($_GET['thread']) ? $_GET['thread'] : '';
$my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
$my_action = isset($_GET['action']) ? $_GET['action'] : '';
$my_post = isset($_GET['post']) ? $_GET['post'] : '';
$my_gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
$form = new FormValidator('thread', 'post', api_get_self() . '?forum=' . Security::remove_XSS($my_forum) . '&gradebook=' . $gradebook . '&thread=' . Security::remove_XSS($my_thread) . '&post=' . Security::remove_XSS($my_post) . '&action=' . Security::remove_XSS($my_action) . '&origin=' . $origin);
$form->setConstants(array('forum' => '5'));
$form->addElement('header', $text);
// Settting the form elements.
$form->addElement('hidden', 'forum_id', intval($my_forum));
$form->addElement('hidden', 'thread_id', intval($my_thread));
$form->addElement('hidden', 'gradebook', $my_gradebook);
// If anonymous posts are allowed we also display a form to allow the user to put his name or username in.
if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) {
$form->addElement('text', 'poster_name', get_lang('Name'));
$form->applyFilter('poster_name', 'html_filter');
}
$form->addElement('text', 'post_title', get_lang('Title'));
$form->addElement('html_editor', 'post_text', get_lang('Text'), true, api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Forum', 'Width' => '100%', 'Height' => '300') : array('ToolbarSet' => 'ForumStudent', 'Width' => '100%', 'Height' => '300', 'UserStatus' => 'student'));
$form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('advanced_settings', '<a href="javascript://" onclick="return advanced_parameters()">
<span id="img_plus_and_minus"> ' . Display::return_icon('div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle')) . ' ' . get_lang('AdvancedParameters') . '</span></a>');
$form->addElement('html', '<div id="id_qualify" style="display:none">');
if ((api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && !$my_thread) {
// Thread qualify
if (Gradebook::is_active()) {
//Loading gradebook select
load_gradebook_select_in_tool($form);
$form->addElement('checkbox', 'thread_qualify_gradebook', '', get_lang('QualifyThreadGradebook'), 'onclick="javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
} else {
$form->addElement('hidden', 'thread_qualify_gradebook', false);
}
$form->addElement('html', '<div id="options_field" style="display:none">');
$form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'));
$form->applyFilter('numeric_calification', 'html_filter');
$form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'));
$form->applyFilter('calification_notebook_title', 'html_filter');
$form->addElement('text', 'weight_calification', get_lang('QualifyWeight'), 'value="0.00" Style="width:40px" onfocus="javascript: this.select();"');
$form->applyFilter('weight_calification', 'html_filter');
$form->addElement('html', '</div>');
}
if ($forum_setting['allow_post_notification'] && isset($_user['user_id'])) {
$form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail') . ' (' . $_user['mail'] . ')');
}
if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $action == 'newthread') {
$form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
}
if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
$values = $form->exportValues();
}
// User upload
$form->addElement('static', null, null, get_lang('AddAnAttachment'));
$form->addElement('file', 'user_upload', get_lang('FileName'), '');
$form->addElement('textarea', 'file_comment', get_lang('FileComment'), array('rows' => 4, 'cols' => 34));
$form->applyFilter('file_comment', 'html_filter');
$form->addElement('html', '</div>');
$form->addElement('style_submit_button', 'SubmitPost', $text, 'class="' . $class . '"');
$form->add_real_progress_bar('DocumentUpload', 'user_upload');
if (!empty($form_values)) {
$defaults['post_title'] = prepare4display($form_values['post_title']);
$defaults['post_text'] = prepare4display($form_values['post_text']);
$defaults['post_notification'] = strval(intval($form_values['post_notification']));
$defaults['thread_sticky'] = strval(intval($form_values['thread_sticky']));
}
// If we are quoting a message we have to retrieve the information of the post we are quoting so that
// we can add this as default to the textarea.
if (($action == 'quote' || $action == 'replymessage') && isset($my_post)) {
//.........这里部分代码省略.........
示例15: createAnswersForm
//.........这里部分代码省略.........
$a_matches = array();
for ($i = 1; $i <= $nb_options; ++$i) {
$a_matches[$i] = chr(64 + $i);
// fill the array with A, B, C.....
}
$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 /> <img src="../img/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"');
}
$form->addGroup($group);
// DISPLAY OPTIONS
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
' . get_lang('Number') . '
</th>
<th width="90%"
' . get_lang('Answer') . '
</th>
</tr>';
//$form -> addElement ('html', $html);
$form->addElement('label', null, $html);
if ($nb_options < 1) {
$nb_options = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
for ($i = 1; $i <= $nb_options; ++$i) {
$form->addElement('html', '<tr><td>');
$group = array();
$puce = $form->createElement('text', null, null, 'value="' . chr(64 + $i) . '"');
$puce->freeze();
$group[] = $puce;
$group[] = $form->createElement('text', 'option[' . $i . ']', null, array('class' => 'span6'));
$form->addGroup($group, null, null, '</td><td>');
$form->addElement('html', '</td></tr>');
}
$form->addElement('html', '</table></div></div>');
$group = array();
global $text, $class;
if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
// setting the save button here and not in the question class.php
$group[] = $form->createElement('submit', 'submitQuestion', $text, 'class="' . $class . '"');
$group[] = $form->createElement('submit', 'lessOptions', get_lang('DelElem'), 'class="minus"');
$group[] = $form->createElement('submit', 'moreOptions', get_lang('AddElem'), 'class="plus"');
} else {
// setting the save button here and not in the question class.php
$group[] = $form->createElement('style_submit_button', 'lessOptions', get_lang('DelElem'), 'class="minus"');
$group[] = $form->createElement('style_submit_button', 'moreOptions', get_lang('AddElem'), ' class="plus"');
$group[] = $form->createElement('style_submit_button', 'submitQuestion', $text, 'class="' . $class . '"');
}
$form->addGroup($group);
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
$form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options));
}