|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 require('../../config.php'); 00027 require_once($CFG->dirroot.'/report/stats/locallib.php'); 00028 00029 $userid = required_param('id', PARAM_INT); 00030 $courseid = required_param('course', PARAM_INT); 00031 00032 $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST); 00033 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 00034 00035 $coursecontext = context_course::instance($course->id); 00036 $personalcontext = context_user::instance($user->id); 00037 00038 if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) 00039 and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) { 00040 //TODO: do not require parents to be enrolled in courses - this is a hack! 00041 require_login(); 00042 $PAGE->set_course($course); 00043 } else { 00044 require_login($course); 00045 } 00046 00047 if (!report_stats_can_access_user_report($user, $course, true)) { 00048 // this should never happen 00049 error('Can not access user statistics report'); 00050 } 00051 00052 add_to_log($course->id, 'course', 'report stats', "report/stats/user.php?id=$user->id&course=$course->id", $course->id); 00053 00054 $stractivityreport = get_string('activityreport'); 00055 00056 $PAGE->set_pagelayout('admin'); 00057 $PAGE->set_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id)); 00058 $PAGE->navigation->extend_for_user($user); 00059 $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed. 00060 $PAGE->set_title("$course->shortname: $stractivityreport"); 00061 $PAGE->set_heading($course->fullname); 00062 echo $OUTPUT->header(); 00063 00064 00065 if (empty($CFG->enablestats)) { 00066 print_error('statsdisable', 'error'); 00067 } 00068 00069 $statsstatus = stats_check_uptodate($course->id); 00070 if ($statsstatus !== NULL) { 00071 echo $OUTPUT->notification($statsstatus); 00072 } 00073 00074 $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_daily}'); 00075 $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_weekly}'); 00076 $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_monthly}'); 00077 00078 if (empty($earliestday)) { 00079 $earliestday = time(); 00080 } 00081 if (empty($earliestweek)) { 00082 $earliestweek = time(); 00083 } 00084 if (empty($earliestmonth)) { 00085 $earliestmonth = time(); 00086 } 00087 00088 $now = stats_get_base_daily(); 00089 $lastweekend = stats_get_base_weekly(); 00090 $lastmonthend = stats_get_base_monthly(); 00091 00092 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); 00093 00094 if (empty($timeoptions)) { 00095 print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); 00096 } 00097 00098 // use the earliest. 00099 $time = array_pop(array_keys($timeoptions)); 00100 00101 $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED); 00102 $params = $param->params; 00103 00104 $param->table = 'user_'.$param->table; 00105 00106 $sql = 'SELECT timeend,'.$param->fields.' FROM {stats_'.$param->table.'} WHERE ' 00107 .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') 00108 .' userid = '.$user->id.' AND timeend >= '.$param->timeafter .$param->extras 00109 .' ORDER BY timeend DESC'; 00110 $stats = $DB->get_records_sql($sql, $params); //TODO: improve these params!! 00111 00112 if (empty($stats)) { 00113 print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline'); 00114 } 00115 00116 if (!empty($CFG->gdversion)) { 00117 echo '<center><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>'; 00118 } 00119 00120 // What the heck is this about? -- MD 00121 $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3))); 00122 00123 $table = new html_table(); 00124 $table->align = array('left','center','center','center'); 00125 $param->table = str_replace('user_','',$param->table); 00126 switch ($param->table) { 00127 case 'daily' : $period = get_string('day'); break; 00128 case 'weekly' : $period = get_string('week'); break; 00129 case 'monthly': $period = get_string('month', 'form'); break; 00130 default : $period = ''; 00131 } 00132 $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3); 00133 foreach ($stats as $stat) { 00134 if (!empty($stat->zerofixed)) { // Don't know why this is necessary, see stats_fix_zeros above - MD 00135 continue; 00136 } 00137 $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1); 00138 $a[] = $stat->line2; 00139 $a[] = $stat->line3; 00140 $table->data[] = $a; 00141 } 00142 echo html_writer::table($table); 00143 00144 00145 echo $OUTPUT->footer();