-
Notifications
You must be signed in to change notification settings - Fork 0
/
showAll.php
168 lines (147 loc) · 4.85 KB
/
showAll.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
<?php include("db_rw.php");
session_start();
if($_SESSION["user"]!=null){
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 60%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<a href="medicine.php">BACK</a>
<div class="form-control" align="center">
<a href="showAll.php"><button class="btn Show" id="btnShow" style="color: blue;">Show All</button></a>
<a href="logout.php"><button class="btn btn-danger" id="btnShow" style="color: blue;">Log Out</button></a>
</div>
<h2 class="text-center" style="color: blue">Medicine List</h2>
<span><?php if($_SESSION['msg']!=NULL) echo $_SESSION['msg'] ?></span>
Search By <select id="slctBy" >
<option value="0">Medicine Name</option>
<option value="2">Company Name</option>
<option value="3">Group Name</option>
</select><br><br>
<input type="text" id="srcInput" onkeyup="search()" placeholder="Search for names.." title="Type in a name" class="form-control" style="margin-right: 25%;">
<br>
<table id="myTable">
<tr class="header">
<th style="width:20%;">Name</th>
<th style="width:15%;">Power</th>
<th style="width:15%">Company</th>
<th style="width:20%">Group Name</th>
<th style="width:15%">Unit Price</th>
<th style="width:10%">Update</th>
<th style="width:10%">Delete</th>
</tr>
<?php
$jsonData= getJSONFromDB("select * from medicine where Activity='Active'");
$jsn=json_decode($jsonData,true);
foreach($jsn as $v){
$groupData= getDataFromDB("select group_name from med_group where group_id='".$v["Group_id"]."'");
?>
<tr>
<td><?php echo $v["Name"];?></td>
<td><?php echo $v["Power"];?></td>
<td><?php echo $v["Company"];?></td>
<?php
foreach($groupData as $gr ){
?>
<td><?php echo $gr["group_name"];?></td>
<?php
}
?>
<td><?php echo $v["Unit_price"];?></td>
<td> <button class="btn btn-primary" id="<?php echo $v['MCode'] ?>" onclick="editData(this.id)">Edit</button></td>
<td><button class="btn btn-danger" id="<?php echo $v['MCode'] ?>" onclick="dltMed(this.id)">Delete</button></td>
</tr>
<?php
}
?>
</table>
<script>
function search() {
var selectId=document.getElementById("slctBy").value;
var input, filter, table, tr, td, i;
input = document.getElementById("srcInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[selectId];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
function dltMed(code){
str=code;
//alert(str);
//window.location = 'delete.php?code=' + code;
var result = confirm("Are you sure you want to delete?");
if (result) {
//Logic to delete the item
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
resp=xmlhttp.responseText;
//alert(resp);
window.location = 'showAll.php';
}
};
var url='delete.php?code=' + code;
//alert(url);
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
else{
window.location = 'showAll.php';
}
}
function editData(code) {
str=code;
//alert(str);
window.location = 'updateMedicine.php?code=' + code;
}
</script>
</body>
</html>
<?php
}
else{
header("Location:index.php");
}