/**
  * Returns a Form validator Obj
  * @todo the form should be auto generated
  * @param   string  $url
  * @param   string  $action add, edit
  *
  * @return  FormValidator form validator obj
  */
 public function return_form($url, $action)
 {
     $form = new FormValidator('grades', 'post', $url);
     // Setting the form elements
     $header = get_lang('Add');
     if ($action == 'edit') {
         $header = get_lang('Modify');
     }
     $form->addElement('header', $header);
     $id = isset($_GET['id']) ? intval($_GET['id']) : '';
     $form->addElement('hidden', 'id', $id);
     $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
     $form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'Careers', 'Width' => '100%', 'Height' => '250'));
     $form->addElement('label', get_lang('Components'));
     // Get components
     $nr_items = 2;
     $max = 10;
     // Setting the defaults
     $defaults = $this->get($id);
     $components = $this->get_components($defaults['id']);
     if ($action == 'edit') {
         if (!empty($components)) {
             $nr_items = count($components) - 1;
         }
     }
     $form->addElement('hidden', 'maxvalue', '100');
     $form->addElement('hidden', 'minvalue', '0');
     $renderer =& $form->defaultRenderer();
     $component_array = array();
     for ($i = 0; $i <= $max; $i++) {
         $counter = $i;
         $form->addElement('text', 'components[' . $i . '][percentage]', null);
         $form->addElement('text', 'components[' . $i . '][acronym]', null);
         $form->addElement('text', 'components[' . $i . '][title]', null);
         $form->addElement('hidden', 'components[' . $i . '][id]', null);
         $template_percentage = '<div id=' . $i . ' style="display: ' . ($i <= $nr_items ? 'inline' : 'none') . ';" class="control-group">
             <p>
             <label class="control-label">{label}</label>
             <div class="controls">
                 <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
                 {element} <!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --> % = ';
         $template_acronym = '
         <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
         {element} {label} <!-- BEGIN error --><span class="form_error">{error}</span> <!-- END error -->';
         $template_title = '&nbsp{element} <!-- BEGIN error --> <span class="form_error">{error}</span><!-- END error -->
          <a href="javascript:plusItem(' . ($counter + 1) . ')">
             <img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="plus-' . ($counter + 1) . '" src="../img/icons/22/add.png" alt="' . get_lang('Add') . '" title="' . get_lang('Add') . '"></img>
         </a>
         <a href="javascript:minItem(' . $counter . ')">
             <img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="min-' . $counter . '" src="../img/delete.png" alt="' . get_lang('Delete') . '" title="' . get_lang('Delete') . '"></img>
         </a>
         </div></p></div>';
         $renderer->setElementTemplate($template_title, 'components[' . $i . '][title]');
         $renderer->setElementTemplate($template_percentage, 'components[' . $i . '][percentage]');
         $renderer->setElementTemplate($template_acronym, 'components[' . $i . '][acronym]');
         if ($i == 0) {
             $form->addRule('components[' . $i . '][percentage]', get_lang('ThisFieldIsRequired'), 'required');
             $form->addRule('components[' . $i . '][title]', get_lang('ThisFieldIsRequired'), 'required');
             $form->addRule('components[' . $i . '][acronym]', get_lang('ThisFieldIsRequired'), 'required');
         }
         $form->addRule('components[' . $i . '][percentage]', get_lang('OnlyNumbers'), 'numeric');
         $form->addRule(array('components[' . $i . '][percentage]', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
         $form->addRule(array('components[' . $i . '][percentage]', 'minvalue'), get_lang('UnderMin'), 'compare', '>=');
         $component_array[] = 'components[' . $i . '][percentage]';
     }
     //New rule added in the formvalidator compare_fields that filters a group of fields in order to compare with the wanted value
     $form->addRule($component_array, get_lang('AllMustWeight100'), 'compare_fields', '==@100');
     $form->addElement('label', '', get_lang('AllMustWeight100'));
     if ($action == 'edit') {
         $form->addButtonUpdate(get_lang('Modify'));
     } else {
         $form->addButtonCreate(get_lang('Add'));
     }
     if (!empty($components)) {
         $counter = 0;
         foreach ($components as $component) {
             foreach ($component as $key => $value) {
                 $defaults['components[' . $counter . '][' . $key . ']'] = $value;
             }
             $counter++;
         }
     }
     $form->setDefaults($defaults);
     // Setting the rules
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     return $form;
 }
 /**
  * function which redifines Question::createAnswersForm
  * @param FormValidator $form
  * @param the answers number to display
  */
 function createAnswersForm($form)
 {
     // getting the exercise list
     $obj_ex = Session::read('objExercise');
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line define how many question by default appear when creating a choice question
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
      Types of Feedback
      $feedback_option[0]=get_lang('Feedback');
      $feedback_option[1]=get_lang('DirectFeedback');
      $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     $comment_title = '';
     if ($obj_ex->selectFeedbackType() == 1) {
         $editor_config['Width'] = '250';
         $editor_config['Height'] = '110';
         $comment_title = '<th width="50%" >' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="50%" >' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th width="50%">' . get_lang('Comment') . '</th>';
     }
     $html = '<table class="table table-striped table-hover">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th>' . get_lang('Number') . '</th>';
     $html .= '<th>' . get_lang('True') . '</th>';
     $html .= '<th width="50%">' . get_lang('Answer') . '</th>';
     $html .= $comment_title . $feedback_title;
     $html .= '<th>' . get_lang('Weighting') . '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     $html .= '<tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     $editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : false;
     if ($editQuestion) {
         //fixing $nb_answers
         $new_list = array();
         $count = 1;
         if (isset($_POST['lessAnswers'])) {
             $lessFromSession = Session::read('less_answer');
             if (!isset($lessFromSession)) {
                 Session::write('less_answer', $this->id);
                 $nb_answers--;
             }
         }
         for ($k = 1; $k <= $nb_answers; ++$k) {
             if ($answer->position[$k] != '666') {
                 $new_list[$count] = $count;
                 $count++;
             }
         }
     } else {
         for ($k = 1; $k <= $nb_answers; ++$k) {
             $new_list[$k] = $k;
         }
     }
     $i = 1;
     //for ($k = 1 ; $k <= $real_nb_answers; $k++) {
     foreach ($new_list as $key) {
         $i = $key;
         $form->addElement('html', '<tr>');
         if (is_object($answer)) {
             if ($answer->position[$i] == 666) {
                 //we set nothing
             } else {
                 if ($answer->correct[$i]) {
                     $correct = $i;
                 }
                 $answer_result = $answer->answer[$i];
                 $weight_result = float_format($answer->weighting[$i], 1);
                 if ($nb_answers == $i) {
                     $weight_result = '0';
                 }
                 $defaults['answer[' . $i . ']'] = $answer_result;
                 $defaults['comment[' . $i . ']'] = $answer->comment[$i];
                 $defaults['weighting[' . $i . ']'] = $weight_result;
                 $item_list = explode('@@', $answer->destination[$i]);
                 $try = $item_list[0];
                 $lp = $item_list[1];
                 $list_dest = $item_list[2];
                 $url = $item_list[3];
                 if ($try == 0) {
                     $try_result = 0;
                 } else {
                     $try_result = 1;
                 }
                 if ($url == 0) {
                     $url_result = '';
                 } else {
                     $url_result = $url;
                 }
                 $temp_scenario['url' . $i] = $url_result;
                 $temp_scenario['try' . $i] = $try_result;
                 $temp_scenario['lp' . $i] = $lp;
                 $temp_scenario['destination' . $i] = $list_dest;
             }
         }
         $defaults['scenario'] = $temp_scenario;
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
         $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config);
         $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config);
         $form->addElement('text', 'weighting[' . $i . ']', null, array('style' => 'width: 60px;', 'value' => '0'));
         $form->addElement('html', '</tr>');
         $i++;
     }
     if (empty($this->id)) {
         $form->addElement('hidden', 'new_question', 1);
     }
     //Adding the "I don't know" question answer
     //if (empty($this -> id)) {
     $i = 666;
     $form->addHtml('<tr>');
     $defaults['answer[' . $i . ']'] = get_lang('DontKnow');
     $defaults['weighting[' . $i . ']'] = 0;
     $defaults['scenario'] = $temp_scenario;
     $renderer =& $form->defaultRenderer();
     $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct');
     $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
     $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
     $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
     $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
     $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="-"');
     $answer_number->freeze();
     $form->addElement('hidden', 'position[' . $i . ']', '666');
     $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
     $form->addHtmlEditor('answer[' . $i . ']', null, array(), false, $editor_config);
     $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
     $form->addHtmlEditor('comment[' . $i . ']', null, array(), false, $editor_config);
     //$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple');
     $form->addText("weighting[{$i}]", null, false, ['style' => 'width: 60px;', 'value' => 0, 'readonly' => 'readonly']);
     $form->addHTml('</tr>');
     $form->addHtml('</tbody></table>');
     $buttonGroup = [];
     global $text, $class;
     //ie6 fix
     if ($obj_ex->edit_exercise_in_lp == true) {
         //setting the save button here and not in the question class.php
         $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
         $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
         $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
         $form->addGroup($buttonGroup);
     }
     //We check the first radio button to be sure a radio button will be check
     if ($correct == 0) {
         $correct = 1;
     }
     $defaults['correct'] = $correct;
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         $form->setDefaults($defaults);
     }
     $form->addElement('hidden', 'nb_answers');
     $form->setConstants(array('nb_answers' => $nb_answers));
 }
    /**
    *	add a form for set WCAG content (replace FCK)
    *	@version 1.1
    */
    function &prepare_admin_form($xhtml, &$form)
    {
        $values = WCAG_Rendering::extract_data($xhtml);
        if ($form == null) {
            $form = new FormValidator('waiForm');
        }
        $form->addElement('textarea', 'text', get_lang('WCAGContent'));
        $file =& $form->addElement('text', 'imagefile', get_lang('WCAGImage'));
        $form->addElement('text', 'imageLabel', get_lang('WCAGLabel'));
        $form->addElement('text', 'link', get_lang('WCAGLink'));
        $form->addElement('text', 'linkLabel', get_lang('WCAGLinkLabel'));
        $form->setDefaults($values);
        $renderer =& $form->defaultRenderer();
        $element_template = '<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}<br />
			<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->	{element}<br />';
        $renderer->setElementTemplate($element_template);
        return $form;
    }
     echo '<br />';
     echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick' => "showfck('" . $name . "', '" . $marksname . "');"));
     echo '<br />';
     echo '<div id="feedback_' . $name . '" style="width:100%">';
     $comnt = trim(Event::get_comments($id, $questionId));
     if (empty($comnt)) {
         echo '<br />';
     } else {
         echo '<div id="question_feedback">' . $comnt . '</div>';
     }
     echo '</div>';
     echo '<div id="' . $name . '" style="display:none">';
     $arrid[] = $questionId;
     $feedback_form = new FormValidator('frmcomments' . $questionId, 'post', '');
     $feedback_form->addElement('html', '<br>');
     $renderer =& $feedback_form->defaultRenderer();
     $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
     $renderer->setCustomElementTemplate('<div align="left">{element}</div>');
     $comnt = Event::get_comments($id, $questionId);
     $default = array('comments_' . $questionId => $comnt);
     if ($useAdvancedEditor) {
         $feedback_form->addElement('html_editor', 'comments_' . $questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
     } else {
         $feedback_form->addElement('textarea', 'comments_' . $questionId);
     }
     $feedback_form->addElement('html', '<br>');
     $feedback_form->setDefaults($default);
     $feedback_form->display();
     echo '</div>';
 } else {
     $comnt = Event::get_comments($id, $questionId);
 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     $obj_ex = Session::read('objExercise');
     /* Mise en variable de Affichage "Reponses" et son icone, "N�", "Vrai", "Reponse" */
     $html = '<table class="data_table">
             <tr>
                 <th width="10px">
                     ' . get_lang('Number') . '
                 </th>
                 <th width="10px">
                     ' . get_lang('True') . '
                 </th>
                 <th width="50%">
                     ' . get_lang('Answer') . '
                 </th>';
     $html .= '<th>' . get_lang('Comment') . '</th>';
     $html .= '</tr>';
     $form->addElement('label', get_lang('Answers') . '<br /> <img src="../img/fill_field.png">', $html);
     $defaults = array();
     $correct = 0;
     $answer = false;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     #le nombre de r�ponses est bien enregistr� sous la forme int(nb)
     /* Ajout mise en forme nb reponse */
     $form->addElement('hidden', 'nb_answers');
     $boxes_names = array();
     /* V�rification : Cr�action d'au moins une r�ponse */
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     //D�but affichage score global dans la modification d'une question
     $scoreA = "0";
     //par reponse
     $scoreG = "0";
     //Global
     /* boucle pour sauvegarder les donn�es dans le tableau defaults */
     for ($i = 1; $i <= $nb_answers; ++$i) {
         /* si la reponse est de type objet */
         if (is_object($answer)) {
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['correct[' . $i . ']'] = $answer->correct[$i];
             // start
             $scoreA = $answer->weighting[$i];
         }
         if ($scoreA > 0) {
             $scoreG = $scoreG + $scoreA;
         }
         //------------- Fin
         //------------- Debut si un des scores par reponse est egal � 0 : la coche vaut 1 (coch�)
         if ($scoreA == 0) {
             $defaults['pts'] = 1;
         }
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         //$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting['.$i.']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         $form->addElement('checkbox', 'correct[' . $i . ']', null, null, 'class="checkbox"');
         $boxes_names[] = 'correct[' . $i . ']';
         $form->addHtmlEditor('answer[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         $form->addHtmlEditor('comment[' . $i . ']', null, null, array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
         $form->addElement('html', '</tr>');
     }
     //--------- Mise en variable du score global lors d'une modification de la question/r�ponse
     $defaults['weighting[1]'] = round($scoreG);
     $form->addElement('html', '</div></div></table>');
     //$form -> addElement ('html', '<br />');
     $form->add_multiple_required_rule($boxes_names, get_lang('ChooseAtLeastOneCheckbox'), 'multiple_required');
     //only 1 answer the all deal ...
     $form->addElement('text', 'weighting[1]', get_lang('Score'));
     global $pts;
     //--------- Creation coche pour ne pas prendre en compte les n�gatifs
     $form->addElement('checkbox', 'pts', '', get_lang('NoNegativeScore'));
     $form->addElement('html', '<br />');
     // Affiche un message si le score n'est pas renseign�
     $form->addRule('weighting[1]', get_lang('ThisFieldIsRequired'), 'required');
     global $text, $class;
     if ($obj_ex->edit_exercise_in_lp == true) {
         $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers');
         $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers');
         $form->addButtonSave($text, 'submitQuestion');
         // setting the save button here and not in the question class.php
     }
     $renderer->setElementTemplate('{element}&nbsp;', 'lessAnswers');
     $renderer->setElementTemplate('{element}&nbsp;', '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));
 }
Example #6
0
 /**
  * Returns the form to update or create a document
  *
  * @param	string	Action (add/edit)
  * @param	integer	ID of the lp_item (if already exists)
  * @param	mixed	Integer if document ID, string if info ('new')
  * @return	string	HTML form
  */
 function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     global $charset, $_course;
     require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
     require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $path_parts = pathinfo($extra_info['dir']);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     //If action==add an existing document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc, __FILE__, __LINE__);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     // create css folder
     $css_name = api_get_setting('stylesheets');
     $perm = api_get_setting('permissions_for_new_directories');
     $perm = octdec(!empty($perm) ? $perm : '0770');
     $css_folder = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/css';
     if (!is_dir($css_folder)) {
         mkdir($css_folder);
         chmod($css_folder, $perm);
         $doc_id = add_document($_course, '/css', 'folder', 0, 'css');
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
     }
     if (!file_exists($css_folder . '/templates.css')) {
         if (file_exists(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')) {
             $template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH) . 'img/', file_get_contents(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css'));
             $template_content = str_replace('images/', api_get_path(REL_CODE_PATH) . 'css/' . $css_name . '/images/', $template_content);
             file_put_contents($css_folder . '/templates.css', $template_content);
         }
     }
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $table_sys_template = Database::get_main_table(TABLE_MAIN_SYSTEM_TEMPLATE);
         $user_id = api_get_user_id();
         // Session used by the ajax request when we are using php 5.3
         $_SESSION['dbName'] = $_course['dbName'];
         // setting some paths
         $img_dir = api_get_path(REL_CODE_PATH) . 'img/';
         $default_course_dir = api_get_path(REL_CODE_PATH) . 'default_course_document/';
         if (!isset($_GET['resource'])) {
             // Load a template into a document
             $query = 'SELECT content, title FROM ' . $table_sys_template . ' WHERE id=' . Database::escape_string(Security::remove_XSS($_GET['tplid']));
             $result = Database::query($query, __FILE__, __LINE__);
             $obj = Database::fetch_object($result);
             $valcontent = $obj->content;
             $valtitle = $obj->title != '' ? get_lang($obj->title) : get_lang('Empty');
             if (isset($_GET['tplid']) && $_GET['tplid'] == 0) {
                 $valcontent = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body></body>';
             }
             $template_css = '';
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $template_css = '<link rel="stylesheet" href="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/css/templates.css" type="text/css" />';
             }
             $js = '';
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'jwplayer/jwplayer.js" language="javascript"></script>' . PHP_EOL;
                 if (api_get_setting('show_glossary_in_documents') != 'none') {
                     $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js"></script>';
                     if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
                     } else {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
                     }
                 }
             }
             $valcontent = str_replace('{CSS}', $template_css . $js, $valcontent);
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $valcontent = str_replace('</head>', $template_css . '</head>', $valcontent);
             }
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $valcontent = str_replace('</head>', $js . '</head>', $valcontent);
             }
             $valcontent = str_replace('{IMG_DIR}', $img_dir, $valcontent);
             $valcontent = str_replace('{REL_PATH}', api_get_path(REL_PATH), $valcontent);
             $valcontent = str_replace('{COURSE_DIR}', $default_course_dir, $valcontent);
         } elseif (isset($_GET['resource']) && $_GET['resource'] == 'mindmap' || $_GET['resource'] == 'video') {
             // Load a mindmap or video into a document
             $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
             $curdirpath = '/mindmaps/';
             if ($_GET['resource'] == 'video') {
                 $curdirpath = '/video/';
                 $curdirpath_flv = '/video/flv/';
             }
             $my_course = api_get_course_id();
             $src_path = api_get_path(WEB_COURSE_PATH) . $my_course . '/document';
             $sql = "SELECT path,title FROM {$tbl_doc} doc,{$propTable} prop WHERE doc.id = prop.ref AND prop.tool = '" . TOOL_DOCUMENT . "'\n      AND doc.filetype = 'file' AND (doc.path LIKE '" . $curdirpath . "%' OR doc.path LIKE '" . $curdirpath_flv . "%') AND (doc.path NOT LIKE '" . $curdirpath . "%/%' OR doc.path NOT LIKE '" . $curdirpath_flv . "%/%')\n      AND prop.visibility = 1 AND doc.id = '" . Database::escape_string(Security::remove_XSS($_GET['tplid'])) . "'";
             $rs = Database::query($sql);
             $row = Database::fetch_array($rs);
             $resource = $src_path . $row['path'];
             $valtitle = $row['title'];
             if ($valtitle != '') {
                 $search = array('.png', '.gif', '.jpg', '.mpg', '.flv', '.swf');
                 // Add other extensions
                 $replace = array('', '', '', '', '', '');
                 $valtitle = str_replace($search, $replace, $valtitle);
             }
             if ($_GET['resource'] == 'mindmap') {
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
           <tbody>
               <tr>
                   <td valign="top"><img border="0" vspace="0" hspace="0" src="' . $resource . '" alt="' . $title . '" title="' . $title . '"/></td>
               </tr>
           </tbody>
       </table>';
             } elseif ($_GET['resource'] == 'video') {
                 $sys_resource = api_get_path(SYS_COURSE_PATH) . $my_course . '/document' . $row['path'];
                 $resource_info = pathinfo($sys_resource);
                 //$video_web_path = api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/flvPlayer/';
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
                                   <tbody>
                                       <tr>
                                          <td valign="top">                     
                                          <!-- Video player plugin -->
                                             <div id="player986311-parent" align="left">
                                             <div style="border-style: none; height: 240px; width: 375px; overflow: hidden; background-color: rgb(220, 220, 220);" id="test">
                                             <div style="display: none; visibility: hidden; width: 0px; height: 0px; overflow: hidden;" id="player986311-config">url=' . $resource . ' width=375 height=240 loop=1 play=true downloadable=false fullscreen=true</div>
                                                 <div class="thePlayer" id="player986311">';
                 if (in_array($resource_info['extension'], array('flv', 'mp4', 'mov'))) {
                     /*if (!api_is_windows_os()) {
                           $valcontent .= '   <script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                                               <object id="player986311-parent2" name="player986311-parent2" width="375" height="240" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
                                               <param name="movie" value="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf" />
                                               <param name="allowFullScreen" value="true" />
                                               <param name="allowscriptaccess" value="always" />
                                               <param name="seamlesstabbing" value="true" />
                                               <param name="wmode" value="transparent" />
                                               <param name="flashvars" value="id=player986311-parent2&autostart=true&repeat=false&file='.$resource.'&skin='.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip&controlbar.position=over"  />                
                                               </object>
                                          ';                                                          
                       } else {*/
                     $valcontent .= '           
                             <script src="' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                             <div id="player986311-parent2">Loading the player ...</div>
                             <script type="text/javascript">jwplayer("player986311-parent2").setup({flashplayer: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf",autostart: "true",repeat: "always",file: "' . $resource . '",height: 240,width: 375,skin: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip"});</script>';
                     //}
                 } else {
                     $sType = '';
                     if ($resource_info['extension'] == 'mpg' || $resource_info['extension'] == 'mpeg') {
                         $sType = 'video/mpeg';
                     } else {
                         if ($resource_info['extension'] == 'avi' || $resource_info['extension'] == 'wmv' || $resource_info['extension'] == 'asf') {
                             $sType = 'video/x-msvideo';
                         }
                     }
                     $valcontent .= '<embed type="' . $sType . '" src="' . $resource . '"
                            autosize = "false"
                            autostart = "true"
                            loop = "false"
                            fullscreen = "true"
                            showcontrols = "true"
                            showpositioncontrols = "false"
                            showtracker = "true"
                            showaudiocontrols = "true"
                            showgotobar = "true"
                            showstatusbar = "true"
                            pluginspace = "http://www.microsoft.com/Windows/MediaPlayer/"
                            codebase = "http://www.microsoft.com/Windows/MediaPlayer/"';
                     $valcontent .= 'width="375px" height="240px"';
                     $valcontent .= '></embed>';
                 }
                 $valcontent .= '              </div>
                                              </div>
                                           </div> 
                                         </td>
                                       </tr>
                                   </tbody>
                               </table>';
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title\n\t\t\t\t\t\t\t\t\tFROM " . $tbl_doc . "\n\t\t\t\t\t\t\t\t\tWHERE id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc, __FILE__, __LINE__);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     /* $return = '	<div class="row">
        <div class="form_header">'; */
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM " . $tbl_lp_item . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlp_id = " . $this->lp_id;
     $result = Database::query($sql, __FILE__, __LINE__);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = $this->arrMenu;
     unset($this->arrMenu);
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
     }
     require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
     $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
     $defaults["title"] = Security::remove_XSS(api_convert_encoding($item_title, api_get_system_encoding(), $this->encoding));
     if (empty($item_title)) {
         $defaults["title"] = Security::remove_XSS($item_title);
     }
     $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('html', '<div style="float:left;padding-right:135px;">');
         $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
         $form->applyFilter('title', 'html_filter');
         $form->addElement('html', '</div>');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     //$parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
     $parent_select =& $form->addElement('select', 'parent', '', '', 'class="learnpath_item_form" style="width:40%;display:none;float:left" onchange="load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // the LP name is also the first section and is not in the same charset like the other sections
             $value['value'] = Security::remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = $_SESSION['parent_item_id'];
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
         }
     }
     //$position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
     $position =& $form->addElement('select', 'previous', '', '', 'id="idPosition" class="learnpath_item_form" style="width:40%;float:left;display:none;"');
     $position->addOption(get_lang("FirstPosition"), 0);
     foreach ($arrHide as $key => $value) {
         $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         //comented the prerequisites, only visible in edit (new document)
         //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
         //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
         // form element for uploading an mp3 file
         //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
         //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
         /* Code deprecated - moved to lp level (not lp-item)
             if ( api_get_setting('search_enabled') === 'true' )
             {
             //add terms field
             $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
             $terms->setValue($item_terms);
             }
            */
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
             }
         }
         /* 	foreach($arrHide as $key => $value){
              $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
              if($key==$s_selected_position && $action == 'add'){
              $select_prerequisites -> setSelected(0);
              }
              elseif($key==$id_prerequisite && $action == 'edit'){
              $select_prerequisites -> setSelected($id_prerequisite);
              }
              }
             */
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to claculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     $relative_path = $extra_info['dir'];
                     if ($relative_path == 'n/') {
                         // A new document, it is in the root of the repository.
                         $relative_path = '';
                         $relative_prefix = '';
                     } else {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $relative_path);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     }
                     $editor_config = array('ToolbarSet' => api_is_allowed_to_edit() ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '700', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/', 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'save';
                         $text = get_lang('Validate');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('html', '<div style="float:right;margin-top:-55px">');
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $form->addElement('html', '</div>');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('{label}{element}', 'content_lp');
                     //$form->addElement('html', '<div');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     //$form->addElement('html', '</div>');
                     $defaults["content_lp"] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     // Add template to content
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $defaults["content_lp"] = $valcontent;
         $defaults["title"] = $valtitle;
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save" style="float:right"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('html', '<div style="float:right;margin-top:-55px">');
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
         $form->addElement('html', '</div>');
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $defaults = array();
     $nb_matches = $nb_options = 2;
     $matches = array();
     $answer = null;
     $counter = 1;
     if (isset($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0) {
             for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                 $correct = $answer->isCorrect($i);
                 if (empty($correct)) {
                     $matches[$answer->selectAutoId($i)] = chr(64 + $counter);
                     $counter++;
                 }
             }
         }
     }
     if ($form->isSubmitted()) {
         $nb_matches = $form->getSubmitValue('nb_matches');
         $nb_options = $form->getSubmitValue('nb_options');
         if (isset($_POST['lessOptions'])) {
             $nb_matches--;
             $nb_options--;
         }
         if (isset($_POST['moreOptions'])) {
             $nb_matches++;
             $nb_options++;
         }
     } else {
         if (!empty($this->id)) {
             if (count($answer->nbrAnswers) > 0) {
                 $nb_matches = $nb_options = 0;
                 for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                     if ($answer->isCorrect($i)) {
                         $nb_matches++;
                         $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                         $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
                         $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
                     } else {
                         $nb_options++;
                         $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                     }
                 }
             }
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
             $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
             $defaults['matches[2]'] = '2';
             $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
             $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
         }
     }
     if (empty($matches)) {
         for ($i = 1; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     } else {
         for ($i = $counter; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     }
     $form->addElement('hidden', 'nb_matches', $nb_matches);
     $form->addElement('hidden', 'nb_options', $nb_options);
     // DISPLAY MATCHES
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="5%">' . get_lang('Number') . '</th>
                 <th width="70%">' . get_lang('Answer') . '</th>
                 <th width="15%">' . get_lang('MatchesTo') . '</th>
                 <th width="10%">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('MakeCorrespond'));
     $form->addHtml($html);
     if ($nb_matches < 1) {
         $nb_matches = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
         $form->addHtml('<tr>');
         $form->addHtml("<td>{$i}</td>");
         $form->addText("answer[{$i}]", null);
         $form->addSelect("matches[{$i}]", null, $matches);
         $form->addText("weighting[{$i}]", null, true, ['value' => 10]);
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody></table>');
     $group = array();
     $form->addGroup($group);
     // DISPLAY OPTIONS
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="15%">' . get_lang('Number') . '</th>
                 <th width="85%">' . get_lang('Answer') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHtml($html);
     if ($nb_options < 1) {
         $nb_options = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_options; ++$i) {
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "option[{$i}]");
         $form->addHtml('<tr>');
         $form->addHtml('<td>' . chr(64 + $i) . '</td>');
         $form->addText("option[{$i}]", null);
         $form->addHtml('</tr>');
     }
     $form->addHtml('</table>');
     $group = array();
     global $text;
     // setting the save button here and not in the question class.php
     $group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessOptions', true);
     $group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreOptions', true);
     $group[] = $form->addButtonSave($text, 'submitQuestion', true);
     $form->addGroup($group);
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults($defaults);
         }
     }
     $form->setConstants(array('nb_matches' => $nb_matches, 'nb_options' => $nb_options));
 }
 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     // Getting the exercise list
     $obj_ex = $_SESSION['objExercise'];
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line defines how many questions by default appear when creating a choice question
     // The previous default value was 2. See task #1759.
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
         Types of Feedback
         $feedback_option[0]=get_lang('Feedback');
        $feedback_option[1]=get_lang('DirectFeedback');
        $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
         //Scenario
         $editor_config['Width'] = '250';
         $editor_config['Height'] = '110';
         $comment_title = '<th width="500px" >' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="350px" >' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th>' . get_lang('Comment') . '</th>';
     }
     $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>
                     ' . $comment_title . '
                     ' . $feedback_title . '
                 <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;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     //Feedback SELECT
     $question_list = $obj_ex->selectQuestionList();
     $select_question = array();
     $select_question[0] = get_lang('SelectTargetQuestion');
     require_once '../newscorm/learnpathList.class.php';
     if (is_array($question_list)) {
         foreach ($question_list as $key => $questionid) {
             //To avoid warning messages
             if (!is_numeric($questionid)) {
                 continue;
             }
             $question = Question::read($questionid);
             $select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
         }
     }
     $select_question[-1] = get_lang('ExitTest');
     $list = new LearnpathList(api_get_user_id());
     $flat_list = $list->get_flat_list();
     $select_lp_id = array();
     $select_lp_id[0] = get_lang('SelectTargetLP');
     foreach ($flat_list as $id => $details) {
         $select_lp_id[$id] = cut($details['lp_name'], 20);
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addElement('html', '<tr>');
         if (isset($answer) && is_object($answer)) {
             if ($answer->correct[$i]) {
                 $correct = $i;
             }
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $item_list = explode('@@', $answer->destination[$i]);
             $try = $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}&nbsp;', 'submitQuestion');
     $renderer->setElementTemplate('{element}&nbsp;', 'lessAnswers');
     $renderer->setElementTemplate('{element}&nbsp;', '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));
 }
Example #9
0
    <?php 
$id = $_REQUEST['question'];
$objQuestionTmp = Question::read($id);
echo "<tr><td><b>" . get_lang('Question') . " : </b>";
echo $objQuestionTmp->selectTitle();
echo "</td></tr>";
echo " <br><tr><td><b><br>" . get_lang('Answer') . " : </b></td></tr>";
$objAnswerTmp = new Answer($id);
$num = $objAnswerTmp->selectNbrAnswers();
$objAnswerTmp->read();
for ($i = 1; $i <= $num; $i++) {
    echo "<tr><td width='10%'> ";
    $ans = $objAnswerTmp->answer[$i];
    $form = new FormValidator('feedbackform', 'post', api_get_self() . "?" . api_get_cidreq() . "&modifyQuestion=" . $modifyQuestion . "&newQuestion=" . $newQuestion);
    $obj_registration_form = new FormValidator('frmRegistration', 'POST');
    $renderer =& $obj_registration_form->defaultRenderer();
    $renderer->setElementTemplate('<tr>
	<td align="left" style="" valign="top" width=30%>{label}
		<!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required -->
	</td>
	<td align="left" width=70%>{element}
		<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
	</td>
</tr>');
    $form->add_html_editor('Feedback', $i . '.' . $ans, false, false, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '600', 'Height' => '200'));
    $form->display();
    echo "</td>";
}
?>
    <form name="frm" action="javascript: void(0);" method="post">
        Click Ok to finish <input type="submit" value="Ok"/>
Example #10
0
 /**
  * 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]);
 }
/**
 * Search options
 * TODO: support for multiple site. aka $_configuration['access_url'] == 1
 * @author Marco Villegas <*****@*****.**>
 */
function handle_search()
{
    global $SettingsStored, $_configuration;
    $search_enabled = api_get_setting('search_enabled');
    $settings = api_get_settings('Search');
    if ($search_enabled !== 'true' || count($settings) < 1) {
        Display::display_error_message(get_lang('SearchFeatureNotEnabledComment'));
        return;
    }
    require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
    $form = new FormValidator('search-options', 'post', api_get_self() . '?category=Search');
    $renderer =& $form->defaultRenderer();
    $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>' . "\n");
    $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>' . "\n" . '<div class="sectionvalue">{element}</div>' . "\n");
    //search_show_unlinked_results
    $form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle'));
    $form->addElement('label', null, get_lang('SearchShowUnlinkedResultsComment'));
    $values = get_settings_options('search_show_unlinked_results');
    $group = array();
    foreach ($values as $key => $value) {
        $element =& $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
        $group[] = $element;
    }
    $form->addGroup($group, 'search_show_unlinked_results', get_lang('SearchShowUnlinkedResultsComment'), '<br />', false);
    $default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results');
    //search_prefilter_prefix
    $form->addElement('header', null, get_lang('SearchPrefilterPrefix'));
    $form->addElement('label', null, get_lang('SearchPrefilterPrefixComment'));
    $specific_fields = get_specific_field_list();
    $sf_values = array();
    foreach ($specific_fields as $sf) {
        $sf_values[$sf['code']] = $sf['name'];
    }
    $group = array();
    $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
    $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
    //$form->addRule('search_show_unlinked_results', get_lang('ThisFieldIsRequired'), 'required');
    $form->addElement('style_submit_button', 'search-options-save', get_lang('Ok'));
    $form->setDefaults($default_values);
    if ($form->validate()) {
        $formvalues = $form->exportValues();
        $r = api_set_settings_category('Search', 'false', $_configuration['access_url']);
        // Save the settings
        foreach ($formvalues as $key => $value) {
            $result = api_set_setting($key, $value, null, null);
        }
        Display::display_normal_message($SettingsStored);
    } else {
        echo '<div id="search-options-form">';
        $form->display();
        echo '</div>';
    }
}
 /**
  * Return the HTML form to display an item (generally a section/module item)
  * @param	string	Item type (module/dokeos_module)
  * @param	string	Title (optional, only when creating)
  * @param	string	Action ('add'/'edit')
  * @param	integer	lp_item ID
  * @param	mixed	Extra info
  * @return	string 	HTML form
  */
 public function display_item_form($item_type, $title = '', $action = 'add_item', $id = 0, $extra_info = 'new')
 {
     $course_id = api_get_course_int_id();
     $_course = api_get_course_info();
     global $charset;
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     if ($id != 0 && is_array($extra_info)) {
         $item_title = $extra_info['title'];
         $item_description = $extra_info['description'];
         $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
         $item_path_fck = '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
     } else {
         $item_title = '';
         $item_description = '';
         $item_path_fck = '';
     }
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $id = intval($id);
     $sql = "SELECT * FROM " . $tbl_lp_item . "\n                WHERE\n                    c_id = " . $course_id . " AND\n                    lp_id = " . $this->lp_id . " AND\n                    id != {$id}";
     if ($item_type == 'module') {
         $sql .= " AND parent_item_id = 0";
     }
     $result = Database::query($sql);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite'], 'display_order' => $row['display_order']);
     }
     $this->tree_array($arrLP);
     $arrLP = isset($this->arrMenu) ? $this->arrMenu : null;
     unset($this->arrMenu);
     $url = api_get_self() . '?' . api_get_cidreq() . '&action=' . $action . '&type=' . $item_type . '&lp_id=' . $this->lp_id;
     $form = new FormValidator('form', 'POST', $url);
     $defaults['title'] = !empty($item_title) ? api_html_entity_decode($item_title, ENT_QUOTES, $charset) : '';
     $defaults['description'] = $item_description;
     $form->addElement('header', $title);
     //$arrHide = array($id);
     $arrHide[0]['value'] = Security::remove_XSS($this->name);
     $arrHide[0]['padding'] = 20;
     $charset = api_get_system_encoding();
     if ($item_type != 'module' && $item_type != 'dokeos_module') {
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($action != 'add') {
                 if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                     $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                     $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
                     if ($parent == $arrLP[$i]['id']) {
                         $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                     }
                 }
             } else {
                 if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                     $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                     $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
                     if ($parent == $arrLP[$i]['id']) {
                         $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                     }
                 }
             }
         }
         if ($action != 'move') {
             $form->addElement('text', 'title', get_lang('Title'));
             $form->applyFilter('title', 'html_filter');
             $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
         } else {
             $form->addElement('hidden', 'title');
         }
         $parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', array('id' => 'idParent', 'onchange' => "javascript: load_cbo(this.value);"));
         foreach ($arrHide as $key => $value) {
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         if (!empty($s_selected_parent)) {
             $parent_select->setSelected($s_selected_parent);
         }
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     // POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             //this is the same!
             if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
         }
     }
     $position = $form->addElement('select', 'previous', get_lang('Position'), '', array('id' => 'previous'));
     $padding = isset($value['padding']) ? $value['padding'] : 0;
     $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
     foreach ($arrHide as $key => $value) {
         $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
     }
     if (!empty($s_selected_position)) {
         $position->setSelected($s_selected_position);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $form->addButtonSave(get_lang('SaveSection'), 'submit_button');
     if ($item_type == 'module' || $item_type == 'dokeos_module') {
         $form->addElement('hidden', 'parent', '0');
     }
     //fix in order to use the tab
     if ($item_type == 'chapter') {
         $form->addElement('hidden', 'type', 'chapter');
     }
     $extension = null;
     if (!empty($item_path)) {
         $extension = pathinfo($item_path, PATHINFO_EXTENSION);
     }
     //assets can't be modified
     //$item_type == 'asset' ||
     if ($item_type == 'sco' && ($extension == 'html' || $extension == 'htm')) {
         if ($item_type == 'sco') {
             $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
         }
         $renderer = $form->defaultRenderer();
         $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
         $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true);
         $form->addHtmlEditor('content_lp', '', false, false, $editor_config);
         $content_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . $item_path_fck;
         $defaults['content_lp'] = file_get_contents($content_path);
     }
     $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4;
     // The previous default value was 2. See task #1759.
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : isset($_POST['moreAnswers']) ? 1 : 0;
     $course_id = api_get_course_int_id();
     $obj_ex = $_SESSION['objExercise'];
     $renderer =& $form->defaultRenderer();
     $defaults = array();
     $html = '<table class="table table-striped table-hover">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th>' . get_lang('Number') . '</th>';
     $html .= '<th>' . get_lang('True') . '</th>';
     $html .= '<th>' . get_lang('False') . '</th>';
     $html .= '<th>' . get_lang('Answer') . '</th>';
     // show column comment when feedback is enable
     if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
         $html .= '<th>' . get_lang('Comment') . '</th>';
     }
     $html .= '</tr>';
     $html .= '</thead>';
     $html .= '<tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $correct = 0;
     $answer = null;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     $boxes_names = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     // Can be more options
     $option_data = Question::readQuestionOption($this->id, $course_id);
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addHtml('<tr>');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, 'value="' . $i . '"');
         $answer_number->freeze();
         if (is_object($answer)) {
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $correct = $answer->correct[$i];
             $defaults['correct[' . $i . ']'] = $correct;
             $j = 1;
             if (!empty($option_data)) {
                 foreach ($option_data as $id => $data) {
                     $form->addElement('radio', 'correct[' . $i . ']', null, null, $id);
                     $j++;
                     if ($j == 3) {
                         break;
                     }
                 }
             }
         } else {
             $form->addElement('radio', 'correct[' . $i . ']', null, null, 1);
             $form->addElement('radio', 'correct[' . $i . ']', null, null, 2);
             $defaults['answer[' . $i . ']'] = '';
             $defaults['comment[' . $i . ']'] = '';
             $defaults['correct[' . $i . ']'] = '';
         }
         $boxes_names[] = 'correct[' . $i . ']';
         $form->addHtmlEditor("answer[{$i}]", get_lang('ThisFieldIsRequired'), true, true, ['ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100']);
         // show comment when feedback is enable
         if ($obj_ex->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
             $form->addElement('html_editor', 'comment[' . $i . ']', null, array(), array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '100'));
         }
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody></table>');
     $correctInputTemplate = '<div class="form-group">';
     $correctInputTemplate .= '<label class="col-sm-2 control-label">';
     $correctInputTemplate .= '<span class="form_required">*</span>' . get_lang('Score');
     $correctInputTemplate .= '</label>';
     $correctInputTemplate .= '<div class="col-sm-8">';
     $correctInputTemplate .= '<table>';
     $correctInputTemplate .= '<tr>';
     $correctInputTemplate .= '<td>';
     $correctInputTemplate .= get_lang('Correct') . '{element}';
     $correctInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
     $correctInputTemplate .= '</td>';
     $wrongInputTemplate = '<td>';
     $wrongInputTemplate .= get_lang('Wrong') . '{element}';
     $wrongInputTemplate .= '<!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->';
     $wrongInputTemplate .= '</td>';
     $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));
 }
Example #14
0
 /**
  * Returns the form to update or create a document
  * @param    string    Action (add/edit)
  * @param    integer    ID of the lp_item (if already exists)
  * @param    mixed    Integer if document ID, string if info ('new')
  * @return    string    HTML form
  */
 public function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     $course_id = api_get_course_int_id();
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             $path_parts = pathinfo($extra_info['dir']);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     // If action==add an existing document
     // We don't display the document form if it's not an editable document (html or txt file).
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = " . $course_id . " AND id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title FROM " . $tbl_doc . "\n                        WHERE c_id = " . $course_id . " AND id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     $return = '<legend>';
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "SELECT * FROM " . $tbl_lp_item . "\n                WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     $result = Database::query($sql);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = null;
     if (isset($this->arrMenu)) {
         $arrLP = $this->arrMenu;
         unset($this->arrMenu);
     }
     if ($action == 'add') {
         $return .= get_lang('CreateTheDocument');
     } elseif ($action == 'move') {
         $return .= get_lang('MoveTheCurrentDocument');
     } else {
         $return .= get_lang('EditTheCurrentDocument');
     }
     $return .= '</legend>';
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
     }
     $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', array('enctype' => "multipart/form-data"));
     $defaults['title'] = Security::remove_XSS($item_title);
     if (empty($item_title)) {
         $defaults['title'] = Security::remove_XSS($item_title);
     }
     $defaults['description'] = $item_description;
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('text', 'title', get_lang('Title'), array('id' => 'idTitle', 'class' => 'span4'));
         $form->applyFilter('title', 'html_filter');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     $parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // The LP name is also the first section and is not in the same charset like the other sections.
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = Session::read('parent_item_id');
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     $s_selected_position = null;
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
         }
     }
     $position = $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
     $position->addOption(get_lang('FirstPosition'), 0);
     foreach ($arrHide as $key => $value) {
         $padding = isset($value['padding']) ? $value['padding'] : 0;
         $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
             }
         }
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to calculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     // A new document, it is in the root of the repository.
                     $relative_path = '';
                     $relative_prefix = '';
                     if (is_array($extra_info) && $extra_info != 'new') {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $extra_info['dir']);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     } else {
                         $_course = api_get_course_info();
                         $result = $this->generate_lp_folder($_course);
                         $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
                         $relative_prefix = '../../';
                     }
                     $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'add';
                         $text = get_lang('LPCreateDocument');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
                     $form->addElement('html', '<div>');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     $form->addElement('html', '</div>');
                     $defaults['content_lp'] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
Example #15
0
 $renderersetCustomElementTemplate->setCustomElementTemplate('<tr><td>{element}</td></tr>');
 $form->addElement('html', $option1);
 $form->addElement('checkbox', 'left', null, get_lang('Yes'));
 $form->addElement('button', 'submit', get_lang('Confirm'), array('class' => 'btn btn-primary'));
 $formHtml = $form->return_form();
 if ($form->validate()) {
     $result = $form->getSubmitValues();
     if (isset($result['left']) && $result['left']) {
         $_SESSION['before_login_accepted'] = 1;
         header('Location: ' . $urlOption1);
         exit;
     }
 }
 $form2 = new FormValidator('form');
 if (!empty($option2) && !empty($urlOption2)) {
     $renderer =& $form2->defaultRenderer();
     $renderer->setHeaderTemplate('');
     $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
     $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
     $form2->addElement('html', $option2);
     $form2->addElement('checkbox', 'right', null, get_lang('Yes'));
     $form2->addElement('button', 'submit', get_lang('Send'));
     $formHtml2 = $form2->return_form();
     if ($form2->validate()) {
         $result = $form2->getSubmitValues();
         if (isset($result['right']) && $result['right']) {
             header('Location: ' . $urlOption2);
             exit;
         }
     }
 }
Example #16
0
 /**
  * Builds the form that enables the user to
  * select a directory to browse/upload in
  *
  * @param array 	An array containing the folders we want to be able to select
  * @param string	The current folder (path inside of the "document" directory, including the prefix "/")
  * @param string	Group directory, if empty, prevents documents to be uploaded (because group documents cannot be uploaded in root)
  * @param	boolean	Whether to change the renderer (this will add a template <span> to the QuickForm object displaying the form)
  * @todo this funcionality is really bad : jmontoya
  * @return string html form
  */
 public static function build_directory_selector($folders, $document_id, $group_dir = '', $change_renderer = false)
 {
     $doc_table = Database::get_course_table(TABLE_DOCUMENT);
     $course_id = api_get_course_int_id();
     $folder_titles = array();
     if (is_array($folders)) {
         $escaped_folders = array();
         foreach ($folders as $key => &$val) {
             $escaped_folders[$key] = Database::escape_string($val);
         }
         $folder_sql = implode("','", $escaped_folders);
         $sql = "SELECT * FROM {$doc_table}\n                WHERE filetype = 'folder' AND c_id = {$course_id} AND path IN ('" . $folder_sql . "')";
         $res = Database::query($sql);
         $folder_titles = array();
         while ($obj = Database::fetch_object($res)) {
             $folder_titles[$obj->path] = $obj->title;
         }
     }
     $form = new FormValidator('selector', 'GET', api_get_self() . '?' . api_get_cidreq());
     $form->addElement('hidden', 'cidReq', api_get_course_id());
     $parent_select = $form->addSelect('id', get_lang('CurrentDirectory'), '', array('onchange' => 'javascript: document.selector.submit();'));
     if ($change_renderer) {
         $renderer = $form->defaultRenderer();
         $renderer->setElementTemplate('<span>{label} : {element}</span> ', 'curdirpath');
     }
     // Group documents cannot be uploaded in the root
     if (empty($group_dir)) {
         $parent_select->addOption(get_lang('Documents'), '/');
         if (is_array($folders)) {
             foreach ($folders as $folder_id => &$folder) {
                 $selected = $document_id == $folder_id ? ' selected="selected"' : '';
                 $path_parts = explode('/', $folder);
                 $folder_titles[$folder] = cut($folder_titles[$folder], 80);
                 $counter = count($path_parts) - 2;
                 if ($counter > 0) {
                     $label = str_repeat('&nbsp;&nbsp;&nbsp;', $counter) . ' &mdash; ' . $folder_titles[$folder];
                 } else {
                     $label = ' &mdash; ' . $folder_titles[$folder];
                 }
                 $parent_select->addOption($label, $folder_id);
                 if ($selected != '') {
                     $parent_select->setSelected($folder_id);
                 }
             }
         }
     } else {
         if (!empty($folders)) {
             foreach ($folders as $folder_id => &$folder) {
                 $selected = $document_id == $folder_id ? ' selected="selected"' : '';
                 $label = $folder_titles[$folder];
                 if ($folder == $group_dir) {
                     $label = get_lang('Documents');
                 } else {
                     $path_parts = explode('/', str_replace($group_dir, '', $folder));
                     $label = cut($label, 80);
                     $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2) . ' &mdash; ' . $label;
                 }
                 $parent_select->addOption($label, $folder_id);
                 if ($selected != '') {
                     $parent_select->setSelected($folder_id);
                 }
             }
         }
     }
     $html = $form->toHtml();
     return $html;
 }
Example #17
0
    /**
     * Shows a question
     * @param Question $objQuestionTmp
     * @param bool $only_questions if true only show the questions, no exercise title
     * @param bool $origin origin i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool $show_title
     * @param bool $freeze
     * @param array $user_choice
     * @param bool $show_comment
     * @param null $exercise_feedback
     * @param bool $show_answers
     * @param null $modelType
     * @param bool $categoryMinusOne
     * @return bool|null|string
     */
    public function showQuestion(Question $objQuestionTmp, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false, $modelType = null, $categoryMinusOne = true)
    {
        // Text direction for the current language
        //$is_ltr_text_direction = api_get_text_direction() != 'rtl';
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        //api_is_allowed_to_edit() && false;
        // Reads question information
        if (!$objQuestionTmp) {
            // Question not found
            return false;
        }
        $html = null;
        $questionId = $objQuestionTmp->id;
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = null;
        $form = new FormValidator('question');
        $renderer = $form->defaultRenderer();
        $form_template = '{content}';
        $renderer->setFormTemplate($form_template);
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    $categoryName = TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id, null, true, $categoryMinusOne);
                    $html .= $categoryName;
                    $html .= Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                } else {
                    $html .= '<div class="media">';
                    $html .= '<div class="pull-left">';
                    $html .= '<div class="media-object">';
                    $html .= Display::div($current_item, array('class' => 'question_no_title'));
                    $html .= '</div>';
                    $html .= '</div>';
                    $html .= '<div class="media-body">';
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                    $html .= '</div>';
                    $html .= '</div>';
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return null;
            }
            $html .= '<div class="question_options">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId, null, $this);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $course_id = api_get_course_int_id();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if ($answerType == MATCHING || $answerType == DRAGGABLE) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="ui-widget ui-helper-clearfix">
                            <ul class="drag_question ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= '<div id="drag' . $questionId . '_question" class="drag_question">';
                    $s .= '<table class="data_table">';
                }
                $j = 1;
                //iterate through answers
                $letter = 'A';
                //mark letters for each answer
                $answer_matching = array();
                $capital_letter = array();
                //for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
                foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $answer = $objAnswerTmp->selectAnswer($answerId);
                    if ($answerCorrect == 0) {
                        // options (A, B, C, ...) that will be put into the list-box
                        // have the "correct" field set to 0 because they are answer
                        $capital_letter[$j] = $letter;
                        //$answer_matching[$j]=$objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $answer_matching[$j] = array('id' => $answerId, 'answer' => $answer);
                        $j++;
                        $letter++;
                    }
                }
                $i = 1;
                $select_items[0]['id'] = 0;
                $select_items[0]['letter'] = '--';
                $select_items[0]['answer'] = '';
                foreach ($answer_matching as $id => $value) {
                    $select_items[$i]['id'] = $value['id'];
                    $select_items[$i]['letter'] = $capital_letter[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $num_suggestions = $nbrAnswers - $j + 1;
            } elseif ($answerType == FREE_ANSWER) {
                $content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null;
                $toolBar = 'TestFreeAnswer';
                if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) {
                    $toolBar = 'TestFreeAnswerStrict';
                }
                $form->addElement('html_editor', "choice[" . $questionId . "]", null, array('id' => "choice[" . $questionId . "]"), array('ToolbarSet' => $toolBar));
                $form->setDefaults(array("choice[" . $questionId . "]" => $content));
                $s .= $form->return_form();
            } elseif ($answerType == ORAL_EXPRESSION) {
                // Add nanogong
                if (api_get_setting('document.enable_nanogong') == 'true') {
                    //@todo pass this as a parameter
                    global $exercise_stat_info, $exerciseId;
                    if (!empty($exercise_stat_info)) {
                        $params = array('exercise_id' => $exercise_stat_info['exe_exo_id'], 'exe_id' => $exercise_stat_info['exe_id'], 'question_id' => $questionId);
                    } else {
                        $params = array('exercise_id' => $exerciseId, 'exe_id' => 'temp_exe', 'question_id' => $questionId);
                    }
                    $nano = new Nanogong($params);
                    $s .= $nano->show_button();
                }
                $form->addElement('html_editor', "choice[" . $questionId . "]", null, array('id' => "choice[" . $questionId . "]"), array('ToolbarSet' => 'TestFreeAnswer'));
                //$form->setDefaults(array("choice[".$questionId."]" => $content));
                $s .= $form->return_form();
            }
            // Now navigate through the possible answers, using the max number of
            // answers for the question as a limiter
            $lines_count = 1;
            // a counter for matching-type answers
            if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
                $header = Display::tag('th', get_lang('Options'));
                foreach ($objQuestionTmp->options as $item) {
                    $header .= Display::tag('th', $item);
                }
                if ($show_comment) {
                    $header .= Display::tag('th', get_lang('Feedback'));
                }
                $s .= '<table class="data_table">';
                $s .= Display::tag('tr', $header, array('style' => 'text-align:left;'));
            }
            if ($show_comment) {
                if (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, GLOBAL_MULTIPLE_ANSWER))) {
                    $header = Display::tag('th', get_lang('Options'));
                    if ($exercise_feedback == EXERCISE_FEEDBACK_TYPE_END) {
                        $header .= Display::tag('th', get_lang('Feedback'));
                    }
                    $s .= '<table class="data_table">';
                    $s .= Display::tag('tr', $header, array('style' => 'text-align:left;'));
                }
            }
            $matching_correct_answer = 0;
            $user_choice_array = array();
            if (!empty($user_choice)) {
                foreach ($user_choice as $item) {
                    $user_choice_array[] = $item['answer'];
                }
            }
            foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
                $answer = $objAnswerTmp->selectAnswer($answerId);
                $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                $comment = $objAnswerTmp->selectComment($answerId);
                //$numAnswer       = $objAnswerTmp->selectAutoId($answerId);
                $numAnswer = $answerId;
                $attributes = array();
                // Unique answer
                if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION))) {
                    $input_id = 'choice-' . $questionId . '-' . $answerId;
                    if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer) {
                        $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1);
                    } else {
                        $attributes = array('id' => $input_id);
                    }
                    if ($debug_mark_answer) {
                        if ($answerCorrect) {
                            $attributes['checked'] = 1;
                            $attributes['selected'] = 1;
                        }
                    }
                    $answer = Security::remove_XSS($answer);
                    $s .= Display::input('hidden', 'choice2[' . $questionId . ']', '0');
                    $answer_input = null;
                    if ($answerType == UNIQUE_ANSWER_IMAGE) {
                        $attributes['style'] = 'display:none';
                        $answer_input .= '<div id="answer' . $questionId . $numAnswer . '" style="float:left" class="highlight_image_default highlight_image">';
                    }
                    $answer_input .= '<label class="radio">';
                    $answer_input .= Display::input('radio', 'choice[' . $questionId . ']', $numAnswer, $attributes);
                    $answer_input .= $answer;
                    $answer_input .= '</label>';
                    if ($answerType == UNIQUE_ANSWER_IMAGE) {
                        $answer_input .= "</div>";
                    }
                    if ($show_comment) {
                        $s .= '<tr><td>';
                        $s .= $answer_input;
                        $s .= '</td>';
                        $s .= '<td>';
                        $s .= $comment;
                        $s .= '</td>';
                        $s .= '</tr>';
                    } else {
                        $s .= $answer_input;
                    }
                } elseif (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_TRUE_FALSE, GLOBAL_MULTIPLE_ANSWER))) {
                    $input_id = 'choice-' . $questionId . '-' . $answerId;
                    $answer = Security::remove_XSS($answer);
                    if (in_array($numAnswer, $user_choice_array)) {
                        $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1);
                    } else {
                        $attributes = array('id' => $input_id);
                    }
                    if ($debug_mark_answer) {
                        if ($answerCorrect) {
                            $attributes['checked'] = 1;
                            $attributes['selected'] = 1;
                        }
                    }
                    if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
                        $s .= '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />';
                        $answer_input = '<label class="checkbox">';
                        $answer_input .= Display::input('checkbox', 'choice[' . $questionId . '][' . $numAnswer . ']', $numAnswer, $attributes);
                        $answer_input .= $answer;
                        $answer_input .= '</label>';
                        if ($show_comment) {
                            $s .= '<tr><td>';
                            $s .= $answer_input;
                            $s .= '</td>';
                            $s .= '<td>';
                            $s .= $comment;
                            $s .= '</td>';
                            $s .= '</tr>';
                        } else {
                            $s .= $answer_input;
                        }
                    } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
                        $my_choice = array();
                        if (!empty($user_choice_array)) {
                            foreach ($user_choice_array as $item) {
                                $item = explode(':', $item);
                                $my_choice[$item[0]] = $item[1];
                            }
                        }
                        $s .= '<tr>';
                        $s .= Display::tag('td', $answer);
                        if (!empty($quiz_question_options)) {
                            foreach ($quiz_question_options as $id => $item) {
                                $id = $item['iid'];
                                if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) {
                                    $attributes = array('checked' => 1, 'selected' => 1);
                                } else {
                                    $attributes = array();
                                }
                                if ($debug_mark_answer) {
                                    if ($id == $answerCorrect) {
                                        $attributes['checked'] = 1;
                                        $attributes['selected'] = 1;
                                    }
                                }
                                $s .= Display::tag('td', Display::input('radio', 'choice[' . $questionId . '][' . $numAnswer . ']', $id, $attributes), array('style' => ''));
                            }
                        }
                        if ($show_comment) {
                            $s .= '<td>';
                            $s .= $comment;
                            $s .= '</td>';
                        }
                        $s .= '</tr>';
                    }
                } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
                    // multiple answers
                    $input_id = 'choice-' . $questionId . '-' . $answerId;
                    if (in_array($numAnswer, $user_choice_array)) {
                        $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1);
                    } else {
                        $attributes = array('id' => $input_id);
                    }
                    if ($debug_mark_answer) {
                        if ($answerCorrect) {
                            $attributes['checked'] = 1;
                            $attributes['selected'] = 1;
                        }
                    }
                    $answer = Security::remove_XSS($answer);
                    $answer_input = '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />';
                    $answer_input .= '<label class="checkbox">';
                    $answer_input .= Display::input('checkbox', 'choice[' . $questionId . '][' . $numAnswer . ']', 1, $attributes);
                    $answer_input .= $answer;
                    $answer_input .= '</label>';
                    if ($show_comment) {
                        $s .= '<tr>';
                        $s .= '<td>';
                        $s .= $answer_input;
                        $s .= '</td>';
                        $s .= '<td>';
                        $s .= $comment;
                        $s .= '</td>';
                        $s .= '</tr>';
                    } else {
                        $s .= $answer_input;
                    }
                } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
                    $s .= '<input type="hidden" name="choice2[' . $questionId . ']" value="0" />';
                    $my_choice = array();
                    if (!empty($user_choice_array)) {
                        foreach ($user_choice_array as $item) {
                            $item = explode(':', $item);
                            $my_choice[$item[0]] = $item[1];
                        }
                    }
                    $answer = Security::remove_XSS($answer);
                    $s .= '<tr>';
                    $s .= Display::tag('td', $answer);
                    foreach ($objQuestionTmp->options as $key => $item) {
                        if (isset($my_choice[$numAnswer]) && $key == $my_choice[$numAnswer]) {
                            $attributes = array('checked' => 1, 'selected' => 1);
                        } else {
                            $attributes = array();
                        }
                        if ($debug_mark_answer) {
                            if ($key == $answerCorrect) {
                                $attributes['checked'] = 1;
                                $attributes['selected'] = 1;
                            }
                        }
                        $s .= Display::tag('td', Display::input('radio', 'choice[' . $questionId . '][' . $numAnswer . ']', $key, $attributes));
                    }
                    if ($show_comment) {
                        $s .= '<td>';
                        $s .= $comment;
                        $s .= '</td>';
                    }
                    $s .= '</tr>';
                } elseif ($answerType == FILL_IN_BLANKS) {
                    list($answer) = explode('::', $answer);
                    //Correct answer
                    api_preg_match_all('/\\[[^]]+\\]/', $answer, $correct_answer_list);
                    //Student's answezr
                    if (isset($user_choice[0]['answer'])) {
                        api_preg_match_all('/\\[[^]]+\\]/', $user_choice[0]['answer'], $student_answer_list);
                        $student_answer_list = $student_answer_list[0];
                    }
                    //If debug
                    if ($debug_mark_answer) {
                        $student_answer_list = $correct_answer_list[0];
                    }
                    if (!empty($correct_answer_list) && !empty($student_answer_list)) {
                        $correct_answer_list = $correct_answer_list[0];
                        $i = 0;
                        foreach ($correct_answer_list as $correct_item) {
                            $value = null;
                            if (isset($student_answer_list[$i]) && !empty($student_answer_list[$i])) {
                                //Cleaning student answer list
                                $value = strip_tags($student_answer_list[$i]);
                                $value = api_substr($value, 1, api_strlen($value) - 2);
                                $value = explode('/', $value);
                                if (!empty($value[0])) {
                                    $value = str_replace('&nbsp;', '', trim($value[0]));
                                }
                                $correct_item = preg_quote($correct_item);
                                $correct_item = api_preg_replace('|/|', '\\/', $correct_item);
                                // to prevent error if there is a / in the text to find
                                $answer = api_preg_replace('/' . $correct_item . '/', Display::input('text', "choice[{$questionId}][]", $value), $answer, 1);
                            }
                            $i++;
                        }
                    } else {
                        $answer = api_preg_replace('/\\[[^]]+\\]/', Display::input('text', "choice[{$questionId}][]", '', $attributes), $answer);
                    }
                    $s .= $answer;
                } elseif ($answerType == MATCHING) {
                    // matching type, showing suggestions and answers
                    // TODO: replace $answerId by $numAnswer
                    if ($lines_count == 1) {
                        $s .= $objAnswerTmp->getJs();
                    }
                    if ($answerCorrect != 0) {
                        // only show elements to be answered (not the contents of
                        // the select boxes, who are correct = 0)
                        $s .= '<tr><td width="45%">';
                        $parsed_answer = $answer;
                        $windowId = $questionId . '_' . $lines_count;
                        //left part questions
                        $s .= ' <div id="window_' . $windowId . '" class="window window_left_question window' . $questionId . '_question">
                                    <b>' . $lines_count . '</b>.&nbsp' . $parsed_answer . '
                                </div>
                                </td>';
                        // middle part (matches selects)
                        $s .= '<td width="10%" align="center">&nbsp;&nbsp;';
                        $s .= '<div style="display:block">';
                        $s .= '<select id="window_' . $windowId . '_select" name="choice[' . $questionId . '][' . $numAnswer . ']">';
                        $selectedValue = 0;
                        // fills the list-box
                        $item = 0;
                        foreach ($select_items as $val) {
                            // set $debug_mark_answer to true at public static function start to
                            // show the correct answer with a suffix '-x'
                            $selected = '';
                            if ($debug_mark_answer) {
                                if ($val['id'] == $answerCorrect) {
                                    $selected = 'selected="selected"';
                                    $selectedValue = $val['id'];
                                }
                            }
                            if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
                                $selected = 'selected="selected"';
                                $selectedValue = $val['id'];
                            }
                            //$s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>';
                            $s .= '<option value="' . $item . '" ' . $selected . '>' . $val['letter'] . '</option>';
                            $item++;
                        }
                        if (!empty($answerCorrect) && !empty($selectedValue)) {
                            $s .= '<script>
                                jsPlumb.ready(function() {
                                    jsPlumb.connect({
                                        source: "window_' . $windowId . '",
                                        target: "window_' . $questionId . '_' . $selectedValue . '_answer",
                                        endpoint:["Blank", { radius:15 }],
                                        anchor:["RightMiddle","LeftMiddle"],
                                        paintStyle:{ strokeStyle:"#8a8888" , lineWidth:8 },
                                        connector: [connectorType, { curviness: curvinessValue } ],
                                    })
                                });
                                </script>';
                        }
                        $s .= '</select></div></td>';
                        $s .= '<td width="45%" valign="top" >';
                        if (isset($select_items[$lines_count])) {
                            $s .= '<div id="window_' . $windowId . '_answer" class="window window_right_question">
                                    <b>' . $select_items[$lines_count]['letter'] . '.</b> ' . $select_items[$lines_count]['answer'] . '
                                  </div>';
                        } else {
                            $s .= '&nbsp;';
                        }
                        $s .= '</td>';
                        $s .= '</tr>';
                        $lines_count++;
                        //if the left side of the "matching" has been completely
                        // shown but the right side still has values to show...
                        if ($lines_count - 1 == $num_suggestions) {
                            // if it remains answers to shown at the right side
                            while (isset($select_items[$lines_count])) {
                                $s .= '<tr>
                                      <td colspan="2"></td>
                                      <td valign="top">';
                                $s .= '<b>' . $select_items[$lines_count]['letter'] . '.</b>';
                                $s .= $select_items[$lines_count]['answer'];
                                $s .= "</td>\n                                </tr>";
                                $lines_count++;
                            }
                            // end while()
                        }
                        // end if()
                        $matching_correct_answer++;
                    }
                } elseif ($answerType == DRAGGABLE) {
                    // matching type, showing suggestions and answers
                    // TODO: replace $answerId by $numAnswer
                    if ($answerCorrect != 0) {
                        // only show elements to be answered (not the contents of
                        // the select boxes, who are correct = 0)
                        $s .= '<td>';
                        $parsed_answer = $answer;
                        $windowId = $questionId . '_' . $numAnswer;
                        //67_293 - 67_294
                        //left part questions
                        $s .= '<li class="ui-state-default" id="' . $windowId . '">';
                        $s .= ' <div id="window_' . $windowId . '" class="window' . $questionId . '_question_draggable question_draggable">
                                   ' . $parsed_answer . '
                                </div>';
                        $s .= '<div style="display:none">';
                        $s .= '<select id="window_' . $windowId . '_select" name="choice[' . $questionId . '][' . $numAnswer . ']" class="select_option">';
                        $selectedValue = 0;
                        // fills the list-box
                        $item = 0;
                        foreach ($select_items as $val) {
                            // set $debug_mark_answer to true at function start to
                            // show the correct answer with a suffix '-x'
                            $selected = '';
                            if ($debug_mark_answer) {
                                if ($val['id'] == $answerCorrect) {
                                    $selected = 'selected="selected"';
                                    $selectedValue = $val['id'];
                                }
                            }
                            if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
                                $selected = 'selected="selected"';
                                $selectedValue = $val['id'];
                            }
                            //$s .= '<option value="'.$val['id'].'" '.$selected.'>'.$val['letter'].'</option>';
                            $s .= '<option value="' . $item . '" ' . $selected . '>' . $val['letter'] . '</option>';
                            $item++;
                        }
                        $s .= '</select>';
                        if (!empty($answerCorrect) && !empty($selectedValue)) {
                            $s .= '<script>
                                $(function() {
                                    deleteItem($("#' . $questionId . '_' . $selectedValue . '"), $("#drop_' . $windowId . '"));
                                });
                                </script>';
                        }
                        if (isset($select_items[$lines_count])) {
                            $s .= '<div id="window_' . $windowId . '_answer" class="">
                                    <b>' . $select_items[$lines_count]['letter'] . '.</b> ' . $select_items[$lines_count]['answer'] . '
                                  </div>';
                        } else {
                            $s .= '&nbsp;';
                        }
                        $lines_count++;
                        //if the left side of the "matching" has been completely
                        // shown but the right side still has values to show...
                        if ($lines_count - 1 == $num_suggestions) {
                            // if it remains answers to shown at the right side
                            while (isset($select_items[$lines_count])) {
                                $s .= '<b>' . $select_items[$lines_count]['letter'] . '.</b>';
                                $s .= $select_items[$lines_count]['answer'];
                                $lines_count++;
                            }
                        }
                        $s .= '</div>';
                        $matching_correct_answer++;
                        $s .= '</li>';
                    }
                }
            }
            // end for()
            if ($show_comment) {
                $s .= '</table>';
            } else {
                if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
                    $s .= '</table>';
                }
            }
            if ($answerType == DRAGGABLE) {
                $s .= '</ul><div class="clear"></div>';
                $counterAnswer = 1;
                foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $windowId = $questionId . '_' . $counterAnswer;
                    if ($answerCorrect == 0) {
                        $s .= '<div id="drop_' . $windowId . '" class="droppable ui-state-default">' . $counterAnswer . '</div>';
                        $counterAnswer++;
                    }
                }
            }
            if ($answerType == MATCHING) {
                $s .= '</div>';
            }
            $s .= '</div>';
            // destruction of the Answer object
            unset($objAnswerTmp);
            // destruction of the Question object
            unset($objQuestionTmp);
            $html .= $s;
            return $html;
        } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
            // Question is a HOT_SPOT
            //checking document/images visibility
            if (api_is_platform_admin() || api_is_course_admin()) {
                $course = api_get_course_info();
                $doc_id = DocumentManager::get_document_id($course, '/images/' . $pictureName);
                if (is_numeric($doc_id)) {
                    $images_folder_visibility = api_get_item_visibility($course, 'document', $doc_id, api_get_session_id());
                    if (!$images_folder_visibility) {
                        //This message is shown only to the course/platform admin if the image is set to visibility = false
                        Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage'));
                    }
                }
            }
            $questionName = $objQuestionTmp->selectTitle();
            $questionDescription = $objQuestionTmp->selectDescription();
            if ($freeze) {
                $s .= Display::img($objQuestionTmp->selectPicturePath());
                $html .= $s;
                return $html;
            }
            // Get the answers, make a list
            $objAnswerTmp = new Answer($questionId);
            // get answers of hotpost
            $answers_hotspot = array();
            foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
                //$answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId));
                $answers_hotspot[$answerId] = $objAnswerTmp->selectAnswer($answerId);
            }
            // display answers of hotpost order by id
            $answer_list = '<div style="padding: 10px; margin-left: 0px; border: 1px solid #A4A4A4; height: 408px; width: 200px;"><b>' . get_lang('HotspotZones') . '</b><dl>';
            if (!empty($answers_hotspot)) {
                ksort($answers_hotspot);
                foreach ($answers_hotspot as $key => $value) {
                    $answer_list .= '<dt>' . $key . '.- ' . $value . '</dt><br />';
                }
            }
            $answer_list .= '</dl></div>';
            if ($answerType == HOT_SPOT_DELINEATION) {
                $answer_list = '';
                $swf_file = 'hotspot_delineation_user';
                $swf_height = 405;
            } else {
                $swf_file = 'hotspot_user';
                $swf_height = 436;
            }
            if (!$only_questions) {
                if ($show_title) {
                    $html .= TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id);
                    $html .= '<div class="question_title">' . $current_item . '. ' . $questionName . '</div>';
                    $html .= $questionDescription;
                } else {
                    $html .= '<div class="media">';
                    $html .= '<div class="pull-left">';
                    $html .= '<div class="media-object">';
                    $html .= Display::div($current_item . '. ', array('class' => 'question_no_title'));
                    $html .= '</div>';
                    $html .= '</div>';
                    $html .= '<div class="media-body">';
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                    $html .= '</div>';
                    $html .= '</div>';
                }
                //@todo I need to the get the feedback type
                $html .= '<input type="hidden" name="hidden_hotspot_id" value="' . $questionId . '" />';
                $html .= '<table class="exercise_questions">
                           <tr>
                            <td valign="top" colspan="2">';
                $html .= '</td></tr>';
            }
            $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
            $s .= ' <script type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script>
                    <script src="../plugin/hotspot/hotspot.js" type="text/javascript" ></script>
                    <script type="text/javascript">
                    <!--
                    // Globals
                    // Major version of Flash required
                    var requiredMajorVersion = 7;
                    // Minor version of Flash required
                    var requiredMinorVersion = 0;
                    // Minor version of Flash required
                    var requiredRevision = 0;
                    // the version of javascript supported
                    var jsVersion = 1.0;
                    // -->
                    </script>
                    <script language="VBScript" type="text/vbscript">
                    <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
                    Function VBGetSwfVer(i)
                      on error resume next
                      Dim swControl, swVersion
                      swVersion = 0

                      set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))
                      if (IsObject(swControl)) then
                        swVersion = swControl.GetVariable("$version")
                      end if
                      VBGetSwfVer = swVersion
                    End Function
                    // -->
                    </script>

                    <script language="JavaScript1.1" type="text/javascript">
                    <!-- // Detect Client Browser type
                    var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
                    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
                    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
                    jsVersion = 1.1;
                    // JavaScript helper required to detect Flash Player PlugIn version information
                    function JSGetSwfVer(i) {
                        // NS/Opera version >= 3 check for Flash plugin in plugin array
                        if (navigator.plugins != null && navigator.plugins.length > 0) {
                            if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
                                var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
                                var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                                descArray = flashDescription.split(" ");
                                tempArrayMajor = descArray[2].split(".");
                                versionMajor = tempArrayMajor[0];
                                versionMinor = tempArrayMajor[1];
                                if ( descArray[3] != "" ) {
                                    tempArrayMinor = descArray[3].split("r");
                                } else {
                                    tempArrayMinor = descArray[4].split("r");
                                }
                                versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
                                flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
                            } else {
                                flashVer = -1;
                            }
                        }
                        // MSN/WebTV 2.6 supports Flash 4
                        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
                        // WebTV 2.5 supports Flash 3
                        else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
                        // older WebTV supports Flash 2
                        else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
                        // Can\'t detect in all other cases
                        else {
                            flashVer = -1;
                        }
                        return flashVer;
                    }
                    // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available

                    function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
                        reqVer = parseFloat(reqMajorVer + "." + reqRevision);
                        // loop backwards through the versions until we find the newest version
                        for (i=25;i>0;i--) {
                            if (isIE && isWin && !isOpera) {
                                versionStr = VBGetSwfVer(i);
                            } else {
                                versionStr = JSGetSwfVer(i);
                            }
                            if (versionStr == -1 ) {
                                return false;
                            } else if (versionStr != 0) {
                                if(isIE && isWin && !isOpera) {
                                    tempArray         = versionStr.split(" ");
                                    tempString        = tempArray[1];
                                    versionArray      = tempString .split(",");
                                } else {
                                    versionArray      = versionStr.split(".");
                                }
                                versionMajor      = versionArray[0];
                                versionMinor      = versionArray[1];
                                versionRevision   = versionArray[2];

                                versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
                                versionNum        = parseFloat(versionString);
                                // is the major.revision >= requested major.revision AND the minor version >= requested minor
                                if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
                                    return true;
                                } else {
                                    return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
                                }
                            }
                        }
                    }
                    // -->
                    </script>';
            $s .= '<tr><td valign="top" colspan="2" width="520"><table><tr><td width="520">
                    <script>
                        // Version check based upon the values entered above in "Globals"
                        var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

                        // Check to see if the version meets the requirements for playback
                        if (hasReqestedVersion) {  // if we\'ve detected an acceptable version
                            var oeTags = \'<object type="application/x-shockwave-flash" data="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&amp;canClick:' . $canClick . '" width="600" height="' . $swf_height . '">\'
                                        + \'<param name="wmode" value="transparent">\'
                                        + \'<param name="movie" value="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&amp;canClick:' . $canClick . '" />\'
                                        + \'<\\/object>\';
                            document.write(oeTags);   // embed the Flash Content SWF when all tests are passed
                        } else {  // flash is too old or we can\'t detect the plugin
                            var alternateContent = "Error<br \\/>"
                                + "Hotspots requires Macromedia Flash 7.<br \\/>"
                                + "<a href=\\"http://www.macromedia.com/go/getflash/\\">Get Flash<\\/a>";
                            document.write(alternateContent);  // insert non-flash content
                        }
                    </script>
                    </td>
                    <td valign="top" align="left">' . $answer_list . '</td></tr>
                    </table>
            </td></tr>';
            $html .= $s;
            $html .= '</table>';
            return $html;
        }
        return $nbrAnswers;
    }
    $form_sent = $_POST['form_sent'];
    $elements_posted = $_POST['elements_in_name'];
    if (!is_array($elements_posted)) {
        $elements_posted = array();
    }
    if ($form_sent == 1) {
        $usergroup->subscribe_courses_to_usergroup($id, $elements_posted);
        header('Location: usergroups.php');
        exit;
    }
}
// Filters
$filters = array(array('type' => 'text', 'name' => 'code', 'label' => get_lang('CourseCode')), array('type' => 'text', 'name' => 'title', 'label' => get_lang('Title')));
$searchForm = new FormValidator('search', 'get', api_get_self() . '?id=' . $id);
$searchForm->addHeader(get_lang('AdvancedSearch'));
$renderer =& $searchForm->defaultRenderer();
$searchForm->addElement('hidden', 'id', $id);
foreach ($filters as $param) {
    $searchForm->addElement($param['type'], $param['name'], $param['label']);
}
$searchForm->addButtonSearch();
$filterData = array();
if ($searchForm->validate()) {
    $filterData = $searchForm->getSubmitValues();
}
$conditions = array();
if (!empty($filters) && !empty($filterData)) {
    foreach ($filters as $filter) {
        if (isset($filter['name']) && isset($filterData[$filter['name']])) {
            $value = $filterData[$filter['name']];
            if (!empty($value)) {
 /**
  * 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));
 }
Example #20
0
    $sessionToShow = array();
    foreach ($sessionList as $session) {
        $url = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'].'&cidReq='.$courseInfo['code'];
        $sessionToShow[] = Display::url($session['name'], $url);
    }
    echo implode(', ', $sessionToShow);
}

echo Display::page_subheader2(get_lang('StudentList'));

// PERSON_NAME_DATA_EXPORT is buggy
$is_western_name_order = api_is_western_name_order();

if (count($a_students) > 0) {
    $form = new FormValidator('reminder_form', 'get', api_get_path(REL_CODE_PATH).'announcements/announcements.php');
    $renderer = $form->defaultRenderer();
    $renderer->setElementTemplate(
        '<span>{label} {element}</span>&nbsp;<button class="save" type="submit">'.get_lang('SendNotification').'</button>',
        'since'
    );
    $options = array (
        2 => '2 '.get_lang('Days'),
        3 => '3 '.get_lang('Days'),
        4 => '4 '.get_lang('Days'),
        5 => '5 '.get_lang('Days'),
        6 => '6 '.get_lang('Days'),
        7 => '7 '.get_lang('Days'),
        15 => '15 '.get_lang('Days'),
        30 => '30 '.get_lang('Days'),
        'never' => get_lang('Never')
    );
function form_special_export()
{
    $form = new FormValidator('special_exports', 'post');
    $renderer = $form->defaultRenderer();
    $renderer->setCustomElementTemplate('<div>{element}</div> ');
    $form->addElement('radio', 'backup_option', '', get_lang('SpecialCreateFullBackup'), 'full_backup');
    $form->addElement('radio', 'backup_option', '', get_lang('SpecialLetMeSelectItems'), 'select_items');
    $form->addElement('html', '<br />');
    $form->addButtonExport(get_lang('CreateBackup'));
    $form->add_progress_bar();
    $values['backup_option'] = 'full_backup';
    $form->setDefaults($values);
    $form->display();
}
 static function print_activities_stats()
 {
     echo '<h4>' . get_lang('ImportantActivities') . '</h4>';
     // Create a search-box
     $form = new FormValidator('search_simple', 'get', api_get_path(WEB_CODE_PATH) . 'admin/statistics/index.php', '', 'width=200px', false);
     $renderer =& $form->defaultRenderer();
     $renderer->setElementTemplate('<span>{element}</span> ');
     $form->addElement('hidden', 'report', 'activities');
     $form->addElement('hidden', 'activities_direction', 'DESC');
     $form->addElement('hidden', 'activities_column', '4');
     $form->addElement('text', 'keyword', get_lang('keyword'));
     $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
     echo '<div class="actions">';
     $form->display();
     echo '</div>';
     $table = new SortableTable('activities', array('Statistics', 'get_number_of_activities'), array('Statistics', 'get_activities_data'), 5, 50, 'DESC');
     $parameters = array();
     $parameters['report'] = 'activities';
     if (isset($_GET['keyword'])) {
         $parameters['keyword'] = Security::remove_XSS($_GET['keyword']);
     }
     $table->set_additional_parameters($parameters);
     $table->set_header(0, get_lang('EventType'));
     $table->set_header(1, get_lang('DataType'));
     $table->set_header(2, get_lang('Value'));
     $table->set_header(3, get_lang('UserName'));
     $table->set_header(4, get_lang('IPAddress'));
     $table->set_header(5, get_lang('Date'));
     $table->display();
 }
 /**
  * @param \Silex\Application $app
  *
  * @return string
  */
 public function displayLoginForm(Application $app)
 {
     /* {{ form_widget(form) }}
         $form = $app['form.factory']->createBuilder('form')
         ->add('name')
         ->add('email')
         ->add('gender', 'choice', array(
         'choices' => array(1 => 'male', 2 => 'female'),
         'expanded' => true,
         ))
         ->getForm();
         return $app['template']->assign('form', $form->createView());
        */
     $form = new \FormValidator('formLogin', 'POST', $app['url_generator']->generate('secured_login_check'), null, array('class' => 'form-signin-block'));
     $renderer =& $form->defaultRenderer();
     $renderer->setElementTemplate('{element}');
     $form->addElement('text', 'username', null, array('class' => 'input-medium autocapitalize_off virtualkey', 'placeholder' => get_lang('UserName'), 'autofocus' => 'autofocus'));
     $form->addElement('password', 'password', null, array('placeholder' => get_lang('Pass'), 'class' => 'input-medium virtualkey'));
     $form->addElement('style_submit_button', 'submitAuth', get_lang('LoginEnter'), array('class' => 'btn btn-primary btn-block'));
     $html = $form->return_form();
     /** Verify if settings is active to set keyboard. Included extra class in form input elements */
     if (api_get_setting('use_virtual_keyboard') == 'true') {
         $html .= "<script>\n                \$(function(){\n                    \$('.virtualkey').keyboard({\n                        layout:'custom',\n                        customLayout: {\n                        'default': [\n                            '1 2 3 4 5 6 7 8 9 0 {bksp}',\n                            'q w e r t y u i o p',\n                            'a s d f g h j k l',\n                            'z x c v b n m',\n                            '{cancel} {accept}'\n                        ]\n                        }\n                    });\n                });\n            </script>";
     }
     return $html;
 }