BOINC /
boinc
| 1 | <?php |
||
| 2 | // This file is part of BOINC. |
||
| 3 | // http://boinc.berkeley.edu |
||
| 4 | // Copyright (C) 2017 University of California |
||
| 5 | // |
||
| 6 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 7 | // under the terms of the GNU Lesser General Public License |
||
| 8 | // as published by the Free Software Foundation, |
||
| 9 | // either version 3 of the License, or (at your option) any later version. |
||
| 10 | // |
||
| 11 | // BOINC is distributed in the hope that it will be useful, |
||
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 14 | // See the GNU Lesser General Public License for more details. |
||
| 15 | // |
||
| 16 | // You should have received a copy of the GNU Lesser General Public License |
||
| 17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | // web interface for administering badges |
||
| 20 | |||
| 21 | require_once('../inc/util_ops.inc'); |
||
| 22 | |||
| 23 | function show_form() { |
||
| 24 | start_table('table-striped'); |
||
| 25 | table_header( |
||
| 26 | "ID", |
||
| 27 | "name", |
||
| 28 | "title", |
||
| 29 | "image URL", |
||
| 30 | "type<br><small>0=user<br>1=team<br>optional</small>", |
||
| 31 | "description<br><small>optional</small>", |
||
| 32 | "level<br><small>optional</small>", |
||
| 33 | "tags<br><small>optional</small>", |
||
| 34 | "SQL rule<br><small>optional</small>", |
||
| 35 | "", "" |
||
| 36 | ); |
||
| 37 | |||
| 38 | $badges = BoincBadge::enum(""); |
||
| 39 | $i = 0; |
||
| 40 | foreach ($badges as $badge) { |
||
| 41 | echo "<tr class=row$i valign=top><form action=badge_admin.php method=POST>"; |
||
| 42 | $i = 1-$i; |
||
| 43 | echo "<td>$badge->id</td>\n"; |
||
| 44 | echo "<input type=hidden name=id value=$badge->id>"; |
||
| 45 | $nu = BoincBadgeUser::count("badge_id=$badge->id"); |
||
| 46 | $nt = BoincBadgeTeam::count("badge_id=$badge->id"); |
||
| 47 | $x = "<br><small>Assigned to $nu users<br>Assigned to $nt teams</small>"; |
||
| 48 | echo "<td><input name=\"name\" value=\"$badge->name\">$x</td>\n"; |
||
| 49 | echo "<td><input name=\"title\" value=\"$badge->title\"></td>\n"; |
||
| 50 | $x = ""; |
||
| 51 | if ($badge->image_url) { |
||
| 52 | if (strstr($badge->image_url, "http") == $badge->image_url) { |
||
| 53 | $y = $badge->image_url; |
||
| 54 | } else { |
||
| 55 | $y = url_base().$badge->image_url; |
||
| 56 | } |
||
| 57 | $x = " <img align=right height=64 src=\"$y\">"; |
||
| 58 | } |
||
| 59 | echo "<td><input name=\"image_url\" value=\"$badge->image_url\">$x</td>\n"; |
||
| 60 | echo "<td><input name=\"type\" size=4 value=\"$badge->type\"></td>\n"; |
||
| 61 | echo "<td><input name=\"description\" value=\"$badge->description\"></td>\n"; |
||
| 62 | echo "<td><input name=\"level\" value=\"$badge->level\"></td>\n"; |
||
| 63 | echo "<td><input name=\"tags\" value=\"$badge->tags\"></td>\n"; |
||
| 64 | echo "<td><input name=\"sql_rule\" value=\"$badge->sql_rule\"></td>\n"; |
||
| 65 | echo "<td><input class=\"btn btn-default\" type=submit name=\"update\" value=Update>\n"; |
||
| 66 | echo "<td><input class=\"btn btn-danger\" type=submit name=\"delete\" value=Delete>\n"; |
||
| 67 | echo "</form></tr>\n"; |
||
| 68 | } |
||
| 69 | |||
| 70 | echo "<tr><form action=badge_admin.php method=POST>"; |
||
| 71 | echo "<td><br></td>\n"; |
||
| 72 | echo "<td><input name=\"name\"></td>\n"; |
||
| 73 | echo "<td><input name=\"title\"></td>\n"; |
||
| 74 | echo "<td><input name=\"image_url\"></td>\n"; |
||
| 75 | echo "<td><input name=\"type\" size=4></td>\n"; |
||
| 76 | echo "<td><input name=\"description\"></td>\n"; |
||
| 77 | echo "<td><input name=\"level\"></td>\n"; |
||
| 78 | echo "<td><input name=\"tags\"></td>\n"; |
||
| 79 | echo "<td><input name=\"sql_rule\"></td>\n"; |
||
| 80 | echo "<td colspan=2><input class=\"btn btn-primary\" type=submit name=\"add_badge\" value=\"Create badge\"></td>\n"; |
||
| 81 | echo "</form></tr>\n"; |
||
| 82 | |||
| 83 | end_table(); |
||
| 84 | } |
||
| 85 | |||
| 86 | function add_badge() { |
||
| 87 | $name = BoincDb::escape_string(post_str("name")); |
||
| 88 | $type = post_int("type"); |
||
| 89 | $title = BoincDb::escape_string(post_str("title")); |
||
| 90 | $description = BoincDb::escape_string(post_str("description")); |
||
| 91 | $image_url = BoincDb::escape_string(post_str("image_url")); |
||
| 92 | $level = BoincDb::escape_string(post_str("level")); |
||
| 93 | $tags = BoincDb::escape_string(post_str("tags")); |
||
| 94 | $sql_rule = BoincDb::escape_string(post_str("sql_rule")); |
||
| 95 | $now = time(); |
||
| 96 | $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')"); |
||
| 97 | if (!$id) { |
||
| 98 | admin_error_page("Insert failed"); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | function update_badge() { |
||
| 103 | $id = post_int("id"); |
||
| 104 | $badge = BoincBadge::lookup_id($id); |
||
| 105 | if (!$badge) { |
||
| 106 | admin_error_page("no such badge"); |
||
| 107 | } |
||
| 108 | $name = BoincDb::escape_string(post_str("name")); |
||
| 109 | $type = post_int("type"); |
||
| 110 | $title = BoincDb::escape_string(post_str("title")); |
||
| 111 | $description = BoincDb::escape_string(post_str("description")); |
||
| 112 | $image_url = BoincDb::escape_string(post_str("image_url")); |
||
| 113 | $level = BoincDb::escape_string(post_str("level")); |
||
| 114 | $tags = BoincDb::escape_string(post_str("tags")); |
||
| 115 | $sql_rule = BoincDb::escape_string(post_str("sql_rule")); |
||
| 116 | $retval = $badge->update("name='$name', type=$type, title='$title', description='$description', image_url='$image_url', level='$level', tags='$tags', sql_rule='$sql_rule'"); |
||
| 117 | if (!$retval) { |
||
| 118 | admin_error_page("update failed"); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | function delete_badge() { |
||
| 123 | $id = post_int("id"); |
||
| 124 | $badge = BoincBadge::lookup_id($id); |
||
| 125 | if (!$badge) { |
||
| 126 | admin_error_page("no such badge"); |
||
| 127 | } |
||
| 128 | BoincBadgeUser::delete("badge_id=$id"); |
||
| 129 | BoincBadgeTeam::delete("badge_id=$id"); |
||
| 130 | $badge->delete(); |
||
| 131 | } |
||
| 132 | |||
| 133 | if (post_str('add_badge', true)) { |
||
| 134 | add_badge(); |
||
| 135 | } else if (post_str('update', true)) { |
||
| 136 | update_badge(); |
||
| 137 | } else if (post_str('delete', true)) { |
||
| 138 | delete_badge(); |
||
| 139 | } |
||
| 140 | admin_page_head("Manage badges"); |
||
| 141 | echo " |
||
| 142 | Manage the set of badges issued by your project. |
||
| 143 | <p> |
||
| 144 | Badges are assigned using a PHP script; |
||
| 145 | see |
||
| 146 | <a href=https://github.com/BOINC/boinc/wiki/BadgeDoc> |
||
| 147 | https://github.com/BOINC/boinc/wiki/BadgeDoc |
||
| 148 | </a> |
||
| 149 | <p> |
||
| 150 | Fields marked 'optional' are not used by the default script. |
||
| 151 | "; |
||
| 152 | |||
| 153 | show_form(); |
||
|
0 ignored issues
–
show
|
|||
| 154 | admin_page_tail(); |
||
| 155 | ?> |
||
| 156 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.