a30487f90be2711432be7ce846660dff89d32658
[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                                 $param = $coltype=='spec' ? $cell : $row;
85                             if (method_exists($pager, $fun)) { 
86                                         $cell = $pager->$fun($param);
87                                 } elseif (function_exists($fun)) {
88                                         $cell = $fun($param);
89                                 } else
90                                         $cell = '';
91 //                  case 'text':
92                     default:
93                           label_cell($cell);
94                     case 'skip':        // column not displayed
95                   }
96           }
97             end_row();
98         }
99         //end of while loop
100         end_table();
101         start_table("$table_style align='center' class='navibar' width=95%");
102         start_row();
103          if($pager->rec_count) {
104                 $from = ($pager->curr_page-1)*$pager->page_len+1;
105                 $to = $from + $pager->page_len - 1;
106                 if ($to > $pager->rec_count)
107                   $to = $pager->rec_count;
108                 $all = $pager->rec_count;
109                 label_cell(sprintf( _('Records %d-%d of %d'), $from, $to, $all),
110                         "style='border:none'");
111                 echo "<td style='border:none'>";
112                 $but_pref = $pager->name.'_page_';
113             start_table("align='right'");
114                 start_row();
115                 echo navi_button_cell($but_pref.'first', _('First'), $pager->first_page, 'right');
116                 echo navi_button_cell($but_pref.'prev', _('Prev'), $pager->prev_page,'right');
117                 echo navi_button_cell($but_pref.'next', _('Next'), $pager->next_page,'right');
118                 echo navi_button_cell($but_pref.'last', _('Last'), $pager->last_page, 'right');
119                 end_row(); 
120                 end_table();    
121                 echo "</td>";
122         } else {
123           label_cell( _('No records'));
124         }
125         end_row();
126         end_table();
127
128    if (isset($pager->marker_txt))
129                 display_note($pager->marker_txt, 0, 1, "class='$pager->notice_class'");
130
131   div_end();
132   return true;
133 }
134
135
136 ?>