www/import/from_brouwhulp.php

changeset 23
4b157d7a1cee
parent 22
99c02fa797f9
child 26
af136d9eb3c5
equal deleted inserted replaced
22:99c02fa797f9 23:4b157d7a1cee
378 function do_mash() 378 function do_mash()
379 { 379 {
380 global $brouwhulp, $db; 380 global $brouwhulp, $db;
381 381
382 echo " Start adding mash profiles to the database\n"; 382 echo " Start adding mash profiles to the database\n";
383 $sql = "TRUNCATE TABLE inventory_mash_steps;";
384 if (! $result = mysqli_query($db, $sql)) {
385 printf("Error: %s\n", mysqli_error($db));
386 }
387 $sql = "TRUNCATE TABLE inventory_mash_profiles;"; 383 $sql = "TRUNCATE TABLE inventory_mash_profiles;";
388 if (! $result = mysqli_query($db, $sql)) { 384 if (! $result = mysqli_query($db, $sql)) {
389 printf("Error: %s\n", mysqli_error($db)); 385 printf("Error: %s\n", mysqli_error($db));
390 } 386 }
391 387
406 if ($mash->TUN_WEIGHT) 402 if ($mash->TUN_WEIGHT)
407 $sql .= "', tun_weight='" . $mash->TUN_WEIGHT; 403 $sql .= "', tun_weight='" . $mash->TUN_WEIGHT;
408 if ($mash->TUN_SPECIFIX_HEAT) 404 if ($mash->TUN_SPECIFIX_HEAT)
409 $sql .= "', tun_specific_heat='" . $mash->TUN_SPECIFIC_HEAT; 405 $sql .= "', tun_specific_heat='" . $mash->TUN_SPECIFIC_HEAT;
410 ($mash->EQUIP_ADJUST == 'TRUE') ? $sql .= "', equip_adjust='1" : $sql .= "', equip_adjust='0"; 406 ($mash->EQUIP_ADJUST == 'TRUE') ? $sql .= "', equip_adjust='1" : $sql .= "', equip_adjust='0";
411 $sql .= "';"; 407
412 /* 408 /*
413 * Store the record and get the record number that is created. 409 * Put the steps in a json array
414 * Store that as a reference in the steps.
415 */
416 if (! $result = mysqli_query($db, $sql)) {
417 printf("Error: %s\n", mysqli_error($db));
418 }
419 $record = mysqli_insert_id($db);
420
421 /*
422 * Put the steps in a different table with a reference to the profile.
423 */ 410 */
424 if ($mash->MASH_STEPS) { 411 if ($mash->MASH_STEPS) {
412 $steps = "[";
413 $comma = FALSE;
425 foreach ($mash->MASH_STEPS->MASH_STEP as $step) { 414 foreach ($mash->MASH_STEPS->MASH_STEP as $step) {
426 415
427 $sql = "INSERT INTO inventory_mash_steps SET name='" . mysqli_real_escape_string($db, $step->NAME); 416 if ($comma)
428 $sql .= "', rec_mash_profile='" . $record; 417 $steps .= ',';
429 if ($step->TYPE) 418 $comma = TRUE;
430 $sql .= "', type='" . $step->TYPE; 419 $steps .= '{"name":"' . mysqli_real_escape_string($db, $step->NAME) . '"';
431 if ($step->INFUSE_AMOUNT) 420 if ($step->TYPE) {
432 $sql .= "', infuse_amount='" . $step->INFUSE_AMOUNT; 421 $steps .= ',"type":"' . $step->TYPE . '"';
433 if ($step->STEP_TEMP)
434 $sql .= "', step_temp='" . $step->STEP_TEMP;
435 if ($step->STEP_TIME)
436 $sql .= "', step_time='" . $step->STEP_TIME;
437 if ($step->RAMP_TIME)
438 $sql .= "', ramp_time='" . $step->RAMP_TIME;
439 if ($step->END_TEMP)
440 $sql .= "', end_temp='" . $step->END_TEMP;
441 if ($step->DESCRIPTION)
442 $sql .= "', description='" . mysqli_real_escape_string($db, $step->DESCRIPTION);
443 $sql .= "';";
444 if (! $result = mysqli_query($db, $sql)) {
445 printf("Error: %s\n", mysqli_error($db));
446 } 422 }
423 if ($step->STEP_TEMP) {
424 $steps .= ',"step_temp":"' . $step->STEP_TEMP . '"';
425 }
426 if ($step->STEP_TIME) {
427 $steps .= ',"step_time":"' . $step->STEP_TIME . '"';
428 }
429 if ($step->RAMP_TIME) {
430 $steps .= ',"ramp_time":"' . $step->RAMP_TIME . '"';
431 }
432 if ($step->END_TEMP) {
433 $steps .= ',"end_temp":"' . $step->END_TEMP . '"';
434 }
435 $steps .= "}";
447 } 436 }
437 $steps .= ']';
438 $sql .= "', steps='" . $steps;
439 }
440 $sql .= "';";
441 if (! $result = mysqli_query($db, $sql)) {
442 printf("Error: %s\n", mysqli_error($db));
448 } 443 }
449 } 444 }
450 } 445 }
451 446
452 447
453 448
454 //do_fermentables(); 449 //do_fermentables();
455 //do_hops(); 450 //do_hops();
456 //do_yeasts(); 451 //do_yeasts();
457 //do_miscs(); 452 //do_miscs();
458 do_waters(); 453 //do_waters();
459 //do_equipments(); 454 //do_equipments();
460 //do_styles(); 455 //do_styles();
461 //do_mash(); 456 do_mash();
462 457
463 mysqli_close($db); 458 mysqli_close($db);
464 459
465 echo "Finished adding data\n"; 460 echo "Finished adding data\n";
466 461

mercurial