10 } |
10 } |
11 mysqli_set_charset($connect, "utf8" ); |
11 mysqli_set_charset($connect, "utf8" ); |
12 |
12 |
13 $rescapers = array("'"); |
13 $rescapers = array("'"); |
14 $rreplacements = array("\\'"); |
14 $rreplacements = array("\\'"); |
|
15 |
|
16 $response = array( |
|
17 'error' => false, |
|
18 'msg' => 'Ok', |
|
19 ); |
15 |
20 |
16 if (isset($_POST['insert']) || isset($_POST['update'])) { |
21 if (isset($_POST['insert']) || isset($_POST['update'])) { |
17 if (isset($_POST['insert'])) { |
22 if (isset($_POST['insert'])) { |
18 $sql = "INSERT INTO"; |
23 $sql = "INSERT INTO"; |
19 } |
24 } |
46 $sql .= "';"; |
51 $sql .= "';"; |
47 } |
52 } |
48 if (isset($_POST['update'])) { |
53 if (isset($_POST['update'])) { |
49 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
54 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
50 } |
55 } |
51 //syslog(LOG_NOTICE, $sql); |
|
52 |
|
53 $result = mysqli_query($connect, $sql); |
56 $result = mysqli_query($connect, $sql); |
54 if (! $result) { |
57 if (! $result) { |
55 syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect)); |
58 syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect)); |
56 //} else { |
59 $response['error'] = true; |
57 // if (isset($_POST['update'])) { |
60 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
58 // syslog(LOG_NOTICE, "db_profile_mash: updated record ".$_POST['record']); |
61 } |
59 // } else { |
62 exit(json_encode($response)); |
60 // $lastid = mysqli_insert_id($connect); |
|
61 // syslog(LOG_NOTICE, "db_profile_mash: inserted record ".$lastid); |
|
62 // } |
|
63 } |
|
64 echo $result; |
|
65 |
63 |
66 } else if (isset($_POST['delete'])) { |
64 } else if (isset($_POST['delete'])) { |
67 // DELETE COMMAND |
65 // DELETE COMMAND |
68 $sql = "DELETE FROM `profile_mash` WHERE record='".$_POST['record']."';"; |
66 $sql = "DELETE FROM `profile_mash` WHERE record='".$_POST['record']."';"; |
69 $result = mysqli_query($connect, $sql); |
67 $result = mysqli_query($connect, $sql); |
70 if (! $result) { |
68 if (! $result) { |
71 syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect)); |
69 syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect)); |
72 } else { |
70 $response['error'] = true; |
73 syslog(LOG_NOTICE, "db_profile_mash: deleted record ".$_POST['record']); |
71 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
74 } |
72 } |
75 echo $result; |
73 exit(json_encode($response)); |
76 |
74 |
77 } else { |
75 } else { |
78 // SELECT COMMAND |
76 // SELECT COMMAND |
79 $query = "SELECT record,JSON_QUOTE(name),JSON_QUOTE(notes),steps FROM profile_mash ORDER BY name"; |
77 $query = "SELECT record,JSON_QUOTE(name),JSON_QUOTE(notes),steps FROM profile_mash ORDER BY name"; |
80 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
78 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
88 $comma = TRUE; |
86 $comma = TRUE; |
89 $mashprofile = '{"record":' . $row['record']; |
87 $mashprofile = '{"record":' . $row['record']; |
90 $mashprofile .= ',"name":' . $row['JSON_QUOTE(name)']; |
88 $mashprofile .= ',"name":' . $row['JSON_QUOTE(name)']; |
91 $mashprofile .= ',"notes":' . $row['JSON_QUOTE(notes)']; |
89 $mashprofile .= ',"notes":' . $row['JSON_QUOTE(notes)']; |
92 $mashprofile .= ',"steps":' . $row['steps'] . '}'; |
90 $mashprofile .= ',"steps":' . $row['steps'] . '}'; |
93 //syslog(LOG_NOTICE, $mashprofile); |
|
94 $mashprofiles .= $mashprofile; |
91 $mashprofiles .= $mashprofile; |
95 } |
92 } |
96 $mashprofiles .= ']'; |
93 $mashprofiles .= ']'; |
97 header("Content-type: application/json"); |
94 header("Content-type: application/json"); |
98 echo $mashprofiles; |
95 exit($mashprofiles); |
99 } |
96 } |
|
97 |
|
98 syslog(LOG_NOTICE, "db_profile_mash: missing arguments"); |
|
99 $response['error'] = true; |
|
100 $response['msg'] = "missing arguments"; |
|
101 echo json_encode($response); |
|
102 |
100 ?> |
103 ?> |