www/includes/db_recipes.php

changeset 352
9d2a4703bdac
parent 350
c314277905e6
child 359
98354ef399cd
equal deleted inserted replaced
351:58c350f286e5 352:9d2a4703bdac
242 $mash .= ',"step_infuse_amount":' . $item['step_infuse_amount']; 242 $mash .= ',"step_infuse_amount":' . $item['step_infuse_amount'];
243 else 243 else
244 $mash .= ',"step_infuse_amount":0'; 244 $mash .= ',"step_infuse_amount":0';
245 $mash .= ',"step_temp":' . $item['step_temp']; 245 $mash .= ',"step_temp":' . $item['step_temp'];
246 $mash .= ',"step_time":' . $item['step_time']; 246 $mash .= ',"step_time":' . $item['step_time'];
247 $mash .= ',"step_thickness":' . $item['step_thickness'];
248 $mash .= ',"ramp_time":' . $item['ramp_time']; 247 $mash .= ',"ramp_time":' . $item['ramp_time'];
249 $mash .= ',"end_temp":' . $item['end_temp'] . '}'; 248 $mash .= ',"end_temp":' . $item['end_temp'] . '}';
250 $mashs .= $mash; 249 $mashs .= $mash;
250 syslog(LOG_NOTICE, $mash);
251 } 251 }
252 } 252 }
253 $mashs .= ']'; 253 $mashs .= ']';
254 $sql .= "', json_mashs='" . $mashs; 254 $sql .= "', json_mashs='" . $mashs;
255 255
295 } 295 }
296 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 296 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
297 $recipes = '['; 297 $recipes = '[';
298 $comma = FALSE; 298 $comma = FALSE;
299 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 299 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
300 $mashkg = 0;
301 // Manual encode to JSON. 300 // Manual encode to JSON.
302 if ($comma) { 301 if ($comma) {
303 $recipes .= ','; 302 $recipes .= ',';
304 } 303 }
305 $comma = TRUE; 304 $comma = TRUE;
374 $recipes .= ',"wa_base_name":' . $row['wa_base_name']; 373 $recipes .= ',"wa_base_name":' . $row['wa_base_name'];
375 if (isset($_GET['record'])) { 374 if (isset($_GET['record'])) {
376 // Append stock information. 375 // Append stock information.
377 $fermentables = json_decode($row['json_fermentables'], true); 376 $fermentables = json_decode($row['json_fermentables'], true);
378 for ($i = 0; $i < count($fermentables); $i++) { 377 for ($i = 0; $i < count($fermentables); $i++) {
379 if ($fermentables[$i]['f_added'] == 0) {
380 $mashkg += $fermentables[$i]['f_amount'];
381 }
382 $fermentables[$i]['f_inventory'] = 0; // Not in stock 378 $fermentables[$i]['f_inventory'] = 0; // Not in stock
383 $fermentables[$i]['f_avail'] = 0; // Ingredient not in db 379 $fermentables[$i]['f_avail'] = 0; // Ingredient not in db
384 $sql2 = "SELECT inventory FROM inventory_fermentables "; 380 $sql2 = "SELECT inventory FROM inventory_fermentables ";
385 $sql2 .= "WHERE name='".str_replace($rescapers, $rreplacements, $fermentables[$i]['f_name'])."' AND"; 381 $sql2 .= "WHERE name='".str_replace($rescapers, $rreplacements, $fermentables[$i]['f_name'])."' AND";
386 $sql2 .= " supplier='".str_replace($rescapers, $rreplacements, $fermentables[$i]['f_supplier'])."'"; 382 $sql2 .= " supplier='".str_replace($rescapers, $rreplacements, $fermentables[$i]['f_supplier'])."'";
455 $recipes .= ',"fermentables":' . $row['json_fermentables']; 451 $recipes .= ',"fermentables":' . $row['json_fermentables'];
456 $recipes .= ',"hops":' . $row['json_hops']; 452 $recipes .= ',"hops":' . $row['json_hops'];
457 $recipes .= ',"miscs":' . $row['json_miscs']; 453 $recipes .= ',"miscs":' . $row['json_miscs'];
458 $recipes .= ',"yeasts":' . $row['json_yeasts']; 454 $recipes .= ',"yeasts":' . $row['json_yeasts'];
459 } 455 }
460 if (isset($_GET['record'])) { 456 $recipes .= ',"mashs":' . $row['json_mashs'];
461 $volume = 0;
462 $mashs = json_decode($row['json_mashs'], true);
463 for ($i = 0; $i < count($mashs); $i++) {
464 $volume += $mashs[$i]['step_infuse_amount'];
465 if ($mashkg > 0)
466 $mashs[$i]['step_thickness'] = floatval(sprintf("%.3f", $volume / $mashkg));
467 else
468 $mashs[$i]['step_thickness'] = 0;
469 }
470 $recipes .= ',"mashs":' . json_encode($mashs, JSON_UNESCAPED_UNICODE);
471 } else {
472 $recipes .= ',"mashs":' . $row['json_mashs'];
473 }
474 $recipes .= '}'; 457 $recipes .= '}';
475 } 458 }
476 $recipes .= ']'; 459 $recipes .= ']';
477 header("Content-type: application/json"); 460 header("Content-type: application/json");
478 echo $recipes; 461 echo $recipes;

mercurial