Ejemplo n.º 1
0
/**
 * This function displays the form for import of the zip file with qti2
 */
function ch_qti2_display_form()
{
    $name_tools = get_lang('ImportQtiQuiz');
    $form = '<div class="actions">';
    $form .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'exercice/exercise.php?show=test&' . api_get_cidreq() . '">' . Display::return_icon('back.png', get_lang('BackToExercisesList'), '', ICON_SIZE_MEDIUM) . '</a>';
    $form .= '</div>';
    $formValidator = new FormValidator('qti_upload', 'post', api_get_self() . "?" . api_get_cidreq(), null, array('enctype' => 'multipart/form-data'));
    $formValidator->addElement('header', $name_tools);
    $formValidator->addElement('file', 'userFile', get_lang('DownloadFile'));
    $formValidator->addButtonImport(get_lang('Upload'));
    $form .= $formValidator->returnForm();
    echo $form;
}
Ejemplo n.º 2
0
    } else {
        $actionsLeft = '<a href="document.php?curdirpath=' . Security::remove_XSS($dir) . '">' . Display::return_icon('back.png', get_lang('Back') . ' ' . get_lang('To') . ' ' . get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM) . '</a>';
    }
    echo $toolbar = Display::toolbarAction('actions-documents', array(0 => $actionsLeft, 1 => ''));
    if ($is_certificate_mode) {
        $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id());
        $str_info = '';
        foreach ($all_information_by_create_certificate[0] as $info_value) {
            $str_info .= $info_value . '<br/>';
        }
        $create_certificate = get_lang('CreateCertificateWithTags');
        Display::display_normal_message($create_certificate . ': <br /><br/>' . $str_info, false);
    }
    // HTML-editor
    echo '<div class="row" style="overflow:hidden">
            <div id="template_col" class="col-md-2">
                <div class="panel panel-default">
                <div class="panel-body">
                    <div id="frmModel" class="items-templates scrollbar-macosx"></div>
                </div>
                </div>
            </div>
            <div class="col-md-1">
                <div id="hide_bar_template"></div>
            </div>
            <div id="doc_form" class="col-md-9">
                ' . $form->returnForm() . '
            </div>
          </div>';
    Display::display_footer();
}
Ejemplo n.º 3
0
$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');
    }
    header('Location: ' . api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php');
    exit;
}
//$tpl = new Template(get_lang('CreateSkill'));
echo $createForm->returnForm();
Ejemplo n.º 4
0
    $friends = SocialManager::get_friends(api_get_user_id());
    if ($friends == 0) {
        $social_right_content .= get_lang('YouNeedToHaveFriendsInYourSocialNetwork');
    } else {
        $social_right_content .= get_lang('YouAlreadyInviteAllYourContacts');
    }
    $social_right_content .= '<div>';
    $social_right_content .= '<a href="search.php">' . get_lang('TryAndFindSomeFriends') . '</a>';
    $social_right_content .= '</div>';
}
$form = new FormValidator('invitation', 'post', api_get_self() . '?id=' . $group_id);
$form->addHidden('form_sent', 1);
$form->addHidden('id', $group_id);
$group_members_element = $form->addElement('advmultiselect', 'invitation', get_lang('Friends'), $nosessionUsersList, 'style="width: 280px;"');
$form->addButtonSave(get_lang('InviteUsersToGroup'));
$social_right_content .= $form->returnForm();
// Current group members
$members = $usergroup->get_users_by_group($group_id, false, array(GROUP_USER_PERMISSION_PENDING_INVITATION));
if (is_array($members) && count($members) > 0) {
    foreach ($members as &$member) {
        $image = UserManager::getUserPicture($member['user_id']);
        $member['image'] = '<img src="' . $image . '"  width="50px" height="50px"  />';
    }
    $social_right_content .= '<h3>' . get_lang('UsersAlreadyInvited') . '</h3>';
    $social_right_content .= Display::return_sortable_grid('invitation_profile', array(), $members, array('hide_navigation' => true, 'per_page' => 100), array(), false, array(true, false, true, true));
}
$tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
$social_menu_block = SocialManager::show_social_menu('member_list', $group_id);
$tpl->addGlobal('social_menu_block', $social_menu_block);
//$tpl->setHelp('Groups');
Ejemplo n.º 5
0
 /**
  * Show the search form
  * @param string $query the value of the search box
  * @return string HTML form
  */
 public static function get_search_form($query)
 {
     $searchType = isset($_GET['search_type']) ? $_GET['search_type'] : null;
     $form = new FormValidator('search_user', 'get', api_get_path(WEB_PATH) . 'main/social/search.php', '', array(), FormValidator::LAYOUT_HORIZONTAL);
     $form->addText('q', get_lang('UsersGroups'), false);
     $options = array(0 => get_lang('Select'), 1 => get_lang('User'), 2 => get_lang('Group'));
     $form->addSelect('search_type', get_lang('Type'), $options, array('onchange' => 'javascript: extra_field_toogle();'));
     // Extra fields
     $extraFields = UserManager::get_extra_filtrable_fields();
     $defaults = [];
     if (is_array($extraFields) && count($extraFields) > 0) {
         foreach ($extraFields as $extraField) {
             $varName = 'field_' . $extraField['variable'];
             $options = [0 => get_lang('Select')];
             foreach ($extraField['data'] as $option) {
                 $checked = '';
                 if (isset($_GET[$varName])) {
                     if ($_GET[$varName] == $option[1]) {
                         $defaults[$option[1]] = true;
                     }
                 }
                 $options[$option[1]] = $option[1];
             }
             $form->addSelect($varName, $extraField['name'], $options);
         }
     }
     $defaults['search_type'] = intval($searchType);
     $defaults['q'] = api_htmlentities(Security::remove_XSS($query));
     $form->setDefaults($defaults);
     $form->addButtonSearch(get_lang('Search'));
     $js = '<script>
     extra_field_toogle();
     function extra_field_toogle() {
         if (jQuery("select[name=search_type]").val() != "1") { jQuery(".extra_field").hide(); } else { jQuery(".extra_field").show(); }
     }
     </script>';
     return $js . $form->returnForm();
 }
Ejemplo n.º 6
0
 /**
  * Subscribe the user to a given course
  * @param string Course code
  * @return string  Message about results
  */
 public function subscribe_user($course_code)
 {
     $user_id = api_get_user_id();
     $all_course_information = CourseManager::get_course_information($course_code);
     if ($all_course_information['registration_code'] == '' || $_POST['course_registration_code'] == $all_course_information['registration_code']) {
         if (api_is_platform_admin()) {
             $status_user_in_new_course = COURSEMANAGER;
         } else {
             $status_user_in_new_course = null;
         }
         if (CourseManager::add_user_to_course($user_id, $course_code, $status_user_in_new_course)) {
             $send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
             if ($send == 1) {
                 CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
             } else {
                 if ($send == 2) {
                     CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
                 }
             }
             $url = Display::url($all_course_information['title'], api_get_course_url($course_code));
             $message = sprintf(get_lang('EnrollToCourseXSuccessful'), $url);
         } else {
             $message = get_lang('ErrorContactPlatformAdmin');
         }
         return array('message' => $message);
     } else {
         if (isset($_POST['course_registration_code']) && $_POST['course_registration_code'] != $all_course_information['registration_code']) {
             return false;
         }
         $message = get_lang('CourseRequiresPassword') . '<br />';
         $message .= $all_course_information['title'] . ' (' . $all_course_information['visual_code'] . ') ';
         $action = api_get_path(WEB_CODE_PATH) . "auth/courses.php?action=subscribe_user_with_password&sec_token=" . $_SESSION['sec_token'];
         $form = new FormValidator('subscribe_user_with_password', 'post', $action);
         $form->addElement('hidden', 'sec_token', $_SESSION['sec_token']);
         $form->addElement('hidden', 'subscribe_user_with_password', $all_course_information['code']);
         $form->addElement('text', 'course_registration_code');
         $form->addButton(get_lang('SubmitRegistrationCode'));
         $content = $form->returnForm();
         return array('message' => $message, 'content' => $content);
     }
 }
Ejemplo n.º 7
0
 /**
  * Creates form that asks for the directory name.
  * @return string	html-output text for the form
  */
 public static function create_dir_form($dirId)
 {
     global $document_id;
     $form = new FormValidator('create_dir_form', 'post', api_get_self() . '?' . api_get_cidreq());
     $form->addElement('hidden', 'create_dir', 1);
     $form->addElement('hidden', 'dir_id', intval($document_id));
     $form->addElement('hidden', 'id', intval($dirId));
     $form->addElement('header', get_lang('CreateDir'));
     $form->addText('dirname', get_lang('NewDir'), array('autofocus' => 'autofocus'));
     $form->addButtonCreate(get_lang('CreateFolder'));
     return $form->returnForm();
 }
Ejemplo n.º 8
0
$tpl = Container::getTwig();
$load_user = 0;
if (isset($_GET['load_user'])) {
    $load_user = 1;
}
$skill_condition = '';
$tpl->addGlobal('skill_id_to_load', '');
if (isset($_GET['skill_id'])) {
    $skillId = intval($_GET['skill_id']);
    $skill_condition = '&skill_id=' . $skillId;
    $tpl->addGlobal('skill_id_to_load', $skillId);
}
$url = api_get_path(WEB_AJAX_PATH) . "skill.ajax.php?a=get_skills_tree_json&load_user={$load_user}";
$tpl->addGlobal('wheel_url', $url);
$url = api_get_path(WEB_AJAX_PATH) . 'skill.ajax.php?1=1';
$tpl->addGlobal('url', $url);
$tpl->addGlobal('isAdministration', true);
$dialogForm = new FormValidator('form', 'post', null, null, ['id' => 'add_item']);
$dialogForm->addLabel(get_lang('Name'), Display::tag('p', null, ['id' => 'name', 'class' => 'form-control-static']));
$dialogForm->addLabel(get_lang('ShortCode'), Display::tag('p', null, ['id' => 'short_code', 'class' => 'form-control-static']));
$dialogForm->addLabel(get_lang('Parent'), Display::tag('p', null, ['id' => 'parent', 'class' => 'form-control-static']));
$dialogForm->addLabel([get_lang('Gradebook'), get_lang('WithCertificate')], Display::tag('ul', null, ['id' => 'gradebook', 'class' => 'form-control-static list-unstyled']));
$dialogForm->addLabel(get_lang('Description'), Display::tag('p', null, ['id' => 'description', 'class' => 'form-control-static']));
$tpl->addGlobal('dialogForm', $dialogForm->returnForm());
$saveProfileForm = new FormValidator('form', 'post', null, null, ['id' => 'dialog-form-profile']);
$saveProfileForm->addHidden('profile_id', null);
$saveProfileForm->addText('name', get_lang('Name'), true, ['id' => 'name_profile']);
$saveProfileForm->addTextarea('description', get_lang('Description'), ['id' => 'description_profile', 'rows' => 6]);
$tpl->addGlobal('saveProfileForm', $saveProfileForm->returnForm());
echo $tpl->render('@template_style/skill/skill_wheel.html.twig');
Container::$legacyTemplate = 'layout_one_col_no_content.html.twig';
Ejemplo n.º 9
0
    $sequence = new Sequence();
    $sequence->setName($values['name']);
    $em->persist($sequence);
    $em->flush();
    header('Location: ' . api_get_self());
    exit;
}
$selectSequence = new FormValidator('');
$selectSequence->addHidden('sequence_type', 'session');
$em = Database::getManager();
$sequenceList = $em->getRepository('ChamiloCoreBundle:Sequence')->findAll();
$selectSequence->addSelect('sequence', get_lang('Sequence'), $sequenceList, ['id' => 'sequence_id', 'cols-size' => [3, 7, 2]]);
$form = new FormValidator('');
$form->addHtml("<div class='col-md-6'>");
$form->addHidden('sequence_type', 'session');
$form->addSelect('sessions', get_lang('Sessions'), $sessionList, ['id' => 'item', 'cols-size' => [4, 7, 1]]);
$form->addButtonNext(get_lang('UseAsReference'), 'use_as_reference', ['cols-size' => [4, 7, 1]]);
$form->addHtml("</div>");
$form->addHtml("<div class='col-md-6'>");
$form->addSelect('requirements', get_lang('Requirements'), $sessionList, ['id' => 'requirements', 'cols-size' => [3, 7, 2]]);
$form->addButtonCreate(get_lang('SetAsRequirement'), 'set_requirement', false, ['cols-size' => [3, 7, 2]]);
$form->addHtml("</div>");
$formSave = new FormValidator('');
$formSave->addHidden('sequence_type', 'session');
$formSave->addButton('save_resource', get_lang('SaveSettings'), 'floppy-o', 'success', null, null, ['cols-size' => [1, 10, 1]]);
$tpl->assign('create_sequence', $formSequence->returnForm());
$tpl->assign('select_sequence', $selectSequence->returnForm());
$tpl->assign('configure_sequence', $form->returnForm());
$tpl->assign('save_sequence', $formSave->returnForm());
$layout = $tpl->get_template('admin/resource_sequence.tpl');
$tpl->display($layout);
Ejemplo n.º 10
0
}
$watermark_deleted = false;
if (isset($_GET['delete_watermark'])) {
    $watermark_deleted = PDF::delete_watermark();
    Display::addFlash(Display::return_message(get_lang('FileDeleted')));
}
if (isset($_GET['action']) && $_GET['action'] == 'delete_grading') {
    $id = intval($_GET['id']);
    api_delete_setting_option($id);
}
$form_search = new FormValidator('search_settings', 'get', api_get_self(), null, array(), FormValidator::LAYOUT_INLINE);
$form_search->addElement('text', 'search_field');
$form_search->addElement('hidden', 'category', 'search_setting');
$form_search->addButtonSearch(get_lang('Search'), 'submit_button');
$form_search->setDefaults(array('search_field' => isset($_REQUEST['search_field']) ? $_REQUEST['search_field'] : null));
$form_search_html = $form_search->returnForm();
$url_id = api_get_current_access_url_id();
$settings = null;
function get_settings($category = null)
{
    $url_id = api_get_current_access_url_id();
    $settings_by_access_list = array();
    if ($url_id == 1) {
        $settings = api_get_settings($category, 'group', $url_id);
    } else {
        $url_info = api_get_access_url($url_id);
        if ($url_info['active'] == 1) {
            // The default settings of Chamilo
            $settings = api_get_settings($category, 'group', 1, 0);
            // The settings that are changeable from a particular site.
            $settings_by_access = api_get_settings($category, 'group', $url_id, 1);
Ejemplo n.º 11
0
    $form->addElement('html', '<div class="label">' . get_lang('SearchFeatureDocumentLanguage') . '</div>');
    $form->addLabel(get_lang('Language'), api_get_languages_combo());
    $form->addElement('html', '</div><div class="sub-form">');
    $specific_fields = get_specific_field_list();
    foreach ($specific_fields as $specific_field) {
        $form->addElement('text', $specific_field['code'], $specific_field['name']);
    }
    $form->addElement('html', '</div>');
}
$form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing');
$form->addElement('radio', 'if_exists', '', get_lang('UplOverwriteLong'), 'overwrite');
$form->addElement('radio', 'if_exists', '', get_lang('UplRenameLong'), 'rename');
// Close the java script and avoid the footer up
$form->addElement('html', '</div>');
// Button upload document
$form->addButtonSend(get_lang('SendDocument'), 'submitDocument');
$form->add_real_progress_bar('DocumentUpload', 'file');
$fileExistsOption = api_get_setting('document.if_file_exists_option');
$defaultFileExistsOption = 'rename';
if (!empty($fileExistsOption)) {
    $defaultFileExistsOption = $fileExistsOption;
}
$defaults = array('index_document' => 'checked="checked"', 'if_exists' => $defaultFileExistsOption);
$form->setDefaults($defaults);
$simple_form = $form->returnForm();
$url = api_get_path(WEB_AJAX_PATH) . 'document.ajax.php?' . api_get_cidreq() . '&a=upload_file&curdirpath=' . $path;
$multipleForm = new FormValidator('drag_drop', 'post', '#', array('enctype' => 'multipart/form-data'));
$multipleForm->addMultipleUpload($url);
$headers = array(get_lang('Upload'), get_lang('Upload') . ' (' . get_lang('Simple') . ')');
echo Display::tabs($headers, array($multipleForm->returnForm(), $form->returnForm()), 'tabs');
Display::display_footer();
Ejemplo n.º 12
0
$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
$tpl = new Template(null, false, false);
$load_user = 0;
if (isset($_GET['load_user'])) {
    $load_user = 1;
}
$skill_condition = '';
if (isset($_GET['skill_id'])) {
    $skill_condition = '&skill_id=' . intval($_GET['skill_id']);
    $tpl->assign('skill_id_to_load', $_GET['skill_id']);
}
$url = api_get_path(WEB_AJAX_PATH) . "skill.ajax.php?a=get_skills_tree_json&load_user={$load_user}";
$tpl->assign('wheel_url', $url);
$url = api_get_path(WEB_AJAX_PATH) . 'skill.ajax.php?1=1';
$tpl->assign('url', $url);
$tpl->assign('isAdministration', true);
$dialogForm = new FormValidator('form', 'post', null, null, ['id' => 'add_item']);
$dialogForm->addLabel(get_lang('Name'), Display::tag('p', null, ['id' => 'name', 'class' => 'form-control-static']));
$dialogForm->addLabel(get_lang('ShortCode'), Display::tag('p', null, ['id' => 'short_code', 'class' => 'form-control-static']));
$dialogForm->addLabel(get_lang('Parent'), Display::tag('p', null, ['id' => 'parent', 'class' => 'form-control-static']));
$dialogForm->addLabel([get_lang('Gradebook'), get_lang('WithCertificate')], Display::tag('ul', null, ['id' => 'gradebook', 'class' => 'form-control-static list-unstyled']));
$dialogForm->addLabel(get_lang('Description'), Display::tag('p', null, ['id' => 'description', 'class' => 'form-control-static']));
$tpl->assign('dialogForm', $dialogForm->returnForm());
$saveProfileForm = new FormValidator('form', 'post', null, null, ['id' => 'dialog-form-profile']);
$saveProfileForm->addHidden('profile_id', null);
$saveProfileForm->addText('name', get_lang('Name'), true, ['id' => 'name_profile']);
$saveProfileForm->addTextarea('description', get_lang('Description'), ['id' => 'description_profile', 'rows' => 6]);
$tpl->assign('saveProfileForm', $saveProfileForm->returnForm());
$content = $tpl->fetch('default/skill/skill_wheel.tpl');
$tpl->assign('content', $content);
$tpl->display_no_layout_template();
Ejemplo n.º 13
0
 public static function displayTrackingAccessOverView($courseId, $sessionId, $studentId)
 {
     $courseId = intval($courseId);
     $sessionId = intval($sessionId);
     $studentId = intval($studentId);
     $em = Database::getManager();
     $sessionRepo = $em->getRepository('ChamiloCoreBundle:Session');
     $courseList = [];
     $sessionList = [];
     $studentList = [];
     if (!empty($courseId)) {
         $course = $em->find('ChamiloCoreBundle:Course', $courseId);
         $courseList[$course->getId()] = $course->getTitle();
     }
     if (!empty($sessionId)) {
         $session = $em->find('ChamiloCoreBundle:Session', $sessionId);
         $sessionList[$session->getId()] = $session->getName();
     }
     if (!empty($studentId)) {
         $student = $em->find('ChamiloUserBundle:User', $studentId);
         $studentList[$student->getId()] = $student->getCompleteName();
     }
     $form = new FormValidator('access_overview', 'GET');
     $form->addElement('select_ajax', 'course_id', get_lang('SearchCourse'), $courseList, ['url' => api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?' . http_build_query(['a' => 'search_course_by_session_all', 'session_id' => $sessionId])]);
     $form->addElement('select_ajax', 'session_id', get_lang('SearchSession'), $sessionList, ['url_function' => "\n                    function () {\n                        var params = \$.param({\n                            a: 'search_session_by_course',\n                            course_id: \$('#course_id').val() || 0\n                        });\n\n                        return '" . api_get_path(WEB_AJAX_PATH) . "session.ajax.php?' + params;\n                    }\n                "]);
     $form->addSelect('profile', get_lang('Profile'), ['' => get_lang('Select'), STUDENT => get_lang('Student'), COURSEMANAGER => get_lang('CourseManager'), DRH => get_lang('Drh')], ['id' => 'profile']);
     $form->addElement('select_ajax', 'student_id', get_lang('SearchUsers'), $studentList, ['placeholder' => get_lang('All'), 'url_function' => "\n                    function () {\n                        var params = \$.param({\n                            a: 'search_user_by_course',\n                            session_id: \$('#session_id').val(),\n                            course_id: \$('#course_id').val()\n                        });\n\n                        return '" . api_get_path(WEB_AJAX_PATH) . "course.ajax.php?' + params;\n                    }\n                "]);
     $form->addDateRangePicker('date', get_lang('DateRange'), true, ['id' => 'date_range', 'format' => 'YYYY-MM-DD', 'timePicker' => 'false', 'validate_format' => 'Y-m-d']);
     $form->addHidden('display', 'accessoverview');
     $form->addRule('course_id', get_lang('Required'), 'required');
     $form->addRule('profile', get_lang('Required'), 'required');
     $form->addButton('submit', get_lang('Generate'), 'gear', 'primary');
     $table = null;
     if ($form->validate()) {
         $table = new SortableTable('tracking_access_overview', ['MySpace', 'getNumberOfRrackingAccessOverview'], ['MySpace', 'getUserDataAccessTrackingOverview'], 0);
         $table->additional_parameters = $form->exportValues();
         $table->set_header(0, get_lang('LoginDate'), true);
         $table->set_header(1, get_lang('Username'), true);
         if (api_is_western_name_order()) {
             $table->set_header(2, get_lang('FirstName'), true);
             $table->set_header(3, get_lang('LastName'), true);
         } else {
             $table->set_header(2, get_lang('LastName'), true);
             $table->set_header(3, get_lang('FirstName'), true);
         }
         $table->set_header(4, get_lang('Clicks'), false);
         $table->set_header(5, get_lang('IP'), false);
         $table->set_header(6, get_lang('TimeLoggedIn'), false);
     }
     $template = new Template(null, false, false, false, false, false, false);
     $template->assign('form', $form->returnForm());
     $template->assign('table', $table ? $table->return_table() : null);
     echo $template->fetch($template->get_template('my_space/accessoverview.tpl'));
 }
Ejemplo n.º 14
0
}
$users_tracking_per_page = '';
if (isset($_GET['users_tracking_per_page'])) {
    $users_tracking_per_page = '&users_tracking_per_page=' . intval($_GET['users_tracking_per_page']);
}
$actionsRight .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&export=csv&' . $addional_param . $users_tracking_per_page . '">
     ' . Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM) . '</a>';
$actionsRight .= '</div>';
// Create a search-box.
$form_search = new FormValidator('search_simple', 'GET', api_get_path(WEB_CODE_PATH) . 'tracking/courseLog.php?' . api_get_cidreq(), '', array(), FormValidator::LAYOUT_INLINE);
$form_search->addElement('hidden', 'from', Security::remove_XSS($from));
$form_search->addElement('hidden', 'session_id', $sessionId);
$form_search->addElement('hidden', 'id_session', $sessionId);
$form_search->addElement('text', 'user_keyword');
$form_search->addButtonSearch(get_lang('SearchUsers'));
echo Display::toolbarAction('toolbar-courselog', array(0 => $actionsLeft, 1 => $form_search->returnForm(), 2 => $actionsRight), 3);
$course_name = get_lang('Course') . ' ' . $courseInfo['name'];
if ($session_id) {
    $titleSession = Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL) . ' ' . api_get_session_name($session_id);
    $titleCourse = Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL) . ' ' . $course_name;
} else {
    $titleSession = Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL) . ' ' . $courseInfo['name'];
}
$teacherList = CourseManager::getTeacherListFromCourseToString($courseInfo['real_id'], ',', false, true);
$coaches = null;
if (!empty($session_id)) {
    $coaches = CourseManager::get_coachs_from_course_to_string($session_id, $courseInfo['real_id'], ',', false, true);
}
$html = '';
if (!empty($teacherList)) {
    $html .= Display::page_subheader2(get_lang('Teachers'));
Ejemplo n.º 15
0
    /**
     * Shows a question
     *
     * @param int    $questionId question id
     * @param bool   $only_questions if true only show the questions, no exercise title
     * @param bool   $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 bool   $exercise_feedback
     * @param bool   $show_answers
     * */
    public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
    {
        $course_id = api_get_course_int_id();
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        // Reads question information
        if (!($objQuestionTmp = Question::read($questionId))) {
            // Question not found
            return false;
        }
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = '';
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                }
                if (!empty($questionDescription)) {
                    echo Display::div($questionDescription, array('class' => 'question_description'));
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return '';
            }
            echo '<div class="question_options row">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $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 (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
                        <div class="clearfix">
                        <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= <<<HTML
                        <div id="drag{$questionId}_question" class="drag_question">
                            <table class="data_table">
HTML;
                }
                // Iterate through answers
                $x = 1;
                //mark letters for each answer
                $letter = 'A';
                $answer_matching = array();
                $cpt1 = array();
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $numAnswer = $objAnswerTmp->selectAutoId($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
                        $cpt1[$x] = $letter;
                        $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $x++;
                        $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'] = $cpt1[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $user_choice_array_position = array();
                if (!empty($user_choice)) {
                    foreach ($user_choice as $item) {
                        $user_choice_array_position[$item['position']] = $item['answer'];
                    }
                }
                $num_suggestions = $nbrAnswers - $x + 1;
            } elseif ($answerType == FREE_ANSWER) {
                $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null;
                $form = new FormValidator('free_choice_' . $questionId);
                $config = array('ToolbarSet' => 'TestFreeAnswer');
                $form->addHtmlEditor("choice[" . $questionId . "]", null, false, false, $config);
                $form->setDefaults(array("choice[" . $questionId . "]" => $fck_content));
                $s .= $form->returnForm();
            } elseif ($answerType == ORAL_EXPRESSION) {
                // Add nanog
                if (api_get_setting('enable_nanogong') == 'true') {
                    //@todo pass this as a parameter
                    global $exercise_stat_info, $exerciseId, $exe_id;
                    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);
                    echo $nano->show_button();
                }
                $form = new FormValidator('free_choice_' . $questionId);
                $config = array('ToolbarSet' => 'TestFreeAnswer');
                $form->addHtmlEditor("choice[" . $questionId . "]", null, false, false, $config);
                //$form->setDefaults(array("choice[" . $questionId . "]" => $fck_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) {
                    if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
                        if (in_array($item, $objQuestionTmp->options)) {
                            $header .= Display::tag('th', get_lang($item));
                        } else {
                            $header .= Display::tag('th', $item);
                        }
                    } else {
                        $header .= Display::tag('th', $item);
                    }
                }
                if ($show_comment) {
                    $header .= Display::tag('th', get_lang('Feedback'));
                }
                $s .= '<table class="table table-hover table-striped">';
                $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_IMAGE, 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="table table-hover table-striped">';
                    $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'];
                }
            }
            for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                $answer = $objAnswerTmp->selectAnswer($answerId);
                $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                $comment = $objAnswerTmp->selectComment($answerId);
                $attributes = array();
                // Unique answer
                if (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, UNIQUE_ANSWER_IMAGE])) {
                    $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;
                        }
                    }
                    if ($show_comment) {
                        $s .= '<tr><td>';
                    }
                    if ($answerType == UNIQUE_ANSWER_IMAGE) {
                        if ($show_comment) {
                            if (empty($comment)) {
                                $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image" style="text-align: center">';
                            } else {
                                $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image col-xs-6 col-sm-12" style="text-align: center">';
                            }
                        } else {
                            $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image col-xs-6 col-md-3" style="text-align: center">';
                        }
                    }
                    $answer = Security::remove_XSS($answer, STUDENT);
                    $s .= Display::input('hidden', 'choice2[' . $questionId . ']', '0');
                    $answer_input = null;
                    if ($answerType == UNIQUE_ANSWER_IMAGE) {
                        $attributes['style'] = 'display: none;';
                        $answer = '<div class="thumbnail">' . $answer . '</div>';
                    }
                    $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 .= $answer_input;
                        $s .= '</td>';
                        $s .= '<td>';
                        $s .= $comment;
                        $s .= '</td>';
                        $s .= '</tr>';
                    } else {
                        $s .= $answer_input;
                    }
                } elseif ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == GLOBAL_MULTIPLE_ANSWER) {
                    $input_id = 'choice-' . $questionId . '-' . $answerId;
                    $answer = Security::remove_XSS($answer, STUDENT);
                    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) {
                                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, STUDENT);
                    $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);
                            if (isset($item[1]) && isset($item[0])) {
                                $my_choice[$item[0]] = $item[1];
                            }
                        }
                    }
                    $answer = Security::remove_XSS($answer, STUDENT);
                    $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) {
                    // display the question, with field empty, for student to fill it,
                    // or filled to display the answer in the Question preview of the exercice/admin.php page
                    $displayForStudent = true;
                    $listAnswerInformations = FillBlanks::getAnswerInfo($answer);
                    $separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']);
                    $separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']);
                    list($answer) = explode('::', $answer);
                    //Correct answers
                    $correctAnswerList = $listAnswerInformations['tabwords'];
                    //Student's answer
                    $studentAnswerList = array();
                    if (isset($user_choice[0]['answer'])) {
                        $arrayStudentAnswer = FillBlanks::getAnswerInfo($user_choice[0]['answer'], true);
                        $studentAnswerList = $arrayStudentAnswer['studentanswer'];
                    }
                    // If the question must be shown with the answer (in page exercice/admin.php) for teacher preview
                    // set the student-answer to the correct answer
                    if ($debug_mark_answer) {
                        $studentAnswerList = $correctAnswerList;
                        $displayForStudent = false;
                    }
                    if (!empty($correctAnswerList) && !empty($studentAnswerList)) {
                        $answer = "";
                        for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) {
                            // display the common word
                            $answer .= $listAnswerInformations["commonwords"][$i];
                            // display the blank word
                            $correctItem = $listAnswerInformations["tabwords"][$i];
                            $correctItemRegexp = $correctItem;
                            // replace / with \/ to allow the preg_replace bellow and all the regexp char
                            $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
                            if (isset($studentAnswerList[$i])) {
                                // If student already started this test and answered this question,
                                // fill the blank with his previous answers
                                // may be "" if student viewed the question, but did not fill the blanks
                                $correctItem = $studentAnswerList[$i];
                            }
                            $attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px";
                            $answer .= FillBlanks::getFillTheBlankHtml($separatorStartRegexp, $separatorEndRegexp, $correctItemRegexp, $questionId, $correctItem, $attributes, $answer, $listAnswerInformations, $displayForStudent, $i);
                        }
                        // display the last common word
                        $answer .= $listAnswerInformations["commonwords"][$i];
                    } else {
                        // display empty [input] with the right width for student to fill it
                        $separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']);
                        $separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']);
                        $answer = "";
                        for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) {
                            // display the common words
                            $answer .= $listAnswerInformations["commonwords"][$i];
                            // display the blank word
                            $attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px";
                            $correctItem = $listAnswerInformations["tabwords"][$i];
                            $correctItemRegexp = $correctItem;
                            // replace / with \/ to allow the preg_replace bellow and all the regexp char
                            $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
                            $answer .= FillBlanks::getFillTheBlankHtml($separatorStartRegexp, $separatorEndRegexp, $correctItemRegexp, $questionId, '', $attributes, $answer, $listAnswerInformations, $displayForStudent, $i);
                        }
                        // display the last common word
                        $answer .= $listAnswerInformations["commonwords"][$i];
                    }
                    $s .= $answer;
                } elseif ($answerType == CALCULATED_ANSWER) {
                    /*
                     * In the CALCULATED_ANSWER test
                     * you mustn't have [ and ] in the textarea
                     * you mustn't have @@ in the textarea
                     * the text to find mustn't be empty or contains only spaces
                     * the text to find mustn't contains HTML tags
                     * the text to find mustn't contains char "
                     */
                    if ($origin !== null) {
                        global $exe_id;
                        $trackAttempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
                        $sqlTrackAttempt = 'SELECT answer FROM ' . $trackAttempts . '
                                            WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId;
                        $rsLastAttempt = Database::query($sqlTrackAttempt);
                        $rowLastAttempt = Database::fetch_array($rsLastAttempt);
                        $answer = $rowLastAttempt['answer'];
                        if (empty($answer)) {
                            $_SESSION['calculatedAnswerId'][$questionId] = mt_rand(1, $nbrAnswers);
                            $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]);
                        }
                    }
                    list($answer) = explode('@@', $answer);
                    // $correctAnswerList array of array with correct anwsers 0=> [0=>[\p] 1=>[plop]]
                    api_preg_match_all('/\\[[^]]+\\]/', $answer, $correctAnswerList);
                    // get student answer to display it if student go back to previous calculated answer question in a test
                    if (isset($user_choice[0]['answer'])) {
                        api_preg_match_all('/\\[[^]]+\\]/', $answer, $studentAnswerList);
                        $studentAnswerListTobecleaned = $studentAnswerList[0];
                        $studentAnswerList = array();
                        for ($i = 0; $i < count($studentAnswerListTobecleaned); $i++) {
                            $answerCorrected = $studentAnswerListTobecleaned[$i];
                            $answerCorrected = api_preg_replace('| / <font color="green"><b>.*$|', '', $answerCorrected);
                            $answerCorrected = api_preg_replace('/^\\[/', '', $answerCorrected);
                            $answerCorrected = api_preg_replace('|^<font color="red"><s>|', '', $answerCorrected);
                            $answerCorrected = api_preg_replace('|</s></font>$|', '', $answerCorrected);
                            $answerCorrected = '[' . $answerCorrected . ']';
                            $studentAnswerList[] = $answerCorrected;
                        }
                    }
                    // If display preview of answer in test view for exemple, set the student answer to the correct answers
                    if ($debug_mark_answer) {
                        // contain the rights answers surronded with brackets
                        $studentAnswerList = $correctAnswerList[0];
                    }
                    /*
                    Split the response by bracket
                    tabComments is an array with text surrounding the text to find
                    we add a space before and after the answerQuestion to be sure to
                    have a block of text before and after [xxx] patterns
                    so we have n text to find ([xxx]) and n+1 block of texts before,
                    between and after the text to find
                    */
                    $tabComments = api_preg_split('/\\[[^]]+\\]/', ' ' . $answer . ' ');
                    if (!empty($correctAnswerList) && !empty($studentAnswerList)) {
                        $answer = "";
                        $i = 0;
                        foreach ($studentAnswerList as $studentItem) {
                            // remove surronding brackets
                            $studentResponse = api_substr($studentItem, 1, api_strlen($studentItem) - 2);
                            $size = strlen($studentItem);
                            $attributes['class'] = self::detectInputAppropriateClass($size);
                            $answer .= $tabComments[$i] . Display::input('text', "choice[{$questionId}][]", $studentResponse, $attributes);
                            $i++;
                        }
                        $answer .= $tabComments[$i];
                    } else {
                        // display exercise with empty input fields
                        // every [xxx] are replaced with an empty input field
                        foreach ($correctAnswerList[0] as $item) {
                            $size = strlen($item);
                            $attributes['class'] = self::detectInputAppropriateClass($size);
                            $answer = str_replace($item, Display::input('text', "choice[{$questionId}][]", '', $attributes), $answer);
                        }
                    }
                    if ($origin !== null) {
                        $s = $answer;
                        break;
                    } else {
                        $s .= $answer;
                    }
                } elseif ($answerType == MATCHING) {
                    // 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 corrrect = 0)
                        $s .= '<tr><td width="45%" valign="top">';
                        $parsed_answer = $answer;
                        //left part questions
                        $s .= '<p class="indent">' . $lines_count . '.&nbsp;' . $parsed_answer . '</p></td>';
                        //middle part (matches selects)
                        $s .= '<td width="10%" valign="top" align="center" >
                                <div class="select-matching">
                                <select name="choice[' . $questionId . '][' . $numAnswer . ']">';
                        // fills the list-box
                        foreach ($select_items as $key => $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"';
                                }
                            }
                            //$user_choice_array_position
                            if (isset($user_choice_array_position[$numAnswer]) && $val['id'] == $user_choice_array_position[$numAnswer]) {
                                $selected = 'selected="selected"';
                            }
                            $s .= '<option value="' . $val['id'] . '" ' . $selected . '>' . $val['letter'] . '</option>';
                        }
                        // end foreach()
                        $s .= '</select></div></td><td width="5%" class="separate">&nbsp;</td>';
                        $s .= '<td width="40%" valign="top" >';
                        if (isset($select_items[$lines_count])) {
                            $s .= '<div class="text-right"><p class="indent">' . $select_items[$lines_count]['letter'] . '.&nbsp; ' . $select_items[$lines_count]['answer'] . '</p></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> ' . $select_items[$lines_count]['answer'];
                                $s .= "</td>\n                                </tr>";
                                $lines_count++;
                            }
                            // end while()
                        }
                        // end if()
                        $matching_correct_answer++;
                    }
                } elseif ($answerType == DRAGGABLE) {
                    if ($answerCorrect != 0) {
                        $parsed_answer = $answer;
                        /*$lines_count = '';
                          $data = $objAnswerTmp->getAnswerByAutoId($numAnswer);
                          $data = $objAnswerTmp->getAnswerByAutoId($data['correct']);
                          $lines_count = $data['answer'];*/
                        $windowId = $questionId . '_' . $lines_count;
                        $s .= '<li class="touch-items" id="' . $windowId . '">';
                        $s .= Display::div($parsed_answer, ['id' => "window_{$windowId}", 'class' => "window{$questionId}_question_draggable exercise-draggable-answer-option"]);
                        $selectedValue = 0;
                        $draggableSelectOptions = [];
                        foreach ($select_items as $key => $val) {
                            if ($debug_mark_answer) {
                                if ($val['id'] == $answerCorrect) {
                                    $selectedValue = $val['id'];
                                }
                            }
                            if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
                                $selectedValue = $val['id'];
                            }
                            $draggableSelectOptions[$val['id']] = $val['letter'];
                        }
                        $s .= Display::select("choice[{$questionId}][{$numAnswer}]", $draggableSelectOptions, $selectedValue, ['id' => "window_{$windowId}_select", 'class' => 'select_option', 'style' => 'display: none;'], false);
                        if (!empty($answerCorrect) && !empty($selectedValue)) {
                            $s .= <<<JAVASCRIPT
                                <script>
                                    \$(function() {
                                        DraggableAnswer.deleteItem(
                                            \$('#{$questionId}_{$selectedValue}'),
                                            \$('#drop_{$windowId}')
                                        );
                                    });
                                </script>
JAVASCRIPT;
                        }
                        if (isset($select_items[$lines_count])) {
                            $s .= Display::div(Display::tag('b', $select_items[$lines_count]['letter']) . $select_items[$lines_count]['answer'], ['id' => "window_{$windowId}_answer", 'style' => 'display: none;']);
                        } else {
                            $s .= '&nbsp;';
                        }
                        $lines_count++;
                        if ($lines_count - 1 == $num_suggestions) {
                            while (isset($select_items[$lines_count])) {
                                $s .= Display::tag('b', $select_items[$lines_count]['letter']);
                                $s .= $select_items[$lines_count]['answer'];
                                $lines_count++;
                            }
                        }
                        $matching_correct_answer++;
                        $s .= '</li>';
                    }
                } elseif ($answerType == MATCHING_DRAGGABLE) {
                    if ($answerId == 1) {
                        echo $objAnswerTmp->getJs();
                    }
                    if ($answerCorrect != 0) {
                        $parsed_answer = $answer;
                        $windowId = "{$questionId}_{$lines_count}";
                        $s .= <<<HTML
                            <tr>
                                <td widht="45%">
                                    <div id="window_{$windowId}" class="window window_left_question window{$questionId}_question">
                                        <strong>{$lines_count}.</strong> {$parsed_answer}
                                    </div>
                                </td>
                                <td width="10%">
HTML;
                        $selectedValue = 0;
                        $questionOptions = [];
                        foreach ($select_items as $key => $val) {
                            if ($debug_mark_answer) {
                                if ($val['id'] == $answerCorrect) {
                                    $selectedValue = $val['id'];
                                }
                            }
                            if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
                                $selectedValue = $val['id'];
                            }
                            $questionOptions[$val['id']] = $val['letter'];
                        }
                        $s .= Display::select("choice[{$questionId}][{$numAnswer}]", $questionOptions, $selectedValue, ['id' => "window_{$windowId}_select", 'class' => 'hidden'], false);
                        if (!empty($answerCorrect) && !empty($selectedValue)) {
                            // Show connect if is not freeze (question preview)
                            if (!$freeze) {
                                $s .= <<<JAVASCRIPT
                                <script>
                                    jsPlumb.ready(function() {
                                        jsPlumb.connect({
                                            source: 'window_{$windowId}',
                                            target: 'window_{$questionId}_{$selectedValue}_answer',
                                            endpoint: ['Blank', {radius: 15}],
                                            anchors: ['RightMiddle', 'LeftMiddle'],
                                            paintStyle: {strokeStyle: '#8A8888', lineWidth: 8},
                                            connector: [
                                                MatchingDraggable.connectorType,
                                                {curvines: MatchingDraggable.curviness}
                                            ]
                                        });
                                    });
                                </script>
JAVASCRIPT;
                            }
                        }
                        $s .= <<<HTML
                            </td>
                            <td width="45%">
HTML;
                        if (isset($select_items[$lines_count])) {
                            $s .= <<<HTML
                                <div id="window_{$windowId}_answer" class="window window_right_question">
                                    <strong>{$select_items[$lines_count]['letter']}.</strong> {$select_items[$lines_count]['answer']}
                                </div>
HTML;
                        } else {
                            $s .= '&nbsp;';
                        }
                        $s .= '</td></tr>';
                        $lines_count++;
                        if ($lines_count - 1 == $num_suggestions) {
                            while (isset($select_items[$lines_count])) {
                                $s .= <<<HTML
                                    <tr>
                                        <td colspan="2"></td>
                                        <td>
                                            <strong>{$select_items[$lines_count]['letter']}</strong>
                                            {$select_items[$lines_count]['answer']}
                                        </td>
                                    </tr>
HTML;
                                $lines_count++;
                            }
                        }
                        $matching_correct_answer++;
                    }
                }
            }
            // end for()
            if ($show_comment) {
                $s .= '</table>';
            } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER_TRUE_FALSE, MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE])) {
                $s .= '</table>';
            }
            if ($answerType == DRAGGABLE) {
                $s .= "</ul></div>";
                $counterAnswer = 1;
                $s .= '<div class="col-md-12"><div class="row">';
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $windowId = $questionId . '_' . $counterAnswer;
                    if ($answerCorrect) {
                        $s .= Display::div($counterAnswer, ['id' => "drop_{$windowId}", 'class' => 'droppable col-md-2']);
                        $counterAnswer++;
                    }
                }
                $s .= '</div></div>';
            }
            if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
                $s .= '</div>';
            }
            $s .= '</div>';
            // destruction of the Answer object
            unset($objAnswerTmp);
            // destruction of the Question object
            unset($objQuestionTmp);
            if ($origin != 'export') {
                echo $s;
            } else {
                return $s;
            }
        } 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) {
                echo Display::img($objQuestionTmp->selectPicturePath());
                return;
            }
            // Get the answers, make a list
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            // get answers of hotpost
            $answers_hotspot = array();
            for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                $answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId));
                $answers_hotspot[$answers['id']] = $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) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo '<div class="question_title">' . $current_item . '. ' . $questionName . '</div>';
                }
                //@todo I need to the get the feedback type
                echo '<input type="hidden" name="hidden_hotspot_id" value="' . $questionId . '" />';
                echo '<table class="exercise_questions" >
                      <tr>
                        <td valign="top" colspan="2">';
                echo $questionDescription;
                echo '</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 . '&canClick:' . $canClick . '" width="600" height="' . $swf_height . '">\'
                                            + \'<param name="wmode" value="transparent">\'
                                            + \'<param name="movie" value="../plugin/hotspot/' . $swf_file . '.swf?modifyAnswers=' . $questionId . '&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>';
            echo $s;
            echo '</table>';
        }
        return $nbrAnswers;
    }
Ejemplo n.º 16
0
<?php

/* For licensing terms, see /license.txt */
//require_once '../inc/global.inc.php';
if (api_get_setting('platform_unsubscribe_allowed') != 'true') {
    api_not_allowed();
}
$tool_name = get_lang('Unsubscribe');
$message = Display::return_message(get_lang('UnsubscribeFromPlatform'), 'warning');
$form = new FormValidator('user_add');
$form->addElement('button', 'submit', get_lang('Unsubscribe'), array('onclick' => "javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang("UnsubscribeFromPlatformConfirm"))) . "')) return false;"));
$content = $form->returnForm();
if ($form->validate()) {
    $user_info = api_get_user_info();
    $result = UserManager::delete_user($user_info['user_id']);
    if ($result) {
        $message = Display::return_message(sprintf(get_lang('UnsubscribeFromPlatformSuccess', $user_info['username'])));
        $content = null;
        online_logout($user_info['user_id'], false);
        api_not_allowed(true, $message);
    }
}
//$tpl = new Template($tool_name);
echo $actions;
echo $message;
echo $content;
Ejemplo n.º 17
0
    /**
     * Shows a question
     *
     * @param int    $questionId question id
     * @param bool   $only_questions if true only show the questions, no exercise title
     * @param bool   $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 bool   $exercise_feedback
     * @param bool   $show_answers
     * */
    public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
    {
        $course_id = api_get_course_int_id();
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        // Reads question information
        if (!($objQuestionTmp = Question::read($questionId))) {
            // Question not found
            return false;
        }
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = '';
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                }
                if (!empty($questionDescription)) {
                    echo Display::div($questionDescription, array('class' => 'question_description'));
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return '';
            }
            echo '<div class="question_options row">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $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 (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
                        <div class="clearfix">
                        <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= '<div id="drag' . $questionId . '_question" class="drag_question">
                           <table class="data_table">';
                }
                // Iterate through answers
                $x = 1;
                //mark letters for each answer
                $letter = 'A';
                $answer_matching = array();
                $cpt1 = array();
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $numAnswer = $objAnswerTmp->selectAutoId($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
                        $cpt1[$x] = $letter;
                        $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $x++;
                        $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_auto'];
                    $select_items[$i]['letter'] = $cpt1[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $user_choice_array_position = array();
                if (!empty($user_choice)) {
                    foreach ($user_choice as $item) {
                        $user_choice_array_position[$item['position']] = $item['answer'];
                    }
                }
                $num_suggestions = $nbrAnswers - $x + 1;
            } elseif ($answerType == FREE_ANSWER) {
                $fck_content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null;
                $form = new FormValidator('free_choice_' . $questionId);
                $config = array('ToolbarSet' => 'TestFreeAnswer');
                $form->addHtmlEditor("choice[" . $questionId . "]", null, false, false, $config);
                $form->setDefaults(array("choice[" . $questionId . "]" => $fck_content));
                $s .= $form->returnForm();
            } elseif ($answerType == ORAL_EXPRESSION) {
                // Add nanog
                if (api_get_setting('document.enable_nanogong') == 'true') {
                    //@todo pass this as a parameter
                    global $exercise_stat_info, $exerciseId, $exe_id;
                    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);
                    echo $nano->show_button();
                }
                $form = new FormValidator('free_choice_' . $questionId);
                $config = array('ToolbarSet' => 'TestFreeAnswer');
                $form->addHtmlEditor("choice[" . $questionId . "]", null, false, false, $config);
                //$form->setDefaults(array("choice[" . $questionId . "]" => $fck_content));
                $s .= $form->returnForm();
            }
            // 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) {
                    if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
                        if (in_array($item, $objQuestionTmp->options)) {
                            $header .= Display::tag('th', get_lang($item));
                        } else {
                            $header .= Display::tag('th', $item);
                        }
                    } else {
                        $header .= Display::tag('th', $item);
                    }
                }
                if ($show_comment) {
                    $header .= Display::tag('th', get_lang('Feedback'));
                }
                $s .= '<table class="table table-hover table-striped">';
                $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_IMAGE, 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="table table-hover table-striped">';
                    $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'];
                }
            }
            for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                $answer = $objAnswerTmp->selectAnswer($answerId);
                $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                $comment = $objAnswerTmp->selectComment($answerId);
                $attributes = array();
                // Unique answer
                if (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, UNIQUE_ANSWER_IMAGE])) {
                    $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;
                        }
                    }
                    if ($show_comment) {
                        $s .= '<tr><td>';
                    }
                    if ($answerType == UNIQUE_ANSWER_IMAGE) {
                        if ($show_comment) {
                            if (empty($comment)) {
                                $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image" style="text-align: center">';
                            } else {
                                $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image col-xs-6 col-sm-12" style="text-align: center">';
                            }
                        } else {
                            $s .= '<div id="answer' . $questionId . $numAnswer . '" ' . 'class="exercise-unique-answer-image col-xs-6 col-md-3" style="text-align: center">';
                        }
                    }
                    $answer = Security::remove_XSS($answer, STUDENT);
                    $s .= Display::input('hidden', 'choice2[' . $questionId . ']', '0');
                    $answer_input = null;
                    if ($answerType == UNIQUE_ANSWER_IMAGE) {
                        $attributes['style'] = 'display: none;';
                        $answer = '<div class="thumbnail">' . $answer . '</div>';
                    }
                    $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 .= $answer_input;
                        $s .= '</td>';
                        $s .= '<td>';
                        $s .= $comment;
                        $s .= '</td>';
                        $s .= '</tr>';
                    } else {
                        $s .= $answer_input;
                    }
                } elseif ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == GLOBAL_MULTIPLE_ANSWER) {
                    $input_id = 'choice-' . $questionId . '-' . $answerId;
                    $answer = Security::remove_XSS($answer, STUDENT);
                    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) {
                                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, STUDENT);
                    $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);
                            if (isset($item[1]) && isset($item[0])) {
                                $my_choice[$item[0]] = $item[1];
                            }
                        }
                    }
                    $answer = Security::remove_XSS($answer, STUDENT);
                    $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) {
                    // display the question, with field empty, for student to fill it,
                    // or filled to display the answer in the Question preview of the exercice/admin.php page
                    $displayForStudent = true;
                    $listAnswerInformations = FillBlanks::getAnswerInfo($answer);
                    $separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']);
                    $separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']);
                    list($answer) = explode('::', $answer);
                    //Correct answers
                    $correctAnswerList = $listAnswerInformations['tabwords'];
                    //Student's answer
                    $studentAnswerList = array();
                    if (isset($user_choice[0]['answer'])) {
                        $arrayStudentAnswer = FillBlanks::getAnswerInfo($user_choice[0]['answer'], true);
                        $studentAnswerList = $arrayStudentAnswer['studentanswer'];
                    }
                    // If the question must be shown with the answer (in page exercice/admin.php) for teacher preview
                    // set the student-answer to the correct answer
                    if ($debug_mark_answer) {
                        $studentAnswerList = $correctAnswerList;
                        $displayForStudent = false;
                    }
                    if (!empty($correctAnswerList) && !empty($studentAnswerList)) {
                        $answer = "";
                        for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) {
                            // display the common word
                            $answer .= $listAnswerInformations["commonwords"][$i];
                            // display the blank word
                            $correctItem = $listAnswerInformations["tabwords"][$i];
                            $correctItemRegexp = $correctItem;
                            // replace / with \/ to allow the preg_replace bellow and all the regexp char
                            $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
                            if (isset($studentAnswerList[$i])) {
                                // If student already started this test and answered this question,
                                // fill the blank with his previous answers
                                // may be "" if student viewed the question, but did not fill the blanks
                                $correctItem = $studentAnswerList[$i];
                            }
                            $attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px";
                            $answer .= FillBlanks::getFillTheBlankHtml($separatorStartRegexp, $separatorEndRegexp, $correctItemRegexp, $questionId, $correctItem, $attributes, $answer, $listAnswerInformations, $displayForStudent, $i);
                        }
                        // display the last common word
                        $answer .= $listAnswerInformations["commonwords"][$i];
                    } else {
                        // display empty [input] with the right width for student to fill it
                        $separatorStartRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorstart']);
                        $separatorEndRegexp = FillBlanks::escapeForRegexp($listAnswerInformations['blankseparatorend']);
                        $answer = "";
                        for ($i = 0; $i < count($listAnswerInformations["commonwords"]) - 1; $i++) {
                            // display the common words
                            $answer .= $listAnswerInformations["commonwords"][$i];
                            // display the blank word
                            $attributes["style"] = "width:" . $listAnswerInformations["tabinputsize"][$i] . "px";
                            $correctItem = $listAnswerInformations["tabwords"][$i];
                            $correctItemRegexp = $correctItem;
                            // replace / with \/ to allow the preg_replace bellow and all the regexp char
                            $correctItemRegexp = FillBlanks::getRegexpProtected($correctItemRegexp);
                            $answer .= FillBlanks::getFillTheBlankHtml($separatorStartRegexp, $separatorEndRegexp, $correctItemRegexp, $questionId, '', $attributes, $answer, $listAnswerInformations, $displayForStudent, $i);
                        }
                        // display the last common word
                        $answer .= $listAnswerInformations["commonwords"][$i];
                    }
                    $s .= $answer;
                } elseif ($answerType == CALCULATED_ANSWER) {
                    /*
                     * In the CALCULATED_ANSWER test
                     * you mustn't have [ and ] in the textarea
                     * you mustn't have @@ in the textarea
                     * the text to find mustn't be empty or contains only spaces
                     * the text to find mustn't contains HTML tags
                     * the text to find mustn't contains char "
                     */
                    if ($origin !== null) {
                        global $exe_id;
                        $trackAttempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
                        $sql = 'SELECT answer
                                FROM ' . $trackAttempts . '
                                WHERE exe_id=' . $exe_id . ' AND question_id=' . $questionId;
                        $rsLastAttempt = Database::query($sql);
                        $rowLastAttempt = Database::fetch_array($rsLastAttempt);
                        $answer = $rowLastAttempt['answer'];
                        if (empty($answer)) {
                            $calculatedAnswerId = [];
                            $calculatedAnswerId[$questionId] = mt_rand(1, $nbrAnswers);
                            $answer = $objAnswerTmp->selectAnswer($calculatedAnswerId[$questionId]);
                            Session::write('calculatedAnswerId', $calculatedAnswerId);
                        }
                    }
                    list($answer) = explode('@@', $answer);
                    // $correctAnswerList array of array with correct anwsers 0=> [0=>[\p] 1=>[plop]]
                    api_preg_match_all('/\\[[^]]+\\]/', $answer, $correctAnswerList);
                    // get student answer to display it if student go back to previous calculated answer question in a test
                    if (isset($user_choice[0]['answer'])) {
                        api_preg_match_all('/\\[[^]]+\\]/', $answer, $studentAnswerList);
                        $studentAnswerListTobecleaned = $studentAnswerList[0];
                        $studentAnswerList = array();
                        for ($i = 0; $i < count($studentAnswerListTobecleaned); $i++) {
                            $answerCorrected = $studentAnswerListTobecleaned[$i];
                            $answerCorrected = api_preg_replace('| / <font color="green"><b>.*$|', '', $answerCorrected);
                            $answerCorrected = api_preg_replace('/^\\[/', '', $answerCorrected);
                            $answerCorrected = api_preg_replace('|^<font color="red"><s>|', '', $answerCorrected);
                            $answerCorrected = api_preg_replace('|</s></font>$|', '', $answerCorrected);
                            $answerCorrected = '[' . $answerCorrected . ']';
                            $studentAnswerList[] = $answerCorrected;
                        }
                    }
                    // If display preview of answer in test view for exemple, set the student answer to the correct answers
                    if ($debug_mark_answer) {
                        // contain the rights answers surronded with brackets
                        $studentAnswerList = $correctAnswerList[0];
                    }
                    /*
                    Split the response by bracket
                    tabComments is an array with text surrounding the text to find
                    we add a space before and after the answerQuestion to be sure to
                    have a block of text before and after [xxx] patterns
                    so we have n text to find ([xxx]) and n+1 block of texts before,
                    between and after the text to find
                    */
                    $tabComments = api_preg_split('/\\[[^]]+\\]/', ' ' . $answer . ' ');
                    if (!empty($correctAnswerList) && !empty($studentAnswerList)) {
                        $answer = "";
                        $i = 0;
                        foreach ($studentAnswerList as $studentItem) {
                            // remove surronding brackets
                            $studentResponse = api_substr($studentItem, 1, api_strlen($studentItem) - 2);
                            $size = strlen($studentItem);
                            $attributes['class'] = self::detectInputAppropriateClass($size);
                            $answer .= $tabComments[$i] . Display::input('text', "choice[{$questionId}][]", $studentResponse, $attributes);
                            $i++;
                        }
                        $answer .= $tabComments[$i];
                    } else {
                        // display exercise with empty input fields
                        // every [xxx] are replaced with an empty input field
                        foreach ($correctAnswerList[0] as $item) {
                            $size = strlen($item);
                            $attributes['class'] = self::detectInputAppropriateClass($size);
                            $answer = str_replace($item, Display::input('text', "choice[{$questionId}][]", '', $attributes), $answer);
                        }
                    }
                    if ($origin !== null) {
                        $s = $answer;
                        break;
                    } else {
                        $s .= $answer;
                    }
                } elseif ($answerType == MATCHING) {
                    // 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 corrrect = 0)
                        $s .= '<tr><td width="45%" valign="top">';
                        $parsed_answer = $answer;
                        //left part questions
                        $s .= '<p class="indent">' . $lines_count . '.&nbsp;' . $parsed_answer . '</p></td>';
                        //middle part (matches selects)
                        $s .= '<td width="10%" valign="top" align="center" >
                                <div class="select-matching">
                                <select name="choice[' . $questionId . '][' . $numAnswer . ']">';
                        // fills the list-box
                        foreach ($select_items as $key => $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"';
                                }
                            }
                            //$user_choice_array_position
                            if (isset($user_choice_array_position[$numAnswer]) && $val['id'] == $user_choice_array_position[$numAnswer]) {
                                $selected = 'selected="selected"';
                            }
                            $s .= '<option value="' . $val['id'] . '" ' . $selected . '>' . $val['letter'] . '</option>';
                        }
                        // end foreach()
                        $s .= '</select></div></td><td width="5%" class="separate">&nbsp;</td>';
                        $s .= '<td width="40%" valign="top" >';
                        if (isset($select_items[$lines_count])) {
                            $s .= '<div class="text-right"><p class="indent">' . $select_items[$lines_count]['letter'] . '.&nbsp; ' . $select_items[$lines_count]['answer'] . '</p></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> ' . $select_items[$lines_count]['answer'];
                                $s .= "</td>\n                                </tr>";
                                $lines_count++;
                            }
                            // end while()
                        }
                        // end if()
                        $matching_correct_answer++;
                    }
                } elseif ($answerType == DRAGGABLE) {
                    if ($answerCorrect != 0) {
                        $parsed_answer = $answer;
                        /*$lines_count = '';
                          $data = $objAnswerTmp->getAnswerByAutoId($numAnswer);
                          $data = $objAnswerTmp->getAnswerByAutoId($data['correct']);
                          $lines_count = $data['answer'];*/
                        $windowId = $questionId . '_' . $lines_count;
                        $s .= '<li class="touch-items" id="' . $windowId . '">';
                        $s .= Display::div($parsed_answer, ['id' => "window_{$windowId}", 'class' => "window{$questionId}_question_draggable exercise-draggable-answer-option"]);
                        $selectedValue = 0;
                        $draggableSelectOptions = [];
                        foreach ($select_items as $key => $val) {
                            if ($debug_mark_answer) {
                                if ($val['id'] == $answerCorrect) {
                                    $selectedValue = $val['id'];
                                }
                            }
                            if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
                                $selectedValue = $val['id'];
                            }
                            $draggableSelectOptions[$val['id']] = $val['letter'];
                        }
                        $s .= Display::select("choice[{$questionId}][{$numAnswer}]", $draggableSelectOptions, $selectedValue, ['id' => "window_{$windowId}_select", 'class' => 'select_option', 'style' => 'display: none;'], false);
                        if (!empty($answerCorrect) && !empty($selectedValue)) {
                            $s .= <<<JAVASCRIPT
                                <script>
                                    \$(function() {
                                        DraggableAnswer.deleteItem(
                                            \$('#{$questionId}_{$selectedValue}'),
                                            \$('#drop_{$windowId}')
                                        );
                                    });
                                </script>
JAVASCRIPT;
                        }
                        if (isset($select_items[$lines_count])) {
                            $s .= Display::div(Display::tag('b', $select_items[$lines_count]['letter']) . $select_items[$lines_count]['answer'], ['id' => "window_{$windowId}_answer", 'style' => 'display: none;']);
                        } else {
                            $s .= '&nbsp;';
                        }
                        $lines_count++;
                        if ($lines_count - 1 == $num_suggestions) {
                            while (isset($select_items[$lines_count])) {
                                $s .= Display::tag('b', $select_items[$lines_count]['letter']);
                                $s .= $select_items[$lines_count]['answer'];
                                $lines_count++;
                            }
                        }
                        $matching_correct_answer++;
                        $s .= '</li>';
                    }
                } elseif ($answerType == MATCHING_DRAGGABLE) {
                    if ($answerId == 1) {
                        echo $objAnswerTmp->getJs();
                    }
                    if ($answerCorrect != 0) {
                        $parsed_answer = $answer;
                        $windowId = "{$questionId}_{$lines_count}";
                        $s .= <<<HTML
                            <tr>
                                <td widht="45%">
                                    <div id="window_{$windowId}" class="window window_left_question window{$questionId}_question">
                                        <strong>{$lines_count}.</strong> {$parsed_answer}
                                    </div>
                                </td>
                                <td width="10%">
HTML;
                        $selectedValue = 0;
                        $selectedPosition = 0;
                        $questionOptions = [];
                        $iTempt = 0;
                        foreach ($select_items as $key => $val) {
                            if ($debug_mark_answer) {
                                if ($val['id'] == $answerCorrect) {
                                    $selectedValue = $val['id'];
                                    $selectedPosition = $iTempt;
                                }
                            }
                            if (isset($user_choice[$matching_correct_answer]) && $val['id'] == $user_choice[$matching_correct_answer]['answer']) {
                                $selectedValue = $val['id'];
                                $selectedPosition = $iTempt;
                            }
                            $questionOptions[$val['id']] = $val['letter'];
                            $iTempt++;
                        }
                        $s .= Display::select("choice[{$questionId}][{$numAnswer}]", $questionOptions, $selectedValue, ['id' => "window_{$windowId}_select", 'class' => 'hidden'], false);
                        if (!empty($answerCorrect) && !empty($selectedValue)) {
                            // Show connect if is not freeze (question preview)
                            if (!$freeze) {
                                $s .= <<<JAVASCRIPT
                                <script>
                                    \$(document).on('ready', function () {
                                        jsPlumb.ready(function() {
                                            jsPlumb.connect({
                                                source: 'window_{$windowId}',
                                                target: 'window_{$questionId}_{$selectedPosition}_answer',
                                                endpoint: ['Blank', {radius: 15}],
                                                anchors: ['RightMiddle', 'LeftMiddle'],
                                                paintStyle: {strokeStyle: '#8A8888', lineWidth: 8},
                                                connector: [
                                                    MatchingDraggable.connectorType,
                                                    {curvines: MatchingDraggable.curviness}
                                                ]
                                            });
                                        });
                                    });
                                </script>
JAVASCRIPT;
                            }
                        }
                        $s .= <<<HTML
                            </td>
                            <td width="45%">
HTML;
                        if (isset($select_items[$lines_count])) {
                            $s .= <<<HTML
                                <div id="window_{$windowId}_answer" class="window window_right_question">
                                    <strong>{$select_items[$lines_count]['letter']}.</strong> {$select_items[$lines_count]['answer']}
                                </div>
HTML;
                        } else {
                            $s .= '&nbsp;';
                        }
                        $s .= '</td></tr>';
                        $lines_count++;
                        if ($lines_count - 1 == $num_suggestions) {
                            while (isset($select_items[$lines_count])) {
                                $s .= <<<HTML
                                    <tr>
                                        <td colspan="2"></td>
                                        <td>
                                            <strong>{$select_items[$lines_count]['letter']}</strong>
                                            {$select_items[$lines_count]['answer']}
                                        </td>
                                    </tr>
HTML;
                                $lines_count++;
                            }
                        }
                        $matching_correct_answer++;
                    }
                }
            }
            // end for()
            if ($show_comment) {
                $s .= '</table>';
            } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER_TRUE_FALSE, MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE])) {
                $s .= '</table>';
            }
            if ($answerType == DRAGGABLE) {
                $s .= "</ul>";
                $s .= "</div>";
                //clearfix
                $counterAnswer = 1;
                $s .= '<div class="col-md-12"><div class="row">';
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $windowId = $questionId . '_' . $counterAnswer;
                    if ($answerCorrect) {
                        $s .= Display::div($counterAnswer, ['id' => "drop_{$windowId}", 'class' => 'droppable col-md-2']);
                        $counterAnswer++;
                    }
                }
                $s .= '</div>';
                // row
                $s .= '</div>';
                // col-md-12
                $s .= '</div>';
                // col-md-12 ui-widget ui-helper-clearfix
            }
            if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
                $s .= '</div>';
                //drag_question
            }
            $s .= '</div>';
            //question_options row
            // destruction of the Answer object
            unset($objAnswerTmp);
            // destruction of the Question object
            unset($objQuestionTmp);
            if ($origin != 'export') {
                echo $s;
            } else {
                return $s;
            }
        } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
            global $exerciseId, $exe_id;
            // 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) {
                echo "\n                    <script>\n                        \$(document).on('ready', function () {\n                            new " . ($answerType == HOT_SPOT ? "HotspotQuestion" : "DelineationQuestion") . "({\n                                questionId: {$questionId},\n                                exerciseId: {$exerciseId},\n                                selector: '#hotspot-preview-{$questionId}',\n                                for: 'preview'\n                            });\n                        });\n                    </script>\n                    <div id=\"hotspot-preview-{$questionId}\"></div>\n                ";
                return;
            }
            // Get the answers, make a list
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            // get answers of hotpost
            $answers_hotspot = array();
            for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                $answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId));
                $answers_hotspot[$answers['id']] = $objAnswerTmp->selectAnswer($answerId);
            }
            $answerList = '';
            if ($answerType != HOT_SPOT_DELINEATION) {
                $answerList = '
                    <div class="well well-sm">
                        <h5 class="page-header">' . get_lang('HotspotZones') . '</h5>
                        <ol>
                ';
                if (!empty($answers_hotspot)) {
                    ksort($answers_hotspot);
                    $countAnswers = 1;
                    foreach ($answers_hotspot as $value) {
                        $answerList .= "<li><p>{$countAnswers} - {$value}</p></li>";
                        $countAnswers++;
                    }
                }
                $answerList .= '
                        </ol>
                    </div>
                ';
            }
            if (!$only_questions) {
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo '<div class="question_title">' . $current_item . '. ' . $questionName . '</div>';
                }
                //@todo I need to the get the feedback type
                echo <<<HOTSPOT
                    <input type="hidden" name="hidden_hotspot_id" value="{$questionId}" />
                    <div class="exercise_questions">
                        {$questionDescription}
                        <div class="row">
HOTSPOT;
            }
            $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
            $s .= "\n                            <div class=\"col-sm-8 col-md-9\">\n                                <div class=\"hotspot-image\"></div>\n                                <script>\n                                    \$(document).on('ready', function () {\n                                        new " . ($answerType == HOT_SPOT_DELINEATION ? 'DelineationQuestion' : 'HotspotQuestion') . "({\n                                            questionId: {$questionId},\n                                            exerciseId: {$exe_id},\n                                            selector: '#question_div_' + {$questionId} + ' .hotspot-image',\n                                            for: 'user'\n                                        });\n                                    });\n                                </script>\n                            </div>\n                            <div class=\"col-sm-4 col-md-3\">\n                                {$answerList}\n                            </div>\n            ";
            echo <<<HOTSPOT
                            {$s}
                        </div>
                    </div>
HOTSPOT;
        }
        return $nbrAnswers;
    }
Ejemplo n.º 18
0
 /**
  * This is the main function that displays the list or the table with all
  * the glossary terms
  * @param  string  View ('table' or 'list'). Optional parameter.
  * Defaults to 'table' and prefers glossary_view from the session by default.
  * @return void
  * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
  * @version januari 2009, dokeos 1.8.6
  */
 public static function display_glossary($view = 'table')
 {
     // This function should always be called with the corresponding
     // parameter for view type. Meanwhile, use this cheap trick.
     $glossaryView = Session::read('glossary_view');
     if (empty($glossaryView)) {
         Session::write('glossary_view', $view);
     }
     // action links
     //echo '<div class="actions">';
     $actionsLeft = '';
     if (api_is_allowed_to_edit(null, true)) {
         $actionsLeft .= '<a href="index.php?' . api_get_cidreq() . '&action=addglossary&msg=add?' . api_get_cidreq() . '">' . Display::return_icon('new_glossary_term.png', get_lang('TermAddNew'), '', ICON_SIZE_MEDIUM) . '</a>';
     }
     $actionsLeft .= '<a href="index.php?' . api_get_cidreq() . '&action=export">' . Display::return_icon('export_csv.png', get_lang('ExportGlossaryAsCSV'), '', ICON_SIZE_MEDIUM) . '</a>';
     if (api_is_allowed_to_edit(null, true)) {
         $actionsLeft .= '<a href="index.php?' . api_get_cidreq() . '&action=import">' . Display::return_icon('import_csv.png', get_lang('ImportGlossary'), '', ICON_SIZE_MEDIUM) . '</a>';
     }
     $actionsLeft .= '<a href="index.php?' . api_get_cidreq() . '&action=export_to_pdf">' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM) . '</a>';
     if (isset($_SESSION['glossary_view']) && $_SESSION['glossary_view'] == 'table' or !isset($_SESSION['glossary_view'])) {
         $actionsLeft .= '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=list">' . Display::return_icon('view_detailed.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM) . '</a>';
     } else {
         $actionsLeft .= '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=table">' . Display::return_icon('view_text.png', get_lang('TableView'), '', ICON_SIZE_MEDIUM) . '</a>';
     }
     /* BUILD SEARCH FORM */
     $form = new FormValidator('search', 'get', api_get_self() . '?' . api_get_cidreq(), '', array(), FormValidator::LAYOUT_INLINE);
     $form->addText('keyword', '', false, array('class' => 'col-md-2'));
     $form->addElement('hidden', 'cidReq', api_get_course_id());
     $form->addElement('hidden', 'id_session', api_get_session_id());
     $form->addButtonSearch(get_lang('Search'));
     $actionsRight = $form->returnForm();
     $toolbar = Display::toolbarAction('toolbar-document', array(0 => $actionsLeft, 1 => $actionsRight));
     echo $toolbar;
     if ($glossaryView == 'table') {
         $table = new SortableTable('glossary', array('GlossaryManager', 'get_number_glossary_terms'), array('GlossaryManager', 'get_glossary_data'), 0);
         //$table->set_header(0, '', false);
         $table->set_header(0, get_lang('TermName'), true);
         $table->set_header(1, get_lang('TermDefinition'), true);
         if (api_is_allowed_to_edit(null, true)) {
             $table->set_header(2, get_lang('Actions'), false, 'width=90px', array('class' => 'td_actions'));
             $table->set_column_filter(2, array('GlossaryManager', 'actions_filter'));
         }
         $table->display();
     }
     if ($glossaryView == 'list') {
         GlossaryManager::display_glossary_list();
     }
 }
Ejemplo n.º 19
0
    });
});
</script>';
$actions = '';
$usergroup = new UserGroup();
if (api_is_allowed_to_edit()) {
    $actions .= '<div class="actions">';
    if ($type == 'registered') {
        $actions .= '<a href="class.php?' . api_get_cidreq() . '&type=not_registered">' . Display::return_icon('add-class.png', get_lang("AddClassesToACourse"), array(), ICON_SIZE_MEDIUM) . '</a>';
    } else {
        $actions .= '<a href="class.php?' . api_get_cidreq() . '&type=registered">' . Display::return_icon('back.png', get_lang("Classes"), array(), ICON_SIZE_MEDIUM) . '</a>';
        $form = new FormValidator('groups', 'post', api_get_self(), '', '', FormValidator::LAYOUT_INLINE);
        $options = [-1 => get_lang('All'), 1 => get_lang('SocialGroups'), 0 => get_lang('Classes')];
        $form->addSelect('group_filter', get_lang('Groups'), $options, ['id' => 'group_filter']);
        $form->setDefaults(['group_filter' => $groupFilter]);
        $actions .= $form->returnForm();
    }
    $actions .= '</div>';
}
if (api_is_allowed_to_edit()) {
    $action = isset($_GET['action']) ? $_GET['action'] : null;
    switch ($action) {
        case 'add_class_to_course':
            $id = $_GET['id'];
            if (!empty($id)) {
                $usergroup->subscribe_courses_to_usergroup($id, array(api_get_course_int_id()), false);
                Display::addFlash(Display::return_message(get_lang('Added')));
            }
            break;
        case 'remove_class_from_course':
            $id = $_GET['id'];
Ejemplo n.º 20
0
            /*
             $('.delete-rule').on('click', function(){
             console.log('deleted');
             $('.input-elm').each(function(){
             $(this).find('option:first').attr('selected', 'selected');
             });
             });*/
        });
    </script>
    <div class="actions">
<?php 
echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'session/session_add.php">' . Display::return_icon('new_session.png', get_lang('AddSession'), '', ICON_SIZE_MEDIUM) . '</a>';
if (api_is_platform_admin()) {
    echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'session/add_many_session_to_category.php">' . Display::return_icon('session_to_category.png', get_lang('AddSessionsInCategories'), '', ICON_SIZE_MEDIUM) . '</a>';
    echo '<a href="' . api_get_path(WEB_CODE_PATH) . 'session/session_category_list.php">' . Display::return_icon('folder.png', get_lang('ListSessionCategory'), '', ICON_SIZE_MEDIUM) . '</a>';
}
if ($list_type == 'complete') {
    echo '<a href="' . api_get_self() . '?list_type=simple">' . Display::return_icon('view_remove.png', get_lang('Simple'), '', ICON_SIZE_MEDIUM) . '</a>';
} else {
    echo '<a href="' . api_get_self() . '?list_type=complete">' . Display::return_icon('view_text.png', get_lang('Complete'), '', ICON_SIZE_MEDIUM) . '</a>';
}
echo $actions;
if (api_is_platform_admin()) {
    echo '<div class="pull-right">';
    echo $sessionFilter->returnForm();
    echo '</div>';
}
echo '</div>';
echo Display::grid_html('sessions');
Display::display_footer();
Ejemplo n.º 21
0
 /**
  * @param $id
  * @param array $params
  * @return string
  */
 public static function generate_message_form($id, $params = array())
 {
     $form = new FormValidator('send_message');
     $form->addText('subject', get_lang('Subject'), false, ['id' => 'subject_id']);
     $form->addTextarea('content', get_lang('Message'), ['id' => 'content_id', 'rows' => '5']);
     return $form->returnForm();
 }
 /**
  * Gets attendance base in the table:
  * TABLE_STATISTIC_TRACK_E_COURSE_ACCESS
  * @param bool $showForm
  * @throws ViewException
  */
 public function getAttendanceBaseInLogin($showForm = false, $exportToPdf = true)
 {
     $table = null;
     $formToDisplay = null;
     $startDate = null;
     $endDate = null;
     $sessionId = api_get_session_id();
     if ($showForm) {
         $form = new FormValidator('search', 'post', api_get_self() . '?' . api_get_cidreq() . '&action=calendar_logins');
         $form->addDateRangePicker('range', get_lang('DateRange'));
         $form->addButton('submit', get_lang('Submit'));
         if ($form->validate()) {
             $values = $form->getSubmitValues();
             $startDate = api_get_utc_datetime($values['range_start']);
             $endDate = api_get_utc_datetime($values['range_end']);
         }
         $formToDisplay = $form->returnForm();
     } else {
         if (!empty($sessionId)) {
             $sessionInfo = api_get_session_info($sessionId);
             $startDate = $sessionInfo['access_start_date'];
             $endDate = $sessionInfo['access_end_date'];
         }
     }
     $attendance = new Attendance();
     if ($exportToPdf) {
         $result = $attendance->exportAttendanceLogin($startDate, $endDate);
         if (empty($result)) {
             api_not_allowed(true, get_lang('NoDataAvailable'));
         }
     }
     $table = $attendance->getAttendanceLoginTable($startDate, $endDate);
     $data = array('form' => $formToDisplay, 'table' => $table);
     $this->view->set_data($data);
     $this->view->set_layout('layout');
     $this->view->set_template('calendar_logins');
     $this->view->render();
 }
Ejemplo n.º 23
0
 }
 if (isset($_REQUEST['filter'])) {
     if (in_array($_REQUEST['filter'], array_keys($values))) {
         $default_filter = $_REQUEST['filter'];
     }
 } else {
     $default_filter = 'today';
 }
 $renderer = $form->defaultRenderer();
 $renderer->setCustomElementTemplate('<div class="col-md-2">{label}</div><div class="col-md-10"> {element} </div>');
 $form->setDefaults(array('filter' => $default_filter, 'group_id' => $groupId));
 if (!$is_locked_attendance || api_is_platform_admin()) {
     $actionsLeft = '<a style="float:left;" href="index.php?' . api_get_cidreq() . '&action=calendar_list&attendance_id=' . $attendance_id . '">' . Display::return_icon('attendance_calendar.png', get_lang('AttendanceCalendar'), '', ICON_SIZE_MEDIUM) . '</a>';
     $actionsLeft .= '<a id="pdf_export" style="float:left;"  href="index.php?' . api_get_cidreq() . '&action=attendance_sheet_export_to_pdf&attendance_id=' . $attendance_id . '&filter=' . $default_filter . '&group_id=' . $groupId . '">' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM) . '</a>';
     //if (count($users_in_course) > 0) {
     $actionsRight = $form->returnForm();
     //}
     $toolbar = Display::toolbarAction('toolbar-attendance', array(0 => $actionsLeft, 1 => $actionsRight), 2, false);
     echo $toolbar;
 }
 $message_information = get_lang('AttendanceSheetDescription');
 if (!empty($message_information)) {
     $message = '<strong>' . get_lang('Information') . '</strong><br />';
     $message .= $message_information;
     Display::display_normal_message($message, false);
 }
 if ($is_locked_attendance) {
     Display::display_warning_message(get_lang('TheAttendanceSheetIsLocked'), false);
 }
 $param_filter = '&filter=' . Security::remove_XSS($default_filter) . '&group_id=' . $groupId;
 if (count($users_in_course) > 0) {
Ejemplo n.º 24
0
            $messageTemplate = new Template();
            $messageTemplate->assign('user', $userInfo);
            $messageTemplate->assign('sale', ['date' => api_format_date($sale['date'], DATE_FORMAT_LONG_NO_DAY), 'product' => $sale['product_name'], 'currency' => $currency['iso_code'], 'price' => $sale['price'], 'reference' => $sale['reference']]);
            $messageTemplate->assign('transfer_accounts', $transferAccounts);
            api_mail_html($userInfo['complete_name'], $userInfo['email'], $plugin->get_lang('bc_subject'), $messageTemplate->fetch('buycourses/view/message_transfer.tpl'));
            Display::addFlash(Display::return_message(sprintf($plugin->get_lang('PurchaseStatusX'), $plugin->get_lang('PendingReasonByTransfer')), 'success', false));
            unset($_SESSION['bc_sale_id']);
            header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/course_catalog.php');
            exit;
        }
        $form->addButton('confirm', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
        $form->addButtonCancel($plugin->get_lang('CancelOrder'), 'cancel');
        $template = new Template();
        if ($buyingCourse) {
            $template->assign('course', $course);
        } elseif ($buyingSession) {
            $template->assign('session', $session);
        }
        $template->assign('buying_course', $buyingCourse);
        $template->assign('buying_session', $buyingSession);
        $template->assign('title', $sale['product_name']);
        $template->assign('price', $sale['price']);
        $template->assign('currency', $sale['currency_id']);
        $template->assign('user', $userInfo);
        $template->assign('transfer_accounts', $transferAccounts);
        $template->assign('form', $form->returnForm());
        $content = $template->fetch('buycourses/view/process_confirm.tpl');
        $template->assign('content', $content);
        $template->display_one_col_template();
        break;
}
Ejemplo n.º 25
0
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
switch ($action) {
    case 'remove_skill':
        $new_skill = array();
        foreach ($skills as $skill_id) {
            if ($id != $skill_id) {
                $new_skill[] = $skill_id;
            }
        }
        $skills = $new_skill;
        Session::write('skills', $skills);
        break;
    case 'load_profile':
        $skill_profile = new SkillRelProfile();
        $skills = $skill_profile->get_skills_by_profile($id);
        $total_skills_to_search = $skill->get_skills_info($skills);
        break;
}
$skill_list = array();
foreach ($total_skills_to_search as $skill_info) {
    $skill_list[$skill_info['id']] = $skill_info;
}
$tpl->assign('skill_list', $skill_list);
$tpl->assign('search_skill_list', $skills);
$form_to_html = $form->returnForm();
$tpl->assign('form', $form_to_html);
$tpl->assign('url', $url);
$content = $tpl->fetch('default/skill/profile.tpl');
$tpl->assign('content', $content);
$tpl->display_one_col_template();
Ejemplo n.º 26
0
 /**
  * @return string
  */
 public function displayLoginForm()
 {
     $form = new FormValidator('formLogin', 'POST', null, null, null, FormValidator::LAYOUT_BOX_NO_LABEL);
     $form->addText('login', get_lang('UserName'), true, array('id' => 'login', 'autofocus' => 'autofocus', 'icon' => 'user fa-fw', 'placeholder' => get_lang('UserName')));
     $form->addElement('password', 'password', get_lang('Pass'), array('id' => 'password', 'icon' => 'lock fa-fw', 'placeholder' => get_lang('Pass')));
     // Captcha
     $captcha = api_get_setting('allow_captcha');
     $allowCaptcha = $captcha == 'true';
     if ($allowCaptcha) {
         $useCaptcha = isset($_SESSION['loginFailed']) ? $_SESSION['loginFailed'] : null;
         if ($useCaptcha) {
             $ajax = api_get_path(WEB_AJAX_PATH) . 'form.ajax.php?a=get_captcha';
             $options = array('width' => 250, 'height' => 90, 'callback' => $ajax . '&var=' . basename(__FILE__, '.php'), 'sessionVar' => basename(__FILE__, '.php'), 'imageOptions' => array('font_size' => 20, 'font_path' => api_get_path(SYS_FONTS_PATH) . 'opensans/', 'font_file' => 'OpenSans-Regular.ttf'));
             // Minimum options using all defaults (including defaults for Image_Text):
             //$options = array('callback' => 'qfcaptcha_image.php');
             $captcha_question = $form->addElement('CAPTCHA_Image', 'captcha_question', '', $options);
             $form->addHtml(get_lang('ClickOnTheImageForANewOne'));
             $form->addElement('text', 'captcha', get_lang('EnterTheLettersYouSee'));
             $form->addRule('captcha', get_lang('EnterTheCharactersYouReadInTheImage'), 'required', null, 'client');
             $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question);
         }
     }
     $form->addButton('submitAuth', get_lang('LoginEnter'), null, 'primary', null, 'btn-block');
     $html = $form->returnForm();
     if (api_get_setting('openid_authentication') == 'true') {
         include_once 'main/auth/openid/login.php';
         $html .= '<div>' . openid_form() . '</div>';
     }
     return $html;
 }
Ejemplo n.º 27
0
    $extraContentForm = new FormValidator('block_extra_data', 'post', '#', null, array('id' => 'block-extra-data', 'class' => ''), FormValidator::LAYOUT_BOX_NO_LABEL);
    $extraContentFormRenderer = $extraContentForm->getDefaultRenderer();
    if ($extraContentForm->validate()) {
        $extraData = $extraContentForm->getSubmitValues();
        $extraData = array_map(['Security', 'remove_XSS'], $extraData);
        if (!empty($extraData['block'])) {
            if (!is_dir($adminExtraContentDir)) {
                mkdir($adminExtraContentDir, api_get_permissions_for_new_directories(), true);
            }
            if (!is_writable($adminExtraContentDir)) {
                die;
            }
            $fullFilePath = $adminExtraContentDir . $extraData['block'];
            $fullFilePath .= "_extra.html";
            file_put_contents($fullFilePath, $extraData['extra_content']);
            Header::location(api_get_self());
        }
    }
    $extraContentForm->addTextarea('extra_content', null, ['id' => 'extra_content']);
    $extraContentFormRenderer->setElementTemplate('<div class="form-group">{element}</div>', 'extra_content');
    $extraContentForm->addElement('hidden', 'block', null, array('id' => 'extra-block'));
    $extraContentForm->addButtonExport(get_lang('Save'), 'submit_extra_content');
    $tpl->assign('extraDataForm', $extraContentForm->returnForm());
}
// The template contains the call to the AJAX version checker
$admin_template = $tpl->get_template('admin/settings_index.tpl');
$content = $tpl->fetch($admin_template);
$tpl->assign('content', $content);
$tpl->assign('message', $message);
$tpl->display_one_col_template();
// Note: version checking mechanism has now been moved to main/inc/ajax/admin.ajax.php
Ejemplo n.º 28
0
                $form_data['action'] = api_get_path(WEB_PATH) . 'user_portal.php';
            }
            $form_data['button'] = Display::button('next', get_lang('Next', null, $_user['language']), array('class' => 'btn btn-primary btn-large'));
        }
    }
    $form_data = CourseManager::redirectToCourse($form_data);
    $form_register = new FormValidator('form_register', 'post', $form_data['action']);
    if (!empty($form_data['message'])) {
        $form_register->addElement('html', $form_data['message'] . '<br /><br />');
    }
    if ($usersCanCreateCourse) {
        $form_register->addElement('html', $form_data['button']);
    } else {
        $form_register->addElement('html', $form_data['go_button']);
    }
    $text_after_registration .= $form_register->returnForm();
    // Just in case
    Session::erase('course_redirect');
    Session::erase('exercise_redirect');
    if (CustomPages::enabled()) {
        CustomPages::display(CustomPages::REGISTRATION_FEEDBACK, array('info' => $text_after_registration));
    } else {
        //$tpl = new Template($tool_name);
        echo Container::getTemplating()->render('@template_style/auth/inscription.html.twig', ['inscription_content' => $content, 'text_after_registration' => $text_after_registration, 'hide_header' => $hideHeaders]);
    }
} else {
    // Custom pages
    if (CustomPages::enabled()) {
        CustomPages::display(CustomPages::REGISTRATION, array('form' => $form));
    } else {
        if (!api_is_anonymous()) {
Ejemplo n.º 29
0
function manage_form($default, $select_from_user_list = null, $sent_to = null)
{
    $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
    $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
    $param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null;
    $form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data'));
    if (empty($group_id)) {
        if (isset($select_from_user_list)) {
            $form->addText('id_text_name', get_lang('SendMessageTo'), true, array('id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off'));
            $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required');
            $form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" >&nbsp;</div>');
            $form->addElement('hidden', 'user_list', 0, array('id' => 'user_list'));
        } else {
            if (!empty($sent_to)) {
                $form->addLabel(get_lang('SendMessageTo'), $sent_to);
            }
            if (empty($default['users'])) {
                //fb select
                $form->addElement('select_ajax', 'users', get_lang('SendMessageTo'), array(), ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users']);
            } else {
                $form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user'));
            }
        }
    } else {
        $userGroup = new UserGroup();
        $group_info = $userGroup->get($group_id);
        $form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name']));
        $form->addElement('hidden', 'group_id', $group_id);
        $form->addElement('hidden', 'parent_id', $message_id);
    }
    $form->addText('title', get_lang('Subject'), true);
    $form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250'));
    if (isset($_GET['re_id'])) {
        $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
        $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title'];
        $form->addElement('hidden', 're_id', intval($_GET['re_id']));
        $form->addElement('hidden', 'save_form', 'save_form');
        //adding reply mail
        $user_reply_info = api_get_user_info($message_reply_info['user_sender_id']);
        $default['content'] = '<p><br/></p>' . sprintf(get_lang('XWroteY'), $user_reply_info['complete_name'], Security::filter_terms($message_reply_info['content']));
    }
    if (empty($group_id)) {
        $form->addElement('label', '', '<div  id="filepaths" class="form-group">
                    <div id="filepath_1">
                    <label>' . get_lang('FilesAttachment') . '</label>
                    <input type="file" name="attach_1"/>
                    <label>' . get_lang('Description') . '</label>
                    <input id="file-descrtiption" type="text" name="legend[]" class="form-control"/>
                    </div>
                </div>');
        $form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span>&nbsp;(' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message.message_max_upload_filesize'))) . ')');
    }
    $form->addButtonSend(get_lang('SendMessage'), 'compose');
    $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
    if (!empty($group_id) && !empty($message_id)) {
        $message_info = MessageManager::get_message_by_id($message_id);
        $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title'];
    }
    $form->setDefaults($default);
    $html = '';
    if ($form->validate()) {
        $check = Security::check_token('post');
        if ($check) {
            $user_list = $default['users'];
            $file_comments = $_POST['legend'];
            $title = $default['title'];
            $content = $default['content'];
            $group_id = isset($default['group_id']) ? $default['group_id'] : null;
            $parent_id = isset($default['parent_id']) ? $default['parent_id'] : null;
            if (is_array($user_list) && count($user_list) > 0) {
                //all is well, send the message
                foreach ($user_list as $user) {
                    $res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id);
                    if ($res) {
                        $html .= MessageManager::display_success_message($user);
                    }
                }
            } else {
                Display::display_error_message('ErrorSendingMessage');
            }
        }
        Security::clear_token();
    } else {
        $token = Security::get_token();
        $form->addElement('hidden', 'sec_token');
        $form->setConstants(array('sec_token' => $token));
        $html .= $form->returnForm();
    }
    return $html;
}
Ejemplo n.º 30
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']);
$form->setDefaults(['name' => $userInfo['complete_name'], 'username' => $userInfo['username'], 'email' => $userInfo['email']]);
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
// View
$templateName = $plugin->get_lang('PaymentMethods');
$interbreadcrumb[] = array("url" => "course_catalog.php", "name" => $plugin->get_lang('CourseListOnSale'));
$tpl = new Template($templateName);
$tpl->assign('buying_course', $buyingCourse);
$tpl->assign('buying_session', $buyingSession);
$tpl->assign('user', api_get_user_info());
$tpl->assign('form', $form->returnForm());
if ($buyingCourse) {
    $tpl->assign('course', $courseInfo);
} elseif ($buyingSession) {
    $tpl->assign('session', $sessionInfo);
}
$content = $tpl->fetch('buycourses/view/process.tpl');
$tpl->assign('content', $content);
$tpl->display_one_col_template();