-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_category.php
236 lines (236 loc) · 8.03 KB
/
mod_category.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
<?php include('pages/page_header.php'); ?>
<link href="css/pmf-settings.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" />
<?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'];
$partsCategoryId = $_GET['partsCategoryId'];
// 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['delCategoryId']) {
$delId = $_GET['delCategoryId'];
deleteRecord($delId, 'partsCategory', 'partsCategoryId');
}
// Select parts uom.
mysql_select_db($dbName) or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM partsCategory WHERE partsCategoryId = '$partsCategoryId'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
$data = mysql_fetch_array($result);
$partsCategoryName = $data['partsCategoryName'];
if(isset($_POST['partsCategoryId']) && isset($_POST['partsCategoryName'])) {
$partsCategoryId = $_POST['partsCategoryId'];
$partsCategoryName = ucwords(strtolower(mysql_escape_string($_POST['partsCategoryName'])));
$query = "SELECT DATE_ADD(NOW(), INTERVAL 13 HOUR) AS 'dateTime'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$time = $row['dateTime'];
$query = "UPDATE partsCategory SET partsCategoryName = '$partsCategoryName' WHERE partsCategoryId = '$partsCategoryId'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
if($result) {
// Category details updated and redirected to previous page.
$_SESSION['STATUS'] = 38;
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($idx, $tables, $tableId) {
$query = "UPDATE $tables SET status = 'Cancel' WHERE $tableId = '$idx'";
$result = mysql_query($query);
if(!$result) die ("Table access failed: " . mysql_error());
if($result) {
header('Location: pmf_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 Category <small>modify category 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>
<a href="javascript:;">Extras</a><i class="fa fa-circle"></i>
</li>
<li>
<a href="javascript:;">Setup</a><i class="fa fa-circle"></i>
</li>
<li>
<a href="javascript:;">Parts Master File</a><i class="fa fa-circle"></i>
</li>
<li class="active">
Modify Category
</li>
</ul>
<div class="row margin-top-10">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="portlet light">
<div class="portlet-title">
<div class="caption"><span class="caption-subject font-green-sharp bold uppercase">Modify Category</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>Category ID</label>
<input type="text" id="partsCategoryId" class="form-control input-lg" style="text-align: center" name="partsCategoryId" value="<?php echo $partsCategoryId; ?>" 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="partsCategoryName" placeholder="Category Name" name="partsCategoryName" value="<?php echo $partsCategoryName; ?>" onkeyup="checkCategoryName();" autofocus="on" onfocus="this.value = this.value;" required>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<span class="error-status" id="partsCategoryName_status"></span>
</div>
<div class="col-md-6"></div>
</div>
</div>
<div class="form-actions" style="text-align: center">
<input type="submit" value="Update" class="btn blue">
<a href="pmf_settings.php"><button type="button" class="btn default">Close</button></a>
<label class="cancel-or-padding">or</label>
<!-- <input type="button" value="DELETE" class="btn red" onclick="return deleteData();"> -->
<input type="button" id="partsCategoryDel" value="DELETE" class="btn red">
</div>
</form>
</div>
</div>
</div>
<div class="col-md-3"></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 partsCategoryId = document.getElementById("partsCategoryId").value;
$('#partsCategoryDel').click(function(){
alertify.confirm("[CAUTION] Are you sure you want to DELETE this record?", function(result) {
if(result) {
window.location="mod_category.php?delCategoryId=" + partsCategoryId;
}
});
})
})
function checkCategoryName() {
var partsCategoryName = document.getElementById("partsCategoryName").value;
if(partsCategoryName) {
$.ajax({
type: 'post',
url: 'check_data.php',
data: {
partsCategoryName: partsCategoryName,
},
success: function (response) {
if(response == "true") {
$('#partsCategoryName_status').html("");
return true;
} else {
$('#partsCategoryName_status').html(response);
return false;
}
}
});
} else {
$('#partsCategoryName_status').html("");
return false;
}
}
function validate() {
var partsCategoryName_status = document.getElementById("partsCategoryName_status").innerHTML;
if(partsCategoryName_status =="") {
return true;
} else {
return false;
}
}
</script>
<?php include('pages/page_footer.php'); ?>
</body>
</html>