includes/functions.php
changeset 359 e0787bb6285b
parent 345 4ccdfeee9a11
child 362 02d315d1cc58
equal deleted inserted replaced
358:b25d34fbc7ab 359:e0787bb6285b
  2077  */
  2077  */
  2078 
  2078 
  2079 function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
  2079 function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
  2080 {
  2080 {
  2081   global $db, $session, $paths, $template, $plugins; // Common objects
  2081   global $db, $session, $paths, $template, $plugins; // Common objects
       
  2082   global $lang;
       
  2083   
  2082   $parser = $template->makeParserText($tpl_text);
  2084   $parser = $template->makeParserText($tpl_text);
  2083   $num_pages = ceil ( $num_results / $perpage );
  2085   $num_pages = ceil ( $num_results / $perpage );
  2084   $out = '';
  2086   $out = '';
  2085   $i = 0;
  2087   $i = 0;
  2086   $this_page = ceil ( $start / $perpage );
  2088   $this_page = ceil ( $start / $perpage );
  2091             'display: block; width: 1px;':
  2093             'display: block; width: 1px;':
  2092             // Other browsers
  2094             // Other browsers
  2093             'display: table; margin: 10px 0 0 auto;';
  2095             'display: table; margin: 10px 0 0 auto;';
  2094   $begin = '<div class="tblholder" style="'. $pg_css . '">
  2096   $begin = '<div class="tblholder" style="'. $pg_css . '">
  2095     <table border="0" cellspacing="1" cellpadding="4">
  2097     <table border="0" cellspacing="1" cellpadding="4">
  2096       <tr><th>Page:</th>';
  2098       <tr><th>' . $lang->get('paginate_lbl_page') . '</th>';
  2097   $block = '<td class="row1" style="text-align: center;">{LINK}</td>';
  2099   $block = '<td class="row1" style="text-align: center;">{LINK}</td>';
  2098   $end = '</tr></table></div>';
  2100   $end = '</tr></table></div>';
  2099   $blk = $template->makeParserText($block);
  2101   $blk = $template->makeParserText($block);
  2100   $inner = '';
  2102   $inner = '';
  2101   $cls = 'row2';
  2103   $cls = 'row2';
  2138       {
  2140       {
  2139         $list[] = $lower + $i;
  2141         $list[] = $lower + $i;
  2140       }
  2142       }
  2141     }
  2143     }
  2142     $url = sprintf($result_url, '0');
  2144     $url = sprintf($result_url, '0');
  2143     $link = ( 0 == $start ) ? "<b>First</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>&laquo; First</a>";
  2145     $link = ( 0 == $start ) ? "<b>" . $lang->get('pagination_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>&laquo; " . $lang->get('pagination_btn_first') . "</a>";
  2144     $blk->assign_vars(array(
  2146     $blk->assign_vars(array(
  2145       'CLASS'=>$cls,
  2147       'CLASS'=>$cls,
  2146       'LINK'=>$link
  2148       'LINK'=>$link
  2147       ));
  2149       ));
  2148     $inner .= $blk->run();
  2150     $inner .= $blk->run();
  2180 
  2182 
  2181       $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2183       $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2182       $offset = strval($total);
  2184       $offset = strval($total);
  2183       $url = sprintf($result_url, $offset);
  2185       $url = sprintf($result_url, $offset);
  2184       $j = $i + 1;
  2186       $j = $i + 1;
  2185       $link = ( $offset == strval($start) ) ? "<b>Last</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Last &raquo;</a>";
  2187       $link = ( $offset == strval($start) ) ? "<b>" . $lang->get('pagination_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('pagination_btn_last') . " &raquo;</a>";
  2186       $blk->assign_vars(array(
  2188       $blk->assign_vars(array(
  2187         'CLASS'=>$cls,
  2189         'CLASS'=>$cls,
  2188         'LINK'=>$link
  2190         'LINK'=>$link
  2189         ));
  2191         ));
  2190       $inner .= $blk->run();
  2192       $inner .= $blk->run();
  2269   $cls = 'row2';
  2271   $cls = 'row2';
  2270   $total = $num_pages * $perpage - $perpage;
  2272   $total = $num_pages * $perpage - $perpage;
  2271   if ( $start > 0 )
  2273   if ( $start > 0 )
  2272   {
  2274   {
  2273     $url = sprintf($result_url, abs($start - $perpage));
  2275     $url = sprintf($result_url, abs($start - $perpage));
  2274     $link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>&laquo; Prev</a>";
  2276     $link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>&laquo; " . $lang->get('paginate_btn_prev') . "</a>";
  2275     $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2277     $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2276     $blk->assign_vars(array(
  2278     $blk->assign_vars(array(
  2277       'CLASS'=>$cls,
  2279       'CLASS'=>$cls,
  2278       'LINK'=>$link
  2280       'LINK'=>$link
  2279       ));
  2281       ));
  2318       {
  2320       {
  2319         $list[] = $lower + $i;
  2321         $list[] = $lower + $i;
  2320       }
  2322       }
  2321     }
  2323     }
  2322     $url = sprintf($result_url, '0');
  2324     $url = sprintf($result_url, '0');
  2323     $link = ( 0 == $start ) ? "<b>First</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>&laquo; First</a>";
  2325     $link = ( 0 == $start ) ? "<b>" . $lang->get('pagination_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>&laquo; " . $lang->get('pagination_btn_first') . "</a>";
  2324     $blk->assign_vars(array(
  2326     $blk->assign_vars(array(
  2325       'CLASS'=>$cls,
  2327       'CLASS'=>$cls,
  2326       'LINK'=>$link
  2328       'LINK'=>$link
  2327       ));
  2329       ));
  2328     $inner .= $blk->run();
  2330     $inner .= $blk->run();
  2358 
  2360 
  2359       $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2361       $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2360       $offset = strval($total);
  2362       $offset = strval($total);
  2361       $url = sprintf($result_url, $offset);
  2363       $url = sprintf($result_url, $offset);
  2362       $j = $i + 1;
  2364       $j = $i + 1;
  2363       $link = ( $offset == strval($start) ) ? "<b>Last</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Last &raquo;</a>";
  2365       $link = ( $offset == strval($start) ) ? "<b>" . $lang->get('pagination_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('pagination_btn_last') . " &raquo;</a>";
  2364       $blk->assign_vars(array(
  2366       $blk->assign_vars(array(
  2365         'CLASS'=>$cls,
  2367         'CLASS'=>$cls,
  2366         'LINK'=>$link
  2368         'LINK'=>$link
  2367         ));
  2369         ));
  2368       $inner .= $blk->run();
  2370       $inner .= $blk->run();
  2372 
  2374 
  2373   if ( $start < $total )
  2375   if ( $start < $total )
  2374   {
  2376   {
  2375     $link_offset = abs($start + $perpage);
  2377     $link_offset = abs($start + $perpage);
  2376     $url = htmlspecialchars(sprintf($result_url, strval($link_offset)));
  2378     $url = htmlspecialchars(sprintf($result_url, strval($link_offset)));
  2377     $link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Next &raquo;</a>";
  2379     $link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_next') . " &raquo;</a>";
  2378     $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2380     $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
  2379     $blk->assign_vars(array(
  2381     $blk->assign_vars(array(
  2380       'CLASS'=>$cls,
  2382       'CLASS'=>$cls,
  2381       'LINK'=>$link
  2383       'LINK'=>$link
  2382       ));
  2384       ));