Changeset 3816
- Timestamp:
- 02/25/07 23:13:41 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
freepbx/branches/quickform/amp_conf/htdocs/admin/common/table.class.php
r3634 r3816 12 12 */ 13 13 var $_titles = false; 14 /** If fields without a title should be hidden 15 */ 16 var $_hideNonTitled = false; 14 17 15 18 var $_currentUrl; … … 50 53 */ 51 54 function table($dbresult) { 52 $this->_data = $dbresult; 55 if (is_array($dbresult)) { 56 $this->_data = $dbresult; 57 } else { 58 $this->_data = array(); 59 } 53 60 54 61 $this->_edit_url = 'config.php?type='.$_REQUEST['type'].'&display='.$_REQUEST['display'].'&method=edit&id='; … … 60 67 * @param array The assoc array containing field=>title 61 68 */ 62 function setTitles($fields) { 69 function setTitles($fields, $hideOthers = false) { 70 $this->_hideNonTitled = $hideOthers; 63 71 if (is_array($fields)) { 64 72 $this->_titles = $fields; … … 88 96 89 97 /** Automatically generate titles 98 * Fills in any missing titles 90 99 */ 91 100 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 } 98 115 } 99 116 } … … 118 135 */ 119 136 function toHtml() { 120 if ($this->_titles === false) { 121 $this->_genTitles(); 122 } 137 $this->_genTitles(); 138 123 139 if ($this->_id_field === false) { 124 140 $this->_findIdField(); … … 132 148 $output .= "\t<tr class=\"heading\">"; 133 149 $output .= '<th> </th>'; // edit links 134 foreach ($row as $field=>$value) { 150 foreach ($this->_titles as $field=>$title) { 151 $value = $row[$field]; 152 135 153 if (!$this->_id_display && ($field == $this->_id_field)) { 136 154 // skip displaying this field 137 155 continue; 138 156 } 139 $output .= '<th>'. (isset($this->_titles[$field]) ? $this->_titles[$field] : $field).'</th>';157 $output .= '<th>'.$title.'</th>'; 140 158 } 141 159 … … 153 171 $output .= '</td>'; 154 172 155 foreach ($row as $field=>$value) { 173 foreach ($this->_titles as $field=>$title) { 174 $value = $row[$field]; 175 156 176 if (!$this->_id_display && ($field == $this->_id_field)) { 157 177 // skip displaying this field 158 178 continue; 159 179 } 180 160 181 $output .= '<td>'.(!empty($value) ? $value : ' ').'</td>'; 161 182 }
