/** * 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; } }
G::LoadClass("pmDrive"); $pmDrive = new PMDrive(); if ($pmDrive->getStatusService()) { $app = new Application(); $user = new Users(); $dataUser = $user->load($_SESSION['USER_LOGGED']); $pmDrive->setDriveUser($dataUser['USR_EMAIL']); $appData = $app->Load($_SESSION['APPLICATION']); 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($_SESSION['USER_LOGGED'])); $appData['APP_DRIVE_FOLDER_UID'] = $result->id; $app->update($appData); } $result = $pmDrive->uploadFile('application/' . $sExtension, $arrayFileTmpName[$i], $arrayFileName[$i], $appData['APP_DRIVE_FOLDER_UID']); $oAppDocument->setDriveDownload('ATTACHED', $result->webContentLink); $fileIdDrive = $result->id; $aFields['DOC_VERSION'] = $iDocVersion; $aFields['APP_DOC_UID'] = $sAppDocUid; $oAppDocument->update($aFields); //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, $_SESSION['APPLICATION']); $criteria->addJoin(ApplicationPeer::PRO_UID, TaskPeer::PRO_UID, Criteria::LEFT_JOIN); $criteria->addJoin(TaskPeer::TAS_UID, TaskUserPeer::TAS_UID, Criteria::LEFT_JOIN); $dataset = TaskUserPeer::doSelectRs($criteria);
$dataUser = $user->load($_SESSION['USER_LOGGED']); $pmDrive->setDriveUser($dataUser['USR_EMAIL']); $applicationUid = $_SESSION['APPLICATION']; $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($_SESSION['USER_LOGGED'])); $appData['APP_DRIVE_FOLDER_UID'] = $result->id; $app->update($appData); } $fileIdDriveDoc = ''; $fileIdDrivePdf = ''; 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;