Changeset 11 for trunk/www/form.php
- Timestamp:
- Jun 11, 2009, 8:28:50 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/form.php
r10 r11 9 9 var $OnSubmit = ''; 10 10 11 function Form($ClassName)11 function __construct($ClassName) 12 12 { 13 13 global $FormClasses; … … 36 36 $Edit = ExecuteTypeEvent($Item['Type'], 'OnView', 37 37 array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type'])); 38 /*39 switch($Item['Type'])40 {41 case 'Boolean':42 if($this->Values[$Index] == 0) $Checked = ''; else $Checked = ' CHECKED';43 $Edit = '<input type="checkbox" name="'.$Context.$Index.'"'.$Checked.' />';44 break;45 case 'String':46 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';47 break;48 case 'Text':49 $Edit = '<textarea style="width: 100%; height: 200px;" name="'.$Context.$Index.'">'.$this->Values[$Index].'</textarea>';50 break;51 case 'Password':52 $Edit = '<input style="width: 100%;" type="password" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';53 break;54 case 'Integer':55 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';56 break;57 case 'Float':58 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';59 break;60 case 'Time':61 if($this->Values[$Index] == 'Now') $this->Values[$Index] = date('j.n.Y');62 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';63 break;64 case 'Array':65 $Form = new Form($Item['ItemClass']);66 $Edit = '<script type="text/javascript" id="syndication">'.67 "var Count = 0;".68 "function AddItem() {".69 "Count = Count + 1;".70 "var newcontent = document.createElement('div');".71 "newcontent.id = '".$Context.$Item['ItemClass']."-' + Count;".72 "newcontent.innerHTML = '<input type=\"hidden\" name=\"".$Context.$Item['ItemClass']."-' + Count + '\">".$Form->ShowEditBlock($Context.$Item['ItemClass']."-' + Count + '")."';".73 "var scr = document.getElementById('syndication');".74 "scr.parentNode.insertBefore(newcontent, scr); }".75 '</script>';76 $Edit .= '<form><input type="button" onclick="AddItem();" value="Přidat položku" /></form>';77 break;78 default:79 if(array_key_exists($Item['Type'], $FormTypes))80 {81 // Custom types82 switch($FormTypes[$Item['Type']]['Type'])83 {84 case 'Enumeration':85 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">';86 foreach($FormTypes[$Item['Type']]['States'] as $StateIndex => $StateName)87 {88 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"';89 else $Selected = '';90 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>';91 }92 $Edit .= '</select>';93 break;94 case 'Reference':95 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">';96 $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');97 while($Row = $DbResult->fetch_assoc())98 {99 if($Row['Id'] == $this->Values[$Index]) $Selected = ' selected="selected"';100 else $Selected = '';101 $Edit .= '<option value="'.$Row['Id'].'"'.$Selected.'>'.$Row['Name'].'</option>';102 }103 $Edit .= '</select>';104 break;105 default:106 $Edit = 'Neznámý typ';107 }108 } else $Edit = 'Neznámý typ';109 }110 */111 38 array_push($Table['Rows'], array($Item['Caption'], $Edit)); 112 39 } … … 136 63 $Edit = ExecuteTypeEvent($Item['Type'], 'OnEdit', 137 64 array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type'])); 138 /*139 switch($Item['Type'])140 {141 case 'Boolean':142 if($this->Values[$Index] == 0) $Checked = ''; else $Checked = ' CHECKED';143 $Edit = '<input type="checkbox" name="'.$Context.$Index.'"'.$Checked.' />';144 break;145 case 'String':146 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';147 break;148 case 'Text':149 $Edit = '<textarea style="width: 100%; height: 200px;" name="'.$Context.$Index.'">'.$this->Values[$Index].'</textarea>';150 break;151 case 'Password':152 $Edit = '<input style="width: 100%;" type="password" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';153 break;154 case 'Integer':155 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';156 break;157 case 'Float':158 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';159 break;160 case 'Time':161 if($this->Values[$Index] == 'Now') $this->Values[$Index] = date('j.n.Y');162 $Edit = '<input style="width: 100%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';163 break;164 case 'Array':165 $Form = new Form($Item['ItemClass']);166 $Edit = '<script type="text/javascript" id="syndication">'.167 "var Count = 0;".168 "function AddItem() {".169 "Count = Count + 1;".170 "var newcontent = document.createElement('div');".171 "newcontent.id = '".$Context.$Item['ItemClass']."-' + Count;".172 "newcontent.innerHTML = '<input type=\"hidden\" name=\"".$Context.$Item['ItemClass']."-' + Count + '\">".$Form->ShowEditBlock($Context.$Item['ItemClass']."-' + Count + '")."';".173 "var scr = document.getElementById('syndication');".174 "scr.parentNode.insertBefore(newcontent, scr); }".175 '</script>';176 $Edit .= '<form><input type="button" onclick="AddItem();" value="Přidat položku" /></form>';177 break;178 default:179 if(array_key_exists($Item['Type'], $FormTypes))180 {181 // Custom types182 switch($FormTypes[$Item['Type']]['Type'])183 {184 case 'Enumeration':185 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">';186 foreach($FormTypes[$Item['Type']]['States'] as $StateIndex => $StateName)187 {188 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"';189 else $Selected = '';190 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>';191 }192 $Edit .= '</select>';193 break;194 case 'Reference':195 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">';196 $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');197 while($Row = $DbResult->fetch_assoc())198 {199 if($Row['Id'] == $this->Values[$Index]) $Selected = ' selected="selected"';200 else $Selected = '';201 $Edit .= '<option value="'.$Row['Id'].'"'.$Selected.'>'.$Row['Name'].'</option>';202 }203 $Edit .= '</select>';204 break;205 default:206 $Edit = 'Neznámý typ';207 }208 } else $Edit = 'Neznámý typ';209 }210 */211 65 array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); 212 66 } … … 225 79 { 226 80 $this->Values[$Index] = $DbRow[$Index]; 227 switch($Item['Type'])228 {229 case 'Password':230 if($Item['Type'] == 'Password') $this->Values[$Index] = ''; // Dont show password231 break;232 case 'Time':233 $this->Values[$Index] == MysqlDateTimeToTime($this->Values[$Index]);234 break;235 }236 81 } 237 82 } … … 241 86 global $Database; 242 87 243 foreach($this->Definition['Items'] as $Index => $Item)244 {245 switch($Item['Type'])246 {247 case 'Password':248 if($this->Values[$Index] == '') unset($this->Values[$Index]); // Do not modify empty passwords249 else $this->Values[$Index] = sha1($this->Values[$Index]);250 break;251 case 'Time':252 $this->Values[$Index] = TimeToMysqlDateTime($this->Values[$Index]);253 break;254 }255 }256 88 if($Id == 0) 257 89 { … … 260 92 } else 261 93 $DbResult = $Database->update($this->Definition['Table'], 'Id='.$Id, $this->Values); 262 //echo($Database->LastQuery);263 94 } 264 95 … … 279 110 $Values[$Index] = ExecuteTypeEvent($Item['Type'], 'OnLoad', 280 111 array('Name' => $Index, 'Type' => $Item['Type'])); 281 /*282 switch($Item['Type'])283 {284 case 'Boolean':285 if(array_key_exists($Context.$Index, $_POST)) $Values[$Index] = 1;286 else $Values[$Index] = 0;287 break;288 case 'String':289 $Values[$Index] = $_POST[$Context.$Index];290 break;291 case 'Text':292 $Values[$Index] = $_POST[$Context.$Index];293 break;294 case 'Password':295 $Values[$Index] = $_POST[$Context.$Index];296 break;297 case 'Integer':298 $Values[$Index] = $_POST[$Context.$Index];299 break;300 case 'Float':301 $Values[$Index] = $_POST[$Context.$Index];302 break;303 case 'Time':304 $Values[$Index] = explode('.', $_POST[$Context.$Index]);305 $Values[$Index] = mktime(0, 0, 0, $Values[$Index][1], $Values[$Index][0], $Values[$Index][2]);306 break;307 case 'Array':308 $I = 1;309 //echo('Expect: '.$Context.$Item['ItemClass'].'-'.$I.'<br />');310 while(isset($_POST[$Context.$Item['ItemClass'].'-'.$I]))311 {312 $Form = new Form($Item['ItemClass']);313 $Values[$Index][] = $Form->LoadValuesFromFormBlock($Context.$Item['ItemClass'].'-'.$I);314 $I++;315 }316 break;317 default:318 if(array_key_exists($Item['Type'], $FormTypes))319 {320 // Custom types321 switch($FormTypes[$Item['Type']]['Type'])322 {323 case 'Enumeration':324 $Values[$Index] = $_POST[$Context.$Index];325 break;326 case 'Reference':327 $Values[$Index] = $_POST[$Context.$Index];328 break;329 default:330 }331 }332 }333 */334 112 } 335 113 return($Values); … … 337 115 } 338 116 339 function MakeLink($Target, $Title)340 {341 return('<a href="'.$Target.'">'.$Title.'</a>');342 }343 344 function Table($Table, $Class)345 {346 $Result = '<table class="'.$Class.'">';347 if(array_key_exists('Header', $Table))348 {349 $Result .= '<tr>';350 foreach($Table['Header'] as $Item)351 $Result .= '<th>'.$Item.'</th>';352 $Result .= '</tr>';353 }354 foreach($Table['Rows'] as $Row)355 {356 $Result .= '<tr>';357 foreach($Row as $Index => $Item)358 {359 if($Index == 0) $Class = ' class="Header"'; else $Class = '';360 $Result .= '<td'.$Class.'>'.$Item.'</td>';361 }362 $Result .= '</tr>';363 }364 $Result .= '</table>';365 return($Result);366 }367 368 function ShowEditTable($ClassName, $Values)369 {370 }371 372 117 ?>
Note:
See TracChangeset
for help on using the changeset viewer.