2012-10-18 16:05:43 +00:00
|
|
|
<?php
|
2013-06-03 18:13:38 -04:00
|
|
|
if (!isset($_SESSION['USER_LOGGED'])) {
|
2013-10-18 16:54:44 -04:00
|
|
|
if ((isset( $_POST['request'] )) && ($_POST['request'] == true)) {
|
|
|
|
|
$response = new stdclass();
|
|
|
|
|
$response->message = G::LoadTranslation('ID_LOGIN_AGAIN1');
|
|
|
|
|
$response->lostSession = true;
|
|
|
|
|
print G::json_encode( $response );
|
|
|
|
|
die();
|
|
|
|
|
} else {
|
|
|
|
|
G::SendMessageText( G::LoadTranslation('ID_LOGIN_TO_SEE_OUTPUTDOCS'), "WARNING" );
|
|
|
|
|
G::header("location: " . "/");
|
|
|
|
|
die();
|
|
|
|
|
}
|
2013-06-03 18:13:38 -04:00
|
|
|
}
|
2012-10-18 16:05:43 +00:00
|
|
|
/**
|
|
|
|
|
* cases_ShowOutputDocument.php
|
|
|
|
|
*
|
|
|
|
|
* ProcessMaker Open Source Edition
|
|
|
|
|
* Copyright (C) 2004 - 2008 Colosa Inc.23
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
2014-03-19 11:24:05 -04:00
|
|
|
*
|
2014-03-19 10:17:29 -04:00
|
|
|
* Created on 13-02-2008
|
|
|
|
|
*
|
2014-03-19 15:20:39 -04:00
|
|
|
*
|
2014-03-19 10:17:29 -04:00
|
|
|
* @author David Callizaya <davidsantos@colosa.com>
|
2012-10-18 16:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require_once ("classes/model/AppDocumentPeer.php");
|
2014-03-19 10:17:29 -04:00
|
|
|
require_once ("classes/model/OutputDocumentPeer.php");
|
2012-10-18 16:05:43 +00:00
|
|
|
|
|
|
|
|
$oAppDocument = new AppDocument();
|
2013-10-18 16:54:44 -04:00
|
|
|
$oAppDocument->Fields = $oAppDocument->load( $_GET['a'], (isset( $_GET['v'] )) ? $_GET['v'] : null );
|
2012-10-18 16:05:43 +00:00
|
|
|
|
|
|
|
|
$sAppDocUid = $oAppDocument->getAppDocUid();
|
2014-03-19 10:17:29 -04:00
|
|
|
$sDocUid = $oAppDocument->Fields['DOC_UID'];
|
|
|
|
|
|
|
|
|
|
$oOutputDocument = new OutputDocument();
|
|
|
|
|
$oOutputDocument->Fields = $oOutputDocument->getByUid( $sDocUid );
|
|
|
|
|
$download = $oOutputDocument->Fields['OUT_DOC_OPEN_TYPE'];
|
|
|
|
|
|
2012-10-18 16:05:43 +00:00
|
|
|
$info = pathinfo( $oAppDocument->getAppDocFilename() );
|
|
|
|
|
if (! isset( $_GET['ext'] )) {
|
|
|
|
|
$ext = $info['extension'];
|
|
|
|
|
} else {
|
|
|
|
|
if ($_GET['ext'] != '') {
|
|
|
|
|
$ext = $_GET['ext'];
|
|
|
|
|
} else {
|
|
|
|
|
$ext = $info['extension'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$ver = (isset( $_GET['v'] ) && $_GET['v'] != '') ? '_' . $_GET['v'] : '';
|
|
|
|
|
|
2014-03-19 10:17:29 -04:00
|
|
|
if (! $ver) //This code is in the case the outputdocument won't be versioned
|
2012-10-18 16:05:43 +00:00
|
|
|
$ver = '_1';
|
|
|
|
|
|
2013-04-29 16:48:29 -04:00
|
|
|
$realPath = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $sAppDocUid . $ver . '.' . $ext;
|
|
|
|
|
$realPath1 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . $ver . '.' . $ext;
|
|
|
|
|
$realPath2 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/outdocs/' . $info['basename'] . '.' . $ext;
|
2013-02-13 17:48:32 -04:00
|
|
|
|
2012-10-18 16:05:43 +00:00
|
|
|
$sw_file_exists = false;
|
|
|
|
|
if (file_exists( $realPath )) {
|
|
|
|
|
$sw_file_exists = true;
|
|
|
|
|
} elseif (file_exists( $realPath1 )) {
|
|
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$realPath = $realPath1;
|
|
|
|
|
} elseif (file_exists( $realPath2 )) {
|
|
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$realPath = $realPath2;
|
|
|
|
|
}
|
2013-02-13 17:48:32 -04:00
|
|
|
|
2012-10-18 16:05:43 +00:00
|
|
|
if (! $sw_file_exists) {
|
2013-02-13 17:48:32 -04:00
|
|
|
|
2013-02-13 19:49:49 -04:00
|
|
|
$oPluginRegistry = & PMPluginRegistry::getSingleton();
|
2013-02-13 17:48:32 -04:00
|
|
|
if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT )) {
|
2013-02-13 19:49:49 -04:00
|
|
|
$error_message = G::LoadTranslation( 'ID_ERROR_FILE_NOT_EXIST', SYS_LANG, array('filename' => $info['basename'] . $ver . '.' . $ext) ) . ' ' . G::LoadTranslation('ID_CONTACT_ADMIN');
|
2013-02-13 17:48:32 -04:00
|
|
|
} else {
|
2013-02-13 19:49:49 -04:00
|
|
|
$error_message = "'" . $info['basename'] . $ver . '.' . $ext . "' " . G::LoadTranslation( 'ID_ERROR_STREAMING_FILE' );
|
2013-02-13 17:48:32 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-18 16:05:43 +00:00
|
|
|
if ((isset( $_POST['request'] )) && ($_POST['request'] == true)) {
|
2013-02-13 17:48:32 -04:00
|
|
|
$res['success'] = 'failure';
|
|
|
|
|
$res['message'] = $error_message;
|
|
|
|
|
print G::json_encode( $res );
|
2012-10-18 16:05:43 +00:00
|
|
|
} else {
|
|
|
|
|
G::SendMessageText( $error_message, "ERROR" );
|
|
|
|
|
$backUrlObj = explode( "sys" . SYS_SYS, $_SERVER['HTTP_REFERER'] );
|
|
|
|
|
G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
|
|
|
|
|
die();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if ((isset( $_POST['request'] )) && ($_POST['request'] == true)) {
|
|
|
|
|
$res['success'] = 'success';
|
|
|
|
|
$res['message'] = $info['basename'] . $ver . '.' . $ext;
|
|
|
|
|
print G::json_encode( $res );
|
|
|
|
|
} else {
|
2015-12-20 10:21:00 -04:00
|
|
|
$nameFile = $info['basename'] . $ver . '.' . $ext;
|
2015-12-19 20:23:57 -04:00
|
|
|
$licensedFeatures = &PMLicensedFeatures::getSingleton();
|
|
|
|
|
$downloadStatus = false;
|
2016-04-21 12:17:13 -04:00
|
|
|
/*----------------------------------********---------------------------------*/
|
2016-01-05 14:52:10 -04:00
|
|
|
if ($licensedFeatures->verifyfeature('AhKNjBEVXZlWUFpWE8wVTREQ0FObmo0aTdhVzhvalFic1M=')) {
|
2015-12-19 20:23:57 -04:00
|
|
|
G::LoadClass( "AppDocumentDrive" );
|
|
|
|
|
$drive = new AppDocumentDrive();
|
|
|
|
|
if ($drive->getStatusDrive()) {
|
|
|
|
|
$fieldDrive = $oAppDocument->getAppDocDriveDownload();
|
|
|
|
|
$drive->loadUser($_SESSION['USER_LOGGED']);
|
|
|
|
|
$type = $ext == 'doc' ? 'OUTPUT_DOC' : 'OUTPUT_PDF';
|
|
|
|
|
$uidDrive = $drive->changeUrlDrive($oAppDocument->Fields, $type);
|
2015-12-20 10:21:00 -04:00
|
|
|
$fileContent = $drive->download($uidDrive);
|
|
|
|
|
if ($fileContent !== null) {
|
|
|
|
|
$downloadStatus = true;
|
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
|
header('Content-Disposition: attachment; filename='.$nameFile);
|
|
|
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
|
header('Set-Cookie: fileLoading=true');
|
|
|
|
|
echo $fileContent;
|
|
|
|
|
exit();
|
|
|
|
|
}
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-04-21 12:17:13 -04:00
|
|
|
/*----------------------------------********---------------------------------*/
|
2015-12-19 20:23:57 -04:00
|
|
|
if (!$downloadStatus) {
|
2015-12-20 10:21:00 -04:00
|
|
|
G::streamFile( $realPath, $download, $nameFile); //download
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//die($realPath);
|
|
|
|
|
//G::streamFile( $realPath, $download, $info['basename'] . $ver . '.' . $ext );
|
2012-10-18 16:05:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//G::streamFile ( $realPath, true);
|
|
|
|
|
|