File size: 5,453 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php

if (! defined( 'JAVA_BRIDGE_PATH' )) {
    define( 'JAVA_BRIDGE_PATH', 'JavaBridgePM' );
}
if (! defined( 'JAVA_BRIDGE_PORT' )) {
    define( 'JAVA_BRIDGE_PORT', '8080' );
}
if (! defined( 'JAVA_BRIDGE_HOST' )) {
    define( 'JAVA_BRIDGE_HOST', '127.0.0.1' );
}

/**
 *
 * @package workflow.engine.classes
 */

class JavaBridgePM
{
    public $JavaBridgeDir = JAVA_BRIDGE_PATH;
    public $JavaBridgePort = JAVA_BRIDGE_PORT;
    public $JavaBridgeHost = JAVA_BRIDGE_HOST;

    /**
     * checkJavaExtension
     * check if the java extension was loaded.
     *
     *
     * @return true or false
     */
    public function checkJavaExtension ()
    {
        try {
            if (! extension_loaded( 'java' )) {
                if (! (@include_once ("java/Java.inc"))) {
                    $urlJavaInc = "http://$this->JavaBridgeHost:$this->JavaBridgePort/$this->JavaBridgeDir/java/Java.inc";
                    @include_once ($urlJavaInc);
                    $includedFiles = get_included_files();
                    $found = false;
                    foreach ($includedFiles as $filename) {
                        if ($urlJavaInc == $filename) {
                            $found = true;
                        }
                    }
                    if (! $found) {
                        throw new Exception( 'The PHP/Java Bridge is not defined' );
                    }

                }
                return true;
            }

            if (! function_exists( "java_get_server_name" )) {
                throw new Exception( 'The loaded java extension is not the PHP/Java Bridge' );
            }

            return true;
        } catch (Exception $e) {
            throw new Exception( 'Error in checkJavaExtension: ' . $e->getMessage() );
        }
    }

    /**
     * convert a php value to a java one...
     *
     * @param string $value
     * @param string $className
     * @return s boolean success
     */
    public function convertValue ($value, $className)
    {
        // if we are a string, just use the normal conversion
        // methods from the java extension...
        try {
            if ($className == 'java.lang.String') {
                $temp = new Java( 'java.lang.String', $value );
                return $temp;
            } elseif ($className == 'java.lang.Boolean' || $className == 'java.lang.Integer' || $className == 'java.lang.Long' || $className == 'java.lang.Short' || $className == 'java.lang.Double' || $className == 'java.math.BigDecimal') {
                $temp = new Java( $className, $value );
                return $temp;
            } elseif ($className == 'java.sql.Timestamp' || $className == 'java.sql.Time') {
                $temp = new Java( $className );
                $javaObject = $temp->valueOf( $value );
                return $javaObject;
            }
        } catch (Exception $err) {
            echo ('unable to convert value, ' . $value . ' could not be converted to ' . $className);
            return false;
        }

        echo ('unable to convert value, class name ' . $className . ' not recognised');
        return false;
    }

    /**
     * generateJrxmlFromDynaform
     *
     * @param string $outDocUid
     * @param string $dynaformUid
     * @param object $template
     * @return void
     */
    public function generateJrxmlFromDynaform ($outDocUid, $dynaformUid, $template)
    {
        require_once 'classes/model/Dynaform.php';
        $dyn = new Dynaform();
        $aFields = $dyn->load( $dynaformUid );
        $xmlFields = $dyn->getDynaformFields( $dynaformUid );

        $reportTpl = PATH_TPL . 'javaBridgePM/classic.xml';
        $reportFilename = PATH_DYNAFORM . $aFields['PRO_UID'] . PATH_SEP . $outDocUid . '.jrxml';
        foreach ($xmlFields as $key => $val) {
            if ($val->type == 'submit' || $val->type == 'button' || $val->type == 'title' || $val->type == 'subtitle') {
                unset( $xmlFields[$key] );
            }
        }

        //$sqlSentence = 'SELECT * from ' . $tableName;
        $sqlSentence = 'dynaform/';

        $template = new TemplatePower( $reportTpl );
        $template->prepare();
        $template->assign( 'sqlSentence', $sqlSentence );
        $template->assign( 'tableName', $aFields['DYN_TITLE'] );
        $template->assign( 'heightDetail', count( $xmlFields ) * 15 + 20 );
        $template->assign( 'PAGE_NUMBER', '{PAGE_NUMBER}' );

        $logoReporte = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '/images/processmaker.logo.jpg';
        $template->assign( 'logoReporte', $logoReporte );

        foreach ($xmlFields as $key => $val) {
            $template->newBlock( 'fields' );
            $template->assign( 'fieldName', $key );
        }

        $posX = 140;
        $posLabelX = 5;
        $posY = 10;
        foreach ($xmlFields as $key => $val) {
            $template->newBlock( 'detailFields' );
            $template->assign( 'fieldName', '{' . $key . '}' );
            $template->assign( 'fieldLabel', $key );
            $template->assign( 'labelPosX', $posLabelX );
            $template->assign( 'fieldPosX', $posX );
            $template->assign( 'fieldPosY', $posY );
            $posY += 15;
        }

        $content = $template->getOutputContent();
        $iSize = file_put_contents( $reportFilename, $content );
        printf( "saved %s bytes in file %s \n", $iSize, $reportFilename );
    }
}