File size: 8,761 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<html>
<head>
<title>SugarCRM test webservices</title>
</head>
<style type="text/css">
ul.krumo-node {
	margin: 0px;
	padding: 0px;
	background-color: white;
}

ul.krumo-node ul {
	margin-left: 20px;
}

* html ul.krumo-node ul {
	margin-left: 24px;
}

div.krumo-root {
	border: solid 1px black;
	margin: 1em 0em;
	text-align: left;
}

ul.krumo-first {
	font: normal 11px tahoma, verdana;
	border: solid 1px white;
}

li.krumo-child {
	display: block;
	list-style: none;
	padding: 0px;
	margin: 0px;
	overflow: hidden;
}

div.krumo-element {
	cursor: default;
	display: block;
	clear: both;
	white-space: nowrap;
	background-color: white;
	background-image: url(/Krumo/skins/schablon.com/empty.gif);
	background-repeat: no-repeat;
	background-position: 6px 5px;
	padding: 2px 0px 3px 20px;
}

* html div.krumo-element {
	padding-bottom: 3px;
	line-height: 13px;
}

a.krumo-name {
	color: navy;
	font: bold 13px courier new;
	line-height: 12px;
}
</style>
<?php


$filter = new InputFilter();
$_POST = $filter->xssFilterHard($_POST);
$_SESSION = $filter->xssFilterHard($_SESSION);
if (isset( $_POST["epr"] )) {
    $_SESSION['END_POINT'] = $_POST["epr"];
}
$endpoint = isset( $_SESSION['END_POINT'] ) ? $_SESSION['END_POINT'] : 'http://sugar.opensource.colosa.net/soap.php';
$endpoint = $filter->xssFilterHard($endpoint);
$sessionId = isset( $_SESSION['SESSION_ID'] ) ? $_SESSION['SESSION_ID'] : '';
$sessionId = $filter->xssFilterHard($sessionId);
?>
<form method="post" action="">

	<div class="krumo-root">
		<ul class="krumo-node krumo-first">
			<div class="krumo-element">
				End Point <input type="text" size="80" maxlength="160" name="epr"
					value="<?php echo $endpoint ?>"> <input type="submit"
					value="change endpoint" name="action">
			</div>
		</ul>
	</div>
</form>

<form method="post" action="">
	<div class="krumo-root">
		<a class="krumo-name">login</a>
		<ul class="krumo-node krumo-first">
			<div>
				User Id <input type="text" size="16" maxlength="20" name="user"
					value="admin"> Password <input type="text" size="16" maxlength="20"
					name="pass" value="sample"> <input type="submit" value="login"
					name="action">
			</div>
		</ul>
	</div>
</form>

<form method="post" action="">
	<div class="krumo-root">
		<a class="krumo-name">createUser</a>
		<ul class="krumo-node krumo-first">
			<div class="krumo-element">
				Session Id <input type="text" size="36" maxlength="32"
					name="sessionid" value="<?php print $sessionId ?>">
			</div>
			<div class="krumo-element">
				User Id <input type="text" size="16" maxlength="20" name="userid"
					value=""> <img src="/Krumo/skins/schablon.com/empty.gif"> First
				Name <input type="text" size="16" maxlength="20" name="firstname"
					value=""> <img src="/Krumo/skins/schablon.com/empty.gif"> Last Name
				<input type="text" size="16" maxlength="20" name="lastname" value="">
				<img src="/Krumo/skins/schablon.com/empty.gif"> Email <input
					type="text" size="16" maxlength="20" name="email" value=""> <img
					src="/Krumo/skins/schablon.com/empty.gif"> Role <input type="text"
					size="16" maxlength="20" name="role" value=""> <img
					src="/Krumo/skins/schablon.com/empty.gif"> <input type="submit"
					value="createUser" name="action">
			</div>
		</ul>
	</div>
</form>

<form method="post" action="">
	<div class="krumo-root">
		<a class="krumo-name">assignUserToGroup</a>
		<ul class="krumo-node krumo-first">
			<div class="krumo-element">
				Session Id <input type="text" size="36" maxlength="32"
					name="sessionid" value="<?php print $sessionId ?>">
			</div>
			<div class="krumo-element">
				User Id <input type="text" size="16" maxlength="20" name="userid"
					value=""> <img src="/Krumo/skins/schablon.com/empty.gif"> Group Id
				<input type="text" size="16" maxlength="20" name="groupid" value="">
				<input type="submit" value="assignUserToGroup" name="action">
			</div>
		</ul>
	</div>
</form>


<form method="post" action="">
	<div class="krumo-root">
		<a class="krumo-name">newCase</a>
		<ul class="krumo-node krumo-first">
			<div class="krumo-element">
				Session Id <input type="text" size="36" maxlength="32"
					name="sessionid" value="<?php print $sessionId ?>">
			</div>
			<div class="krumo-element">
				Process Id <input type="text" size="16" maxlength="20"
					name="processid" value=""> <img
					src="/Krumo/skins/schablon.com/empty.gif"> Variables <input
					type="text" size="16" maxlength="20" name="variables" value=""> <input
					type="submit" value="newCase" name="action">
			</div>
		</ul>
	</div>
</form>

<?php

if (! isset( $_POST["action"] ) or $_POST["action"] == 'change endpoint') {
    die();
}
$action = $_POST["action"];
//krumo ($_POST);


ini_set( "soap.wsdl_cache_enabled", "0" ); // disabling WSDL cache


switch ($action) {
    case 'login':
        $user = $_POST["user"];
        $pass = G::encryptOld( $_POST["pass"] );
        $wsdl = $endpoint;
        //$client = new SoapClient( $endpoint );
        $client = new SoapClient( null, array ('location' => $endpoint,'uri' => 'http://www.sugarcrm.com/sugarcrm','soap_version' => SOAP_1_1,        //SOAP_1_2 - 1.2 not supported by sugar nusoap
'trace' => 1,'exceptions' => 0,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5
        ) );

        $params = array ('user_name' => $user,'password' => $pass,'version' => '1'
        );
        $result = $client->__SoapCall( 'login', array ('user_auth' => $params,'application_name' => 'ProcessMaker'
        ) );
        if ($result->error->number == 0) {
            $_SESSION['SESSION_ID'] = $result->id;
            $session = $result->id;

            $res = $client->__getFunctions();
            krumo( $res );

            $params = array ('session' => $result->id
            );
            $res = $client->__SoapCall( 'is_user_admin', array ($session
            ) );
            if ($res == 1)
                print "is Administrator user";

            $first_name = 'juan';
            $last_name = 'perez';
            $phone = '7235131';
            $fax = '2454545';
            $companyname = 'ABC company';
            $prod_desc = 'descripcion del prod 1 ';
            $user_guid = '';
            $set_entry_params = array ('session' => $session,'module_name' => 'Leads',
                            'name_value_list' => array (array ('name' => 'last_name','value' => $last_name
                            ),array ('name' => 'status','value' => 'New'
                            ),array ('name' => 'phone_work','value' => $phone
                            ),array ('name' => 'phone_fax','value' => $fax
                            ),array ('name' => 'account_name','value' => $companyname
                            ),array ('name' => 'lead_source','value' => 'Web Site'
                            ),array ('name' => 'description','value' => $prod_desc
                            ),array ('name' => 'email1','value' => 'juan@colosa.com'
                            ),array ('name' => 'assigned_user_id','value' => $user_guid
                            )
                            )
            );
            $res = $client->__SoapCall( 'set_entry', $set_entry_params );
            krumo( $res );

            //$query = "contacts.email1 != '' ";
            //$orderby = 'email1 desc ';
            $query = '';
            $orderby = '';
            $fields = array ('id','first_name','last_name','account_name','account_id','email1','phone_work'
            );
            $params = array ($session,'Leads',$query,$orderby,0,$fields,100,false
            );
            $res = $client->__SoapCall( 'get_entry_list', $params );
            krumo( $res );
        }
        break;
    case 'processList':
        $wsdl = PATH_METHODS . "services" . PATH_SEP . "pmos.wsdl";
        $endpoint = $wsdl;
        $client = new SoapClient( $endpoint );
        $params = array ('sessionId' => $sessionId
        );
        $result = $client->__SoapCall( 'processesList', array ($params
        ) );

        krumo( $result );
        die();
        break;
    default:
        krumo( $_POST );
        die();
}

?>
<div class="krumo-root">
	<ul class="krumo-node krumo-first">
		<li class="krumo-child">
			<div class="krumo-element">
				status_code (<em class="krumo-type">Integer</em>) <strong
					class="krumo-integer"><?php echo $result->error->number ?></strong>
			</div>
			<div class="krumo-element">
				message (<em class="krumo-type">string</em>) <strong
					class="krumo-integer"><?php echo $result->error->name ?></strong>
			</div>
			<div class="krumo-element">
				timestamp (<em class="krumo-type">string</em>) <strong
					class="krumo-integer"><?php echo $result->error->description ?></strong>
			</div>
		</li>
	</ul>
</div>