Chenaged api for inserted columns
[fa-stable.git] / includes / ui / db_pager_view.inc
1 <?php
2 //--------------------------------------------------------------------------------------------------
3 function pager_link($link_text, $url)
4 {
5         global $path_to_root;
6         
7         $link = access_string($link_text);
8
9         $href = $path_to_root . $url;
10         return "<a href='$href'$link[1]>" . $link[0] . "</a>";
11 }
12
13 function navi_button($name, $value, $enabled=true, $icon = false) {
14         global $path_to_root;
15         return "<button ". ($enabled ? '':'disabled')
16                 ." class=\"navibutton\" type=\"submit\""
17             ." name=\"$name\"  id=\"$name\" value=\"$value\">"
18                 .($icon ? "<img src='$path_to_root/themes/".user_theme()."/images/".$icon."'>":'')
19                 ."<span>$value</span></button>\n";
20 }
21
22 function navi_button_cell($name, $value, $enabled=true, $align='left') {
23         label_cell(navi_button($name, $value, $enabled), "align='$align'");
24 }
25 //-----------------------------------------------------------------------------
26 //
27 //    Sql paged table view. Call this function inside form.
28 //
29 function display_db_pager(&$pager) {
30     global      $table_style, $use_popup_windows, $use_date_picker, $path_to_root;
31
32         $pager->select_records();
33
34         div_start("_{$pager->name}_span");
35     $headers = array();
36 //display_error(print_r($pager->columns,true));
37         foreach($pager->columns as $num_col=>$col) {
38         if (isset($col['head'])) {
39                         if (!isset($col['ord'])) 
40                                 $headers[] = $col['head'];
41                         else {
42                                 $icon = (($col['ord'] == 'desc') ? 'sort_desc.gif' : 
43                                         ($col['ord'] == 'asc' ? 'sort_asc.gif' : 'sort_none.gif'));
44                                 $headers[] = navi_button($pager->name.'_sort_'.$num_col, 
45                                         $col['head'], true, $icon);
46                         }
47                 }
48         }
49     /* show a table of records returned by the sql */
50     start_table("$table_style width=95%");
51     table_header($headers);
52
53         $cc = 0; //row colour counter
54         foreach($pager->data as $line_no => $row) {     
55
56                 $marker = $pager->marker;
57             if ($marker && $marker($row)) 
58                 start_row("class='$pager->marker_class'");
59             else        
60                         alt_table_row_color($cc);
61             foreach ($pager->columns as $k=>$col) {
62                    $coltype = $col['type'];
63                    $cell = isset($col['name']) ? $row[$col['name']] : '';
64
65                    if (isset($col['fun'])) { // use data input function if defined
66                     $fun = $col['fun']; 
67                     if (method_exists($pager, $fun)) { 
68                                 $cell = $pager->$fun($row, $cell);
69                         } elseif (function_exists($fun)) {
70                                 $cell = $fun($row, $cell);
71                         } else
72                                 $cell = '';
73                    }
74
75                    switch($coltype) { // format column
76                     case 'date':
77                           label_cell(sql2date($cell), "align='center'"); break;
78                     case 'dstamp':      // time stamp displayed as date
79                           label_cell(sql2date(substr($cell, 0, 10)), "align='center'"); break;
80                     case 'tstamp':      // time stamp - FIX user format
81                           label_cell(sql2date(substr($cell, 0, 10)).
82                           ' '. substr($cell, 10), "align='center'"); break;
83                     case 'percent':
84                           percent_cell($cell); break;
85                     case 'amount':
86                           amount_cell($cell, false); break;
87                     case 'qty':
88                           qty_cell($cell); break;
89                     case 'rate':
90                           rate_cell($cell);  break;
91                     default:
92 //                  case 'text':
93                           if (isset( $col['align']))
94                                   label_cell($cell, "align='" . $col['align'] . "'");
95                           else
96                                   label_cell($cell);
97                     case 'skip':        // column not displayed
98                   }
99           }
100             end_row();
101         }
102         //end of while loop
103         end_table();
104         start_table("$table_style align='center' class='navibar' width=95%");
105         start_row();
106          if($pager->rec_count) {
107                 $from = ($pager->curr_page-1)*$pager->page_len+1;
108                 $to = $from + $pager->page_len - 1;
109                 if ($to > $pager->rec_count)
110                   $to = $pager->rec_count;
111                 $all = $pager->rec_count;
112                 label_cell(sprintf( _('Records %d-%d of %d'), $from, $to, $all),
113                         "style='border:none'");
114                 echo "<td style='border:none'>";
115                 $but_pref = $pager->name.'_page_';
116             start_table("align='right'");
117                 start_row();
118                 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
119                 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
120                 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
121                 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
122                 end_row(); 
123                 end_table();    
124                 echo "</td>";
125         } else {
126           label_cell( _('No records'));
127         }
128         end_row();
129         end_table();
130
131    if (isset($pager->marker_txt))
132                 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");
133
134   div_end();
135   return true;
136 }
137
138
139 ?>