|
1 | 1 | <?php
|
2 | 2 | session_start();
|
3 | 3 | require_once 'config/config.php';
|
4 |
| -require_once BASE_PATH.'/includes/auth_validate.php'; |
| 4 | +require_once BASE_PATH . '/includes/auth_validate.php'; |
5 | 5 |
|
6 | 6 | // Costumers class
|
7 |
| -require_once BASE_PATH.'/lib/Costumers/Costumers.php'; |
| 7 | +require_once BASE_PATH . '/lib/Costumers/Costumers.php'; |
8 | 8 | $costumers = new Costumers();
|
9 | 9 |
|
10 | 10 | // Get Input data from query string
|
|
13 | 13 | $order_by = filter_input(INPUT_GET, 'order_by');
|
14 | 14 |
|
15 | 15 | // Per page limit for pagination.
|
16 |
| -$pagelimit = 20; |
| 16 | +$pagelimit = 15; |
17 | 17 |
|
18 | 18 | // Get current page.
|
19 | 19 | $page = filter_input(INPUT_GET, 'page');
|
20 |
| -if (!$page) |
21 |
| -{ |
22 |
| - $page = 1; |
| 20 | +if (!$page) { |
| 21 | + $page = 1; |
23 | 22 | }
|
24 | 23 |
|
25 | 24 | // If filter types are not selected we show latest added data first
|
26 |
| -if (!$filter_col) |
27 |
| -{ |
28 |
| - $filter_col = 'id'; |
| 25 | +if (!$filter_col) { |
| 26 | + $filter_col = 'id'; |
29 | 27 | }
|
30 |
| -if (!$order_by) |
31 |
| -{ |
32 |
| - $order_by = 'Desc'; |
| 28 | +if (!$order_by) { |
| 29 | + $order_by = 'Desc'; |
33 | 30 | }
|
34 | 31 |
|
35 | 32 | //Get DB instance. i.e instance of MYSQLiDB Library
|
36 | 33 | $db = getDbInstance();
|
37 |
| -$select = array('id', 'f_name', 'l_name', 'gender', 'phone','created_at','updated_at'); |
| 34 | +$select = array('id', 'f_name', 'l_name', 'gender', 'phone', 'created_at', 'updated_at'); |
38 | 35 |
|
39 | 36 | //Start building query according to input parameters.
|
40 | 37 | // If search string
|
41 |
| -if ($search_string) |
42 |
| -{ |
43 |
| - $db->where('f_name', '%' . $search_string . '%', 'like'); |
44 |
| - $db->orwhere('l_name', '%' . $search_string . '%', 'like'); |
| 38 | +if ($search_string) { |
| 39 | + $db->where('f_name', '%' . $search_string . '%', 'like'); |
| 40 | + $db->orwhere('l_name', '%' . $search_string . '%', 'like'); |
45 | 41 | }
|
46 | 42 |
|
47 | 43 | //If order by option selected
|
48 |
| -if ($order_by) |
49 |
| -{ |
50 |
| - $db->orderBy($filter_col, $order_by); |
| 44 | +if ($order_by) { |
| 45 | + $db->orderBy($filter_col, $order_by); |
51 | 46 | }
|
52 | 47 |
|
53 | 48 | // Set pagination limit
|
|
57 | 52 | $rows = $db->arraybuilder()->paginate('customers', $page, $select);
|
58 | 53 | $total_pages = $db->totalPages;
|
59 | 54 |
|
60 |
| -include BASE_PATH.'/includes/header.php'; |
| 55 | +include BASE_PATH . '/includes/header.php'; |
61 | 56 | ?>
|
62 | 57 | <!-- Main container -->
|
63 | 58 | <div id="page-wrapper">
|
|
71 | 66 | </div>
|
72 | 67 | </div>
|
73 | 68 | </div>
|
74 |
| - <?php include BASE_PATH.'/includes/flash_messages.php'; ?> |
| 69 | + <?php include BASE_PATH . '/includes/flash_messages.php';?> |
75 | 70 |
|
76 | 71 | <!-- Filters -->
|
77 | 72 | <div class="well text-center filter-form">
|
|
81 | 76 | <label for="input_order">Order By</label>
|
82 | 77 | <select name="filter_col" class="form-control">
|
83 | 78 | <?php
|
84 |
| - foreach ($costumers->setOrderingValues() as $opt_value => $opt_name): |
85 |
| - ($order_by === $opt_value) ? $selected = 'selected' : $selected = ''; |
86 |
| - echo ' <option value="'.$opt_value.'" '.$selected.'>'.$opt_name.'</option>'; |
87 |
| - endforeach; |
88 |
| - ?> |
| 79 | +foreach ($costumers->setOrderingValues() as $opt_value => $opt_name): |
| 80 | + ($order_by === $opt_value) ? $selected = 'selected' : $selected = ''; |
| 81 | + echo ' <option value="' . $opt_value . '" ' . $selected . '>' . $opt_name . '</option>'; |
| 82 | +endforeach; |
| 83 | +?> |
89 | 84 | </select>
|
90 | 85 | <select name="order_by" class="form-control" id="input_order">
|
91 | 86 | <option value="Asc" <?php
|
92 |
| - if ($order_by == 'Asc') { |
93 |
| - echo 'selected'; |
94 |
| - } |
95 |
| - ?> >Asc</option> |
| 87 | +if ($order_by == 'Asc') { |
| 88 | + echo 'selected'; |
| 89 | +} |
| 90 | +?> >Asc</option> |
96 | 91 | <option value="Desc" <?php
|
97 |
| - if ($order_by == 'Desc') { |
98 |
| - echo 'selected'; |
99 |
| - } |
100 |
| - ?>>Desc</option> |
| 92 | +if ($order_by == 'Desc') { |
| 93 | + echo 'selected'; |
| 94 | +} |
| 95 | +?>>Desc</option> |
101 | 96 | </select>
|
102 | 97 | <input type="submit" value="Go" class="btn btn-primary">
|
103 | 98 | </form>
|
|
120 | 115 | <?php foreach ($rows as $row): ?>
|
121 | 116 | <tr>
|
122 | 117 | <td><?php echo $row['id']; ?></td>
|
123 |
| - <td><?php echo htmlspecialchars($row['f_name'].' '.$row['l_name']); ?></td> |
| 118 | + <td><?php echo htmlspecialchars($row['f_name'] . ' ' . $row['l_name']); ?></td> |
124 | 119 | <td><?php echo htmlspecialchars($row['gender']); ?></td>
|
125 | 120 | <td><?php echo htmlspecialchars($row['phone']); ?></td>
|
126 | 121 | <td>
|
|
151 | 146 | </div>
|
152 | 147 | </div>
|
153 | 148 | <!-- //Delete Confirmation Modal -->
|
154 |
| - <?php endforeach; ?> |
| 149 | + <?php endforeach;?> |
155 | 150 | </tbody>
|
156 | 151 | </table>
|
157 | 152 | <!-- //Table -->
|
158 | 153 |
|
159 | 154 | <!-- Pagination -->
|
160 | 155 | <div class="text-center">
|
161 |
| - <?php |
162 |
| - if (!empty($_GET)) { |
163 |
| - // We must unset $_GET[page] if previously built by http_build_query function |
164 |
| - unset($_GET['page']); |
165 |
| - // To keep the query sting parameters intact while navigating to next/prev page, |
166 |
| - $http_query = "?" . http_build_query($_GET); |
167 |
| - } else { |
168 |
| - $http_query = "?"; |
169 |
| - } |
170 |
| - // Show pagination links |
171 |
| - if ($total_pages > 1) { |
172 |
| - echo '<ul class="pagination text-center">'; |
173 |
| - for ($i = 1; $i <= $total_pages; $i++) { |
174 |
| - ($page == $i) ? $li_class = ' class="active"' : $li_class = ''; |
175 |
| - echo '<li' . $li_class . '><a href="customers.php' . $http_query . '&page=' . $i . '">' . $i . '</a></li>'; |
176 |
| - } |
177 |
| - echo '</ul>'; |
178 |
| - } |
179 |
| - ?> |
| 156 | + <?php echo paginationLinks($page, $total_pages, 'customers.php'); ?> |
180 | 157 | </div>
|
181 | 158 | <!-- //Pagination -->
|
182 | 159 | </div>
|
183 | 160 | <!-- //Main container -->
|
184 |
| -<?php include BASE_PATH.'/includes/footer.php'; ?> |
| 161 | +<?php include BASE_PATH . '/includes/footer.php';?> |
0 commit comments