2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 //--------------------------------------------------------------------------------------------------
13 function pager_link($link_text, $url, $icon=false)
17 $link = access_string($link_text);
18 if (user_graphic_links() && $icon)
19 $link[0] = set_icon($icon, $link[0]);
21 $href = $path_to_root . $url;
22 return "<a href='$href'$link[1]>" . $link[0] . "</a>";
25 function navi_button($name, $value, $enabled=true, $icon = false) {
27 return "<button ". ($enabled ? '':'disabled')
28 ." class=\"navibutton\" type=\"submit\""
29 ." name=\"$name\" id=\"$name\" value=\"$value\">"
30 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/".$icon."'>":'')
31 ."<span>$value</span></button>\n";
34 function navi_button_cell($name, $value, $enabled=true, $align='left') {
35 label_cell(navi_button($name, $value, $enabled), "align='$align'");
37 //-----------------------------------------------------------------------------
39 // Sql paged table view. Call this function inside form.
41 function display_db_pager(&$pager) {
42 global $table_style, $use_popup_windows, $use_date_picker, $path_to_root;
44 $pager->select_records();
46 div_start("_{$pager->name}_span");
48 //display_error(print_r($pager->columns,true));
49 foreach($pager->columns as $num_col=>$col) {
50 if (isset($col['head'])) {
51 if (!isset($col['ord']))
52 $headers[] = $col['head'];
54 $icon = (($col['ord'] == 'desc') ? 'sort_desc.gif' :
55 ($col['ord'] == 'asc' ? 'sort_asc.gif' : 'sort_none.gif'));
56 $headers[] = navi_button($pager->name.'_sort_'.$num_col,
57 $col['head'], true, $icon);
61 /* show a table of records returned by the sql */
62 start_table("$table_style width=95%");
63 table_header($headers);
65 if($pager->header_fun) { // if set header handler
66 start_row("class='{$pager->header_class}'");
67 $fun = $pager->header_fun;
68 if (method_exists($pager, $fun)) {
69 $h = $pager->$fun($pager);
70 } elseif (function_exists($fun)) {
74 foreach($h as $c) { // draw header columns
75 $pars = isset($c[1]) ? $c[1] : '';
76 label_cell($c[0], $pars);
81 $cc = 0; //row colour counter
82 foreach($pager->data as $line_no => $row) {
84 $marker = $pager->marker;
85 if ($marker && $marker($row))
86 start_row("class='$pager->marker_class'");
88 alt_table_row_color($cc);
89 foreach ($pager->columns as $k=>$col) {
90 $coltype = $col['type'];
91 $cell = isset($col['name']) ? $row[$col['name']] : '';
93 if (isset($col['fun'])) { // use data input function if defined
95 if (method_exists($pager, $fun)) {
96 $cell = $pager->$fun($row, $cell);
97 } elseif (function_exists($fun)) {
98 $cell = $fun($row, $cell);
103 switch($coltype) { // format column
105 label_cell($cell, "width=40"); break;
107 label_cell(sql2date($cell), "align='center' width=50"); break;
108 case 'dstamp': // time stamp displayed as date
109 label_cell(sql2date(substr($cell, 0, 10)), "align='center'"); break;
110 case 'tstamp': // time stamp - FIX user format
111 label_cell(sql2date(substr($cell, 0, 10)).
112 ' '. substr($cell, 10), "align='center'"); break;
114 percent_cell($cell); break;
119 amount_cell($cell, false); break;
124 qty_cell($cell, false, isset($col['dec']) ? $col['dec'] : null); break;
126 rate_cell($cell); break;
129 if (isset( $col['align']))
130 label_cell($cell, "align='" . $col['align'] . "'");
133 case 'skip': // column not displayed
140 if($pager->footer_fun) { // if set footer handler
141 start_row("class='{$pager->footer_class}'");
142 $fun = $pager->footer_fun;
143 if (method_exists($pager, $fun)) {
144 $h = $pager->$fun($pager);
145 } elseif (function_exists($fun)) {
149 foreach($h as $c) { // draw footer columns
150 $pars = isset($c[1]) ? $c[1] : '';
151 label_cell($c[0], $pars);
157 start_table("$table_style align='center' class='navibar' width=95%");
159 if($pager->rec_count) {
160 $from = ($pager->curr_page-1)*$pager->page_len+1;
161 $to = $from + $pager->page_len - 1;
162 if ($to > $pager->rec_count)
163 $to = $pager->rec_count;
164 $all = $pager->rec_count;
165 label_cell(sprintf( _('Records %d-%d of %d'), $from, $to, $all),
166 "style='border:none'");
167 echo "<td style='border:none'>";
168 $but_pref = $pager->name.'_page_';
169 start_table("align='right'");
171 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
172 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
173 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
174 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
179 label_cell( _('No records'));
184 if (isset($pager->marker_txt))
185 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");