1 <?php |
|
2 require_once('config.php'); |
|
3 require("version.php"); |
|
4 require("includes/formulas.php"); |
|
5 |
|
6 |
|
7 $target_dir = "tmp/"; |
|
8 $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); |
|
9 $uploadOk = 1; |
|
10 $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); |
|
11 |
|
12 // Check if file already exists |
|
13 if (file_exists($target_file)) { |
|
14 echo "Fout 1: bestand bestaat al. "; |
|
15 $uploadOk = 0; |
|
16 } |
|
17 // Check file size |
|
18 if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) { |
|
19 echo "Fout 2: het bestand is te groot. "; |
|
20 $uploadOk = 0; |
|
21 } |
|
22 // Allow certain file formats |
|
23 if ($imageFileType != "xml" && $uploadOk) { |
|
24 echo "Fout 3: alleen XML bestanden toegestaan. "; |
|
25 $uploadOk = 0; |
|
26 } |
|
27 // Check if $uploadOk is set to 0 by an error |
|
28 if ($uploadOk == 0) { |
|
29 exit; |
|
30 } |
|
31 |
|
32 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { |
|
33 echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />"; |
|
34 } else { |
|
35 echo "Fout 4: er ging iets fout met de upload."; |
|
36 exit; |
|
37 } |
|
38 |
|
39 |
|
40 $db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
|
41 if (! $db) { |
|
42 echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error(); |
|
43 exit; |
|
44 } |
|
45 mysqli_set_charset($db, "utf8" ); |
|
46 date_default_timezone_set('Europe/Amsterdam'); |
|
47 |
|
48 |
|
49 $imported = 0; |
|
50 $myfermentables= simplexml_load_file($target_file); |
|
51 |
|
52 |
|
53 foreach ($myfermentables->FERMENTABLE as $fermentable) { |
|
54 |
|
55 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid')); |
|
56 $sql = "INSERT INTO inventory_fermentables SET uuid='" . $uuid; |
|
57 |
|
58 $sql .= "', name='" . mysqli_real_escape_string($db, $fermentable->NAME); |
|
59 if ($fermentable->TYPE == 'Grain') |
|
60 $sql .= "', type='0"; |
|
61 else if ($fermentable->TYPE == 'Sugar') |
|
62 $sql .= "', type='1"; |
|
63 else if ($fermentable->TYPE == 'Extract') |
|
64 $sql .= "', type='2"; |
|
65 else if ($fermentable->TYPE == 'Dry extract') |
|
66 $sql .= "', type='3"; |
|
67 else if ($fermentable->TYPE == 'Adjunct') |
|
68 $sql .= "', type='4"; |
|
69 else |
|
70 echo "Unknown TYPE " . $fermentable->TYPE . "<br />"; |
|
71 if ($fermentable->YIELD) |
|
72 $sql .= "', yield='" . floatval($fermentable->YIELD); |
|
73 if ($fermentable->COLOR) { |
|
74 $sql .= "', color='" . srm_to_ebc(floatval($fermentable->COLOR)); |
|
75 } |
|
76 ($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; |
|
77 if ($fermentable->ADDED == 'Mash') |
|
78 $sql .= "', added='0"; |
|
79 else if ($fermentable->ADDED == 'Boil') |
|
80 $sql .= "', added='1"; |
|
81 else if ($fermentable->ADDED == 'Fermentation') |
|
82 $sql .= "', added='2"; |
|
83 else if ($fermentable->ADDED == 'Lagering') |
|
84 $sql .= "', added='3"; |
|
85 else if ($fermentable->ADDED == 'Bottle') |
|
86 $sql .= "', added='4"; |
|
87 else |
|
88 echo "Unknown ADDED " . $fermentable->ADDED . "<br />"; |
|
89 |
|
90 $sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN); |
|
91 $sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER); |
|
92 $sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES); |
|
93 if ($fermentable->COARSE_FINE_DIFF) |
|
94 $sql .= "', coarse_fine_diff='" . floatval($fermentable->COARSE_FINE_DIFF); |
|
95 if ($fermentable->MOISTURE) |
|
96 $sql .= "', moisture='" . floatval($fermentable->MOISTURE); |
|
97 if ($fermentable->DIASTATIC_POWER) |
|
98 $sql .= "', diastatic_power='" . floatval($fermentable->DIASTATIC_POWER); |
|
99 if ($fermentable->PROTEIN) |
|
100 $sql .= "', protein='" . floatval($fermentable->PROTEIN); |
|
101 if ($fermentable->DISSOLVED_PROTEIN) |
|
102 $sql .= "', dissolved_protein='" . floatval($fermentable->DISSOLVED_PROTEIN); |
|
103 if ($fermentable->MAX_IN_BATCH) |
|
104 $sql .= "', max_in_batch='" . floatval($fermentable->MAX_IN_BATCH); |
|
105 ($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; |
|
106 ($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
|
107 if ($fermentable->INVENTORY) |
|
108 $sql .= "', inventory='" . floatval($fermentable->INVENTORY); |
|
109 if ($fermentable->COST) |
|
110 $sql .= "', cost='" . floatval($fermentable->COST); |
|
111 |
|
112 /* |
|
113 * These are not beerxml standard: |
|
114 */ |
|
115 if ($fermentable->DI_pH) |
|
116 $sql .= "', di_ph='" . floatval($fermentable->DI_pH); |
|
117 if ($fermentable->{'ACID_TO_pH_5.7'}) |
|
118 $sql .= "', acid_to_ph_57='" . floatval($fermentable->{'ACID_TO_pH_5.7'}); |
|
119 if ($fermentable->GRAINTYPE == 'Base') |
|
120 $sql .= "', graintype='0"; |
|
121 else if ($fermentable->GRAINTYPE == 'Roast') |
|
122 $sql .= "', graintype='1"; |
|
123 else if ($fermentable->GRAINTYPE == 'Crystal') |
|
124 $sql .= "', graintype='2"; |
|
125 else if ($fermentable->GRAINTYPE == 'Kilned') |
|
126 $sql .= "', graintype='3"; |
|
127 else if ($fermentable->GRAINTYPE == 'Sour malt') |
|
128 $sql .= "', graintype='4"; |
|
129 else if ($fermentable->GRAINTYPE == 'Special') |
|
130 $sql .= "', graintype='5"; |
|
131 else if ($fermentable->GRAINTYPE == 'No malt') |
|
132 $sql .= "', graintype='6"; |
|
133 else |
|
134 echo "Unknown GRAINTYPE " . $fermentable->GRAINTYPE . "<br />"; |
|
135 $sql .= "';"; |
|
136 if (! $result = mysqli_query($db, $sql)) { |
|
137 echo "Fout 8: " . mysqli_error($db) . "<br />"; |
|
138 } else { |
|
139 echo "+ " . $fermentable->NAME . "<br />"; |
|
140 $imported++; |
|
141 } |
|
142 } |
|
143 |
|
144 if ($imported == 0) { |
|
145 echo "Fout 7: geen vergistbare ingredienten in dit bestand.<br />"; |
|
146 } else { |
|
147 echo $imported . " ingredienten toegevoegd.<br />"; |
|
148 } |
|
149 |
|
150 |
|
151 |
|
152 // Don't clutter the upload directory. |
|
153 unlink($target_file); |
|
154 |
|
155 ?> |
|