コード例 #1
0
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;
}
コード例 #2
0
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email info@colosa.com.
 */
require_once "classes/model/AppDocumentPeer.php";
$oAppDocument = new AppDocument();
if (!isset($_GET['v'])) {
    //Load last version of the document
    $docVersion = $oAppDocument->getLastAppDocVersion($_GET['a']);
} else {
    $docVersion = $_GET['v'];
}
$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;
コード例 #3
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;

    }
コード例 #4
0
ファイル: AppFolder.php プロジェクト: rrsc/processmaker
    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 );
        }
    }
コード例 #5
0
ファイル: Light.php プロジェクト: rrsc/processmaker
    /**
     * 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;
    }
コード例 #6
0
ファイル: appFolderAjax.php プロジェクト: rrsc/processmaker
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');
     */
}