Changeset 442 for trunk/Common/Forms.php
- Timestamp:
- Oct 14, 2012, 9:27:26 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Forms.php
r440 r442 33 33 { 34 34 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 35 $System->Type->RegisterType($Item['Type'], '', 36 $FormTypes[$Item['Type']]); 37 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 38 $Edit = ''.$System->Type->ExecuteTypeEvent('OneToMany', 'OnView', 39 array('Value' => $this->Values[$Index], 'Name' => $Index, 40 'Type' => $Item['Type'])).''; 41 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 42 $Edit = ''.$System->Type->ExecuteTypeEvent('Enumeration', 'OnView', 43 array('Value' => $this->Values[$Index], 'Name' => $Index, 44 'Type' => $Item['Type'])).''; 45 } else $Edit = ''.$System->Type->ExecuteTypeEvent($Item['Type'], 'OnView', 46 array('Value' => $this->Values[$Index], 'Name' => $Index)).''; 35 $System->Type->RegisterType($Item['Type'], '', $FormTypes[$Item['Type']]); 36 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 37 $UseType = 'OneToMany'; 38 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 39 $UseType = 'Enumeration'; 40 } else $UseType = $Item['Type']; 41 $Edit = $System->Type->ExecuteTypeEvent($UseType, 'OnView', 42 array('Value' => $this->Values[$Index], 'Name' => $Index, 'Type' => $Item['Type'])); 47 43 array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); 48 44 } … … 63 59 function ShowEditBlock($Context = '') 64 60 { 65 global $Database, $FormTypes ;61 global $Database, $FormTypes, $System; 66 62 67 63 $Table = array( … … 75 71 { 76 72 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 77 switch($Item['Type']) 78 { 79 case 'Boolean': 80 if($this->Values[$Index] == 0) $Checked = ''; else $Checked = ' CHECKED'; 81 $Edit = '<input type="checkbox" name="'.$Context.$Index.'"'.$Checked.' />'; 82 break; 83 case 'String': 84 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 85 break; 86 case 'Text': 87 $Edit = '<textarea style="width: 98%; height: 200px;" name="'.$Context.$Index.'">'.$this->Values[$Index].'</textarea>'; 88 break; 89 case 'Password': 90 $Edit = '<input style="width: 98%;" type="password" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 91 break; 92 case 'Integer': 93 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 94 break; 95 case 'Float': 96 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 97 break; 98 case 'Time': 99 if($this->Values[$Index] == 'Now') $this->Values[$Index] = date('G:i:s'); 100 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 101 break; 102 case 'Date': 103 if($this->Values[$Index] == 'Now') $this->Values[$Index] = date('j.n.Y'); 104 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 105 break; 106 case 'DateTime': 107 if($this->Values[$Index] == 'Now') $this->Values[$Index] = date('j.n.Y G:i:s'); 108 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />'; 109 break; 110 case 'Array': 111 $Form = new Form($Item['ItemClass']); 112 $Edit = '<script type="text/javascript" id="syndication">'. 113 "var Count = 0;". 114 "function AddItem() {". 115 "Count = Count + 1;". 116 "var newcontent = document.createElement('div');". 117 "newcontent.id = '".$Context.$Item['ItemClass']."-' + Count;". 118 "newcontent.innerHTML = '<input type=\"hidden\" name=\"".$Context.$Item['ItemClass']."-' + Count + '\">".$Form->ShowEditBlock($Context.$Item['ItemClass']."-' + Count + '")."';". 119 "var scr = document.getElementById('syndication');". 120 "scr.parentNode.insertBefore(newcontent, scr); }". 121 '</script>'; 122 $Edit .= '<form><input type="button" onclick="AddItem();" value="Přidat položku" /></form>'; 123 break; 124 default: 125 if(array_key_exists($Item['Type'], $FormTypes)) 126 { 127 // Custom types 128 switch($FormTypes[$Item['Type']]['Type']) 129 { 130 case 'Enumeration': 131 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">'; 132 foreach($FormTypes[$Item['Type']]['States'] as $StateIndex => $StateName) 133 { 134 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"'; 135 else $Selected = ''; 136 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>'; 137 } 138 $Edit .= '</select>'; 139 break; 140 case 'Reference': 141 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">'; 142 $DbResult = $Database->select($FormTypes[$Item['Type']]['Table'], $FormTypes[$Item['Type']]['Id'].' as Id, '.$FormTypes[$Item['Type']]['Name'].' as Name', $FormTypes[$Item['Type']]['Filter'].' ORDER BY Name'); 143 while($Row = $DbResult->fetch_assoc()) 144 { 145 if($Row['Id'] == $this->Values[$Index]) $Selected = ' selected="selected"'; 146 else $Selected = ''; 147 $Edit .= '<option value="'.$Row['Id'].'"'.$Selected.'>'.$Row['Id'].': '.$Row['Name'].'</option>'; 148 } 149 $Edit .= '</select>'; 150 break; 151 default: 152 $Edit = 'Neznámý typ'; 153 } 154 } else $Edit = 'Neznámý typ'; 155 } 73 if(array_key_exists($Item['Type'], $FormTypes)) 74 { 75 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 76 $System->Type->RegisterType($Item['Type'], '', 77 $FormTypes[$Item['Type']]); 78 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 79 $UseType = 'OneToMany'; 80 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 81 $UseType = 'Enumeration'; 82 } else $UseType = $Item['Type']; 83 $Edit = ''.$System->Type->ExecuteTypeEvent($UseType, 'OnEdit', 84 array('Value' => $this->Values[$Index], 'Name' => $Index, 85 'Type' => $Item['Type'])).''; 86 156 87 array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); 157 88 } … … 163 94 function LoadValuesFromDatabase($Id) 164 95 { 165 global $Database, $FormTypes ;96 global $Database, $FormTypes, $System; 166 97 167 98 $DbResult = $Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id); … … 171 102 (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 172 103 { 173 $this->Values[$Index] = $DbRow[$Index]; 174 switch($Item['Type']) 175 { 176 case 'Password': 177 if($Item['Type'] == 'Password') $this->Values[$Index] = ''; // Dont show password 178 break; 179 case 'Time': 180 $this->Values[$Index] == MysqlDateTimeToTime($this->Values[$Index]); 181 break; 182 } 104 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 105 if(array_key_exists($Item['Type'], $FormTypes)) 106 { 107 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 108 $System->Type->RegisterType($Item['Type'], '', 109 $FormTypes[$Item['Type']]); 110 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 111 $UseType = 'OneToMany'; 112 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 113 $UseType = 'Enumeration'; 114 } else $UseType = $Item['Type']; 115 $this->Values[$Index] = ''.$System->Type->ExecuteTypeEvent($UseType, 'OnLoadDb', 116 array('Value' => $DbRow[$Index], 'Name' => $Index, 117 'Type' => $Item['Type'])).''; 118 119 //echo($DbRow[$Index].'='.$this->Values[$Index].'<br/>'); 183 120 } 184 121 } … … 186 123 function SaveValuesToDatabase($Id) 187 124 { 188 global $Database; 189 190 foreach($this->Definition['Items'] as $Index => $Item) 191 { 192 switch($Item['Type']) 193 { 194 case 'Password': 195 if($this->Values[$Index] == '') unset($this->Values[$Index]); // Do not modify empty passwords 196 else $this->Values[$Index] = sha1($this->Values[$Index]); 197 break; 198 case 'Time': 199 $this->Values[$Index] = TimeToMysqlDateTime($this->Values[$Index]); 200 break; 201 } 125 global $Database, $FormTypes, $System; 126 127 $Values = array(); 128 foreach($this->Definition['Items'] as $Index => $Item) 129 if(!array_key_exists($Item['Type'], $FormTypes) or 130 (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 131 { 132 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 133 if(array_key_exists($Item['Type'], $FormTypes)) 134 { 135 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 136 $System->Type->RegisterType($Item['Type'], '', 137 $FormTypes[$Item['Type']]); 138 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 139 $UseType = 'OneToMany'; 140 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 141 $UseType = 'Enumeration'; 142 } else $UseType = $Item['Type']; 143 $Values[$Index] = ''.$System->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', 144 array('Value' => $this->Values[$Index], 'Name' => $Index, 145 'Type' => $Item['Type'])).''; 146 147 //echo($DbRow[$Index].'='.$this->Values[$Index].'<br/>'); 202 148 } 203 149 if($Id == 0) 204 150 { 205 $ this->Values['Id'] = $Id;206 $DbResult = $Database->insert($this->Definition['Table'], $ this->Values);151 $Values['Id'] = $Id; 152 $DbResult = $Database->insert($this->Definition['Table'], $Values); 207 153 } else 208 $DbResult = $Database->update($this->Definition['Table'], 'Id='.$Id, $ this->Values);154 $DbResult = $Database->update($this->Definition['Table'], 'Id='.$Id, $Values); 209 155 //echo($Database->LastQuery); 210 156 } … … 217 163 function LoadValuesFromFormBlock($Context = '') 218 164 { 219 global $ FormTypes;165 global $Database, $FormTypes, $System; 220 166 221 167 if($Context != '') $Context = $Context.'-'; … … 223 169 foreach($this->Definition['Items'] as $Index => $Item) 224 170 { 225 if(array_key_exists($Context.$Index, $_POST)) 226 switch($Item['Type']) 227 { 228 case 'Boolean': 229 if(array_key_exists($Context.$Index, $_POST)) $Values[$Index] = 1; 230 else $Values[$Index] = 0; 231 break; 232 case 'String': 233 $Values[$Index] = $_POST[$Context.$Index]; 234 break; 235 case 'Text': 236 $Values[$Index] = $_POST[$Context.$Index]; 237 break; 238 case 'Password': 239 $Values[$Index] = $_POST[$Context.$Index]; 240 break; 241 case 'Integer': 242 $Values[$Index] = $_POST[$Context.$Index]; 243 break; 244 case 'Float': 245 $Values[$Index] = $_POST[$Context.$Index]; 246 break; 247 case 'Time': 248 $Values[$Index] = explode('.', $_POST[$Context.$Index]); 249 $Values[$Index] = mktime(0, 0, 0, $Values[$Index][1], $Values[$Index][0], $Values[$Index][2]); 250 break; 251 case 'Array': 252 $I = 1; 253 //echo('Expect: '.$Context.$Item['ItemClass'].'-'.$I.'<br />'); 254 while(isset($_POST[$Context.$Item['ItemClass'].'-'.$I])) 255 { 256 $Form = new Form($Item['ItemClass']); 257 $Values[$Index][] = $Form->LoadValuesFromFormBlock($Context.$Item['ItemClass'].'-'.$I); 258 $I++; 259 } 260 break; 261 default: 262 if(array_key_exists($Item['Type'], $FormTypes)) 263 { 264 // Custom types 265 switch($FormTypes[$Item['Type']]['Type']) 266 { 267 case 'Enumeration': 268 $Values[$Index] = $_POST[$Context.$Index]; 269 break; 270 case 'Reference': 271 $Values[$Index] = $_POST[$Context.$Index]; 272 break; 273 default: 274 } 275 } 276 } 171 //if(array_key_exists($Context.$Index, $_POST)) 172 if(array_key_exists($Item['Type'], $FormTypes)) 173 { 174 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 175 $System->Type->RegisterType($Item['Type'], '', 176 $FormTypes[$Item['Type']]); 177 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 178 $UseType = 'OneToMany'; 179 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 180 $UseType = 'Enumeration'; 181 } else $UseType = $Item['Type']; 182 $Values[$Index] = ''.$System->Type->ExecuteTypeEvent($UseType, 'OnLoad', 183 array('Name' => $Index, 'Type' => $Item['Type'])).''; 277 184 } 278 185 return($Values);
Note:
See TracChangeset
for help on using the changeset viewer.