~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to user/index.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?PHP // $Id: index.php,v 1.64.4.3 2004/11/03 14:11:52 moodler Exp $
 
1
<?PHP // $Id: index.php,v 1.88.2.3 2005/06/20 03:45:49 defacer Exp $
2
2
 
3
3
//  Lists all the users within a given course
4
4
 
5
 
    require_once("../config.php");
 
5
    require_once('../config.php');
 
6
    require_once($CFG->libdir.'/tablelib.php');
6
7
 
7
8
    define('USER_SMALL_CLASS', 20);   // Below this is considered small
8
9
    define('USER_LARGE_CLASS', 200);  // Above this is considered large
9
 
 
10
 
    require_variable($id);   //course
11
 
    optional_variable($sort, "lastaccess");  //how to sort students
12
 
    optional_variable($dir,"desc");          //how to sort students
13
 
    optional_variable($page, "0");           // which page to show
14
 
    optional_variable($lastinitial, "");     // only show students with this last initial
15
 
    optional_variable($firstinitial, "");    // only show students with this first initial
16
 
    optional_variable($perpage, "20");       // how many per page
17
 
 
18
 
 
19
 
    if (! $course = get_record("course", "id", $id)) {
 
10
    define('DEFAULT_PAGE_SIZE', 20);
 
11
 
 
12
    $id           = required_param('id', PARAM_INT);                          // Course id
 
13
    $group        = optional_param('group', -1, PARAM_INT);                   // Group to show
 
14
    $page         = optional_param('page', 0, PARAM_INT);                     // which page to show
 
15
    $perpage      = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT);  // how many per page
 
16
    $mode         = optional_param('mode', NULL);                             // '0' for less details, '1' for more
 
17
    $showteachers = optional_param('teachers', 1, PARAM_INT);                 // do we want to see the teacher list?
 
18
 
 
19
    if (! $course = get_record('course', 'id', $id)) {
20
20
        error("Course ID is incorrect");
21
21
    }
22
22
 
23
23
    require_login($course->id);
24
 
    
 
24
 
25
25
    if (!$course->category) {
26
26
        if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
27
27
            notice(get_string('sitepartlist0'));
28
28
        }
29
 
        if ($CFG->showsiteparticipantslist < 2 and !isteacher()) {
 
29
        if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
30
30
            notice(get_string('sitepartlist1'));
31
31
        }
32
32
    }
33
33
 
34
 
    add_to_log($course->id, "user", "view all", "index.php?id=$course->id", "");
 
34
    add_to_log($course->id, 'user', 'view all', 'index.php?id='.$course->id, '');
35
35
 
36
36
    $isteacher = isteacher($course->id);
37
 
    $showteachers = ($page == 0 and $sort == "lastaccess" and $dir == "desc");
38
 
 
39
 
    if ($showteachers) {
40
 
        $participantslink = get_string("participants");
 
37
 
 
38
    $countries = get_list_of_countries();
 
39
 
 
40
    $strnever = get_string('never');
 
41
 
 
42
    $datestring->day   = get_string('day');
 
43
    $datestring->days  = get_string('days');
 
44
    $datestring->hour  = get_string('hour');
 
45
    $datestring->hours = get_string('hours');
 
46
    $datestring->min   = get_string('min');
 
47
    $datestring->mins  = get_string('mins');
 
48
    $datestring->sec   = get_string('sec');
 
49
    $datestring->secs  = get_string('secs');
 
50
 
 
51
    if ($mode !== NULL) {
 
52
        $SESSION->userindexmode = $fullmode = ($mode == 1);
 
53
    } else if (isset($SESSION->userindexmode)) {
 
54
        $fullmode = $SESSION->userindexmode;
41
55
    } else {
42
 
        $participantslink = "<a href=\"index.php?id=$course->id\">".get_string("participants")."</a>";
43
 
    }
44
 
 
45
 
    $isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and 
 
56
        $fullmode = false;
 
57
    }
 
58
 
 
59
/// Check to see if groups are being used in this forum
 
60
/// and if so, set $currentgroup to reflect the current group
 
61
 
 
62
    $groupmode    = groupmode($course);   // Groups are being used
 
63
    $currentgroup = get_and_set_current_group($course, $groupmode, $group);
 
64
 
 
65
    if (!$currentgroup) {      // To make some other functions work better later
 
66
        $currentgroup  = NULL;
 
67
    }
 
68
 
 
69
    $isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
46
70
                         !isteacheredit($course->id));
47
71
 
48
 
    $currentgroup = $isseparategroups ? get_current_group($course->id) : NULL;
 
72
    if ($isseparategroups and (!$currentgroup) ) {  //XXX
 
73
        print_heading(get_string("notingroup", "forum"));
 
74
        print_footer($course);
 
75
        exit;
 
76
    }
 
77
 
 
78
    // Should use this variable so that we don't break stuff every time a variable is added or changed.
 
79
    $baseurl = $CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$currentgroup.'&amp;perpage='.$perpage.'&amp;teachers='.$showteachers;
 
80
 
 
81
/// Print headers
49
82
 
50
83
    if ($course->category) {
51
 
        print_header("$course->shortname: ".get_string("participants"), "$course->fullname",
52
 
                     "<A HREF=../course/view.php?id=$course->id>$course->shortname</A> -> ".
53
 
                     "$participantslink", "", "", true, "&nbsp;", navmenu($course));
 
84
        print_header("$course->shortname: ".get_string('participants'), $course->fullname,
 
85
                     "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> -> ".
 
86
                     get_string('participants'), "", "", true, "&nbsp;", navmenu($course));
54
87
    } else {
55
 
        print_header("$course->shortname: ".get_string("participants"), "$course->fullname", 
56
 
                     "$participantslink", "", "", true, "&nbsp;", navmenu($course));
57
 
    }
58
 
 
59
 
    $exceptions = ''; // This will be a list of userids that are shown as teachers and thus
60
 
                      // do not have to be shown as users as well. Only relevant on site course.
61
 
    if ($showteachers) {
62
 
        if ($teachers = get_course_teachers($course->id)) {
63
 
            echo "<h2 align=\"center\">$course->teachers</h2>";
64
 
            foreach ($teachers as $teacher) {
65
 
                if ($isseparategroups) {
66
 
                    if (($teacher->editall or ismember($currentgroup, $teacher->id)) and ($teacher->authority > 0)) {
67
 
                        print_user($teacher, $course);
68
 
                        $exceptions .= "$teacher->id,";
69
 
                    }
70
 
                } else if ($teacher->authority > 0) {    // Don't print teachers with no authority
 
88
        print_header("$course->shortname: ".get_string('participants'), $course->fullname,
 
89
                     get_string('participants'), "", "", true, "&nbsp;", navmenu($course));
 
90
    }
 
91
 
 
92
/// Print settings and things in a table across the top
 
93
 
 
94
    echo '<table class="controls" cellspacing="0"><tr>';
 
95
 
 
96
    if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
 
97
        if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
 
98
            echo '<td class="left">';
 
99
            print_group_menu($groups, $groupmode, $currentgroup, $baseurl);
 
100
            echo '</td>';
 
101
        }
 
102
    }
 
103
 
 
104
    echo '<td class="right">';
 
105
    echo get_string('userlist').': ';
 
106
    $formatmenu = array( '0' => get_string('detailedless'),
 
107
                         '1' => get_string('detailedmore'));
 
108
    echo popup_form($baseurl.'&amp;mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', true);
 
109
    echo '</td></tr></table>';
 
110
 
 
111
    if ($currentgroup and (!$isseparategroups or isteacheredit($course->id))) {    /// Display info about the group
 
112
        if ($group = get_record('groups', 'id', $currentgroup)) {              
 
113
            if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) { 
 
114
                echo '<table class="groupinfobox"><tr><td class="left side picture">';
 
115
                print_group_picture($group, $course->id, true, false, false);
 
116
                echo '</td><td class="content">';
 
117
                echo '<h3>'.$group->name;
 
118
                if (isteacheredit($course->id)) {
 
119
                    echo '&nbsp;<a title="'.get_string('editgroupprofile').'" href="../course/groups.php?id='.$course->id.'&amp;group='.$group->id.'">';
 
120
                    echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="" border="0">';
 
121
                    echo '</a>';
 
122
                }
 
123
                echo '</h3>';
 
124
                echo format_text($group->description);
 
125
                echo '</td></tr></table>';
 
126
            }
 
127
        }
 
128
    }
 
129
 
 
130
 
 
131
    $exceptions = array(); // This will be an array of userids that are shown as teachers and thus
 
132
                           // do not have to be shown as users as well. Only relevant on site course.
 
133
 
 
134
    if($showteachers) {
 
135
 
 
136
        $tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
 
137
        $tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));
 
138
 
 
139
        $table = new flexible_table('user-index-teachers');
 
140
 
 
141
        $table->define_columns($tablecolumns);
 
142
        $table->define_headers($tableheaders);
 
143
        $table->define_baseurl($baseurl);
 
144
 
 
145
        $table->sortable(true, 'lastaccess', SORT_DESC);
 
146
 
 
147
        $table->set_attribute('cellspacing', '0');
 
148
        $table->set_attribute('id', 'teachers');
 
149
        $table->set_attribute('class', 'generaltable generalbox');
 
150
 
 
151
        $table->setup();
 
152
 
 
153
        if($whereclause = $table->get_sql_where()) {
 
154
            $whereclause .= ' AND ';
 
155
        }
 
156
 
 
157
        $teachersql = "SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
 
158
                                   u.email, u.maildisplay, u.city, u.country, u.lastlogin, u.picture, u.lang, u.timezone,
 
159
                                   u.emailstop, t.authority,t.role,t.editall,t.timeaccess as lastaccess, m.groupid
 
160
                            FROM {$CFG->prefix}user u
 
161
                       LEFT JOIN {$CFG->prefix}user_teachers t ON t.userid = u.id 
 
162
                       LEFT JOIN {$CFG->prefix}groups_members m ON m.userid = u.id ";
 
163
 
 
164
        if($isseparategroups) {
 
165
            $whereclause .= '(t.editall OR groupid = '.$currentgroup.') AND ';
 
166
        }
 
167
        else if ($currentgroup) {    // Displaying a group by choice
 
168
            $whereclause .= 'groupid = '.$currentgroup.' AND ';
 
169
        }
 
170
 
 
171
        $teachersql .= 'WHERE '.$whereclause.' t.course = '.$course->id.' AND u.deleted = 0 AND u.confirmed = 1 AND t.authority > 0';
 
172
 
 
173
        if($sortclause = $table->get_sql_sort()) {
 
174
            $teachersql .= ' ORDER BY '.$sortclause;
 
175
        }
 
176
 
 
177
        $teachers = get_records_sql($teachersql);
 
178
 
 
179
        if(!empty($teachers)) {
 
180
 
 
181
            echo '<h2>'.$course->teachers;
 
182
            echo ' <a href="'.$baseurl.'&amp;teachers=0">';
 
183
            echo '<img src="'.$CFG->pixpath.'/i/hide.gif" height="16" width="16" alt="'.get_string('hide').'" /></a>';
 
184
            if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
 
185
                echo ' <a href="'.$CFG->wwwroot.'/course/teacher.php?id='.$course->id.'">';
 
186
                echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="'.get_string('edit').'" /></a>';
 
187
            }
 
188
            echo '</h2>';
 
189
 
 
190
            $exceptions = array_keys($teachers);
 
191
 
 
192
            if ($fullmode) {
 
193
                foreach ($teachers as $key => $teacher) {
71
194
                    print_user($teacher, $course);
72
 
                    $exceptions .= "$teacher->id,";
73
 
                }
 
195
                }
 
196
            } else {
 
197
                $countrysort = (strpos($sortclause, 'country') !== false);
 
198
                foreach ($teachers as $teacher) {
 
199
        
 
200
                    if ($teacher->lastaccess) {
 
201
                        $lastaccess = format_time(time() - $teacher->lastaccess, $datestring);
 
202
                    } else {
 
203
                        $lastaccess = $strnever;
 
204
                    }
 
205
 
 
206
                    if (empty($teacher->country)) {
 
207
                        $country = '';
 
208
                    }
 
209
                    else {
 
210
                        if($countrysort) {
 
211
                            $country = '('.$teacher->country.') '.$countries[$teacher->country];
 
212
                        }
 
213
                        else {
 
214
                            $country = $countries[$teacher->country];
 
215
                        }
 
216
                    }
 
217
        
 
218
                    $table->add_data(array (
 
219
                                    //'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
 
220
                                    print_user_picture($teacher->id, $course->id, $teacher->picture, false, true),
 
221
                                    '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.'&amp;course='.$course->id.'">'.fullname($teacher, $isteacher).'</a></strong>',
 
222
                                    $teacher->city,
 
223
                                    $country,
 
224
                                    $lastaccess));
 
225
                }
 
226
                
 
227
                $table->print_html();
74
228
            }
75
229
        }
76
230
    }
 
231
    else {
 
232
        // Don't show teachers
 
233
        echo '<h2>'.$course->teachers;
 
234
        echo ' <a href="'.$baseurl.'&amp;teachers=1">';
 
235
        echo '<img src="'.$CFG->pixpath.'/i/show.gif" height="16" width="16" alt="'.get_string('show').'" /></a>';
 
236
        if (isadmin() or ($course->category and (iscreator() or (isteacheredit($course->id) and !empty($CFG->teacherassignteachers))))) {
 
237
            echo ' <a href="'.$CFG->wwwroot.'/course/teacher.php?id='.$course->id.'">';
 
238
            echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="'.get_string('edit').'" /></a>';
 
239
        }
 
240
        echo '</h2>';
 
241
    }
 
242
 
77
243
    $guest = get_guest();
78
 
    $exceptions .= $guest->id;
79
 
    
80
 
    if ($sort == "lastaccess") {
81
 
        $dsort = "s.timeaccess";
82
 
    } else {
83
 
        $dsort = "u.$sort";
84
 
    }
85
 
    $students = get_course_students($course->id, $dsort, $dir, $page*$perpage, 
86
 
                                $perpage, $firstinitial, $lastinitial, $currentgroup);
87
 
    $totalcount = count_course_students($course, "", "", "", $currentgroup);
88
 
    if ($firstinitial or $lastinitial) {
89
 
        $matchcount = count_course_students($course, "", $firstinitial, $lastinitial, $currentgroup);
90
 
    } else {
91
 
        $matchcount = $totalcount;
92
 
    }
93
 
 
94
 
 
95
 
    echo "<h2 align=center>$totalcount $course->students</h2>";
96
 
 
97
 
    if (($CFG->longtimenosee < 500) and (!$page) and ($sort == "lastaccess")) {
98
 
        echo "<center><p><font size=1>(";
99
 
        print_string("unusedaccounts","",$CFG->longtimenosee);
100
 
        echo ")</font></p></center>";
101
 
    }
102
 
 
103
 
    /// Print paging bars if necessary
104
 
 
105
 
    if ($totalcount > $perpage) {
106
 
        $alphabet = explode(',', get_string('alphabet'));
107
 
        $strall = get_string("all");
108
 
 
109
 
 
110
 
        /// Bar of first initials
111
 
 
112
 
        echo "<center><p align=\"center\">";
113
 
        echo get_string("firstname")." : ";
114
 
        if ($firstinitial) {
115
 
            echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
116
 
                   "perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
117
 
        } else {
118
 
            echo " <b>$strall</b> ";
119
 
        }
120
 
        foreach ($alphabet as $letter) {
121
 
            if ($letter == $firstinitial) {
122
 
                echo " <b>$letter</b> ";
123
 
            } else {
124
 
                echo " <a href=\"index.php?id=$course->id&sort=firstname&dir=ASC&".
125
 
                       "perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
126
 
            }
127
 
        }
128
 
        echo "<br />";
129
 
 
130
 
        /// Bar of last initials
131
 
 
132
 
        echo get_string("lastname")." : ";
133
 
        if ($lastinitial) {
134
 
            echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
135
 
                   "perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
136
 
        } else {
137
 
            echo " <b>$strall</b> ";
138
 
        }
139
 
        foreach ($alphabet as $letter) {
140
 
            if ($letter == $lastinitial) {
141
 
                echo " <b>$letter</b> ";
142
 
            } else {
143
 
                echo " <a href=\"index.php?id=$course->id&sort=lastname&dir=ASC&".
144
 
                       "perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
145
 
            }
146
 
        }
147
 
        echo "</p>";
148
 
        echo "</center>";
149
 
 
150
 
        print_paging_bar($matchcount, $page, $perpage, 
151
 
                         "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
152
 
 
153
 
    }
154
 
 
155
 
    if ($matchcount < 1) {
156
 
        print_heading(get_string("nostudentsfound", "", $course->students));
157
 
 
158
 
    } if (0 < $matchcount and $matchcount < USER_SMALL_CLASS) {    // Print simple listing
159
 
        foreach ($students as $student) {
160
 
            print_user($student, $course);
161
 
        }
162
 
 
163
 
    } else if ($matchcount > 0) {
164
 
 
165
 
        // Print one big table with abbreviated info
166
 
        $columns = array("firstname", "lastname", "city", "country", "lastaccess");
167
 
 
168
 
        $countries = get_list_of_countries();
169
 
 
170
 
        $strnever = get_string("never");
171
 
 
172
 
        $datestring->day   = get_string("day");
173
 
        $datestring->days  = get_string("days");
174
 
        $datestring->hour  = get_string("hour");
175
 
        $datestring->hours = get_string("hours");
176
 
        $datestring->min   = get_string("min");
177
 
        $datestring->mins  = get_string("mins");
178
 
        $datestring->sec   = get_string("sec");
179
 
        $datestring->secs  = get_string("secs");
180
 
 
181
 
        foreach ($columns as $column) {
182
 
            $colname[$column] = get_string($column);
183
 
            if ($sort != $column) {
184
 
                $columnicon = "";
185
 
                if ($column == "lastaccess") {
186
 
                    $columndir = "desc";
187
 
                } else {
188
 
                    $columndir = "asc";
189
 
                }
190
 
            } else {
191
 
                $columndir = $dir == "asc" ? "desc":"asc";
192
 
                if ($column == "lastaccess") {
193
 
                    $columnicon = $dir == "asc" ? "up":"down";
194
 
                } else {
195
 
                    $columnicon = $dir == "asc" ? "down":"up";
196
 
                }
197
 
                $columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />";
198
 
            }
199
 
            $$column = "<a href=\"index.php?id=$course->id&sort=$column&dir=$columndir\">".$colname["$column"]."</a>$columnicon";
200
 
        }
201
 
 
202
 
        foreach ($students as $key => $student) {
203
 
            $students[$key]->country = ($student->country) ? $countries[$student->country] : '';
204
 
        }
205
 
        if ($sort == "country") {  // Need to re-sort by full country name, not code
 
244
    $exceptions[] = $guest->id;
 
245
 
 
246
    $tablecolumns = array('picture', 'fullname', 'city', 'country', 'lastaccess');
 
247
    $tableheaders = array('', get_string('fullname'), get_string('city'), get_string('country'), get_string('lastaccess'));
 
248
 
 
249
    $table = new flexible_table('user-index-students');
 
250
 
 
251
    $table->define_columns($tablecolumns);
 
252
    $table->define_headers($tableheaders);
 
253
    $table->define_baseurl($baseurl);
 
254
 
 
255
    $table->sortable(true, 'lastaccess', SORT_DESC);
 
256
 
 
257
    $table->set_attribute('cellspacing', '0');
 
258
    $table->set_attribute('id', 'students');
 
259
    $table->set_attribute('class', 'generaltable generalbox');
 
260
 
 
261
    $table->set_control_variables(array(
 
262
        TABLE_VAR_SORT    => 'ssort',
 
263
        TABLE_VAR_HIDE    => 'shide',
 
264
        TABLE_VAR_SHOW    => 'sshow',
 
265
        TABLE_VAR_IFIRST  => 'sifirst',
 
266
        TABLE_VAR_ILAST   => 'silast',
 
267
        TABLE_VAR_PAGE    => 'spage'
 
268
    ));
 
269
    $table->setup();
 
270
 
 
271
    if(SITEID == $course->id) {
 
272
        $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country, 
 
273
                      u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, u.lastaccess ';
 
274
        $from   = 'FROM '.$CFG->prefix.'user u ';
 
275
        $where  = 'WHERE confirmed = 1 AND u.deleted = 0 ';
 
276
    }
 
277
    else {
 
278
        $select = 'SELECT u.id, u.username, u.firstname, u.lastname, u.email, u.city, u.country, 
 
279
                      u.picture, u.lang, u.timezone, u.emailstop, u.maildisplay, s.timeaccess AS lastaccess ';
 
280
        $from   = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'user_students s ON s.userid = u.id ';
 
281
        $where  = 'WHERE s.course = '.$course->id.' AND u.deleted = 0 ';
 
282
    }
 
283
 
 
284
    if ($currentgroup) {    // Displaying a group by choice
 
285
        // FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
 
286
        $from  .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
 
287
        $where .= ' AND gm.groupid = '.$currentgroup;
 
288
    }
 
289
 
 
290
    if($course->id == SITEID) {
 
291
        $where .= ' AND u.id NOT IN ('.implode(',', $exceptions).')';
 
292
    }
 
293
 
 
294
    $totalcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
 
295
 
 
296
    if($table->get_sql_where()) {
 
297
        $where .= ' AND '.$table->get_sql_where();
 
298
    }
 
299
 
 
300
    if($table->get_sql_sort()) {
 
301
        $sort = ' ORDER BY '.$table->get_sql_sort();
 
302
    }
 
303
    else {
 
304
        $sort = '';
 
305
    }
 
306
 
 
307
    if($table->get_sql_sort()) {
 
308
        $sort = ' ORDER BY '.$table->get_sql_sort();
 
309
    }
 
310
    else {
 
311
        $sort = '';
 
312
    }
 
313
 
 
314
    $matchcount = count_records_sql('SELECT COUNT(*) '.$from.$where);
 
315
 
 
316
    $table->initialbars($totalcount > $perpage);
 
317
    $table->pagesize($perpage, $matchcount);
 
318
 
 
319
    if($table->get_page_start() !== '' && $table->get_page_size() !== '') {
 
320
        $limit = ' '.sql_paging_limit($table->get_page_start(), $table->get_page_size());
 
321
    }
 
322
    else {
 
323
        $limit = '';
 
324
    }    
 
325
    
 
326
    $students = get_records_sql($select.$from.$where.$sort.$limit);
 
327
 
 
328
    $a->count = $totalcount;
 
329
    $a->items = $totalcount == 1 ? $course->student : $course->students;
 
330
    echo '<h2>'.get_string('counteditems', '', $a);
 
331
    if (isteacheredit($course->id)) {
 
332
        echo ' <a href="../course/student.php?id='.$course->id.'">';
 
333
        echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="" /></a>';
 
334
    }
 
335
    echo '</h2>';
 
336
 
 
337
    if ($CFG->longtimenosee > 0 && $CFG->longtimenosee < 1000 && $totalcount > 0) {
 
338
        echo '<p id="longtimenosee">('.get_string('unusedaccounts', '', $CFG->longtimenosee).')</p>';
 
339
    }
 
340
 
 
341
    if ($fullmode) {    // Print simple listing
 
342
        if ($totalcount < 1) {
 
343
            print_heading(get_string("nostudentsfound", "", $course->students));
 
344
        }
 
345
        else {
 
346
            
 
347
            if($totalcount > $perpage) {
 
348
 
 
349
                $firstinitial = $table->get_initial_first();
 
350
                $lastinitial  = $table->get_initial_last();
 
351
                $strall = get_string('all');
 
352
                $alpha  = explode(',', get_string('alphabet'));
 
353
    
 
354
                // Bar of first initials
 
355
    
 
356
                echo '<div class="initialbar firstinitial">'.get_string('firstname').' : ';
 
357
                if(!empty($firstinitial)) {
 
358
                    echo '<a href="'.$baseurl.'&amp;sifirst=">'.$strall.'</a>';
 
359
                } else {
 
360
                    echo '<strong>'.$strall.'</strong>';
 
361
                }
 
362
                foreach ($alpha as $letter) {
 
363
                    if ($letter == $firstinitial) {
 
364
                        echo ' <strong>'.$letter.'</strong>';
 
365
                    } else {
 
366
                        echo ' <a href="'.$baseurl.'&amp;sifirst='.$letter.'">'.$letter.'</a>';
 
367
                    }
 
368
                }
 
369
                echo '</div>';
 
370
    
 
371
                // Bar of last initials
 
372
    
 
373
                echo '<div class="initialbar lastinitial">'.get_string('lastname').' : ';
 
374
                if(!empty($lastinitial)) {
 
375
                    echo '<a href="'.$baseurl.'&amp;silast=">'.$strall.'</a>';
 
376
                } else {
 
377
                    echo '<strong>'.$strall.'</strong>';
 
378
                }
 
379
                foreach ($alpha as $letter) {
 
380
                    if ($letter == $lastinitial) {
 
381
                        echo ' <strong>'.$letter.'</strong>';
 
382
                    } else {
 
383
                        echo ' <a href="'.$baseurl.'&amp;silast='.$letter.'">'.$letter.'</a>';
 
384
                    }
 
385
                }
 
386
                echo '</div>';
 
387
 
 
388
                print_paging_bar($matchcount, intval($table->get_page_start() / $perpage), $perpage, $baseurl.'&amp;', 'spage');
 
389
 
 
390
            }
 
391
 
 
392
            if($matchcount > 0) {
 
393
                foreach ($students as $student) {
 
394
                    print_user($student, $course);
 
395
                }
 
396
            }
 
397
            else {
 
398
                print_heading(get_string('nothingtodisplay'));
 
399
            }
 
400
        }
 
401
    }
 
402
    else {
 
403
        $countrysort = (strpos($sort, 'country') !== false);
 
404
        if (!empty($students))  {
206
405
            foreach ($students as $student) {
207
 
                $sstudents[$student->id] = $student->country;
208
 
            }
209
 
            asort($sstudents);
210
 
            foreach ($sstudents as $key => $value) {
211
 
                $nstudents[] = $students[$key];
212
 
            }
213
 
            $students = $nstudents;
214
 
        }
215
 
 
216
 
 
217
 
        $table->head = array ("&nbsp;", "$firstname / $lastname", $city, $country, $lastaccess);
218
 
        $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT");
219
 
        $table->size = array ("10",  "*", "*", "*", "*");
220
 
        $table->size = array ("10",  "*", "*", "*", "*");
221
 
        $table->cellpadding = 4;
222
 
        $table->cellspacing = 0;
223
 
        
224
 
        foreach ($students as $student) {
225
 
 
226
 
            if ($student->lastaccess) {
227
 
                $lastaccess = format_time(time() - $student->lastaccess, $datestring);
228
 
            } else {
229
 
                $lastaccess = $strnever;
230
 
            }
231
 
 
232
 
            $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
233
 
 
234
 
            $fullname = fullname($student, $isteacher);
235
 
 
236
 
            $table->data[] = array ($picture,
237
 
                "<b><a href=\"$CFG->wwwroot/user/view.php?id=$student->id&course=$course->id\">$fullname</a></b>",
238
 
                "<font size=2>$student->city</font>", 
239
 
                "<font size=2>$student->country</font>",
240
 
                "<font size=2>$lastaccess</font>");
241
 
        }
242
 
        print_table($table);
243
 
 
244
 
        print_paging_bar($matchcount, $page, $perpage, 
245
 
                         "index.php?id=$course->id&sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&");
246
 
 
247
 
        if ($perpage != 99999) {
248
 
            echo "<center><p>";
249
 
            echo "<a href=\"index.php?id=$course->id&sort=$sort&dir=$dir&perpage=99999\">".get_string("showall", "", $totalcount)."</a>";
250
 
            echo "</p></center>";
251
 
        }
252
 
    }
253
 
 
 
406
                if ($student->lastaccess) {
 
407
                    $lastaccess = format_time(time() - $student->lastaccess, $datestring);
 
408
                } else {
 
409
                    $lastaccess = $strnever;
 
410
                }
 
411
    
 
412
                if (empty($student->country)) {
 
413
                    $country = '';
 
414
                }
 
415
                else {
 
416
                    if($countrysort) {
 
417
                        $country = '('.$student->country.') '.$countries[$student->country];
 
418
                    }
 
419
                    else {
 
420
                        $country = $countries[$student->country];
 
421
                    }
 
422
                }
 
423
 
 
424
                $table->add_data(array (
 
425
                        //'<input type="checkbox" name="userid[]" value="'.$teacher->id.'" />',
 
426
                        print_user_picture($student->id, $course->id, $student->picture, false, true),
 
427
                        '<strong><a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student).'</a></strong>',
 
428
                        $student->city,
 
429
                        $country,
 
430
                        $lastaccess));
 
431
            }
 
432
        }
 
433
 
 
434
        $table->print_html();
 
435
 
 
436
    }
 
437
 
 
438
    if ($perpage == 99999) {
 
439
        echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage='.DEFAULT_PAGE_SIZE.'">'.get_string('showperpage', '', DEFAULT_PAGE_SIZE).'</a></div>';
 
440
    }
 
441
    else if ($matchcount > 0 && $perpage < $matchcount) {
 
442
        echo '<div id="showall"><a href="'.$baseurl.'&amp;perpage=99999">'.get_string('showall', '', $matchcount).'</a></div>';
 
443
    }
 
444
    
254
445
    print_footer($course);
255
446
 
256
447
?>