summaryrefslogtreecommitdiff
path: root/sqlbox/report.php
blob: d67a6a041f5388e4400603fd001f384f077b5568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');

$id  = required_param('id', PARAM_INT);   //moduleid

if ($id) {
    $cm     = get_coursemodule_from_id('sqlbox', $id, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $sqlbox = $DB->get_record('sqlbox', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
    print_error('invalidcourse');
}

require_login($course, true, $cm);

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/sqlbox:readqueries', $context);

add_to_log($course->id, 'sqlbox', 'report', "report.php?id={$cm->id}", $sqlbox->name, $cm->id);

$PAGE->set_url('/mod/sqlbox/report.php', array('id' => $cm->id));
$PAGE->set_title(format_string($sqlbox->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);

echo $OUTPUT->header();

echo '<div class="reportlink">';
echo "<a href=\"reportall.php?id=$cm->id\">View all results</a>";
echo '</div>';


$sql = "SELECT
            u.id,
            translate(to_char(s.correct, 'FM9'), '01', '☒☑'),
            (u.firstname || ' ' || u.lastname),
            s.query
          FROM {user} u, {sqlbox_solutions} s
        WHERE
          u.id = s.userid and
          s.sqlboxid = :id";
$records = $DB->get_records_sql($sql, array('id' => $sqlbox->id));
$table = new html_table;
$table->head = array("Lösung", "Nutzer", "Anfrage");
$table->align = array("center", "left", "left");
if ($records) {
    foreach ($records as $record)
        $table->data[] = array_slice((array)$record, 1);
}
echo html_writer::table($table);

echo $OUTPUT->footer();

?>