-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.php
More file actions
239 lines (228 loc) · 9.02 KB
/
application.php
File metadata and controls
239 lines (228 loc) · 9.02 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
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
<?php
include 'core/core.inc.php';
if (!isset($_SESSION['user_id'])) { header("Location: login.php");}
$save_message = false;
$apply_message = false;
require_once "core/user.db.php";
$u = new User($host, $db_name, $db_user, $db_pass);
if (isset($_POST['draft'])) {
$start_timestamp = 0;
$end_timestamp = 0;
if(!empty($_POST['start_date']) && $_POST['start_time']){
$start_timestamp = strtotime($_POST['start_date'].' '.$_POST['start_time']);
}
if(!empty($_POST['end_date']) && $_POST['end_time']){
$end_timestamp = strtotime($_POST['end_date'].' '.$_POST['end_time']);
}
if ($_POST['applied'] == 'N') {
require_once "core/application.db.php";
$a = new Application($host, $db_name, $db_user, $db_pass);
$draft_id = 0;
if (!isset($_GET['draft_id'])) {
$draft_id = $a->insert($_SESSION['user_id'], $_POST['to']);
$rdr = true;
}else{
$draft_id = $_GET['draft_id'];
}
$a->update("receiver", $_POST['to'], $draft_id);
$a->update("message", $_POST['message'], $draft_id);
$a->update("department", $u->getName($_POST['to'])[0]['department'], $draft_id);
$a->update("start_date", $start_timestamp, $draft_id);
$a->update("ending_date", $end_timestamp, $draft_id);
$a->update("vehicle_req", $_POST['vehicle_req'], $draft_id);
$a->update("pickup_location", $_POST['pickup_location'], $draft_id);
$save_message = "Successfuly saved in draft";
$notify = 'N';
if (isset($_POST['notify'])) { $notify = 'Y'; }
$a->update("notification", $notify, $draft_id);
if (isset($rdr)) {
header("Location: ?draft_id=".$draft_id);
}
}else{
$apply_message = "Already applied. You can't edit once your application is submitted";
}
}
if (isset($_GET['draft_id'])) {
require_once "core/application.db.php";
$a = new Application($host, $db_name, $db_user, $db_pass);
$draft_details = $a->fetch_by_id('draft_id', $_GET['draft_id'])[0];
if ($draft_details['start_date'] != 0) {
$start_date = date('Y-m-d', $draft_details['start_date']);
$start_time = date('H:i', $draft_details['start_date']);
}
if ($draft_details['ending_date']) {
$end_date = date('Y-m-d', $draft_details['ending_date']);
$end_time = date('H:i', $draft_details['ending_date']);
}
if ($draft_details['applied'] == 'Y') {
header("Location: application.php");
}
}
if (isset($_POST['apply'])) {
if (empty($draft_details['receiver'])) {
$apply_message = "Not a valid receiver";
}elseif (empty($draft_details['department'])) {
$apply_message = "No any department associted with application receiver";
}elseif (empty($draft_details['start_date'])) {
$apply_message = "When you need vehicle";
}elseif (empty($draft_details['vehicle_req'])) {
$apply_message = "Which kind of vehicle you need?";
}elseif (empty($draft_details['pickup_location'])) {
$apply_message = "No pickup location specified, How we find you?";
}elseif (empty($draft_details['message'])) {
$apply_message = "You did not written about your need";
}else{
require_once "core/application.db.php";
$a = new Application($host, $db_name, $db_user, $db_pass);
$a->update("applied", 'Y', $_GET['draft_id']);
$a->update("status", 'Y', 'Application received');
$a->update("log", 'Y', 'Application received');
$a->update("application_date", time(), $_GET['draft_id']);
}
}
$admin_list = $u->getAdmins($_SESSION['auth_level']);
?>
<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
<meta name="og:title" property="og:title" content="TATA Sponge Limited :: Dashboard"/>
<?php
include 'core/meta.php';
?>
<link rel="stylesheet" href="css/core.css">
<style type="text/css">
.paper_form input{
/*border: 0px;*/
}
.paper_form label{
padding: 0 0 0 15px;
}
</style>
</head>
<body>
<?php
require "core/top_nav.php";
?>
<div class="container-fluid">
<div class="row">
<div class="col col-lg-3 side_nav">
<?php
$active = "application";
require "core/side_nav.php";
?>
</div>
<div class="col-md-9">
<center>
<h1>Application for vehicle</h1>
</center>
<br/>
<form class="paper_form" method="POST">
<input type="hidden" name="applied" value="<?php if(isset($_GET['draft_id'])){echo $draft_details['applied'];}else{ echo "N";} ?>">
<div class="form-row">
<div class="form-group col-md-4">
<label class="text-success"><b>Application ID : <?php if (isset($_GET['draft_id'])) { echo $_GET['draft_id'];} ?></b></label>
</div>
</div>
<div class="form-row justify-content-between">
<div class="form-group col-md-4">
<label for="sendingTo">Respected Sir/Madem,</label>
<select name="to" class="form-control" id="sendingTo" >
<?php foreach ($admin_list as $key => $value): ?>
<option <?php if(isset($draft_details['receiver'])) if($draft_details['receiver'] == $value['id']){echo "selected";}?> value="<?=$value['id']?>"><?=$value['name']?> (<?=$value['department']?>)</option>
<?php endforeach ?>
</select>
</div>
<div class="form-group col-md-4">
<label> Date: <?php echo date("d M Y", time()); ?></label>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="startDate">Starting Date</label>
<input type="date" name="start_date" class="form-control" id="startDate" value="<?php if(isset($start_date)){ echo $start_date;} ?>">
</div>
<div class="form-group col-md-3">
<label for="startTime">Starting Time</label>
<input type="time" name="start_time" class="form-control" id="startTime" value="<?php if(isset($start_time)){ echo $start_time;} ?>" >
</div>
</div>
<div class="form-row end_datetime">
<div class="form-group col-md-3">
<label for="endDate">End Date</label>
<input type="date" name="end_date" class="form-control" value="<?php if(isset($end_date)){echo $end_date;} ?>" id="endDate">
</div>
<div class="form-group col-md-3">
<label for="endTime">End Time</label>
<input type="time" name="end_time" class="form-control" value="<?php if(isset($end_time)){echo $end_time;} ?>" id="endTime">
</div>
</div>
<div class="form-row justify-content-between">
<div class="form-group col-md-2">
<label for="vehicleType">Requesting Vehicle</label>
<input type="text" name="vehicle_req" class="form-control" value="<?php if(isset($_GET['draft_id'])){ echo $draft_details['vehicle_req'];} ?>" id="vehicleType" placeholder="Bus, Car, Bike">
</div>
<div class="form-group col-md-10">
<label for="vehicleType">Pickup Location</label>
<input type="text" name="pickup_location" class="form-control" value="<?php if(isset($_GET['draft_id'])){ echo $draft_details['pickup_location'];} ?>" id="vehicleType" placeholder="Near air field">
</div>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Describe your requirement</label>
<textarea class="form-control" name="message" id="exampleFormControlTextarea1" rows="5"><?php if (isset($_GET['draft_id'])) {
echo $draft_details['message'];
} ?></textarea>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="notify" id="defaultCheck1" <?php if (isset($_GET['draft_id'])) {
if ($draft_details['notification'] == 'Y') {
echo "checked";
}
}else echo "checked"; ?>>
<label class="form-check-label" for="defaultCheck1">Receive Notification</label>
</div>
<br>
<button type="submit" name="draft" class="btn btn-primary">Save to Draft</button>
<?php if (isset($_GET['draft_id'])) {
echo '<button type="submit" name="apply" class="btn btn-primary">Apply</button>';
} ?>
</form>
<br><br>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/swal.js"></script>
<script type="text/javascript">
<?php
if ($save_message) {
echo 'swal({title:"'.$save_message.'",icon: "success"});';
}
if ($apply_message) {
echo 'swal({title:"'.$apply_message.'",icon: "error"});';
}
?>
function set_application_reciver(id, depart, name) {
$('#helper').html("");
$('#sending_to_id').val(id);
$('#department').val(depart);
$('#sendingTo').val(name);
}
$("#sendingTo").keyup(function (e) {
$.ajax({
url: "ajax/get_suggestion.php?q="+this.value,
dataType: 'JSON',
success: function(result){
console.log(result);
$('#helper').html("");
for (var i = result.length - 1; i >= 0; i--) {
console.log(result[i]);
$('#helper').append('<label style="border: 1px dotted black; width: 100%; cursor: pointer;" onclick="set_application_reciver(\''+result[i]['id']+'\', \''+result[i]['department']+'\',\''+result[i]['f_name']+' '+result[i]['m_name']+' '+result[i]['surname']+'\' )">'+result[i]['f_name']+' '+result[i]['m_name']+' '+result[i]['surname']+' ('+result[i]['department']+')</label>');
}
},
});
});
</script>
</html>