NOBUG standardising prevention of output buffering
[moodle.git] / admin / report / configlog / index.php
1 <?php
3 require_once(dirname(__FILE__).'/../../../config.php');
4 require_once($CFG->libdir.'/adminlib.php');
6 // page parameters
7 $page    = optional_param('page', 0, PARAM_INT);
8 $perpage = optional_param('perpage', 30, PARAM_INT);    // how many per page
9 $sort    = optional_param('sort', 'timemodified', PARAM_ALPHA);
10 $dir     = optional_param('dir', 'DESC', PARAM_ALPHA);
12 admin_externalpage_setup('reportconfiglog');
13 echo $OUTPUT->header();
15 echo $OUTPUT->heading(get_string('configlog', 'report_configlog'));
17 $changescount = $DB->count_records('config_log');
19 $columns = array('firstname'    => get_string('firstname'),
20                  'lastname'     => get_string('lastname'),
21                  'timemodified' => get_string('timemodified', 'report_configlog'),
22                  'plugin'       => get_string('plugin', 'report_configlog'),
23                  'name'         => get_string('setting', 'report_configlog'),
24                  'value'        => get_string('value', 'report_configlog'),
25                  'oldvalue'     => get_string('oldvalue', 'report_configlog'),
26                 );
27 $hcolumns = array();
30 if (!isset($columns[$sort])) {
31     $sort = 'lastname';
32 }
34 foreach ($columns as $column=>$strcolumn) {
35     if ($sort != $column) {
36         $columnicon = '';
37         if ($column == 'lastaccess') {
38             $columndir = 'DESC';
39         } else {
40             $columndir = 'ASC';
41         }
42     } else {
43         $columndir = $dir == 'ASC' ? 'DESC':'ASC';
44         if ($column == 'lastaccess') {
45             $columnicon = $dir == 'ASC' ? 'up':'down';
46         } else {
47             $columnicon = $dir == 'ASC' ? 'down':'up';
48         }
49         $columnicon = " <img src=\"" . $OUTPUT->pix_url('t/' . $columnicon) . "\" alt=\"\" />";
51     }
52     $hcolumns[$column] = "<a href=\"index.php?sort=$column&amp;dir=$columndir&amp;page=$page&amp;perpage=$perpage\">".$strcolumn."</a>$columnicon";
53 }
55 $baseurl = new moodle_url('index.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage));
56 echo $OUTPUT->paging_bar($changescount, $page, $perpage, $baseurl);
58 $override = new stdClass();
59 $override->firstname = 'firstname';
60 $override->lastname = 'lastname';
61 $fullnamelanguage = get_string('fullnamedisplay', '', $override);
62 if (($CFG->fullnamedisplay == 'firstname lastname') or
63     ($CFG->fullnamedisplay == 'firstname') or
64     ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'firstname lastname' )) {
65     $fullnamedisplay = $hcolumns['firstname'].' / '.$hcolumns['lastname'];
66 } else { // ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'lastname firstname')
67     $fullnamedisplay = $hcolumns['lastname'].' / '.$hcolumns['firstname'];
68 }
70 $table = new html_table();
71 $table->head  = array($hcolumns['timemodified'], $fullnamedisplay, $hcolumns['plugin'], $hcolumns['name'], $hcolumns['value'], $hcolumns['oldvalue']);
72 $table->align = array('left',                    'left',           'left',              'left',            'left',             'left');
73 $table->size  = array('30%',                     '10%',            '10%',               '10%',             '20%',              '20%');
74 $table->width = '95%';
75 $table->data  = array();
77 if ($sort == 'firstname' or $sort == 'lastname') {
78     $orderby = "u.$sort $dir";
79 } else {
80     $orderby = "cl.$sort $dir";
81 }
83 $ufields = user_picture::fields('u');
84 $sql = "SELECT $ufields,
85                cl.timemodified, cl.plugin, cl.name, cl.value, cl.oldvalue
86           FROM {config_log} cl
87           JOIN {user} u ON u.id = cl.userid
88       ORDER BY $orderby";
90 $rs = $DB->get_recordset_sql($sql, array(), $page*$perpage, $perpage);
91 foreach ($rs as $log) {
92     $row = array();
93     $row[] = userdate($log->timemodified);
94     $row[] = fullname($log);
95     if (is_null($log->plugin)) {
96         $row[] = 'core';
97     } else {
98         $row[] = $log->plugin;
99     }
100     $row[] = $log->name;
101     $row[] = s($log->value);
102     $row[] = s($log->oldvalue);
104     $table->data[] = $row;
106 $rs->close();
108 echo html_writer::table($table);
110 echo $OUTPUT->footer();