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 pagedHeader($rows, $searchfields = array(), $orderfields = false, $view = false, $params = false, $extra_buttons = 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 = '';" > <?php // Add the sort drop-down if (isset($rows[0])) { $row = $rows[0]; $thispage = basename($_SERVER['PHP_SELF']); if ($view === false) { $view = $thispage; } $desc = isset($params['desc']) ? $params['desc'] + 0 : 0; $order_by = isset($params['order_by']) ? $params['order_by'] : ''; $first = true; 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)) { continue; } if ($first) { ?> <span class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> Sort Order <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <?php $first = false; } $override = array('order_by' => $k, 'desc' => 0, 'page_start' => false); $d = $desc; $note = " ↑"; if ($k == $order_by || $order_by == '' && $k == 'id') { $d = ($desc + 1) % 2; $override['desc'] = $d; $note = " ↓"; } $detail = Table::makeUrl($thispage, $params, $override); echo '<li><a href="' . $detail . '">'; echo ucwords(str_replace('_', ' ', $k)); if ($note) { echo $note; } echo "</a></li>\n"; } if (!$first) { echo "\n</ul></span>\n"; } } if (is_array($extra_buttons)) { foreach ($extra_buttons as $button_text => $button_url) { echo '<a href="' . $button_url . '" class="btn btn-default">' . _m($button_text) . '</a>' . "\n"; } } ?> </form> <?php }