File: bolt_admin.php

package info (click to toggle)
boinc 7.14.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,132 kB
  • sloc: cpp: 163,589; php: 113,173; ansic: 49,284; pascal: 35,620; xml: 17,864; java: 13,521; python: 6,551; sh: 4,082; perl: 1,843; makefile: 1,796; objc: 1,543; sql: 959; csh: 126; lisp: 47
file content (201 lines) | stat: -rw-r--r-- 6,449 bytes parent folder | download | duplicates (7)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

require_once("../inc/bolt_db.inc");
require_once("../inc/util_ops.inc");

function show_course($course) {
    $x = "<b>$course->name</b>
            <br>Description: $course->description
            <br>Created: ".date_str($course->create_time)."
    ";
    $y = "<a href=bolt_map.php?course_id=$course->id>Map</a>
        <br><a href=bolt_compare.php?course_id=$course->id>Experiments</a>
        <br>
    ";
    row2_init($x, $y);
    if ($course->hidden) {
        show_button("bolt_admin.php?action=unhide&course_id=$course->id", "Unhide", "Unhide this course");
    } else {
        show_button("bolt_admin.php?action=hide&course_id=$course->id", "Hide", "Hide this course");
    }
    show_button("bolt_admin.php?action=clear_confirm&course_id=$course->id", "Clear data", "Clear student data for this course");
    echo "</td></tr>";
}

function show_courses() {
    $courses = BoltCourse::enum();
    start_table();
    table_header("Course", "Tools");
    foreach ($courses as $course) {
        show_course($course);
    }
    end_table();
}

function add_course_form() {
    echo "
        <form action=bolt_admin.php method=get>
        <input type=hidden name=action value=add_course>
    ";
    start_table();
    row1("Add course");
    row2("Course name<br><p class=\"text-muted\">Visible to users</p>", "<input name=course_name>");
    row2("Internal name<br><p class=\"text-muted\">Not visible to users; used as a directory name, so no spaces or special chars</p>", "<input name=short_name>");
    row2("Description<br><p class=\"text-muted\">Visible to users</p>", "<textarea name=description cols=60></textarea>");
    row2("", "<input class=\"btn btn-primary\" type=submit name=submit value=\"Add course\">");
    end_table();
    echo "</form>";
}

function user_settings() {
    global $user;
    $flags = $user->bolt->flags;
    echo "<form action=bolt_admin.php method=get>
        <input type=hidden name=action value=update_user>
    ";
    start_table();
    row1("User settings");
    $x = ($flags&BOLT_FLAGS_SHOW_ALL)?"checked":"";
    row2("Show hidden courses?", "<input type=checkbox name=show_all $x>");
    $x = ($flags&BOLT_FLAGS_DEBUG)?"checked":"";
    row2("Show debugging output?", "<input type=checkbox name=debug $x>");
    row2("", "<input class=\"btn btn-primary\" type=submit name=submit value=\"Update settings\">");
    end_table();
    echo "</form>";
}

function show_all() {
    admin_page_head("Bolt course administration");
    show_courses();
    echo "<p>
        <a href=bolt_admin.php?action=add_course_form>Add course</a>
        <p>
        <a href=bolt_admin.php?action=update_user_form>User settings</a>
    ";
    admin_page_tail();
}

function clear_confirm() {
    global $course_id;

    admin_page_head("Bolt course administration");
    echo "This will clear all student data for this course.
        This is irrevocable.
        Are you sure you want to do this?
        <p>
        <a href=bolt_admin.php?action=clear&course_id=$course_id>Yes</a>
    ";
    admin_page_tail();
}

function clear() {
    global $course_id;

    admin_page_head("Deleting course data");
    BoltEnrollment::delete_aux("course_id = $course_id");
    BoltView::delete_aux("course_id = $course_id");
    BoltResult::delete_aux("course_id = $course_id");
    BoltXsetResult::delete_aux("course_id = $course_id");
    BoltSelectFinished::delete_aux("course_id = $course_id");
    BoltRefreshRec::delete_aux("course_id = $course_id");
    BoltQuestion::delete_aux("course_id = $course_id");
    
    echo "
        Course data deleted.
    ";
    admin_page_tail();
}

$user = get_logged_in_user();

$db = BoltDb::get();
if (!$db) error_page("Can't connect to database server");

if (!$db->table_exists('bolt_course')) {
    page_head("Create Bolt database");
    $db_name = $db->db_name;
    echo "
        The database tables for Bolt don't seem to exist.
        To create them, go to ~/boinc/db and type
        <pre>
mysql $db_name < bolt_schema.sql
</pre>
    Then <a href=bolt_admin.php>reload this page</a>.
    ";
    page_tail();
    exit();
}

BoltUser::lookup($user);
$course_id = get_int('course_id', true);
if ($course_id) $course = BoltCourse::lookup_id($course_id);

$action = get_str('action', true);
switch ($action) {
case 'add_course_form':
    admin_page_head("Add course");
    add_course_form();
    admin_page_tail();
    break;
case 'add_course':
    $short_name = BoltDb::escape_string(get_str('short_name'));
    $name = BoltDb::escape_string(get_str('course_name'));
    $description = BoltDb::escape_string(get_str('description'));
    $now = time();
    BoltCourse::insert("(create_time, short_name, name, description) values ($now, '$short_name', '$name', '$description')");
    Header('Location: bolt_admin.php');
    break;
case 'update_user_form':
    admin_page_head("Bolt user settings");
    user_settings();
    admin_page_tail();
    break;
case 'update_user':
    $flags = 0;
    if (get_str('show_all', true)) $flags |= BOLT_FLAGS_SHOW_ALL;
    if (get_str('debug', true)) $flags |= BOLT_FLAGS_DEBUG;
    $user->bolt->update("flags=$flags");
    $user->bolt->flags = $flags;
    Header('Location: bolt_admin.php');
    break;
case 'hide':
    if (!$course) error_page("no such course");
    $course->update("hidden=1");
    Header('Location: bolt_admin.php');
    break;
case 'unhide':
    if (!$course) error_page("no such course");
    $course->update("hidden=0");
    Header('Location: bolt_admin.php');
    break;
case 'clear_confirm':
    clear_confirm();
    break;
case 'clear':
    clear();
    break;
case '':
    show_all();
    break;
default:
    error_page("unknown action $action");
}


?>