-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.php
171 lines (162 loc) · 7.79 KB
/
order.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
$title = "سفارش کالا";
include("includes/header.php");
include("includes/db_link.php");
$id = 0;
$query = "";
if (isset($_GET["id"])) {
$id = $_GET["id"];
$query = "SELECT * FROM products WHERE id = '$id'";
} else {
if (isset($_COOKIE["last-viewed-item"])) {
$id = $_COOKIE["last-viewed-item"];
$query = "SELECT * FROM products WHERE id = '$id'";
} else {
exit("<span class='error'>خطایی در حین دریافت اطلاعات کالا از دیتابیس رخ داده.</span>");
}
}
if (!(isset($_SESSION["state_login"]) && $_SESSION["state_login"] === true)) {
?>
<script>
location.replace('not_logged_in.php');
</script>
<?php
}
$request = mysqli_query($link, $query);
?>
<form name="order" action="action_order.php" method="POST">
<table style="width: 100%;" border='1px'>
<tr>
<td style="width: 60%;">
<?php
if ($row = mysqli_fetch_array($request)) {
?>
<br>
<table style="width: 100%;" border="0">
<tr>
<td style="width: 22%;">کد کالا</td>
<td style="width: 78%;"> <input type="text" id="id" name="id" value="
<?= ($id); ?>" class="readonly" readonly> </td>
</tr>
<tr>
<td>نام کالا</td>
<td> <input type="text" id="name" name="name" value="
<?= ($row['name']); ?>" class="readonly" readonly> </td>
</tr>
<tr>
<td>تعداد سفارش <span class="required">*</span></td>
<td> <input type="text" class="ltr" id="qty" name="qty" onchange="calc_price();"> </td>
</tr>
<tr>
<td>قیمت واحد کالا</td>
<td><input type="text" class="ltr readonly" id="price" name="price" value="<?= $row['price']; ?>" readonly> تومان</td>
</tr>
<tr>
<td>مبلغ قابل پرداخت <span class="required"> *</span></td>
<td>
<input type="text" class="ltr readonly" id="total" name="total" value="0" readonly> تومان
</td>
</tr>
<!--cal script-->
<script type="text/javascript">
function calc_price() {
var qty = <?= $row['qty']; ?>;
var price = document.getElementById('price').value;
var count = document.getElementById('qty').value;
if (count > qty) {
alert('تعداد موجودی انبار کمتر از درخواست شما است !');
document.getElementById('qty').value = 0;
count = 0;
}
if (count == 0 || count == '')
total = 0;
else
total = count * price;
document.getElementById('total').value = total;
}
</script>
<?php
$query = "SELECT * FROM `users` WHERE username='{$_SESSION['username']}'";
$request = mysqli_query($link, $query);
$user_row = mysqli_fetch_array($request);
?>
<tr>
<td><br><br><br></td>
<td></td>
</tr>
<tr>
<td style="width: 40%;">نام خریدار</td>
<td style="width: 40%;">
<input type="text" id="realname" name="realname" value="<?= $user_row['realname']; ?>" class="readonly" readonly>
</td>
</tr>
<tr>
<td style="width: 40%;">ایمیل</td>
<td style="width: 40%;">
<input type="text" id="email" name="email" value="<?= $user_row['email']; ?>" class="ltr readonly" readonly>
</td>
</tr>
<tr>
<td style="width: 40%;">شماره همراه <span class="required">*</span></td>
<td style="width: 40%;">
<input type="text" id="number" name="number" value="" class="ltr">
</td>
</tr>
<tr>
<td style="width: 40%;">آدرس پستی گیرنده <span class="required">*</span></td>
<td style="width: 40%;">
<textarea id="address" name="address" cols="30" rows="4" wrap="virtual"></textarea>
</td>
</tr>
<tr>
<td><br><br><br><br></td>
<td><input type="button" value="خرید کالا" onclick="check_input();"></td>
</tr>
</table>
</td>
<td style="vertical-align:top;width:33%">
<script type="text/javascript">
function check_input() {
var r = confirm("از اطلاعات وارد شده اطمینان دارید؟");
if (r == true) {
var validation = true;
var count = document.getElementById('qty').value;
var number = document.getElementById('number').value;
var address = document.getElementById('address').value;
if (count == 0 || count == '')
validation = false;
if (number.length < 11)
validation = false;
if (address.length < 15)
validation = false;
if (validation)
document.order.submit();
else
alert('برخی از ورودی ها فرم سفارش کالا به درستی پر نشده اند.');
}
}
</script>
<table>
<tr>
<td>
<h3 style="color:saddlebrown;margin: 10px 0;"> <?= $row['name']; ?> </h3>
<img src="products/<?= $row['image']; ?>" width="250px" height="120px">
<br>
<span>قیمت: <?= toman($row["price"], true) ?></span>
<br>
<span>تعداد موجودی: <?= $row['qty'] ?></span>
<br>
<span style="font-size: 14px; text-align: justify">توضیحات:
<?= details($row['details']) ?></span>
<br><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<?php
}
include('includes/footer.php');
?>