www/includes/db_product.php

changeset 235
0a063ac5d7f5
parent 192
7f69b43e6084
child 237
9337b5ff8698
equal deleted inserted replaced
234:b8b5efa495bb 235:0a063ac5d7f5
23 if (isset($_POST['update'])) { 23 if (isset($_POST['update'])) {
24 $sql = "UPDATE `products` SET "; 24 $sql = "UPDATE `products` SET ";
25 } 25 }
26 26
27 $stage = $_POST['stage']; 27 $stage = $_POST['stage'];
28 if ($stage == 'Plan')
29 $stageno = 0;
30 else if ($stage == 'Wait')
31 $stageno = 1;
32 else if ($stage == 'Brew')
33 $stageno = 2;
34 else if ($stage == 'Primary')
35 $stageno = 3;
36 else if ($stage == 'Secondary')
37 $stageno = 4;
38 else if ($stage == 'Tertiary')
39 $stageno = 5;
40 else if ($stage == 'Package')
41 $stageno = 6;
42 else if ($stage == 'Carbonation')
43 $stageno = 7;
44 else if ($stage == 'Mature')
45 $stageno = 8;
46 else if ($stage == 'Taste')
47 $stageno = 9;
48 else if ($stage == 'Ready')
49 $stageno = 10;
50 else if ($stage == 'Closed')
51 $stageno = 11;
52 28
53 // Basic settings 29 // Basic settings
54 if (isset($_POST['uuid'])) { 30 if (isset($_POST['uuid'])) {
55 $sql .= "uuid='" . $_POST['uuid']; 31 $sql .= "uuid='" . $_POST['uuid'];
56 syslog(LOG_NOTICE, 'Keep uuid '); 32 syslog(LOG_NOTICE, 'Keep uuid ');
317 } else { 293 } else {
318 /* 294 /*
319 * SELECT, produce a list of products that are not yet Closed. 295 * SELECT, produce a list of products that are not yet Closed.
320 */ 296 */
321 if (isset($_GET['select']) && ($_GET['select'] == "inprod")) { 297 if (isset($_GET['select']) && ($_GET['select'] == "inprod")) {
322 $query = "SELECT record,name,code,birth,stage FROM products WHERE stage != 'Closed' ORDER BY birth,code;"; 298 $query = "SELECT record,name,code,birth,stage FROM products WHERE stage != '11' ORDER BY birth,code;";
323 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 299 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
324 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 300 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
325 $brews[] = array( 301 $brews[] = array(
326 'record' => $row['record'], 302 'record' => $row['record'],
327 'name' => $row['name'], 303 'name' => $row['name'],
328 'code' => $row['code'], 304 'code' => $row['code'],
329 'birth' => $row['birth'], 305 'birth' => $row['birth'],
330 'stage' => $row['stage'] 306 'stage' => $row['stage']
331 ); 307 );
332 } 308 }
333 echo json_encode($brews); 309 echo json_encode($brews, JSON_UNESCAPED_UNICODE);
334 return; 310 return;
335 } 311 }
336 312
337 /* 313 /*
338 * SELECT, produce a list of products that can be fermented. 314 * SELECT, produce a list of products that can be fermented.
339 */ 315 */
340 if (isset($_GET['select']) && ($_GET['select'] == "ferment")) { 316 if (isset($_GET['select']) && ($_GET['select'] == "ferment")) {
341 $query = "SELECT code,name,uuid,stage FROM products WHERE "; 317 $query = "SELECT code,name,uuid,stage FROM products WHERE ";
342 $query .= "stage='Wait' OR stage='Brew' OR stage='Primary' OR stage='Secondary' OR stage='Tertiary' OR stage='Carbonation' ORDER BY code;"; 318 $query .= "stage='1' OR stage='2' OR stage='3' OR stage='4' OR stage='5' OR stage='6' ORDER BY code;";
343 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 319 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
344 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 320 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
345 $brews[] = array( 321 $brews[] = array(
346 'code' => $row['code'], 322 'code' => $row['code'],
347 'name' => $row['name'], 323 'name' => $row['name'],
348 'uuid' => $row['uuid'], 324 'uuid' => $row['uuid'],
349 'stage' => $row['stage'] 325 'stage' => $row['stage']
350 ); 326 );
351 } 327 }
352 echo json_encode($brews); 328 echo json_encode($brews, JSON_UNESCAPED_UNICODE);
353 return; 329 return;
354 } 330 }
355 331
356 /* 332 /*
357 * Default, select all or a given record. 333 * Default, select all or a given record.
372 $brew = '{"record":' . $row['record']; 348 $brew = '{"record":' . $row['record'];
373 $brew .= ',"uuid":"' . str_replace($escapers, $replacements, $row['uuid']); 349 $brew .= ',"uuid":"' . str_replace($escapers, $replacements, $row['uuid']);
374 $brew .= '","name":"' . str_replace($escapers, $replacements, $row['name']); 350 $brew .= '","name":"' . str_replace($escapers, $replacements, $row['name']);
375 $brew .= '","code":"' . str_replace($escapers, $replacements, $row['code']); 351 $brew .= '","code":"' . str_replace($escapers, $replacements, $row['code']);
376 $brew .= '","birth":"' . str_replace($escapers, $replacements, $row['birth']); 352 $brew .= '","birth":"' . str_replace($escapers, $replacements, $row['birth']);
377 $brew .= '","stage":"' . str_replace($escapers, $replacements, $row['stage']); 353 $brew .= '","stage":' . $row['stage'];
378 $brew .= '","notes":"' . str_replace($escapers, $replacements, $row['notes']); 354 $brew .= ',"notes":"' . str_replace($escapers, $replacements, $row['notes']);
379 $brew .= '","log_brew":' . $row['log_brew']; 355 $brew .= '","log_brew":' . $row['log_brew'];
380 $brew .= ',"log_fermentation":' . $row['log_fermentation']; 356 $brew .= ',"log_fermentation":' . $row['log_fermentation'];
381 $brew .= ',"inventory_reduced":' . $row['inventory_reduced']; 357 $brew .= ',"inventory_reduced":' . $row['inventory_reduced'];
382 $brew .= ',"locked":' . $row['locked']; 358 $brew .= ',"locked":' . $row['locked'];
383 $brew .= ',"eq_name":"' . str_replace($escapers, $replacements, $row['eq_name']); 359 $brew .= ',"eq_name":"' . str_replace($escapers, $replacements, $row['eq_name']);
385 $brew .= '","eq_boil_size":' . floatval($row['eq_boil_size']); 361 $brew .= '","eq_boil_size":' . floatval($row['eq_boil_size']);
386 $brew .= ',"eq_batch_size":' . floatval($row['eq_batch_size']); 362 $brew .= ',"eq_batch_size":' . floatval($row['eq_batch_size']);
387 $brew .= ',"eq_tun_volume":' . floatval($row['eq_tun_volume']); 363 $brew .= ',"eq_tun_volume":' . floatval($row['eq_tun_volume']);
388 $brew .= ',"eq_tun_weight":' . floatval($row['eq_tun_weight']); 364 $brew .= ',"eq_tun_weight":' . floatval($row['eq_tun_weight']);
389 $brew .= ',"eq_tun_specific_heat":' . floatval($row['eq_tun_specific_heat']); 365 $brew .= ',"eq_tun_specific_heat":' . floatval($row['eq_tun_specific_heat']);
390 $brew .= ',"eq_tun_material":"' . $row['eq_tun_material']; 366 $brew .= ',"eq_tun_material":' . $row['eq_tun_material'];
391 $brew .= '","eq_tun_height":' . floatval($row['eq_tun_height']); 367 $brew .= ',"eq_tun_height":' . floatval($row['eq_tun_height']);
392 $brew .= ',"eq_top_up_water":' . floatval($row['eq_top_up_water']); 368 $brew .= ',"eq_top_up_water":' . floatval($row['eq_top_up_water']);
393 $brew .= ',"eq_trub_chiller_loss":' . floatval($row['eq_trub_chiller_loss']); 369 $brew .= ',"eq_trub_chiller_loss":' . floatval($row['eq_trub_chiller_loss']);
394 $brew .= ',"eq_evap_rate":' . floatval($row['eq_evap_rate']); 370 $brew .= ',"eq_evap_rate":' . floatval($row['eq_evap_rate']);
395 $brew .= ',"eq_boil_time":' . floatval($row['eq_boil_time']); 371 $brew .= ',"eq_boil_time":' . floatval($row['eq_boil_time']);
396 $brew .= ',"eq_calc_boil_volume":' . $row['eq_calc_boil_volume']; 372 $brew .= ',"eq_calc_boil_volume":' . $row['eq_calc_boil_volume'];
417 $brew .= ',"brew_preboil_ph":' . floatval($row['brew_preboil_ph']); 393 $brew .= ',"brew_preboil_ph":' . floatval($row['brew_preboil_ph']);
418 $brew .= ',"brew_aboil_volume":' . floatval($row['brew_aboil_volume']); 394 $brew .= ',"brew_aboil_volume":' . floatval($row['brew_aboil_volume']);
419 $brew .= ',"brew_aboil_sg":' . floatval($row['brew_aboil_sg']); 395 $brew .= ',"brew_aboil_sg":' . floatval($row['brew_aboil_sg']);
420 $brew .= ',"brew_aboil_ph":' . floatval($row['brew_aboil_ph']); 396 $brew .= ',"brew_aboil_ph":' . floatval($row['brew_aboil_ph']);
421 $brew .= ',"brew_aboil_efficiency":' . floatval($row['brew_aboil_efficiency']); 397 $brew .= ',"brew_aboil_efficiency":' . floatval($row['brew_aboil_efficiency']);
422 $brew .= ',"brew_cooling_method":"' . $row['brew_cooling_method']; 398 $brew .= ',"brew_cooling_method":' . $row['brew_cooling_method'];
423 $brew .= '","brew_cooling_time":' . floatval($row['brew_cooling_time']); 399 $brew .= ',"brew_cooling_time":' . floatval($row['brew_cooling_time']);
424 $brew .= ',"brew_cooling_to":' . floatval($row['brew_cooling_to']); 400 $brew .= ',"brew_cooling_to":' . floatval($row['brew_cooling_to']);
425 $brew .= ',"brew_whirlpool9":' . floatval($row['brew_whirlpool9']); 401 $brew .= ',"brew_whirlpool9":' . floatval($row['brew_whirlpool9']);
426 $brew .= ',"brew_whirlpool7":' . floatval($row['brew_whirlpool7']); 402 $brew .= ',"brew_whirlpool7":' . floatval($row['brew_whirlpool7']);
427 $brew .= ',"brew_whirlpool6":' . floatval($row['brew_whirlpool6']); 403 $brew .= ',"brew_whirlpool6":' . floatval($row['brew_whirlpool6']);
428 $brew .= ',"brew_whirlpool2":' . floatval($row['brew_whirlpool2']); 404 $brew .= ',"brew_whirlpool2":' . floatval($row['brew_whirlpool2']);
429 $brew .= ',"brew_fermenter_volume":' . floatval($row['brew_fermenter_volume']); 405 $brew .= ',"brew_fermenter_volume":' . floatval($row['brew_fermenter_volume']);
430 $brew .= ',"brew_fermenter_extrawater":' . floatval($row['brew_fermenter_extrawater']); 406 $brew .= ',"brew_fermenter_extrawater":' . floatval($row['brew_fermenter_extrawater']);
431 $brew .= ',"brew_aeration_time":' . floatval($row['brew_aeration_time']); 407 $brew .= ',"brew_aeration_time":' . floatval($row['brew_aeration_time']);
432 $brew .= ',"brew_aeration_speed":' . floatval($row['brew_aeration_speed']); 408 $brew .= ',"brew_aeration_speed":' . floatval($row['brew_aeration_speed']);
433 $brew .= ',"brew_aeration_type":"' . $row['brew_aeration_type']; 409 $brew .= ',"brew_aeration_type":' . $row['brew_aeration_type'];
434 $brew .= '","brew_fermenter_sg":' . floatval($row['brew_fermenter_sg']); 410 $brew .= ',"brew_fermenter_sg":' . floatval($row['brew_fermenter_sg']);
435 $brew .= ',"brew_fermenter_ibu":' . floatval($row['brew_fermenter_ibu']); 411 $brew .= ',"brew_fermenter_ibu":' . floatval($row['brew_fermenter_ibu']);
436 $brew .= ',"brew_date_end":"' . $row['brew_date_end']; 412 $brew .= ',"brew_date_end":"' . $row['brew_date_end'];
437 $brew .= '","brew_log_available":' . $row['brew_log_available']; 413 $brew .= '","brew_log_available":' . $row['brew_log_available'];
438 $brew .= ',"og":' . floatval($row['og']); 414 $brew .= ',"og":' . floatval($row['og']);
439 $brew .= ',"fg":' . floatval($row['fg']); 415 $brew .= ',"fg":' . floatval($row['fg']);
446 $brew .= ',"secondary_end_date":"' . $row['secondary_end_date']; 422 $brew .= ',"secondary_end_date":"' . $row['secondary_end_date'];
447 $brew .= '","tertiary_temp":' . floatval($row['tertiary_temp']); 423 $brew .= '","tertiary_temp":' . floatval($row['tertiary_temp']);
448 $brew .= ',"package_date":"' . $row['package_date']; 424 $brew .= ',"package_date":"' . $row['package_date'];
449 $brew .= '","bottle_amount":' . floatval($row['bottle_amount']); 425 $brew .= '","bottle_amount":' . floatval($row['bottle_amount']);
450 $brew .= ',"bottle_carbonation":' . floatval($row['bottle_carbonation']); 426 $brew .= ',"bottle_carbonation":' . floatval($row['bottle_carbonation']);
451 $brew .= ',"bottle_priming_sugar":"' . str_replace($escapers, $replacements, $row['bottle_priming_sugar']); 427 $brew .= ',"bottle_priming_sugar":' . $row['bottle_priming_sugar'];
452 $brew .= '","bottle_priming_amount":' . floatval($row['bottle_priming_amount']); 428 $brew .= ',"bottle_priming_amount":' . floatval($row['bottle_priming_amount']);
453 $brew .= ',"bottle_carbonation_temp":' . floatval($row['bottle_carbonation_temp']); 429 $brew .= ',"bottle_carbonation_temp":' . floatval($row['bottle_carbonation_temp']);
454 $brew .= ',"keg_amount":' . floatval($row['keg_amount']); 430 $brew .= ',"keg_amount":' . floatval($row['keg_amount']);
455 $brew .= ',"keg_carbonation":' . floatval($row['keg_carbonation']); 431 $brew .= ',"keg_carbonation":' . floatval($row['keg_carbonation']);
456 $brew .= ',"keg_priming_sugar":"' . str_replace($escapers, $replacements, $row['keg_priming_sugar']); 432 $brew .= ',"keg_priming_sugar":' . $row['keg_priming_sugar'];
457 $brew .= '","keg_priming_amount":' . floatval($row['keg_priming_amount']); 433 $brew .= ',"keg_priming_amount":' . floatval($row['keg_priming_amount']);
458 $brew .= ',"keg_carbonation_temp":' . floatval($row['keg_carbonation_temp']); 434 $brew .= ',"keg_carbonation_temp":' . floatval($row['keg_carbonation_temp']);
459 $brew .= ',"keg_forced_carb":' . floatval($row['keg_forced_carb']); 435 $brew .= ',"keg_forced_carb":' . floatval($row['keg_forced_carb']);
460 $brew .= ',"keg_pressure":' . floatval($row['keg_pressure']); 436 $brew .= ',"keg_pressure":' . floatval($row['keg_pressure']);
461 $brew .= ',"taste_notes":"' . str_replace($escapers, $replacements, $row['taste_notes']); 437 $brew .= ',"taste_notes":"' . str_replace($escapers, $replacements, $row['taste_notes']);
462 $brew .= '","taste_rate":' . floatval($row['taste_rate']); 438 $brew .= '","taste_rate":' . floatval($row['taste_rate']);
469 $brew .= '","taste_mouthfeel":"' . str_replace($escapers, $replacements, $row['taste_mouthfeel']); 445 $brew .= '","taste_mouthfeel":"' . str_replace($escapers, $replacements, $row['taste_mouthfeel']);
470 $brew .= '","taste_aftertaste":"' . str_replace($escapers, $replacements, $row['taste_aftertaste']); 446 $brew .= '","taste_aftertaste":"' . str_replace($escapers, $replacements, $row['taste_aftertaste']);
471 $brew .= '","st_guide":"' . str_replace($escapers, $replacements, $row['st_guide']); 447 $brew .= '","st_guide":"' . str_replace($escapers, $replacements, $row['st_guide']);
472 $brew .= '","st_letter":"' . str_replace($escapers, $replacements, $row['st_letter']); 448 $brew .= '","st_letter":"' . str_replace($escapers, $replacements, $row['st_letter']);
473 $brew .= '","st_name":"' . str_replace($escapers, $replacements, $row['st_name']); 449 $brew .= '","st_name":"' . str_replace($escapers, $replacements, $row['st_name']);
474 $brew .= '","st_type":"' . str_replace($escapers, $replacements, $row['st_type']); 450 $brew .= '","st_type":' . $row['st_type'];
475 $brew .= '","st_category":"' . str_replace($escapers, $replacements, $row['st_category']); 451 $brew .= ',"st_category":"' . str_replace($escapers, $replacements, $row['st_category']);
476 $brew .= '","st_category_number":' . floatval($row['st_category_number']); 452 $brew .= '","st_category_number":' . floatval($row['st_category_number']);
477 $brew .= ',"st_og_min":' . floatval($row['st_og_min']); 453 $brew .= ',"st_og_min":' . floatval($row['st_og_min']);
478 $brew .= ',"st_og_max":' . floatval($row['st_og_max']); 454 $brew .= ',"st_og_max":' . floatval($row['st_og_max']);
479 $brew .= ',"st_fg_min":' . floatval($row['st_fg_min']); 455 $brew .= ',"st_fg_min":' . floatval($row['st_fg_min']);
480 $brew .= ',"st_fg_max":' . floatval($row['st_fg_max']); 456 $brew .= ',"st_fg_max":' . floatval($row['st_fg_max']);
484 $brew .= ',"st_color_max":' . floatval($row['st_color_max']); 460 $brew .= ',"st_color_max":' . floatval($row['st_color_max']);
485 $brew .= ',"st_carb_min":' . floatval($row['st_carb_min']); 461 $brew .= ',"st_carb_min":' . floatval($row['st_carb_min']);
486 $brew .= ',"st_carb_max":' . floatval($row['st_carb_max']); 462 $brew .= ',"st_carb_max":' . floatval($row['st_carb_max']);
487 $brew .= ',"st_abv_min":' . floatval($row['st_abv_min']); 463 $brew .= ',"st_abv_min":' . floatval($row['st_abv_min']);
488 $brew .= ',"st_abv_max":' . floatval($row['st_abv_max']); 464 $brew .= ',"st_abv_max":' . floatval($row['st_abv_max']);
489 $brew .= ',"type":"' . $row['type']; 465 $brew .= ',"type":' . $row['type'];
490 $brew .= '","batch_size":' . floatval($row['batch_size']); 466 $brew .= ',"batch_size":' . floatval($row['batch_size']);
491 $brew .= ',"boil_size":' . floatval($row['boil_size']); 467 $brew .= ',"boil_size":' . floatval($row['boil_size']);
492 $brew .= ',"boil_time":' . floatval($row['boil_time']); 468 $brew .= ',"boil_time":' . floatval($row['boil_time']);
493 $brew .= ',"efficiency":' . floatval($row['efficiency']); 469 $brew .= ',"efficiency":' . floatval($row['efficiency']);
494 $brew .= ',"est_og":' . floatval($row['est_og']); 470 $brew .= ',"est_og":' . floatval($row['est_og']);
495 $brew .= ',"est_fg":' . floatval($row['est_fg']); 471 $brew .= ',"est_fg":' . floatval($row['est_fg']);
496 $brew .= ',"est_abv":' . floatval($row['est_abv']); 472 $brew .= ',"est_abv":' . floatval($row['est_abv']);
497 $brew .= ',"est_carb":' . floatval($row['est_carb']); 473 $brew .= ',"est_carb":' . floatval($row['est_carb']);
498 $brew .= ',"est_color":' . floatval($row['est_color']); 474 $brew .= ',"est_color":' . floatval($row['est_color']);
499 $brew .= ',"color_method":"' . $row['color_method']; 475 $brew .= ',"color_method":' . $row['color_method'];
500 $brew .= '","est_ibu":' . floatval($row['est_ibu']); 476 $brew .= ',"est_ibu":' . floatval($row['est_ibu']);
501 $brew .= ',"ibu_method":"' . $row['ibu_method']; 477 $brew .= ',"ibu_method":' . $row['ibu_method'];
502 $brew .= '","sparge_temp":' . floatval($row['sparge_temp']); 478 $brew .= ',"sparge_temp":' . floatval($row['sparge_temp']);
503 $brew .= ',"sparge_ph":' . floatval($row['sparge_ph']); 479 $brew .= ',"sparge_ph":' . floatval($row['sparge_ph']);
504 $brew .= ',"sparge_volume":' . floatval($row['sparge_volume']); 480 $brew .= ',"sparge_volume":' . floatval($row['sparge_volume']);
505 $brew .= ',"sparge_source":"' . $row['sparge_source']; 481 $brew .= ',"sparge_source":' . $row['sparge_source'];
506 $brew .= '","sparge_acid_type":"' . $row['sparge_acid_type']; 482 $brew .= ',"sparge_acid_type":' . $row['sparge_acid_type'];
507 $brew .= '","sparge_acid_perc":' . floatval($row['sparge_acid_perc']); 483 $brew .= ',"sparge_acid_perc":' . floatval($row['sparge_acid_perc']);
508 $brew .= ',"sparge_acid_amount":' . floatval($row['sparge_acid_amount']); 484 $brew .= ',"sparge_acid_amount":' . floatval($row['sparge_acid_amount']);
509 $brew .= ',"mash_ph":' . $row['mash_ph']; 485 $brew .= ',"mash_ph":' . $row['mash_ph'];
510 $brew .= ',"mash_name":"' . $row['mash_name']; 486 $brew .= ',"mash_name":"' . $row['mash_name'];
511 $brew .= '","calc_acid":' . $row['calc_acid']; 487 $brew .= '","calc_acid":' . $row['calc_acid'];
512 $brew .= ',"w1_name":"' . str_replace($escapers, $replacements, $row['w1_name']); 488 $brew .= ',"w1_name":"' . str_replace($escapers, $replacements, $row['w1_name']);
527 $brew .= ',"w2_sodium":' . $row['w2_sodium']; 503 $brew .= ',"w2_sodium":' . $row['w2_sodium'];
528 $brew .= ',"w2_magnesium":' . $row['w2_magnesium']; 504 $brew .= ',"w2_magnesium":' . $row['w2_magnesium'];
529 $brew .= ',"w2_total_alkalinity":' . $row['w2_total_alkalinity']; 505 $brew .= ',"w2_total_alkalinity":' . $row['w2_total_alkalinity'];
530 $brew .= ',"w2_ph":' . $row['w2_ph']; 506 $brew .= ',"w2_ph":' . $row['w2_ph'];
531 $brew .= ',"w2_cost":' . $row['w2_cost']; 507 $brew .= ',"w2_cost":' . $row['w2_cost'];
532 $brew .= ',"fermentables":' . $row['json_fermentables']; 508 $brew .= ',"wa_acid_name":' . $row['wa_acid_name'];
533 $brew .= ',"hops":' . $row['json_hops']; 509 $brew .= ',"wa_acid_perc":' . $row['wa_acid_perc'];
534 $brew .= ',"miscs":' . $row['json_miscs']; 510 $brew .= ',"wa_base_name":' . $row['wa_base_name'];
535 $brew .= ',"yeasts":' . $row['json_yeasts']; 511 if (isset($_GET['record'])) {
512 // Append stock information.
513 $fermentables = json_decode($row['json_fermentables'], true);
514 for ($i = 0; $i < count($fermentables); $i++) {
515 $fermentables[$i]['f_inventory'] = 0; // Not in stock
516 $fermentables[$i]['f_avail'] = 0; // Ingredient not in db
517 $sql2 = "SELECT inventory FROM inventory_fermentables ";
518 $sql2 .= "WHERE name='".str_replace($rescapers, $rreplacements, $fermentables[$i]['f_name'])."' AND";
519 $sql2 .= " supplier='".str_replace($rescapers, $rreplacements, $fermentables[$i]['f_supplier'])."'";
520 if ($result2 = mysqli_query($connect, $sql2)) {
521 if ($obj = mysqli_fetch_object($result2)) {
522 $fermentables[$i]['f_inventory'] = floatval($obj->inventory);
523 $fermentables[$i]['f_avail'] = 1;
524 }
525 mysqli_free_result($result2);
526 }
527 }
528 $brew .= ',"fermentables":' . json_encode($fermentables, JSON_UNESCAPED_UNICODE);
529
530 $hops = json_decode($row['json_hops'], true);
531 for ($i = 0; $i < count($hops); $i++) {
532 $hops[$i]['h_inventory'] = 0; // Not in stock
533 $hops[$i]['h_avail'] = 0; // Ingredient not in db
534 $sql2 = "SELECT inventory FROM inventory_hops ";
535 $sql2 .= "WHERE name='".str_replace($rescapers, $rreplacements, $hops[$i]['h_name'])."' AND";
536 $sql2 .= " origin='".str_replace($rescapers, $rreplacements, $hops[$i]['h_origin'])."' AND";
537 $sql2 .= " form='".$hops[$i]['h_form']."'";
538 if ($result2 = mysqli_query($connect, $sql2)) {
539 if ($obj = mysqli_fetch_object($result2)) {
540 $hops[$i]['h_inventory'] = floatval($obj->inventory);
541 $hops[$i]['h_avail'] = 1;
542 }
543 mysqli_free_result($result2);
544 }
545 }
546 $brew .= ',"hops":' . json_encode($hops, JSON_UNESCAPED_UNICODE);
547
548 $miscs = json_decode($row['json_miscs'], true);
549 for ($i = 0; $i < count($miscs); $i++) {
550 $miscs[$i]['m_inventory'] = 0; // Not in stock
551 $miscs[$i]['m_avail'] = 0; // Ingredient not in db
552 $sql2 = "SELECT inventory FROM inventory_miscs ";
553 $sql2 .= "WHERE name='".str_replace($rescapers, $rreplacements, $miscs[$i]['m_name'])."' AND";
554 $sql2 .= " type='".$miscs[$i]['m_type']."'";
555 if ($result2 = mysqli_query($connect, $sql2)) {
556 if ($obj = mysqli_fetch_object($result2)) {
557 $miscs[$i]['m_inventory'] = floatval($obj->inventory);
558 $miscs[$i]['m_avail'] = 1;
559 }
560 mysqli_free_result($result2);
561 }
562 }
563 $brew .= ',"miscs":' . json_encode($miscs, JSON_UNESCAPED_UNICODE);
564
565 $yeasts = json_decode($row['json_yeasts'], true);
566 for ($i = 0; $i < count($yeasts); $i++) {
567 $yeasts[$i]['y_inventory'] = 0; // Not in stock
568 $yeasts[$i]['y_avail'] = 0; // Ingredient not in db
569 $sql2 = "SELECT inventory FROM inventory_yeasts ";
570 $sql2 .= "WHERE name='".str_replace($rescapers, $rreplacements, $yeasts[$i]['y_name'])."' AND";
571 $sql2 .= " form='".str_replace($rescapers, $rreplacements, $yeasts[$i]['y_form'])."' AND";
572 $sql2 .= " laboratory='".str_replace($rescapers, $rreplacements, $yeasts[$i]['y_laboratory'])."' AND";
573 $sql2 .= " product_id='".str_replace($rescapers, $rreplacements, $yeasts[$i]['y_product_id'])."'";
574 if ($result2 = mysqli_query($connect, $sql2)) {
575 if ($obj = mysqli_fetch_object($result2)) {
576 $yeasts[$i]['y_inventory'] = floatval($obj->inventory);
577 $yeasts[$i]['y_avail'] = 1;
578 }
579 mysqli_free_result($result2);
580 }
581 }
582 $brew .= ',"yeasts":' . json_encode($yeasts, JSON_UNESCAPED_UNICODE);
583 } else {
584 // Just leave it
585 $brew .= ',"fermentables":' . $row['json_fermentables'];
586 $brew .= ',"hops":' . $row['json_hops'];
587 $brew .= ',"miscs":' . $row['json_miscs'];
588 $brew .= ',"yeasts":' . $row['json_yeasts'];
589 }
536 $brew .= ',"mashs":' . $row['json_mashs']; 590 $brew .= ',"mashs":' . $row['json_mashs'];
537 $brew .= '}'; 591 $brew .= '}';
538 // syslog(LOG_NOTICE, $brew); 592 // syslog(LOG_NOTICE, $brew);
539 $brews .= $brew; 593 $brews .= $brew;
540 } 594 }

mercurial