![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: customfieldsparser.class.php 38 2008-02-11 11:38:51Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/classes/customfieldsparser.class.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 class CustomFieldsParser { 7 var $fields_array = array(); 8 var $custom_record_type; 9 var $previous_data = array(); 10 var $row_id = 0; 11 var $custom_record_types = array(); 12 13 var $table_name = 'tasks'; 14 var $field_name = 'task_custom'; 15 var $id_field_name = 'task_id'; 16 17 /** 18 * @return CustomFieldsParser 19 * @param char Field type: TaskCustomFields, CompanyCustomFields 20 * @desc Constructor 21 */ 22 function CustomFieldsParser($custom_record_type, $row_id = 0) { 23 $this->custom_record_type = $custom_record_type; 24 25 $this->_fetchFields(); 26 $this->_fetchCustomRecordTypes(); 27 28 switch ($this->custom_record_type) { 29 case 'TaskCustomFields': 30 $this->table_name = 'tasks'; 31 $this->field_name = 'task_custom'; 32 $this->id_field_name = 'task_id'; 33 break; 34 case 'CompanyCustomFields': 35 $this->table_name = 'companies'; 36 $this->field_name = 'company_custom'; 37 $this->id_field_name = 'company_id'; 38 break; 39 default: 40 $AppUI->setMsg('Invalid custom field record type: ' . $custom_record_type); 41 break; 42 } 43 44 $this->row_id = $row_id; 45 if ($this->row_id != 0) { 46 $this->_fetchPreviousData(); 47 } 48 } 49 50 function _fetchFields() { 51 $this->fields_array = w2PgetSysVal($this->custom_record_type); 52 } 53 54 function _fetchCustomRecordTypes() { 55 switch ($this->custom_record_type) { 56 case 'TaskCustomFields': 57 $field_types = 'TaskType'; 58 break; 59 case 'CompanyCustomFields': 60 $field_types = 'CompanyType'; 61 break; 62 } 63 $this->custom_record_types = w2PgetSysVal($field_types); 64 } 65 66 function _fetchPreviousData() { 67 $q = new DBQuery; 68 $q->addTable($this->table_name); 69 $q->addQuery($this->field_name); 70 $q->addWhere($this->id_field_name . ' = ' . $this->row_id); 71 $previous_data = $q->loadResult(); 72 73 if ($previous_data != '') { 74 $previous_data = unserialize($previous_data); 75 $previous_data = !is_array($previous_data) ? array() : $previous_data; 76 } else { 77 $previous_data = array(); 78 } 79 $this->previous_data = $previous_data; 80 } 81 82 function _getLabelHTML($field_config) { 83 if ($field_config['type'] == 'label') { 84 $separador = ''; 85 $colspan = 'colspan="2"'; 86 $field_config['name'] = '<b>' . $field_config['name'] . '</b>'; 87 } else { 88 $separador = ':'; 89 $colspan = ''; 90 } 91 92 return '<td ' . $colspan . '>' . $field_config['name'] . ' ' . $separador . '</td>'; 93 } 94 95 function parseEditField($key) { 96 $field_config = unserialize($this->fields_array[$key]); 97 $parsed = '<tr id="custom_tr_' . $key . '">'; 98 99 $parsed .= $this->_getLabelHTML($field_config); 100 switch ($field_config['type']) { 101 case 'text': 102 $parsed .= '<td align="left"><input type="text" name="custom_' . $key .'" class="text" ' . $field_config['options'] . ' value="' . (isset($this->previous_data[$key]) ? $this->previous_data[$key] : '') . '" /></td>'; 103 break; 104 case 'href': 105 $parsed .= '<td align="left"><input type="text" name="custom_' . $key . '" class="text" ' . $field_config['options'] . ' value="' . (isset($this->previous_data[$key]) ? $this->previous_data[$key] : '') . '" /></td>'; 106 break; 107 case 'select': 108 $parsed .= '<td align="left">' . arraySelect(explode(',', $field_config['selects']), 'custom_' . $key, 'size="1" class="text" ' . $field_config['options'], (isset($this->previous_data[$key]) ? $this->previous_data[$key] : '')) . '</td>'; 109 break; 110 case 'textarea': 111 $parsed .= '<td align="left"><textarea name="custom_' . $key . '" class="textarea" ' . $field_config['options'] . '>' . (isset($this->previous_data[$key]) ? $this->previous_data[$key] : '') . '</textarea></td>'; 112 break; 113 case 'checkbox': 114 $options_array = explode(',', $field_config['selects']); 115 $parsed .= '<td align="left">'; 116 foreach ($options_array as $option) { 117 $checked = ''; 118 if (isset($this->previous_data[$key]) && array_key_exists($option, array_flip($this->previous_data[$key]))) { 119 $checked = 'checked'; 120 } 121 $parsed .= '<input type="checkbox" value="' . $option . '" name="custom_' . $key . '[]" class="text" style="border:0" ' . $checked . ' ' . $field_config['options'] . ' />' . $option . '<br />'; 122 $checked = ''; 123 } 124 $parsed .= '</td>'; 125 break; 126 } 127 $parsed .= '</tr>'; 128 return $parsed; 129 } 130 131 function parseViewField($key) { 132 $field_config = unserialize($this->fields_array[$key]); 133 $parsed = '<tr id="custom_tr_' . $key . '">'; 134 $parsed .= $this->_getLabelHTML($field_config); 135 switch ($field_config['type']) { 136 case 'text': 137 $parsed .= '<td class="hilite">' . w2PformSafe((isset($this->previous_data[$key]) ? $this->previous_data[$key] : '')) . '</td>'; 138 break; 139 case 'href': 140 $parsed .= '<td class="hilite"><a href="' . w2PformSafe((isset($this->previous_data[$key]) ? $this->previous_data[$key] : '')) . '">' . w2PformSafe((isset($this->previous_data[$key]) ? $this->previous_data[$key] : '')) . '</a></td>'; 141 break; 142 case 'select': 143 $optionarray = explode(',', $field_config['selects']); 144 $parsed .= '<td class="hilite" width="300">' . w2PformSafe((isset($this->previous_data[$key]) ? $optionarray[$this->previous_data[$key]] : '')) . '</td>'; 145 break; 146 case 'textarea': 147 $parsed .= '<td valign="top" class="hilite">' . w2PformSafe((isset($this->previous_data[$key]) ? $this->previous_data[$key] : '')) . '</td>'; 148 break; 149 case 'checkbox': 150 $optionarray = explode(',', $field_config['selects']); 151 $parsed .= '<td align="left">'; 152 foreach ($optionarray as $option) { 153 $checked = ''; 154 if (isset($this->previous_data[$key]) && array_key_exists($option, array_flip($this->previous_data[$key]))) { 155 $checked = 'checked'; 156 } 157 $parsed .= '<input type="checkbox" value="' . $option . '" name="custom_' . $key . '[]" class="text" locked style="border:0" ' . $checked . ' ' . $field_config['options'] . ' disabled />' . $option . '<br />'; 158 } 159 $parsed .= '</td>'; 160 break; 161 } 162 $parsed .= '</tr>'; 163 return $parsed; 164 } 165 166 function parseTableForm($edit = false, $record_type = null) { 167 $parsed = '<table>'; 168 169 $visible_keys = array(); 170 if (!is_null($record_type)) { 171 $visible_keys = $this->_getVisibleKeysForType($record_type); 172 } 173 174 foreach ($this->fields_array as $key => $field) { 175 $field_config = unserialize($field); 176 if ($edit) { 177 $fnc_name = 'parseEditField'; 178 } else { 179 $fnc_name = 'parseViewField'; 180 } 181 182 if (in_array($key, $visible_keys)) { 183 $parsed .= $this->$fnc_name($key); 184 } else 185 if (is_null($record_type)) { 186 $parsed .= $this->$fnc_name($key); 187 } 188 } 189 $parsed .= '</table>'; 190 return $parsed; 191 } 192 193 function _getVisibleKeysForType($record_type) { 194 if (!isset($this->visible_keys)) { 195 $this->visible_keys = array(); 196 } 197 198 if (isset($this->visible_keys[$record_type])) { 199 return $this->visible_keys[$record_type]; 200 } else { 201 $this->visible_keys[$record_type] = array(); 202 } 203 204 foreach ($this->fields_array as $key => $field) { 205 $field_config = unserialize($field); 206 if ($field_config['record_type'] == $record_type || $field_config['record_type'] == '') { 207 $this->visible_keys[$record_type][] = $key; 208 } 209 } 210 return $this->visible_keys[$record_type]; 211 } 212 213 function _parseShowFunction($key) { 214 $parsed = ''; 215 $record_type = $this->custom_record_types[$key]; 216 217 $record_type = str_replace(' ', '_', $record_type); 218 $parsed .= 'function show' . $record_type . "(){\n"; 219 220 foreach ($this->_getVisibleKeysForType($record_type) as $visible_key) { 221 $parsed .= "document.getElementById('custom_tr_$visible_key').style.display='';\n"; 222 } 223 $parsed .= "}\n"; 224 225 return $parsed; 226 } 227 228 function parseShowFunctions() { 229 $parsed = ''; 230 231 foreach ($this->custom_record_types as $key => $record_type) { 232 $parsed .= $this->_parseShowFunction($key); 233 } 234 return $parsed; 235 } 236 237 function showHideAllRowsFunction() { 238 $parsed = "function hideAllRows(){\n"; 239 foreach ($this->fields_array as $key => $field_config) { 240 $field_config = unserialize($field_config); 241 if ($field_config['record_type'] != '') { 242 $parsed .= "document.getElementById('custom_tr_$key').style.display='none';\n"; 243 } 244 } 245 $parsed .= "}\n"; 246 return $parsed; 247 } 248 249 } 250 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Jul 17 03:00:04 2010 | Cross-referenced by PHPXref 0.7 |