Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/report/overview/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 require_once '../../../config.php';
00019 require_once $CFG->libdir.'/gradelib.php';
00020 require_once $CFG->dirroot.'/grade/lib.php';
00021 require_once $CFG->dirroot.'/grade/report/overview/lib.php';
00022 
00023 $courseid = required_param('id', PARAM_INT);
00024 $userid   = optional_param('userid', $USER->id, PARAM_INT);
00025 
00026 $PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id'=>$courseid)));
00027 
00029 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
00030     print_error('nocourseid');
00031 }
00032 require_login($course);
00033 
00034 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00035 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00036 require_capability('gradereport/overview:view', $context);
00037 
00038 if (empty($userid)) {
00039     require_capability('moodle/grade:viewall', $systemcontext);
00040 
00041 } else {
00042     if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
00043         print_error('invaliduserid');
00044     }
00045 }
00046 
00047 $access = false;
00048 if (has_capability('moodle/grade:viewall', $systemcontext)) {
00049     //ok - can view all course grades
00050     $access = true;
00051 
00052 } else if ($userid == $USER->id and has_capability('moodle/grade:viewall', $context)) {
00053     //ok - can view any own grades
00054     $access = true;
00055 
00056 } else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
00057     //ok - can view own course grades
00058     $access = true;
00059 
00060 } else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) {
00061     // ok - can view grades of this user- parent most probably
00062     $access = true;
00063 }
00064 
00065 if (!$access) {
00066     // no access to grades!
00067     print_error('nopermissiontoviewgrades', 'error',  $CFG->wwwroot.'/course/view.php?id='.$courseid);
00068 }
00069 
00071 $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));
00072 
00074 if (!isset($USER->grade_last_report)) {
00075     $USER->grade_last_report = array();
00076 }
00077 $USER->grade_last_report[$course->id] = 'overview';
00078 
00079 //first make sure we have proper final grades - this must be done before constructing of the grade tree
00080 grade_regrade_final_grades($courseid);
00081 
00082 if (has_capability('moodle/grade:viewall', $systemcontext)) { //Admins will see all student reports
00083     // please note this would be extremely slow if we wanted to implement this properly for all teachers
00084     $groupmode    = groups_get_course_groupmode($course);   // Groups are being used
00085     $currentgroup = groups_get_course_group($course, true);
00086 
00087     if (!$currentgroup) {      // To make some other functions work better later
00088         $currentgroup = NULL;
00089     }
00090 
00091     $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
00092 
00093     if ($isseparategroups and (!$currentgroup)) {
00094         // no separate group access, can view only self
00095         $userid = $USER->id;
00096         $user_selector = false;
00097     } else {
00098         $user_selector = true;
00099     }
00100 
00101     if (empty($userid)) {
00102         // Add tabs
00103         print_grade_page_head($courseid, 'report', 'overview');
00104 
00105         groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
00106 
00107         if ($user_selector) {
00108             $renderer = $PAGE->get_renderer('gradereport_overview');
00109             echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
00110         }
00111         // do not list all users
00112 
00113     } else { // Only show one user's report
00114         $report = new grade_report_overview($userid, $gpr, $context);
00115         print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview'). ' - '.fullname($report->user));
00116         groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
00117 
00118         if ($user_selector) {
00119             $renderer = $PAGE->get_renderer('gradereport_overview');
00120             echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
00121         }
00122 
00123         if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
00124             echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
00125         } else {
00126             if ($report->fill_table()) {
00127                 echo '<br />'.$report->print_table(true);
00128             }
00129         }
00130     }
00131 } else { //Non-admins will see just their own report
00132 
00133     // Create a report instance
00134     $report = new grade_report_overview($userid, $gpr, $context);
00135 
00136     // print the page
00137     print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview'). ' - '.fullname($report->user));
00138 
00139     if ($report->fill_table()) {
00140         echo '<br />'.$report->print_table(true);
00141     }
00142 }
00143 
00144 echo $OUTPUT->footer();
00145 
00146 
 All Data Structures Namespaces Files Functions Variables Enumerations