Example #1
0
function intro($object_test, $id_param)
{
    if (!checkPerm('view', true, 'organization') && !checkPerm('view', true, 'storage')) {
        die("You can't access");
    }
    require_once _base_ . '/lib/lib.form.php';
    require_once $GLOBALS['where_lms'] . '/class.module/track.test.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.param.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.test.php';
    $lang =& DoceboLanguage::createInstance('test');
    $id_test = $object_test->getId();
    $id_reference = getLoParam($id_param, 'idReference');
    $url_coded = urlencode(serialize($object_test->back_url));
    $id_track = retriveTrack($id_reference, $id_test, Docebo::user()->getIdst());
    if ($id_track === false) {
        $GLOBALS['page']->add(getErrorUi($lang->def('_TEST_TRACK_FAILURE') . getBackUi(Util::str_replace_once('&', '&', $object_test->back_url), $lang->def('_BACK'))), 'content');
    }
    $track_info = Track_Test::getTrackInfoById($id_track);
    $test_man = new TestManagement($id_test);
    $play_man = new PlayTestManagement($id_test, Docebo::user()->getIdst(), $id_track, $test_man);
    $test_info = $test_man->getTestAllInfo();
    $prerequisite = $test_man->getPrerequisite();
    $group_test_man = new GroupTestManagement();
    $tests_score =& $group_test_man->getTestsScores(array($id_test), array(Docebo::user()->getIdst()));
    if ($test_info['time_dependent'] && $test_info['time_assigned']) {
        $minute_assigned = (int) ($test_info['time_assigned'] / 60);
        $second_assigned = (int) ($test_info['time_assigned'] % 60);
        if (strlen($second_assigned) == 1) {
            $second_assigned = '0' . $second_assigned;
        }
        $time_readable = str_replace('[time_assigned]', $minute_assigned . ':' . $second_assigned . '', $lang->def('_TEST_TIME_ASSIGNED'));
        $time_readable = str_replace('[second_assigned]', '' . $second_assigned, str_replace('[minute_assigned]', '' . $minute_assigned, $time_readable));
    }
    $page_title = array(Util::str_replace_once('&', '&', $object_test->back_url) => $lang->def('_TITLE'), $test_info['title']);
    $GLOBALS['page']->add(getTitleArea($page_title, 'test', $lang->def('_TEST_INFO')) . '<div class="std_block">' . getBackUi(Util::str_replace_once('&', '&amp;', $object_test->back_url), $lang->def('_BACK')) . '<span class="text_bold">' . $lang->def('_TITLE') . ' : </span>' . $test_info['title'] . '<br /><br />' . ($test_info['description'] != '' ? '<span class="text_bold">' . $lang->def('_DESCRIPTION') . ' : </span>' . $test_info['description'] . '<br /><br />' : '') . (isset($track_info['score']) && $track_info['score'] >= $test_info['point_required'] ? '<span class="text_bold">' . str_replace('[score]', $track_info['score'], $lang->def('_RESTART_INFO')) . '</span><br /><br />' : ''), 'content');
    if ($test_info['hide_info'] == 0) {
        $GLOBALS['page']->add('<span class="text_bold">' . $lang->def('_TEST_INFO') . ' : </span><br />' . '<ul class="test_info_list">', 'content');
        if ($test_info['order_type'] != 2) {
            $GLOBALS['page']->add('<li>' . str_replace('[max_score]', '' . ($test_info['point_type'] != 1 ? $test_man->getMaxScore() : 100), $lang->def('_TEST_MAXSCORE')) . '</li>', 'content');
        }
        $GLOBALS['page']->add('<li>' . str_replace('[question_number]', '' . $test_man->getNumberOfQuestion(), $lang->def('_TEST_QUESTION_NUMBER')) . '</li>', 'content');
        if ($test_info['point_required'] != 0) {
            $GLOBALS['page']->add('<li>' . str_replace('[score_req]', '' . $test_info['point_required'], $lang->def('_TEST_REQUIREDSCORE')) . '</li>', 'content');
        }
        $GLOBALS['page']->add('<li>' . ($test_info['save_keep'] ? $lang->def('_TEST_SAVEKEEP') : $lang->def('_TEST_SAVEKEEP_NO')) . '</li>' . '<li>' . ($test_info['mod_doanswer'] ? $lang->def('_TEST_MOD_DOANSWER') : $lang->def('_TEST_MOD_DOANSWER_NO')) . '</li>' . '<li>' . ($test_info['can_travel'] ? $lang->def('_TEST_CAN_TRAVEL') : $lang->def('_TEST_CAN_TRAVEL_NO')) . '</li>' . '<li>' . ($test_info['show_score'] || $test_info['show_score_cat'] ? $lang->def('_TEST_SHOW_SCORE') : $lang->def('_TEST_SHOW_SCORE_NO')) . '</li>' . '<li>' . ($test_info['show_solution'] ? $lang->def('_TEST_SHOW_SOLUTION') : $lang->def('_TEST_SHOW_SOLUTION_NO')) . '</li>' . '<li>', 'content');
        switch ($test_info['time_dependent']) {
            case 0:
                $GLOBALS['page']->add($lang->def('_TEST_TIME_ASSIGNED_NO'), 'content');
                break;
            case 1:
                $GLOBALS['page']->add($time_readable, 'content');
                break;
            case 2:
                $GLOBALS['page']->add($lang->def('_TEST_TIME_ASSIGNED_QUEST'), 'content');
                break;
        }
        if ($test_info['max_attempt'] > 0) {
            $GLOBALS['page']->add('<li>' . str_replace('[remaining_attempt]', $test_info['max_attempt'] - $track_info['number_of_attempt'], Lang::t('_NUMBER_OF_ATTEMPT', 'test')) . '</li>', 'content');
        }
        $GLOBALS['page']->add('</ul>' . '<br />', 'content');
    }
    if ($tests_score[$id_test][Docebo::user()->getIdst()]['comment'] !== '') {
        $GLOBALS['page']->add('<span class="text_bold">' . $lang->def('_COMMENTS') . ' : </span>' . $tests_score[$id_test][Docebo::user()->getIdst()]['comment'] . '<br /><br />', 'content');
    }
    // Actions
    $score_status = $play_man->getScoreStatus();
    $show_result = $test_info['show_score'] || $test_info['show_score_cat'] || $test_info['show_solution'];
    $is_end = $score_status == 'valid' || $score_status == 'not_checked' || $score_status == 'passed' || $score_status == 'not_passed';
    $GLOBALS['page']->add(Form::openForm('test_intro', 'index.php?modname=test&amp;op=play') . Form::getHidden('id_test', 'id_test', $id_test) . Form::getHidden('id_param', 'id_param', $id_param) . Form::getHidden('idTrack', 'idTrack', $id_track) . Form::getHidden('back_url', 'back_url', $url_coded) . Form::getHidden('next_step', 'next_step', 'play'), 'content');
    if ($test_info['max_attempt'] > 0) {
        if ($test_info['max_attempt'] - $track_info['number_of_attempt'] <= 0) {
            //$GLOBALS['page']->add($lang->def('_MAX_ATTEMPT_REACH'), 'content');
            $GLOBALS['page']->add(Lang::t('_MAX_ATTEMPT_REACH', 'test'), 'content');
            if ($show_result) {
                $GLOBALS['page']->add('<div class="align_right">' . Form::getHidden('show_result', 'show_result', 1) . Form::getButton('show_review', 'show_review', $lang->def('_TEST_SHOW_REVIEW')) . '</div>', 'content');
            }
            $GLOBALS['page']->add(Form::closeForm() . '</div>', 'content');
            return;
        }
        if ($is_end && $track_info['score'] >= $test_info['point_required']) {
            $GLOBALS['page']->add($lang->def('_YOU_HAVE_PASS_THIS_TEST'), 'content');
            if ($show_result) {
                $GLOBALS['page']->add('<div class="align_right">' . Form::getHidden('show_result', 'show_result', 1) . Form::getButton('show_review', 'show_review', $lang->def('_TEST_SHOW_REVIEW')) . '</div>', 'content');
            }
            $GLOBALS['page']->add(Form::closeForm() . '</div>', 'content');
            return;
        }
    }
    //--- check for suspension condition -------------------------------------------
    if ($test_info['use_suspension']) {
        $attempts_until_now = $track_info['attempts_for_suspension'];
        $last_suspension_date = $track_info['suspended_until'];
        if ($last_suspension_date == "") {
            $last_suspension_date = '0000-00-00 00:00:00';
        }
        $now = date("Y-m-d H:i:s");
        //check remaining attempts
        $diff_attempts = $test_info['suspension_num_attempts'] - $attempts_until_now;
        if ($diff_attempts > 0 && ($last_suspension_date < $now || $test_info['suspension_num_hours'] <= 0)) {
            //warning: $diff_attempts remaining before suspesion
            cout(UIFeedback::pnotice($lang->def('_ATTEMPTS_REMAINING_BEFORE_SUSPENSION') . ' : ' . $diff_attempts) . '<br /><br />', 'content');
        } else {
            if ($test_info['suspension_num_hours'] <= 0) {
                cout(UIFeedback::pnotice($lang->def('_TEST_SUSPENDED')) . '<br /><br />', 'content');
                cout(Form::closeForm() . '</div>', 'content');
                return;
            } else {
                //check if last suspension date is prior to now
                if ($last_suspension_date > $now) {
                    //user is suspended for this test until "last_suspension_date"
                    cout(UIFeedback::pnotice($lang->def('_TEST_SUSPENDED_UNTIL') . ' : ' . Format::date($last_suspension_date, "datetime")) . '<br /><br />', 'content');
                    cout(Form::closeForm() . '</div>', 'content');
                    return;
                } else {
                    //we shouldn't get here, except if test options about suspension have been modified
                    //in a second time: in this case update test track data and go on
                    $suspend_info = array('attempts_for_suspension' => 0);
                    $re = Track_Test::updateTrack($id_track, $suspend_info);
                    $diff_attempts = $test_info['suspension_num_attempts'];
                    cout(UIFeedback::pnotice($lang->def('_ATTEMPTS_REMAINING_BEFORE_SUSPENSION') . ' : ' . $diff_attempts) . '<br /><br />', 'content');
                }
            }
        }
        //check if the user should re-play LO in prerequisites
        if ($test_info['suspension_prerequisites']) {
            if ($prerequisite != "") {
                //check all prerequisites conditions
                $query = "SELECT idOrg FROM " . $GLOBALS['prefix_lms'] . "_organization WHERE objectType='test' AND idResource=" . (int) $test_info['idTest'];
                list($idOrg) = sql_fetch_row(sql_query($query));
                $conditions = explode(",", $prerequisite);
                $req_arr = array();
                foreach ($conditions as $condition) {
                    if (is_numeric($condition) && (int) $condition != $idOrg) {
                        $req_arr[] = $condition;
                    }
                }
                if (count($req_arr) > 0) {
                    $query = "SELECT * FROM " . $GLOBALS['prefix_lms'] . "_commontrack WHERE idReference IN (" . implode(",", $req_arr) . ") " . " AND dateAttempt>'" . $last_suspension_date . "' AND status IN ('completed','passed')";
                    $res = sql_query($query);
                    if (sql_num_rows($res) < count($req_arr)) {
                        cout(UIFeedback::pnotice($lang->def('_UNREACHED_PREREQUISITES')) . '<br /><br />', 'content');
                        cout(Form::closeForm() . '</div>', 'content');
                        return;
                    }
                }
            }
        }
    }
    //--- end suspension check -----------------------------------------------------
    if ($score_status == 'passed') {
        $incomplete = FALSE;
    } elseif ($score_status == 'valid') {
        $track_info = $play_man->getTrackAllInfo();
        if ($track_info['score'] >= $test_info['point_required']) {
            $incomplete = FALSE;
        } else {
            $incomplete = TRUE;
        }
    } else {
        $incomplete = TRUE;
    }
    if ($score_status == 'not_complete') {
        $GLOBALS['page']->add(Form::getHidden('page_continue', 'page_continue', $play_man->getLastPageSeen()), 'content');
    }
    if ($is_end) {
        $GLOBALS['page']->add(Form::getHidden('show_result', 'show_result', 1), 'content');
    }
    if ($test_info['save_keep'] && $score_status == 'not_complete') {
        $GLOBALS['page']->add('<span class="text_bold">' . $lang->def('_TEST_SAVED') . '</span><br /><br />', 'content');
    }
    $GLOBALS['page']->add('<div class="align_right">', 'content');
    if ($is_end && $show_result) {
        $GLOBALS['page']->add(Form::getButton('show_review', 'show_review', $lang->def('_TEST_SHOW_REVIEW')), 'content');
    } elseif ($test_info['save_keep'] && $score_status == 'not_complete') {
        $GLOBALS['page']->add(Form::getButton('continue', 'continue', $lang->def('_TEST_CONTINUE')), 'content');
    }
    if ($score_status == 'not_complete') {
        $GLOBALS['page']->add(Form::getButton('restart', 'restart', $lang->def('_TEST_BEGIN')), 'content');
    } elseif ($is_end) {
        if ($_SESSION['levelCourse'] > '3') {
            $GLOBALS['page']->add(Form::getButton('restart', 'restart', $lang->def('_TEST_RESTART')), 'content');
        } elseif (str_replace('incomplete', '', $prerequisite) !== $prerequisite) {
            $incomplete ? $GLOBALS['page']->add(Form::getButton('restart', 'restart', $lang->def('_TEST_RESTART')), 'content') : $GLOBALS['page']->add($lang->def('_TEST_COMPLETED'), 'content');
        } elseif (str_replace('NULL', '', $prerequisite) !== $prerequisite) {
            $score_status !== 'valid' && $score_status !== 'passed' ? $GLOBALS['page']->add(Form::getButton('restart', 'restart', $lang->def('_TEST_RESTART')), 'content') : $GLOBALS['page']->add($lang->def('_TEST_COMPLETED'), 'content');
        } else {
            $GLOBALS['page']->add(Form::getButton('restart', 'restart', $lang->def('_TEST_RESTART')), 'content');
        }
    } else {
        resetTrack($id_test, $id_track);
        $GLOBALS['page']->add(Form::getButton('begin', 'begin', $lang->def('_TEST_BEGIN')), 'content');
    }
    $GLOBALS['page']->add('</div>' . Form::closeForm() . '</div>', 'content');
}