/workflow/engine/methods/services/upload.php

https://bitbucket.org/ferOnti/processmaker · PHP · 157 lines · 83 code · 32 blank · 42 comment · 20 complexity · 519bfa903a246b9d666a8579f5945fcc MD5 · raw file

  1. <?php
  2. /**
  3. * class.wsBase.php
  4. *
  5. * ProcessMaker Open Source Edition
  6. * Copyright (C) 2004 - 2008 Colosa Inc.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
  22. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
  23. */
  24. /**
  25. * @Updated Dec 14, 2009 by Erik <erik@colosa.com>
  26. *
  27. * The point of this application is upload the file and create the input document record
  28. *
  29. * if the post attached file has error code 0 continue in other case nothing to do.
  30. */
  31. if (isset( $_FILES ) && $_FILES["ATTACH_FILE"]["error"] == 0) {
  32. try {
  33. G::LoadClass( "case" );
  34. $folderId = "";
  35. $fileTags = "";
  36. if (isset( $_POST["DOC_UID"] ) && $_POST["DOC_UID"] != - 1) {
  37. //The document is of an Specific Input Document. Get path and Tag information
  38. require_once ("classes/model/AppFolder.php");
  39. require_once ("classes/model/InputDocument.php");
  40. $oInputDocument = new InputDocument();
  41. $aID = $oInputDocument->load( $_POST["DOC_UID"] );
  42. //Get the Custom Folder ID (create if necessary)
  43. $oFolder = new AppFolder();
  44. $folderId = $oFolder->createFromPath( $aID["INP_DOC_DESTINATION_PATH"], $_POST["APPLICATION"] );
  45. //Tags
  46. $fileTags = $oFolder->parseTags( $aID["INP_DOC_TAGS"], $_POST["APPLICATION"] );
  47. }
  48. $oAppDocument = new AppDocument();
  49. if (isset( $_POST["APP_DOC_UID"] ) && trim( $_POST["APP_DOC_UID"] ) != "") {
  50. //Update
  51. echo "[update]";
  52. $aFields["APP_DOC_UID"] = $_POST["APP_DOC_UID"];
  53. $aFields["DOC_VERSION"] = $_POST["DOC_VERSION"];
  54. $aFields["APP_DOC_FILENAME"] = $_FILES["ATTACH_FILE"]["name"];
  55. if (isset( $_POST["APPLICATION"] )) {
  56. $aFields["APP_UID"] = $_POST["APPLICATION"];
  57. }
  58. if (isset( $_POST["INDEX"] )) {
  59. $aFields["DEL_INDEX"] = $_POST["INDEX"];
  60. }
  61. if (isset( $_POST["USR_UID"] )) {
  62. $aFields["USR_UID"] = $_POST["USR_UID"];
  63. }
  64. if (isset( $_POST["DOC_UID"] )) {
  65. $aFields["DOC_UID"] = $_POST["DOC_UID"];
  66. }
  67. if (isset( $_POST["APP_DOC_TYPE"] )) {
  68. $aFields["APP_DOC_TYPE"] = $_POST["APP_DOC_TYPE"];
  69. }
  70. $aFields["APP_DOC_CREATE_DATE"] = date( "Y-m-d H:i:s" );
  71. $aFields["APP_DOC_COMMENT"] = (isset( $_POST["COMMENT"] )) ? $_POST["COMMENT"] : "";
  72. $aFields["APP_DOC_TITLE"] = (isset( $_POST["TITLE"] )) ? $_POST["TITLE"] : "";
  73. //$aFields["FOLDER_UID"] = $folderId,
  74. //$aFields["APP_DOC_TAGS"] = $fileTags
  75. $aFields["APP_DOC_FIELDNAME"] = $_POST["APP_DOC_FIELDNAME"];
  76. } else {
  77. //New record
  78. $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" => $_POST["APP_DOC_FIELDNAME"]
  79. );
  80. }
  81. $oAppDocument->create( $aFields );
  82. $sAppUid = $oAppDocument->getAppUid();
  83. $sAppDocUid = $oAppDocument->getAppDocUid();
  84. $iDocVersion = $oAppDocument->getDocVersion();
  85. $info = pathinfo( $oAppDocument->getAppDocFilename() );
  86. $ext = (isset( $info["extension"] )) ? $info["extension"] : "";
  87. //Save the file
  88. echo $sPathName = PATH_DOCUMENT . $sAppUid . PATH_SEP;
  89. echo $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $ext;
  90. print G::uploadFile( $_FILES["ATTACH_FILE"]["tmp_name"], $sPathName, $sFileName );
  91. print ("* The file " . $_FILES["ATTACH_FILE"]["name"] . " was uploaded successfully in case " . $sAppUid . " as input document..\n") ;
  92. //Get current Application Fields
  93. $application = new Application();
  94. $appFields = $application->Load( $_POST["APPLICATION"] );
  95. $appFields = unserialize( $appFields["APP_DATA"] );
  96. $_SESSION["APPLICATION"] = $appFields["APPLICATION"];
  97. $_SESSION["PROCESS"] = $appFields["PROCESS"];
  98. $_SESSION["TASK"] = $appFields["TASK"];
  99. $_SESSION["INDEX"] = $appFields["INDEX"];
  100. $_SESSION["USER_LOGGED"] = $appFields["USER_LOGGED"]; //$_POST["USR_UID"]
  101. //$_SESSION["USR_USERNAME"] = $appFields["USR_USERNAME"];
  102. //$_SESSION["STEP_POSITION"] = 0;
  103. //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
  104. $oPluginRegistry = &PMPluginRegistry::getSingleton();
  105. if ($oPluginRegistry->existsTrigger( PM_UPLOAD_DOCUMENT ) && class_exists( "uploadDocumentData" )) {
  106. $triggerDetail = $oPluginRegistry->getTriggerInfo( PM_UPLOAD_DOCUMENT );
  107. $documentData = new uploadDocumentData( $_POST["APPLICATION"], $_POST["USR_UID"], $sPathName . $sFileName, $aFields["APP_DOC_FILENAME"], $sAppDocUid, $iDocVersion );
  108. $uploadReturn = $oPluginRegistry->executeTriggers( PM_UPLOAD_DOCUMENT, $documentData );
  109. if ($uploadReturn) {
  110. $aFields["APP_DOC_PLUGIN"] = $triggerDetail->sNamespace;
  111. if (! isset( $aFields["APP_DOC_UID"] )) {
  112. $aFields["APP_DOC_UID"] = $sAppDocUid;
  113. }
  114. if (! isset( $aFields["DOC_VERSION"] )) {
  115. $aFields["DOC_VERSION"] = $iDocVersion;
  116. }
  117. $oAppDocument->update( $aFields );
  118. unlink( $sPathName . $sFileName );
  119. }
  120. }
  121. //End plugin
  122. } catch (Exception $e) {
  123. print ($e->getMessage()) ;
  124. }
  125. }