~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to course/user.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php // $Id: user.php,v 1.66.2.1 2007/02/28 05:36:14 nicolasconnault Exp $
 
1
<?php // $Id: user.php,v 1.75.2.12 2008/12/01 19:20:16 skodak Exp $
2
2
 
3
3
// Display user activity reports for a course
4
4
 
5
5
    require_once("../config.php");
6
6
    require_once("lib.php");
7
7
 
8
 
    $modes = array("outline", "complete", "todaylogs", "alllogs");
9
 
 
10
8
    $id      = required_param('id',PARAM_INT);       // course id
11
9
    $user    = required_param('user',PARAM_INT);     // user id
12
10
    $mode    = optional_param('mode', "todaylogs", PARAM_ALPHA);
13
11
    $page    = optional_param('page', 0, PARAM_INT);
14
12
    $perpage = optional_param('perpage', 100, PARAM_INT);
15
13
 
16
 
    require_login();
17
 
 
18
14
    if (! $course = get_record("course", "id", $id)) {
19
15
        error("Course id is incorrect.");
20
16
    }
23
19
        error("User ID is incorrect");
24
20
    }
25
21
 
26
 
    $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
 
22
    $coursecontext   = get_context_instance(CONTEXT_COURSE, $course->id);
27
23
    $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
28
24
 
29
 
    // if in either context, we can read report, then we can proceed
30
 
    if (!(has_capability('moodle/site:viewreports', $coursecontext) or ($course->showreports and $USER->id == $user->id) or has_capability('moodle/user:viewuseractivitiesreport', $personalcontext))) {
31
 
        error("You are not allowed to look at this page");
32
 
    }
33
 
 
34
 
    add_to_log($course->id, "course", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id"); 
 
25
    require_login();
 
26
    if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and !has_capability('moodle/course:view', $coursecontext)) {
 
27
        // do not require parents to be enrolled in courses ;-)
 
28
        course_setup($course);
 
29
    } else {
 
30
        require_login($course);
 
31
    }
 
32
 
 
33
    if ($user->deleted) {
 
34
        print_header();
 
35
        print_heading(get_string('userdeleted'));
 
36
        print_footer();
 
37
        die;
 
38
    }
 
39
 
 
40
    // prepare list of allowed modes
 
41
    $myreports  = ($course->showreports and $USER->id == $user->id);
 
42
    $anyreport  = has_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
 
43
 
 
44
    $modes = array();
 
45
 
 
46
    if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
 
47
        $modes[] = 'outline';
 
48
    }
 
49
 
 
50
    if ($myreports or $anyreport or has_capability('coursereport/outline:view', $coursecontext)) {
 
51
        $modes[] = 'complete';
 
52
    }
 
53
 
 
54
    if ($myreports or $anyreport or has_capability('coursereport/log:viewtoday', $coursecontext)) {
 
55
        $modes[] = 'todaylogs';
 
56
    }
 
57
 
 
58
    if ($myreports or $anyreport or has_capability('coursereport/log:view', $coursecontext)) {
 
59
        $modes[] = 'alllogs';
 
60
    }
 
61
 
 
62
    if ($myreports or $anyreport or has_capability('coursereport/stats:view', $coursecontext)) {
 
63
        $modes[] = 'stats';
 
64
    }
 
65
 
 
66
    if (has_capability('moodle/grade:viewall', $coursecontext)) {
 
67
        //ok - can view all course grades
 
68
        $modes[] = 'grade';
 
69
 
 
70
    } else if ($course->showgrades and $user->id == $USER->id and has_capability('moodle/grade:view', $coursecontext)) {
 
71
        //ok - can view own grades
 
72
        $modes[] = 'grade';
 
73
 
 
74
    } else if ($course->showgrades and has_capability('moodle/grade:viewall', $personalcontext)) {
 
75
        // ok - can view grades of this user - parent most probably
 
76
        $modes[] = 'grade';
 
77
 
 
78
    } else if ($course->showgrades and $anyreport) {
 
79
        // ok - can view grades of this user - parent most probably
 
80
        $modes[] = 'grade';
 
81
    }
 
82
 
 
83
    if (empty($modes)) {
 
84
        require_capability('moodle/user:viewuseractivitiesreport', $personalcontext);
 
85
    }
 
86
 
 
87
    if (!in_array($mode, $modes)) {
 
88
        // forbidden or non-exitent mode
 
89
        $mode = reset($modes);
 
90
    }
 
91
 
 
92
    add_to_log($course->id, "course", "user report", "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode", "$user->id");
35
93
 
36
94
    $stractivityreport = get_string("activityreport");
37
95
    $strparticipants   = get_string("participants");
42
100
    $strmode           = get_string($mode);
43
101
    $fullname          = fullname($user, true);
44
102
 
45
 
    if ($course->id != SITEID) {
46
 
        print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname,
47
 
                 "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
48
 
                  <a href=\"../user/index.php?id=$course->id\">$strparticipants</a> ->
49
 
                  <a href=\"../user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> -> 
50
 
                  $stractivityreport -> $strmode");
51
 
    } else {
52
 
        print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname,
53
 
                 "<a href=\"../user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a> -> 
54
 
                  $stractivityreport -> $strmode");
 
103
    $navlinks = array();
 
104
 
 
105
    if ($course->id != SITEID && has_capability('moodle/course:viewparticipants', $coursecontext)) {
 
106
        $navlinks[] = array('name' => $strparticipants, 'link' => "../user/index.php?id=$course->id", 'type' => 'misc');
55
107
    }
56
108
 
 
109
    $navlinks[] = array('name' => $fullname, 'link' => "../user/view.php?id=$user->id&amp;course=$course->id", 'type' => 'misc');
 
110
    $navlinks[] = array('name' => $stractivityreport, 'link' => null, 'type' => 'misc');
 
111
    $navlinks[] = array('name' => $strmode, 'link' => null, 'type' => 'misc');
 
112
    $navigation = build_navigation($navlinks);
 
113
 
 
114
    print_header("$course->shortname: $stractivityreport ($mode)", $course->fullname, $navigation);
 
115
 
57
116
 
58
117
/// Print tabs at top
59
118
/// This same call is made in:
64
123
    $showroles = 1;
65
124
    include($CFG->dirroot.'/user/tabs.php');
66
125
 
67
 
    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
68
 
 
69
126
    switch ($mode) {
70
127
        case "grade":
71
 
            $course = get_record('course', 'id', required_param('id', PARAM_INT));
72
 
            if (!empty($course->showgrades)) {
73
 
                require_once($CFG->dirroot.'/grade/lib.php');
74
 
                print_student_grade($user, $course);
 
128
            if (empty($CFG->grade_profilereport) or !file_exists($CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php')) {
 
129
                $CFG->grade_profilereport = 'user';
 
130
            }
 
131
            require_once $CFG->libdir.'/gradelib.php';
 
132
            require_once $CFG->dirroot.'/grade/lib.php';
 
133
            require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php';
 
134
 
 
135
            $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport';
 
136
            if (function_exists($functionname)) {
 
137
                $functionname($course, $user);
75
138
            }
76
139
            break;
77
 
      
 
140
 
78
141
        case "todaylogs" :
79
142
            echo '<div class="graph">';
80
143
            print_log_graph($course, $user->id, "userday.png");
81
144
            echo '</div>';
82
 
            print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage, 
 
145
            print_log($course, $user->id, usergetmidnight(time()), "l.time DESC", $page, $perpage,
83
146
                      "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
84
147
            break;
85
148
 
87
150
            echo '<div class="graph">';
88
151
            print_log_graph($course, $user->id, "usercourse.png");
89
152
            echo '</div>';
90
 
            print_log($course, $user->id, 0, "l.time DESC", $page, $perpage, 
 
153
            print_log($course, $user->id, 0, "l.time DESC", $page, $perpage,
91
154
                      "user.php?id=$course->id&amp;user=$user->id&amp;mode=$mode");
92
155
            break;
93
156
        case 'stats':
106
169
            $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend');
107
170
            $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend');
108
171
            $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend');
109
 
    
 
172
 
110
173
            if (empty($earliestday)) $earliestday = time();
111
174
            if (empty($earliestweek)) $earliestweek = time();
112
175
            if (empty($earliestmonth)) $earliestmonth = time();
113
 
            
 
176
 
114
177
            $now = stats_get_base_daily();
115
178
            $lastweekend = stats_get_base_weekly();
116
179
            $lastmonthend = stats_get_base_monthly();
117
180
 
118
181
            $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
119
182
 
120
 
            if (empty($timeoptions)) { 
121
 
                error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
 
183
            if (empty($timeoptions)) {
 
184
                print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
122
185
            }
123
186
 
124
187
            // use the earliest.
125
188
            $time = array_pop(array_keys($timeoptions));
126
 
            
 
189
 
127
190
            $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED);
128
191
 
129
192
            $param->table = 'user_'.$param->table;
137
200
            $stats = get_records_sql($sql);
138
201
 
139
202
            if (empty($stats)) {
140
 
                error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
 
203
                print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
141
204
            }
142
205
 
143
 
            echo '<center><img src="'.$CFG->wwwroot.'/course/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>';
 
206
            // MDL-10818, do not display broken graph when user has no permission to view graph
 
207
            if ($myreports or has_capability('coursereport/stats:view', $coursecontext)) {
 
208
                echo '<center><img src="'.$CFG->wwwroot.'/course/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>';
 
209
            }
144
210
 
145
211
            // What the heck is this about?   -- MD
146
212
            $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
148
214
            $table = new object();
149
215
            $table->align = array('left','center','center','center');
150
216
            $param->table = str_replace('user_','',$param->table);
151
 
            $table->head = array(get_string('periodending','moodle',$param->table),$param->line1,$param->line2,$param->line3);
 
217
            switch ($param->table) {
 
218
                case 'daily'  : $period = get_string('day'); break;
 
219
                case 'weekly' : $period = get_string('week'); break;
 
220
                case 'monthly': $period = get_string('month', 'form'); break;
 
221
                default : $period = '';
 
222
            }
 
223
            $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3);
152
224
            foreach ($stats as $stat) {
153
225
                if (!empty($stat->zerofixed)) {  // Don't know why this is necessary, see stats_fix_zeros above - MD
154
226
                    continue;
160
232
            }
161
233
            print_table($table);
162
234
            break;
 
235
 
163
236
        case "outline" :
164
237
        case "complete" :
165
 
        default:
 
238
            get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
166
239
            $sections = get_all_sections($course->id);
167
240
 
168
241
            for ($i=0; $i<=$course->numsections; $i++) {
183
256
                                default: print_string("section"); break;
184
257
                            }
185
258
                            echo " $i</h2>";
186
 
    
 
259
 
187
260
                            echo '<div class="content">';
188
261
 
189
262
                            if ($mode == "outline") {
196
269
                                    continue;
197
270
                                }
198
271
                                $mod = $mods[$sectionmod];
199
 
    
 
272
 
200
273
                                if (empty($mod->visible)) {
201
274
                                    continue;
202
275
                                }
223
296
                                                echo "<h4>$image $mod->modfullname: ".
224
297
                                                     "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
225
298
                                                     format_string($instance->name,true)."</a></h4>";
226
 
                                                
 
299
 
227
300
                                                ob_start();
228
301
 
229
302
                                                echo "<ul>";
232
305
 
233
306
                                                $output = ob_get_contents();
234
307
                                                ob_end_clean();
235
 
                                                
 
308
 
236
309
                                                if (str_replace(' ', '', $output) != '<ul></ul>') {
237
310
                                                    echo $output;
238
311
                                                }
241
314
                                        }
242
315
                                    }
243
316
                                }
244
 
    
 
317
 
245
318
                            if ($mode == "outline") {
246
319
                                echo "</table>";
247
320
                            }
252
325
                }
253
326
            }
254
327
            break;
 
328
        default:
 
329
            // can not be reached ;-)
255
330
    }
256
331
 
257
332
 
285
360
}
286
361
 
287
362
?>
288