Better color in data picker
[fa-stable.git] / includes / db_pager.inc
index a3eee7967c339dbf23b10e960bb42ef87a43fe82..819b4757f5c7e3381b749f9bc3d7073b8ea187ec 100644 (file)
@@ -1,4 +1,14 @@
 <?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       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/gpl-3.0.html>.
+***********************************************************************/
 //
 //     Controler part of database table pager with column sort.
 //     To display actual html object call display_db_pager($name) inside
@@ -16,6 +26,7 @@ class db_pager {
        var $marker_txt;        
        var $marker_class;
        var $notice_class;
+       var $width;                     // table width (default '95%')
        var $header_fun;        // additional row between title and body
        var $header_class;
        var $footer_fun;
@@ -47,6 +58,8 @@ class db_pager {
        //      $name is base name for pager controls
        function db_pager($sql, $name, $page_len=0) 
        {
+               global $table_style;
+               $this->width = "95%";
                if ($page_len == 0) $page_len = user_query_size();
                $this->name = $name;
                $this->page_len = $page_len;
@@ -250,10 +263,10 @@ class db_pager {
                }
 
                $sql = "$select FROM $from $where";
-               if($group) $sql.= " GROUP BY $group";
+               if ($group) $sql.= " GROUP BY $group";
            $ord = array();
 
-           foreach$this->columns as $col) {
+           foreach ($this->columns as $col) {
                if (isset($col['ord'])) {
                        if ( $col['ord'] != '' && isset($col['name'])) {
                            $ord[] = $col['name'] .' '. $col['ord'];
@@ -281,6 +294,8 @@ class db_pager {
        //
        function _init() 
        {
+               global $go_debug;
+               
            if ($this->ready == false ) {
                        $sql = $this->_sql_gen(true);
                        $result = db_query($sql, 'Error reading record set');
@@ -288,7 +303,20 @@ class db_pager {
                                return false;
                        $row = db_fetch_row($result);
                        $this->rec_count = $row[0];
-                       $this->max_page = ceil($this->rec_count/$this->page_len);
+                       $this->max_page = $this->page_len ?
+                               ceil($this->rec_count/$this->page_len) : 0;
+               
+                       if ($go_debug) { // FIX - need column name parsing, but for now:
+                               // check if field names are set explicite in col def
+                               // for all initially ordered columns
+                           foreach ($this->columns as $col) {
+                               if (isset($col['ord']) && $col['ord'] != '' 
+                                               &&  !isset($col['name'])) {
+                                                       display_warning("Result field names must be set
+                                                               for all intially ordered db_pager columns.");
+                               }
+                               }
+               }
                        $this->set_page(1);
                        $this->ready = true;
            }