2 //--------------------------------------------------------------------------------------------------
3 function pager_link($link_text, $url)
7 $link = access_string($link_text);
9 $href = $path_to_root . $url;
10 return "<a href='$href'$link[1]>" . $link[0] . "</a>";
13 function navi_button($name, $value, $enabled=true, $icon = false) {
15 return "<button ". ($enabled ? '':'disabled')
16 ." class=\"navibutton\" type=\"submit\""
17 ." name=\"$name\" id=\"$name\" value=\"$value\">"
18 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/".$icon."'>":'')
19 ."<span>$value</span></button>\n";
22 function navi_button_cell($name, $value, $enabled=true, $align='left') {
23 label_cell(navi_button($name, $value, $enabled), "align='$align'");
25 //-----------------------------------------------------------------------------
27 // Sql paged table view. Call this function inside form.
29 function display_db_pager(&$pager) {
30 global $table_style, $use_popup_windows, $use_date_picker, $path_to_root;
32 $pager->select_records();
34 div_start("_{$pager->name}_span");
36 //display_error(print_r($pager->columns,true));
37 foreach($pager->columns as $num_col=>$col) {
38 if (isset($col['head'])) {
39 if (!isset($col['ord']))
40 $headers[] = $col['head'];
42 $icon = (($col['ord'] == 'desc') ? 'sort_desc.gif' :
43 ($col['ord'] == 'asc' ? 'sort_asc.gif' : 'sort_none.gif'));
44 $headers[] = navi_button($pager->name.'_sort_'.$num_col,
45 $col['head'], true, $icon);
49 /* show a table of records returned by the sql */
50 start_table("$table_style width=95%");
51 table_header($headers);
53 $cc = 0; //row colour counter
54 foreach($pager->data as $line_no => $row) {
56 $marker = $pager->marker;
57 if ($marker && $marker($row))
58 start_row("class='$pager->marker_class'");
60 alt_table_row_color($cc);
61 foreach ($pager->columns as $k=>$col) {
62 $coltype = $col['type'];
63 $cell = isset($col['name']) ? $row[$col['name']] : '';
65 if (isset($col['fun'])) { // use data input function if defined
67 if (method_exists($pager, $fun)) {
68 $cell = $pager->$fun($row, $cell);
69 } elseif (function_exists($fun)) {
70 $cell = $fun($row, $cell);
75 switch($coltype) { // format column
77 label_cell(sql2date($cell), "align='center'"); break;
78 case 'dstamp': // time stamp displayed as date
79 label_cell(sql2date(substr($cell, 0, 10)), "align='center'"); break;
80 case 'tstamp': // time stamp - FIX user format
81 label_cell(sql2date(substr($cell, 0, 10)).
82 ' '. substr($cell, 10), "align='center'"); break;
84 percent_cell($cell); break;
86 amount_cell($cell, false); break;
88 qty_cell($cell); break;
90 rate_cell($cell); break;
93 if (isset( $col['align']))
94 label_cell($cell, "align='" . $col['align'] . "'");
97 case 'skip': // column not displayed
104 start_table("$table_style align='center' class='navibar' width=95%");
106 if($pager->rec_count) {
107 $from = ($pager->curr_page-1)*$pager->page_len+1;
108 $to = $from + $pager->page_len - 1;
109 if ($to > $pager->rec_count)
110 $to = $pager->rec_count;
111 $all = $pager->rec_count;
112 label_cell(sprintf( _('Records %d-%d of %d'), $from, $to, $all),
113 "style='border:none'");
114 echo "<td style='border:none'>";
115 $but_pref = $pager->name.'_page_';
116 start_table("align='right'");
118 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
119 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
120 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
121 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
126 label_cell( _('No records'));
131 if (isset($pager->marker_txt))
132 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");