-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservicerpt.php
More file actions
444 lines (407 loc) · 19.1 KB
/
servicerpt.php
File metadata and controls
444 lines (407 loc) · 19.1 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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<?php
session_start();
require_once "pdo.php";
if( !isset($_SESSION['id']) )
{
die('ACCESS DENIED');
}
if( $_SESSION['role'] != '0' )
{
die('ACCESS DENIED');
}
if(isset($_POST['cancel']))
{
header("Location: index.php");
return;
}
if(!isset($_POST['department']))
{
$autoc=$pdo->prepare("SELECT department,purpose,quantity from transfer_request where transfer_request_id = :tid");
$autoc->execute(array(':tid'=>$_GET['id']));
$rowauto=$autoc->fetch(PDO::FETCH_ASSOC);
$dept=$rowauto['department'];
$pur=$rowauto['purpose'];
$qty=$rowauto['quantity'];
}
if(!isset($_GET['id']))
{
$_SESSION['error']="Transfer Request not Found<br>";
header("Location:home.php");
return;
}
else if(isset($_POST['department']) )
{
/*
if ( strlen($_POST['name']) < 1 || strlen($_POST['department']) < 1 || strlen($_POST['purpose']) < 1|| strlen($_POST['quantity']) < 1)
{
$_SESSION['error'] = "All Fields are required";
header('Location: servicerpt.php');
return;
}
*/
// else
$flag1=0;
for($i=1;$i<=$_POST['totalqty'];$i++)
{
$getmid=$pdo->prepare('SELECT COUNT(*),machine_id from machine where MAC_ADDR = :mid and state=:act');
$getmid->execute( array(':mid' => $_POST["machine".$i],':act' => 'ACTIVE'));
$row=$getmid->fetch(PDO::FETCH_ASSOC);
if($row['COUNT(*)']==0)
{
$flag1=1;
$_SESSION['error']="Machine".$row['machine_id']."Not found \n";
header("Location:home.php");
return;
}
}
$stmt2=$pdo->prepare('SELECT lab_id from lab where name = :labid');
$stmt2->execute( array(':labid' => $_POST['labid'] ));
$row=$stmt2->fetch(PDO::FETCH_ASSOC);
$labid=$row['lab_id'];
$stmt = $pdo->prepare('INSERT INTO system_transfer_report( department, purpose, lab_id ,date_of_assignment,trid) VALUES (:dept, :purpose, :labid, :dat,:trid)');
$stmt->execute(array(':dept' => $_POST['department'], ':purpose' => $_POST['purpose'], ':labid'=>$labid,':dat' => date('y-m-d'),':trid'=>$_GET['id']));
$strid = $pdo->lastInsertId();
if($flag1==1)
{
return;
}
for($i =1 ;$i<=$_POST['totalqty'];$i++)
{
$getmid=$pdo->prepare('SELECT machine_id,COUNT(*) from machine where MAC_ADDR = :mid and state=:act');
$getmid->execute( array(':mid' => $_POST["machine".$i],':act' => 'ACTIVE'));
$row=$getmid->fetch(PDO::FETCH_ASSOC);
$mid=$row['machine_id'];
if($row['COUNT(*)']!=0)
{
$stmt3= $pdo->prepare("UPDATE position set final_date= :fdate WHERE machine_id = :mid AND final_date='1970-01-01'");
$stmt3->execute(array(':mid' => $mid,':fdate'=>date('y-m-d') ));
$insdata=$pdo->prepare("INSERT INTO position (machine_id,lab_id,initial_date,final_date) VALUES(:mid,:labid,:idate,:fdate)");
$insdata->execute(array(':mid'=>$mid,':labid' =>$labid ,':idate' => date('y-m-d'),':fdate' =>'1970-01-01'));
$insdata2=$pdo->prepare("INSERT INTO system_transfer_report_history (system_transfer_report_id, machine_id) VALUES(:strid, :mid)");
$insdata2->execute(array(':strid'=>$strid,':mid' =>$mid));
$_SESSION['success'] = "Machine ".$_POST['machine'.$i]." Sent Successfully";
}
else
{
$_SESSION['error']="Unable to transfer machine ".$_POST['machine'.$i].". Machine is either inactive or does not exsists";
}
}
//header("Location: printservice_report.php?strid=$strid");
echo("<script>
window.open('printservice_report.php?strid=$strid', '_blank');
</script>");
echo("<script>window.open('home.php','_self')</script>");
//header("Location:home.php");
//return;
}
$processor = $pdo->query("SELECT name_id FROM name where name = 'processor'");
$processorn = $processor->fetch(PDO::FETCH_ASSOC);
$processorn=$processorn['name_id'];
$ram= $pdo->query("SELECT name_id FROM name where name = 'ram'");
$ramn = $ram->fetch(PDO::FETCH_ASSOC);
$ramn=$ramn['name_id'];
$memory = $pdo->query("SELECT name_id FROM name where name = 'harddisk'");
$memoryn = $memory->fetch(PDO::FETCH_ASSOC);
$memoryn=$memoryn['name_id'];
if(isset($_POST['processor'])&&$_POST['processor']=='-1')
$processorfilter='*';
else if(isset($_POST['processor']))
$processorfilter=$_POST['processor'];
if(isset($_POST['ram'])&&$_POST['ram']=='-1')
$ramfilter='*';
else if(isset($_POST['ram']))
$ramfilter=$_POST['ram'];
if(isset($_POST['memory'])&&$_POST['memory']=='-1')
$memoryfilter='*';
else if(isset($_POST['memory']))
$memoryfilter=$_POST['memory'];
if(isset($_POST['os'])&&$_POST['os']=='-1')
$osfilter='*';
else if(isset($_POST['os']))
$osfilter=$_POST['os'];
?>
<html>
<head>
<title>Machine Tracking</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width = device-width, initial-scale = 1">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<link rel="stylesheet" type="text/css" href="style5.css">
<style>
.input-group-addon {
min-width:150px;
text-align:left;
}
</style>
</head>
<body>
<div class="wrapper">
<?php if (isset($_SESSION['id'])&&$_SESSION['role']=='0') include "navbar.php";
else if(isset($_SESSION['id'])&&$_SESSION['role']=='1') include "navbar_faculty.php";
else include "navbar_tech.php";?>
<div class="container" id="content">
<div class="page-header">
<h1>System Transfer Report</h1>
</div>
<div id="error" style="color: red; margin-left: 90px; margin-bottom: 20px;">
</div>
<?php
if ( isset($_SESSION['error']) )
{
echo('<p style="color: red;">'.$_SESSION['error']."</p>\n");
unset($_SESSION['error']);
}
?>
<form method="POST" action= "<?= 'servicerpt.php?id='.$_GET['id'] ?>" class="col-xs-5">
<div class="input-group">
<span class="input-group-addon">Department </span>
<input type="text" value="<?= $dept ?>" disabled class="form-control"> </div><br/>
<input type="text" name="department" value="<?= $dept ?>" hidden>
<div class="input-group">
<span class="input-group-addon">Purpose</span>
<input type="text" value ="<?= $pur ?>" disabled class="form-control"> </div><br/>
<input type="text" name="purpose" value ="<?= $pur ?>" hidden>
<div class="input-group">
<span class="input-group-addon">Lab no.</span>
<select name="labid" class="form-control" required>
<?php
$read=$pdo->query('select name,lab_id from lab order by name');
while($row = $read->fetch(PDO::FETCH_ASSOC))
{
$labname=$row['name'];
$labid=$row['lab_id'];
echo '<option name = $labid>';
echo $labname;
echo '</option>';
}
?>
</select>
</div><br>
<div class="input-group">
<span class="input-group-addon">Choose number of PC</span><input type="Number" class="form-control" name="totalqty" id="totalqty" value = "<?php echo $qty; ?>" min=1 onchange="addtags();" required>
<br>
<!--a class="link-black" href="#" onclick="addtags()">Add Machines</a-->
</div>
<br>
<div id="add-machine" class="input-group"></div>
<script type="text/javascript">
var total=document.getElementById("totalqty").value;
var addimg=document.getElementById("add-machine");
while (addimg.hasChildNodes())
{
addimg.removeChild(addimg.lastChild);
}
for (i=1;i<=total;i++)
{
addimg.appendChild(document.createTextNode("Machine " + i+" Address"));
var ipt = document.createElement("input");
ipt.type = "text";
ipt.name = "machine"+ i;
idadd=document.createAttribute('id');
idadd.value="machine"+ i;
ipt.setAttributeNode(idadd);
classadd=document.createAttribute('class');
classadd.value="form-control";
ipt.setAttributeNode(classadd);
onchangeadd=document.createAttribute("onchange");
onchangeadd.value= "Number(this.id);"//Number('machine'+i);";
ipt.setAttributeNode(onchangeadd);
var att=document.createAttribute("required");
ipt.setAttributeNode(att);
// addimg.appendChild(ipt);
// addimg.appendChild(document.createElement("br"));
document.getElementById("add-machine").appendChild(ipt);
document.getElementById("add-machine").innerHTML+='<br><br>';
}
</script>
<input type="submit" value="Register Transfer Request" class="btn btn-info">
<a class ="link-no-format" href="home.php"><div class="btn btn-my">Cancel</div></a>
</form>
<div class="page-header">
<form method="POST" class="form-inline col-xs-12">
<label id="processor">Processor</label>
<select class="form-control" id="processor" name="processor">
<option value="-1">Any</option>
<?php
//This query will select all distinct(description) and hardware_id from hardware table and name will be equal to processor number selected in line 13
$qr=$pdo->prepare("SELECT spec from specification WHERE name_id=:processorn");
$qr->execute(array(":processorn"=>$processorn));
while($row=$qr->fetch(PDO::FETCH_ASSOC))
{
echo "<option>". $row['spec']."</option> ";
}
?>
</select>
<label id="ram">RAM</label>
<select class="form-control" id="ram" name="ram">
<option value='-1'>Any</option>
<?php
//This query will select all distinct(description) and hardware_id from hardware table and name will be equal to ram number selected in line 13
$qr=$pdo->prepare("SELECT spec from specification WHERE name_id=:ramn");
$qr->execute(array(":ramn"=>$ramn));
while($row=$qr->fetch(PDO::FETCH_ASSOC))
{
echo "<option>". $row['spec']."</option>";
}
?>
</select>
<label id="memory">Memory</label>
<select class="form-control" id="memory" name="memory">
<option value='-1'>Any</option>
<?php
//This query will select all distinct(description) and hardware_id from hardware table and name will be equal to memory number selected in line 13
$qr=$pdo->prepare("SELECT spec from specification WHERE name_id=:memoryn");
$qr->execute(array(":memoryn"=>$memoryn));
// $qr=$pdo->query("SELECT distinct(os) from machine");
while($row=$qr->fetch(PDO::FETCH_ASSOC))
{
echo "<option>". $row['spec']."</option>";
//echo "<option>". $row['memory']."</option>";
}
?>
<!--ipt.onchange="Number(machine"+i+")";-->
</select>
<label id="os">OS</label>
<select class="form-control" id="os" name="os">
<option value='-1'>Any</option>
<?php
//AS OS is stored directly in machine table simple query is used
$qr=$pdo->query("SELECT distinct(os) from machine");
while($row=$qr->fetch(PDO::FETCH_ASSOC))
{
echo "<option>". $row['os']."</option>";
}
?>
</select>
<input class="btn btn-my"type="submit" name="submit">
</form>
</div>
<?php
if ( isset($_SESSION['error']) )
{
echo('<p style="color: red;">'.$_SESSION['error']."</p>\n");
unset($_SESSION['error']);
}
if ( isset($_SESSION['success']))
{
echo('<p style="color: green;">'.$_SESSION['success']."</p>\n");
unset($_SESSION['success']);
}
//Now this code does all the magic
if(isset($_POST['processor'])||isset($_POST['ram'])||isset($_POST['memory'])||isset($_POST['os']))
{
//Checking if machine exsists
$stmtcnt = $pdo->query("SELECT COUNT(*) FROM machine ");
$row = $stmtcnt->fetch(PDO::FETCH_ASSOC);
if($row['COUNT(*)']!=='0')
{
echo ("<table class=\"table table-striped\">
<tr> <th>S.no.</th><th>MAC ADDRESS</th><th>Processor</th><th>RAM</th><th>Storage</th><th>OS</th><th>DOP</th><th>Price</th><th>Location</th></tr>");
$stmt=$pdo->query("SELECT * FROM machine");
$i=1;
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
$stmtn = $pdo->prepare("SELECT lab_id FROM position where machine_id = :mid AND final_date = '1970-01-01'");
$stmtn->execute(array(':mid' => $row['machine_id']));
$rown = $stmtn->fetch(PDO::FETCH_ASSOC);
$stmtn2 = $pdo->prepare("SELECT name FROM lab where lab_id = :lid");
$stmtn2->execute(array(':lid' => $rown['lab_id']));
$rownlabid = $stmtn2->fetch(PDO::FETCH_ASSOC);
//echo $row['processor'];
$stmtrow=$pdo->prepare("SELECT spec FROM specification JOIN hardware ON(specification.spec_id = hardware.description AND hardware.hardware_id=:hid)"
);
$stmtrow->execute(array(":hid"=>$row['processor']));
$processorspec=$stmtrow->fetch(PDO::FETCH_ASSOC);
$stmtrow=$pdo->prepare("SELECT spec FROM specification JOIN hardware ON(specification.spec_id = hardware.description AND hardware.hardware_id = :hid)"
);
$stmtrow->execute(array(":hid"=>$row['ram']));
$ramspec=$stmtrow->fetch(PDO::FETCH_ASSOC);
$stmtrow=$pdo->prepare("SELECT spec FROM specification JOIN hardware ON(specification.spec_id = hardware.description AND hardware.hardware_id = :hid)"
);
$stmtrow->execute(array(":hid"=>$row['memory']));
$memoryspec=$stmtrow->fetch(PDO::FETCH_ASSOC);
if($_POST['processor']!='-1'&&$processorspec['spec']!=$_POST['processor'])
continue;
if($_POST['ram']!='-1'&&$ramspec['spec']!=$_POST['ram'])
continue;
if($_POST['memory']!='-1'&&$memoryspec['spec']!=$_POST['memory'])
continue;
if($_POST['os']!='-1'&&$row['os']!=$_POST['os'])
continue;
if($row['state']=='INACTIVE')
continue;
echo ("<tr>");
echo ("<td>");
echo($i);
echo("</td>");
echo ("<td>");
echo(htmlentities($row['MAC_ADDR']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($processorspec['spec']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($ramspec['spec']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($memoryspec['spec']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($row['os']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($row['DOP']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($row['price']));
echo ("</td>");
echo ("<td>");
echo(htmlentities($rownlabid['name']));
echo ("</td>");
$i++;
}
}
}
?>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
function addtags()
{
var total=document.getElementById("totalqty").value;
var addimg=document.getElementById("add-machine");
while (addimg.hasChildNodes())
{
addimg.removeChild(addimg.lastChild);
}
for (i=1;i<=total;i++)
{
addimg.appendChild(document.createTextNode("Machine " + i+" Address"));
var ipt = document.createElement("input");
ipt.type = "text";
ipt.name = "machine"+ i;
idadd=document.createAttribute('id');
idadd.value="machine"+ i;
ipt.setAttributeNode(idadd);
classadd=document.createAttribute('class');
classadd.value="form-control";
ipt.setAttributeNode(classadd);
onchangeadd=document.createAttribute("onchange");
onchangeadd.value= "Number(this.id);"//Number('machine'+i);";
ipt.setAttributeNode(onchangeadd);
var att=document.createAttribute("required");
ipt.setAttributeNode(att);
// addimg.appendChild(ipt);
// addimg.appendChild(document.createElement("br"));
document.getElementById("add-machine").appendChild(ipt);
document.getElementById("add-machine").innerHTML+='<br><br>';
}
}
</script>
</body>
</html>