-
Notifications
You must be signed in to change notification settings - Fork 0
/
lu_agency.php
172 lines (138 loc) · 4.74 KB
/
lu_agency.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
<?include_once 'header.php'?>
<?
//Get All Agencies
$sql = "Select * from agencies order by agency_name";
$res = $con->query($sql);
//Check for Adding
$action = "nada";
if (isset($_POST['action'])) {
$action = $_POST['action'];
}
switch ($action) {
case "add":
agency_add($con);
echo " <span></span>";
echo "<script>toastr.success(\"Added\");</script>";
break;
case "save":
echo " <span></span>";
echo "<script>toastr.success(\"Saved\");</script>";
agency_save($con);
break;
case "delete":
agency_delete($con);
echo " <span></span>";
echo "<script>toastr.success(\"Removed\");</script>";
break;
case "nada":
break;
}
$res = $con->query($sql);
?>
<div class="container">
<div class="section">
<div>
<h4> Insert Agency </h4>
</div>
<form method="POST" class="form-inline">
<div class="form-group row">
<input type="hidden" name="action" value="add">
<label for="agency_name" class="col-lg-4 col-form-label">Agency:</label>
<div class="col-lg-6" >
<input type="text" class="form-control" name="agency_name" placeholder="Insert Agency Name">
</div>
<div class="col-lg-2">
<input type="submit" value="Add" class="form-control btn btn-success">
</div>
</div>
</form>
</div>
<hr>
<div class="section row">
<div class="col-ms-12 hdr"> Agency Name</div>
</div>
<!-- Now we're looping -->
<div class="section">
<?php
while ($obj = $res->fetch_object()) {
?>
<div class='lst row'>
<div class='col-md-4'>
<?=$obj->agency_name?>
</div>
<div class="col-md-8 col-xs-4">
<form method="POST">
<input type="hidden" name="action" value="edit">
<input type="hidden" name="agency_id" value="<?=$obj->agency_id?>">
<button type="button" class="btn btn-primary" onClick="edititm(this.form, '<?=$obj->agency_name?>' , '<?=$obj->agency_id?>' )"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-danger" onClick="removeitm(this.form, '<?=$obj->agency_name?>')"><i class="fa fa-trash"></i></button>
</form>
</div>
</div>
<?php
}
//echo $res->num_rows;
?>
</div><!-- end section -->
</div>
<div id="editbox" class="modal">
<!-- Modal content -->
<div class="modal-content" >
<form method="POST">
<input type="hidden" name="action" value="save">
<input type="hidden" name="agency_id" id="edt_id">
<div class="form-group">
<label for="edt_nm">Edit Name:</label>
<div class="form-control">
<input type="text" class="form-control" name="agency_name" id="edt_nm">
</div>
<button class="btn btn-primary">Save</button>
<button class="btn btn-default" onClick="cancelitm()">Cancel</button>
</form>
</div>
</div>
<?php
function agency_add($con)
{
// echo "Inside Function now";
$ins = "insert into agencies(agency_name) values('" . $_POST['agency_name'] . "')";
$con->query($ins);
}
function agency_delete($con) {
$rm = "delete from agencies where agency_id=" . $_POST['agency_id'];
$con->query($rm);
}
function agency_save($con){
$edt = "update agencies set agency_name='" . $_POST['agency_name'] . "' where agency_id=" . $_POST['agency_id'];
$con->query($edt);
}
?>
<script>
function removeitm(frm,nm) {
frm["action"].value="delete";
var bcheck = confirm("Delete this agency: " + nm);
if(bcheck) {
//alert(frm["agency_id"].value);
frm.submit();
}
else {
return false;
}
}
function edititm(frm,nm,id) {
var modal = document.getElementById('editbox');
var div_nm = document.getElementById("edt_nm");
var div_id = document.getElementById("edt_id");
div_nm.value = nm;
div_id.value = id;
modal.style.display = "block";
}
function cancelitm(){
var modal = document.getElementById('editbox');
var div_nm = document.getElementById("edt_nm");
var div_id = document.getElementById("edt_id");
div_nm.value = "";
div_id.value = "";
modal.style.display = "none";
}
</script>