Changeset 373 for trunk/Common/ViewForm.php
- Timestamp:
- Jan 19, 2012, 9:43:36 PM (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/ViewForm.php
r372 r373 1 1 <?php 2 2 3 define('ViewItemTypeDate', 'Date'); 4 define('ViewItemTypeTime', 'Time'); 5 define('ViewItemTypeDateTime', 'DateTime'); 6 define('ViewItemTypeText', 'Text'); 7 define('ViewItemTypeString', 'String'); 8 define('ViewItemTypeBoolean', 'Boolean'); 9 define('ViewItemTypeInteger', 'Integer'); 10 define('ViewItemTypeFloat', 'Float'); 11 define('ViewItemTypeOneToMany', 'OneToMany'); 12 define('ViewItemTypeManyToOne', 'ManyToOne'); 13 define('ViewItemTypeManyToMany', 'ManyToMany'); 14 define('ViewItemTypeIPv4', 'IPv4'); 15 define('ViewItemTypeIPv6', 'IPv6'); 16 define('ViewItemTypeMACAddrees', 'MACAddress'); 17 define('ViewItemTypeFileName', 'FileName'); 18 define('ViewItemTypePassword', 'Password'); 19 define('ViewItemTypeURL', 'URL'); 20 define('ViewItemTypeImage', 'Image'); 21 22 class View 3 class ViewForm extends View 23 4 { 24 var $Name;25 var $Title;26 var $Items;27 var $ModelName;28 5 var $SubmitText; 29 6 var $Values = array(); 30 7 var $OnSubmit = ''; 31 var $Database;32 8 33 9 function __construct($Database) … … 38 14 function AddItemOneToMany($Name, $Title, $TargetModel, $Default) 39 15 { 40 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeOneToMany, 'Default' => $Default, 16 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 17 'Type' => ViewItemTypeOneToMany, 'Default' => $Default, 41 18 'TargetModel' => $TargetModel); 42 19 } … … 44 21 function AddItemManyToOne($Name, $Title, $TargetModel, $Default) 45 22 { 46 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeManyToOne, 'Default' => $Default, 23 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 24 'Type' => ViewItemTypeManyToOne, 'Default' => $Default, 47 25 'TargetModel' => $TargetModel); 48 26 } … … 50 28 function AddItemInteger($Name, $Title, $Default) 51 29 { 52 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeInteger, 'Default' => $Default); 30 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 31 'Type' => ViewItemTypeInteger, 'Default' => $Default); 53 32 } 54 33 55 34 function AddItemFloat($Name, $Title, $Default) 56 35 { 57 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeFloat, 'Default' => $Default); 36 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 37 'Type' => ViewItemTypeFloat, 'Default' => $Default); 58 38 } 59 39 60 40 function AddItemText($Name, $Title, $Default) 61 41 { 62 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeText, 'Default' => $Default); 42 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 43 'Type' => ViewItemTypeText, 'Default' => $Default); 63 44 } 64 45 65 46 function AddItemString($Name, $Title, $Default) 66 47 { 67 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeString, 'Default' => $Default); 48 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 49 'Type' => ViewItemTypeString, 'Default' => $Default); 68 50 } 69 51 70 52 function AddItemBoolean($Name, $Title, $Default) 71 53 { 72 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeBoolean, 'Default' => $Default); 54 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 55 'Type' => ViewItemTypeBoolean, 'Default' => $Default); 73 56 } 74 57 75 58 function AddItemDate($Name, $Title, $Default) 76 59 { 77 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeDate, 'Default' => $Default); 60 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 61 'Type' => ViewItemTypeDate, 'Default' => $Default); 78 62 } 79 63 80 64 function AddItemTime($Name, $Title, $Default) 81 65 { 82 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeTime, 'Default' => $Default); 66 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 67 'Type' => ViewItemTypeTime, 'Default' => $Default); 83 68 } 84 69 85 70 function AddItemDateTime($Name, $Title, $Default) 86 71 { 87 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeDateTime, 'Default' => $Default); 72 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 73 'Type' => ViewItemTypeDateTime, 'Default' => $Default); 88 74 } 89 75 90 76 function AddItemIPv4($Name, $Title, $Default) 91 77 { 92 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeIPv4, 'Default' => $Default); 78 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 79 'Type' => ViewItemTypeIPv4, 'Default' => $Default); 93 80 } 94 81 95 82 function AddItemIPv6($Name, $Title, $Default) 96 83 { 97 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeIPv6, 'Default' => $Default); 84 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 85 'Type' => ViewItemTypeIPv6, 'Default' => $Default); 98 86 } 99 87 100 88 function AddItemMACAddress($Name, $Title, $Default) 101 89 { 102 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeMACAddress, 'Default' => $Default); 90 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 91 'Type' => ViewItemTypeMACAddress, 'Default' => $Default); 103 92 } 104 93 105 94 function AddItemFileName($Name, $Title, $Default) 106 95 { 107 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeFileName, 'Default' => $Default); 96 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 97 'Type' => ViewItemTypeFileName, 'Default' => $Default); 108 98 } 109 99 110 100 function AddItemURL($Name, $Title, $Default) 111 101 { 112 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeURL, 'Default' => $Default); 102 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 103 'Type' => ViewItemTypeURL, 'Default' => $Default); 113 104 } 114 105 115 106 function AddItemPassword($Name, $Title, $Default) 116 107 { 117 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypePassword, 'Default' => $Default); 108 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 109 'Type' => ViewItemTypePassword, 'Default' => $Default); 118 110 } 119 111 120 112 function AddItemImage($Name, $Title, $Default) 121 113 { 122 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeImage, 'Default' => $Default); 114 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 115 'Type' => ViewItemTypeImage, 'Default' => $Default); 123 116 } 124 117 118 function AddItemEnumeration($Name, $Title, $Default, $States) 119 { 120 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 121 'Type' => ViewItemTypeEnumeration, 'Default' => $Default, 'States' => $States); 122 } 123 125 124 function ShowEditForm() 126 125 { … … 173 172 else $Selected = ''; 174 173 $Edit .= '<option value="'.$Row['Id'].'"'.$Selected.'>'.$Row['Id'].': '.$Row['Name'].'</option>'; 174 } 175 $Edit .= '</select>'; 176 break; 177 case ViewItemTypeEnumeration: 178 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">'; 179 foreach($Item['States'] as $StateIndex => $StateName) 180 { 181 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"'; 182 else $Selected = ''; 183 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>'; 175 184 } 176 185 $Edit .= '</select>'; … … 191 200 break; 192 201 default: 193 if(array_key_exists($Item['Type'], $FormTypes)) 194 { 195 // Custom types 196 switch($FormTypes[$Item['Type']]['Type']) 197 { 198 case 'Enumeration': 199 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">'; 200 foreach($FormTypes[$Item['Type']]['States'] as $StateIndex => $StateName) 201 { 202 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"'; 203 else $Selected = ''; 204 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>'; 205 } 206 $Edit .= '</select>'; 207 break; 208 default: 209 $Edit = 'Neznámý typ'; 210 } 211 } else $Edit = 'Neznámý typ'; 202 $Edit = 'Neznámý typ'; 212 203 } 213 204 array_push($Table['Rows'], array($Item['Title'].':', $Edit)); … … 297 288 $Values[$Index] = explode('.', $_POST[$Context.$Index]); 298 289 $Values[$Index] = mktime(0, 0, 0, $Values[$Index][1], $Values[$Index][0], $Values[$Index][2]); 299 break; 290 break; 291 case ViewItemTypeOneToMany: 292 $Values[$Index] = $_POST[$Context.$Index]; 293 break; 294 case ViewItemTypeEnumeration: 295 $Values[$Index] = $_POST[$Context.$Index]; 296 break; 300 297 case 'Array': 301 298 $I = 1; … … 309 306 break; 310 307 default: 311 if(array_key_exists($Item['Type'], $FormTypes))312 {313 // Custom types314 switch($FormTypes[$Item['Type']]['Type'])315 {316 case 'Enumeration':317 $Values[$Index] = $_POST[$Context.$Index];318 break;319 case 'Reference':320 $Values[$Index] = $_POST[$Context.$Index];321 break;322 default:323 }324 }325 308 } 326 309 }
Note:
See TracChangeset
for help on using the changeset viewer.