Changeset 659 for trunk/Common
- Timestamp:
- May 29, 2014, 11:59:39 PM (11 years ago)
- Location:
- trunk/Common
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Database.php
r634 r659 8 8 var $PDOStatement; 9 9 var $num_rows = 0; 10 10 11 11 function fetch_assoc() 12 12 { 13 13 return($this->PDOStatement->fetch(PDO::FETCH_ASSOC)); 14 14 } 15 15 16 16 function fetch_array() 17 17 { … … 36 36 var $ShowSQLError; 37 37 var $ShowSQLQuery; 38 38 39 39 function __construct() 40 { 40 { 41 41 $this->Type = 'mysql'; // mysql, pgsql 42 42 $this->ShowSQLError = false; … … 44 44 $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()'); 45 45 } 46 46 47 47 function Connect($Host, $User, $Password, $Database) 48 { 48 { 49 49 if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 50 50 else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; … … 59 59 } 60 60 } 61 61 62 62 function Disconnect() 63 63 { 64 64 unset($this->PDO); 65 65 } 66 66 67 67 function Connected() 68 68 { 69 69 return(isset($this->PDO)); 70 70 } 71 71 72 72 function select_db($Database) 73 73 { 74 74 $this->query('USE `'.$Database.'`'); 75 75 } 76 76 77 77 function query($Query) 78 78 { 79 79 if(!$this->Connected()) throw new Exception('Not connected to database'); 80 80 $this->LastQuery = $Query; 81 if($this->ShowSQLQuery == true) 81 if($this->ShowSQLQuery == true) 82 82 echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n"); 83 83 $Result = new DatabaseResult(); … … 91 91 $this->Error = $this->PDO->errorInfo(); 92 92 $this->Error = $this->Error[2]; 93 if(($this->Error != '') and ($this->ShowSQLError == true)) 93 if(($this->Error != '') and ($this->ShowSQLError == true)) 94 94 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 95 95 throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query); 96 96 } 97 return($Result); 97 return($Result); 98 98 } 99 99 100 100 function select($Table, $What = '*', $Condition = 1) 101 { 102 return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition)); 101 { 102 return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition)); 103 103 } 104 104 105 105 function delete($Table, $Condition) 106 106 { 107 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 108 } 109 107 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 108 } 109 110 110 function insert($Table, $Data) 111 111 { … … 115 115 { 116 116 $Name .= ',`'.$Key.'`'; 117 if(!in_array($Value, $this->Functions)) 117 if(!in_array($Value, $this->Functions)) 118 118 { 119 119 if(is_null($Value)) $Value = 'NULL'; … … 124 124 $Name = substr($Name, 1); 125 125 $Values = substr($Values, 1); 126 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 126 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 127 127 $this->insert_id = $this->PDO->lastInsertId(); 128 128 } 129 129 130 130 function update($Table, $Condition, $Data) 131 131 { … … 133 133 foreach($Data as $Key => $Value) 134 134 { 135 if(!in_array($Value, $this->Functions)) 135 if(!in_array($Value, $this->Functions)) 136 136 { 137 137 if(is_null($Value)) $Value = 'NULL'; … … 140 140 $Values .= ', `'.$Key.'`='.$Value; 141 141 } 142 $Values = substr($Values, 2); 142 $Values = substr($Values, 2); 143 143 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 144 144 } 145 145 146 146 function replace($Table, $Data) 147 147 { … … 150 150 foreach($Data as $Key => $Value) 151 151 { 152 if(!in_array($Value, $this->Functions)) 152 if(!in_array($Value, $this->Functions)) 153 153 { 154 154 if(is_null($Value)) $Value = 'NULL'; … … 164 164 //echo($this->error().'<br>'); 165 165 } 166 166 167 167 function charset($Charset) 168 168 { 169 169 $this->query('SET NAMES "'.$Charset.'"'); 170 170 } 171 171 172 172 function real_escape_string($Text) 173 173 { 174 174 return(addslashes($Text)); 175 175 } 176 176 177 177 public function __sleep() 178 178 { … … 188 188 { 189 189 if($Time == NULL) return(NULL); 190 else return(date('Y-m-d H:i:s', $Time)); 190 else return(date('Y-m-d H:i:s', $Time)); 191 191 } 192 192 … … 194 194 { 195 195 if($Time == NULL) return(NULL); 196 else return(date('Y-m-d', $Time)); 196 else return(date('Y-m-d', $Time)); 197 197 } 198 198 … … 200 200 { 201 201 if($Time == NULL) return(NULL); 202 else return(date('H:i:s', $Time)); 202 else return(date('H:i:s', $Time)); 203 203 } 204 204 205 205 function MysqlDateTimeToTime($DateTime) 206 206 { 207 if($DateTime == '') return(NULL); 207 if($DateTime == '') return(NULL); 208 208 $Parts = explode(' ', $DateTime); 209 $DateParts = explode('-', $Parts[0]); 209 $DateParts = explode('-', $Parts[0]); 210 210 $TimeParts = explode(':', $Parts[1]); 211 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 212 return($Result); 211 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 212 return($Result); 213 213 } 214 214 … … 216 216 { 217 217 if($Date == '') return(NULL); 218 return(MysqlDateTimeToTime($Date.' 0:0:0')); 218 return(MysqlDateTimeToTime($Date.' 0:0:0')); 219 219 } 220 220 … … 222 222 { 223 223 if($Time == '') return(NULL); 224 return(MysqlDateTimeToTime('0000-00-00 '.$Time)); 225 } 224 return(MysqlDateTimeToTime('0000-00-00 '.$Time)); 225 } -
trunk/Common/Form/Types/DateTime.php
r616 r659 10 10 { 11 11 global $MonthNames; 12 12 13 13 if($Item['Value'] == 0) return(''); 14 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 $Parts['hours'].':'.$Parts['minutes'].':'.$Parts['seconds'];17 sprintf('%02d', $Parts['hours']).':'.sprintf('%02d', $Parts['minutes']).':'.sprintf('%02d', $Parts['seconds']); 18 18 return($Output); 19 19 } … … 25 25 if(($Item['Value'] !== null) and ((strtolower($Item['Value']) == 'now') or (strtolower($Item['Value']) == ''))) $Item['Value'] = time(); 26 26 $Parts = getdate($Item['Value']); 27 27 28 28 $Output = ''; 29 29 $Style = ''; … … 43 43 $Item['Name'].'-day\');toggle(\''.$Item['Name'].'-month\');toggle(\''.$Item['Name'].'-year\');"/>'; 44 44 } 45 45 46 46 // Hour 47 47 $Output .= '<select name="'.$Item['Name'].'-hour" id="'.$Item['Name'].'-hour" '.$Style.'>'; … … 106 106 return(MysqlDateTimeToTime($Item['Value'])); 107 107 } 108 108 109 109 function OnSaveDb($Item) 110 { 110 { 111 111 if($Item['Value'] == null) return(null); 112 112 else return(date('Y-m-d H:i:s', $Item['Value'])); -
trunk/Common/Form/Types/File.php
r577 r659 9 9 var $DirectoryId; 10 10 var $TempName; 11 11 12 12 function DetectMimeType() 13 13 { … … 18 18 return($Result); 19 19 } 20 20 21 21 function GetSize($Item) 22 22 { … … 24 24 if(file_exists($FileName)) $Result = filesize($FileName); 25 25 else $Result = 0; 26 return($Result); 26 return($Result); 27 27 } 28 28 29 29 function GetFullName() 30 30 { 31 31 $ParentId = $this->Directory; 32 while($Paren Id != null)32 while($ParentId != null) 33 33 { 34 34 $DbResult = $this->Database->select('FileDirectory', '*', 'Id='.$ParentId); … … 36 36 $Path .= $DbRow['Name'].'/'; 37 37 $ParentId = $DbRow['Parent']; 38 } 38 } 39 39 $Result = $this->UploadFileFolder.'/'.$Path.$File->Name; 40 40 return($Result); 41 41 } 42 42 43 43 function GetExt() 44 44 { 45 45 return(substr($this->Name, 0, strpos($this->Name, '.') - 1)); 46 46 } 47 47 48 48 function Delete() 49 49 { 50 50 if(file_exists($this->GetFullName())) unlink($this->GetFullName()); 51 51 } 52 52 53 53 function GetContent() 54 54 { … … 64 64 var $FileDownloadURL; 65 65 var $DirectoryId; 66 66 67 67 function __construct($FormManager) 68 68 { … … 71 71 $this->DirectoryId = null; 72 72 } 73 73 74 74 function OnView($Item) 75 75 { … … 99 99 { 100 100 $File->Name = $UploadFile['name']; 101 $File->Size = $UploadFile['size']; 101 $File->Size = $UploadFile['size']; 102 102 $File->TempName = $UploadFile['tmp_name']; 103 103 } … … 105 105 return($File); 106 106 } 107 107 108 108 function OnLoadDb($Item) 109 109 { … … 120 120 return($File); 121 121 } 122 122 123 123 function OnSaveDb($Item) 124 124 { 125 125 if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); 126 126 $File = &$Item['Value']; 127 $Properties = array('Name' => $File->Name, 127 $Properties = array('Name' => $File->Name, 128 128 'Size' => $File->GetSize(), 'Directory' => $File->Directory); 129 129 $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); … … 131 131 { 132 132 $DbRow = $DbResult->fetch_assoc(); 133 if($File->TempName != '') 133 if($File->TempName != '') 134 134 { 135 135 $FileName = $File->GetFullName(); … … 137 137 } 138 138 $this->Database->update('File', 'Id='.$File->Id, $Properties); 139 } else 139 } else 140 140 { 141 141 $this->Database->insert('File', $Properties); … … 145 145 SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!'); 146 146 } 147 147 148 148 } -
trunk/Common/Form/Types/Time.php
r616 r659 13 13 $TimeParts = getdate($Item['Value']); 14 14 15 $Output = $TimeParts['hours'].':'.$TimeParts['minutes'].':'.$TimeParts['seconds'];15 $Output = sprintf('%02d', $TimeParts['hours']).':'.sprintf('%02d', $TimeParts['minutes']).':'.sprintf('%02d', $TimeParts['seconds']); 16 16 return($Output); 17 17 } … … 24 24 $Output = ''; 25 25 $Style = ''; 26 if(array_key_exists('Null', $Item) and $Item['Null']) 26 if(array_key_exists('Null', $Item) and $Item['Null']) 27 27 { 28 if($Item['Value'] != null) 28 if($Item['Value'] != null) 29 29 { 30 30 $Checked = ' checked="1"'; 31 31 $Style = 'style="display:inline;"'; 32 } else 32 } else 33 33 { 34 34 $Checked = ''; 35 $Style = 'style="display:none;"'; 35 $Style = 'style="display:none;"'; 36 36 } 37 37 $Output .= '<input type="checkbox" name="'.$Item['Name'].'-null"'.$Checked.' onclick="toggle(\''. 38 $Item['Name'].'-hour\');toggle(\''.$Item['Name'].'-minute\');toggle(\''.$Item['Name'].'-second\');"/>'; 38 $Item['Name'].'-hour\');toggle(\''.$Item['Name'].'-minute\');toggle(\''.$Item['Name'].'-second\');"/>'; 39 39 } 40 40 41 41 // Hour 42 42 $Output .= '<select name="'.$Item['Name'].'-hour" id="'.$Item['Name'].'-hour" '.$Style.'>'; … … 68 68 function OnLoad($Item) 69 69 { 70 if(!array_key_exists($Item['Name'].'-null', $_POST) and array_key_exists('Null', $Item) and ($Item['Null'] == true)) return(null); 70 if(!array_key_exists($Item['Name'].'-null', $_POST) and array_key_exists('Null', $Item) and ($Item['Null'] == true)) return(null); 71 71 return(mktime($_POST[$Item['Name'].'-hour'], $_POST[$Item['Name'].'-minute'], $_POST[$Item['Name'].'-second'])); 72 72 } -
trunk/Common/Form/Types/Type.php
r623 r659 24 24 include(dirname(__FILE__).'/MacAddress.php'); 25 25 include(dirname(__FILE__).'/Image.php'); 26 include(dirname(__FILE__).'/TimeDiff.php'); 26 27 27 28 class Type … … 58 59 'IPv6Address' => array('Name' => 'IPv6Address', 'Class' => 'IPv6Address', 'ParentType' => '', 'Parameters' => array()), 59 60 'Image' => array('Name' => 'Image', 'Class' => 'Image', 'ParentType' => '', 'Parameters' => array()), 61 'TimeDiff' => array('Name' => 'TimeDiff', 'Class' => 'TimeDiff', 'ParentType' => 'Integer', 'Parameters' => array()), 60 62 ); 61 63 } … … 72 74 } else return($TypeName); 73 75 } 74 76 75 77 function IsHidden($TypeName) 76 78 { … … 90 92 $Type = $this->TypeDefinitionList[$ParentType]; 91 93 } else $Type = array(); 92 94 93 95 $Type['Name'] = $Name; 94 96 $Type['Class'] = $Name; … … 104 106 // TODO: remove dependent types 105 107 } 106 108 107 109 function GetTypeDefinition($TypeName) 108 110 { -
trunk/Common/Global.php
r655 r659 346 346 function GetRemoteAddress() 347 347 { 348 if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'] ; 349 else if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR']; 348 if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR']; 350 349 else $IP = '0.0.0.0'; 351 350 return($IP);
Note:
See TracChangeset
for help on using the changeset viewer.