Changeset 871 for trunk/Common/Form
- Timestamp:
- Apr 6, 2020, 9:19:50 PM (5 years ago)
- Location:
- trunk/Common/Form
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Form/Form.php
r747 r871 43 43 function LoadDefaults() 44 44 { 45 foreach($this->Definition['Items'] as $Index => $Item) 46 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 47 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 48 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 49 { 50 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) 51 $this->Values[$Index] = $Item['Default']; 45 foreach ($this->Definition['Items'] as $Index => $Item) 46 { 47 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 48 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 49 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 50 { 51 if (!array_key_exists($Index, $this->Values)) 52 $this->Values[$Index] = $Item['Default']; 53 } 52 54 } 53 55 } … … 128 130 'Rows' => array(), 129 131 ); 130 if ($Context != '') $Context = $Context.'-';131 foreach ($this->Definition['Items'] as $Index => $Item)132 { 133 if (!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;134 if($Item['ReadOnly'] == false)135 if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))136 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or137 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and138 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))139 {132 if ($Context != '') $Context = $Context.'-'; 133 foreach ($this->Definition['Items'] as $Index => $Item) 134 { 135 if (!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false; 136 if ($Item['ReadOnly'] == false) 137 if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false)) 138 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 139 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 140 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 141 { 140 142 $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index, 141 142 if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];143 'Type' => $Item['Type'], 'Values' => $this->Values); 144 if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null']; 143 145 else unset($Parameters['Null']); 144 if (array_key_exists('OnPreset', $Item)) $Parameters['OnPreset'] = $Item['OnPreset'];146 if (array_key_exists('OnPreset', $Item)) $Parameters['OnPreset'] = $Item['OnPreset']; 145 147 else unset($Parameters['OnPreset']); 146 148 147 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))148 { 149 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))149 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 150 { 151 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 150 152 $this->FormManager->Type->RegisterType($Item['Type'], '', 151 153 $this->FormManager->FormTypes[$Item['Type']]); 152 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')154 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 153 155 { 154 156 $UseType = 'OneToMany'; 155 } else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')157 } else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 156 158 $UseType = 'Enumeration'; 157 159 } else $UseType = $Item['Type']; 158 160 $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters); 159 if(array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix']; 160 161 $Caption = $Item['Caption'].':'; 162 if(array_key_exists($Index, $this->ValuesValidate) and 163 $this->ValuesValidate[$Index]) { 161 if (array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix']; 162 163 $Caption = $Item['Caption'].':'; 164 if (array_key_exists($Index, $this->ValuesValidate) and 165 $this->ValuesValidate[$Index]) 166 { 164 167 $Format = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'GetValidationFormat', array()); 165 if ($Format != '') $Caption .= '<br/><small>'.$Format.'</small>';168 if ($Format != '') $Caption .= '<br/><small>'.$Format.'</small>'; 166 169 $Caption = '<span style="color:red;">'.$Caption.'</span>'; 167 170 } 168 if(!$this->FormManager->Type->IsHidden($UseType))171 if (!$this->FormManager->Type->IsHidden($UseType)) 169 172 array_push($Table['Rows'], array($Caption, $Edit)); 170 else $Hidden .= $Edit;171 }173 else $Hidden .= $Edit; 174 } 172 175 } 173 176 $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.Table($Table). 174 177 $Hidden.'</fieldset>'; 175 return ($Output);178 return $Output; 176 179 } 177 180 … … 270 273 function LoadValuesFromFormBlock($Context = '') 271 274 { 272 if ($Context != '') $Context = $Context.'-';275 if ($Context != '') $Context = $Context.'-'; 273 276 $Values = array(); 277 foreach ($this->Definition['Items'] as $Index => $Item) 278 { 279 if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false)) 280 { 281 if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 282 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 283 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and 284 (!array_key_exists('ReadOnly', $Item) or 285 (array_key_exists('ReadOnly', $Item) and 286 ($Item['ReadOnly'] != true)))) 287 { 288 //if (array_key_exists($Context.$Index, $_POST)) 289 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 290 { 291 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 292 $this->FormManager->Type->RegisterType($Item['Type'], '', 293 $this->FormManager->FormTypes[$Item['Type']]); 294 $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type']; 295 if ($CustomType == 'Reference') 296 $UseType = 'OneToMany'; 297 else if ($CustomType == 'Enumeration') 298 $UseType = 'Enumeration'; 299 } else $UseType = $Item['Type']; 300 $Parameters = array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values); 301 if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null']; 302 else unset($Parameters['Null']); 303 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad', 304 $Parameters); 305 } 306 } else 307 { 308 if (isset($Item['Default'])) { 309 if (isset($Item['Null']) and ($Item['Null'] == true)) 310 $Values[$Index] = null; 311 else $Values[$Index] = $Item['Default']; 312 } 313 } 314 } 315 return($Values); 316 } 317 318 function Validate() 319 { 320 $Valid = true; 274 321 foreach($this->Definition['Items'] as $Index => $Item) 275 if(!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))276 {277 322 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 278 323 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and … … 294 339 $UseType = 'Enumeration'; 295 340 } else $UseType = $Item['Type']; 296 $Parameters = array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values);297 if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];298 else unset($Parameters['Null']);299 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad',300 $Parameters);301 }302 } else303 {304 if(isset($Item['Default'])) {305 if(isset($Item['Null']) and ($Item['Null'] == true))306 $Values[$Index] = null;307 else $Values[$Index] = $Item['Default'];308 }309 }310 return($Values);311 }312 313 function Validate()314 {315 $Valid = true;316 foreach($this->Definition['Items'] as $Index => $Item)317 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or318 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and319 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and320 (!array_key_exists('ReadOnly', $Item) or321 (array_key_exists('ReadOnly', $Item) and322 ($Item['ReadOnly'] != true))))323 {324 //if(array_key_exists($Context.$Index, $_POST))325 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))326 {327 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))328 $this->FormManager->Type->RegisterType($Item['Type'], '',329 $this->FormManager->FormTypes[$Item['Type']]);330 $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type'];331 if($CustomType == 'Reference')332 $UseType = 'OneToMany';333 else if($CustomType == 'Enumeration')334 $UseType = 'Enumeration';335 } else $UseType = $Item['Type'];336 341 337 342 $Parameters = array('Value' => $this->Values[$Index]); -
trunk/Common/Form/Types/DateTime.php
r738 r871 11 11 global $MonthNames; 12 12 13 if ($Item['Value'] == 0) return('');14 if ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == '')) $Item['Value'] = time();13 if ($Item['Value'] == 0) return ''; 14 if ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == '')) $Item['Value'] = time(); 15 15 $Parts = getdate($Item['Value']); 16 16 $Output = $Parts['mday'].'.'.$Parts['mon'].'.'.$Parts['year'].' '. 17 17 sprintf('%02d', $Parts['hours']).':'.sprintf('%02d', $Parts['minutes']).':'.sprintf('%02d', $Parts['seconds']); 18 return ($Output);18 return $Output; 19 19 } 20 20 … … 23 23 global $MonthNames; 24 24 25 if(($Item['Value'] !== null) and ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == ''))) $Item['Value'] = time(); 25 if (($Item['Value'] == null) or (($Item['Value'] !== null) and ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == '')))) 26 { 27 $Item['Value'] = time(); 28 $IsNull = true; 29 } else $IsNull = false; 26 30 $Parts = getdate($Item['Value']); 27 31 28 32 $Output = ''; 29 33 $Style = ''; 30 if (array_key_exists('Null', $Item) and $Item['Null'])34 if (array_key_exists('Null', $Item) and $Item['Null']) 31 35 { 32 if ($Item['Value'] != null)36 if (!$IsNull) 33 37 { 34 38 $Checked = ' checked="1"'; … … 46 50 // Hour 47 51 $Output .= '<select name="'.$Item['Name'].'-hour" id="'.$Item['Name'].'-hour" '.$Style.'>'; 48 for ($I = 1; $I <= 24; $I++)52 for ($I = 1; $I <= 24; $I++) 49 53 { 50 if ($Parts['hours'] == $I) $Selected = ' selected="1"'; else $Selected = '';54 if ($Parts['hours'] == $I) $Selected = ' selected="1"'; else $Selected = ''; 51 55 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; 52 56 } … … 54 58 // Minute 55 59 $Output .= '<select name="'.$Item['Name'].'-minute" id="'.$Item['Name'].'-minute" '.$Style.'>'; 56 for ($I = 1; $I <= 60; $I++)60 for ($I = 1; $I <= 60; $I++) 57 61 { 58 if ($Parts['minutes'] == $I) $Selected = ' selected="1"'; else $Selected = '';62 if ($Parts['minutes'] == $I) $Selected = ' selected="1"'; else $Selected = ''; 59 63 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; 60 64 } … … 62 66 // Second 63 67 $Output .= '<select name="'.$Item['Name'].'-second" id="'.$Item['Name'].'-second" '.$Style.'>'; 64 for ($I = 1; $I <= 60; $I++)68 for ($I = 1; $I <= 60; $I++) 65 69 { 66 if ($Parts['seconds'] == $I) $Selected = ' selected="1"'; else $Selected = '';70 if ($Parts['seconds'] == $I) $Selected = ' selected="1"'; else $Selected = ''; 67 71 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; 68 72 } … … 70 74 // Day 71 75 $Output .= ' <select name="'.$Item['Name'].'-day" id="'.$Item['Name'].'-day" '.$Style.'>'; 72 for ($I = 1; $I <= 31; $I++)76 for ($I = 1; $I <= 31; $I++) 73 77 { 74 if ($Parts['mday'] == $I) $Selected = ' selected="1"'; else $Selected = '';78 if ($Parts['mday'] == $I) $Selected = ' selected="1"'; else $Selected = ''; 75 79 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; 76 80 } … … 78 82 // Month 79 83 $Output .= '<select name="'.$Item['Name'].'-month" id="'.$Item['Name'].'-month" '.$Style.'>'; 80 for ($I = 1; $I <= 12; $I++)84 for ($I = 1; $I <= 12; $I++) 81 85 { 82 if ($Parts['mon'] == $I) $Selected = ' selected="1"'; else $Selected = '';86 if ($Parts['mon'] == $I) $Selected = ' selected="1"'; else $Selected = ''; 83 87 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$MonthNames[$I].'</option>'; 84 88 } … … 86 90 // Year 87 91 $Output .= '<select name="'.$Item['Name'].'-year" id="'.$Item['Name'].'-year" '.$Style.'>'; 88 for ($I = 1900; $I < 2100; $I++)92 for ($I = 1900; $I < 2100; $I++) 89 93 { 90 if ($Parts['year'] == $I) $Selected = ' selected="1"'; else $Selected = '';94 if ($Parts['year'] == $I) $Selected = ' selected="1"'; else $Selected = ''; 91 95 $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>'; 92 96 } 93 97 $Output .= '</select>'; 94 return ($Output);98 return $Output; 95 99 } 96 100 97 101 function OnLoad($Item) 98 102 { 99 if (!array_key_exists($Item['Name'].'-null', $_POST) and array_key_exists('Null', $Item) and ($Item['Null'] == true)) return(null);100 else return (mktime($_POST[$Item['Name'].'-hour'], $_POST[$Item['Name'].'-minute'], $_POST[$Item['Name'].'-second'],101 $_POST[$Item['Name'].'-month'], $_POST[$Item['Name'].'-day'], $_POST[$Item['Name'].'-year']) );103 if (!array_key_exists($Item['Name'].'-null', $_POST) and array_key_exists('Null', $Item) and ($Item['Null'] == true)) return null; 104 else return mktime($_POST[$Item['Name'].'-hour'], $_POST[$Item['Name'].'-minute'], $_POST[$Item['Name'].'-second'], 105 $_POST[$Item['Name'].'-month'], $_POST[$Item['Name'].'-day'], $_POST[$Item['Name'].'-year']); 102 106 } 103 107 104 108 function OnLoadDb($Item) 105 109 { 106 return (MysqlDateTimeToTime($Item['Value']));110 return MysqlDateTimeToTime($Item['Value']); 107 111 } 108 112 109 113 function OnSaveDb($Item) 110 114 { 111 if ($Item['Value'] == null) return(null);112 else return (date('Y-m-d H:i:s', $Item['Value']));115 if ($Item['Value'] == null) return null; 116 else return date('Y-m-d H:i:s', $Item['Value']); 113 117 } 114 118 115 119 function DatabaseEscape($Value) 116 120 { 117 return ('"'.addslashes($Value).'"');121 return '"'.addslashes($Value).'"'; 118 122 } 119 123 }
Note:
See TracChangeset
for help on using the changeset viewer.