TimeTrex/interface/send_file.php

529 lines
43 KiB
PHP
Raw Permalink Normal View History

2022-12-13 07:10:06 +01:00
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
if ( isset( $_GET['disable_db'] ) && $_GET['disable_db'] == 1 ) {
$disable_database_connection = true;
}
require_once( '../includes/global.inc.php' );
require_once( 'PEAR.php' );
require_once( 'HTTP/Download.php' );
extract( FormVariables::GetVariables(
[
'action',
'api', //Called from JS
'object_type',
'parent_object_type_id',
'object_id',
'parent_id',
'mode',
] ) );
function getSendFileDownloadMode( $mode, $default_mode = null ) {
$mode = trim( strtolower( (string)$mode ) );
if ( $mode == '' && $default_mode != '' ) {
return $default_mode;
}
if ( $mode == 'inline' ) {
return HTTP_DOWNLOAD_INLINE;
} elseif ( $mode == 'download' ) {
return HTTP_DOWNLOAD_ATTACHMENT;
}
return HTTP_DOWNLOAD_ATTACHMENT;
}
//sendFormIFrameCall (js) passes json data
//Make sure we accept it here GovernmentDocument uses this
if ( isset( $_POST['json'] ) && $_POST['json'] != '' ) {
$json_arguments = json_decode( $_POST['json'], true );
if ( isset( $json_arguments['object_id'] ) ) {
Debug::Text( 'JSON overriding object_id...', __FILE__, __LINE__, __METHOD__, 10 );
$object_id = $json_arguments['object_id'];
}
}
if ( isset( $api ) && $api == true ) {
require_once( '../includes/API.inc.php' );
}
$object_type = strtolower( $object_type );
if ( !in_array( $object_type, [ 'primary_company_logo', 'company_logo', 'legal_entity_logo', 'invoice_config', 'copyright', 'smcopyright', 'copyright_wide' ] ) ) {
$skip_message_check = true;
require_once( Environment::getBasePath() . 'includes/Interface.inc.php' );
if ( $authentication->checkValidCSRFToken() == false ) { //Help prevent CSRF attacks with this, run this check during and before the user is logged in.
echo TTi18n::getText( 'Invalid CSRF token!' );
//Debug::writeToLog(); //Handled in TTShutdown now.
exit;
}
} elseif ( in_array( $object_type, [ 'company_logo', 'invoice_config' ] ) ) { //These require $current_user or $current_company variables to exist.
require_once( Environment::getBasePath() . 'includes/Interface.inc.php' );
}
switch ( $object_type ) {
case 'document':
Debug::Text( 'Document...', __FILE__, __LINE__, __METHOD__, 10 );
//RateLimit failed download attempts to prevent brute force.
$rl = TTNew( 'RateLimit' ); /** @var RateLimit $rl */
$rl->setID( 'document_' . Misc::getRemoteIPAddress() );
$rl->setAllowedCalls( 25 );
$rl->setTimeFrame( 900 ); //15 minutes
if ( $rl->check() == false ) {
Debug::Text( 'Excessive document download attempts... Preventing downloads from: ' . Misc::getRemoteIPAddress() . ' for up to 15 minutes...', __FILE__, __LINE__, __METHOD__, 10 );
sleep( 5 ); //Excessive download attempts, sleep longer.
} else {
if ( ( $permission->Check( 'document', 'view' ) || $permission->Check( 'document', 'view_own' ) || $permission->Check( 'document', 'view_child' ) || $permission->Check( 'document', 'view_private' ) )
|| ( isset( $parent_object_type_id ) && $parent_object_type_id == 400 //400=Expense
&& ( $permission->Check( 'expense', 'view_own' ) || $permission->Check( 'expense', 'view_child' ) || $permission->Check( 'expense', 'view' ) ) )
) {
$filter_data = [ 'filter_data' => [ 'id' => $parent_id, 'filter_items_per_page' => 1, 'filter_columns' => [ 'id' => true ] ] ];
//Don't need to pass in object_type_id filter anymore as APIDocument->getDocument() now grabs the object_type and does its own permission checks there.
//if ( isset( $parent_object_type_id ) && $parent_object_type_id != '' ) {
// $filter_data['filter_data']['object_type_id'] = $parent_object_type_id;
//}
//Make sure user has access to this document first, before checking for any revisions.
$api_f = TTNew( 'APIDocument' ); /** @var APIDocument $api_f */
$result = $api_f->stripReturnHandler( $api_f->getDocument( $filter_data ) );
if ( isset( $result[0] ) && count( $result[0] ) > 0 ) {
$document_id = TTUUID::castUUID( $result[0]['id'] );
// The attached documents to expenses all be marked as 'Private', and the regular employee no have the 'view_private' permission, so need to set the view_private to TRUE.
if ( isset( $parent_object_type_id ) && $parent_object_type_id == 400 ) {
$private_allowed = true;
} else {
$private_allowed = $permission->Check( 'document', 'view_private' );
}
$drlf = TTnew( 'DocumentRevisionListFactory' ); /** @var DocumentRevisionListFactory $drlf */
$drlf->getByCompanyIdAndIdAndDocumentIdAndPrivateAllowed( $current_company->getId(), $object_id, $document_id, $private_allowed );
Debug::Text( 'Record Count: ' . $drlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10 );
if ( $drlf->getRecordCount() == 1 ) {
$dr_obj = $drlf->getCurrent();
$file_name = $dr_obj->getStoragePath() . $dr_obj->getLocalFileName();
Debug::Text( 'File Name: ' . $file_name . ' Mime: ' . $dr_obj->getMimeType(), __FILE__, __LINE__, __METHOD__, 10 );
if ( file_exists( $file_name ) ) {
$rl->delete(); //Clear download rate limit upon successful download.
//Log document downloads in audit report, just so people can see who has viewed which revision.
//Make sure we link this to the main document_id so its viewed in the main document audit tab.
TTLog::addEntry( $document_id, 5, TTi18n::getText( 'Downloaded Revision: %1', [ $dr_obj->getRevision() ] ), null, $dr_obj->getTable(), $dr_obj );
$params['file'] = $file_name;
$params['ContentType'] = $dr_obj->getMimeType();
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_ATTACHMENT ), basename( $dr_obj->getRemoteFileName() ) ];
$params['cache'] = false;
} else {
Debug::Text( 'File does not exist... File Name: ' . $file_name . ' Mime: ' . $dr_obj->getMimeType(), __FILE__, __LINE__, __METHOD__, 10 );
}
} else {
Debug::text( 'Document Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
} else {
Debug::text( 'ERROR: User does not have access to document! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
} else {
Debug::text( 'Permissions failed!', __FILE__, __LINE__, __METHOD__, 10 );
}
}
//Debug::writeToLog(); //Write to log when downloading documents. //Handled in TTShutdown now.
break;
case 'client_payment_signature':
Debug::Text( 'Client Payment Signature...', __FILE__, __LINE__, __METHOD__, 10 );
//RateLimit failed download attempts to prevent brute force.
$rl = TTNew( 'RateLimit' ); /** @var RateLimit $rl */
$rl->setID( 'document_' . Misc::getRemoteIPAddress() );
$rl->setAllowedCalls( 25 );
$rl->setTimeFrame( 900 ); //15 minutes
if ( $rl->check() == false ) {
Debug::Text( 'Excessive document download attempts... Preventing downloads from: ' . Misc::getRemoteIPAddress() . ' for up to 15 minutes...', __FILE__, __LINE__, __METHOD__, 10 );
sleep( 5 ); //Excessive download attempts, sleep longer.
} else {
$cplf = TTnew( 'ClientPaymentListFactory' ); /** @var ClientPaymentListFactory $cplf */
$cplf->getByIdAndClientId( $object_id, $parent_id );
if ( $cplf->getRecordCount() == 1 ) {
//echo "File Name: $file_name<br>\n";
$cp_obj = $cplf->getCurrent();
$file_name = $cp_obj->getSignatureFileName();
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( file_exists( $file_name ) ) {
$rl->delete(); //Clear download rate limit upon successful download.
$params['file'] = $file_name;
$params['ContentType'] = 'image/png';
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_ATTACHMENT ), 'signature.png' ];
$params['cache'] = false;
} else {
Debug::text( 'Document Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
}
}
break;
case 'invoice_config':
Debug::Text( 'Invoice Config...', __FILE__, __LINE__, __METHOD__, 10 );
if ( isset( $current_company ) && is_object( $current_company ) ) {
$icf = TTNew( 'InvoiceConfigFactory' ); /** @var InvoiceConfigFactory $icf */
$file_name = $icf->getLogoFileName( $current_company->getId() );
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( file_exists( $file_name ) ) {
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
}
} else {
Debug::Text( 'WARNING: current_company object does not exist! Interface.inc.php not included or user is not logged in...', __FILE__, __LINE__, __METHOD__, 10 );
}
break;
case 'company_logo':
Debug::Text( 'Company Logo...', __FILE__, __LINE__, __METHOD__, 10 );
header_remove( 'Expires' ); //Allow caching.
if ( isset( $current_company ) && is_object( $current_company ) ) {
$cf = TTnew( 'CompanyFactory' ); /** @var CompanyFactory $cf */
$file_name = $cf->getLogoFileName( $current_company->getId() );
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
}
} else {
Debug::Text( 'WARNING: current_company object does not exist! Interface.inc.php not included or user is not logged in...', __FILE__, __LINE__, __METHOD__, 10 );
}
break;
case 'legal_entity_logo':
Debug::Text( 'Legal Entity Logo [' . $object_id . ']...', __FILE__, __LINE__, __METHOD__, 10 );
header_remove( 'Expires' ); //Allow caching.
$lef = TTnew( 'LegalEntityFactory' ); /** @var LegalEntityFactory $lef */
$file_name = $lef->getLogoFileName( $object_id );
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
}
break;
case 'primary_company_logo':
Debug::Text( 'Primary Company Logo...', __FILE__, __LINE__, __METHOD__, 10 );
header_remove( 'Expires' ); //Allow caching.
$cf = TTnew( 'CompanyFactory' ); /** @var CompanyFactory $cf */
$file_name = $cf->getLogoFileName( PRIMARY_COMPANY_ID, true, true );
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
}
break;
case 'user_photo':
Debug::Text( 'User Photo...', __FILE__, __LINE__, __METHOD__, 10 );
//RateLimit failed download attempts to prevent brute force.
$rl = TTNew( 'RateLimit' ); /** @var RateLimit $rl */
$rl->setID( 'user_photo_' . Misc::getRemoteIPAddress() );
$rl->setAllowedCalls( 25 );
$rl->setTimeFrame( 900 ); //15 minutes
if ( $rl->check() == false ) {
Debug::Text( 'Excessive document download attempts... Preventing downloads from: ' . Misc::getRemoteIPAddress() . ' for up to 15 minutes...', __FILE__, __LINE__, __METHOD__, 10 );
sleep( 5 ); //Excessive download attempts, sleep longer.
} else {
if ( $permission->Check( 'user', 'view' )
|| $permission->Check( 'user', 'view_own' )
|| $permission->Check( 'user', 'view_child' ) ) {
$api_f = TTNew( 'APIUser' ); /** @var APIUser $api_f */
$result = $api_f->stripReturnHandler( $api_f->getUser( [ 'filter_data' => [ 'id' => $object_id ], 'filter_columns' => [ 'id' => true ] ] ) );
if ( isset( $result[0] ) && count( $result[0] ) > 0 ) {
$uf = TTnew( 'UserFactory' ); /** @var UserFactory $uf */
$file_name = $uf->getPhotoFileName( $current_company->getId(), $object_id );
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$rl->delete(); //Clear download rate limit upon successful download.
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
} else {
Debug::text( 'aPhoto Download Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
} else {
Debug::text( 'bPhoto Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
}
}
break;
case 'remittance_source_account':
Debug::Text( 'Remittance Source Account Signature...', __FILE__, __LINE__, __METHOD__, 10 );
//RateLimit failed download attempts to prevent brute force.
$rl = TTNew( 'RateLimit' ); /** @var RateLimit $rl */
$rl->setID( 'remittance_source_account_' . Misc::getRemoteIPAddress() );
$rl->setAllowedCalls( 25 );
$rl->setTimeFrame( 900 ); //15 minutes
if ( $rl->check() == false ) {
Debug::Text( 'Excessive document download attempts... Preventing downloads from: ' . Misc::getRemoteIPAddress() . ' for up to 15 minutes...', __FILE__, __LINE__, __METHOD__, 10 );
sleep( 5 ); //Excessive download attempts, sleep longer.
} else {
if ( $permission->Check( 'remittance_source_account', 'view' )
|| $permission->Check( 'remittance_source_account', 'view_own' )
|| $permission->Check( 'remittance_source_account', 'view_child' ) ) {
$api_f = TTNew( 'APIRemittanceSourceAccount' ); /** @var APIRemittanceSourceAccount $api_f */
$result = $api_f->stripReturnHandler( $api_f->getRemittanceSourceAccount( [ 'filter_data' => [ 'id' => $object_id ] ] ) );
if ( isset( $result[0] ) && count( $result[0] ) > 0 ) {
$rsaf = TTnew( 'RemittanceSourceAccountFactory' ); /** @var RemittanceSourceAccountFactory $rsaf */
$file_name = $rsaf->getSignatureFileName( $current_company->getId(), $object_id );
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$rl->delete(); //Clear download rate limit upon successful download.
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
} else {
Debug::text( 'aSignature Download Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
} else {
Debug::text( 'bSignature Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
}
}
break;
case 'government_document':
Debug::Text( 'Government Document...', __FILE__, __LINE__, __METHOD__, 10 );
//RateLimit failed download attempts to prevent brute force.
$rl = TTNew( 'RateLimit' ); /** @var RateLimit $rl */
$rl->setID( 'document_' . Misc::getRemoteIPAddress() );
$rl->setAllowedCalls( 25 );
$rl->setTimeFrame( 900 ); //15 minutes
if ( $rl->check() == false ) {
Debug::Text( 'Excessive document download attempts... Preventing downloads from: ' . Misc::getRemoteIPAddress() . ' for up to 15 minutes...', __FILE__, __LINE__, __METHOD__, 10 );
sleep( 5 ); //Excessive download attempts, sleep longer.
} else {
if ( $permission->Check( 'government_document', 'view' )
|| $permission->Check( 'government_document', 'view_own' )
|| $permission->Check( 'government_document', 'view_child' ) ) {
$api_f = TTNew( 'APIGovernmentDocument' ); /** @var APIGovernmentDocument $api_f */
$result = $api_f->stripReturnHandler( $api_f->getGovernmentDocument( [ 'filter_data' => [ 'id' => $object_id ] ] ) );
if ( isset( $result ) && is_array( $result ) && count( $result ) > 0 ) {
$rl->delete(); //Clear download rate limit upon successful download.
$files = [];
foreach ( $result as $doc ) {
$gf = TTnew( 'GovernmentDocumentFactory' ); /** @var GovernmentDocumentFactory $gf */
$file_name = $gf->getFileName( $current_company->getId(), $doc['type_id'], $doc['user_id'], $doc['id'] );
if ( $file_name != '' && file_exists( $file_name ) ) {
//Mark notifications as read if the currently logged in user is viewing their own documents one at a time.
if ( count( $result ) == 1 ) {
global $current_user;
if ( is_object( $current_user ) && $current_user->getId() == $doc['user_id'] ) {
NotificationFactory::updateStatusByObjectIdAndObjectTypeId( 60, $doc['id'], $current_user->getId() ); //60=GovernmentDocument, Mark any notifications linked to these exceptions as read.
}
}
$file = [];
$file['file_name'] = $doc['type'] . '_' . TTDate::getYear( TTDate::parseDateTime( $doc['date'] ) ) . '_' . $gf->Validator->stripNonAlphaNumeric( $doc['last_name'] ) . '_' . $gf->Validator->stripNonAlphaNumeric( $doc['first_name'] ) . '.pdf';
$file['data'] = file_get_contents( $file_name );
$file['mime_type'] = 'application/pdf';
$files[] = $file;
}
}
if ( count( $files ) > 0 ) {
$zip_file = Misc::zip( $files, false, true );
$zip_file_name = 'government_documents.zip';
if ( count( $files ) == 1 ) {
$zip_file_name = $zip_file['file_name'];
}
Misc::APIFileDownload( $zip_file_name, $zip_file['mime_type'], $zip_file['data'] );
} else {
Debug::text( 'ERROR: No file to download! File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
}
//Debug::writeToLog(); //Handled in TTShutdown now.
die();
} else {
Debug::text( 'bDocument Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
}
}
break;
case 'punch_image':
Debug::Text( 'Punch Image...', __FILE__, __LINE__, __METHOD__, 10 );
//RateLimit failed download attempts to prevent brute force.
$rl = TTNew( 'RateLimit' ); /** @var RateLimit $rl */
$rl->setID( 'punch_image_' . Misc::getRemoteIPAddress() );
$rl->setAllowedCalls( 25 );
$rl->setTimeFrame( 900 ); //15 minutes
if ( $rl->check() == false ) {
Debug::Text( 'Excessive document download attempts... Preventing downloads from: ' . Misc::getRemoteIPAddress() . ' for up to 15 minutes...', __FILE__, __LINE__, __METHOD__, 10 );
sleep( 5 ); //Excessive download attempts, sleep longer.
} else {
if ( $permission->Check( 'punch', 'view' )
|| $permission->Check( 'punch', 'view_own' )
|| $permission->Check( 'punch', 'view_child' ) ) {
$api_f = TTNew( 'APIPunch' ); /** @var APIPunch $api_f */
$result = $api_f->stripReturnHandler( $api_f->getPunch( [ 'filter_data' => [ 'id' => $object_id ] ] ) );
if ( isset( $result[0] ) && count( $result[0] ) > 0 ) {
$pf = TTnew( 'PunchFactory' ); /** @var PunchFactory $pf */
$file_name = $pf->getImageFileName( $current_company->getId(), $parent_id, $object_id );
Debug::Text( 'File Name: ' . $file_name . ' Company ID: ' . $current_company->getId() . ' User ID: ' . $parent_id, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$rl->delete(); //Clear download rate limit upon successful download.
$params['file'] = $file_name;
$params['ContentType'] = Misc::getMimeType( $file_name );
//$params['ContentType'] = 'image/'. strtolower( pathinfo($file_name, PATHINFO_EXTENSION) );
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_INLINE ), basename( $file_name ) ];
$params['cache'] = true;
} else {
Debug::text( 'aPunch image Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
} else {
Debug::text( 'bPunch image Downloads Failed! Attempt: ' . $rl->getAttempts(), __FILE__, __LINE__, __METHOD__, 10 );
sleep( ( $rl->getAttempts() * 0.5 ) );
}
}
}
break;
case 'copyright':
Debug::Text( 'Copyright Logo...', __FILE__, __LINE__, __METHOD__, 10 );
header_remove( 'Expires' ); //Allow caching.
//
//REMOVING OR CHANGING THIS LOGO IS IN STRICT VIOLATION OF THE LICENSE AGREEMENT AND COPYRIGHT LAWS.
//
if ( getTTProductEdition() >= TT_PRODUCT_PROFESSIONAL ) {
$file_name = Environment::getImagesPath() . '/powered_by.jpg';
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$params['file'] = $file_name;
$params['ContentType'] = 'image/jpeg';
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_ATTACHMENT ), 'pro_copyright.jpg' ];
$params['data'] = file_get_contents( $file_name );
$params['cache'] = true;
}
} else {
$params['ContentType'] = 'image/jpeg';
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_ATTACHMENT ), 'copyright.jpg' ];
$params['data'] = base64_decode( '/9j/4AAQSkZ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ROTUdKcTW2a2uuXy3znQ9UfGs8olJkD7BJOFjHDOMWAvcvjY/ATf3hKKnD0UVjP6KK06QiGvOeDdLQwN7V47ZFeONAJnb25oKuK23sY0SC9KeQTS7gBxT8YNzqlUbJuRTMumoiB0zSWHOLblIHZoSOxQkHlEeji3un50QkKAQUNR+VGRdjphiDGMl4z4y/Vu7sv5lUKighRWW7I+OWh5doz3Rd2ZTV75p3OxqP4qtTR/qeUzScmnAKt7dOqEO+bWHXJsy5F4lJI6zWBbqJOu55AyJY3XvcH3Htp7QcV4cRHhmsDHyMBbvan+VGNCGJo8oC8q36F35dwfgNxFcnkvKwZMs55cyN5Dtrl/zZDqC9dWBSGfV9SbLe+LFW49VSf1PFNlfytx1e51h5HWiMS9U8rYybBVWWkKDWTori4n9SiX7Mqib4pB8cgUzaOUMYpju8PrYfnUGdIvdPa06Tkpo8vkfFfK5pcpWDgUn10u92doKERYg2MZi2uW2Wxmz8tNEASj4KOTMY4t2LdZY83x7j2T5Pk2YrFs3TO1c46Njb3e8oUaF+ZJIa0FxDTEZ3O4/juOdksk/bENGtH1Pd2YwaKSn2AAkkNBIO3s/wCocxd52q36ZFxUbnnByOjH9TaZ+/QcOYgstHoOj15KgyZkWj2waE3knRXNpn1w9O9TUOgZJIQj0GWp+4XH+F8T49b4K2WTlAIf5Am4gpvdMNQGOASKMago5T63Pzbg2c5bybOT5mdI+OEFvjK7QQuwRHRXglZH9CFCD0BlhvuPTnuJ1uNzae4IEpHyWFiNRl9wXuBKOqo2axiFKe
$params['cache'] = true;
}
break;
case 'copyright_wide':
case 'smcopyright':
Debug::Text( 'Copyright Logo...', __FILE__, __LINE__, __METHOD__, 10 );
header_remove( 'Expires' ); //Allow caching.
//
//REMOVING OR CHANGING THIS LOGO IS IN STRICT VIOLATION OF THE LICENSE AGREEMENT AND COPYRIGHT LAWS.
//
if ( getTTProductEdition() >= TT_PRODUCT_PROFESSIONAL ) {
$file_name = Environment::getImagesPath() . '/powered_by_wide.png';
Debug::Text( 'File Name: ' . $file_name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $file_name != '' && file_exists( $file_name ) ) {
$params['file'] = $file_name;
$params['ContentType'] = 'image/png';
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_ATTACHMENT ), 'pro_copyright_wide.png' ];
$params['data'] = file_get_contents( $file_name );
$params['cache'] = true;
}
} else {
$params['ContentType'] = 'image/png';
$params['ContentDisposition'] = [ getSendFileDownloadMode( $mode, HTTP_DOWNLOAD_ATTACHMENT ), 'copyright_wide.png' ];
$params['data'] = base64_decode( 'iVBORw0KGgoAAAANSUhEUgAAAMwAAAAiCAYAAAFkawaWAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAFftJREFUeNpi/P//PwM9ABOxCk3SZ4EoYyBNnstAPqqoqPh/8uRJIPP/mcbGRjAbJAYELk+ePAHRIHVdBw8c+L99+/b/82bPBIsZp838v2DH+f8gOqZ1LZj++PUHmIaJXXvwGqyGERZ0lZWVWB1SV1f3n5OTkxHqo/+pRv8Z/EKiGSSFeRhBfCCeDsSZQBwMxO5AdelnZqaBDb3+8A2DprwIwkfEYKALwcEHZE8jVg8yBgggRnokBhaiE0LGbIZ0o3//pfWdGLzMVRlJsgQYJ2CvtLe3r16/fn3oqVOnUBRERUUx6OrqMoL8/Q+o8uvD8wx9j978Lwq1hFn0HxSULsZKYE5HmsseIAXCLkBxlyBbTQaCCQBo+TQglQXEFp+/fj/uX7eWYV9vDLJPpkETwB5ghLsAIxyUEPYALfgETAi7gWxXoiNv9swZIFqXnIgHCCCqRzw4yTMyMhhL/GeY2ZCWsenozel+1uqM9CxpQME3kwR9u6F0EDbJMzNSu88+Z/h/cP/e6S+vHgB58P/FC+f/I3n4PwyvO3wdJL4bmu9dgFgQxIaVbEBcDlObNWHrfyQ5JSgNB+CYASVmYFoSAtLvhISEGN69e4fhQGBBw/D9+3fktOe6bNmy3cCEvhqoLxTIh4W+64ED+3fd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IFQjTElZO5vuWU/vrz702H9dnmdeCvBi0WbLMt2gkR6T6k3OhJlsqnZ1w9U
$params['cache'] = true;
}
break;
default:
break;
}
//Debug::Arr($params, 'Download Params:', __FILE__, __LINE__, __METHOD__, 10);
if ( isset( $params ) ) {
$retval = HTTP_Download::staticSend( $params );
if ( $retval !== true ) {
Debug::Arr( $params, 'Download Params:', __FILE__, __LINE__, __METHOD__, 10 );
Debug::Text( 'ERROR: Download Failed: ' . $retval->message, __FILE__, __LINE__, __METHOD__, 10 );
//Debug::writeToLog(); //Handled in TTShutdown now.
}
} else {
echo "File does not exist, unable to download!<br>\n";
//Debug::writeToLog(); //Handled in TTShutdown now.
}
?>