-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarAdd.php
More file actions
157 lines (133 loc) · 5.09 KB
/
CarAdd.php
File metadata and controls
157 lines (133 loc) · 5.09 KB
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
<script >
function render(dialog){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = (winW/2) - (550 * .5)+"px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Acknowledge This Message";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button onclick="ok()">OK</button>';
}
function ok(){
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
</script>
<?php
require 'Usedcars\UCarController.php';
$carController = new UCarController();
$title ="Add a new Car";
$excss="css/Addstyle.css";
$jsfile="";
// so that we do not have to resubmit form on back and forth nav
header('Cache-Control: no cache'); //no cache
session_cache_limiter('private_no_expire'); // works
if (isset($_SESSION)) {
}else{
session_start();
}
if (isset($_SESSION['uemail'])){}
else{
echo '<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
</div>
</div>
<div style:clear=both;></div>';
echo' <script>render("Please login to our website.");</script>';
}
if(isset($_GET["update"]))
{
$car = $carController->GetCarById($_GET["update"]);
$content ="<form action='' method='post' >
<fieldset style='width: 1000px; margin: 0 auto;background-color: #eaeaea;'>
<legend>Update your Car</legend>
<label for='name'>Name: </label>
<input type='text' class='inputField' name='txtName' value='". $car->name ."' required /><br/>
<label for='price'>Price: </label>
<input type='text' class='inputField' name='txtPrice' value='$car->price'/><br/>
<label for='description'>description: </label>
<textarea cols='70' rows='12' name='txtdesc'>$car->descp</textarea></br>
<label for='type'>Type: </label>
<select class='inputField' name='ddltype'>
<option value='%'>All</option>"
.$carController->CreateOptionValues($carController->GetCarTypes()).
"</select><br/>
<label for='image'>Image: </label>
<select class='inputField' name='ddlImage'>"
.$carController->GetImages().
"</select></br>
<input type='submit' value='Submit'>
</fieldset>
</form>";
}
else
{
$content ="<form action='' method='post'>
<fieldset style='width: 1000px; margin: 0 auto;background-color: #eaeaea;' >
<legend>Add a new Car</legend>
<label for='name'>Name: </label>
<input type='text' class='inputField' name='txtName' required /><br/><br/>
<label for='price'>Price: </label>
<input type='text' class='inputField' name='txtPrice' required/><br/><br/>
<label for='description'>description: </label>
<textarea cols='70' rows='12' name='txtdesc' required></textarea></br><br/>
<label for='type'>Type: </label>
<select class='inputField' name='ddltype' required>
<option value='%'>All</option>"
.$carController->CreateOptionValues($carController->GetCarTypes()).
"</select><br/><br/>
<label for='image' >Image: </label>
<select class='inputField' name='ddlImage' required>"
.$carController->GetImages().
"</select></br><br/>
<input type='submit' value='Submit'>
</fieldset>
</form>";
}
$content.='<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
</div>
</div>';
if(isset($_GET["update"]))
{
if(isset($_POST["txtName"]) && isset($_POST["txtPrice"]) && isset($_POST["txtdesc"]))
{
if(isset($_SESSION['uemail'])){
$carController->UpdateCar($_GET["update"]);
echo"<script>alert('Successful updated data to our website');</script>";
header('Refresh:0; url=CarOverview.php');
}
else
echo"<script>render('Please login to our website.');</script>";
}
}
else
{
if(isset($_POST["txtName"]) && isset($_POST["txtPrice"]) && isset($_POST["txtdesc"]))
{
if(isset($_SESSION['uemail'])){
$carController->InsertCar();
echo"<script>alert('Successful Inserted data to our website');</script>";
header('Refresh:0; url=CarOverview.php');
}
else
{
echo"<script>render('Please login to our website.');</script>";
}
}
}
include 'CarTemplate.php';
?>