13 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"); |
13 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"); |
14 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); |
14 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); |
15 $rescapers = array("'"); |
15 $rescapers = array("'"); |
16 $rreplacements = array("\\'"); |
16 $rreplacements = array("\\'"); |
17 $disallowed = array('visibleindex','uniqueid','boundindex','uid','h_weight','m_weight'); |
17 $disallowed = array('visibleindex','uniqueid','boundindex','uid','h_weight','m_weight'); |
|
18 |
|
19 $response = array( |
|
20 'error' => false, |
|
21 'msg' => 'Ok', |
|
22 ); |
18 |
23 |
19 if (isset($_POST['insert']) || isset($_POST['update'])) { |
24 if (isset($_POST['insert']) || isset($_POST['update'])) { |
20 if (isset($_POST['insert'])) { |
25 if (isset($_POST['insert'])) { |
21 // INSERT COMMAND |
26 // INSERT COMMAND |
22 $sql = "INSERT INTO `recipes` SET "; |
27 $sql = "INSERT INTO `recipes` SET "; |
351 } |
356 } |
352 |
357 |
353 $result = mysqli_query($connect, $sql); |
358 $result = mysqli_query($connect, $sql); |
354 if (! $result) { |
359 if (! $result) { |
355 syslog(LOG_NOTICE, "db_recipes: result: ".mysqli_error($connect)); |
360 syslog(LOG_NOTICE, "db_recipes: result: ".mysqli_error($connect)); |
|
361 $response['error'] = true; |
|
362 $response['msg'] = "SQL fout: ".mysqli_error($connect); |
356 } else { |
363 } else { |
357 if (isset($_POST['update'])) { |
364 if (isset($_POST['update'])) { |
358 syslog(LOG_NOTICE, "db_recipes: updated record ".$_POST['record']); |
365 //syslog(LOG_NOTICE, "db_recipes: updated record ".$_POST['record']); |
359 } else { |
366 } else { |
360 $lastid = mysqli_insert_id($connect); |
367 $lastid = mysqli_insert_id($connect); |
361 syslog(LOG_NOTICE, "db_recipes: inserted record ".$lastid); |
368 //syslog(LOG_NOTICE, "db_recipes: inserted record ".$lastid); |
362 } |
369 } |
363 } |
370 } |
364 echo $result; |
371 echo json_encode($response); |
365 |
372 |
366 } else if (isset($_POST['delete'])) { |
373 } else if (isset($_POST['delete'])) { |
367 // DELETE COMMAND |
374 // DELETE COMMAND |
368 $sql = "DELETE FROM `recipes` WHERE record='".$_POST['record']."';"; |
375 $sql = "DELETE FROM `recipes` WHERE record='".$_POST['record']."';"; |
369 $result = mysqli_query($connect, $sql); |
376 $result = mysqli_query($connect, $sql); |
370 if (! $result) { |
377 if (! $result) { |
371 syslog(LOG_NOTICE, "db_recipes: result: ".mysqli_error($connect)); |
378 syslog(LOG_NOTICE, "db_recipes: result: ".mysqli_error($connect)); |
|
379 $response['error'] = true; |
|
380 $response['msg'] = "SQL delete fout: ".mysqli_error($connect); |
372 } else { |
381 } else { |
373 syslog(LOG_NOTICE, "db_recipes: deleted record ".$_POST['record']); |
382 syslog(LOG_NOTICE, "db_recipes: deleted record ".$_POST['record']); |
374 } |
383 } |
375 echo $result; |
384 echo json_encode($response); |
376 |
385 |
377 } else { |
386 } else { |
378 /* |
387 /* |
379 * Select all or a given record. |
388 * Select all or a given record. |
380 */ |
389 */ |
560 if (! isset($yeasts[$i]['y_pitch_temperature'])) |
569 if (! isset($yeasts[$i]['y_pitch_temperature'])) |
561 $yeasts[$i]['y_pitch_temperature'] = floatval($obj->pitch_temperature); |
570 $yeasts[$i]['y_pitch_temperature'] = floatval($obj->pitch_temperature); |
562 if (! isset($yeasts[$i]['y_pofpos'])) |
571 if (! isset($yeasts[$i]['y_pofpos'])) |
563 $yeasts[$i]['y_pofpos'] = intval($obj->pofpos); |
572 $yeasts[$i]['y_pofpos'] = intval($obj->pofpos); |
564 if (! isset($yeasts[$i]['y_zymocide'])) |
573 if (! isset($yeasts[$i]['y_zymocide'])) |
565 $yeasts[$i]['y_zymocide'] = intval($obj->zymocide); |
574 $yeasts[$i]['y_zymocide'] = intval($obj->zymocide); |
|
575 if (! isset($yeasts[$i]['y_gr_hl_lo'])) |
|
576 $yeasts[$i]['y_gr_hl_lo'] = intval($obj->gr_hl_lo); |
|
577 if (! isset($yeasts[$i]['y_sg_lo'])) |
|
578 $yeasts[$i]['y_sg_lo'] = floatval($obj->sg_lo); |
|
579 if (! isset($yeasts[$i]['y_gr_hl_hi'])) |
|
580 $yeasts[$i]['y_gr_hl_hi'] = intval($obj->gr_hl_hi); |
|
581 if (! isset($yeasts[$i]['y_sg_hi'])) |
|
582 $yeasts[$i]['y_sg_hi'] = floatval($obj->sg_hi); |
566 } else { |
583 } else { |
567 if (! isset($yeasts[$i]['y_sta1'])) |
584 if (! isset($yeasts[$i]['y_sta1'])) |
568 $yeasts[$i]['y_sta1'] = 0; |
585 $yeasts[$i]['y_sta1'] = 0; |
569 if (! isset($yeasts[$i]['y_bacteria'])) |
586 if (! isset($yeasts[$i]['y_bacteria'])) |
570 $yeasts[$i]['y_bacteria'] = 0; |
587 $yeasts[$i]['y_bacteria'] = 0; |
575 if (! isset($yeasts[$i]['y_pitch_temperature'])) |
592 if (! isset($yeasts[$i]['y_pitch_temperature'])) |
576 $yeasts[$i]['y_pitch_temperature'] = 0; |
593 $yeasts[$i]['y_pitch_temperature'] = 0; |
577 if (! isset($yeasts[$i]['y_pofpos'])) |
594 if (! isset($yeasts[$i]['y_pofpos'])) |
578 $yeasts[$i]['y_pofpos'] = 0; |
595 $yeasts[$i]['y_pofpos'] = 0; |
579 if (! isset($yeasts[$i]['y_zymocide'])) |
596 if (! isset($yeasts[$i]['y_zymocide'])) |
580 $yeasts[$i]['y_zymocide'] = 0; |
597 $yeasts[$i]['y_zymocide'] = 0; |
|
598 if (! isset($yeasts[$i]['y_gr_hl_lo'])) |
|
599 $yeasts[$i]['y_gr_hl_lo'] = 50; |
|
600 if (! isset($yeasts[$i]['y_sg_lo'])) |
|
601 $yeasts[$i]['y_sg_lo'] = 1.04; |
|
602 if (! isset($yeasts[$i]['y_gr_hl_hi'])) |
|
603 $yeasts[$i]['y_gr_hl_hi'] = 80; |
|
604 if (! isset($yeasts[$i]['y_sg_hi'])) |
|
605 $yeasts[$i]['y_sg_hi'] = 1.08; |
581 } |
606 } |
582 mysqli_free_result($result2); |
607 mysqli_free_result($result2); |
583 } |
608 } |
584 } |
609 } |
585 //syslog(LOG_NOTICE, json_encode($yeasts, JSON_UNESCAPED_UNICODE)); |
610 //syslog(LOG_NOTICE, json_encode($yeasts, JSON_UNESCAPED_UNICODE)); |