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) {
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 if ($pager->row_fun) {
87 if (function_exists($pager->row_fun)) {
88 $fn = $pager->row_fun;
93 $marker = $pager->marker;
94 if ($marker && $marker($row))
95 start_row("class='$pager->marker_class'");
97 alt_table_row_color($cc);
98 foreach ($pager->columns as $k=>$col) {
99 $coltype = $col['type'];
100 $cell = isset($col['name']) ? $row[$col['name']] : '';
102 if (isset($col['fun'])) { // use data input function if defined
104 if (method_exists($pager, $fun)) {
105 $cell = $pager->$fun($row, $cell);
106 } elseif (function_exists($fun)) {
107 $cell = $fun($row, $cell);
111 switch($coltype) { // format column
113 label_cell($cell, "width='40'"); break;
115 label_cell(sql2date($cell), "align='center' nowrap"); break;
116 case 'dstamp': // time stamp displayed as date
117 label_cell(sql2date(substr($cell, 0, 10)), "align='center' nowrap"); break;
118 case 'tstamp': // time stamp - FIX user format
119 label_cell(sql2date(substr($cell, 0, 10)).
120 ' '. substr($cell, 10), "align='center'"); break;
122 percent_cell($cell); break;
127 amount_cell($cell, false); break;
132 qty_cell($cell, false, isset($col['dec']) ? $col['dec'] : null); break;
134 email_cell($cell,isset( $col['align']) ? "align='" . $col['align'] . "'" : null);
137 label_cell(number_format2($cell, user_exrate_dec()), "align=center"); break;
139 if(get_post('show_inactive'))
140 $pager->inactive_control_cell($row); break;
142 if (isset( $col['align']))
143 label_cell($cell, "align='" . $col['align'] . "'");
146 case 'skip': // column not displayed
153 if($pager->footer_fun) { // if set footer handler
154 start_row("class='{$pager->footer_class}'");
155 $fun = $pager->footer_fun;
156 if (method_exists($pager, $fun)) {
157 $h = $pager->$fun($pager);
158 } elseif (function_exists($fun)) {
162 foreach($h as $c) { // draw footer columns
163 $pars = isset($c[1]) ? $c[1] : '';
164 label_cell($c[0], $pars);
169 start_row("class='navibar'");
170 $colspan = count($pager->columns);
171 $inact = @$pager->inactive_ctrl==true
172 ? ' '.checkbox(null, 'show_inactive', null, true). _("Show also Inactive") : '';
173 if($pager->rec_count) {
174 echo "<td colspan=$colspan class='navibar' style='border:none;padding:3px;'>";
175 echo "<div style='float:right;'>";
176 $but_pref = $pager->name.'_page_';
179 if (@$pager->inactive_ctrl)
180 submit('Update', _('Update'), true, '', null); // inactive update
181 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
182 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
183 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
184 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
188 $from = ($pager->curr_page-1)*$pager->page_len+1;
189 $to = $from + $pager->page_len - 1;
190 if ($to > $pager->rec_count)
191 $to = $pager->rec_count;
192 $all = $pager->rec_count;
193 echo sprintf( _('Records %d-%d of %d'), $from, $to, $all);
197 label_cell( _('No records') . $inact, "colspan=$colspan class='navibar'");
204 if (isset($pager->marker_txt))
205 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");