Changeset 3816

Show
Ignore:
Timestamp:
02/25/07 23:13:41 (3 years ago)
Author:
gregmac
Message:

Add hideTitles flag to setTitles(), allow title order to control field order

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/quickform/amp_conf/htdocs/admin/common/table.class.php

    r3634 r3816  
    1212         */ 
    1313        var $_titles = false; 
     14        /** If fields without a title should be hidden 
     15         */ 
     16        var $_hideNonTitled = false; 
    1417         
    1518        var $_currentUrl; 
     
    5053         */ 
    5154        function table($dbresult) { 
    52                 $this->_data = $dbresult; 
     55                if (is_array($dbresult)) { 
     56                        $this->_data = $dbresult; 
     57                } else { 
     58                        $this->_data = array(); 
     59                } 
    5360                 
    5461                $this->_edit_url = 'config.php?type='.$_REQUEST['type'].'&display='.$_REQUEST['display'].'&method=edit&id='; 
     
    6067         * @param  array   The assoc array containing field=>title 
    6168         */ 
    62         function setTitles($fields) { 
     69        function setTitles($fields, $hideOthers = false) { 
     70                $this->_hideNonTitled = $hideOthers; 
    6371                if (is_array($fields)) { 
    6472                        $this->_titles = $fields; 
     
    8896         
    8997        /** Automatically generate titles 
     98         * Fills in any missing titles 
    9099         */ 
    91100        function _genTitles() { 
    92                 if (isset($this->_data[0]) && is_array($this->_data[0])) { 
    93                         foreach (array_keys($this->_data[0]) as $key) { 
    94                                 // convert a db fieldname into a title 
    95                                 $title = str_replace(array('_','-'), ' ', $key); 
    96                                 $title = ucwords($title); 
    97                                 $this->_titles[$key] = $title; 
     101                if ($this->_titles == false && !$this->_hideNonTitled) { 
     102                        // setTitles() was called, and we're not hiding titles 
     103                        if (isset($this->_data[0]) && is_array($this->_data[0])) { 
     104                                // we have valid data to use  
     105                                foreach (array_keys($this->_data[0]) as $key) { 
     106                                        if (!isset($this->_titles[$key])) { 
     107                                                // this field isn't already set  
     108                                                 
     109                                                // convert a db fieldname into a title 
     110                                                $title = str_replace(array('_','-'), ' ', $key); 
     111                                                $title = ucwords($title); 
     112                                                $this->_titles[$key] = $title; 
     113                                        } 
     114                                } 
    98115                        } 
    99116                } 
     
    118135         */ 
    119136        function toHtml() { 
    120                 if ($this->_titles === false) { 
    121                         $this->_genTitles(); 
    122                 } 
     137                $this->_genTitles(); 
     138                 
    123139                if ($this->_id_field === false) { 
    124140                        $this->_findIdField(); 
     
    132148                                $output .= "\t<tr class=\"heading\">"; 
    133149                                $output .= '<th>&nbsp;</th>'; // edit links 
    134                                 foreach ($row as $field=>$value) { 
     150                                foreach ($this->_titles as $field=>$title) { 
     151                                        $value = $row[$field]; 
     152                                         
    135153                                        if (!$this->_id_display && ($field == $this->_id_field)) { 
    136154                                                // skip displaying this field 
    137155                                                continue; 
    138156                                        } 
    139                                         $output .= '<th>'.(isset($this->_titles[$field]) ? $this->_titles[$field] : $field).'</th>'; 
     157                                        $output .= '<th>'.$title.'</th>'; 
    140158                                } 
    141159                                 
     
    153171                        $output .= '</td>'; 
    154172                         
    155                         foreach ($row as $field=>$value) { 
     173                        foreach ($this->_titles as $field=>$title) { 
     174                                $value = $row[$field]; 
     175                                 
    156176                                if (!$this->_id_display && ($field == $this->_id_field)) { 
    157177                                        // skip displaying this field 
    158178                                        continue; 
    159179                                } 
     180                                 
    160181                                $output .= '<td>'.(!empty($value) ? $value : '&nbsp;').'</td>'; 
    161182                        }