Пример #1
0
function coursereport()
{
    global $nquest;
    global $course_score, $course_score_max;
    global $test_title;
    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();
    $tests = 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)) {
        switch ($info_report['source_of']) {
            case "test":
                $id_test[] = $info_report['id_source'];
                break;
        }
    }
    $id_user = getLogUserId();
    if (count($id_test)) {
        $title = $GLOBALS['course_descriptor']->getValue('name');
        $username = Docebo::user()->getUserName();
        $GLOBALS['page']->add(getTitleArea($lang->def('_GRADEBOOK_AREATITLE'), 'gradebook') . '<div class="std_block">' . '<div class="print">' . '<a href="#" onclick="window.print(); return false;">' . '<img src="' . getPathImage() . 'standard/print.gif" alt="' . $lang->def('_PRINT') . '" /> ' . $lang->def('_PRINT') . '</a>' . '</div>' . getBackUi('index.php?modname=gradebook&amp;op=showgrade', $lang->def('_BACK')) . '<div class="title coursereport-title">' . $username . '</div><div class="title coursereport-title">' . $title . '</div>', 'content');
        $GLOBALS['page']->add('<div class="coursereport-div"><table class="coursereport-table">' . '<tr><td><strong>' . $lang->def('_TEST_N') . '</strong></td><td><strong>' . $lang->def('_QUESTION') . '</strong></td><td align="right"><strong>' . $lang->def('_SCORE') . '</strong></td></tr>', 'content');
        $nquest = 0;
        $course_score = 0;
        $course_score_max = 0;
        $j = 0;
        for ($i = 0; $i < count($id_test); $i++) {
            $test_title = $tests_info[$id_test[$i]]['title'];
            $GLOBALS['page']->add('<tr><td colspan="3"><br /><strong>' . $test_title . '</strong></td></tr>', 'content');
            $query_track = "SELECT idTrack FROM " . $GLOBALS['prefix_lms'] . "_testtrack " . "WHERE idTest =" . $id_test[$i] . " AND idUser="******"3" align="right"><strong>' . $lang->def('_TOTAL') . ':&nbsp;' . $course_score . ' ' . $lang->def('_ON') . ' ' . $course_score_max . ' (' . $perc_course_score . '%)</strong> </td></tr>', 'content');
        $GLOBALS['page']->add('</table>', 'content');
        /*
        if ($perc_course_score<75) {
        	$msg_feedback=$lang->def('_COURSE_NOT_OK').' '.$lang->def('_COURSE_CHECK_GRAPH');
        } else {
        	$msg_feedback=$lang->def('_COURSE_OK');
        }
        
        $GLOBALS['page']->add('<p><strong>'.$msg_feedback.'</strong>', 'content');
        */
        $GLOBALS['page']->add('</div>', 'content');
        draw_bar($tests);
        $GLOBALS['page']->add('</div>', 'content');
    }
}
Пример #2
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);
}