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'");
38 //-----------------------------------------------------------------------------
40 // Sql paged table view. Call this function inside form.
42 function display_db_pager(&$pager) {
43 global $use_popup_windows, $use_date_picker, $path_to_root;
45 $pager->select_records();
47 div_start("_{$pager->name}_span");
50 foreach($pager->columns as $num_col=>$col) {
51 // record status control column is displayed only when control checkbox is on
52 if (isset($col['head']) && ($col['type']!='inactive' || get_post('show_inactive'))) {
53 if (!isset($col['ord']))
54 $headers[] = $col['head'];
56 $icon = (($col['ord'] == 'desc') ? 'sort_desc.gif' :
57 ($col['ord'] == 'asc' ? 'sort_asc.gif' : 'sort_none.gif'));
58 $headers[] = navi_button($pager->name.'_sort_'.$num_col,
59 $col['head'], true, $icon);
63 /* show a table of records returned by the sql */
64 start_table(TABLESTYLE, "width='$pager->width'");
65 table_header($headers);
67 if($pager->header_fun) { // if set header handler
68 start_row("class='{$pager->header_class}'");
69 $fun = $pager->header_fun;
70 if (method_exists($pager, $fun)) {
71 $h = $pager->$fun($pager);
72 } elseif (function_exists($fun)) {
76 foreach($h as $c) { // draw header columns
77 $pars = isset($c[1]) ? $c[1] : '';
78 label_cell($c[0], $pars);
83 $cc = 0; //row colour counter
84 foreach($pager->data as $line_no => $row) {
86 $marker = $pager->marker;
87 if ($marker && $marker($row))
88 start_row("class='$pager->marker_class'");
90 alt_table_row_color($cc);
91 foreach ($pager->columns as $k=>$col) {
92 $coltype = $col['type'];
93 $cell = isset($col['name']) ? $row[$col['name']] : '';
95 if (isset($col['fun'])) { // use data input function if defined
97 if (method_exists($pager, $fun)) {
98 $cell = $pager->$fun($row, $cell);
99 } elseif (function_exists($fun)) {
100 $cell = $fun($row, $cell);
104 switch($coltype) { // format column
106 label_cell($cell, "width='40'"); break;
108 label_cell(sql2date($cell), "align='center' nowrap"); break;
109 case 'dstamp': // time stamp displayed as date
110 label_cell(sql2date(substr($cell, 0, 10)), "align='center' nowrap"); break;
111 case 'tstamp': // time stamp - FIX user format
112 label_cell(sql2date(substr($cell, 0, 10)).
113 ' '. substr($cell, 10), "align='center'"); break;
115 percent_cell($cell); break;
120 amount_cell($cell, false); break;
125 qty_cell($cell, false, isset($col['dec']) ? $col['dec'] : null); break;
127 email_cell($cell,isset( $col['align']) ? "align='" . $col['align'] . "'" : null);
130 label_cell(number_format2($cell, user_exrate_dec()), "align=center"); break;
132 if(get_post('show_inactive'))
133 $pager->inactive_control_cell($row); break;
136 if (isset( $col['align']))
137 label_cell($cell, "align='" . $col['align'] . "'");
140 case 'skip': // column not displayed
147 if($pager->footer_fun) { // if set footer handler
148 start_row("class='{$pager->footer_class}'");
149 $fun = $pager->footer_fun;
150 if (method_exists($pager, $fun)) {
151 $h = $pager->$fun($pager);
152 } elseif (function_exists($fun)) {
156 foreach($h as $c) { // draw footer columns
157 $pars = isset($c[1]) ? $c[1] : '';
158 label_cell($c[0], $pars);
163 start_row("class='navibar'");
164 $colspan = count($pager->columns);
165 $inact = @$pager->inactive_ctrl==true
166 ? ' '.checkbox(null, 'show_inactive', null, true). _("Show also Inactive") : '';
167 if($pager->rec_count) {
168 echo "<td colspan=$colspan class='navibar' style='border:none;padding:3px;'>";
169 echo "<div style='float:right;'>";
170 $but_pref = $pager->name.'_page_';
173 if (@$pager->inactive_ctrl)
174 submit('Update', _('Update'), true, '', null); // inactive update
175 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
176 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
177 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
178 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
182 $from = ($pager->curr_page-1)*$pager->page_len+1;
183 $to = $from + $pager->page_len - 1;
184 if ($to > $pager->rec_count)
185 $to = $pager->rec_count;
186 $all = $pager->rec_count;
187 echo sprintf( _('Records %d-%d of %d'), $from, $to, $all);
191 label_cell( _('No records') . $inact, "colspan=$colspan class='navibar'");
198 if (isset($pager->marker_txt))
199 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");