function casesShowOuputDocumentExist($url)
{
    $urlArray = explode("?", $url);
    $urlParametroString = $urlArray[1];
    parse_str($urlParametroString, $_GET);
    require_once "classes/model/AppDocumentPeer.php";
    $oAppDocument = new AppDocument();
    $oAppDocument->Fields = $oAppDocument->load($_GET['a'], isset($_GET['v']) ? $_GET['v'] : null);
    $sAppDocUid = $oAppDocument->getAppDocUid();
    $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'] : '';
    if (!$ver) {
        //This code is in the case the outputdocument won't be versioned
        $ver = '_1';
    }
    $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;
    $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;
    }
    $swFileExist = 0;
    if ($sw_file_exists) {
        $swFileExist = 1;
    }
    return $swFileExist;
}
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 */
try {
    //save info
    G::LoadClass('case');
    G::LoadClass('tasks');
    $oAppDocument = new AppDocument();
    $aFields = array('APP_UID' => $_GET['APP_UID'], 'DEL_INDEX' => 100000, 'USR_UID' => $_SESSION['USER_LOGGED'], 'DOC_UID' => $_GET['UID'], 'APP_DOC_TYPE' => $_POST['form']['APP_DOC_TYPE'], 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_COMMENT' => isset($_POST['form']['APP_DOC_COMMENT']) ? $_POST['form']['APP_DOC_COMMENT'] : '', 'APP_DOC_TITLE' => '', 'APP_DOC_FILENAME' => isset($_FILES['form']['name']['APP_DOC_FILENAME']) ? $_FILES['form']['name']['APP_DOC_FILENAME'] : '');
    $oAppDocument->create($aFields);
    $sAppDocUid = $oAppDocument->getAppDocUid();
    $info = pathinfo($oAppDocument->getAppDocFilename());
    $ext = isset($info['extension']) ? $info['extension'] : '';
    //save the file
    if (!empty($_FILES['form'])) {
        if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) {
            $sPathName = PATH_DOCUMENT . G::getPathFromUID($_GET['APP_UID']) . PATH_SEP;
            $sFileName = $sAppDocUid . '.' . $ext;
            $sOriginalName = $_FILES['form']['name']['APP_DOC_FILENAME'];
            G::uploadFile($_FILES['form']['tmp_name']['APP_DOC_FILENAME'], $sPathName, $sFileName);
            //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
            $oPluginRegistry =& PMPluginRegistry::getSingleton();
            if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
                $oData['APP_UID'] = $_GET['APP_UID'];
                $documentData = new uploadDocumentData($_GET['APP_UID'], $_SESSION['USER_LOGGED'], $sPathName . $sFileName, $aFields['APP_DOC_FILENAME'], $sAppDocUid);
                $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                unlink($sPathName . $sFileName);
            }
            //end plugin
            //update AppData with the current file uploaded
            $oCase = new Cases();
            $aAppDataFields = $oCase->loadCase($_GET['APP_UID']);
示例#3
0
     $oInputDocument = new InputDocument();
     $aID = $oInputDocument->load($indocUid);
     //Get the Custom Folder ID (create if necessary)
     $oFolder = new AppFolder();
     $documentFileStructure = $oFolder->getFolderStructure();
     $aFields = array("APP_UID" => $_SESSION["APPLICATION"], "DEL_INDEX" => $_SESSION["INDEX"], "USR_UID" => $_SESSION["USER_LOGGED"], "DOC_UID" => $indocUid, "APP_DOC_TYPE" => "INPUT", "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), "APP_DOC_COMMENT" => "", "APP_DOC_TITLE" => "", "APP_DOC_FILENAME" => $arrayFileName[$i], "FOLDER_UID" => $oFolder->createFromPath($aID["INP_DOC_DESTINATION_PATH"]), "APP_DOC_TAGS" => $oFolder->parseTags($aID["INP_DOC_TAGS"]), "APP_DOC_FIELDNAME" => $fieldName);
 } else {
     $aFields = array("APP_UID" => $_SESSION["APPLICATION"], "DEL_INDEX" => $_SESSION["INDEX"], "USR_UID" => $_SESSION["USER_LOGGED"], "DOC_UID" => -1, "APP_DOC_TYPE" => "ATTACHED", "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), "APP_DOC_COMMENT" => "", "APP_DOC_TITLE" => "", "APP_DOC_FILENAME" => $arrayFileName[$i], "APP_DOC_FIELDNAME" => $fieldName);
 }
 $oAppDocument = new AppDocument();
 $oAppDocument->create($aFields);
 $iDocVersion = $oAppDocument->getDocVersion();
 $sAppDocUid = $oAppDocument->getAppDocUid();
 $aInfo = pathinfo($oAppDocument->getAppDocFilename());
 $sExtension = isset($aInfo["extension"]) ? $aInfo["extension"] : "";
 $pathUID = G::getPathFromUID($_SESSION["APPLICATION"]);
 $sPathName = PATH_DOCUMENT . $pathUID . PATH_SEP;
 // . $documentFileStructure;
 $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $sExtension;
 G::uploadFile($arrayFileTmpName[$i], $sPathName, $sFileName);
 //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
 $oPluginRegistry =& PMPluginRegistry::getSingleton();
 if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists("uploadDocumentData")) {
     $triggerDetail = $oPluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);
     $documentData = new uploadDocumentData($_SESSION["APPLICATION"], $_SESSION["USER_LOGGED"], $sPathName . $sFileName, $aFields["APP_DOC_FILENAME"], $sAppDocUid, $iDocVersion);
     $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
     if ($uploadReturn) {
         $aFields["APP_DOC_PLUGIN"] = $triggerDetail->sNamespace;
         if (!isset($aFields["APP_DOC_UID"])) {
             $aFields["APP_DOC_UID"] = $sAppDocUid;
         }
示例#4
0
 $Fields['APP_DATA'] = $oCase->ExecuteTriggers($_SESSION['TASK'], 'OUTPUT_DOCUMENT', $_GET['UID'], 'AFTER', $Fields['APP_DATA']);
 $Fields['DEL_INDEX'] = $_SESSION['INDEX'];
 $Fields['TAS_UID'] = $_SESSION['TASK'];
 //Execute after triggers - End
 //Save data - Start
 unset($Fields['APP_STATUS']);
 unset($Fields['APP_PROC_STATUS']);
 unset($Fields['APP_PROC_CODE']);
 unset($Fields['APP_PIN']);
 $oCase->updateCase($_SESSION['APPLICATION'], $Fields);
 //Save data - End
 //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
 $oPluginRegistry =& PMPluginRegistry::getSingleton();
 if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
     $triggerDetail = $oPluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);
     $sPathName = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . PATH_SEP;
     $oData['APP_UID'] = $_SESSION['APPLICATION'];
     $oData['ATTACHMENT_FOLDER'] = true;
     switch ($aOD['OUT_DOC_GENERATE']) {
         case "BOTH":
             $documentData = new uploadDocumentData($_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $pathOutput . $sFilename . '.pdf', $sFilenameOriginal . '.pdf', $sDocUID, $oAppDocument->getDocVersion());
             $documentData->sFileType = "PDF";
             $documentData->bUseOutputFolder = true;
             $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
             if ($uploadReturn) {
                 //Only delete if the file was saved correctly
                 $aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
                 //$oAppDocument = new AppDocument();
                 //$oAppDocument->update($aFields);
                 unlink($pathOutput . $sFilename . '.pdf');
             }
 *
 * @author David Callizaya <*****@*****.**>
 */
switch ($RBAC->userCanAccess('PM_SUPERVISOR')) {
    case -2:
        G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels');
        G::header('location: ../login/login');
        die;
        break;
    case -1:
        G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
        G::header('location: ../login/login');
        die;
        break;
}
require_once "classes/model/AppDocumentPeer.php";
$oAppDocument = new AppDocument();
$oAppDocument->Fields = $oAppDocument->load($_GET['a']);
$sAppDocUid = $oAppDocument->getAppDocUid();
$info = pathinfo($oAppDocument->getAppDocFilename());
if (!isset($_GET['ext'])) {
    $ext = $info['extension'];
} else {
    if ($_GET['ext'] != '') {
        $ext = $_GET['ext'];
    } else {
        $ext = $info['extension'];
    }
}
$realPath = PATH_DOCUMENT . G::getPathFromUID($_SESSION['APPLICATION']) . '/outdocs/' . $info['basename'] . '.' . $ext;
G::streamFile($realPath, true);
 /**
  * Get data of Cases OutputDocument
  *
  * @param string $applicationUid
  * @param string $outputDocumentUid
  * @param string $userUid
  *
  * return object Return an object with data of an OutputDocument
  */
 public function addCasesOutputDocument($applicationUid, $outputDocumentUid, $userUid)
 {
     try {
         $sApplication = $applicationUid;
         $index = \AppDelegation::getCurrentIndex($applicationUid);
         $sUserLogged = $userUid;
         $outputID = $outputDocumentUid;
         $g = new \G();
         $g->sessionVarSave();
         \G::LoadClass( 'case' );
         $oCase = new \Cases();
         $oCase->thisIsTheCurrentUser( $sApplication, $index, $sUserLogged, '', 'casesListExtJs' );
         //require_once 'classes/model/OutputDocument.php';
         $oOutputDocument = new \OutputDocument();
         $aOD = $oOutputDocument->load( $outputID );
         $Fields = $oCase->loadCase( $sApplication );
         $sFilename = preg_replace( '[^A-Za-z0-9_]', '_', \G::replaceDataField( $aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA'] ) );
         require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "AppFolder.php");
         require_once (PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "AppDocument.php");
         //Get the Custom Folder ID (create if necessary)
         $oFolder = new \AppFolder();
         $folderId = $oFolder->createFromPath( $aOD['OUT_DOC_DESTINATION_PATH'], $sApplication );
         //Tags
         $fileTags = $oFolder->parseTags( $aOD['OUT_DOC_TAGS'], $sApplication );
         //Get last Document Version and apply versioning if is enabled
         $oAppDocument = new \AppDocument();
         $lastDocVersion = $oAppDocument->getLastDocVersion( $outputID, $sApplication );
         $oCriteria = new \Criteria( 'workflow' );
         $oCriteria->add( \AppDocumentPeer::APP_UID, $sApplication );
         $oCriteria->add( \AppDocumentPeer::DOC_UID, $outputID );
         $oCriteria->add( \AppDocumentPeer::DOC_VERSION, $lastDocVersion );
         $oCriteria->add( \AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT' );
         $oDataset = \AppDocumentPeer::doSelectRS( $oCriteria );
         $oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
         $oDataset->next();
         if (($aOD['OUT_DOC_VERSIONING']) && ($lastDocVersion != 0)) {
             //Create new Version of current output
             $lastDocVersion ++;
             if ($aRow = $oDataset->getRow()) {
                 $aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion + 1,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags);
                 $oAppDocument = new \AppDocument();
                 $oAppDocument->create( $aFields );
                 $sDocUID = $aRow['APP_DOC_UID'];
             }
         } else {
             ////No versioning so Update a current Output or Create new if no exist
             if ($aRow = $oDataset->getRow()) {
                 //Update
                 $aFields = array ('APP_DOC_UID' => $aRow['APP_DOC_UID'],'APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
                 );
                 $oAppDocument = new \AppDocument();
                 $oAppDocument->update( $aFields );
                 $sDocUID = $aRow['APP_DOC_UID'];
             } else {
                 //we are creating the appdocument row
                 //create
                 if ($lastDocVersion == 0) {
                     $lastDocVersion ++;
                 }
                 $aFields = array ('APP_UID' => $sApplication,'DEL_INDEX' => $index,'DOC_UID' => $outputID,'DOC_VERSION' => $lastDocVersion,'USR_UID' => $sUserLogged,'APP_DOC_TYPE' => 'OUTPUT','APP_DOC_CREATE_DATE' => date( 'Y-m-d H:i:s' ),'APP_DOC_FILENAME' => $sFilename,'FOLDER_UID' => $folderId,'APP_DOC_TAGS' => $fileTags
                 );
                 $oAppDocument = new \AppDocument();
                 $aFields['APP_DOC_UID'] = $sDocUID = $oAppDocument->create( $aFields );
             }
         }
         $sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion;
         $pathOutput = PATH_DOCUMENT . \G::getPathFromUID($sApplication) . PATH_SEP . 'outdocs' . PATH_SEP; //G::pr($sFilename);die;
         \G::mk_dir( $pathOutput );
         $aProperties = array ();
         if (! isset( $aOD['OUT_DOC_MEDIA'] )) {
             $aOD['OUT_DOC_MEDIA'] = 'Letter';
         }
         if (! isset( $aOD['OUT_DOC_LEFT_MARGIN'] )) {
             $aOD['OUT_DOC_LEFT_MARGIN'] = '15';
         }
         if (! isset( $aOD['OUT_DOC_RIGHT_MARGIN'] )) {
             $aOD['OUT_DOC_RIGHT_MARGIN'] = '15';
         }
         if (! isset( $aOD['OUT_DOC_TOP_MARGIN'] )) {
             $aOD['OUT_DOC_TOP_MARGIN'] = '15';
         }
         if (! isset( $aOD['OUT_DOC_BOTTOM_MARGIN'] )) {
             $aOD['OUT_DOC_BOTTOM_MARGIN'] = '15';
         }
         $aProperties['media'] = $aOD['OUT_DOC_MEDIA'];
         $aProperties['margins'] = array ('left' => $aOD['OUT_DOC_LEFT_MARGIN'],'right' => $aOD['OUT_DOC_RIGHT_MARGIN'],'top' => $aOD['OUT_DOC_TOP_MARGIN'],'bottom' => $aOD['OUT_DOC_BOTTOM_MARGIN']
         );
         if (isset($aOD['OUT_DOC_REPORT_GENERATOR'])) {
             $aProperties['report_generator'] = $aOD['OUT_DOC_REPORT_GENERATOR'];
         }
         $this->generate( $outputID, $Fields['APP_DATA'], $pathOutput, $sFilename, $aOD['OUT_DOC_TEMPLATE'], (boolean) $aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'], $aProperties , $applicationUid);
         //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
         //G::LoadClass('plugin');
         $oPluginRegistry = & \PMPluginRegistry::getSingleton();
         if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT ) && class_exists( 'uploadDocumentData' )) {
             $triggerDetail = $oPluginRegistry->getTriggerInfo( PM_UPLOAD_DOCUMENT );
             $aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
             $oAppDocument1 = new \AppDocument();
             $oAppDocument1->update( $aFields );
             $sPathName = PATH_DOCUMENT . \G::getPathFromUID($sApplication) . PATH_SEP;
             $oData['APP_UID'] = $sApplication;
             $oData['ATTACHMENT_FOLDER'] = true;
             switch ($aOD['OUT_DOC_GENERATE']) {
                 case "BOTH":
                     $documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
                     $documentData->sFileType = "PDF";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink( $pathOutput . $sFilename . '.pdf' );
                     }
                     $documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
                     $documentData->sFileType = "DOC";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink( $pathOutput . $sFilename . '.doc' );
                     }
                     break;
                 case "PDF":
                     $documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion() );
                     $documentData->sFileType = "PDF";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink( $pathOutput . $sFilename . '.pdf' );
                     }
                     break;
                 case "DOC":
                     $documentData = new \uploadDocumentData( $sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion() );
                     $documentData->sFileType = "DOC";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink( $pathOutput . $sFilename . '.doc' );
                     }
                     break;
             }
         }
         $g->sessionVarRestore();
         $oAppDocument = \AppDocumentPeer::retrieveByPK( $aFields['APP_DOC_UID'], $lastDocVersion);
         if ($oAppDocument->getAppDocStatus() == 'DELETED') {
             $oAppDocument->setAppDocStatus('ACTIVE');
             $oAppDocument->save();
         }
         $response = $this->getCasesOutputDocument($applicationUid, $userUid, $aFields['APP_DOC_UID']);
         return $response;
     } catch (\Exception $e) {
         throw $e;
     }
 }
示例#7
0
 /**
  * Get data of Cases OutputDocument
  *
  * @param string $applicationUid
  * @param string $outputDocumentUid
  * @param string $userUid
  *
  * return object Return an object with data of an OutputDocument
  */
 public function addCasesOutputDocument($applicationUid, $outputDocumentUid, $userUid)
 {
     try {
         $sApplication = $applicationUid;
         $index = \AppDelegation::getCurrentIndex($applicationUid);
         $sUserLogged = $userUid;
         $outputID = $outputDocumentUid;
         $g = new \G();
         $g->sessionVarSave();
         \G::LoadClass('case');
         $oCase = new \Cases();
         $oCase->thisIsTheCurrentUser($sApplication, $index, $sUserLogged, '', 'casesListExtJs');
         //require_once 'classes/model/OutputDocument.php';
         $oOutputDocument = new \OutputDocument();
         $aOD = $oOutputDocument->load($outputID);
         $Fields = $oCase->loadCase($sApplication);
         $sFilename = preg_replace('[^A-Za-z0-9_]', '_', \G::replaceDataField($aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA']));
         require_once PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "AppFolder.php";
         require_once PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "AppDocument.php";
         //Get the Custom Folder ID (create if necessary)
         $oFolder = new \AppFolder();
         $folderId = $oFolder->createFromPath($aOD['OUT_DOC_DESTINATION_PATH'], $sApplication);
         //Tags
         $fileTags = $oFolder->parseTags($aOD['OUT_DOC_TAGS'], $sApplication);
         //Get last Document Version and apply versioning if is enabled
         $oAppDocument = new \AppDocument();
         $lastDocVersion = $oAppDocument->getLastDocVersion($outputID, $sApplication);
         $oCriteria = new \Criteria('workflow');
         $oCriteria->add(\AppDocumentPeer::APP_UID, $sApplication);
         $oCriteria->add(\AppDocumentPeer::DOC_UID, $outputID);
         $oCriteria->add(\AppDocumentPeer::DOC_VERSION, $lastDocVersion);
         $oCriteria->add(\AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT');
         $oDataset = \AppDocumentPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         if ($aOD['OUT_DOC_VERSIONING'] && $lastDocVersion != 0) {
             //Create new Version of current output
             $lastDocVersion++;
             if ($aRow = $oDataset->getRow()) {
                 $aFields = array('APP_DOC_UID' => $aRow['APP_DOC_UID'], 'APP_UID' => $sApplication, 'DEL_INDEX' => $index, 'DOC_UID' => $outputID, 'DOC_VERSION' => $lastDocVersion + 1, 'USR_UID' => $sUserLogged, 'APP_DOC_TYPE' => 'OUTPUT', 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_FILENAME' => $sFilename, 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
                 $oAppDocument = new \AppDocument();
                 $oAppDocument->create($aFields);
                 $sDocUID = $aRow['APP_DOC_UID'];
             }
         } else {
             ////No versioning so Update a current Output or Create new if no exist
             if ($aRow = $oDataset->getRow()) {
                 //Update
                 $aFields = array('APP_DOC_UID' => $aRow['APP_DOC_UID'], 'APP_UID' => $sApplication, 'DEL_INDEX' => $index, 'DOC_UID' => $outputID, 'DOC_VERSION' => $lastDocVersion, 'USR_UID' => $sUserLogged, 'APP_DOC_TYPE' => 'OUTPUT', 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_FILENAME' => $sFilename, 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
                 $oAppDocument = new \AppDocument();
                 $oAppDocument->update($aFields);
                 $sDocUID = $aRow['APP_DOC_UID'];
             } else {
                 //we are creating the appdocument row
                 //create
                 if ($lastDocVersion == 0) {
                     $lastDocVersion++;
                 }
                 $aFields = array('APP_UID' => $sApplication, 'DEL_INDEX' => $index, 'DOC_UID' => $outputID, 'DOC_VERSION' => $lastDocVersion, 'USR_UID' => $sUserLogged, 'APP_DOC_TYPE' => 'OUTPUT', 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_FILENAME' => $sFilename, 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
                 $oAppDocument = new \AppDocument();
                 $aFields['APP_DOC_UID'] = $sDocUID = $oAppDocument->create($aFields);
             }
         }
         $sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion;
         $pathOutput = PATH_DOCUMENT . \G::getPathFromUID($sApplication) . PATH_SEP . 'outdocs' . PATH_SEP;
         //G::pr($sFilename);die;
         \G::mk_dir($pathOutput);
         $aProperties = array();
         if (!isset($aOD['OUT_DOC_MEDIA'])) {
             $aOD['OUT_DOC_MEDIA'] = 'Letter';
         }
         if (!isset($aOD['OUT_DOC_LEFT_MARGIN'])) {
             $aOD['OUT_DOC_LEFT_MARGIN'] = '15';
         }
         if (!isset($aOD['OUT_DOC_RIGHT_MARGIN'])) {
             $aOD['OUT_DOC_RIGHT_MARGIN'] = '15';
         }
         if (!isset($aOD['OUT_DOC_TOP_MARGIN'])) {
             $aOD['OUT_DOC_TOP_MARGIN'] = '15';
         }
         if (!isset($aOD['OUT_DOC_BOTTOM_MARGIN'])) {
             $aOD['OUT_DOC_BOTTOM_MARGIN'] = '15';
         }
         $aProperties['media'] = $aOD['OUT_DOC_MEDIA'];
         $aProperties['margins'] = array('left' => $aOD['OUT_DOC_LEFT_MARGIN'], 'right' => $aOD['OUT_DOC_RIGHT_MARGIN'], 'top' => $aOD['OUT_DOC_TOP_MARGIN'], 'bottom' => $aOD['OUT_DOC_BOTTOM_MARGIN']);
         if (isset($aOD['OUT_DOC_REPORT_GENERATOR'])) {
             $aProperties['report_generator'] = $aOD['OUT_DOC_REPORT_GENERATOR'];
         }
         $this->generate($outputID, $Fields['APP_DATA'], $pathOutput, $sFilename, $aOD['OUT_DOC_TEMPLATE'], (bool) $aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'], $aProperties, $applicationUid);
         /*----------------------------------********---------------------------------*/
         $licensedFeatures =& \PMLicensedFeatures::getSingleton();
         if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
             \G::LoadClass("pmDrive");
             $pmDrive = new \PMDrive();
             if ($pmDrive->getStatusService()) {
                 $app = new \Application();
                 $user = new \Users();
                 $dataUser = $user->load($userUid);
                 $pmDrive->setDriveUser($dataUser['USR_EMAIL']);
                 $appData = $app->Load($applicationUid);
                 if ($appData['APP_DRIVE_FOLDER_UID'] == null) {
                     $process = new \Process();
                     $process->setProUid($appData['PRO_UID']);
                     $result = $pmDrive->createFolder($process->getProTitle() . ' - ' . G::LoadTranslation("ID_CASE") . ' #' . $appData['APP_NUMBER'], $pmDrive->getFolderIdPMDrive($userUid));
                     $appData['APP_DRIVE_FOLDER_UID'] = $result->id;
                     $app->update($appData);
                 }
                 $fileIdDriveDoc = '';
                 $fileIdDrivePdf = '';
                 $sFilenameOriginal = preg_replace('[^A-Za-z0-9_]', '_', \G::replaceDataField($aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA']));
                 switch ($aOD['OUT_DOC_GENERATE']) {
                     case "BOTH":
                         $result = $pmDrive->uploadFile('application/pdf', $pathOutput . $sFilename . '.pdf', $sFilenameOriginal . '.pdf', $appData['APP_DRIVE_FOLDER_UID']);
                         $oAppDocument->setDriveDownload('OUTPUT_PDF', $result->webContentLink);
                         $fileIdDrivePdf = $result->id;
                         $result = $pmDrive->uploadFile('application/doc', $pathOutput . $sFilename . '.doc', $sFilenameOriginal . '.doc', $appData['APP_DRIVE_FOLDER_UID']);
                         $oAppDocument->setDriveDownload('OUTPUT_DOC', $result->webContentLink);
                         $fileIdDriveDoc = $result->id;
                         break;
                     case "PDF":
                         $result = $pmDrive->uploadFile('application/pdf', $pathOutput . $sFilename . '.pdf', $sFilenameOriginal . '.pdf', $appData['APP_DRIVE_FOLDER_UID']);
                         $oAppDocument->setDriveDownload('OUTPUT_PDF', $result->webContentLink);
                         $fileIdDrivePdf = $result->id;
                         break;
                     case "DOC":
                         $result = $pmDrive->uploadFile('application/doc', $pathOutput . $sFilename . '.doc', $sFilenameOriginal . '.doc', $appData['APP_DRIVE_FOLDER_UID']);
                         $oAppDocument->setDriveDownload('OUTPUT_DOC', $result->webContentLink);
                         $fileIdDriveDoc = $result->id;
                         break;
                 }
                 $aFields['DOC_VERSION'] = $oAppDocument->getDocVersion();
                 // $docVersion;
                 $aFields['APP_DOC_UID'] = $oAppDocument->getAppDocUid();
                 //$appDocUid;
                 $appDocUid = $aFields['APP_DOC_UID'];
                 $oAppDocument->update($aFields);
                 //$option = 'pmDrive';
                 //add permissions
                 $criteria = new \Criteria('workflow');
                 $criteria->addSelectColumn(\ApplicationPeer::PRO_UID);
                 $criteria->addSelectColumn(\TaskUserPeer::TAS_UID);
                 $criteria->addSelectColumn(\TaskUserPeer::USR_UID);
                 $criteria->addSelectColumn(\TaskUserPeer::TU_RELATION);
                 $criteria->add(\ApplicationPeer::APP_UID, $applicationUid);
                 $criteria->addJoin(\ApplicationPeer::PRO_UID, \TaskPeer::PRO_UID, \Criteria::LEFT_JOIN);
                 $criteria->addJoin(\TaskPeer::TAS_UID, \TaskUserPeer::TAS_UID, \Criteria::LEFT_JOIN);
                 $dataset = \ApplicationPeer::doSelectRS($criteria);
                 $dataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 $userPermission = array();
                 $case = new \Cases();
                 while ($dataset->next()) {
                     $row = $dataset->getRow();
                     if ($row['TU_RELATION'] == 1) {
                         //users
                         $dataUser = $user->load($row['USR_UID']);
                         if (array_search($dataUser['USR_EMAIL'], $userPermission) === false) {
                             $objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid, $row['TAS_UID'], $row['USR_UID']);
                             if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) !== false) {
                                 $userPermission[] = $dataUser['USR_EMAIL'];
                             }
                         }
                     } else {
                         //Groups
                         $criteria = new \Criteria('workflow');
                         $criteria->addSelectColumn(\UsersPeer::USR_EMAIL);
                         $criteria->addSelectColumn(\UsersPeer::USR_UID);
                         $criteria->add(\GroupUserPeer::GRP_UID, $row['USR_UID']);
                         $criteria->addJoin(\GroupUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN);
                         $oDataset = \AppDelegationPeer::doSelectRS($criteria);
                         $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                         while ($oDataset->next()) {
                             $aRow = $oDataset->getRow();
                             if (array_search($aRow['USR_EMAIL'], $userPermission) === false) {
                                 $objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid, $row['TAS_UID'], $aRow['USR_UID']);
                                 if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) !== false) {
                                     $userPermission[] = $aRow['USR_EMAIL'];
                                 }
                             }
                         }
                     }
                 }
                 $userPermission = array_unique($userPermission);
                 foreach ($userPermission as $key => $val) {
                     $pmDrive->setPermission($appData['APP_DRIVE_FOLDER_UID'], $val, 'user', 'writer');
                     $pmDrive->setPermission($fileIdDrivePdf, $val);
                     $pmDrive->setPermission($fileIdDriveDoc, $val);
                 }
             }
         }
         /*----------------------------------********---------------------------------*/
         //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
         //G::LoadClass('plugin');
         $oPluginRegistry =& \PMPluginRegistry::getSingleton();
         if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
             $triggerDetail = $oPluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);
             $aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
             $oAppDocument1 = new \AppDocument();
             $oAppDocument1->update($aFields);
             $sPathName = PATH_DOCUMENT . \G::getPathFromUID($sApplication) . PATH_SEP;
             $oData['APP_UID'] = $sApplication;
             $oData['ATTACHMENT_FOLDER'] = true;
             switch ($aOD['OUT_DOC_GENERATE']) {
                 case "BOTH":
                     $documentData = new \uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion());
                     $documentData->sFileType = "PDF";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink($pathOutput . $sFilename . '.pdf');
                     }
                     $documentData = new \uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion());
                     $documentData->sFileType = "DOC";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink($pathOutput . $sFilename . '.doc');
                     }
                     break;
                 case "PDF":
                     $documentData = new \uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion());
                     $documentData->sFileType = "PDF";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink($pathOutput . $sFilename . '.pdf');
                     }
                     break;
                 case "DOC":
                     $documentData = new \uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion());
                     $documentData->sFileType = "DOC";
                     $documentData->bUseOutputFolder = true;
                     $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                     if ($uploadReturn) {
                         //Only delete if the file was saved correctly
                         unlink($pathOutput . $sFilename . '.doc');
                     }
                     break;
             }
         }
         $g->sessionVarRestore();
         $oAppDocument = \AppDocumentPeer::retrieveByPK($aFields['APP_DOC_UID'], $lastDocVersion);
         if ($oAppDocument->getAppDocStatus() == 'DELETED') {
             $oAppDocument->setAppDocStatus('ACTIVE');
             $oAppDocument->save();
         }
         $response = $this->getCasesOutputDocument($applicationUid, $userUid, $aFields['APP_DOC_UID']);
         return $response;
     } catch (\Exception $e) {
         throw $e;
     }
 }
$oAppDocument->Fields = $oAppDocument->load($_GET['a'], $docVersion);
$sAppDocUid = $oAppDocument->getAppDocUid();
$iDocVersion = $oAppDocument->getDocVersion();
$info = pathinfo($oAppDocument->getAppDocFilename());
$ext = $info['extension'];
if (isset($_GET['b'])) {
    if ($_GET['b'] == '0') {
        $bDownload = false;
    } else {
        $bDownload = true;
    }
} else {
    $bDownload = true;
}
$realPath = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/' . $sAppDocUid . '_' . $iDocVersion . '.' . $ext;
$realPath1 = PATH_DOCUMENT . G::getPathFromUID($oAppDocument->Fields['APP_UID']) . '/' . $sAppDocUid . '.' . $ext;
$sw_file_exists = false;
if (file_exists($realPath)) {
    $sw_file_exists = true;
} elseif (file_exists($realPath1)) {
    $sw_file_exists = true;
    $realPath = $realPath1;
}
if (!$sw_file_exists) {
    $error_message = "'" . $oAppDocument->Fields['APP_DOC_FILENAME'] . "' " . G::LoadTranslation('ID_ERROR_STREAMING_FILE');
    if (isset($_POST['request']) && $_POST['request'] == true) {
        $res['success'] = 'failure';
        $res['message'] = $error_message;
        print G::json_encode($res);
    } else {
        G::SendMessageText($error_message, "ERROR");
/**
 *
 * @method
 *
 * Generates an Output Document
 *
 * @name PMFGenerateOutputDocument
 * @label PMF Generate Output Document
 *
 * @param string(32) | $outputID | Output ID | Output Document ID
 * @return none | $none | None | None
 *
 */
function PMFGenerateOutputDocument($outputID, $sApplication = null, $index = null, $sUserLogged = null)
{
    $g = new G();
    $g->sessionVarSave();
    if ($sApplication) {
        $_SESSION["APPLICATION"] = $sApplication;
    } else {
        $sApplication = $_SESSION["APPLICATION"];
    }
    if ($index) {
        $_SESSION["INDEX"] = $index;
    } else {
        $index = $_SESSION["INDEX"];
    }
    if ($sUserLogged) {
        $_SESSION["USER_LOGGED"] = $sUserLogged;
    } else {
        $sUserLogged = $_SESSION["USER_LOGGED"];
    }
    G::LoadClass('case');
    $oCase = new Cases();
    $oCase->thisIsTheCurrentUser($sApplication, $index, $sUserLogged, '', 'casesListExtJs');
    //require_once 'classes/model/OutputDocument.php';
    $oOutputDocument = new OutputDocument();
    $aOD = $oOutputDocument->load($outputID);
    $Fields = $oCase->loadCase($sApplication);
    //The $_GET['UID'] variable is used when a process executes.
    //$_GET['UID']=($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID'];
    //$sUID = ($aOD['OUT_DOC_VERSIONING'])?$_GET['UID']:$aOD['OUT_DOC_UID'];
    $sFilename = preg_replace('[^A-Za-z0-9_]', '_', G::replaceDataField($aOD['OUT_DOC_FILENAME'], $Fields['APP_DATA']));
    require_once 'classes/model/AppFolder.php';
    require_once 'classes/model/AppDocument.php';
    //Get the Custom Folder ID (create if necessary)
    $oFolder = new AppFolder();
    //$aOD['OUT_DOC_DESTINATION_PATH'] = ($aOD['OUT_DOC_DESTINATION_PATH']=='')?PATH_DOCUMENT
    //      . $_SESSION['APPLICATION'] . PATH_SEP . 'outdocs'. PATH_SEP:$aOD['OUT_DOC_DESTINATION_PATH'];
    $folderId = $oFolder->createFromPath($aOD['OUT_DOC_DESTINATION_PATH'], $sApplication);
    //Tags
    $fileTags = $oFolder->parseTags($aOD['OUT_DOC_TAGS'], $sApplication);
    //Get last Document Version and apply versioning if is enabled
    $oAppDocument = new AppDocument();
    $lastDocVersion = $oAppDocument->getLastDocVersion($outputID, $sApplication);
    $oCriteria = new Criteria('workflow');
    $oCriteria->add(AppDocumentPeer::APP_UID, $sApplication);
    //$oCriteria->add(AppDocumentPeer::DEL_INDEX,    $index);
    $oCriteria->add(AppDocumentPeer::DOC_UID, $outputID);
    $oCriteria->add(AppDocumentPeer::DOC_VERSION, $lastDocVersion);
    $oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT');
    $oDataset = AppDocumentPeer::doSelectRS($oCriteria);
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    $oDataset->next();
    if ($aOD['OUT_DOC_VERSIONING'] && $lastDocVersion != 0) {
        //Create new Version of current output
        $lastDocVersion++;
        if ($aRow = $oDataset->getRow()) {
            $aFields = array('APP_DOC_UID' => $aRow['APP_DOC_UID'], 'APP_UID' => $sApplication, 'DEL_INDEX' => $index, 'DOC_UID' => $outputID, 'DOC_VERSION' => $lastDocVersion + 1, 'USR_UID' => $sUserLogged, 'APP_DOC_TYPE' => 'OUTPUT', 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_FILENAME' => $sFilename, 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
            $oAppDocument = new AppDocument();
            $oAppDocument->create($aFields);
            $sDocUID = $aRow['APP_DOC_UID'];
        }
    } else {
        ////No versioning so Update a current Output or Create new if no exist
        if ($aRow = $oDataset->getRow()) {
            //Update
            $aFields = array('APP_DOC_UID' => $aRow['APP_DOC_UID'], 'APP_UID' => $sApplication, 'DEL_INDEX' => $index, 'DOC_UID' => $outputID, 'DOC_VERSION' => $lastDocVersion, 'USR_UID' => $sUserLogged, 'APP_DOC_TYPE' => 'OUTPUT', 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_FILENAME' => $sFilename, 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
            $oAppDocument = new AppDocument();
            $oAppDocument->update($aFields);
            $sDocUID = $aRow['APP_DOC_UID'];
        } else {
            //we are creating the appdocument row
            //create
            if ($lastDocVersion == 0) {
                $lastDocVersion++;
            }
            $aFields = array('APP_UID' => $sApplication, 'DEL_INDEX' => $index, 'DOC_UID' => $outputID, 'DOC_VERSION' => $lastDocVersion, 'USR_UID' => $sUserLogged, 'APP_DOC_TYPE' => 'OUTPUT', 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_FILENAME' => $sFilename, 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
            $oAppDocument = new AppDocument();
            $aFields['APP_DOC_UID'] = $sDocUID = $oAppDocument->create($aFields);
        }
    }
    $sFilename = $aFields['APP_DOC_UID'] . "_" . $lastDocVersion;
    $pathOutput = PATH_DOCUMENT . G::getPathFromUID($sApplication) . PATH_SEP . 'outdocs' . PATH_SEP;
    //G::pr($sFilename);die;
    G::mk_dir($pathOutput);
    $aProperties = array();
    if (!isset($aOD['OUT_DOC_MEDIA'])) {
        $aOD['OUT_DOC_MEDIA'] = 'Letter';
    }
    if (!isset($aOD['OUT_DOC_LEFT_MARGIN'])) {
        $aOD['OUT_DOC_LEFT_MARGIN'] = '15';
    }
    if (!isset($aOD['OUT_DOC_RIGHT_MARGIN'])) {
        $aOD['OUT_DOC_RIGHT_MARGIN'] = '15';
    }
    if (!isset($aOD['OUT_DOC_TOP_MARGIN'])) {
        $aOD['OUT_DOC_TOP_MARGIN'] = '15';
    }
    if (!isset($aOD['OUT_DOC_BOTTOM_MARGIN'])) {
        $aOD['OUT_DOC_BOTTOM_MARGIN'] = '15';
    }
    $aProperties['media'] = $aOD['OUT_DOC_MEDIA'];
    $aProperties['margins'] = array('left' => $aOD['OUT_DOC_LEFT_MARGIN'], 'right' => $aOD['OUT_DOC_RIGHT_MARGIN'], 'top' => $aOD['OUT_DOC_TOP_MARGIN'], 'bottom' => $aOD['OUT_DOC_BOTTOM_MARGIN']);
    if (isset($aOD['OUT_DOC_REPORT_GENERATOR'])) {
        $aProperties['report_generator'] = $aOD['OUT_DOC_REPORT_GENERATOR'];
    }
    $oOutputDocument->generate($outputID, $Fields['APP_DATA'], $pathOutput, $sFilename, $aOD['OUT_DOC_TEMPLATE'], (bool) $aOD['OUT_DOC_LANDSCAPE'], $aOD['OUT_DOC_GENERATE'], $aProperties);
    //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
    //G::LoadClass('plugin');
    $oPluginRegistry =& PMPluginRegistry::getSingleton();
    if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
        $triggerDetail = $oPluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);
        $aFields['APP_DOC_PLUGIN'] = $triggerDetail->sNamespace;
        $oAppDocument1 = new AppDocument();
        $oAppDocument1->update($aFields);
        $sPathName = PATH_DOCUMENT . G::getPathFromUID($sApplication) . PATH_SEP;
        $oData['APP_UID'] = $sApplication;
        $oData['ATTACHMENT_FOLDER'] = true;
        switch ($aOD['OUT_DOC_GENERATE']) {
            case "BOTH":
                $documentData = new uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion());
                $documentData->sFileType = "PDF";
                $documentData->bUseOutputFolder = true;
                $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                if ($uploadReturn) {
                    //Only delete if the file was saved correctly
                    unlink($pathOutput . $sFilename . '.pdf');
                }
                $documentData = new uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion());
                $documentData->sFileType = "DOC";
                $documentData->bUseOutputFolder = true;
                $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                if ($uploadReturn) {
                    //Only delete if the file was saved correctly
                    unlink($pathOutput . $sFilename . '.doc');
                }
                break;
            case "PDF":
                $documentData = new uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.pdf', $sFilename . '.pdf', $sDocUID, $oAppDocument->getDocVersion());
                $documentData->sFileType = "PDF";
                $documentData->bUseOutputFolder = true;
                $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                if ($uploadReturn) {
                    //Only delete if the file was saved correctly
                    unlink($pathOutput . $sFilename . '.pdf');
                }
                break;
            case "DOC":
                $documentData = new uploadDocumentData($sApplication, $sUserLogged, $pathOutput . $sFilename . '.doc', $sFilename . '.doc', $sDocUID, $oAppDocument->getDocVersion());
                $documentData->sFileType = "DOC";
                $documentData->bUseOutputFolder = true;
                $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
                if ($uploadReturn) {
                    //Only delete if the file was saved correctly
                    unlink($pathOutput . $sFilename . '.doc');
                }
                break;
        }
    }
    $g->sessionVarRestore();
}
$oAppDocument->Fields = $oAppDocument->load($_GET['a'], $docVersion);
$sAppDocUid = $oAppDocument->getAppDocUid();
$iDocVersion = $oAppDocument->getDocVersion();
$info = pathinfo($oAppDocument->getAppDocFilename());
$ext = isset($info['extension']) ? $info['extension'] : '';
//BUG fix: must handle files without any extension
if (isset($_GET['b'])) {
    if ($_GET['b'] == '0') {
        $bDownload = false;
    } else {
        $bDownload = true;
    }
} else {
    $bDownload = true;
}
$app_uid = G::getPathFromUID($oAppDocument->Fields['APP_UID']);
$file = G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $sAppDocUid);
$realPath = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '_' . $iDocVersion . '.' . $ext;
$realPath1 = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '.' . $ext;
$sw_file_exists = false;
if (file_exists($realPath)) {
    $sw_file_exists = true;
} elseif (file_exists($realPath1)) {
    $sw_file_exists = true;
    $realPath = $realPath1;
}
if (!$sw_file_exists) {
    $error_message = G::LoadTranslation('ID_ERROR_STREAMING_FILE');
    if (isset($_POST['request']) && $_POST['request'] == true) {
        $res['success'] = 'failure';
        $res['message'] = $error_message;
示例#11
0
    /**
     * second step for upload file
     * upload file in foler app_uid
     *
     * @param $userUid
     * @param $Fields
     * @param $type
     * @throws \Exception
     */
    public function documentUploadFiles($userUid, $app_uid, $app_doc_uid, $request_data)
    {
        $response = array("status" => "fail");
        if (isset( $_FILES["form"]["name"] ) && count( $_FILES["form"]["name"] ) > 0) {
            $arrayField = array ();
            $arrayFileName = array ();
            $arrayFileTmpName = array ();
            $arrayFileError = array ();
            $i = 0;

            foreach ($_FILES["form"]["name"] as $fieldIndex => $fieldValue) {
                if (is_array( $fieldValue )) {
                    foreach ($fieldValue as $index => $value) {
                        if (is_array( $value )) {
                            foreach ($value as $grdFieldIndex => $grdFieldValue) {
                                $arrayField[$i]["grdName"] = $fieldIndex;
                                $arrayField[$i]["grdFieldName"] = $grdFieldIndex;
                                $arrayField[$i]["index"] = $index;

                                $arrayFileName[$i] = $_FILES["form"]["name"][$fieldIndex][$index][$grdFieldIndex];
                                $arrayFileTmpName[$i] = $_FILES["form"]["tmp_name"][$fieldIndex][$index][$grdFieldIndex];
                                $arrayFileError[$i] = $_FILES["form"]["error"][$fieldIndex][$index][$grdFieldIndex];
                                $i = $i + 1;
                            }
                        }
                    }
                } else {
                    $arrayField[$i] = $fieldIndex;

                    $arrayFileName[$i] = $_FILES["form"]["name"][$fieldIndex];
                    $arrayFileTmpName[$i] = $_FILES["form"]["tmp_name"][$fieldIndex];
                    $arrayFileError[$i] = $_FILES["form"]["error"][$fieldIndex];
                    $i = $i + 1;
                }
            }
            if (count( $arrayField ) > 0) {
                for ($i = 0; $i <= count( $arrayField ) - 1; $i ++) {
                    if ($arrayFileError[$i] == 0) {
                        $indocUid = null;
                        $fieldName = null;
                        $fileSizeByField = 0;

                        $oAppDocument = new \AppDocument();
                        $aAux = $oAppDocument->load($app_doc_uid);

                        $iDocVersion = $oAppDocument->getDocVersion();
                        $sAppDocUid = $oAppDocument->getAppDocUid();
                        $aInfo = pathinfo( $oAppDocument->getAppDocFilename() );
                        $sExtension = ((isset( $aInfo["extension"] )) ? $aInfo["extension"] : "");
                        $pathUID = G::getPathFromUID($app_uid);
                        $sPathName = PATH_DOCUMENT . $pathUID . PATH_SEP;
                        $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $sExtension;
                        G::uploadFile( $arrayFileTmpName[$i], $sPathName, $sFileName );
                        $response = array("status" => "ok");
                    }
                }
            }
        }

        return $response;
    }
示例#12
0
function uploadExternalDocument()
{
    $response['action']=$_POST['action']. " - ".$_POST['option'];
    $response['error']="error";
    $response['message']="error";
    $response['success']=false;
    $overwrite = (isset($_REQUEST['overwrite_files'])) ? $_REQUEST['overwrite_files'] : false;
    if (isset($_POST["confirm"]) && $_POST["confirm"] == "true") {
        if (isset($_FILES['uploadedFile'])) {
            $uploadedInstances=count($_FILES['uploadedFile']['name']);
            $sw_error=false;
            $sw_error_exists=isset($_FILES['uploadedFile']['error']);
            $emptyInstances=0;
            $quequeUpload=array();
            //overwrite files
            if ($overwrite) {
                for ($i=0; $i<$uploadedInstances; $i++) {
                    overwriteFile($_REQUEST['dir'], stripslashes($_FILES['uploadedFile']['name'][$i]));
                }
            }
            // upload files & check for errors
            for ($i=0; $i<$uploadedInstances; $i++) {
                $errors[$i] = null;
                $tmp = $_FILES['uploadedFile']['tmp_name'][$i];
                $items[$i] = stripslashes($_FILES['uploadedFile']['name'][$i]);
                if ($sw_error_exists) {
                    $up_err = $_FILES['uploadedFile']['error'][$i];
                } else {
                    $up_err=(file_exists($tmp)?0:4);
                }
                if ($items[$i]=="" || $up_err==4) {
                    $emptyInstances++;
                    continue;
                }
                if ($up_err==1 || $up_err==2) {
                    $errors[$i]='miscfilesize';
                    $sw_error = true;
                    continue;
                }
                if ($up_err==3) {
                    $errors[$i]='miscfilepart';
                    $sw_error=true;
                    continue;
                }
                if (!@is_uploaded_file($tmp)) {
                    $errors[$i]='uploadfile';
                    $sw_error=true;
                    continue;
                }
                //The uplaoded files seems to be correct and ready to be uploaded. Add to the Queque
                $fileInfo=array("tempName"=>$tmp,"fileName"=>$items[$i]);
                $quequeUpload[]=$fileInfo;
            }
        } elseif (isset($_POST['selitems'])) {
            $response="";
            $response['msg']= "correct reload";
            $response['success']=true;
            if (isset($_REQUEST['option']) && isset($_REQUEST['copyMove'])) {
                if ($_REQUEST['option'] == 'directory' && $_REQUEST['copyMove'] == 'all') {
                    $response['action'] = $_POST['action']. " - ".$_POST['option'];
                    $response['error']  = "Complete";
                    $response['message']= str_replace("Execute", "", $_POST['action']). " ". "Complete";
                    $response['success']= 'success';
                    $response['node']   = '';
                    $_POST ['node']     = "";
                    $newFolderUid = checkTree($_REQUEST['dir'], $_REQUEST['new_dir']);
                }
                $_POST['selitems'] = array();
            } else {
                require_once ("classes/model/AppDocument.php");
                $oAppDocument = new AppDocument();
                if (isset($_POST['selitems']) && is_array($_POST['selitems'])) {
                    foreach ($_POST['selitems'] as $docId) {
                        $arrayDocId = explode ('_',$docId);
                        $docInfo=$oAppDocument->load($arrayDocId[0]);
                        $docInfo['FOLDER_UID'] =  $_POST['new_dir'];
                        $docInfo['APP_DOC_CREATE_DATE'] = date('Y-m-d H:i:s');
                        $oAppDocument->update($docInfo);
                    }
                }
            }
        }
        //G::pr($quequeUpload);

        //Read. Instance Document classes
        if (!empty($quequeUpload)) {
            $docUid=$_POST['docUid'];
            $appDocUid=isset($_POST['APP_DOC_UID'])?$_POST['APP_DOC_UID']:"";
            $docVersion=isset($_POST['docVersion'])?$_POST['docVersion']:"";
            $actionType=isset($_POST['actionType'])?$_POST['actionType']:"";
            $folderId=$_POST['dir']==""?"/":$_POST['dir'];
            $appId=$_POST['appId'];
            $docType=isset($_POST['docType'])?$_GET['docType']:"INPUT";
            //save info

            require_once ("classes/model/AppDocument.php");
            require_once ('classes/model/AppFolder.php');
            require_once ('classes/model/InputDocument.php');

            $oInputDocument = new InputDocument();
            if ($docUid != -1) {
                $aID = $oInputDocument->load($docUid);
            } else {
                $oFolder=new AppFolder();
                $folderStructure=$oFolder->getFolderStructure($folderId);
                $aID=array('INP_DOC_DESTINATION_PATH'=>$folderStructure['PATH']);
            }



            //Get the Custom Folder ID (create if necessary)
            $oFolder=new AppFolder();
            if ($docUid!=-1) {
                //krumo("jhl");
                $folderId=$oFolder->createFromPath($aID['INP_DOC_DESTINATION_PATH'],$appId);
                //Tags
                $fileTags=$oFolder->parseTags($aID['INP_DOC_TAGS'],$appId);
            } else {
                $folderId=$folderId;
                $fileTags="EXTERNAL";
            }
            foreach ($quequeUpload as $key => $fileObj) {
                $oAppDocument = new AppDocument();
                switch ($actionType) {
                    case "R":
                        //replace
                        $aFields = array(
                            'APP_DOC_UID'           => $appDocUid,
                            'APP_UID'               => $appId,
                            'DOC_VERSION'           => $docVersion,
                            'DEL_INDEX'             => 1,
                            'USR_UID'               => $_SESSION['USER_LOGGED'],
                            'DOC_UID'               => $docUid,
                            'APP_DOC_TYPE'          => $docType,
                            'APP_DOC_CREATE_DATE'   => date('Y-m-d H:i:s'),
                            'APP_DOC_COMMENT'       => isset($_POST['form']['APP_DOC_COMMENT']) ?
                                $_POST['form']['APP_DOC_COMMENT'] : '',
                            'APP_DOC_TITLE'         => '',
                            'APP_DOC_FILENAME'      => $fileObj['fileName'],
                            'FOLDER_UID'            => $folderId,
                            'APP_DOC_TAGS'          => $fileTags
                        );
                        $oAppDocument->update($aFields);
                        break;
                    case "NV":
                        //New Version
                        $aFields = array(
                            'APP_DOC_UID'           => $appDocUid,
                            'APP_UID'               => $appId,
                            'DEL_INDEX'             => 1,
                            'USR_UID'               => $_SESSION['USER_LOGGED'],
                            'DOC_UID'               => $docUid,
                            'APP_DOC_TYPE'          => $docType,
                            'APP_DOC_CREATE_DATE'   => date('Y-m-d H:i:s'),
                            'APP_DOC_COMMENT'       => isset($_POST['form']['APP_DOC_COMMENT']) ?
                                $_POST['form']['APP_DOC_COMMENT'] : '',
                            'APP_DOC_TITLE'         => '',
                            'APP_DOC_FILENAME'      => $fileObj['fileName'],
                            'FOLDER_UID'            => $folderId,
                            'APP_DOC_TAGS'          => $fileTags
                        );
                        $oAppDocument->create($aFields);
                        break;
                    default:
                        //New
                        $aFields = array(
                            'APP_UID'               => $appId,
                            'DEL_INDEX'             => isset($_SESSION['INDEX'])?$_SESSION['INDEX']:1,
                            'USR_UID'               => $_SESSION['USER_LOGGED'],
                            'DOC_UID'               => $docUid,
                            'APP_DOC_TYPE'          => $docType,
                            'APP_DOC_CREATE_DATE'   => date('Y-m-d H:i:s'),
                            'APP_DOC_COMMENT'       => isset($_POST['form']['APP_DOC_COMMENT']) ?
                                $_POST['form']['APP_DOC_COMMENT'] : '',
                            'APP_DOC_TITLE'         => '',
                            'APP_DOC_FILENAME'      => $fileObj['fileName'],
                            'FOLDER_UID'            => $folderId,
                            'APP_DOC_TAGS'          => $fileTags
                        );
                        $oAppDocument->create($aFields);
                        break;
                }
                $sAppDocUid = $oAppDocument->getAppDocUid();
                $iDocVersion = $oAppDocument->getDocVersion();

                $info = pathinfo($oAppDocument->getAppDocFilename());
                $ext = (isset($info['extension']) ? $info['extension'] : '');
                //save the file
                //if (!empty($_FILES['form'])) {
                //if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) {
                $sPathName = PATH_DOCUMENT . G::getPathFromUID($appId) . PATH_SEP;
                $file = G::getPathFromFileUID($appId, $sAppDocUid);
                $sPathName .= $file[0];
                $sFileName = $file[1] . "_" . $iDocVersion . '.' . $ext;

                G::uploadFile($fileObj['tempName'], $sPathName, $sFileName); //upload

                //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
                $oPluginRegistry =& PMPluginRegistry::getSingleton();
                if ($oPluginRegistry->existsTrigger (PM_UPLOAD_DOCUMENT) && class_exists ('uploadDocumentData')) {
                    $oData['APP_UID']   = $appId;
                    $documentData = new uploadDocumentData (
                        $appId,
                        $_SESSION['USER_LOGGED'],
                        $sPathName . $sFileName,
                        $fileObj['fileName'],
                        $sAppDocUid
                    );
                    //$oPluginRegistry->executeTriggers (PM_UPLOAD_DOCUMENT , $documentData);
                    //unlink ($sPathName . $sFileName);
                }
                //end plugin
                if ($sw_error) {
                    // there were errors
                    $err_msg="";
                    for ($i=0; $i<$uploadedInstances; $i++) {
                        if ($errors[$i]==null) {
                            continue;
                        }
                        $err_msg .= $items[$i]." : ".$errors[$i]."\n";
                    }
                    $response['error']=$err_msg;
                    $response['message']=$err_msg;
                    $response['success']=false;
                } elseif ($emptyInstances==$uploadedInstances) {
                    $response['error']= G::LoadTranslation('ID_UPLOAD_LEAST_FILE');
                    $response['message']= G::LoadTranslation('ID_UPLOAD_LEAST_FILE');
                    $response['success']=false;
                } else {
                    $response['error']= G::LoadTranslation('ID_UPLOAD_COMPLETE');
                    $response['message']="Upload complete";
                    $response['success']=true;
                }
            }
        }
    }
    print_r(G::json_encode($response));
    /*
     G::LoadClass ('case');
     $oCase = new Cases ();

     $G_PUBLISH = new Publisher ();
     $Fields ['DOC_UID'] = "-1";

     $Fields ['appId'] = "00000000000000000000000000000000";

     $G_PUBLISH->AddContent ('xmlform', 'xmlform', 'cases/cases_AttachInputDocumentGeneral', '', $Fields,
     'appFolderSaveDocument?UID=-1&appId=' . $Fields ['appId'] . "&folderId=" . $_POST ['folderID']);
     G::RenderPage ('publish', 'raw');
     */
}
示例#13
0
     $aFields["APP_DOC_TITLE"] = isset($_POST["TITLE"]) ? $_POST["TITLE"] : "";
     //$aFields["FOLDER_UID"] = $folderId,
     //$aFields["APP_DOC_TAGS"] = $fileTags
     $aFields["APP_DOC_FIELDNAME"] = $_POST["APP_DOC_FIELDNAME"];
 } else {
     //New record
     $aFields = array("APP_UID" => $_POST["APPLICATION"], "DEL_INDEX" => $_POST["INDEX"], "USR_UID" => $_POST["USR_UID"], "DOC_UID" => $_POST["DOC_UID"], "APP_DOC_TYPE" => $_POST["APP_DOC_TYPE"], "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), "APP_DOC_COMMENT" => isset($_POST["COMMENT"]) ? $_POST["COMMENT"] : "", "APP_DOC_TITLE" => isset($_POST["TITLE"]) ? $_POST["TITLE"] : "", "APP_DOC_FILENAME" => isset($_FILES["ATTACH_FILE"]["name"]) ? $_FILES["ATTACH_FILE"]["name"] : "", "FOLDER_UID" => $folderId, "APP_DOC_TAGS" => $fileTags, "APP_DOC_FIELDNAME" => isset($_POST["APP_DOC_FIELDNAME"]) ? $_POST["APP_DOC_FIELDNAME"] : (isset($_FILES["ATTACH_FILE"]["name"]) ? $_FILES["ATTACH_FILE"]["name"] : ""));
 }
 $oAppDocument->create($aFields);
 $sAppUid = $oAppDocument->getAppUid();
 $sAppDocUid = $oAppDocument->getAppDocUid();
 $iDocVersion = $oAppDocument->getDocVersion();
 $info = pathinfo($oAppDocument->getAppDocFilename());
 $ext = isset($info["extension"]) ? $info["extension"] : "";
 //Save the file
 echo $sPathName = PATH_DOCUMENT . G::getPathFromUID($sAppUid) . PATH_SEP;
 echo $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $ext;
 print G::uploadFile($_FILES["ATTACH_FILE"]["tmp_name"], $sPathName, $sFileName);
 print "* The file " . $_FILES["ATTACH_FILE"]["name"] . " was uploaded successfully in case " . $sAppUid . " as input document..\n";
 //Get current Application Fields
 $application = new Application();
 $appFields = $application->Load($_POST["APPLICATION"]);
 $appFields = unserialize($appFields["APP_DATA"]);
 $_SESSION["APPLICATION"] = $appFields["APPLICATION"];
 $_SESSION["PROCESS"] = $appFields["PROCESS"];
 $_SESSION["TASK"] = $appFields["TASK"];
 $_SESSION["INDEX"] = $appFields["INDEX"];
 $_SESSION["USER_LOGGED"] = $appFields["USER_LOGGED"];
 //$_POST["USR_UID"]
 //$_SESSION["USR_USERNAME"]  = $appFields["USR_USERNAME"];
 //$_SESSION["STEP_POSITION"] = 0;
         $oAppDocument->create($aFields);
         break;
     default:
         //New
         $aFields = array('APP_UID' => $appId, 'DEL_INDEX' => isset($_SESSION['INDEX']) ? $_SESSION['INDEX'] : 1, 'USR_UID' => $_SESSION['USER_LOGGED'], 'DOC_UID' => $docUid, 'APP_DOC_TYPE' => $_POST['form']['APP_DOC_TYPE'], 'APP_DOC_CREATE_DATE' => date('Y-m-d H:i:s'), 'APP_DOC_COMMENT' => isset($_POST['form']['APP_DOC_COMMENT']) ? $_POST['form']['APP_DOC_COMMENT'] : '', 'APP_DOC_TITLE' => '', 'APP_DOC_FILENAME' => isset($_FILES['form']['name']['APP_DOC_FILENAME']) ? $_FILES['form']['name']['APP_DOC_FILENAME'] : '', 'FOLDER_UID' => $folderId, 'APP_DOC_TAGS' => $fileTags);
         $oAppDocument->create($aFields);
         break;
 }
 $sAppDocUid = $oAppDocument->getAppDocUid();
 $iDocVersion = $oAppDocument->getDocVersion();
 $info = pathinfo($oAppDocument->getAppDocFilename());
 $ext = isset($info['extension']) ? $info['extension'] : '';
 //save the file
 if (!empty($_FILES['form'])) {
     if ($_FILES['form']['error']['APP_DOC_FILENAME'] == 0) {
         $sPathName = PATH_DOCUMENT . G::getPathFromUID($appId) . PATH_SEP;
         $sFileName = $sAppDocUid . "_" . $iDocVersion . '.' . $ext;
         G::uploadFile($_FILES['form']['tmp_name']['APP_DOC_FILENAME'], $sPathName, $sFileName);
         //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
         $oPluginRegistry =& PMPluginRegistry::getSingleton();
         if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
             $oData['APP_UID'] = $appId;
             $documentData = new uploadDocumentData($appId, $_SESSION['USER_LOGGED'], $sPathName . $sFileName, $aFields['APP_DOC_FILENAME'], $sAppDocUid);
             $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
             unlink($sPathName . $sFileName);
         }
         //end plugin
     }
 }
 G::header('location: appFolderList');
 die;
示例#15
0
    /**

     * Add a input document

     *

     * Return the application document ID

     *

     * @param string $inputDocumentUid Input document ID

     * @param string $appDocUid Application document ID

     * @param int $docVersion Document version

     * @param string $appDocType Document type

     * @param string $appDocComment Document comment

     * @param string $inputDocumentAction Action, posible values: null or empty (Add), "R" (Replace), "NV" (New Version)

     * @param string $applicationUid Application ID

     * @param int $delIndex Delegation index

     * @param string $taskUid Task ID

     * @param string $userUid User ID

     * @param string $option Option, posible values: "xmlform", "file"

     * @param string $file File ($_FILES["form"]["name"]["APP_DOC_FILENAME"] or path to file)

     * @param int $fileError File error ($_FILES["form"]["error"]["APP_DOC_FILENAME"] or 0)

     * @param string $fileTmpName File temporal name ($_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"] or null)

     * @param string $fileSize    File size ($_FILES["form"]["size"]["APP_DOC_FILENAME"] or 0)

     * @return string Return application document ID

     */

    public function addInputDocument($inputDocumentUid, $appDocUid, $docVersion, $appDocType, $appDocComment, $inputDocumentAction, $applicationUid, $delIndex, $taskUid, $userUid, $option, $file, $fileError = 0, $fileTmpName = null, $fileSize = 0)

    {

        $appDocFileName = null;

        $sw = 0;



        switch ($option) {

            case "xmlform":

                $appDocFileName = $file;



                if ($fileError == 0) {

                    $sw = 1;

                }

                break;

            case "file":

                $appDocFileName = basename($file);



                if (file_exists($file) && is_file($file)) {

                    $sw = 1;

                }

                break;

        }



        if ($sw == 0) {

            return null;

        }



        //Info

        $inputDocument = new InputDocument();

        $arrayInputDocumentData = $inputDocument->load($inputDocumentUid);



        //--- Validate Filesize of $_FILE

        $inpDocMaxFilesize = $arrayInputDocumentData["INP_DOC_MAX_FILESIZE"];

        $inpDocMaxFilesizeUnit = $arrayInputDocumentData["INP_DOC_MAX_FILESIZE_UNIT"];



        $inpDocMaxFilesize = $inpDocMaxFilesize * (($inpDocMaxFilesizeUnit == "MB")? 1024 *1024 : 1024); //Bytes



        if ($inpDocMaxFilesize > 0 && $fileSize > 0) {

            if ($fileSize > $inpDocMaxFilesize) {

                throw new Exception(G::LoadTranslation("ID_SIZE_VERY_LARGE_PERMITTED"));

            }

        }



        //Get the Custom Folder ID (create if necessary)

        $appFolder = new AppFolder();

        $folderId = $appFolder->createFromPath($arrayInputDocumentData["INP_DOC_DESTINATION_PATH"], $applicationUid);



        $tags = $appFolder->parseTags($arrayInputDocumentData["INP_DOC_TAGS"], $applicationUid);



        $appDocument = new AppDocument();

        $arrayField = array();



        switch ($inputDocumentAction) {

            case "R":

                //Replace

                $arrayField = array(

                    "APP_DOC_UID" => $appDocUid,

                    "APP_UID" => $applicationUid,

                    "DOC_VERSION" => $docVersion,

                    "DEL_INDEX" => $delIndex,

                    "USR_UID" => $userUid,

                    "DOC_UID" => $inputDocumentUid,

                    "APP_DOC_TYPE" => $appDocType,

                    "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),

                    "APP_DOC_COMMENT" => $appDocComment,

                    "APP_DOC_TITLE" => "",

                    "APP_DOC_FILENAME" => $appDocFileName,

                    "FOLDER_UID" => $folderId,

                    "APP_DOC_TAGS" => $tags

                );



                $appDocument->update($arrayField);

                break;

            case "NV":

                //New Version

                $arrayField = array(

                    "APP_DOC_UID" => $appDocUid,

                    "APP_UID" => $applicationUid,

                    "DEL_INDEX" => $delIndex,

                    "USR_UID" => $userUid,

                    "DOC_UID" => $inputDocumentUid,

                    "APP_DOC_TYPE" => $appDocType,

                    "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),

                    "APP_DOC_COMMENT" => $appDocComment,

                    "APP_DOC_TITLE" => "",

                    "APP_DOC_FILENAME" => $appDocFileName,

                    "FOLDER_UID" => $folderId,

                    "APP_DOC_TAGS" => $tags

                );



                $appDocument->create($arrayField);

                break;

            default:

                //New

                $arrayField = array(

                    "APP_UID" => $applicationUid,

                    "DEL_INDEX" => $delIndex,

                    "USR_UID" => $userUid,

                    "DOC_UID" => $inputDocumentUid,

                    "APP_DOC_TYPE" => $appDocType,

                    "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),

                    "APP_DOC_COMMENT" => $appDocComment,

                    "APP_DOC_TITLE" => "",

                    "APP_DOC_FILENAME" => $appDocFileName,

                    "FOLDER_UID" => $folderId,

                    "APP_DOC_TAGS" => $tags

                );



                $appDocument->create($arrayField);

                break;

        }



        //Save the file

        $appDocUid = $appDocument->getAppDocUid();

        $docVersion = $appDocument->getDocVersion();

        $arrayInfo = pathinfo($appDocument->getAppDocFilename());

        $extension = (isset($arrayInfo["extension"])) ? $arrayInfo["extension"] : null;

        $strPathName = PATH_DOCUMENT . G::getPathFromUID($applicationUid) . PATH_SEP;

        $strFileName = $appDocUid . "_" . $docVersion . "." . $extension;



        switch ($option) {

            case "xmlform":

                G::uploadFile($fileTmpName, $strPathName, $strFileName);

                break;

            case "file":

                $umaskOld = umask(0);



                if (!is_dir($strPathName)) {

                    G::verifyPath($strPathName, true);

                }



                G::LoadSystem('inputfilter');

                $filter = new InputFilter();

                $file = $filter->xssFilterHard($file, 'path');



                copy($file, $strPathName . $strFileName);

                chmod($strPathName . $strFileName, 0666);

                umask($umaskOld);

                break;

        }



        //Plugin Hook PM_UPLOAD_DOCUMENT for upload document

        $pluginRegistry = &PMPluginRegistry::getSingleton();



        if ($pluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists("uploadDocumentData")) {

            $triggerDetail = $pluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);

            $documentData = new uploadDocumentData(

                            $applicationUid,

                            $userUid,

                            $strPathName . $strFileName,

                            $arrayField["APP_DOC_FILENAME"],

                            $appDocUid,

                            $docVersion

            );

            $uploadReturn = $pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);



            if ($uploadReturn) {

                $arrayField["APP_DOC_PLUGIN"] = $triggerDetail->sNamespace;



                if (!isset($arrayField["APP_DOC_UID"])) {

                    $arrayField["APP_DOC_UID"] = $appDocUid;

                }



                if (!isset($arrayField["DOC_VERSION"])) {

                    $arrayField["DOC_VERSION"] = $docVersion;

                }



                $appDocument->update($arrayField);



                unlink($strPathName . $strFileName);

            }

        }

        //End plugin



        return $appDocUid;

    }
    $ext = $info['extension'];
} else {
    if ($_GET['ext'] != '') {
        $ext = $_GET['ext'];
    } else {
        $ext = $info['extension'];
    }
}
$ver = isset($_GET['v']) && $_GET['v'] != '' ? '_' . $_GET['v'] : '';
if (!$ver) {
    //This code is in the case the outputdocument won't be versioned
    $ver = '_1';
}
$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;
$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;
}
if (!$sw_file_exists) {
    $oPluginRegistry =& PMPluginRegistry::getSingleton();
    if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT)) {
        $error_message = G::LoadTranslation('ID_ERROR_FILE_NOT_EXIST', SYS_LANG, array('filename' => $info['basename'] . $ver . '.' . $ext)) . ' ' . G::LoadTranslation('ID_CONTACT_ADMIN');
    } else {
示例#17
0
    public function getCompleteDocumentInfo ($appUid, $appDocUid, $docVersion, $docUid, $usrId)
    {
        //require_once ("classes/model/AppDocument.php");
        //require_once ("classes/model/InputDocument.php");
        //require_once ("classes/model/OutputDocument.php");
        //require_once ("classes/model/Users.php");

        //**** start get Doc Info
        $oApp = new Application();
        $oAppDocument = new AppDocument();
        G::LoadClass( 'case' );
        $oCase = new Cases();
        G::LoadClass( 'process' );
        $oProcess = new Process();
        if (($oApp->exists( $appUid )) || ($appUid == "00000000000000000000000000000000")) {
            if ($appUid == "00000000000000000000000000000000") {
                //External Files
                $row1 = $oAppDocument->load( $appDocUid, $docVersion );
                $row2 = array ('PRO_TITLE' => G::LoadTranslation( 'ID_NOT_PROCESS_RELATED' ));
                $row3 = array ('APP_TITLE' => G::LoadTranslation( 'ID_NOT_PROCESS_RELATED' ));
            } else {
                $row1 = $oAppDocument->load( $appDocUid, $docVersion );
                $row2 = $oCase->loadCase( $appUid );
                $row3 = $oProcess->Load( $row2['PRO_UID'] );
            }
            $lastVersion = $oAppDocument->getLastAppDocVersion( $appDocUid, $appUid );

            switch ($row1['APP_DOC_TYPE']) {
                case "OUTPUT":
                    $oOutputDocument = new OutputDocument();

                    $row4 = array();
                    $swOutDocExists = 0;

                    if ($oOutputDocument->OutputExists($docUid)) {
                        $row4 = $oOutputDocument->load($docUid);
                        $swOutDocExists = 1;
                    }

                    if ($swOutDocExists == 0) {
                        $swpdf = 0;
                        $swdoc = 0;

                        $info = pathinfo($oAppDocument->getAppDocFilename());

                        $version = (!empty($docVersion))? "_" . $docVersion : "_1";
                        $outDocPath = PATH_DOCUMENT . G::getPathFromUID($row1["APP_UID"]) . PATH_SEP . "outdocs" . PATH_SEP;

                        if (file_exists($outDocPath . $appDocUid . $version . ".pdf") ||
                            file_exists($outDocPath . $info["basename"] . $version . ".pdf") ||
                            file_exists($outDocPath . $info["basename"] . ".pdf")
                        ) {
                            $swpdf = 1;
                        }

                        if (file_exists($outDocPath . $appDocUid . $version . ".doc") ||
                            file_exists($outDocPath . $info["basename"] . $version . ".doc") ||
                            file_exists($outDocPath . $info["basename"] . ".doc")
                        ) {
                            $swdoc = 1;
                        }

                        if ($swpdf == 1 && $swdoc == 1) {
                            $row4["OUT_DOC_GENERATE"] = "BOTH";
                        } else {
                            if ($swpdf == 1) {
                                $row4["OUT_DOC_GENERATE"] = "PDF";
                            } else {
                                if ($swdoc == 1) {
                                    $row4["OUT_DOC_GENERATE"] = "DOC";
                                } else {
                                    $row4["OUT_DOC_GENERATE"] = "NOFILE";
                                }
                            }
                        }
                    }

                    $versioningEnabled = false; //$row4['OUT_DOC_VERSIONING']; //Only enabled for Input or Attached documents. Need to study the best way for Output docs.

                    switch ($row4['OUT_DOC_GENERATE']) {
                        case "PDF":
                            $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand();
                            $downloadLink1 = "";
                            $downloadLabel = ".pdf";
                            $downloadLabel1 = "";
                            break;
                        case "DOC":
                            $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand();
                            $downloadLink1 = "";
                            $downloadLabel = ".doc";
                            $downloadLabel1 = "";
                            break;
                        case "BOTH":
                            $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand();
                            $downloadLink1 = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand();
                            $downloadLabel = ".pdf";
                            $downloadLabel1 = ".doc";
                            break;
                        case "NOFILE":
                            $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
                            $downloadLink1 = "";
                            $downloadLabel = G::LoadTranslation("ID_DOWNLOAD");
                            $downloadLabel1 = "";
                            break;
                    }

                    if ($swOutDocExists == 0) {
                        $row4 = array();
                    }
                    break;
                case "INPUT":
                    $oInputDocument = new InputDocument();
                    if ($docUid != - 1) {
                        if ($oInputDocument->InputExists( $docUid )) {
                            $row4 = $oInputDocument->load( $docUid );
                            $versioningEnabled = $row4['INP_DOC_VERSIONING'];
                        } else {
                            $row4 = array ();
                            $versioningEnabled = false;
                        }
                        $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
                        $downloadLink1 = "";
                        $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
                        $downloadLabel1 = "";
                    } else {
                        $row4 = array ();
                        $versioningEnabled = false;
                        $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
                        $downloadLink1 = "";
                        $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
                        $downloadLabel1 = "";
                    }

                    if (! empty( $row1["APP_DOC_PLUGIN"] )) {
                        $pluginRegistry = &PMPluginRegistry::getSingleton();
                        $pluginName = $row1["APP_DOC_PLUGIN"];
                        $fieldValue = "";

                        if (file_exists( PATH_PLUGINS . $pluginName . ".php" )) {
                            $pluginDetail = $pluginRegistry->getPluginDetails( $pluginName . ".php" );

                            if ($pluginDetail) {
                                if ($pluginDetail->enabled) {
                                    require_once (PATH_PLUGINS . $pluginName . ".php");
                                    $pluginNameClass = $pluginName . "Plugin";
                                    $objPluginClass = new $pluginNameClass( $pluginName );

                                    if (isset( $objPluginClass->sMethodGetUrlDownload ) && ! empty( $objPluginClass->sMethodGetUrlDownload )) {
                                        if (file_exists( PATH_PLUGINS . $pluginName . PATH_SEP . "class." . $pluginName . ".php" )) {
                                            require_once (PATH_PLUGINS . $pluginName . PATH_SEP . "class." . $pluginName . ".php");
                                            $pluginNameClass = $pluginName . "Class";
                                            $objClass = new $pluginNameClass();

                                            if (method_exists( $objClass, $objPluginClass->sMethodGetUrlDownload )) {
                                                eval( "\$url = \$objClass->" . $objPluginClass->sMethodGetUrlDownload . "(\"" . $row1["APP_DOC_UID"] . "\");" );
                                                $downloadLink = $url;
                                                $fieldValue = $row1["APP_DOC_PLUGIN"];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        $row1["APP_DOC_PLUGIN"] = $fieldValue;
                    }
                    break;
                default:
                    $row4 = array ();
                    $versioningEnabled = false;
                    $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
                    $downloadLink1 = "";
                    $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
                    $downloadLabel1 = "";
                    break;
            }
            $oUser = new Users();
            if (($usrId != "-1") && ($oUser->userExists( $usrId ))) {
                $row5 = $oUser->load( $usrId );
            } else {
                $row5['USR_USERNAME'] = "******";
            }

            //Labels/Links
            $row6 = array ();
            $row6['DELETE_LABEL'] = G::LoadTranslation( 'ID_DELETE' );
            $row6['DOWNLOAD_LABEL'] = $downloadLabel;
            $row6['DOWNLOAD_LINK'] = $downloadLink;
            $row6['DOWNLOAD_LABEL1'] = $downloadLabel1;
            $row6['DOWNLOAD_LINK1'] = $downloadLink1;
            //if(($docVersion>1)&&($row1['APP_DOC_TYPE']!="OUTPUT")){
            if (($docVersion > 1)) {
                $row6['VERSIONHISTORY_LABEL'] = G::LoadTranslation( 'ID_VERSION_HISTORY' );
            }
            if ($versioningEnabled) {
                $row6['NEWVERSION_LABEL'] = G::LoadTranslation( 'ID_NEW_VERSION' );
            }
            $row6['APP_DOC_UID_VERSION'] = $appDocUid . "_" . $docVersion;

            if ($appUid == "00000000000000000000000000000000") {
                //External Files
                $row1['APP_DOC_TYPE'] = G::LoadTranslation( 'ID_EXTERNAL_FILE' );
            }
            //**** End get docinfo
            $infoMerged = array_merge( $row1, $row2, $row3, $row4, $row5, $row6 );

            $sUserUID = $_SESSION['USER_LOGGED'];
            $aObjectPermissions = array ();
            if (isset( $infoMerged['PRO_UID'] )) {
                $aObjectPermissions = $oCase->getAllObjects( $infoMerged['PRO_UID'], $infoMerged['APP_UID'], '', $sUserUID );
            }

            if (! is_array( $aObjectPermissions )) {
                $aObjectPermissions = array ('DYNAFORMS' => array (- 1),
                'INPUT_DOCUMENTS' => array (- 1),
                'OUTPUT_DOCUMENTS' => array (- 1)
                );
            }
            if (! isset( $aObjectPermissions['DYNAFORMS'] )) {
                $aObjectPermissions['DYNAFORMS'] = array (- 1);
            } else {
                if (! is_array( $aObjectPermissions['DYNAFORMS'] )) {
                    $aObjectPermissions['DYNAFORMS'] = array (- 1);
                }
            }
            if (! isset( $aObjectPermissions['INPUT_DOCUMENTS'] )) {
                $aObjectPermissions['INPUT_DOCUMENTS'] = array (- 1);
            } else {
                if (! is_array( $aObjectPermissions['INPUT_DOCUMENTS'] )) {
                    $aObjectPermissions['INPUT_DOCUMENTS'] = array (- 1);
                }
            }
            if (! isset( $aObjectPermissions['OUTPUT_DOCUMENTS'] )) {
                $aObjectPermissions['OUTPUT_DOCUMENTS'] = array (- 1);
            } else {
                if (! is_array( $aObjectPermissions['OUTPUT_DOCUMENTS'] )) {
                    $aObjectPermissions['OUTPUT_DOCUMENTS'] = array (- 1);
                }
            }
            return array_merge( $infoMerged, $aObjectPermissions );
        }
    }
示例#18
0
    /**
     * @url POST /case/:app_uid/upload/location
     *
     * @param string $app_uid      { @min 32}{@max 32}
     * @param float $latitude      {@min -90}{@max 90}
     * @param float $longitude     {@min -180}{@max 180}
     */
    public function postInputDocumentLocation($app_uid, $latitude, $longitude)
    {
        try {
            $userUid       = $this->getUserId();
            $oMobile       = new \ProcessMaker\BusinessModel\Light();

            $url           = "http://maps.googleapis.com/maps/api/staticmap?center=".$latitude.','.$longitude."&format=jpg&size=600x600&zoom=15&markers=color:blue%7Clabel:S%7C".$latitude.','.$longitude;
            $imageLocation = imagecreatefromjpeg($url);
            $tmpfname = tempnam("php://temp","pmm");
            imagejpeg($imageLocation, $tmpfname);

            $_FILES["form"]["type"] = "image/jpeg";
            $_FILES["form"]["name"] = 'Location.jpg';
            $_FILES["form"]["tmp_name"] = $tmpfname;
            $_FILES["form"]["error"] = 0;
            $sizes = getimagesize($tmpfname);
            $_FILES["form"]["size"] = ($sizes['0'] * $sizes['1']);

            $request_data = array(array('name' => $_FILES["form"]["name"]));
            $file = $oMobile->postUidUploadFiles($userUid, $app_uid, $request_data);

            $strPathName = PATH_DOCUMENT . G::getPathFromUID($app_uid) . PATH_SEP;
            $strFileName = $file[0]['appDocUid'] . "_" . $file[0]['docVersion'] . ".jpg";
            if (! is_dir( $strPathName )) {
                G::verifyPath( $strPathName, true );
            }
            copy($tmpfname, $strPathName . $strFileName);
            unlink($tmpfname);
        } catch (\Exception $e) {
            throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
        }
        return $file;
    }
 $app_uid = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
 $inp_doc_uid = isset($_REQUEST['d']) ? $_REQUEST['d'] : null;
 $oAppDocument = new \AppDocument();
 if (!isset($fileData['version'])) {
     $docVersion = $oAppDocument->getLastAppDocVersion($inp_doc_uid);
 } else {
     $docVersion = $fileData['version'];
 }
 $oAppDocument->Fields = $oAppDocument->load($inp_doc_uid, $docVersion);
 $sAppDocUid = $oAppDocument->getAppDocUid();
 $iDocVersion = $oAppDocument->getDocVersion();
 $info = pathinfo($oAppDocument->getAppDocFilename());
 $ext = isset($info['extension']) ? $info['extension'] : '';
 $file = \G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $sAppDocUid);
 $realPath = PATH_DOCUMENT . G::getPathFromUID($app_uid) . '/' . $file[0] . $file[1] . '_' . $iDocVersion . '.' . $ext;
 $realPath1 = PATH_DOCUMENT . G::getPathFromUID($app_uid) . '/' . $file[0] . $file[1] . '.' . $ext;
 if (file_exists($realPath)) {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mimeType = finfo_file($finfo, $realPath);
     finfo_close($finfo);
     if ($ext == "mp3") {
         $mimeType = "audio/mpeg";
     }
     rangeDownload($realPath, $mimeType);
 } elseif (file_exists($realPath1)) {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mimeType = finfo_file($finfo, $realPath1);
     finfo_close($finfo);
     if ($ext == "mp3") {
         $mimeType = "audio/mpeg";
     }