Ejemplo n.º 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');
}
Ejemplo n.º 2
0
function showgrade()
{
    checkPerm('view');
    require_once $GLOBALS['where_lms'] . '/lib/lib.test.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.coursereport.php';
    require_once _base_ . '/lib/lib.table.php';
    $lang =& DoceboLanguage::createInstance('gradebook', 'lms');
    $out =& $GLOBALS['page'];
    $out->setWorkingZone('content');
    $test_man = new GroupTestManagement();
    $report_man = new CourseReportManager();
    // XXX: update if needed
    $org_tests =& $report_man->getTest();
    $tests_info =& $test_man->getTestInfo($org_tests);
    $i_test = array();
    $i_test_report_id = array();
    // XXX: Info for updates
    $query_tot_report = "\r\n\tSELECT COUNT(*)\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\tWHERE id_course = '" . $_SESSION['idCourse'] . "'";
    list($tot_report) = sql_fetch_row(sql_query($query_tot_report));
    $query_tests = "\r\n\tSELECT id_report, id_source\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\tWHERE id_course = '" . $_SESSION['idCourse'] . "' AND source_of = 'test'";
    $re_tests = sql_query($query_tests);
    while (list($id_r, $id_t) = sql_fetch_row($re_tests)) {
        $i_test[$id_t] = $id_t;
        $i_test_report_id[$id_r] = $id_r;
    }
    // XXX: Update if needed
    if ($tot_report == 0) {
        $report_man->initializeCourseReport($org_tests);
    } else {
        if (is_array($i_test)) {
            $test_to_add = array_diff($org_tests, $i_test);
        } else {
            $test_to_add = $org_tests;
        }
        if (is_array($i_test)) {
            $test_to_del = array_diff($i_test, $org_tests);
        } else {
            $test_to_del = $org_tests;
        }
        if (!empty($test_to_add) || !empty($test_to_del)) {
            $report_man->addTestToReport($test_to_add, 1);
            $report_man->delTestToReport($test_to_del);
            $included_test = $org_tests;
        }
    }
    $report_man->updateTestReport($org_tests);
    $reports = array();
    $id_test = array();
    $id_report = array();
    // XXX: retrive all report info
    $query_report = "\r\n\tSELECT id_report, title, max_score, required_score, weight, show_to_user, use_for_final, source_of, id_source\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\tWHERE id_course = '" . $_SESSION['idCourse'] . "' AND show_to_user = '******'\r\n\tORDER BY sequence ";
    $re_report = sql_query($query_report);
    while ($info_report = mysql_fetch_assoc($re_report)) {
        $reports[$info_report['id_report']] = $info_report;
        switch ($info_report['source_of']) {
            case "test":
                $id_test[] = $info_report['id_source'];
                break;
            case "activity":
            case "final_vote":
                $id_report[] = $info_report['id_report'];
                break;
        }
    }
    // XXX: retrive report and test score
    $report_score =& $report_man->getReportsScores($id_report, getLogUserId());
    $tests_score =& $test_man->getTestsScores($id_test, array(getLogUserId()));
    // XXX: create table
    $table = new Table(0, $lang->def('_GRADEBOOK_CAPTION'), $lang->def('_GRADEBOOK_SUMMARY'));
    $type_h = array('', 'align_center', 'align_center', '', '');
    $cont_h = array($lang->def('_TITLE'), $lang->def('_SCORE'), $lang->def('_REQUIRED_SCORE'), $lang->def('_DATE'), $lang->def('_COMMENTS'), $lang->def('_SHOW_RESULTS'));
    $table->setColsStyle($type_h);
    $table->addHead($cont_h);
    $id_user = getLogUserId();
    // XXX: construct table data
    if (!empty($reports)) {
        while (list($id_report, $report_info) = each($reports)) {
            $id_source = $report_info['id_source'];
            $title = strip_tags($report_info['title']);
            $score = '';
            $required = $report_info['required_score'];
            $maxscore = $report_info['max_score'];
            $date = '';
            $comment = '';
            switch ($report_info['source_of']) {
                case "scorm_item":
                    $query_report = "\r\n\t\t\t\t\t\tSELECT *\r\n\t\t\t\t\t\tFROM " . $GLOBALS['prefix_lms'] . "_scorm_tracking\r\n\t\t\t\t\t\tWHERE idscorm_item = '" . $report_info['id_source'] . "' and idUser='******'";
                    $query2 = sql_query($query_report);
                    $query = sql_fetch_assoc($query2);
                    $score = $query['score_raw'];
                    $date = Format::date($query['last_completed'], 'datetime');
                    $comment = "";
                    break;
                case "test":
                    $title = $tests_info[$id_source]['title'];
                    if (isset($tests_score[$id_source][$id_user])) {
                        switch ($tests_score[$id_source][$id_user]['score_status']) {
                            case "not_checked":
                                $score = '<span class="cr_not_check">' . $lang->def('_NOT_CHECKED') . '</span>';
                                break;
                            case "passed":
                                //$score = '<span class="cr_passed">'.$lang->def('_PASSED').'</span>';
                                $score = '<img src="' . getPathImage('fw') . 'emoticons/thumbs_up.gif" alt="' . $lang->def('_PASSED') . '" />&nbsp;' . $tests_score[$id_source][$id_user]['score'];
                                $date = Format::date($tests_score[$id_source][$id_user]['date_attempt']);
                                $comment = $tests_score[$id_source][$id_user]['comment'];
                                break;
                            case "not_passed":
                                //$score = '<span class="cr_not_passed">'.$lang->def('_NOT_PASSED').'</span>';
                                $score = '<img src="' . getPathImage('fw') . 'emoticons/thumbs_down.gif" alt="' . $lang->def('_NOT_PASSED') . '" />&nbsp;' . $tests_score[$id_source][$id_user]['score'];
                                $date = Format::date($tests_score[$id_source][$id_user]['date_attempt']);
                                $comment = $tests_score[$id_source][$id_user]['comment'];
                                break;
                            case "valid":
                                $score = $tests_score[$id_source][$id_user]['score'];
                                if ($score == $report_info['max_score']) {
                                    $score = '<span class="cr_max_score">' . $score . '</span>';
                                } elseif ($score < $report_info['required_score']) {
                                    $score = '<span class="cr_not_passed">' . $score . '</span>';
                                }
                                $date = Format::date($tests_score[$id_source][$id_user]['date_attempt']);
                                $comment = $tests_score[$id_source][$id_user]['comment'];
                                break;
                        }
                    }
                    $link_result = '<a href="index.php?modname=organization&op=test_track&id_user='******'&id_org=' . $id_source . '&back=gradebook">' . '<img src="' . getPathImage() . 'standard/report.png" /></a>';
                    break;
                case "activity":
                    if (isset($report_score[$id_report][$id_user]) && $report_score[$id_report][$id_user]['score_status'] == 'valid') {
                        $score = $report_score[$id_report][$id_user]['score'];
                        if ($score == $report_info['max_score']) {
                            $score = '<span class="cr_max_score">' . $score . '</span>';
                        } elseif ($score < $report_info['required_score']) {
                            $score = '<span class="cr_not_passed">' . $score . '</span>';
                        }
                        $date = Format::date($report_score[$id_report][$id_user]['date_attempt']);
                        $comment = $report_score[$id_report][$id_user]['comment'];
                    }
                    break;
                case "final_vote":
                    $title = strip_tags($lang->def('_FINAL_SCORE'));
                    if (isset($report_score[$id_report][$id_user]) && $report_score[$id_report][$id_user]['score_status'] == 'valid') {
                        $score = $report_score[$id_report][$id_user]['score'];
                        if ($score == $report_info['max_score']) {
                            $score = '<span class="cr_max_score">' . $score . '</span>';
                        } elseif ($score < $report_info['required_score']) {
                            $score = '<span class="cr_not_passed">' . $score . '</span>';
                        }
                        $date = Format::date($report_score[$id_report][$id_user]['date_attempt']);
                        $comment = $report_score[$id_report][$id_user]['comment'];
                    }
                    break;
            }
            $table->addBody(array($title, $score == '' ? $lang->def('_NOT_ASSIGNED') : $score . ' ' . $lang->def('_MAX_DIVISOR') . ' ' . $maxscore, $report_info['source_of'] === 'scorm_item' ? "-" : $required, $date, $comment, $link_result));
        }
    }
    $out->add(getTitleArea($lang->def('_GRADEBOOK_AREATITLE'), 'gradebook') . '<div class="std_block">' . $table->getTable() . '</div>');
}
Ejemplo n.º 3
0
function export()
{
    checkPerm('view');
    require_once $GLOBALS['where_lms'] . '/lib/lib.coursereport.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.test.php';
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.table.php';
    $lang =& DoceboLanguage::createInstance('coursereport', 'lms');
    $out =& $GLOBALS['page'];
    $out->setWorkingZone('content');
    $included_test = array();
    $mod_perm = checkPerm('mod', true);
    $csv = '';
    $acl_man = Docebo::user()->getAclManager();
    $test_man = new GroupTestManagement();
    $report_man = new CourseReportManager();
    $org_tests =& $report_man->getTest();
    $tests_info = $test_man->getTestInfo($org_tests);
    $id_students =& $report_man->getStudentId();
    $students_info =& $acl_man->getUsers($id_students);
    $lang2 =& DoceboLanguage::createInstance('levels', 'lms');
    if (isset($_POST['type_filter'])) {
        $type_filter = $_POST['type_filter'];
    } else {
        $type_filter = false;
    }
    if ($type_filter == "false") {
        $type_filter = false;
    }
    $lev = $type_filter;
    $students = getSubscribedInfo((int) $_SESSION['idCourse'], FALSE, $lev, TRUE, false, false, true);
    $i = 0;
    $students_info = array();
    foreach ($students as $idst => $user_course_info) {
        $students_info[$idst] =& $acl_man->getUser($idst, FALSE);
    }
    $query_tot_report = "\r\n\tSELECT COUNT(*)\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\tWHERE id_course = '" . $_SESSION['idCourse'] . "'";
    list($tot_report) = sql_fetch_row(sql_query($query_tot_report));
    $query_tests = "\r\n\tSELECT id_report, id_source\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\tWHERE id_course = '" . $_SESSION['idCourse'] . "' AND source_of = 'test'";
    $re_tests = sql_query($query_tests);
    while (list($id_r, $id_t) = sql_fetch_row($re_tests)) {
        $included_test[$id_t] = $id_t;
        $included_test_report_id[$id_r] = $id_r;
    }
    if ($tot_report == 0) {
        $report_man->initializeCourseReport($org_tests);
    } else {
        if (is_array($included_test)) {
            $test_to_add = array_diff($org_tests, $included_test);
        } else {
            $test_to_add = $org_tests;
        }
        if (is_array($included_test)) {
            $test_to_del = array_diff($included_test, $org_tests);
        } else {
            $test_to_del = $org_tests;
        }
        if (!empty($test_to_add) || !empty($test_to_del)) {
            $report_man->addTestToReport($test_to_add, 1);
            $report_man->delTestToReport($test_to_del);
            $included_test = $org_tests;
        }
    }
    $report_man->updateTestReport($org_tests);
    $img_mod = '<img src="' . getPathImage() . 'standard/edit.png" alt="' . $lang->def('_MOD') . '" />';
    $cont_h[] = $lang->def('_DETAILS');
    $csv .= '"' . $lang->def('_DETAILS') . '"';
    $a_line_1 = array('');
    $a_line_2 = array('');
    $colums['max_score'] = array($lang->def('_MAX_SCORE'));
    $colums['required_score'] = array($lang->def('_REQUIRED_SCORE'));
    $colums['weight'] = array($lang->def('_WEIGHT'));
    $colums['show_to_user'] = array($lang->def('_SHOW_TO_USER'));
    $colums['use_for_final'] = array($lang->def('_USE_FOR_FINAL'));
    $query_report = "\r\n\tSELECT id_report, title, max_score, required_score, weight, show_to_user, use_for_final, source_of, id_source\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\tWHERE id_course = '" . $_SESSION['idCourse'] . "'\r\n\tORDER BY sequence ";
    $re_report = sql_query($query_report);
    $total_weight = 0;
    $i = 1;
    while ($info_report = sql_fetch_assoc($re_report)) {
        $id = $info_report['id_source'];
        $reports[$info_report['id_report']] = $info_report;
        $reports_id[] = $info_report['id_report'];
        // XXX: set action colums
        switch ($info_report['source_of']) {
            case "test":
                $title = strip_tags($tests_info[$info_report['id_source']]['title']);
                break;
            case "scoitem":
                $title = strip_tags($info_report['title']);
                break;
            case "activity":
                $title = strip_tags($info_report['title']);
                break;
            case "final_vote":
                $title = strip_tags($lang->def('_FINAL_SCORE'));
                break;
        }
        $top = $title;
        $cont_h[] = $top;
        $csv .= ';"' . $top . '"';
        $i++;
        //set info colums
        $colums['max_score'][] = $info_report['max_score'];
        $colums['required_score'][] = $info_report['required_score'];
        $colums['weight'][] = $info_report['weight'];
        $colums['show_to_user'][] = $info_report['show_to_user'] == 'true' ? $lang->def('_YES') : $lang->def('_NO');
        $colums['use_for_final'][] = $info_report['use_for_final'] == 'true' ? $lang->def('_YES') : $lang->def('_NO');
        if ($info_report['use_for_final'] == 'true') {
            $total_weight += $info_report['weight'];
        }
    }
    $csv .= "\n";
    $first = true;
    foreach ($colums['max_score'] as $content) {
        if ($first) {
            $first = false;
            $csv .= '"' . $content . '"';
        } else {
            $csv .= ';"' . $content . '"';
        }
    }
    $csv .= "\n";
    $first = true;
    foreach ($colums['required_score'] as $content) {
        if ($first) {
            $first = false;
            $csv .= '"' . $content . '"';
        } else {
            $csv .= ';"' . $content . '"';
        }
    }
    $csv .= "\n";
    $first = true;
    foreach ($colums['weight'] as $content) {
        if ($first) {
            $first = false;
            $csv .= '"' . $content . '"';
        } else {
            $csv .= ';"' . $content . '"';
        }
    }
    $csv .= "\n";
    $first = true;
    foreach ($colums['show_to_user'] as $content) {
        if ($first) {
            $first = false;
            $csv .= '"' . $content . '"';
        } else {
            $csv .= ';"' . $content . '"';
        }
    }
    $csv .= "\n";
    $first = true;
    foreach ($colums['use_for_final'] as $content) {
        if ($first) {
            $first = false;
            $csv .= '"' . $content . '"';
        } else {
            $csv .= ';"' . $content . '"';
        }
    }
    $csv .= "\n\n\n";
    $first = true;
    foreach ($cont_h as $content) {
        if ($first) {
            $first = false;
            $csv .= '"' . $content . '"';
        } else {
            $csv .= ';"' . $content . '"';
        }
    }
    $csv .= "\n";
    $tests_score =& $test_man->getTestsScores($included_test, $id_students);
    $test_details = array();
    if (is_array($included_test)) {
        while (list($id_test, $users_result) = each($tests_score)) {
            while (list($id_user, $single_test) = each($users_result)) {
                if ($single_test['score_status'] == 'valid') {
                    if (!isset($test_details[$id_test]['max_score'])) {
                        $test_details[$id_test]['max_score'] = $single_test['score'];
                    } elseif ($single_test['score'] > $test_details[$id_test]['max_score']) {
                        $test_details[$id_test]['max_score'] = $single_test['score'];
                    }
                    if (!isset($test_details[$id_test]['min_score'])) {
                        $test_details[$id_test]['min_score'] = $single_test['score'];
                    } elseif ($single_test['score'] < $test_details[$id_test]['min_score']) {
                        $test_details[$id_test]['min_score'] = $single_test['score'];
                    }
                    if (!isset($test_details[$id_test]['num_result'])) {
                        $test_details[$id_test]['num_result'] = 1;
                    } else {
                        $test_details[$id_test]['num_result']++;
                    }
                    if (!isset($test_details[$id_test]['averange'])) {
                        $test_details[$id_test]['averange'] = $single_test['score'];
                    } else {
                        $test_details[$id_test]['averange'] += $single_test['score'];
                    }
                }
            }
        }
        while (list($id_test, $single_detail) = each($test_details)) {
            if (isset($single_detail['num_result'])) {
                $test_details[$id_test]['averange'] /= $test_details[$id_test]['num_result'];
            }
        }
        reset($test_details);
    }
    $reports_score =& $report_man->getReportsScores(isset($included_test_report_id) && is_array($included_test_report_id) ? array_diff($reports_id, $included_test_report_id) : $reports_id);
    $report_details = array();
    while (list($id_report, $users_result) = each($reports_score)) {
        while (list($id_user, $single_report) = each($users_result)) {
            if ($single_report['score_status'] == 'valid') {
                if (!isset($report_details[$id_report]['max_score'])) {
                    $report_details[$id_report]['max_score'] = $single_report['score'];
                } elseif ($single_report['score'] > $report_details[$id_report]['max_score']) {
                    $report_details[$id_report]['max_score'] = $single_report['score'];
                }
                if (!isset($report_details[$id_report]['min_score'])) {
                    $report_details[$id_report]['min_score'] = $single_report['score'];
                } elseif ($single_report['score'] < $report_details[$id_report]['min_score']) {
                    $report_details[$id_report]['min_score'] = $single_report['score'];
                }
                if (!isset($report_details[$id_report]['num_result'])) {
                    $report_details[$id_report]['num_result'] = 1;
                } else {
                    $report_details[$id_report]['num_result']++;
                }
                if (!isset($report_details[$id_report]['averange'])) {
                    $report_details[$id_report]['averange'] = $single_report['score'];
                } else {
                    $report_details[$id_report]['averange'] += $single_report['score'];
                }
            }
        }
    }
    while (list($id_report, $single_detail) = each($report_details)) {
        if (isset($single_detail['num_result'])) {
            $report_details[$id_report]['averange'] /= $report_details[$id_report]['num_result'];
        }
    }
    reset($report_details);
    if (!empty($students_info)) {
        while (list($idst_user, $user_info) = each($students_info)) {
            $user_name = $user_info[ACL_INFO_LASTNAME] . $user_info[ACL_INFO_FIRSTNAME] ? $user_info[ACL_INFO_LASTNAME] . ' ' . $user_info[ACL_INFO_FIRSTNAME] : $acl_man->relativeId($user_info[ACL_INFO_USERID]);
            $csv .= '"' . $user_name . '"';
            foreach ($reports as $id_report => $info_report) {
                switch ($info_report['source_of']) {
                    case "test":
                        $id_test = $info_report['id_source'];
                        if (isset($tests_score[$id_test][$idst_user])) {
                            switch ($tests_score[$id_test][$idst_user]['score_status']) {
                                case "not_complete":
                                    $csv .= ';"-"';
                                    break;
                                case "not_checked":
                                    $csv .= ';"' . $lang->def('_NOT_CHECKED') . '"';
                                    if (!isset($test_details[$id_test]['not_checked'])) {
                                        $test_details[$id_test]['not_checked'] = 1;
                                    } else {
                                        $test_details[$id_test]['not_checked']++;
                                    }
                                    break;
                                case "passed":
                                    $csv .= ';"' . $lang->def('_PASSED') . '"';
                                    if (!isset($test_details[$id_test]['passed'])) {
                                        $test_details[$id_test]['passed'] = 1;
                                    } else {
                                        $test_details[$id_test]['passed']++;
                                    }
                                    break;
                                case "not_passed":
                                    $csv .= ';"' . $lang->def('_NOT_PASSED') . '"';
                                    if (!isset($test_details[$id_test]['not_passed'])) {
                                        $test_details[$id_test]['not_passed'] = 1;
                                    } else {
                                        $test_details[$id_test]['not_passed']++;
                                    }
                                    break;
                                case "valid":
                                    $score = $tests_score[$id_test][$idst_user]['score'];
                                    if ($score >= $info_report['required_score']) {
                                        if ($score == $test_details[$id_test]['max_score']) {
                                            $csv .= ';"' . $score . " " . $tt . '"';
                                        } else {
                                            $csv .= ';"' . " " . $tt . '"';
                                        }
                                        if (!isset($test_details[$id_test]['passed'])) {
                                            $test_details[$id_test]['passed'] = 1;
                                        } else {
                                            $test_details[$id_test]['passed']++;
                                        }
                                    } else {
                                        if ($score == $test_details[$id_test]['max_score']) {
                                            $csv .= ';"' . $score . " " . $tt . '"';
                                        } else {
                                            $csv .= ';"' . $score . " " . $tt . '"';
                                        }
                                        if (!isset($test_details[$id_test]['not_passed'])) {
                                            $test_details[$id_test]['not_passed'] = 1;
                                        } else {
                                            $test_details[$id_test]['not_passed']++;
                                        }
                                    }
                                    if (isset($test_details[$id_test]['varianza']) && isset($test_details[$id_test]['averange'])) {
                                        $test_details[$id_test]['varianza'] += pow($tests_score[$id_test][$idst_user]['score'] - $test_details[$id_test]['averange'], 2);
                                    } else {
                                        $test_details[$id_test]['varianza'] = pow($tests_score[$id_test][$idst_user]['score'] - $test_details[$id_test]['averange'], 2);
                                    }
                                    break;
                                default:
                                    $csv .= ';"-"';
                            }
                        } else {
                            $csv .= ';"-"';
                        }
                        break;
                    case "scoitem":
                        $query_report = "\r\n\t\t\t\t\t\tSELECT *\r\n\t\t\t\t\t\tFROM " . $GLOBALS['prefix_lms'] . "_scorm_tracking\r\n\t\t\t\t\t\tWHERE idscorm_item = '" . $info_report['id_source'] . "' AND idUser = '******'\r\n\t\t\t\t\t\t";
                        $report = sql_fetch_assoc(sql_query($query_report));
                        if ($report['score_raw'] == NULL) {
                            $report['score_raw'] = "-";
                        }
                        $id_track = isset($report['idscorm_tracking']) ? $report['idscorm_tracking'] : 0;
                        $query_report = "\r\n\t\t\t\t\t\tSELECT *\r\n\t\t\t\t\t\tFROM " . $GLOBALS['prefix_lms'] . "_scorm_tracking_history\r\n\t\t\t\t\t\tWHERE idscorm_tracking = '" . $id_track . "'\r\n\t\t\t\t\t\t";
                        $query = sql_query($query_report);
                        $num = sql_num_rows($query);
                        $csv .= ';"' . $report['score_raw'] . '"';
                        break;
                    case "activity":
                    case "final_vote":
                        $id_report = $info_report['id_report'];
                        if (isset($reports_score[$id_report][$idst_user])) {
                            switch ($reports_score[$id_report][$idst_user]['score_status']) {
                                case "not_complete":
                                    $csv .= ';"-"';
                                    break;
                                case "valid":
                                    if ($reports_score[$id_report][$idst_user]['score'] >= $info_report['required_score']) {
                                        if ($reports_score[$id_report][$idst_user]['score'] == $info_report['max_score']) {
                                            $csv .= ';"' . $reports_score[$id_report][$idst_user]['score'] . '"';
                                        } else {
                                            $csv .= ';"' . $reports_score[$id_report][$idst_user]['score'] . '"';
                                        }
                                        // Count passed
                                        if (!isset($report_details[$id_report]['passed'])) {
                                            $report_details[$id_report]['passed'] = 1;
                                        } else {
                                            $report_details[$id_report]['passed']++;
                                        }
                                    } else {
                                        $csv .= ';"' . $reports_score[$id_report][$idst_user]['score'] . '"';
                                        // Count not passed
                                        if (!isset($report_details[$id_report]['not_passed'])) {
                                            $report_details[$id_report]['not_passed'] = 1;
                                        } else {
                                            $report_details[$id_report]['not_passed']++;
                                        }
                                    }
                                    if (isset($report_details[$id_report]['varianza']) && isset($report_details[$id_report]['averange'])) {
                                        $report_details[$id_report]['varianza'] += round(pow($reports_score[$id_report][$idst_user]['score'] - $report_details[$id_report]['averange'], 2), 2);
                                    } else {
                                        $report_details[$id_report]['varianza'] = round(pow($reports_score[$id_report][$idst_user]['score'] - $report_details[$id_report]['averange'], 2), 2);
                                    }
                                    break;
                            }
                        } else {
                            $csv .= ';"-"';
                        }
                        break;
                }
            }
            $csv .= "\n";
        }
    }
    $file_name = date('YmdHis') . '_report_export.csv';
    require_once _base_ . '/lib/lib.download.php';
    sendStrAsFile($csv, $file_name);
}