Changeset 502
- Timestamp:
- Mar 12, 2013, 10:58:10 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 11 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 } -
trunk/Common/Version.php
r501 r502 1 1 <?php 2 2 3 $Revision = 50 1; // Subversion revision4 $DatabaseRevision = 50 1;3 $Revision = 502; // Subversion revision 4 $DatabaseRevision = 502; 5 5 $ReleaseTime = '2013-03-10'; 6 6 -
trunk/Modules/FinanceBankAPI/FileImport.php
r501 r502 3 3 include_once(dirname(__FILE__).'/../../Common/Global.php'); 4 4 5 class PageFileImport extends Page5 class FileImport 6 6 { 7 var $FullTitle = 'Import plateb'; 8 var $ShortTitle = 'Import plateb'; 7 var $Database; 8 var $BankAccountId; 9 10 function __construct($Database) 11 { 12 $this->Database = &$Database; 13 } 14 15 function Import() 16 { 17 } 18 19 function ImportFile($Content, $Ext) 20 { 21 } 22 } 23 24 class PageImportAPI extends Page 25 { 26 var $FullTitle = 'Import plateb přes API'; 27 var $ShortTitle = 'Import plateb přes API'; 28 29 function Show() 30 { 31 if(!$this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění'); 32 33 $DbResult = $this->Database->select('FinanceBankAccount', '*', 'Id='.$_GET['id']); 34 $BankAccount = $DbResult->fetch_assoc(); 35 36 $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']); 37 $Bank = $DbResult->fetch_assoc(); 38 $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'; 39 40 if($Bank['Code'] == '2010') $Import = new ImportFio($this->Database); 41 else if($Bank['Code'] == '0300') $Import = new ImportPS($this->Database); 42 else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován'); 43 $Import->BankAccountId = $BankAccount['Id']; 44 $Output .= $Import->Import(); 45 46 return($Output); 47 } 48 } 49 50 class PageImportFile extends Page 51 { 52 var $FullTitle = 'Import plateb ze souboru'; 53 var $ShortTitle = 'Import plateb ze souboru'; 9 54 10 55 function Show() … … 23 68 function ShowForm() 24 69 { 25 $FormImport = new Form('ImportBankFile'); 26 $FormImport->OnSubmit = '?Operation=prepare'; 27 $Output = $FormImport->ShowEditForm(); 70 $Form = new Form($this->System->FormManager); 71 $Form->SetClass('ImportBankFile'); 72 $Form->OnSubmit = '?Operation=prepare'; 73 $Form->Values['BankAccount'] = $_GET['id']; 74 $Output = $Form->ShowEditForm(); 28 75 return($Output); 29 76 } … … 31 78 function Prepare() 32 79 { 33 $FormImport = new Form('ImportBankFile'); 34 $FormImport->LoadValuesFromForm(); 35 $Output = $FormImport->ShowEditForm(); 80 $Form = new Form($this->System->FormManager); 81 $Form->SetClass('ImportBankFile'); 82 $Form->LoadValuesFromForm(); 83 $File = $Form->Values['File']; 84 $Output = $File->Name.'<br/>'; 85 $Output .= $File->GetFullName().'<br/>'; 86 87 $DbResult = $this->Database->select('FinanceBankAccount', '*', 'Id='.$Form->Values['BankAccount']); 88 $BankAccount = $DbResult->fetch_assoc(); 36 89 37 $ Finance = $this->System->Modules['Finance'];38 $ Output = $FormImport->Values['File'];39 return($Output);90 $DbResult = $this->Database->select('FinanceBank', '*', 'Id='.$BankAccount['Bank']); 91 $Bank = $DbResult->fetch_assoc(); 92 $Output .= 'Účet: '.$BankAccount['Number'].'/'.$Bank['Code'].' ('.$Bank['Name'].')'; 40 93 41 $Data = $FormImport->Values['File']; 42 foreach($Data as $Key => $Value) 43 { 44 $Value = str_replace('\"', '"', $Value); 45 $Data[$Key] = str_getcsv($Value, ',', '"', "\\"); 46 //print_r($Data[$Key]); 47 foreach($Data[$Key] as $Key2 => $Value2) 48 { 49 if(substr($Data[$Key][$Key2], 0, 2) == '\"') 50 $Data[$Key][$Key2] = substr($Data[$Key][$Key2], 2, -2); 51 } 52 } 53 $Header = array( 54 0 => 'datum zaúčtování', 55 1 => 'částka', 56 2 => 'měna', 57 3 => 'zůstatek', 58 4 => 'konstantní symbol', 59 5 => 'variabilní symbol', 60 6 => 'specifický symbol', 61 7 => 'označení operace', 62 8 => 'název protiúčtu', 63 9 => 'protiúčet', 64 10 => 'poznámka', 65 11 => '', 66 ); 67 //print_r($Header); 68 //print_r($Data[0]); 69 //print_r($_POST['Source']); 70 //print_r($Data); 71 72 if($Header != $Data[0]) $Output = 'Nekompatibilní struktura CSV'; 73 else 74 { 75 array_shift($Data); 76 $Automatic = ''; 77 $Manual = ''; 78 $Output = '<form action="?Operation=insert" method="post">'; 79 $I = 0; 80 foreach($Data as $Key => $Value) 81 { 82 if(count($Value) <= 1) continue; 83 if($Value[9] == '') $Value[5] = 128; // Žádný účet => Poštovní spořitelna 84 $Time = explode('.', $Value[0]); 85 $Time = $Time[2].'-'.$Time[1].'-'.$Time[0]; 86 $Money = $Value[1]; 87 if(is_numeric($Value[5])) 88 { 89 $Subject = $Value[5] * 1; 90 $DbResult = $this->Database->query('SELECT Id FROM Subject WHERE Id='.$this->Database->real_escape_string($Subject)); 91 if($DbResult->num_rows == 0) $Subject = '? ('.($Value[5] * 1).')'; 92 } else 93 { 94 $Subject = '? ('.$Value[5].')'; 95 } 96 if(!is_numeric($Subject)) 97 { 98 $Mode = 'Ručně'; 99 $Style = 'style="background-color: LightPink;" '; 100 } else 101 { 102 $Mode = 'Automaticky'; 103 $Style = ''; 104 } 105 106 if($Money < 0) $Text = 'Platba převodem'; 107 else $Text = 'Přijatá platba'; 108 $Automatic .= '<tr>'. 109 //'<td>'.$Mode.'</td>'. 110 '<td><input type="text" name="Date'.$I.'" value="'.$Time.'"/></td>'. 111 '<td><input type="text" '.$Style.'name="Subject'.$I.'" value="'.$Subject.'"/></td>'. 112 '<td>'.$Value[8].'</td>'. 113 '<td><input type="text" name="Money'.$I.'" value="'.$Money.'"/></td>'. 114 '<td><input type="text" name="Text'.$I.'" value="'.$Text.'"/></td>'. 115 '<td><input type="text" name="Taxable'.$I.'" value="1"/></td>'. 116 '<td><input type="text" name="Network'.$I.'" value="1"/></td>'. 117 '</tr><tr><td colspan="7">'.implode(', ', $Value).'</td></tr>'; 118 $I++; 119 } 120 $Output .= '<table class="WideTable">'. 121 '<tr>'. 122 //'<th>Zpracování</th>'. 123 '<th>Datum</th><th>Var. symbol</th><th>Protiúčet</th><th>Částka [Kč]</th><th>Text</th><th>Zdanitelné</th><th>Síť</th></tr>'; 124 $Output .= $Automatic.'</table>'; 125 $Output .= '<input type="hidden" name="ItemCount" value="'.$I.'"/>'; 126 $Output .= '<input type="submit" value="Zpracovat"/></form>'; 127 } 94 if($Bank['Code'] == '2010') $Import = new ImportFio($this->Database); 95 else if($Bank['Code'] == '0300') $Import = new ImportPS($this->Database); 96 else $Output = $this->SystemMessage('Nepodporované API', 'Pro zvolenou banku není import podporován'); 97 $Import->BankAccountId = $BankAccount['Id']; 98 $Output .= $Import->ImportFile($File->GetContent(), $File->GetExt()); 99 128 100 return($Output); 129 101 } -
trunk/Modules/FinanceBankAPI/FinanceBankAPI.php
r501 r502 2 2 3 3 include_once(dirname(__FILE__).'/FileImport.php'); 4 include_once(dirname(__FILE__).'/ImportPS.php'); 5 include_once(dirname(__FILE__).'/ImportFio.php'); 4 6 5 7 class ModuleFinanceBankAPI extends AppModule … … 27 29 { 28 30 parent::Start(); 29 $this->System->RegisterPage('finance', array('import' => 'PageFileImport')); 31 $FormClass = array( 32 'Title' => 'Import souborů s platbami', 33 'Table' => 'FinanceBank', 34 'SubmitText' => 'Načíst', 35 'Items' => array( 36 'BankAccount' => array('Type' => 'TBankAccount', 'Caption' => 'Bankovní účet', 'Default' => ''), 37 'File' => array('Type' => 'File', 'Caption' => 'Soubor', 'Default' => ''), 38 ), 39 ); 40 $this->System->FormManager->RegisterClass('ImportBankFile', $FormClass); 41 $this->System->RegisterPage('finance', array('import-api' => 'PageImportAPI', 42 'import-soubor' => 'PageImportFile')); 30 43 } 31 44 -
trunk/Modules/IS/IS.php
r501 r502 167 167 168 168 foreach($FormClass['Items'] as $ItemIndex => $FormItem) 169 if(!array_key_exists($FormItem['Type'], $this->System->FormManager-> Type) or169 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or 170 170 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and 171 171 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) 172 { 172 173 $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']); 174 } 173 175 $TableColumns[] = array('Name' => '', 'Title' => 'Akce'); 174 176 if(!array_key_exists('DefaultSortColumn', $FormClass)) -
trunk/admin/Updates.php
r500 r502 142 142 } 143 143 144 function UpdateTo502($Manager) 145 { 146 $Manager->Execute("ALTER TABLE `FinanceBankAccount` ADD `LoginName` VARCHAR( 255 ) NOT NULL "); 147 $Manager->Execute("ALTER TABLE `FinanceBankAccount` ADD `LoginPassword` VARCHAR( 255 ) NOT NULL"); 148 $Manager->Execute("ALTER TABLE `FinanceBankAccount` ADD `Currency` INT NOT NULL AFTER `Use` ,". 149 "ADD INDEX ( `Currency` ) "); 150 $Manager->Execute("INSERT INTO `ISMenuItem` (`Id` ,`Name` ,`Parent` ,`Table` ,`IconName`) ". 151 "VALUES (NULL , 'Banka', '2', '', '');"); 152 $Manager->Execute("UPDATE `ISMenuItem` SET `Parent` = '51' WHERE `ISMenuItem`.`Id` =10; ". 153 "UPDATE `ISMenuItem` SET `Parent` = '51' WHERE `ISMenuItem`.`Id` =48;". 154 "UPDATE `ISMenuItem` SET `Parent` = '51' WHERE `ISMenuItem`.`Id` =50;"); 155 } 156 144 157 $Updates = array( 145 158 491 => array('Revision' => 493, 'Function' => 'UpdateTo493'), … … 150 163 498 => array('Revision' => 499, 'Function' => 'UpdateTo499'), 151 164 499 => array('Revision' => 500, 'Function' => 'UpdateTo500'), 165 500 => array('Revision' => 502, 'Function' => 'UpdateTo502'), 152 166 ); 153 167 -
trunk/form_classes.php
r501 r502 19 19 { 20 20 $FormManager->Classes = array( 21 'ImportBankFile' => array(22 'Title' => 'Import souborů s platbami',23 'Table' => 'FinanceBank',24 'SubmitText' => 'Načíst',25 'Items' => array(26 'BankAccount' => array('Type' => 'TBankAccount', 'Caption' => 'Bankovní účet', 'Default' => ''),27 'File' => array('Type' => 'File', 'Caption' => 'Soubor', 'Default' => ''),28 )29 ),30 21 'FinanceBank' => array( 31 22 'Title' => 'Banky', … … 493 484 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''), 494 485 'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => ''), 486 'Currency' => array('Type' => 'TCurrency', 'Caption' => 'Měna', 'Default' => ''), 487 'LoginName' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno / token', 'Default' => ''), 488 'LoginPassword' => array('Type' => 'String', 'Caption' => 'Přihlašovací heslo', 'Default' => ''), 495 489 'Operations' => array('Type' => 'TFinanceOperationListAccount', 'Caption' => 'Operace', 'Default' => ''), 490 ), 491 'ItemActions' => array( 492 array('Caption' => 'Import plateb z banky', 'URL' => '/finance/import-api/?'), 493 array('Caption' => 'Import plateb ze souboru', 'URL' => '/finance/import-soubor/?'), 496 494 ), 497 495 ), … … 931 929 'Table' => 'FinanceBankAccount', 932 930 'Id' => 'Id', 933 'Name' => 'CONCAT(Comment, " (", Number, ")")', 931 'Name' => 'CONCAT(`Comment`, " (", `Number`, "/", '. 932 '(SELECT `FinanceBank`.`Code` FROM `FinanceBank` WHERE `FinanceBank`.`Id`=`FinanceBankAccount`.`Bank`), ")")', 934 933 'Filter' => '1', 935 934 ),
Note:
See TracChangeset
for help on using the changeset viewer.