/** * * @param string $folderName * @param strin(32) $folderParent * @return Ambigous <>|number */ public function createFolder ($folderName, $folderParent = "/", $action = "createifnotexists") { $validActions = array ("createifnotexists","create","update"); if (! in_array( $action, $validActions )) { $action = "createifnotexists"; } //Clean Folder and Parent names (delete spaces...) $folderName = trim( $folderName ); $folderParent = trim( $folderParent ); //Try to Load the folder (Foldername+FolderParent) $oCriteria = new Criteria( 'workflow' ); $oCriteria->add( AppFolderPeer::FOLDER_NAME, $folderName ); $oCriteria->add( AppFolderPeer::FOLDER_PARENT_UID, $folderParent ); $oDataset = AppFolderPeer::doSelectRS( $oCriteria ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset->next(); if ($aRow = $oDataset->getRow()) { //Folder exist, then return the ID $response['success'] = false; $response['message'] = $response['error'] = "Can't create folder <br /> A folder with same name already exist. <br /> $folderName"; $response['folderUID'] = $aRow['FOLDER_UID']; //return ($aRow ['FOLDER_UID']); return ($response); } else { //Folder doesn't exist. Create and return the ID $folderUID = G::GenerateUniqueID(); $tr = new AppFolder(); $tr->setFolderUid( $folderUID ); $tr->setFolderParentUid( $folderParent ); $tr->setFolderName( $folderName ); $tr->setFolderCreateDate( 'now' ); $tr->setFolderUpdateDate( 'now' ); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); $response['success'] = true; $response['message'] = "Folder successfully created. <br /> $folderName"; $response['folderUID'] = $folderUID; return ($response); //return $folderUID; } else { // Something went wrong. We can now get the validationFailures and handle them. $msg = ''; $validationFailuresArray = $tr->getValidationFailures(); foreach ($validationFailuresArray as $objValidationFailure) { $msg .= $objValidationFailure->getMessage() . "<br/>"; } $response['success'] = false; $response['message'] = $response['error'] = "Can't create folder \n A \n " . $msg; return ($response); } } }
$aOD['__DYNAFORM_OPTIONS']['NEXT_STEP'] = $aNextStep['PAGE']; $aOD['__DYNAFORM_OPTIONS']['NEXT_STEP_LABEL'] = G::loadTranslation("ID_NEXT_STEP"); switch ($_GET['ACTION']) { case 'GENERATE': //START: If there is a Break Step registered from Plugin Similar as a Trigger debug $oPluginRegistry =& PMPluginRegistry::getSingleton(); if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT_BEFORE)) { //If a Plugin has registered a Break Page Evaluator $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT_BEFORE, array('USR_UID' => $_SESSION['USER_LOGGED'])); } //END: If there is a Break Step registered from Plugin $sFilenameOriginal = $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(); $folderId = $oFolder->createFromPath($aOD['OUT_DOC_DESTINATION_PATH']); //Tags $fileTags = $oFolder->parseTags($aOD['OUT_DOC_TAGS']); //Get last Document Version and apply versioning if is enabled $oAppDocument = new AppDocument(); $lastDocVersion = $oAppDocument->getLastDocVersion($_GET['UID'], $_SESSION['APPLICATION']); //if(($aOD['OUT_DOC_VERSIONING'])||($lastDocVersion==0)){ // $lastDocVersion++; //} $oCriteria = new Criteria('workflow'); $oCriteria->add(AppDocumentPeer::APP_UID, $_SESSION['APPLICATION']); //$oCriteria->add(AppDocumentPeer::DEL_INDEX, $_SESSION['INDEX']); $oCriteria->add(AppDocumentPeer::DOC_UID, $_GET['UID']); $oCriteria->add(AppDocumentPeer::DOC_VERSION, $lastDocVersion); $oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT');
<?php global $rootFolder; require_once "classes/model/AppFolder.php"; $oPMFolder = new AppFolder(); if ($rootFolder == '0' || $rootFolder == 0) { $folderPath['PATH'] = "/"; } else { $folderPath = $oPMFolder->getFolderStructure($rootFolder); } $html = ' <div> <div class="boxTopBlue"><div class="a"></div><div class="b"></div><div class="c"></div></div> <div class="boxContentBlue"> <table style="margin:0px;" cellspacing="0" cellpadding="0"> <tr> <td class="userGroupTitle"><div class="userGroupLink">' . G::LoadTranslation("ID_PM_FOLDER") . ': <a href="javascript:openPMFolder(\'' . $rootFolder . '\',\'' . $rootFolder . '\')">' . $folderPath['PATH'] . '</a></div></td> </tr> </table> </div> <div class="boxBottomBlue"><div class="a"></div><div class="b"></div><div class="c"></div></div> '; $html .= '<div class="treeBase" style="width:360px;height: expression( this.scrollHeight > 319 ? \'320px\' : \'auto\' ); /* sets max-height for IE */ max-height: 320px; /* sets max-height value for all standards-compliant browsers */ overflow:hidden;"> <div class="boxTop"> <div class="a"></div> <div class="b"></div> <div class="c"></div> </div>
$docType = isset($_GET['docType']) ? $_GET['docType'] : ""; //save info require_once "classes/model/AppDocument.php"; require_once 'classes/model/AppFolder.php'; require_once 'classes/model/InputDocument.php'; $oInputDocument = new InputDocument(); if ($_GET['UID'] != -1) { $aID = $oInputDocument->load($_GET['UID']); } else { $oFolder = new AppFolder(); $folderStructure = $oFolder->getFolderStructure(isset($_GET['folderId']) ? $_GET['folderId'] : "/"); $aID = array('INP_DOC_DESTINATION_PATH' => $folderStructure['PATH']); } $oAppDocument = new AppDocument(); //Get the Custom Folder ID (create if necessary) $oFolder = new AppFolder(); if ($_GET['UID'] != -1) { //krumo("jhl"); $folderId = $oFolder->createFromPath($aID['INP_DOC_DESTINATION_PATH'], $appId); //Tags $fileTags = $oFolder->parseTags($aID['INP_DOC_TAGS'], $appId); } else { $folderId = isset($_GET['folderId']) ? $_GET['folderId'] : "/"; $fileTags = "EXTERNAL"; } 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' => $_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->update($aFields); break;
/** * 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; }
$indocUid = $_POST["INPUTS"][$arrayField[$i]["grdName"]][$arrayField[$i]["grdFieldName"]]; } $fieldName = $arrayField[$i]["grdName"] . "_" . $arrayField[$i]["index"] . "_" . $arrayField[$i]["grdFieldName"]; } else { if (isset($_POST["INPUTS"][$arrayField[$i]]) && !empty($_POST["INPUTS"][$arrayField[$i]])) { $indocUid = $_POST["INPUTS"][$arrayField[$i]]; } $fieldName = $arrayField[$i]; } if ($indocUid != null) { //require_once ("classes/model/AppFolder.php"); //require_once ("classes/model/InputDocument.php"); $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;
/** * 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; } }
/** * * @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(); }
<?php try { $form = $_POST['form']; $FolderUid = $form['FOLDER_UID']; $FolderParentUid = $form['FOLDER_PARENT_UID']; $FolderName = $form['FOLDER_NAME']; $FolderCreateDate = 'now'; $FolderUpdateDate = 'now'; require_once "classes/model/AppFolder.php"; //if exists the row in the database propel will update it, otherwise will insert. $tr = AppFolderPeer::retrieveByPK($FolderUid); if (!(is_object($tr) && get_class($tr) == 'AppFolder')) { $tr = new AppFolder(); } $tr->setFolderUid($FolderUid); $tr->setFolderParentUid($FolderParentUid); $tr->setFolderName($FolderName); $tr->setFolderCreateDate($FolderCreateDate); $tr->setFolderUpdateDate($FolderUpdateDate); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); } else { // Something went wrong. We can now get the validationFailures and handle them. $msg = ''; $validationFailuresArray = $tr->getValidationFailures(); foreach ($validationFailuresArray as $objValidationFailure) { $msg .= $objValidationFailure->getMessage() . "<br/>"; } //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
* * if the post attached file has error code 0 continue in other case nothing to do. */ if (isset($_FILES) && $_FILES["ATTACH_FILE"]["error"] == 0) { try { G::LoadClass("case"); $folderId = ""; $fileTags = ""; if (isset($_POST["DOC_UID"]) && $_POST["DOC_UID"] != -1) { //The document is of an Specific Input Document. Get path and Tag information require_once "classes/model/AppFolder.php"; require_once "classes/model/InputDocument.php"; $oInputDocument = new InputDocument(); $aID = $oInputDocument->load($_POST["DOC_UID"]); //Get the Custom Folder ID (create if necessary) $oFolder = new AppFolder(); $folderId = $oFolder->createFromPath($aID["INP_DOC_DESTINATION_PATH"], $_POST["APPLICATION"]); //Tags $fileTags = $oFolder->parseTags($aID["INP_DOC_TAGS"], $_POST["APPLICATION"]); } $oAppDocument = new AppDocument(); if (isset($_POST["APP_DOC_UID"]) && trim($_POST["APP_DOC_UID"]) != "") { //Update echo "[update]"; $aFields["APP_DOC_UID"] = $_POST["APP_DOC_UID"]; $aFields["DOC_VERSION"] = $_POST["DOC_VERSION"]; $aFields["APP_DOC_FILENAME"] = $_FILES["ATTACH_FILE"]["name"]; if (isset($_POST["APPLICATION"])) { $aFields["APP_UID"] = $_POST["APPLICATION"]; } if (isset($_POST["INDEX"])) {
* The point of this application is upload the file and create the input document record * * if the post attached file has error code 0 continue in other case nothing to do. */ if (isset($_FILES) && $_FILES['ATTACH_FILE']['error'] == 0) { try { G::LoadClass('case'); $folderId = ''; $fileTags = ''; if (isset($_POST['DOC_UID']) && $_POST['DOC_UID'] != -1) { //The document is of an Specific Input Document. Get path and Tag information require_once 'classes/model/AppFolder.php'; require_once 'classes/model/InputDocument.php'; $oInputDocument = new InputDocument(); $aID = $oInputDocument->load($_POST['DOC_UID']); //Get the Custom Folder ID (create if necessary) $oFolder = new AppFolder(); $folderId = $oFolder->createFromPath($aID['INP_DOC_DESTINATION_PATH'], $_POST['APPLICATION']); //Tags $fileTags = $oFolder->parseTags($aID['INP_DOC_TAGS'], $_POST['APPLICATION']); } $oAppDocument = new AppDocument(); if (isset($_POST['APP_DOC_UID']) && trim($_POST['APP_DOC_UID']) != '') { //Update echo '[update]'; $aFields['APP_DOC_UID'] = $_POST['APP_DOC_UID']; $aFields['DOC_VERSION'] = $_POST['DOC_VERSION']; $aFields['APP_DOC_FILENAME'] = $_FILES['ATTACH_FILE']['name']; if (isset($_POST['APPLICATION'])) { $aFields['APP_UID'] = $_POST['APPLICATION']; } if (isset($_POST['INDEX'])) {
function deletePMFolder() { include_once ("classes/model/AppFolder.php"); $oAppFoder = new AppFolder (); $oAppFoder->remove($_POST['sFileUID'],$_POST['rootfolder']); }
/** * 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; } }