diff --git a/workflow/engine/src/BusinessModel/Cases/InputDocument.php b/workflow/engine/src/BusinessModel/Cases/InputDocument.php index e4ed6410a..745a79399 100644 --- a/workflow/engine/src/BusinessModel/Cases/InputDocument.php +++ b/workflow/engine/src/BusinessModel/Cases/InputDocument.php @@ -119,12 +119,13 @@ class InputDocument * * @param string $applicationUid * @param string $taskUid + * @param string $appDocComment * @param string $inputDocumentUid * @param string $userUid * * return array Return an array with data of an InputDocument */ - public function addCasesInputDocument($applicationUid, $taskUid, $inputDocumentUid, $userUid) + public function addCasesInputDocument($applicationUid, $taskUid, $appDocComment, $inputDocumentUid, $userUid) { try { if ((isset( $_FILES['form'] )) && ($_FILES['form']['error'] != 0)) { @@ -164,7 +165,6 @@ class InputDocument $appDocUid = \G::generateUniqueID(); $docVersion = ''; $appDocType = 'INPUT'; - $appDocComment = (isset($_POST["form"]))? $_POST["form"] : ""; $case = new \Cases(); $delIndex = \AppDelegation::getCurrentIndex($applicationUid); $case->thisIsTheCurrentUser($applicationUid, $delIndex, $userUid, "REDIRECT", "casesListExtJs"); diff --git a/workflow/engine/src/BusinessModel/Cases/OutputDocument.php b/workflow/engine/src/BusinessModel/Cases/OutputDocument.php index eb129cdea..c6d99c80a 100644 --- a/workflow/engine/src/BusinessModel/Cases/OutputDocument.php +++ b/workflow/engine/src/BusinessModel/Cases/OutputDocument.php @@ -49,11 +49,11 @@ class OutputDocument * * @param string $applicationUid * @param string $userUid - * @param string $outputDocumentUid + * @param string $applicationDocumentUid * * return array Return an array with data of an OutputDocument */ - public function getCasesOutputDocument($applicationUid, $userUid, $outputDocumentUid) + public function getCasesOutputDocument($applicationUid, $userUid, $applicationDocumentUid) { try { $sApplicationUID = $applicationUid; @@ -79,7 +79,7 @@ class OutputDocument $docrow['app_doc_type'] = $row['TYPE']; $docrow['app_doc_index'] = $row['APP_DOC_INDEX']; $docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK']; - if ($docrow['app_doc_uid'] == $outputDocumentUid) { + if ($docrow['app_doc_uid'] == $applicationDocumentUid) { $result = $docrow; } } @@ -93,20 +93,20 @@ class OutputDocument /** * Delete OutputDocument * - * @param string $outputDocumentUid + * @param string $applicationDocumentUid * * return array Return an array with data of an OutputDocument */ - public function removeOutputDocument($outputDocumentUid) + public function removeOutputDocument($applicationDocumentUid) { try { - $oAppDocument = \AppDocumentPeer::retrieveByPK( $outputDocumentUid, 1 ); + $oAppDocument = \AppDocumentPeer::retrieveByPK( $applicationDocumentUid, 1 ); if (is_null( $oAppDocument ) || $oAppDocument->getAppDocStatus() == 'DELETED') { throw (new \Exception('This row doesn\'t exist!')); } \G::LoadClass('wsBase'); $ws = new \wsBase(); - $ws->removeDocument($outputDocumentUid); + $ws->removeDocument($applicationDocumentUid); } catch (\Exception $e) { throw $e; } @@ -124,8 +124,489 @@ class 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(); + return $this->getCasesOutputDocument($applicationUid, $userUid, $sDocUID); } catch (\Exception $e) { throw $e; } } + + /* + * Generate the output document + * @param string $sUID + * @param array $aFields + * @param string $sPath + * @return variant + */ + + public function generate($sUID, $aFields, $sPath, $sFilename, $sContent, $sLandscape = false, $sTypeDocToGener = 'BOTH', $aProperties = array(), $sApplication) + { + if (($sUID != '') && is_array($aFields) && ($sPath != '')) { + $sContent = \G::replaceDataGridField($sContent, $aFields); + \G::verifyPath($sPath, true); + //Start - Create .doc + $oFile = fopen($sPath . $sFilename . '.doc', 'wb'); + $size = array(); + $size["Letter"] = "216mm 279mm"; + $size["Legal"] = "216mm 357mm"; + $size["Executive"] = "184mm 267mm"; + $size["B5"] = "182mm 257mm"; + $size["Folio"] = "216mm 330mm"; + $size["A0Oversize"] = "882mm 1247mm"; + $size["A0"] = "841mm 1189mm"; + $size["A1"] = "594mm 841mm"; + $size["A2"] = "420mm 594mm"; + $size["A3"] = "297mm 420mm"; + $size["A4"] = "210mm 297mm"; + $size["A5"] = "148mm 210mm"; + $size["A6"] = "105mm 148mm"; + $size["A7"] = "74mm 105mm"; + $size["A8"] = "52mm 74mm"; + $size["A9"] = "37mm 52mm"; + $size["A10"] = "26mm 37mm"; + $size["Screenshot640"] = "640mm 480mm"; + $size["Screenshot800"] = "800mm 600mm"; + $size["Screenshot1024"] = "1024mm 768mm"; + $sizeLandscape["Letter"] = "279mm 216mm"; + $sizeLandscape["Legal"] = "357mm 216mm"; + $sizeLandscape["Executive"] = "267mm 184mm"; + $sizeLandscape["B5"] = "257mm 182mm"; + $sizeLandscape["Folio"] = "330mm 216mm"; + $sizeLandscape["A0Oversize"] = "1247mm 882mm"; + $sizeLandscape["A0"] = "1189mm 841mm"; + $sizeLandscape["A1"] = "841mm 594mm"; + $sizeLandscape["A2"] = "594mm 420mm"; + $sizeLandscape["A3"] = "420mm 297mm"; + $sizeLandscape["A4"] = "297mm 210mm"; + $sizeLandscape["A5"] = "210mm 148mm"; + $sizeLandscape["A6"] = "148mm 105mm"; + $sizeLandscape["A7"] = "105mm 74mm"; + $sizeLandscape["A8"] = "74mm 52mm"; + $sizeLandscape["A9"] = "52mm 37mm"; + $sizeLandscape["A10"] = "37mm 26mm"; + $sizeLandscape["Screenshot640"] = "480mm 640mm"; + $sizeLandscape["Screenshot800"] = "600mm 800mm"; + $sizeLandscape["Screenshot1024"] = "768mm 1024mm"; + if (!isset($aProperties['media'])) { + $aProperties['media'] = 'Letter'; + } + if ($sLandscape) { + $media = $sizeLandscape[$aProperties['media']]; + } else { + $media = $size[$aProperties['media']]; + } + $marginLeft = '15'; + if (isset($aProperties['margins']['left'])) { + $marginLeft = $aProperties['margins']['left']; + } + $marginRight = '15'; + if (isset($aProperties['margins']['right'])) { + $marginRight = $aProperties['margins']['right']; + } + $marginTop = '15'; + if (isset($aProperties['margins']['top'])) { + $marginTop = $aProperties['margins']['top']; + } + $marginBottom = '15'; + if (isset($aProperties['margins']['bottom'])) { + $marginBottom = $aProperties['margins']['bottom']; + } + fwrite($oFile, ' +
+ + + + + + + + + + +