3 require_once('../../../config.php');
7 $course=$DB->get_record('course',array('id'=>required_param('course',PARAM_INT)));
9 error('Specified course not found');
12 // Sort (default lastname, optionally firstname)
13 $sort=optional_param('sort','',PARAM_ALPHA);
14 $firstnamesort=$sort=='firstname';
17 $format=optional_param('format','',PARAM_ALPHA);
18 $excel=$format=='excelcsv';
19 $csv=$format=='csv' || $excel;
21 // Whether to show idnumber
22 // TODO: This should really not be using a config option 'intended' for
23 // gradebook, but that option is also used in quiz reports as well. There ought
24 // to be a generic option somewhere.
25 $idnumbers=$CFG->grade_report_showuseridnumber;
27 function csv_quote($value) {
30 $tl=textlib_get_instance();
31 return $tl->convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE');
33 return '"'.str_replace('"',"'",$value).'"';
37 require_login($course->id);
39 // Check basic permission
40 $context=get_context_instance(CONTEXT_COURSE,$course->id);
41 require_capability('moodle/course:viewprogress',$context);
44 $group=groups_get_course_group($course,true); // Supposed to verify group
45 if($group===0 && $course->groupmode==SEPARATEGROUPS) {
46 require_capability('moodle/site:accessallgroups',$context);
49 // Get data on activities and progress of all users, and give error if we've
50 // nothing to display (no users or no activities)
51 $reportsurl=$CFG->wwwroot.'/course/report.php?id='.$course->id;
52 $completion=new completion_info($course);
53 $activities=$completion->get_activities();
54 if(count($activities)==0) {
55 print_error('err_noactivities','completion',$reportsurl);
57 $progress=$completion->get_progress_all($firstnamesort,$group);
61 header('Content-Disposition: attachment; filename=progress.'.
62 preg_replace('/[^a-z0-9-]/','_',strtolower($course->shortname)).'.csv');
63 // Unicode byte-order mark for Excel
65 header('Content-Type: text/csv; charset=UTF-16LE');
66 print chr(0xFF).chr(0xFE);
70 header('Content-Type: text/csv; charset=UTF-8');
75 // Use SVG to draw sideways text if supported
76 $svgcleverness=ajaxenabled(array('Firefox'=>2.0)) && !$USER->screenreader;
78 // Navigation and header
79 $strreports = get_string("reports");
80 $strcompletion = get_string('completionreport','completion');
82 $navlinks[] = array('name' => $strreports, 'link' => "../../report.php?id=$course->id", 'type' => 'misc');
83 $navlinks[] = array('name' => $strcompletion, 'link' => null, 'type' => 'misc');
85 require_js(array('yui_yahoo','yui_event','yui_dom'));
87 print_header($strcompletion,$course->fullname,build_navigation($navlinks));
89 print '<script type="text/javascript" src="textrotate.js"></script>';
92 // Handle groups (if enabled)
93 groups_print_course_menu($course,$CFG->wwwroot.'/course/report/progress/?course='.$course->id);
96 // Okay, let's draw the table of progress info,
100 print '<br class="clearer"/>'; // ugh
101 if(count($progress)==0) {
102 print '<p class="nousers">'.get_string('err_nousers','completion').'</p>';
103 print '<p><a href="'.$reportsurl.'">'.get_string('continue').'</a></p>';
104 print_footer($course);
107 print '<table id="completion-progress" class="generaltable flexible boxaligncenter" style="text-align:left"><tr style="vertical-align:top">';
109 // User heading / sort option
110 print '<th scope="col" class="completion-sortchoice">';
113 get_string('firstname').' / <a href="./?course='.$course->id.'">'.
114 get_string('lastname').'</a>';
116 print '<a href="./?course='.$course->id.'&sort=firstname">'.
117 get_string('firstname').'</a> / '.
118 get_string('lastname');
123 print '<th>'.get_string('idnumber').'</th>';
133 foreach($activities as $activity) {
134 $activity->datepassed = $activity->completionexpected && $activity->completionexpected <= time();
135 $activity->datepassedclass=$activity->datepassed ? 'completion-expired' : '';
137 if($activity->completionexpected) {
138 $datetext=userdate($activity->completionexpected,get_string('strftimedate','langconfig'));
144 print $sep.csv_quote($activity->name).$sep.csv_quote($datetext);
146 print '<th scope="col" class="'.$activity->datepassedclass.'">'.
147 '<a href="'.$CFG->wwwroot.'/mod/'.$activity->modname.
148 '/view.php?id='.$activity->id.'">'.
149 '<img src="'.$CFG->pixpath.'/mod/'.$activity->modname.'/icon.gif" alt="'.
150 get_string('modulename',$activity->modname).'" /> <span class="completion-activityname">'.
151 format_string($activity->name).'</span></a>';
152 if($activity->completionexpected) {
153 print '<div class="completion-expected"><span>'.$datetext.'</span></div>';
166 foreach($progress as $user) {
169 print csv_quote(fullname($user));
171 print $sep.csv_quote($user->idnumber);
174 print '<tr><th scope="row"><a href="'.$CFG->wwwroot.'/user/view.php?id='.
175 $user->id.'&course='.$course->id.'">'.fullname($user).'</a></th>';
177 print '<td>'.htmlspecialchars($user->idnumber).'</td>';
181 // Progress for each activity
182 foreach($activities as $activity) {
184 // Get progress information and state
185 if(array_key_exists($activity->id,$user->progress)) {
186 $progress=$user->progress[$activity->id];
187 $state=$progress->completionstate;
188 $date=userdate($progress->timemodified);
190 $state=COMPLETION_INCOMPLETE;
194 // Work out how it corresponds to an icon
196 ($activity->completion==COMPLETION_TRACKING_AUTOMATIC ? 'auto' : 'manual').
199 case COMPLETION_INCOMPLETE : $completiontype.='n'; break;
200 case COMPLETION_COMPLETE : $completiontype.='y'; break;
201 case COMPLETION_COMPLETE_PASS : $completiontype.='pass'; break;
202 case COMPLETION_COMPLETE_FAIL : $completiontype.='fail'; break;
205 $describe=get_string('completion-alt-'.$completiontype,'completion');
209 $a->user=fullname($user);
210 $a->activity=$activity->name;
211 $fulldescribe=get_string('progress-title','completion',$a);
214 print $sep.csv_quote($describe).$sep.csv_quote($date);
216 print '<td class="completion-progresscell '.$activity->datepassedclass.'">'.
217 '<img src="'.$CFG->pixpath.'/i/completion-'.$completiontype.
218 '.gif" alt="'.$describe.'" title="'.$fulldescribe.'" /></td>';
234 print '<ul class="progress-actions"><li><a href="index.php?course='.$course->id.
235 '&format=csv">'.get_string('csvdownload','completion').'</a></li>
236 <li><a href="index.php?course='.$course->id.'&format=excelcsv">'.
237 get_string('excelcsvdownload','completion').'</a></li></ul>';
239 print_footer($course);