Example #1
0
$form = new FormValidator('confirm_sale');
if ($form->validate()) {
    $formValues = $form->getSubmitValues();
    if (!$formValues['payment_type']) {
        Display::addFlash(Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false));
        header('Location:' . api_get_self() . '?' . $queryString);
        exit;
    }
    $saleId = $plugin->registerSale($item['id'], $formValues['payment_type']);
    if ($saleId !== false) {
        $_SESSION['bc_sale_id'] = $saleId;
        header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/process_confirm.php');
    }
    exit;
}
$form->addHeader($plugin->get_lang('UserInformation'));
$form->addText('name', get_lang('Name'), false, ['cols-size' => [5, 7, 0]]);
$form->addText('username', get_lang('Username'), false, ['cols-size' => [5, 7, 0]]);
$form->addText('email', get_lang('EmailAddress'), false, ['cols-size' => [5, 7, 0]]);
$form->addHeader($plugin->get_lang('PaymentMethods'));
$paymentTypesOptions = $plugin->getPaymentTypes();
if (!$paypalEnabled) {
    unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL]);
}
if (!$transferEnabled) {
    unset($paymentTypesOptions[BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER]);
}
$form->addRadio('payment_type', null, $paymentTypesOptions);
$form->addHidden('t', intval($_GET['t']));
$form->addHidden('i', intval($_GET['i']));
$form->freeze(['name', 'username', 'email']);
 /**
  * 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));
 }
 /**
  * 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::read('objExercise');
     $editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
     //this line defines how many questions by default appear when creating a choice question
     // The previous default value was 2. See task #1759.
     $nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 4;
     $nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
     /*
      Types of Feedback
      $feedback_option[0]=get_lang('Feedback');
      $feedback_option[1]=get_lang('DirectFeedback');
      $feedback_option[2]=get_lang('NoFeedback');
     */
     $feedback_title = '';
     if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
         //Scenario
         $comment_title = '<th width="20%">' . get_lang('Comment') . '</th>';
         $feedback_title = '<th width="20%">' . get_lang('Scenario') . '</th>';
     } else {
         $comment_title = '<th width="40%">' . get_lang('Comment') . '</th>';
     }
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr style="text-align: center;">
                 <th width="5%">' . get_lang('Number') . '</th>
                 <th width="5%"> ' . get_lang('True') . '</th>
                 <th width="40%">' . get_lang('Answer') . '</th>
                     ' . $comment_title . '
                     ' . $feedback_title . '
                 <th width="10%">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('Answers'));
     $form->addHtml($html);
     $defaults = array();
     $correct = 0;
     if (!empty($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
             $nb_answers = $answer->nbrAnswers;
         }
     }
     $form->addElement('hidden', 'nb_answers');
     //Feedback SELECT
     $question_list = $obj_ex->selectQuestionList();
     $select_question = array();
     $select_question[0] = get_lang('SelectTargetQuestion');
     if (is_array($question_list)) {
         foreach ($question_list as $key => $questionid) {
             //To avoid warning messages
             if (!is_numeric($questionid)) {
                 continue;
             }
             $question = Question::read($questionid);
             $select_question[$questionid] = 'Q' . $key . ' :' . cut($question->selectTitle(), 20);
         }
     }
     $select_question[-1] = get_lang('ExitTest');
     $list = new LearnpathList(api_get_user_id());
     $flat_list = $list->get_flat_list();
     $select_lp_id = array();
     $select_lp_id[0] = get_lang('SelectTargetLP');
     foreach ($flat_list as $id => $details) {
         $select_lp_id[$id] = cut($details['lp_name'], 20);
     }
     $temp_scenario = array();
     if ($nb_answers < 1) {
         $nb_answers = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_answers; ++$i) {
         $form->addHtml('<tr>');
         if (isset($answer) && is_object($answer)) {
             if ($answer->correct[$i]) {
                 $correct = $i;
             }
             $defaults['answer[' . $i . ']'] = $answer->answer[$i];
             $defaults['comment[' . $i . ']'] = $answer->comment[$i];
             $defaults['weighting[' . $i . ']'] = float_format($answer->weighting[$i], 1);
             $item_list = explode('@@', $answer->destination[$i]);
             $try = isset($item_list[0]) ? $item_list[0] : '';
             $lp = isset($item_list[1]) ? $item_list[1] : '';
             $list_dest = isset($item_list[2]) ? $item_list[2] : '';
             $url = isset($item_list[3]) ? $item_list[3] : '';
             if ($try == 0) {
                 $try_result = 0;
             } else {
                 $try_result = 1;
             }
             if ($url == 0) {
                 $url_result = '';
             } else {
                 $url_result = $url;
             }
             $temp_scenario['url' . $i] = $url_result;
             $temp_scenario['try' . $i] = $try_result;
             $temp_scenario['lp' . $i] = $lp;
             $temp_scenario['destination' . $i] = $list_dest;
         } else {
             $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1');
             $defaults['weighting[1]'] = 10;
             $defaults['answer[2]'] = get_lang('DefaultUniqueAnswer2');
             $defaults['weighting[2]'] = 0;
             $temp_scenario['destination' . $i] = array('0');
             $temp_scenario['lp' . $i] = array('0');
         }
         $defaults['scenario'] = $temp_scenario;
         $renderer = $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'correct');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'counter[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'answer[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'comment[' . $i . ']');
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>', 'weighting[' . $i . ']');
         $answer_number = $form->addElement('text', 'counter[' . $i . ']', null, ' value = "' . $i . '"');
         $answer_number->freeze();
         $form->addElement('radio', 'correct', null, null, $i, 'class="checkbox"');
         $form->addHtmlEditor('answer[' . $i . ']', null, null, true, $editor_config);
         $form->addRule('answer[' . $i . ']', get_lang('ThisFieldIsRequired'), 'required');
         if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
             $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config);
             // Direct feedback
             //Adding extra feedback fields
             $group = array();
             $group['try' . $i] = $form->createElement('checkbox', 'try' . $i, null, get_lang('TryAgain'));
             $group['lp' . $i] = $form->createElement('select', 'lp' . $i, get_lang('SeeTheory') . ': ', $select_lp_id);
             $group['destination' . $i] = $form->createElement('select', 'destination' . $i, get_lang('GoToQuestion') . ': ', $select_question);
             $group['url' . $i] = $form->createElement('text', 'url' . $i, get_lang('Other') . ': ', array('class' => 'col-md-2', 'placeholder' => get_lang('Other')));
             $form->addGroup($group, 'scenario');
             $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}', 'scenario');
         } else {
             $form->addHtmlEditor('comment[' . $i . ']', null, null, false, $editor_config);
         }
         $form->addText('weighting[' . $i . ']', null, null, array('value' => '0'));
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody>');
     $form->addHtml('</table>');
     global $text;
     $buttonGroup = [];
     //ie6 fix
     if ($obj_ex->edit_exercise_in_lp == true) {
         //setting the save button here and not in the question class.php
         $buttonGroup[] = $form->addButtonDelete(get_lang('LessAnswer'), 'lessAnswers', true);
         $buttonGroup[] = $form->addButtonCreate(get_lang('PlusAnswer'), 'moreAnswers', true);
         $buttonGroup[] = $form->addButtonSave($text, 'submitQuestion', true);
         $form->addGroup($buttonGroup);
     }
     // We check the first radio button to be sure a radio button will be check
     if ($correct == 0) {
         $correct = 1;
     }
     $defaults['correct'] = $correct;
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             // Default sample content.
             $form->setDefaults($defaults);
         } else {
             $form->setDefaults(array('correct' => 1));
         }
     }
     $form->setConstants(array('nb_answers' => $nb_answers));
 }
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
    $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']];
Example #6
0
/**
 * Builds the form thats enables the user to
 * move a document from one directory to another
 * This function has been copied from the document/document.inc.php library
 *
 * @param array $folders
 * @param string $curdirpath
 * @param string $move_file
 * @param string $group_dir
 * @return string html form
 */
function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_dir = '')
{
    $course_id = api_get_course_int_id();
    $move_file = intval($move_file);
    $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $sql = "SELECT title, url FROM {$tbl_work}\n            WHERE c_id = {$course_id} AND id ='" . $move_file . "'";
    $result = Database::query($sql);
    $row = Database::fetch_array($result, 'ASSOC');
    $title = empty($row['title']) ? basename($row['url']) : $row['title'];
    $form = new FormValidator('move_to_form', 'post', api_get_self() . '?' . api_get_cidreq() . '&curdirpath=' . Security::remove_XSS($curdirpath));
    $form->addHeader(get_lang('MoveFile') . ' - ' . Security::remove_XSS($title));
    $form->addHidden('item_id', $move_file);
    $form->addHidden('action', 'move_to');
    //group documents cannot be uploaded in the root
    if ($group_dir == '') {
        if ($curdirpath != '/') {
            //$form .= '<option value="0">/ ('.get_lang('Root').')</option>';
        }
        if (is_array($folders)) {
            foreach ($folders as $fid => $folder) {
                //you cannot move a file to:
                //1. current directory
                //2. inside the folder you want to move
                //3. inside a subfolder of the folder you want to move
                if ($curdirpath != $folder && $folder != $move_file && substr($folder, 0, strlen($move_file) + 1) != $move_file . '/') {
                    //$form .= '<option value="'.$fid.'">'.$folder.'</option>';
                    $options[$fid] = $folder;
                }
            }
        }
    } else {
        if ($curdirpath != '/') {
            $form .= '<option value="0">/ (' . get_lang('Root') . ')</option>';
        }
        foreach ($folders as $fid => $folder) {
            if ($curdirpath != $folder && $folder != $move_file && substr($folder, 0, strlen($move_file) + 1) != $move_file . '/') {
                //cannot copy dir into his own subdir
                $display_folder = substr($folder, strlen($group_dir));
                $display_folder = $display_folder == '' ? '/ (' . get_lang('Root') . ')' : $display_folder;
                //$form .= '<option value="'.$fid.'">'.$display_folder.'</option>'."\n";
                $options[$fid] = $display_folder;
            }
        }
    }
    $form->addSelect('move_to_id', get_lang('Select'), $options);
    $form->addButtonSend(get_lang('MoveFile'), 'move_file_submit');
    return $form->returnForm();
}
 */
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$nameFilter = null;
$minFilter = 0;
$maxFilter = 0;
$form = new FormValidator('search_filter_form', 'get', null, null, [], FormValidator::LAYOUT_INLINE);
if ($form->validate()) {
    $formValues = $form->getSubmitValues();
    $nameFilter = isset($formValues['name']) ? $formValues['name'] : null;
    $minFilter = isset($formValues['min']) ? $formValues['min'] : 0;
    $maxFilter = isset($formValues['max']) ? $formValues['max'] : 0;
}
$form->addHeader($plugin->get_lang('SearchFilter'));
$form->addText('name', get_lang('SessionName'), false);
$form->addElement('number', 'min', $plugin->get_lang('MinimumPrice'), ['step' => '0.01', 'min' => '0']);
$form->addElement('number', 'max', $plugin->get_lang('MaximumPrice'), ['step' => '0.01', 'min' => '0']);
$form->addHtml('<hr>');
$form->addButtonFilter(get_lang('Search'));
$courseList = $plugin->getCatalogCourseList($nameFilter, $minFilter, $maxFilter);
//View
if (api_is_platform_admin()) {
    $interbreadcrumb[] = ['url' => 'configuration.php', 'name' => $plugin->get_lang('AvailableCoursesConfiguration')];
    $interbreadcrumb[] = ['url' => 'paymentsetup.php', 'name' => $plugin->get_lang('PaymentsConfiguration')];
} else {
    $interbreadcrumb[] = ['url' => 'course_panel.php', 'name' => get_lang('TabsDashboard')];
}
$templateName = $plugin->get_lang('CourseListOnSale');
$tpl = new Template($templateName);
Example #8
0
 /**
  * Displays the form to create a new post
  * @author Toon Keppens
  *
  * @param Integer $blog_id
  */
 public static function display_new_comment_form($blog_id, $post_id, $title)
 {
     $form = new FormValidator('add_post', 'post', api_get_path(WEB_CODE_PATH) . "blog/blog.php?action=view_post&blog_id=" . intval($blog_id) . "&post_id=" . intval($post_id) . "&" . api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
     $header = get_lang('AddNewComment');
     if (isset($_GET['task_id'])) {
         $header = get_lang('ExecuteThisTask');
     }
     $form->addHeader($header);
     $form->addText('title', get_lang('Title'));
     $config = array();
     if (!api_is_allowed_to_edit()) {
         $config['ToolbarSet'] = 'ProjectComment';
     } else {
         $config['ToolbarSet'] = 'ProjectCommentStudent';
     }
     $form->addHtmlEditor('comment', get_lang('Comment'), false, false, $config);
     $form->addFile('user_upload', get_lang('AddAnAttachment'));
     $form->addTextarea('post_file_comment', get_lang('FileComment'));
     $form->addHidden('action', null);
     $form->addHidden('comment_parent_id', 0);
     if (isset($_GET['task_id'])) {
         $form->addHidden('new_task_execution_submit', 'true');
         $form->addHidden('task_id', intval($_GET['task_id']));
     } else {
         $form->addHidden('new_comment_submit', 'true');
     }
     $form->addButton('save', get_lang('Save'));
     $form->display();
 }
Example #9
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]);
 }
Example #10
0
    $skillDefaultInfo['gradebook_id'][] = $gradebook['id'];
}
$skillList = [0 => get_lang('None')];
$gradebookList = [];
foreach ($allSkills as $skill) {
    if ($skill['id'] == $skillInfo['id']) {
        continue;
    }
    $skillList[$skill['id']] = $skill['name'];
}
foreach ($allGradebooks as $gradebook) {
    $gradebookList[$gradebook['id']] = $gradebook['name'];
}
/* Form */
$editForm = new FormValidator('skill_edit');
$editForm->addHeader(get_lang('SkillEdit'));
$editForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
$editForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
$editForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
$editForm->addSelect('gradebook_id', [get_lang('Gradebook'), get_lang('WithCertificate')], $gradebookList, ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]);
$editForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
$editForm->addButtonSave(get_lang('Save'));
$editForm->addHidden('id', null);
$editForm->setDefaults($skillDefaultInfo);
if ($editForm->validate()) {
    $updated = $objSkill->edit($editForm->getSubmitValues());
    if ($updated) {
        Session::write('message', Display::return_message(get_lang('TheSkillHasBeenUpdated'), 'success'));
    } else {
        Session::write('message', Display::return_message(get_lang('CannotUpdateSkill'), 'error'));
    }
Example #11
0
     $currentUrl = api_get_self() . '?' . api_get_cidreq();
     Display::addFlash(Display::return_message(get_lang('Updated')));
     CourseHome::deleteIcon($id);
     header('Location: ' . $currentUrl);
     exit;
     break;
 case 'edit_icon':
     $tool = CourseHome::getTool($id);
     if (empty($tool)) {
         api_not_allowed(true);
     }
     $interbreadcrumb[] = array('url' => api_get_self() . '?' . api_get_cidreq(), 'name' => get_lang('CustomizeIcons'));
     $toolName = $tool['name'];
     $currentUrl = api_get_self() . '?action=edit_icon&id=' . $id . '&' . api_get_cidreq();
     $form = new FormValidator('icon_edit', 'post', $currentUrl);
     $form->addHeader(get_lang('EditIcon'));
     $form->addHtml('<div class="col-md-7">');
     $form->addText('name', get_lang('Name'));
     $form->addText('link', get_lang('Links'));
     $allowed_picture_types = array('jpg', 'jpeg', 'png');
     $form->addFile('icon', get_lang('CustomIcon'));
     $form->addRule('icon', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
     $form->addSelect('target', get_lang('LinkTarget'), ['_self' => get_lang('LinkOpenSelf'), '_blank' => get_lang('LinkOpenBlank')]);
     $form->addSelect('visibility', get_lang('Visibility'), array(1 => get_lang('Visible'), 0 => get_lang('Invisible')));
     $form->addTextarea('description', get_lang('Description'), array('rows' => '3', 'cols' => '40'));
     $form->addButtonUpdate(get_lang('Update'));
     $form->addHtml('</div>');
     $form->addHtml('<div class="col-md-5">');
     if (isset($tool['custom_icon']) && !empty($tool['custom_icon'])) {
         $form->addLabel(get_lang('CurrentIcon'), Display::img(CourseHome::getCustomWebIconPath() . $tool['custom_icon']));
         $form->addCheckBox('delete_icon', null, get_lang('DeletePicture'));
 /**
  * Return HTML form to add/edit a student publication (work)
  * @param	string	Action (add/edit)
  * @param	integer	Item ID if already exists
  * @param	mixed	Extra info (work ID if integer)
  * @return	string	HTML form
  */
 public function display_student_publication_form($action = 'add', $id = 0, $extra_info = '')
 {
     $course_id = api_get_course_int_id();
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
     } elseif (is_numeric($extra_info)) {
         $extra_info = intval($extra_info);
         $sql = "SELECT title, description\n                    FROM " . $tbl_publication . "\n                    WHERE c_id = " . $course_id . " AND id = " . $extra_info;
         $result = Database::query($sql);
         $row = Database::fetch_array($result);
         $item_title = $row['title'];
     } else {
         $item_title = get_lang('Student_publication');
     }
     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 = isset($this->arrMenu) ? $this->arrMenu : null;
     unset($this->arrMenu);
     $form = new FormValidator('frm_student_publication', 'post', '#');
     if ($action == 'add') {
         $form->addHeader(get_lang('Student_publication'));
     } elseif ($action == 'move') {
         $form->addHeader(get_lang('MoveCurrentStudentPublication'));
     } else {
         $form->addHeader(get_lang('EditCurrentStudentPublication'));
     }
     if ($action != 'move') {
         $form->addText('title', get_lang('Title'), true, ['class' => 'learnpath_item_form', 'id' => 'idTitle']);
     }
     $parentSelect = $form->addSelect('parent', get_lang('Parent'), ['0' => $this->name], ['onchange' => 'javascript: load_cbo(this.value);', 'class' => 'learnpath_item_form', 'id' => 'idParent']);
     $arrHide = array($id);
     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)) {
                 $parentSelect->addOption($arrLP[$i]['title'], $arrLP[$i]['id'], ['style' => 'padding-left: ' . ($arrLP[$i]['depth'] * 10 + 20) . 'px;']);
                 if ($parent == $arrLP[$i]['id']) {
                     $parentSelect->setSelected($arrLP[$i]['id']);
                 }
             } else {
                 $arrHide[] = $arrLP[$i]['id'];
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $parentSelect->addOption($arrLP[$i]['title'], $arrLP[$i]['id'], ['style' => 'padding-left: ' . ($arrLP[$i]['depth'] * 10 + 20) . 'px;']);
                 if ($parent == $arrLP[$i]['id']) {
                     $parentSelect->setSelected($arrLP[$i]['id']);
                 }
             }
         }
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $previousSelect = $form->addSelect('previous', get_lang('Position'), ['0' => get_lang('FirstPosition')], ['id' => 'previous', 'class' => 'learnpath_item_form']);
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             $previousSelect->addOption(get_lang('After') . ' "' . $arrLP[$i]['title'] . '"', $arrLP[$i]['id']);
             if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $previousSelect->setSelected($arrLP[$i]['id']);
             } elseif ($action == 'add') {
                 $previousSelect->setSelected($arrLP[$i]['id']);
             }
         }
     }
     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 ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = 0;
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
             }
         }
     }
     if ($action == 'add') {
         $form->addButtonCreate(get_lang('AddAssignmentToCourse'), 'submit_button');
     } else {
         $form->addButtonCreate(get_lang('EditCurrentStudentPublication'), 'submit_button');
     }
     if ($action == 'move') {
         $form->addHidden('title', $item_title);
         $form->addHidden('description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addHidden('path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addHidden('path', $extra_info['path']);
     }
     $form->addHidden('type', TOOL_STUDENTPUBLICATION);
     $form->addHidden('post_time', time());
     $form->setDefaults(['title' => $item_title]);
     $return = '<div class="sectioncomment">';
     $return .= $form->returnForm();
     $return .= '</div>';
     return $return;
 }
 /**
  * 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));
 }
 /**
  * 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));
 }
Example #15
0
     Display::display_error_message(get_lang('QualificationCanNotBeGreaterThanMaxScore'), false);
 }
 if (!empty($score)) {
     $saveResult = saveThreadScore($currentThread, $userIdToQualify, $threadId, $score, api_get_utc_datetime(), api_get_session_id());
 }
 // show qualifications history
 $type = isset($_GET['type']) ? $_GET['type'] : '';
 $historyList = getThreadScoreHistory($userIdToQualify, $threadId, $type);
 $counter = count($historyList);
 // Show current qualify in my form
 $qualify = current_qualify_of_thread($threadId, api_get_session_id(), $_GET['user']);
 $result = get_statistical_information($threadId, $_GET['user_id'], api_get_course_int_id());
 $url = api_get_path(WEB_CODE_PATH) . 'forum/forumqualify.php?' . api_get_cidreq() . '&forum=' . intval($_GET['forum']) . '&thread=' . $threadId . '&user='******'user']) . '&user_id=' . intval($_GET['user']);
 $userToQualifyInfo = api_get_user_info($userIdToQualify);
 $form = new FormValidator('forum-thread-qualify', 'post', $url);
 $form->addHeader($userToQualifyInfo['complete_name']);
 $form->addLabel(get_lang('Thread'), $currentThread['thread_title']);
 $form->addLabel(get_lang('CourseUsers'), $result['user_course']);
 $form->addLabel(get_lang('PostsNumber'), $result['post']);
 $form->addLabel(get_lang('NumberOfPostsForThisUser'), $result['user_post']);
 $form->addLabel(get_lang('AveragePostPerUser'), round($result['user_post'] / $result['post'], 2));
 $form->addText('idtextqualify', array(get_lang('Qualification'), get_lang('MaxScore') . ' ' . $maxQualify), $qualify);
 include 'viewpost.inc.php';
 $form->addButtonSave(get_lang('QualifyThisThread'));
 $form->setDefaults(array('idtextqualify' => $qualify));
 $form->display();
 // Show past data
 if (api_is_allowed_to_edit() && $counter > 0) {
     if (isset($_GET['gradebook'])) {
         $view_gradebook = '&gradebook=view';
     }
Example #16
0
        <a href="<?php 
echo Security::remove_XSS($_SESSION['gradebook_dest']) . '?' . $my_api_cidreq;
?>
&selectcat=<?php 
echo $my_selectcat;
?>
">
            <?php 
echo Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM);
?>
        </a>
    </div>
<?php 
$form->display();
$formNormal = new FormValidator('normal_weight', 'post', $currentUrl);
$formNormal->addHeader(get_lang('EditWeight'));
$formNormal->display();
//$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $masked_total);
$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $original_total);
Display::display_warning_message($warning_message, false);
?>
<form method="post" action="gradebook_edit_all.php?<?php 
echo $my_api_cidreq;
?>
&selectcat=<?php 
echo $my_selectcat;
?>
">
    <table class="data_table">
        <tr class="row_odd">
            <th style="width: 35px;"><?php 
    /**
     * Generic part of any survey question: the question field
     * @param array $surveyData
     * @param array $formData
     *
     * @return FormValidator
     */
    public function createForm($surveyData, $formData)
    {
        $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
        $questionId = isset($_GET['question_id']) ? intval($_GET['question_id']) : null;
        $surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
        $toolName = Display::return_icon(SurveyManager::icon_question(Security::remove_XSS($_GET['type'])), get_lang(ucfirst(Security::remove_XSS($_GET['type']))), array('align' => 'middle', 'height' => '22px')) . ' ';
        if ($action == 'add') {
            $toolName .= get_lang('AddQuestion');
        }
        if ($action == 'edit') {
            $toolName .= get_lang('EditQuestion');
        }
        if ($_GET['type'] == 'yesno') {
            $toolName .= ': ' . get_lang('YesNo');
        } else {
            if ($_GET['type'] == 'multiplechoice') {
                $toolName .= ': ' . get_lang('UniqueSelect');
            } else {
                $toolName .= ': ' . get_lang(api_ucfirst(Security::remove_XSS($_GET['type'])));
            }
        }
        $sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null;
        $url = api_get_self() . '?action=' . $action . '&type=' . Security::remove_XSS($_GET['type']) . '&survey_id=' . $surveyId . '&question_id=' . $questionId . '&' . api_get_cidreq();
        $form = new FormValidator('question_form', 'post', $url);
        $form->addHeader($toolName);
        $form->addHidden('survey_id', $surveyId);
        $form->addHidden('question_id', $questionId);
        $form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId));
        $form->addHidden('type', Security::remove_XSS($_GET['type']));
        $config = array('ToolbarSet' => 'SurveyQuestion', 'Width' => '100%', 'Height' => '120');
        $form->addHtmlEditor('question', get_lang('Question'), true, false, $config);
        // When survey type = 1??
        if ($surveyData['survey_type'] == 1) {
            $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
            $sql = 'SELECT id,name FROM ' . $table_survey_question_group . '
                    WHERE survey_id = ' . (int) $_GET['survey_id'] . '
                    ORDER BY name';
            $rs = Database::query($sql);
            $glist = null;
            while ($row = Database::fetch_array($rs, 'NUM')) {
                $glist .= '<option value="' . $row[0] . '" >' . $row[1] . '</option>';
            }
            $grouplist = $grouplist1 = $grouplist2 = $glist;
            if (!empty($formData['assigned'])) {
                $grouplist = str_replace('<option value="' . $formData['assigned'] . '"', '<option value="' . $formData['assigned'] . '" selected', $glist);
            }
            if (!empty($formData['assigned1'])) {
                $grouplist1 = str_replace('<option value="' . $formData['assigned1'] . '"', '<option value="' . $formData['assigned1'] . '" selected', $glist);
            }
            if (!empty($formData['assigned2'])) {
                $grouplist2 = str_replace('<option value="' . $formData['assigned2'] . '"', '<option value="' . $formData['assigned2'] . '" selected', $glist);
            }
            $this->html .= '	<tr><td colspan="">
			<fieldset style="border:1px solid black"><legend>' . get_lang('Condition') . '</legend>

			<b>' . get_lang('Primary') . '</b><br />
			' . '<input type="radio" name="choose" value="1" ' . ($formData['choose'] == 1 ? 'checked' : '') . '><select name="assigned">' . $grouplist . '</select><br />';
            $this->html .= '
			<b>' . get_lang('Secondary') . '</b><br />
			' . '<input type="radio" name="choose" value="2" ' . ($formData['choose'] == 2 ? 'checked' : '') . '><select name="assigned1">' . $grouplist1 . '</select> ' . '<select name="assigned2">' . $grouplist2 . '</select>' . '</fieldset><br />';
            //$form->addRadio('choose', get_lang('Primary'));
            //$form->addRadio('choose', get_lang('Secondary'));
        }
        $this->setForm($form);
        return $form;
    }
Example #18
0
 /**
  * @param int $id
  * @param string $action
  *
  * @return FormValidator
  */
 public static function getCategoryForm($id, $action)
 {
     $form = new FormValidator('category', 'post', api_get_self() . '?action=' . $action . '&' . api_get_cidreq());
     $defaults = [];
     if ($action == 'addcategory') {
         $form->addHeader(get_lang('CategoryAdd'));
         $my_cat_title = get_lang('CategoryAdd');
     } else {
         $form->addHeader(get_lang('CategoryMod'));
         $my_cat_title = get_lang('CategoryMod');
         $defaults = self::getCategory($id);
     }
     $form->addHidden('id', $id);
     $form->addText('category_title', get_lang('CategoryName'));
     $form->addTextarea('description', get_lang('Description'));
     $form->addButtonSave($my_cat_title, 'submitCategory');
     $form->setDefaults($defaults);
     return $form;
 }
Example #19
0
$reset = Request::get('reset');
$userId = Request::get('id');
$this_section = SECTION_CAMPUS;
$tool_name = get_lang('LostPassword');
if ($reset && $userId) {
    $messageText = Login::reset_password($reset, $userId, true);
    if (CustomPages::enabled() && CustomPages::exists(CustomPages::INDEX_UNLOGGED)) {
        CustomPages::display(CustomPages::INDEX_UNLOGGED, ['info' => $messageText]);
        exit;
    }
    Display::addFlash(Display::return_message($messageText));
    header('Location: ' . api_get_path(WEB_PATH));
    exit;
}
$form = new FormValidator('lost_password');
$form->addHeader($tool_name);
$form->addText('user', [get_lang('LoginOrEmailAddress'), get_lang('EnterEmailUserAndWellSendYouPassword')], true);
$form->addButtonSend(get_lang('Send'));
if ($form->validate()) {
    $values = $form->exportValues();
    $user = Login::get_user_accounts_by_username($values['user']);
    if (!$user) {
        $messageText = get_lang('NoUserAccountWithThisEmailAddress');
        if (CustomPages::enabled() && CustomPages::exists(CustomPages::LOST_PASSWORD)) {
            CustomPages::display(CustomPages::LOST_PASSWORD, ['info' => $messageText]);
            exit;
        }
        Display::addFlash(Display::return_message($messageText, 'error'));
        header('Location: ' . api_get_self());
        exit;
    }
Example #20
0
        $formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
    }
}
$allSkills = $objSkill->get_all();
$allGradebooks = $objGradebook->find('all');
$skillList = [0 => get_lang('None')];
$gradebookList = [];
foreach ($allSkills as $skill) {
    $skillList[$skill['id']] = $skill['name'];
}
foreach ($allGradebooks as $gradebook) {
    $gradebookList[$gradebook['id']] = $gradebook['name'];
}
/* Form */
$createForm = new FormValidator('skill_create');
$createForm->addHeader(get_lang('CreateSkill'));
$createForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
$createForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
$createForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
$createForm->addSelect('gradebook_id', [get_lang('Gradebook'), get_lang('WithCertificate')], $gradebookList, ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]);
$createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
$createForm->addButtonSave(get_lang('Save'));
$createForm->addHidden('id', null);
$createForm->setDefaults($formDefaultValues);
if ($createForm->validate()) {
    $created = $objSkill->add($createForm->getSubmitValues());
    if ($created) {
        Display::return_message(get_lang('TheSkillHasBeenCreated'), 'success');
    } else {
        Display::return_message(get_lang('CannotCreateSkill'), 'error');
    }
$userId = isset($_GET['user_id']) ? $_GET['user_id'] : null;
SessionManager::protectSession($sessionId);
$sessionInfo = api_get_session_info($sessionId);
if (empty($sessionInfo)) {
    api_not_allowed(true);
}
if (!isset($sessionInfo['duration']) || isset($sessionInfo['duration']) && empty($sessionInfo['duration'])) {
    api_not_allowed(true);
}
if (empty($sessionId) || empty($userId)) {
    api_not_allowed(true);
}
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
$interbreadcrumb[] = array('url' => "resume_session.php?id_session=" . $sessionId, "name" => get_lang('SessionOverview'));
$form = new FormValidator('edit', 'post', api_get_self() . '?session_id=' . $sessionId . '&user_id=' . $userId);
$form->addHeader(get_lang('EditUserSessionDuration'));
$data = SessionManager::getUserSession($userId, $sessionId);
$userInfo = api_get_user_info($userId);
// Show current end date for the session for this user, if any
$userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser($sessionId, $userId);
if (count($userAccess) == 0) {
    // User never accessed the session. End date is still open
    $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']);
} else {
    // The user already accessed the session. Show a clear detail of the days count.
    $duration = $sessionInfo['duration'];
    if (!empty($data['duration'])) {
        $duration = $duration + $data['duration'];
    }
    $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration);
    $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC');