File size: 2,693 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
$ipaddress = $_SERVER['REMOTE_ADDR'];
try {
    $aux = explode( '|', $_GET['id'] );

    $index = 0;
    $ObjUid = str_replace( '"', '', $aux[$index ++] );
    if (isset( $_GET['v'] ))
        $versionReq = $_GET['v'];

        //downloading the file
    $localPath = PATH_DOCUMENT . 'input' . PATH_SEP;
    G::mk_dir( $localPath );
    $newfilename = G::GenerateUniqueId() . '.pm';

    $downloadUrl = PML_DOWNLOAD_URL . '?id=' . $ObjUid . (isset( $_GET['s'] ) ? '&s=' . $_GET['s'] : '');
    //print "<hr>$downloadUrl<hr>";die;

    $oProcess = new Processes();
    $oProcess->downloadFile( $downloadUrl, $localPath, $newfilename );

    //getting the ProUid from the file recently downloaded
    $oData = $oProcess->getProcessData( $localPath . $newfilename );
    if (is_null( $oData )) {
        throw new Exception( G::LoadTranslation( 'ID_ERROR' ) );
    }
    $Fields['IMPORT_OPTION'] = 2;
    $Fields['PRO_FILENAME'] = $newfilename;
    $Fields['OBJ_UID'] = $ObjUid;
    $sProUid = $oData->process['PRO_UID'];
    $oData->process['PRO_UID_OLD'] = $sProUid;
    //print $sProUid;die;
    //if the process exists, we need to ask what kind of re-import the user wants,
    if ($oProcess->processExists( $sProUid )) {
        $G_MAIN_MENU = 'processmaker';
        $G_ID_MENU_SELECTED = 'PROCESSES';
        $G_PUBLISH = new Publisher();
        $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'processes/processes_ImportExisting', '', $Fields, 'downloadPML_ImportExisting' );
        G::RenderPage( 'publish', 'blank' );
        die();
    }

    //creating the process
    $oProcess->createProcessFromData( $oData, $localPath . $newfilename );

    //show the info after the imported process

    $oProcess = new Processes();
    $oProcess->ws_open_public();
    $processData = $oProcess->ws_processGetData( $ObjUid );

    $Fields['pro_title'] = $processData->title;
    $Fields['installSteps'] = nl2br( $processData->installSteps );
    $Fields['category'] = (isset( $processData->category ) ? $processData->category : '');
    $Fields['version'] = $processData->version;
    $G_MAIN_MENU = 'processmaker';
    $G_ID_MENU_SELECTED = 'PROCESSES';
    $G_PUBLISH = new Publisher();
    $Fields['PRO_UID'] = $sProUid;
    $processmapLink = "processes_Map?PRO_UID=$sProUid";
    $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'processes/processes_ImportSucessful', '', $Fields, $processmapLink );
    G::RenderPage( 'publish', 'blank' );
    die();

} catch (Exception $e) {
    $G_PUBLISH = new Publisher();
    $aMessage['MESSAGE'] = $e->getMessage();
    $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
    G::RenderPage( 'publish', 'blank' );
}