public static function pagedTable($rows, $searchfields = array(), $orderfields = false, $view = false, $params = false) { if ($params === false) { $params = $_GET; } if ($orderfields === false) { $orderfields = $searchfields; } $page_start = isset($params['page_start']) ? $params['page_start'] + 0 : 0; if ($page_start < 0) { $page_start = 0; } $page_length = isset($params['page_length']) ? $params['page_length'] + 0 : self::$DEFAULT_PAGE_LENGTH; if ($page_length < 0) { $page_length = 0; } $search = ''; if (isset($params['search_text'])) { $search = $params['search_text']; } $count = count($rows); $have_more = false; if ($count > $page_length) { $have_more = true; $count = $page_length; } echo '<div style="float:right">'; if ($page_start > 0) { echo '<form style="display: inline">'; echo '<input type="submit" value="Back" class="btn btn-default">'; $page_back = $page_start - $page_length; if ($page_back < 0) { $page_back = 0; } Table::doForm($params, array('page_start' => $page_back)); echo "</form>\n"; } if ($have_more) { echo '<form style="display: inline">'; echo '<input type="submit" value="Next" class="btn btn-default"> '; $page_next = $page_start + $page_length; Table::doForm($params, array('page_start' => $page_next)); echo "</form>\n"; } echo "</div>\n"; echo '<form>'; echo '<input type="text" id="paged_search_box" value="' . htmlent_utf8($search) . '" name="search_text">'; Table::doForm($params, array('search_text' => false, 'page_start' => false)); ?> <input type="submit" value="Search" class="btn btn-default"> <input type="submit" value="Clear Search" class="btn btn-default" onclick="document.getElementById('paged_search_box').value = '';" > </form> <?php 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 (!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 = "black"; if ($k == $order_by || $order_by == '' && $k == 'id') { $d = ($desc + 1) % 2; $override['desc'] = $d; $color = $d == 1 ? 'green' : 'red'; } $stuff = Table::doUrl($params, $override); echo '<th>'; echo ' <a href="' . $thispage; if (strlen($stuff) > 0) { echo "?"; echo $stuff; } echo '" style="color: ' . $color . '">'; echo ucwords(str_replace('_', ' ', $k)); 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) { echo '<a href="' . $view . '?' . $link_name . "=" . $link_val . '">'; if (strlen($v) < 1) { $v = $link_name . ':' . $link_val; } } echo htmlent_utf8($v); if ($link_name !== false) { echo '</a>'; } $link_name = false; echo "</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; echo "</div>\n"; }
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"; }