Better layout in big forms
[fa-stable.git] / includes / ui / db_pager_view.inc
index ee74aca5fc944c42f27c6ea9a141415da3b15adb..d0c50ad1bc2b6ab047746027778c3da5e8a30a91 100644 (file)
@@ -1,10 +1,22 @@
 <?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU Affero General Public License,
+       AGPL, as published by the Free Software Foundation, either version 
+       3 of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
 //--------------------------------------------------------------------------------------------------
-function pager_link($link_text, $url)
+function pager_link($link_text, $url, $icon=false)
 {
        global $path_to_root;
        
        $link = access_string($link_text);
+       if (user_graphic_links() && $icon)
+               $link[0] = set_icon($icon, $link[0]);
 
        $href = $path_to_root . $url;
        return "<a href='$href'$link[1]>" . $link[0] . "</a>";
@@ -50,6 +62,22 @@ function display_db_pager(&$pager) {
     start_table("$table_style width=95%");
     table_header($headers);
 
+       if($pager->header_fun) {        // if set header handler
+               start_row("class='{$pager->header_class}'");
+               $fun = $pager->header_fun;
+               if (method_exists($pager, $fun)) { 
+                       $h = $pager->$fun($pager);
+               } elseif (function_exists($fun)) {
+                       $h = $fun($pager);
+               }
+               
+               foreach($h as $c) {      // draw header columns
+                       $pars = isset($c[1]) ? $c[1] : '';
+                       label_cell($c[0], $pars);
+               }
+               end_row();
+       }
+
        $cc = 0; //row colour counter
        foreach($pager->data as $line_no => $row) {     
 
@@ -62,9 +90,21 @@ function display_db_pager(&$pager) {
                   $coltype = $col['type'];
                   $cell = isset($col['name']) ? $row[$col['name']] : '';
 
-                  switch($coltype) {
+                  if (isset($col['fun'])) { // use data input function if defined
+                   $fun = $col['fun']; 
+                   if (method_exists($pager, $fun)) { 
+                               $cell = $pager->$fun($row, $cell);
+                       } elseif (function_exists($fun)) {
+                               $cell = $fun($row, $cell);
+                       } else
+                               $cell = '';
+                  }
+
+                  switch($coltype) { // format column
+                   case 'time':
+                         label_cell($cell, "width=40"); break;
                    case 'date':
-                         label_cell(sql2date($cell), "align='center'"); break;
+                         label_cell(sql2date($cell), "align='center' width=50"); break;
                    case 'dstamp':      // time stamp displayed as date
                          label_cell(sql2date(substr($cell, 0, 10)), "align='center'"); break;
                    case 'tstamp':      // time stamp - FIX user format
@@ -73,29 +113,46 @@ function display_db_pager(&$pager) {
                    case 'percent':
                          percent_cell($cell); break;
                    case 'amount':
-                         amount_cell($cell); break;
+                         if ($cell=='')
+                               label_cell('');
+                         else
+                               amount_cell($cell, false); break;
                    case 'qty':
-                         qty_cell($cell); break;
+                         if ($cell=='')
+                               label_cell('');
+                         else
+                               qty_cell($cell, false, isset($col['dec']) ? $col['dec'] : null); break;
                    case 'rate':
                          rate_cell($cell);  break;
-                       case 'insert':  // extra inserted column
-                       case 'spec':    // special formatting function
-                               $fun = $col['fun']; 
-                           if (method_exists($pager, $fun)) { 
-                                       $cell = $pager->$fun($row, $cell);
-                               } elseif (function_exists($fun)) {
-                                       $cell = $fun($row, $cell);
-                               } else
-                                       $cell = '';
-//                 case 'text':
                    default:
-                         label_cell($cell);
+//                 case 'text':
+                         if (isset( $col['align']))
+                                 label_cell($cell, "align='" . $col['align'] . "'");
+                         else
+                                 label_cell($cell);
                    case 'skip':        // column not displayed
                  }
          }
            end_row();
        }
        //end of while loop
+
+       if($pager->footer_fun) {        // if set footer handler
+               start_row("class='{$pager->footer_class}'");
+               $fun = $pager->footer_fun;
+               if (method_exists($pager, $fun)) { 
+                       $h = $pager->$fun($pager);
+               } elseif (function_exists($fun)) {
+                       $h = $fun($pager);
+               }
+               
+               foreach($h as $c) {      // draw footer columns
+                       $pars = isset($c[1]) ? $c[1] : '';
+                       label_cell($c[0], $pars);
+               }
+               end_row();
+       }
+
        end_table();
        start_table("$table_style align='center' class='navibar' width=95%");
        start_row();