public static function pagedTable($rows, $searchfields = array(), $orderfields = false, $view = false, $params = false, $extra_buttons = false) { if ($params == false) { $params = $_GET; } self::pagedHeader($rows, $searchfields, $orderfields, $view, $params, $extra_buttons); $count = count($rows); $page_length = isset($params['page_length']) ? $params['page_length'] + 0 : self::$DEFAULT_PAGE_LENGTH; if ($page_length < 0) { $page_length = 0; } // When we are doing paging, we select page_length+1 rows to know whether // we should show a Next button - but we don't want to show that extra // row in the output. if ($page_length > 0 && $count > $page_length) { $count = $page_length; } if ($count < 1) { echo "<p>Nothing to display.</p>\n"; return; } // print_r($orderfields); // echo("<hr>\n"); // print_r($rows[0]); ?> <div style="padding:3px;"> <table border="1" class="table table-hover table-condensed table-responsive"> <tr> <?php $first = true; $thispage = basename($_SERVER['PHP_SELF']); if ($view === false) { $view = $thispage; } foreach ($rows as $row) { $count--; if ($count < 0) { break; } if ($first) { echo "\n<tr>\n"; $desc = isset($params['desc']) ? $params['desc'] + 0 : 0; $order_by = isset($params['order_by']) ? $params['order_by'] : ''; foreach ($row as $k => $v) { if (strpos($k, "_") === 0) { continue; } if ($view !== false && strpos($k, "_id") !== false && is_numeric($v)) { continue; } if ($orderfields && !Table::matchColumns($k, $orderfields)) { echo "<th>" . CrudForm::fieldToTitle($k) . "</th>\n"; continue; } $override = array('order_by' => $k, 'desc' => 0, 'page_start' => false); $d = $desc; $color = "normal"; $arrow = ''; if ($k == $order_by || $order_by == '' && $k == 'id') { $d = ($desc + 1) % 2; $override['desc'] = $d; $color = $d == 1 ? 'success' : 'info'; $arrow = $d == 1 ? ' ↑' : ' ↓'; } $stuff = Table::doUrl($params, $override); echo '<th class="' . $color . '">'; echo ' <a href="' . $thispage; if (strlen($stuff) > 0) { echo "?"; echo $stuff; } echo '">'; echo ucwords(str_replace('_', ' ', $k)); echo $arrow; echo "</a></th>\n"; } echo "</tr>\n"; } $first = false; $link_name = false; echo "<tr>\n"; foreach ($row as $k => $v) { if (strpos($k, "_") === 0) { continue; } if ($view !== false && strpos($k, "_id") !== false && is_numeric($v)) { $link_name = $k; $link_val = $v; continue; } echo "<td>"; if ($link_name !== false) { $detail = Table::makeUrl($view, $params, array($link_name => $link_val)); echo '<a href="' . $detail . '">'; if (strlen($v) < 1) { $v = $link_name . ':' . $link_val; } } echo htmlent_utf8($v); if ($link_name !== false) { echo '</a>'; } $link_name = false; $link_val = false; echo "</td>\n"; } if ($link_val !== false) { echo "<td>"; echo htmlent_utf8($link_val); echo "</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; echo "</div>\n"; }