Changed 'spec','insert' handlers API.
[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                    switch($coltype) {
66                     case 'date':
67                           label_cell(sql2date($cell), "align='center'"); break;
68                     case 'dstamp':      // time stamp displayed as date
69                           label_cell(sql2date(substr($cell, 0, 10)), "align='center'"); break;
70                     case 'tstamp':      // time stamp - FIX user format
71                           label_cell(sql2date(substr($cell, 0, 10)).
72                           ' '. substr($cell, 10), "align='center'"); break;
73                     case 'percent':
74                           percent_cell($cell); break;
75                     case 'amount':
76                           amount_cell($cell); break;
77                     case 'qty':
78                           qty_cell($cell); break;
79                     case 'rate':
80                           rate_cell($cell);  break;
81                         case 'insert':  // extra inserted column
82                         case 'spec':    // special formatting function
83                                 $fun = $col['fun']; 
84                             if (method_exists($pager, $fun)) { 
85                                         $cell = $pager->$fun($row, $cell);
86                                 } elseif (function_exists($fun)) {
87                                         $cell = $fun($row, $cell);
88                                 } else
89                                         $cell = '';
90 //                  case 'text':
91                     default:
92                           label_cell($cell);
93                     case 'skip':        // column not displayed
94                   }
95           }
96             end_row();
97         }
98         //end of while loop
99         end_table();
100         start_table("$table_style align='center' class='navibar' width=95%");
101         start_row();
102          if($pager->rec_count) {
103                 $from = ($pager->curr_page-1)*$pager->page_len+1;
104                 $to = $from + $pager->page_len - 1;
105                 if ($to > $pager->rec_count)
106                   $to = $pager->rec_count;
107                 $all = $pager->rec_count;
108                 label_cell(sprintf( _('Records %d-%d of %d'), $from, $to, $all),
109                         "style='border:none'");
110                 echo "<td style='border:none'>";
111                 $but_pref = $pager->name.'_page_';
112             start_table("align='right'");
113                 start_row();
114                 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
115                 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
116                 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
117                 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
118                 end_row(); 
119                 end_table();    
120                 echo "</td>";
121         } else {
122           label_cell( _('No records'));
123         }
124         end_row();
125         end_table();
126
127    if (isset($pager->marker_txt))
128                 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");
129
130   div_end();
131   return true;
132 }
133
134
135 ?>