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