www/upl_miscs.php

changeset 818
f9c071906643
parent 817
6ee186182c70
child 819
d759d9ed357e
equal deleted inserted replaced
817:6ee186182c70 818:f9c071906643
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 $miscs = simplexml_load_file($target_file);
51
52 foreach ($miscs->MISC as $misc) {
53
54 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
55 $sql = "INSERT INTO inventory_miscs SET uuid='" . $uuid;
56 $sql .= "', name='" . mysqli_real_escape_string($db, $misc->NAME);
57 if ($misc->NOTES)
58 $sql .= "', notes='" . mysqli_real_escape_string($db, $misc->NOTES);
59
60 if ($misc->TYPE == 'Spice')
61 $sql .= "', type='0";
62 else if ($misc->TYPE == 'Herb')
63 $sql .= "', type='1";
64 else if ($misc->TYPE == 'Flavor')
65 $sql .= "', type='2";
66 else if ($misc->TYPE == 'Fining')
67 $sql .= "', type='3";
68 else if ($misc->TYPE == 'Water agent')
69 $sql .= "', type='4";
70 else if ($misc->TYPE == 'Yeast nutrient')
71 $sql .= "', type='5";
72 else if ($misc->TYPE == 'Other')
73 $sql .= "', type='6";
74 else
75 echo "Unknown TYPE " . $misc->TYPE . "<br />";
76
77 if ($misc->USE == 'Starter')
78 $sql .= "', use_use='0";
79 else if ($misc->USE == 'Mash')
80 $sql .= "', use_use='1";
81 else if ($misc->USE == 'Boil')
82 $sql .= "', use_use='2";
83 else if ($misc->USE == 'Primary')
84 $sql .= "', use_use='3";
85 else if ($misc->USE == 'Secondary')
86 $sql .= "', use_use='4";
87 else if ($misc->USE == 'Bottling')
88 $sql .= "', use_use='5";
89 else
90 echo "Unknown USE " . $misc->USE . "<br />";
91
92 $sql .= "', time='" . $misc->TIME;
93 ($misc->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='1" : $sql .= "', amount_is_weight='0";
94 if ($misc->USE_FOR)
95 $sql .= "', use_for='" . mysqli_real_escape_string($db, $misc->USE_FOR);
96 if ($misc->ALWAYS_ON_STOCK)
97 ($misc->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
98 if ($misc->INVENTORY)
99 $sql .= "', inventory='" . floatval($misc->INVENTORY) / 1000.0;
100 if ($misc->COST)
101 $sql .= "', cost='" . floatval($misc->COST);
102 $sql .= "';";
103 if (! $result = mysqli_query($db, $sql)) {
104 echo "Fout 8: " . mysqli_error($db) . "<br />";
105 } else {
106 echo "+ " . $misc->NAME . "<br />";
107 $imported++;
108 }
109 }
110
111 if ($imported == 0) {
112 echo "Fout 7: geen diverse ingredienten in dit bestand.<br />";
113 } else {
114 echo $imported . " diverse ingredienten toegevoegd.<br />";
115 }
116
117
118
119 // Don't clutter the upload directory.
120 unlink($target_file);
121
122 ?>

mercurial