Changeset 502 for trunk/Common/Form
- Timestamp:
- Mar 12, 2013, 10:58:10 PM (12 years ago)
- Location:
- trunk/Common/Form
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Form/Form.php
r501 r502 83 83 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 84 84 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 85 ($ $this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))85 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 86 86 { 87 87 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; -
trunk/Common/Form/Types/File.php
r501 r502 1 1 <?php 2 3 class DbFile 4 { 5 var $Id; 6 var $FileName; 7 var $Size; 8 var $Directory; 9 var $DirectoryId; 10 var $TempName; 11 12 function DetectMimeType() 13 { 14 // For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems 15 $FileInfo = new finfo(FILEINFO_MIME, '/usr/share/misc/magic'); 16 $Result = $FileInfo->file($FileName); 17 //$FileInfo->close(); 18 return($Result); 19 } 20 21 function GetSize($Item) 22 { 23 $FileName = $this->GetFullName($Item); 24 if(file_exists($FileName)) $Result = filesize($FileName); 25 else $Result = 0; 26 return($Result); 27 } 28 29 function GetFullName() 30 { 31 $ParentId = $this->Directory; 32 while($ParenId != null) 33 { 34 $DbResult = $this->Database->select('FileDirectory', '*', 'Id='.$ParentId); 35 $DbRow = $DbResult->fetch_assoc(); 36 $Path .= $DbRow['Name'].'/'; 37 $ParentId = $DbRow['Parent']; 38 } 39 $Result = $this->UploadFileFolder.'/'.$Path.$File->Name; 40 return($Result); 41 } 42 43 function GetExt() 44 { 45 return(substr($this->Name, 0, strpos($this->Name, '.') - 1)); 46 } 47 48 function Delete() 49 { 50 if(file_exists($this->GetFullName())) unlink($this->GetFullName()); 51 } 52 53 function GetContent() 54 { 55 if($this->TempName != '') $Content = file_get_contents($this->TempName); 56 else $Content = file_get_contents($this->GetFullName()); 57 return($Content); 58 } 59 } 2 60 3 61 class TypeFile extends TypeBase … … 7 65 var $DirectoryId; 8 66 9 function __construct( )67 function __construct($FormManager) 10 68 { 69 parent::__construct($FormManager); 11 70 $this->FileDownloadURL = 'File.php'; 12 71 $this->DirectoryId = null; … … 15 74 function OnView($Item) 16 75 { 17 global $Database; 18 19 $DbResult = $Database->query('SELECT `Name`, `Size` FROM `SystemFile` WHERE `Id`='.$Item['Value']); 20 if($DbResult->num_rows > 0) 21 { 22 $DbRow = $DbResult->fetch_assoc(); 23 return('<a href="'.$this->FileDownloadURL.'?Id='.$Item['Value'].'">'.$DbRow['Name'].'</a> ('.HumanSize($DbRow['Size']).')'); 24 } else return(''); 76 $File = &$Item['Value']; 77 return('<a href="'.$this->FileDownloadURL.'?Id='.$File->Id.'">'. 78 $File.'</a> ('.HumanSize($File->Size).')'); 25 79 } 26 80 … … 30 84 // ini_set("upload_max_filesize", "100M"); 31 85 // <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> 32 $Output = '<input type="file" name="'.$Item['Name'].'" value="">'; 86 $File = &$Item['Value']; 87 $Output = '<input type="file" name="'.$Item['Name'].'" value="'.$File->Name.'">'; 33 88 return($Output); 34 89 } … … 36 91 function OnLoad($Item) 37 92 { 38 global $Database, $Config; 39 40 $Result = 0; 41 print_r($_FILES); 42 print_r($_POST); 93 if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); 94 $File = &$Item['Value']; 43 95 if(array_key_exists($Item['Name'], $_FILES) and ($_FILES[$Item['Name']]['name'] != '')) 44 96 { 45 if(file_exists($_FILES[$Item['Name']]['tmp_name'])) 97 $UploadFile = $_FILES[$Item['Name']]; 98 if(file_exists($UploadFile['tmp_name'])) 46 99 { 47 $FileName = substr($_FILES[$Item['Name']]['name'], strrpos($_FILES[$Item['Name']]['name'], '/')); 48 $Database->insert('File', array('Name' => $FileName, 'Size' => filesize($_FILES[$Item['Name']]['tmp_name']), 49 'Directory' => $this->DirectoryId)); 50 $Result = $Database->insert_id; 51 if(!move_uploaded_file($_FILES[$Item['Name']]['tmp_name'], $this->UploadFileFolder.'/'.$Result)) 52 SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!'); 100 $File->Name = $UploadFile['name']; 101 $File->Size = $UploadFile['size']; 102 $File->TempName = $UploadFile['tmp_name']; 53 103 } 54 104 } 55 return($ Result);105 return($File); 56 106 } 107 108 function OnLoadDb($Item) 109 { 110 if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); 111 $File = &$Item['Value']; 112 $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); 113 if($DbResult->num_rows() > 0) 114 { 115 $DbRow = $DbResult->fetch_assoc(); 116 $File->Name = $DbRow['Name']; 117 $File->Size = $DbRow['Size']; 118 $File->Directory = $DbRow['Directory']; 119 } 120 return($File); 121 } 122 123 function OnSaveDb($Item) 124 { 125 if(!is_object($Item['Value'])) $Item['Value'] = new DbFile(); 126 $File = &$Item['Value']; 127 $Properties = array('Name' => $File->Name, 128 'Size' => $File->GetSize(), 'Directory' => $File->Directory); 129 $DbResult = $this->Database->select('File', '*', 'Id='.$File->Id); 130 if($DbResult->num_rows() > 0) 131 { 132 $DbRow = $DbResult->fetch_assoc(); 133 if($File->TempName != '') 134 { 135 $FileName = $File->GetFullName(); 136 unlink($FileName); 137 } 138 $this->Database->update('File', 'Id='.$File->Id, $Properties); 139 } else 140 { 141 $this->Database->insert('File', $Properties); 142 $File->Id = $this->Database->insert_id; 143 } 144 if(!move_uploaded_file($File->TempName, $FileName)) 145 SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!'); 146 } 147 57 148 } 58 149 -
trunk/Common/Form/Types/File/FileDownload.php
r428 r502 1 1 <?php 2 2 3 // For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems4 function DetectMimeType($FileName)5 {6 $FileInfo = new finfo(FILEINFO_MIME, '/usr/share/misc/magic');7 $Result = $FileInfo->file($FileName);8 //$FileInfo->close();9 return($Result);10 }11 3 12 4 chdir('../..'); -
trunk/Common/Form/Types/OneToMany.php
r501 r502 7 7 function OnView($Item) 8 8 { 9 $Type = $this-> System->Type->TypeDefinitionList[$Item['Type']];9 $Type = $this->FormManager->Type->TypeDefinitionList[$Item['Type']]; 10 10 if($Item['Value'] != '') 11 11 { 12 12 if(array_key_exists('View', $Type['Parameters'])) $Table = $Type['Parameters']['View']; 13 13 else $Table = $Type['Parameters']['Table']; 14 $DbResult = $this-> System->Database->query('SELECT '.$Type['Parameters']['Name'].14 $DbResult = $this->Database->query('SELECT '.$Type['Parameters']['Name']. 15 15 ' AS `Name` FROM '.$Table.' WHERE `'. 16 16 $Type['Parameters']['Id'].'`='.$Item['Value']); -
trunk/Common/Form/Types/Type.php
r501 r502 17 17 include(dirname(__FILE__).'/Hidden.php'); 18 18 include(dirname(__FILE__).'/File.php'); 19 include(dirname(__FILE__).'/FileContent.php');20 19 include(dirname(__FILE__).'/GPS.php'); 21 20 include(dirname(__FILE__).'/IPv4Address.php'); … … 53 52 'Color' => array('Name' => 'Color', 'Class' => 'Color', 'ParentType' => '', 'Parameters' => array()), 54 53 'RandomHash' => array('Name' => 'RandomHash', 'Class' => 'RandomHash', 'ParentType' => '', 'Parameters' => array()), 55 'FileContent' => array('Name' => 'FileContent', 'Class' => 'FileContent', 'ParentType' => '', 'Parameters' => array()),56 54 ); 57 55 }
Note:
See TracChangeset
for help on using the changeset viewer.