forked from staktrace/bugmash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtags.php
54 lines (45 loc) · 1.39 KB
/
tags.php
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
<?php
include_once( 'common.php' );
if (! (isset( $_POST['user'] ) && $_POST['user'] == $_ME)) {
fail( 'Incorrect user: ' . $_POST['user'] );
}
if (! (isset( $_POST['bugs'] ) && isset( $_POST['action'] ))) {
fail( 'Required parameters not set' );
}
$bugs = explode( ',', $_POST['bugs'] );
if (count( $bugs ) == 0) {
fail( 'No bugs specified' );
}
// sanitize input
$bugs = array_map( 'intval', $bugs );
$_DB = new mysqli( $_MYSQL_HOST, $_MYSQL_USER, $_MYSQL_PASS, $_MYSQL_DB );
if (mysqli_connect_errno()) {
fail( 'Error connecting to db: ' . mysqli_connect_error() );
}
if (strcmp( $_POST['action'], 'get' ) == 0) {
$result = $_DB->query( 'SELECT * FROM tags WHERE bug=' . implode( ' OR bug=', $bugs ) );
if (! $result) {
fail( 'Unable to load tags' );
}
$tags = array();
while ($row = $result->fetch_assoc()) {
$tags[ $row['bug'] ][] = $row['tag'];
}
header( 'Content-Type: application/json' );
print json_encode( $tags );
} else if (strcmp( $_POST['action'], 'set' ) == 0) {
if (! isset( $_POST['tags'] )) {
fail( 'Required parameter tags not set' );
}
$tagUpdates = array();
foreach ($bugs AS $bug) {
$tagUpdates[ $bug ] = $_POST['tags'];
}
updateTags( $tagUpdates );
header( 'Content-Type: text/plain' );
print 'OK';
} else {
fail( 'Unknown action: ' . $_POST['action'] );
}
$_DB->close();
?>