|
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 $styles = simplexml_load_file($target_file); |
|
51 |
|
52 foreach ($styles->STYLE as $style) { |
|
53 |
|
54 $sql = "INSERT INTO profile_styles SET name='" . mysqli_real_escape_string($db, $style->NAME); |
|
55 if ($style->NOTES) |
|
56 $sql .= "', notes='" . mysqli_real_escape_string($db, $style->NOTES); |
|
57 if ($style->CATEGORY) |
|
58 $sql .= "', category='" . mysqli_real_escape_string($db, $style->CATEGORY); |
|
59 if ($style->CATEGORY_NUMBER) |
|
60 $sql .= "', category_number='" . $style->CATEGORY_NUMBER; |
|
61 if ($style->STYLE_LETTER) |
|
62 $sql .= "', style_letter='" . mysqli_real_escape_string($db, $style->STYLE_LETTER); |
|
63 if ($style->STYLE_GUIDE) |
|
64 $sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE); |
|
65 |
|
66 if ($style->TYPE == 'Lager') |
|
67 $sql .= "', type='0"; |
|
68 else if ($style->TYPE == 'Ale') |
|
69 $sql .= "', type='1"; |
|
70 else if ($style->TYPE == 'Mead') |
|
71 $sql .= "', type='2"; |
|
72 else if ($style->TYPE == 'Wheat') |
|
73 $sql .= "', type='3"; |
|
74 else if ($style->TYPE == 'Mixed') |
|
75 $sql .= "', type='4"; |
|
76 else if ($style->TYPE == 'Cider') |
|
77 $sql .= "', type='5"; |
|
78 else |
|
79 echo "Unknown TYPE " . $style->TYPE . "<br />"; |
|
80 |
|
81 $sql .= "', og_min='" . floatval($style->OG_MIN); |
|
82 $sql .= "', og_max='" . floatval($style->OG_MAX); |
|
83 $sql .= "', fg_min='" . floatval($style->FG_MIN); |
|
84 $sql .= "', fg_max='" . floatval($style->FG_MAX); |
|
85 $sql .= "', ibu_min='" . floatval($style->IBU_MIN); |
|
86 $sql .= "', ibu_max='" . floatval($style->IBU_MAX); |
|
87 $sql .= "', color_min='" . srm_to_ebc(floatval($style->COLOR_MIN)); |
|
88 $sql .= "', color_max='" . srm_to_ebc(floatval($style->COLOR_MAX)); |
|
89 $sql .= "', carb_min='" . floatval($style->CARB_MIN); |
|
90 $sql .= "', carb_max='" . floatval($style->CARB_MAX); |
|
91 $sql .= "', abv_min='" . floatval($style->ABV_MIN); |
|
92 $sql .= "', abv_max='" . floatval($style->ABV_MAX); |
|
93 if ($style->PROFILE) |
|
94 $sql .= "', profile='" . mysqli_real_escape_string($db, $style->PROFILE); |
|
95 if ($style->INGREDIENTS) |
|
96 $sql .= "', ingredients='" . mysqli_real_escape_string($db, $style->INGREDIENTS); |
|
97 if ($style->EXAMPLES) |
|
98 $sql .= "', examples='" . mysqli_real_escape_string($db, $style->EXAMPLES); |
|
99 |
|
100 $sql .= "';"; |
|
101 if (! $result = mysqli_query($db, $sql)) { |
|
102 echo "Fout 8: " . mysqli_error($db) . "<br />"; |
|
103 } else { |
|
104 echo "+ " . $style->NAME . "<br />"; |
|
105 $imported++; |
|
106 } |
|
107 } |
|
108 |
|
109 if ($imported == 0) { |
|
110 echo "Fout 7: geen stylen in dit bestand.<br />"; |
|
111 } else { |
|
112 echo $imported . " stylen toegevoegd.<br />"; |
|
113 } |
|
114 |
|
115 |
|
116 |
|
117 // Don't clutter the upload directory. |
|
118 unlink($target_file); |
|
119 |
|
120 ?> |