-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtestdrive.php
293 lines (280 loc) · 8.53 KB
/
testdrive.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
session_start();
include("header.php");
include("sidebar.php");
include("dbconnection.php");
if(!isset($_SESSION[custid]))
{
if(!isset($_SESSION[empid]))
{
header("Location: login.php");
}
}
?>
<script type="text/javascript">
function validate()
{
if(document.form1.bookingid.value=="")
{
alert("Enter Booking ID");
document.form1.bookingid.focus();
return false;
}
if(document.form1.vehname.value=="")
{
alert("Enter Vehicle Name");
document.form1.vehname.focus();
return false;
}
if(document.form1.custname.value=="")
{
alert("Enter Customer Name");
document.form1.custname.focus();
return false;
}
if(document.form1.date.value=="")
{
alert("Enter the Date");
document.form1.date.focus();
return false;
}
if(document.form1.time.value=="")
{
alert("Enter the Time");
document.form1.time.focus();
return false;
}
if(document.form1.comment.value=="")
{
alert("Enter the Comment");
document.form1.comment.focus();
return false;
}
if(document.form1.status.value=="")
{
alert("Enter Status");
document.form1.status.focus();
return false;
}
}
</script>
<?php
//if(isset($_SESSION[custid]))
//{
// header("Location: account.php");
//}
$dt= date("Y-m-d");
$tm= date("H:m:s");
if(isset($_POST["submit"]))
{
$tim = $_POST[hour].":". $_POST[minute].":00";
$originalDate = $_POST[date];
$newDate = date("Y-m-d", strtotime($originalDate));
$sql ="insert into testdrive(vehicleid,custid,date,time,comments,status) values('$_POST[vahicleid]','$_SESSION[custid]','$newDate','$tim','$_POST[comment]','Pending')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
if(isset($_POST["update"]))
{
$originalDate = $_POST[date];
$newDate = date("Y-m-d", strtotime($originalDate));
$tim = $_POST[hour].":". $_POST[minute].":00";
$sql ="update testdrive set vehicleid='$_POST[vahicleid]',custid='$_SESSION[custid]',date='$newDate',time='$tim',comments='$_POST[comment]' where bookingid='$_GET[testid]'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
if(mysql_affected_rows() == 1)
{
$resrec = "Test drive record updated succcessfully...";
}
}
?>
<?php
if(isset($_GET['testid']))
{
$result = mysql_query("select * from testdrive where bookingid='$_GET[testid]'");
$res=mysql_fetch_array($result);
$dt = $res['date'];
$tm = $res['time'];
}
?>
<div id="main">
<a name="TemplateInfo"></a>
<h1>Test drive</h1>
<p>
<?php
if($ctins == 1)
{
echo "<center><b>Custmer registered Successfully...</b></center><br>";
echo "<center><b><a href='login.php'>Click here to Login.</a></b></center>";
}
else
{
if(isset($_POST[submit]) || isset($_POST[update]))
{
echo "<h4>Test drive request sent successfully... </h4>";
}
else
{
?>
</p>
<p><?php echo $resrec; ?> </p>
<form id="form1" name="form1" method="post" action="" onsubmit="return validate()">
<table width="522" border="0">
<?php
if(isset($_GET['testid']))
{
?>
<tr>
<th width="170" height="33" scope="row">Booking ID </th>
<td width="247">
<label for="vehname"></label>
<input name="bookingid" value="<?php echo $res['bookingid']; ?>" readonly="readonly" type="text" id="bookingid" size="35" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/>
</td>
</tr>
<?php
}
?>
<tr>
<th height="37" scope="row">Vehicle name
<label for="vehname"></label></th>
<td>
<?php if(isset($_GET['vahicleidnum']))
{
$res = mysql_query("select vehname from vehiclestore where vehicleid='$_GET[vahicleidnum]'");
$rows = mysql_fetch_array($res);
?><input name="vahiclename" type="text" value="<?php echo $rows['vehname']; ?>" /><input type="hidden" name="vahicleid" value="<?php echo $_GET['vahicleidnum']; ?>" />
<?php } else { ?>
<select name="vahicleid" id="bstatus3">
<?php
$sql = mysql_query("select vehname,vehicleid from vehiclestore");
while($row = mysql_fetch_array($sql))
{
if($row['vahicleid'] == $res['vehicleid'])
{
?>
<option value="<?php echo $row['vehicleid']; ?>" selected="selected"><?php echo $row['vehname']; ?></option>
<?php }else{ ?>
<option value="<?php echo $row['vehicleid']; ?>"><?php echo $row['vehname']; ?></option>
<?php
}
}
?>
</select><?php } ?></td>
</tr>
<!-- <tr>
<th height="36" scope="row">Customer name</th>
<td><label for="custname"></label>
<select name="custid" id="bstatus2">
<?php
//$sql = mysql_query("select custid,fname from customer");
// while($row = mysql_fetch_array($sql))
// {
// if($row['custid'] == $res['custid'])
// {
?>
<option value="<?php //echo $row['custid']; ?>" selected="selected"><?php //echo $row['fname']; ?></option>
// <?php //}else{ ?>
// <option value="<?php //echo $row['custid']; ?>"><?php //echo $row['fname']; ?></option>
// <?php
// }
// }
?>
</select></td>
</tr>-->
<tr>
<th height="34" scope="row">Date</th>
<td>
<?php
$dt1 = date("m-d-Y"); ?>
<script src="datetimepicker_css.js"></script>
<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>
<input name="date" type="text" value="<?php echo $dt1; ?>" id="date" size="35" />
<a href="javascript:NewCal('date','ddmmmyyyy',false,24)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
</td>
</tr>
<tr>
<th height="40" scope="row">Time</th>
<td><label for="time"></label>
<select name="hour" id="hour">
<option>Hour</option>
<option>00</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>11</option>
<option>11</option>
<option>11</option>
<option>11</option>
</select>
<select name="minute" id="minute">
<option>Minute</option>
<option>00</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<?php
for($i=10; $i<=59; $i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<th height="37" scope="row">Comment</th>
<td><textarea name="comment" cols="35" id="comment"><?php echo $res['comments']; ?></textarea></td>
</tr>
<!-- <tr>
<th height="37" scope="row">Status</th>
<td><label for="bstatus"></label>
<select name="bstatus" id="bstatus">
<option value="Pending">Pending</option>
<option value="Finished">Finished</option>
</select></td>
</tr>-->
<tr>
<th scope="row"> </th>
<td><br /><?php if(isset($_GET['testid'])) { ?><input type="submit" name="update" id="submit" value="Update test drive" /><?php } else { ?><input type="submit" name="submit" id="submit" value="Add test drive" /><?php } ?></td>
</tr>
</table>
</form>
<?php
}
}
?>
<p> </p>
<br />
</div>
<!-- wrap ends here -->
</div>
<?php
include("footer.php");
?>