-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcategory.php
254 lines (207 loc) · 9.44 KB
/
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
include('lock.php');
include_once('plugins/html_table.class.php');
include_once('config.db.php');
include_once('dbplugin.php');
include_once('plugins/KLogger.php');
$error = $_GET['error'];
$success = $_GET['success'];
// number of rows per page
$page_rows = 10;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>expense tracker | Category Management</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="css/pagination.css" type="text/css" media="screen"/>
<link type="text/css" href="scripts/jquery/css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="scripts/jquery/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="scripts/jquery/js/jquery-ui-1.10.3.custom.js"></script>
<style type="text/css">
table.demoTbl {
border-collapse: collapse;
border-spacing: 0;
}
#tblCap {
font-weight: bold;
font-size: 15px;
margin: 1em auto .4em;
}
table.demoTbl .category {
width: 400px;
}
table.demoTbl .actions {
width: 150px;
}
table.demoTbl td, table.demoTbl th {
padding: 1px;
}
table.demoTbl th.first {
text-align: center;
padding: 3px;
background-color: #CCCCCC;
border: 2px solid #FFFFFF;
}
table.demoTbl td.cat {
text-align: left;
padding-left: 150px;
}
table.demoTbl td.actions {
text-align: center;
}
table.demoTbl td.foot {
text-align: center;
}
</style>
<script type="text/javascript">
$(function () {
$("#add-cat-btn").button();
});
</script>
</head>
<body>
<body>
<div id="container">
<?php include("header.php"); ?>
<?php include("menu.php"); ?>
<div id="content">
<div id="main_content">
<h2>Category Management</h2><br>
<div id="form_content">
<form id="addCat" action='category_handler.php' method='post'>
<div id="form_left">
<label>Category Name : </label>
</div>
<div id="form_right">
<input id="category" name="category" type=="text">
<br><br>
<button id="add-cat-btn">Add Category</button>
</div>
<br><br>
<br><br>
</form>
<br><br>
<div style="padding-left:50px; font-size:15px; color:#FF0000;"><?php echo $error; ?></div>
<div style="padding-left:50px; font-size:15px; color:#19aa2f;"><?php echo $success; ?></div>
<br>
<?php
// pagination
$pagenum = $_GET['pagenum'];
// populate table
$getcatsql = "SELECT id,category from category WHERE status='ACTIVE'";
$cat_result = mysqli_query($db, $getcatsql);
$rowcount = mysqli_num_rows($cat_result);
if ($rowcount >= 1) {
$log = new KLogger ("/var/www/extracker/logs/", KLogger::DEBUG);
// arguments: id, class, border,
// can include associative array of optional additional attributes
$tbl = new HTML_Table('', 'demoTbl', 0);
$tbl->addCaption('Categories', 'cap', array('id' => 'tblCap'));
$tbl->addColgroup();
// span, class
$tbl->addCol(0, 'category');
$tbl->addCol(1, 'actions');
// thead
$tbl->addTSection('thead');
$tbl->addRow();
// arguments: cell content, class, type (default is 'data' for td, pass 'header' for th)
// can include associative array of optional additional attributes
$tbl->addCell('Category', 'first', 'header');
$tbl->addCell('Actions', 'first', 'header');
// tfoot
$tbl->addTSection('tfoot');
$tbl->addRow();
// span all 3 columns
$tbl->addCell('', 'foot', 'data', array('colspan' => 4));
// tbody
$tbl->addTSection('tbody');
if (!(isset($pagenum))) {
$pagenum = 1;
}
//This tells us the page number of our last page
$last = ceil($rowcount / $page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1) {
$pagenum = 1;
} elseif ($pagenum > $last) {
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysqli_query($db, $getcatsql . $max) or die(mysql_error());
while ($row = mysqli_fetch_array($data_p)) {
$id = $row['id'];
$ctgry = $row['category'];
$actions = "<a href='category_handler.php?delid=" . $id . "' method='post'><button class=\"ui-state-default ui-corner-all\" title=\"delete record\" onclick=\"deleteRecord($recId)\"><span class=\"ui-icon ui-icon-trash\"></span></button></a>";
$tbl->addRow();
$tbl->addCell($ctgry, 'cat');
$tbl->addCell($actions, 'actions');
}
echo $tbl->display();
echo "<br>";
$html = '';
$current_page = $pagenum;
if ($current_page != 1) {
$html .= '<a class="first" title="First" href="category.php?pagenum=1">«</a>';
$previousPageNumber = $current_page - 1;
$previousPage = "category.php?pagenum=" . $previousPageNumber;
$html .= '<a class="first" title="Previous" href=' . $previousPage . '>Previous</a>';
} else {
$html .= '<span class="disabled first" title="First">«</span>';
$html .= '<span class="disabled first" title="Previous">Previous</span>';
}
for ($i = 1; $i <= $last; $i++) {
if ($i != $current_page) {
$pageNumber = "category.php?pagenum=" . $i;
$html .= '<a title="' . $i . '" href=' . $pageNumber . '>' . $i . '</a>';
} else {
$html .= '<span class="current">' . $i . '</span>';
}
}
if ($current_page != $last) {
$nextPageNumber = $current_page + 1;
$nextPage = "category.php?pagenum=" . $nextPageNumber;
$html .= '<a class="next" title="Next" href=' . $nextPage . '>Next</a>';
$lastPage = "category.php?pagenum=" . $last;
$html .= '<a class="last" title="Last" href=' . $lastPage . '>»</a>';
} else {
$html .= '<span class="disabled next" title="Next">Next</span>';
$html .= '<span class="disabled last" title="Last">»</span>';
}
echo '<div class="pagination">' . $html . '</div>';
} else {
$tbl = new HTML_Table('', 'demoTbl', 0);
$tbl->addCaption('Categories', 'cap', array('id' => 'tblCap'));
$tbl->addColgroup();
// span, class
$tbl->addCol(0, 'category');
$tbl->addCol(1, 'actions');
// thead
$tbl->addTSection('thead');
$tbl->addRow();
// arguments: cell content, class, type (default is 'data' for td, pass 'header' for th)
// can include associative array of optional additional attributes
$tbl->addCell('Category', 'first', 'header');
$tbl->addCell('Actions', 'first', 'header');
$tbl->addTSection('tbody');
$tbl->addRow();
// span all 3 columns
$tbl->addCell('<br><br><b>No Data to Display</b>', 'foot', 'data', array('colspan' => 4));
echo $tbl->display();
}
?>
</div>
</div>
<div id="summary_content">
<?php include("stats.php"); ?>
</div>
<div id="clearfix"></div>
</div>
<?php include("footer.php"); ?>
</div>
</body>
</html>