2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 //--------------------------------------------------------------------------------------------------
13 function pager_link($link_text, $url, $icon=false)
17 if (user_graphic_links() && $icon)
18 $link_text = set_icon($icon, $link_text);
20 $href = $path_to_root . $url;
21 return "<a href='$href'>" . $link_text . "</a>";
24 function navi_button($name, $value, $enabled=true, $icon = false) {
26 return "<button ". ($enabled ? '':'disabled')
27 ." class=\"navibutton\" type=\"submit\""
28 ." name=\"$name\" id=\"$name\" value=\"$value\">"
29 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/".$icon."'>":'')
30 ."<span>$value</span></button>\n";
33 function navi_button_cell($name, $value, $enabled=true, $align='left') {
34 label_cell(navi_button($name, $value, $enabled), "align='$align'");
36 //-----------------------------------------------------------------------------
38 // Sql paged table view. Call this function inside form.
40 function display_db_pager(&$pager) {
41 global $table_style, $use_popup_windows, $use_date_picker, $path_to_root;
43 $pager->select_records();
45 div_start("_{$pager->name}_span");
48 foreach($pager->columns as $num_col=>$col) {
49 if (isset($col['head'])) {
50 if (!isset($col['ord']))
51 $headers[] = $col['head'];
53 $icon = (($col['ord'] == 'desc') ? 'sort_desc.gif' :
54 ($col['ord'] == 'asc' ? 'sort_asc.gif' : 'sort_none.gif'));
55 $headers[] = navi_button($pager->name.'_sort_'.$num_col,
56 $col['head'], true, $icon);
60 /* show a table of records returned by the sql */
61 start_table("$table_style width=$pager->width");
62 table_header($headers, 'nowrap');
64 if($pager->header_fun) { // if set header handler
65 start_row("class='{$pager->header_class}'");
66 $fun = $pager->header_fun;
67 if (method_exists($pager, $fun)) {
68 $h = $pager->$fun($pager);
69 } elseif (function_exists($fun)) {
73 foreach($h as $c) { // draw header columns
74 $pars = isset($c[1]) ? $c[1] : '';
75 label_cell($c[0], $pars);
80 $cc = 0; //row colour counter
81 foreach($pager->data as $line_no => $row) {
83 $marker = $pager->marker;
84 if ($marker && $marker($row))
85 start_row("class='$pager->marker_class'");
87 alt_table_row_color($cc);
88 foreach ($pager->columns as $k=>$col) {
89 $coltype = $col['type'];
90 $cell = isset($col['name']) ? $row[$col['name']] : '';
92 if (isset($col['fun'])) { // use data input function if defined
94 if (method_exists($pager, $fun)) {
95 $cell = $pager->$fun($row, $cell);
96 } elseif (function_exists($fun)) {
97 $cell = $fun($row, $cell);
102 switch($coltype) { // format column
104 label_cell($cell, "width=40"); break;
106 label_cell(sql2date($cell), "align='center' nowrap"); break;
107 case 'dstamp': // time stamp displayed as date
108 label_cell(sql2date(substr($cell, 0, 10)), "align='center' nowrap"); break;
109 case 'tstamp': // time stamp - FIX user format
110 label_cell(sql2date(substr($cell, 0, 10)).
111 ' '. substr($cell, 10), "align='center'"); break;
113 percent_cell($cell); break;
118 amount_cell($cell, false); break;
123 qty_cell($cell, false, isset($col['dec']) ? $col['dec'] : null); break;
125 label_cell(number_format2($cell, user_exrate_dec()), "align=center"); break;
128 if (isset( $col['align']))
129 label_cell($cell, "align='" . $col['align'] . "'");
132 case 'skip': // column not displayed
139 if($pager->footer_fun) { // if set footer handler
140 start_row("class='{$pager->footer_class}'");
141 $fun = $pager->footer_fun;
142 if (method_exists($pager, $fun)) {
143 $h = $pager->$fun($pager);
144 } elseif (function_exists($fun)) {
148 foreach($h as $c) { // draw footer columns
149 $pars = isset($c[1]) ? $c[1] : '';
150 label_cell($c[0], $pars);
155 start_row("class='navibar'");
156 $colspan = count($pager->columns);
157 if($pager->rec_count) {
158 echo "<td colspan=$colspan class='navibar' style='border:none;padding:3px;'>";
159 echo "<div style='float:right;'>";
160 $but_pref = $pager->name.'_page_';
163 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
164 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
165 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
166 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
170 $from = ($pager->curr_page-1)*$pager->page_len+1;
171 $to = $from + $pager->page_len - 1;
172 if ($to > $pager->rec_count)
173 $to = $pager->rec_count;
174 $all = $pager->rec_count;
175 echo sprintf( _('Records %d-%d of %d'), $from, $to, $all);
178 label_cell( _('No records'), "colspan=$colspan class='navibar'");
184 if (isset($pager->marker_txt))
185 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");