-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct_list.php
124 lines (121 loc) · 5.1 KB
/
product_list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
if (isset($_SESSION['user_id']) && isset($_SESSION['list']))
{
//echo $_SESSION['user_id'];
$data = $_SESSION['list'];
for ($i=0; $i < sizeof($data); $i++)
{
$data[$i][0] = (int)$data[$i][0]; //ID
$data[$i][1] = (int)$data[$i][1]; //amount
$data[$i][2] = $data[$i][2]; //name
}
//$id = doubleval()
include "database.php";
$db = new database();
for ($i=0; $i < sizeof($data); $i++)
{
$sql = "SELECT * FROM coles WHERE Product_ID = ".$data[$i][0]." AND Product_Name = '".mysqli_real_escape_string($db->conn , trim($data[$i][2]))."' UNION ALL SELECT * FROM woolworths WHERE Product_ID = ".$data[$i][0]." AND Product_Name = '".mysqli_real_escape_string($db->conn , trim($data[$i][2]))."' UNION ALL SELECT * FROM aldi WHERE Product_ID = ".$data[$i][0]." AND Product_Name = '".mysqli_real_escape_string($db->conn , trim($data[$i][2]))."'";
$result = mysqli_query($db->conn,$sql);
$out[$i] = mysqli_fetch_assoc($result);
$cost = ((double)$out[$i]['Price'])*($data[$i][1]);
//$str = "$".$out['Price']." * ".$_POST['amount']."= ";
$str_cost = "$".$cost;
$out[$i]['amount'] = $data[$i][1];
$out[$i]['cost'] = $str_cost;
}
for ($i=0; $i < sizeof($out); $i++)
{
if ($out[$i]['amount'] == "")
{
continue;
}
?>
<tr id="row<?=$out[$i]['Product_ID']?>" class="rows">
<td>
<p><span id="product_list_name<?=$out[$i]['Product_ID']?>"><?=$out[$i]['Product_Name']?></span></p>
</td>
<td>
<input class="amount disable_scrolling btn-outline-info" type="number" min="0" placeholder="<?=$out[$i]['amount']?>" readonly>
</td>
<td>
<div class="dropdown">
<button type="button" class="btn btn-sm btn-outline-info dropdown-toggle" data-toggle="dropdown">
<?=$out[$i]['Unit']?>
</button>
</div>
</td>
<td>
<input id="cost<?=$out[$i]['Product_ID']?>" class="amount disable_scrolling btn-outline-info" type="number" min="0" placeholder="<?=$out[$i]['cost']?>" readonly>
</td>
<td>
<button data-id="<?=$out[$i]['Product_ID']?>" data-unit="<?=$out[$i]['Unit']?>" id="product_list_edit<?=$out[$i]['Product_ID']?>" class="btn btn-sm btn-outline-success">Edit</button>
</td>
<td>
<button data-id="<?=$out[$i]['Product_ID']?>" id="product_list_remove<?=$out[$i]['Product_ID']?>" class="btn btn-sm btn-outline-danger">Remove</button>
</td>
<td style="display: none;">
<span id="product_list_id"><?=$out[$i]['Product_ID']?></span>
</td>
</tr>
<?php } ?>
<?php }
elseif(isset($_POST['data']))
{
$data = $_POST['data'];
for ($i=0; $i < sizeof($data); $i++)
{
$data[$i][0] = (int)$data[$i][0]; //ID
$data[$i][1] = (int)$data[$i][1]; //amount
$data[$i][2] = $data[$i][2]; //name
}
//$id = doubleval()
include_once "database.php";
$db = new database();
for ($i=0; $i < sizeof($data); $i++)
{
$sql = "SELECT * FROM coles WHERE Product_ID = ".$data[$i][0]." AND Product_Name = '".mysqli_real_escape_string($db->conn , trim($data[$i][2]))."' UNION ALL SELECT * FROM woolworths WHERE Product_ID = ".$data[$i][0]." AND Product_Name = '".mysqli_real_escape_string($db->conn , trim($data[$i][2]))."' UNION ALL SELECT * FROM aldi WHERE Product_ID = ".$data[$i][0]." AND Product_Name = '".mysqli_real_escape_string($db->conn , trim($data[$i][2]))."'";
$result = mysqli_query($db->conn,$sql);
$out[$i] = mysqli_fetch_assoc($result);
$cost = ((double)$out[$i]['Price'])*($data[$i][1]);
//$str = "$".$out['Price']." * ".$_POST['amount']."= ";
$str_cost = "$".$cost;
$out[$i]['amount'] = $data[$i][1];
$out[$i]['cost'] = $str_cost;
}
for ($i=0; $i < sizeof($out); $i++)
{
if ($out[$i]['amount'] == "")
{
continue;
}
?>
<tr id="row<?=$out[$i]['Product_ID']?>" class="rows">
<td>
<p><span id="product_list_name<?=$out[$i]['Product_ID']?>"><?=$out[$i]['Product_Name']?></span></p>
</td>
<td>
<input class="amount disable_scrolling btn-outline-info" type="number" min="0" placeholder="<?=$out[$i]['amount']?>" readonly>
</td>
<td>
<div class="dropdown">
<button type="button" class="btn btn-sm btn-outline-info dropdown-toggle" data-toggle="dropdown">
<?=$out[$i]['Unit']?>
</button>
</div>
</td>
<td>
<input id="cost<?=$out[$i]['Product_ID']?>" class="amount disable_scrolling btn-outline-info" type="number" min="0" placeholder="<?=$out[$i]['cost']?>" readonly>
</td>
<td>
<button data-id="<?=$out[$i]['Product_ID']?>" data-unit="<?=$out[$i]['Unit']?>" id="product_list_edit<?=$out[$i]['Product_ID']?>" class="btn btn-sm btn-outline-success">Edit</button>
</td>
<td>
<button data-id="<?=$out[$i]['Product_ID']?>" id="product_list_remove<?=$out[$i]['Product_ID']?>" class="btn btn-sm btn-outline-danger">Remove</button>
</td>
<td style="display: none;">
<span id="product_list_id"><?=$out[$i]['Product_ID']?></span>
</td>
</tr>
<?php }?>
<?php
} ?>