File indexing completed on 2024-04-06 12:23:16
0001 <?php
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 include('Net/URL.php');
0012
0013
0014 function page_a($url, $page, $text) {
0015 $url_obj = new Net_URL($url);
0016 $url_obj->addQueryString('page', $page);
0017 $newurl = $url_obj->getURL();
0018 return "<a href='$newurl'>$text</a>";
0019 }
0020
0021
0022 function draw_pager($url, $total_pages, $current_page = 1, $new_search = NULL) {
0023 echo "<div class='pager'>";
0024
0025 if ($current_page <=0 || $current_page > $total_pages ) {
0026 $current_page = 1;
0027 }
0028
0029 if ($current_page > 1) {
0030 echo page_a($url, 1, '[Start]'), " \n";
0031 echo page_a($url, ($current_page-1), '[Prev]'), " \n";
0032 }
0033
0034 for ($i = ($current_page-5); $i <= $current_page+5; $i++) {
0035 if ($i < 1) continue;
0036 if ($i > $total_pages) break;
0037
0038 if ($i != $current_page) {
0039 echo page_a($url, $i, $i), " \n";
0040 } else {
0041 echo page_a($url, $i, "<strong>$i</strong>"), " \n";
0042 }
0043 }
0044
0045 if ($current_page < $total_pages) {
0046 echo page_a($url, ($current_page+1), '[Next]'), " \n";
0047 echo page_a($url, $total_pages, '[End]'), " \n";
0048 }
0049
0050 if ($new_search) {
0051 echo "<a href='$new_search'>[New Search]</a>";
0052 }
0053
0054 echo "</div>";
0055 }
0056
0057
0058 function total_pages($total_rows, $rows_per_page) {
0059 if ($total_rows < 1) $total_rows = 1;
0060 return ceil($total_rows/$rows_per_page);
0061 }
0062
0063
0064 function page_to_row($current_page, $rows_per_page) {
0065 $start_row = ($current_page-1) * $rows_per_page +1;
0066 return $start_row;
0067 }
0068
0069
0070 function count_rows(& $conn, $select, $binds) {
0071 $sql = "SELECT COUNT(*) AS num_rows FROM($select)";
0072 $stmt = oci_parse($conn, $sql);
0073 foreach ($binds as $handle => $var) {
0074 oci_bind_by_name($stmt, $handle, $binds[$handle]);
0075 }
0076 oci_define_by_name($stmt, "NUM_ROWS", $num_rows);
0077 oci_execute($stmt);
0078 oci_fetch($stmt);
0079 return $num_rows;
0080 }
0081
0082
0083 function & paged_result(& $conn, $select, $binds, $start_row, $rows_per_page) {
0084 $end_row = $start_row + $rows_per_page -1;
0085
0086 $sql = "SELECT * FROM ( SELECT r.*, ROWNUM AS row_number FROM ( $select ) r WHERE ROWNUM <= :end_row ) WHERE :start_row <= row_number";
0087
0088 $stmt = oci_parse($conn, $sql);
0089 $binds[':start_row'] = $start_row;
0090 $binds[':end_row'] = $end_row;
0091 foreach ($binds as $handle => $var) {
0092 oci_bind_by_name($stmt, $handle, $binds[$handle]);
0093 }
0094
0095 oci_execute($stmt);
0096
0097 oci_set_prefetch($stmt, $rows_per_page);
0098
0099 return $stmt;
0100 }
0101 ?>