7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
8 if (! $connect) { |
8 if (! $connect) { |
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
10 } |
10 } |
11 mysqli_set_charset($connect, "utf8" ); |
11 mysqli_set_charset($connect, "utf8" ); |
|
12 |
|
13 $response = array( |
|
14 'error' => false, |
|
15 'msg' => 'Ok', |
|
16 ); |
12 |
17 |
13 $rescapers = array("'"); |
18 $rescapers = array("'"); |
14 $rreplacements = array("\\'"); |
19 $rreplacements = array("\\'"); |
15 |
20 |
16 if (isset($_POST['insert']) || isset($_POST['update'])) { |
21 if (isset($_POST['insert']) || isset($_POST['update'])) { |
58 $sql .= "';"; |
63 $sql .= "';"; |
59 } |
64 } |
60 if (isset($_POST['update'])) { |
65 if (isset($_POST['update'])) { |
61 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
66 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
62 } |
67 } |
63 //syslog(LOG_NOTICE, $sql); |
|
64 |
|
65 $result = mysqli_query($connect, $sql); |
68 $result = mysqli_query($connect, $sql); |
66 if (! $result) { |
69 if (! $result) { |
67 syslog(LOG_NOTICE, "db_profile_fermentation: ".$sql." result: ".mysqli_error($connect)); |
70 syslog(LOG_NOTICE, "db_profile_fermentation: ".$sql." result: ".mysqli_error($connect)); |
68 //} else { |
71 $response['error'] = true; |
69 // if (isset($_POST['update'])) { |
72 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
70 // syslog(LOG_NOTICE, "db_profile_fermentation: updated record ".$_POST['record']); |
73 } |
71 // } else { |
74 exit(json_encode($response)); |
72 // $lastid = mysqli_insert_id($connect); |
|
73 // syslog(LOG_NOTICE, "db_profile_fermentation: inserted record ".$lastid); |
|
74 // } |
|
75 } |
|
76 echo $result; |
|
77 |
75 |
78 } else if (isset($_POST['delete'])) { |
76 } else if (isset($_POST['delete'])) { |
79 // DELETE COMMAND |
77 // DELETE COMMAND |
80 $sql = "DELETE FROM `profile_fermentation` WHERE record='".$_POST['record']."';"; |
78 $sql = "DELETE FROM `profile_fermentation` WHERE record='".$_POST['record']."';"; |
81 $result = mysqli_query($connect, $sql); |
79 $result = mysqli_query($connect, $sql); |
82 if (! $result) { |
80 if (! $result) { |
83 syslog(LOG_NOTICE, "db_profile_fermentation: ".$sql." result: ".mysqli_error($connect)); |
81 syslog(LOG_NOTICE, "db_profile_fermentation: ".$sql." result: ".mysqli_error($connect)); |
84 } else { |
82 $response['error'] = true; |
85 syslog(LOG_NOTICE, "db_profile_fermentation: deleted record ".$_POST['record']); |
83 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
86 } |
84 } |
87 echo $result; |
85 exit(json_encode($response)); |
88 |
86 |
89 } else { |
87 } else { |
90 // SELECT COMMAND |
88 // SELECT COMMAND |
91 $query = "SELECT record,JSON_QUOTE(uuid),JSON_QUOTE(name),inittemp_lo,inittemp_hi,fridgemode,totalsteps,duration,steps "; |
89 $query = "SELECT record,JSON_QUOTE(uuid),JSON_QUOTE(name),inittemp_lo,inittemp_hi,fridgemode,totalsteps,duration,steps "; |
92 $query .= "FROM profile_fermentation ORDER BY name;"; |
90 $query .= "FROM profile_fermentation ORDER BY name;"; |
109 $profiles .= ',"duration":' . $row['duration']; |
107 $profiles .= ',"duration":' . $row['duration']; |
110 $profiles .= ',"steps":' . $row['steps']; |
108 $profiles .= ',"steps":' . $row['steps']; |
111 $profiles .= '}'; |
109 $profiles .= '}'; |
112 } |
110 } |
113 $profiles .= ']'; |
111 $profiles .= ']'; |
114 // syslog(LOG_NOTICE, $profiles); |
|
115 header("Content-type: application/json"); |
112 header("Content-type: application/json"); |
116 echo $profiles; |
113 exit($profiles); |
117 } |
114 } |
|
115 |
|
116 syslog(LOG_NOTICE, "db_profile_fermentation: missing arguments"); |
|
117 $response['error'] = true; |
|
118 $response['msg'] = "missing arguments"; |
|
119 echo json_encode($response); |
|
120 |
118 ?> |
121 ?> |