-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_status.php
255 lines (255 loc) · 7.76 KB
/
mod_status.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
<?php include('pages/page_header.php'); ?>
<link href="css/center.css" rel="stylesheet" type="text/css" />
<link href="css/components.css" rel="stylesheet" type="text/css" />
<link href="css/layout.css" rel="stylesheet" type="text/css" />
<!-- <link href="css/setadmin.css" rel="stylesheet" type="text/css" /> -->
<script type = "text/javascript">
history.pushState(null, null, 'mod_status.php');
window.addEventListener('popstate', function(event) {
history.pushState(null, null, 'mod_status.php');
});
</script>
<?php include('pages/page_meta.php'); ?>
<?php
require_once('db/db_config.php');
/**
Check session id.
**/
$login = $_SESSION['LOGIN_ID'];
$dbSelected = mysql_select_db($dbName) or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM tempSession WHERE emailAdd = '$login'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
$data = mysql_fetch_assoc($result);
$sid = $data['sid'];
if($sid == $_SESSION['SID']) {
if(isset($_SESSION['LOGGEDIN']) && isset($_SESSION['SID'])) {
if($_SESSION['GID'] < 3000) {
$fname = $_SESSION['FNAME'];
$uid = $_SESSION['UID'];
$sessionTimeout = $_SESSION['SESSIONTIMEOUT'];
$statusId = $_GET['statusId'];
$lastPage = $_SESSION['LAST_PAGE'];
/**
Lifetime added 5min.
**/
if(isset($_SESSION['EXPIRETIME'])) {
if($_SESSION['EXPIRETIME'] < time()) {
unset($_SESSION['EXPIRETIME']);
header('Location: logout.php?TIMEOUT');
exit(0);
} else {
/**
Session time out time 5min.
**/
//$_SESSION['EXPIRETIME'] = time() + 300;
$_SESSION['EXPIRETIME'] = time() + $sessionTimeout;
};
};
/**
Remove record.
**/
if($_GET['delStatusId']) {
$delStatusId = $_GET['delStatusId'];
deleteRecord($delStatusId);
}
/**
Select status lists.
**/
mysql_select_db($dbName) or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM status WHERE statusId = '$statusId'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
$data = mysql_fetch_array($result);
$statusName = $data['statusName'];
if(isset($_POST['statusId']) && isset($_POST['statusName'])) {
$statusId = $_POST['statusId'];
$statusName = ucwords(mysql_escape_string($_POST['statusName']));
$query = "SELECT DATE_ADD(NOW(), INTERVAL 13 HOUR) as 'dateTime'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$time = $row['dateTime'];
$query = "UPDATE status SET statusName = '$statusName' WHERE statusId = '$statusId'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
if($result) {
/**
Unit information updated and redirected to previous page.
**/
$_SESSION['STATUS'] = 30;
header("Location: status.php");
};
};
} else {
/**
Redirect to dashboard if not Superuser or Manager
**/
$_SESSION['STATUS'] = 10;
header('Location: status.php');
}
} else {
unset($_SESSION['STATUS']);
header('Location: status.php');
};
} else {
unset($_SESSION['STATUS']);
header('Location: status.php');
}
function deleteRecord($delStatusId) {
$query = "UPDATE status SET status = 'Cancel' WHERE statusId = '$delStatusId'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
if($result) {
header('Location: general_settings.php');
}
}
?>
<?php include('pages/page_menu.php'); ?>
<div class="page-container">
<div class="page-head">
<div class="container">
<div class="page-title">
<h1>Modify Status <small>modify status details</small></h1>
</div>
<div class="page-toolbar">
<div class="btn-group btn-theme-panel"><a href="javascript:;" class="btn dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="glyphicon glyphicon-cog"></i></a></div>
</div>
</div>
</div>
<div class="page-content">
<div class="container">
<ul class="breadcrumb">
<li>
<a href="index.php">Home</a><i class="fa fa-circle"></i>
</li>
<li class="active">
Modify Status
</li>
</ul>
<div class="block" style="height:100%">
<div class="centered-usereg">
<div class="row">
<div class="col-md-12">
<div class="portlet light">
<div class="portlet-title">
<div class="caption"><span class="caption-subject font-green-sharp bold uppercase">Modify Status</span></div>
<div class="tools"></div>
</div>
<div class="portlet-body form">
<form role="form" action="" method="post" onsubmit="return validate()">
<div class="form-body text-left">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Status ID</label>
<input type="text" class="form-control input-lg" style="text-align: center" name="statusId" id="statusId" value="<?php echo $statusId; ?>" readonly>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label>Name</label>
<div class="input-icon input-icon-lg">
<i class="fa fa-code"></i>
<input type="text" class="form-control input-lg" id="statusName" placeholder="Status Name" name="statusName" value="<?php echo $statusName; ?>" onkeyup="checkStatusName();" autofocus="on" required>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<span class="error-status" id="statusName_status"></span>
</div>
<div class="col-md-6"></div>
</div>
</div>
<div class="form-actions">
<input type="submit" value="Update" class="btn blue">
<a href="<?php echo $lastPage; ?>"><button type="button" class="btn default">Close</button></a>
<label class="cancel-or-padding">or</label>
<input type="button" id="statusDel" value="DELETE" class="btn red">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include('pages/page_jquery.php'); ?>
<script>
/**
Alertify confirm logout.
**/
$(function() {
$('.logoutAlert').click(function() {
alertify.confirm("[ALERT] Are you sure you want to LOGOUT?", function(result) {
if(result) {
window.location = "logout.php";
}
})
})
})
/**
Bootbox alert customize.
**/
/*
$(function() {
$('.logoutAlert').click(function(){
bootbox.confirm("Are you sure you want to LOGOUT?", function(result) {
if(result) {
window.location = "logout.php";
}
});
})
})
*/
$(function() {
var statusId = document.getElementById("statusId").value;
$('#statusDel').click(function(){
// bootbox.confirm("[CAUTION] Are you sure you want to DELETE this record?", function(result) {
alertify.confirm("[CAUTION] Are you sure you want to DELETE this record?", function(result) {
if(result) {
window.location="mod_status.php?delStatusId=" + statusId;
}
});
})
})
function checkStatusName() {
var statusName = document.getElementById("statusName").value;
if(statusName) {
$.ajax({
type: 'post',
url: 'check_data.php',
data: {
statusName: statusName,
},
success: function (response) {
if(response == "true") {
$('#statusName_status').html("");
return true;
} else {
$('#statusName_status').html(response);
return false;
}
}
});
} else {
$('#statusName_status').html("");
return false;
}
}
function validate() {
var statusName_status = document.getElementById("statusName_status").innerHTML;
if(statusName_status =="") {
return true;
} else {
return false;
}
}
</script>
<?php include('pages/page_footer.php'); ?>
</body>
</html>