.
// web interface for administering badges
require_once('../inc/util_ops.inc');
function show_form() {
start_table();
table_header(
"ID",
"name",
"title",
"image URL",
"type
0=user
1=team
optional
",
"description
optional
",
"level
optional
",
"tags
optional
",
"SQL rule
optional
",
"", ""
);
$badges = BoincBadge::enum("");
$i = 0;
foreach ($badges as $badge) {
echo "
\n";
}
echo "
\n";
end_table();
}
function add_badge() {
$name = BoincDb::escape_string(post_str("name"));
$type = post_int("type");
$title = BoincDb::escape_string(post_str("title"));
$description = BoincDb::escape_string(post_str("description"));
$image_url = BoincDb::escape_string(post_str("image_url"));
$level = BoincDb::escape_string(post_str("level"));
$tags = BoincDb::escape_string(post_str("tags"));
$sql_rule = BoincDb::escape_string(post_str("sql_rule"));
$now = time();
$id = BoincBadge::insert("(create_time, name, type, title, description, image_url, level, tags, sql_rule) values ($now, '$name', $type, '$title', '$description', '$image_url', '$level', '$tags', '$sql_rule')");
if (!$id) {
admin_error_page("Insert failed");
}
}
function update_badge() {
$id = post_int("id");
$badge = BoincBadge::lookup_id($id);
if (!$badge) {
admin_error_page("no such badge");
}
$name = BoincDb::escape_string(post_str("name"));
$type = post_int("type");
$title = BoincDb::escape_string(post_str("title"));
$description = BoincDb::escape_string(post_str("description"));
$image_url = BoincDb::escape_string(post_str("image_url"));
$level = BoincDb::escape_string(post_str("level"));
$tags = BoincDb::escape_string(post_str("tags"));
$sql_rule = BoincDb::escape_string(post_str("sql_rule"));
$retval = $badge->update("name='$name', type=$type, title='$title', description='$description', image_url='$image_url', level='$level', tags='$tags', sql_rule='$sql_rule'");
if (!$retval) {
admin_error_page("update failed");
}
}
function delete_badge() {
$id = post_int("id");
$badge = BoincBadge::lookup_id($id);
if (!$badge) {
admin_error_page("no such badge");
}
BoincBadgeUser::delete("badge_id=$id");
BoincBadgeTeam::delete("badge_id=$id");
$badge->delete();
}
if (post_str('add_badge', true)) {
add_badge();
} else if (post_str('update', true)) {
update_badge();
} else if (post_str('delete', true)) {
delete_badge();
}
admin_page_head("Manage badges");
echo "
Manage the set of badges issued by your project.
Badges are assigned using a PHP script;
see
http://boinc.berkeley.edu/trac/wiki/BadgeDoc
Fields marked 'optional' are not used by the default script.
";
show_form();
admin_page_tail();
?>