-
Notifications
You must be signed in to change notification settings - Fork 0
/
userloan.php
393 lines (318 loc) · 14.5 KB
/
userloan.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!--
Author: Khalil Greenidge
Email: [email protected]
Created: 30/04/2015
-->
<?php
session_start();
if(empty($_SESSION["login"])){
header("Location: login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HEDU IMS | Loan an asset</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<link href="dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="http://code.ionicframework.com/ionicons/2.0.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link rel="shortcut icon" href="dist/img/logo.gif" />
<link href="http://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link href="dist/css/skins/_all-skins.min.css" rel="stylesheet" type="text/css" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<script>
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body class="skin-blue">
<!-- Site wrapper -->
<div class="wrapper">
<!-- header logo: style can be found in header.less -->
<header class="main-header">
<?php include "header.php"; ?>
</header>
<!-- =============================================== -->
<!-- Left side column. contains the sidebar -->
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- search form -->
<form action="search.php" method="get" class="sidebar-form">
<div class="input-group">
<input type="text" name="key" autocomplete="off" onkeyup="showResult(this.value)" required class="form-control" placeholder="Search Serial#, Service Tag, Type"/>
<span class="input-group-btn">
<button type='submit' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i></button>
</span>
</div>
<div id="livesearch"></div>
</form>
<!-- /.search form -->
<!-- sidebar menu: : style can be found in sidebar.less -->
<?php
if($_SESSION["user"] == "admin"){
include "adminmenu.php";
}
else{
include "menu.php";
}
?>
</section>
<!-- /.sidebar -->
</aside>
<!-- =============================================== -->
<!-- Right side column. Contains the navbar and content of the page -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Loan Form
</h1>
<a href="remainder.php">Click here to view items remaining!</a>
</section>
<!-- Main content -->
<section class="content">
<hr/>
<form class="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
Ticket# : <input name="ticket" type="text" value="<?php
$num = 0; $number = 0;
$highest = 0;
$con = mysqli_connect("localhost", "root", "");
$db = mysqli_select_db($con, "heduis");
$rs = mysqli_query($con, "SELECT * FROM loan");
if(!$con || !$db || !$rs ){
die('Error: '.mysqli_error());
}
else{
while($row = mysqli_fetch_array($rs)){
$num = $row['ticket_id'];
if($num > $highest ){
$highest = $num;
}
}
$number = $highest +1;
echo $number;
}
mysqli_close();
?>" readonly /> <br/><br/>
Serial#: <input name="id" id="id" type="text" onkeyup="upperCase()" required/> <br/><br/>
<b>Browser Support: </b>
<a href="http://www.opera.com/computer/windows" target="blank"><img src="dist/img/opera.gif" alt="Opera" width="20" height="20"></a>
<a href="http://download.cnet.com/Apple-Safari/3000-2356_4-10697481.html" target="blank"><img src="dist/img/safari.gif" alt="Safari" width="20" height="20"></a>
<a href="https://www.google.com/chrome/browser/desktop/" target="blank"><img src="dist/img/chrome.gif" alt="Chrome" width="20" height="20"></a>
<img src="dist/img/firefox.gif" alt="firefox" width="20" height="20">
<img src="dist/img/ie.gif" alt="IE" width="20" height="20">
<br/><br/>
Start Date: <img src="dist/img/calender.png" /><input type="date" required name="startDate" max="<?php
date_default_timezone_set("America/La_Paz");
echo date("Y-m-d", strtotime("today +7 days"));
?>" /> <br/><br/>
End Date: <img src="dist/img/calender.png" /><input type="date" required name="endDate" min="<?php
date_default_timezone_set("America/La_Paz");
echo date("Y-m-d", strtotime("now"));
?>" /><br/><br/>
Reason: <br/><textarea name="reason" placeholder="State" cols="50" rows="6" maxlength="180" required>
</textarea><br/><br/>
<input type="submit" /> <input type="reset" />
</form>
<script>
function upperCase(){
//GET REPRESENTATIVE
var f = document.getElementById("id");
//GET FIRST LETTER
f.value = f.value.toUpperCase();
}
</script>
<?php
//VARIABLES
$id = $name = $item = $email = $startDate = $endDate = $duration = $reason = $status = $cat = $dbB = "";
$ticket = $days = 0;
//PROCESS FORM
if($_SERVER["REQUEST_METHOD"] == "POST"){
$ticket = $_POST["ticket"];
$id = $_POST["id"];
$name = ucwords(test_input($_SESSION["name"]));
$email = $_SESSION["email"];
$startDate = $_POST["startDate"];
$endDate = $_POST["endDate"];
$reason = test_input($_POST["reason"]);
$days = strtotime($endDate) - strtotime($startDate);
if($days == 0){
$duration = "24 hours";
}
else{
$duration = date("d", $days) . "day(s)";
}
$con = mysqli_connect("localhost", "root", "");
$db = mysqli_select_db($con, "heduis");
$rs = mysqli_query($con, "SELECT * FROM stock WHERE id=\"$id\" ");
if(!$con || !$db || !$rs ){
die('Error: '.mysqli_error());
}
else{
while($row = mysqli_fetch_array($rs)){
$dbB = $row['loaned'];
$item = $row["type"];
}
//IF ITEM IS BURROWED, PRINT ALREADY BURROWED. ELSE --> NEW ITEM ADDED!
if($dbB == "yes" ||(mysqli_num_rows($rs) < 1)){
//ERROR
echo "<div id=\"ani\" class='error'><img src=\"dist/img/x.png\"/> Item already Loaned/ doesn't exist! </div>";
}
else{
//SUCCESS
$rs3 = mysqli_query("INSERT INTO loan VALUES($ticket, \"$id\", \"$name\", \"$email\",\"no\", \"$startDate\", \"$endDate\", \"$duration\", \"$reason\", \"pending\")") or die('Error: '.mysqli_error());
//SEND AN EMAIL TO ADMIN FOR ACCEPTANCE
$subject = "HEDU IMS | Ticket Request";
// the message
$msg = "
<!--BACKGROUND TABLE-->
<style>
p {color: #444444;}
</style>
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\" align=\"center\" style=\"padding-top:0px;font-family:Arial,Helvetica,sans-serif;font-weight:normal;font-size:14px;line-height:19px;color:#444444;border-collapse:collapse;background-color:#ececec\">
<tbody>
<tr>
<td width=\"100%\">
<br>
<!--INNER TABLE-->
<table width=\"600\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"center\" >
<tbody>
<!--HEADER ROW-->
<tr style=\"background-color: #3c8dbc;\" align=\"center\">
<td width=\"100%\" height=\"75\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"
style=\"align: center;background-color: #3c8dbc;!important;font-family:
Arial,Helvetica,sans-serif;font-weight:normal;font-size:20px;
line-height:19px;color: white;border-collapse:collapse\">
<a href=\"http://localhost:8000/index.php\" style=\"text-decoration:none;display:inline; color: white;\" target=\"_blank\">
<img alt=\"logo\" border=\"0\" style=\"vertical-align:middle;display:inline;
float:none\" src=\"http://s14.postimg.org/ojywskxwt/logo.gif\" width=\"80\" height=\"75\" class=\"CToWUd\">
HEDU IMS
</a>
</td>
</tr><!--END HEADER ROW-->
<tr><!--CONTENT 1-->
<td width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#ffffff\" Height=\"100%\" valign=\"top\" style=\"padding:30px 68px 22px; font-family:Arial,Helvetica,sans-serif;font-weight:normal;font-size:14px;line-height:19px;color:#444444;background-color:#ffffff!important; border-bottom:0; \">
<p style=\"line-height:24px!important;font-size:14px!important;margin-bottom:20px\">
Hi Admin,<br>
<br/>
An officer by the name of - ".$name. " has requested to loan a ".$item." with the serial number of ".$id." from HEDU IMS.<br/>
Do you accept? Please login and go to the custodians page.
<br>
<br/>
<a href=\"http://localhost:8000/login.php\" target=\"_blank\">Click here to login</a>
<br/>
</p>
<br/><br/>
<p style=\"font-family:Arial,Helvetica,sans-serif;font-weight:normal;font-size:14px;line-height:24px;margin-top:0!important;margin-bottom:0!important\">
Thanks!<br>
HEDU IMS
</p>
<p style=\"margin-bottom:6px\">
<br/>
</p>
<br/>
</td>
</tr><!--END CONTENT-->
<!--FOOTER-->
<tr style=\"background: #3c8dbc\">
<td width=\"100%\" height=\"82\" align=\"center\" valign=\"middle\" style=\"padding:0px 13px 12px; vertical-align:middle;height: 100%; line-height: 20px;text-align: center; color: #ccc;font-size: 11px;\">
<br/>
<h3>HEDU IMS</h3>
<p>© 2015 - ".date("Y").",
Developed by: <a href=\"mailto:[email protected]\" target=\"_blank\">Khalil Greenidge</a></p>
</td>
</tr>
</tbody>
</table><!--END INNER TABLE-->
<!--FINE LINES-->
<table width=\"100%\" bgcolor=\"#ECECEC\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-family:Arial,Helvetica,sans-serif;font-weight:normal;font-size:14px;line-height:19px;color:#7e7e7e;border-collapse:collapse\">
<tbody>
<tr>
<td width=\"100%\" style=\"text-align:left;color:#7e7e7e!important;font-size:10px;line-height:14px;padding:10px 15px\">
<p style=\"text-align:center;color:#a4a4a4\">
Please do not reply directly to this email. Only click the link as instructed.<br>
You can reach tech support by sending a message to <a href=\"mailto:[email protected]\" target=\"_blank\">techadmin@<span class=\"il\">hedu</span>.edu.bb</a>.<br/><br/></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>";
//HEADERS
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
date_default_timezone_set("America/La_Paz");
$headers .= "Date: ".date("Y/m/d, h:i:sa")."\r\n";
$headers .= "From: HEDU IMS <[email protected]>";
// send email
if(mail("[email protected]", $subject,$msg, $headers)){
//SHOW MESSAGE
echo "<div id=\"ani\" class='info'><img src=\"dist/img/info.png\" width=\"20\" height=\"20\" /> Your request has been received. Please wait for approval.</div>";
}
else {
//ERROR
echo "<div id=\"ani\" class=\"error\"><img src=\"dist/img/x.png\"/> Error sending mail!</div>";
}
}
}
mysqli_close($con);
$location = "remainder.php";
echo '<META HTTP-EQUIV="Refresh" Content="7; URL='.$location.'">';
}
//TEST FUNCTION
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<footer class="main-footer">
<?php include "footer.php";?>
</footer>
</div><!-- ./wrapper -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js" type="text/javascript"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js" type="text/javascript"></script>
</body>
</html>