0003871: [Fixed Assets] new patch fix for: 0003866, 0003869
[fa-stable.git] / includes / ui / db_pager_view.inc
1 <?php
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)
14 {
15         global $path_to_root;
16         
17         if (user_graphic_links() && $icon)
18                 $link_text = set_icon($icon, $link_text);
19
20         $href = $path_to_root . $url;
21         return "<a href='$href'>" . $link_text . "</a>";
22 }
23
24 function navi_button($name, $value, $enabled=true, $icon = false) {
25         global $path_to_root;
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";
31 }
32
33 function navi_button_cell($name, $value, $enabled=true, $align='left') {
34         label_cell(navi_button($name, $value, $enabled), "align='$align'");
35 }
36
37
38 //-----------------------------------------------------------------------------
39 //
40 //    Sql paged table view. Call this function inside form.
41 //
42 function display_db_pager(&$pager) {
43     global      $path_to_root;
44
45         $pager->select_records();
46
47         div_start("_{$pager->name}_span");
48     $headers = array();
49
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'];
55                         else {
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);
60                         }
61                 }
62         }
63     /* show a table of records returned by the sql */
64     start_table(TABLESTYLE, "width='$pager->width'");
65     table_header($headers);
66
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)) {
73                         $h = $fun($pager);
74                 }
75                 
76                 foreach($h as $c) {      // draw header columns
77                         $pars = isset($c[1]) ? $c[1] : '';
78                         label_cell($c[0], $pars);
79                 }
80                 end_row();
81         }
82
83         $cc = 0; //row colour counter
84         foreach($pager->data as $line_no => $row) {     
85
86         if ($pager->row_fun) {
87             if (function_exists($pager->row_fun)) {
88                 $fn = $pager->row_fun;
89                 $row = $fn($row);
90             }
91         }
92
93                 $marker = $pager->marker;
94             if ($marker && $marker($row)) 
95                 start_row("class='$pager->marker_class'");
96             else        
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']] : '';
101
102                    if (isset($col['fun'])) { // use data input function if defined
103                     $fun = $col['fun']; 
104                     if (method_exists($pager, $fun)) { 
105                                 $cell = $pager->$fun($row, $cell);
106                         } elseif (function_exists($fun)) {
107                                 $cell = $fun($row, $cell);
108                         } else
109                                 $cell = '';
110                    }
111                    switch($coltype) { // format column
112                     case 'time':
113                           label_cell($cell, "width='40'"); break;
114                     case 'date':
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;
121                     case 'percent':
122                           percent_cell($cell); break;
123                     case 'amount':
124                           if ($cell=='')
125                                 label_cell('');
126                           else
127                                 amount_cell($cell, false); break;
128                     case 'qty':
129                           if ($cell=='')
130                                 label_cell('');
131                           else
132                                 qty_cell($cell, false, isset($col['dec']) ? $col['dec'] : null); break;
133                         case 'email':
134                                 email_cell($cell,isset( $col['align']) ? "align='" . $col['align'] . "'" : null);
135                                 break;
136                     case 'rate':
137                                 label_cell(number_format2($cell, user_exrate_dec()), "align=center"); break;
138                         case 'inactive':
139                                 if(get_post('show_inactive'))
140                                         $pager->inactive_control_cell($row); break;
141                     default:
142                           if (isset( $col['align']))
143                                   label_cell($cell, "align='" . $col['align'] . "'");
144                           else
145                                   label_cell($cell);
146                     case 'skip':        // column not displayed
147                   }
148           }
149             end_row();
150         }
151         //end of while loop
152
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)) {
159                         $h = $fun($pager);
160                 }
161                 
162                 foreach($h as $c) {      // draw footer columns
163                         $pars = isset($c[1]) ? $c[1] : '';
164                         label_cell($c[0], $pars);
165                 }
166                 end_row();
167         }
168
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_';
177             start_table();
178                 start_row();
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');
185                 end_row(); 
186                 end_table();
187                 echo "</div>";
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);
194                 echo $inact;
195                 echo "</td>";
196         } else {
197                 label_cell( _('No records') . $inact, "colspan=$colspan class='navibar'");
198         }
199
200         end_row();
201
202         end_table();
203
204    if (isset($pager->marker_txt))
205                 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");
206
207   div_end();
208   return true;
209 }
210
211