Spaces:
Sleeping
Sleeping
File size: 17,643 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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | <?php
use ProcessMaker\Core\System;
/**
* class.pmSugar.pmFunctions.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.
* *
*/
////////////////////////////////////////////////////
// pmSugar PM Functions
//
// Copyright (C) 2007 COLOSA
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
function getSoapClientOptions ()
{
$options = array ('trace' => 1);
//Apply proxy settings
$sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') {
$options['proxy_host'] = $sysConf['proxy_host'];
if ($sysConf['proxy_port'] != '') {
$options['proxy_port'] = $sysConf['proxy_port'];
}
if ($sysConf['proxy_user'] != '') {
$options['proxy_login'] = $sysConf['proxy_user'];
}
if ($sysConf['proxy_pass'] != '') {
$options['proxy_password'] = $sysConf['proxy_pass'];
}
}
return $options;
}
/**
* This collection of triggers allows to interact by getting and sending information to SugarCRM
* @class pmSugar
*
* @name Sugar CRM Triggers
* @icon /images/triggers/icon_SugarCRM.gif
* @className class.pmSugar.pmFunctions.php
*/
function sugarLogin ($sugarSoap, $user, $password)
{
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$auth_array = array ('user_auth' => array ('user_name' => $user,'password' => G::encryptOld( $password ),'version' => '1.0') );
$login_results = $client->__SoapCall( 'login', $auth_array );
$session_id = $login_results->id;
$user_guid = $client->__SoapCall( 'get_user_id', array ($session_id) );
return $session_id;
}
function objectToArray ($object)
{
if (! is_object( $object ) && ! is_array( $object )) {
return $object;
}
if (is_object( $object )) {
$object = get_object_vars( $object );
}
return array_map( "objectToArray", $object );
}
/**
*
* @method
*
* Gets SugarCRM entry using get_entry web service.
*
* @name GetSugarEntry
* @label Get SugarCRM Entry
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl [^]
* @param string | $user | User
* @param string | $password | Password
* @param string | $module | The name of the module from which to retrieve records.
* @param string | $id | The SugarBean’s ID.
* @param string | $selectedFields | Optional. The list of fields to be returned in the results.
* @param string | $linkNameToFieldsArray | A list of link names and the fields to be returned for each link name.
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarEntries | Sugar Entries (array or object) |
*
*/
function GetSugarEntry ($sugarSoap, $user, $password, $module, $id, $selectFields, $linkNameToFieldsArray, $resultType = 'array')
{
$sessionId = sugarLogin( $sugarSoap, $user, $password );
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$request_array = array ('session' => $sessionId,'module_name' => $module,'id' => $id,'select_fields' => $select_fields,'link_name_to_fields_array' => $linkNameToFieldsArray);
$sugarEntry = $client->__SoapCall( 'get_entry', $request_array );
if ($resultType == 'array') {
$sugarEntry = objectToArray( $sugarEntry );
}
return $sugarEntry;
}
/**
*
* @method
*
* Gets SugarCRM entries from the indicated module.
*
* @name GetSugarEntries
* @label Get SugarCRM Entries
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $module | Module
* @param string | $query | Query
* @param string | $orderBy | Order By
* @param string | $selectedFields | Selected Fields
* @param string | $maxResults=50 | Max Results
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarEntries | Sugar Entries (array or object) |
*
*/
function GetSugarEntries ($sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array")
{
$sessionId = sugarLogin( $sugarSoap, $user, $password );
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$request_array = array ('session' => $sessionId,'module_name' => $module,'query' => $query,'order_by' => $orderBy,'offset' => "",'select_fields' => "",'max_result' => $maxResults);
$sugarEntriesO = $client->__SoapCall( 'get_entry_list', $request_array );
switch ($resultType) {
case 'array':
$sugarEntries = objectToArray( $sugarEntriesO );
break;
case 'object':
$sugarEntries = $sugarEntriesO;
break;
default:
$sugarEntries = objectToArray( $sugarEntries );
}
return $sugarEntries;
}
/**
*
* @method
*
* Gets SugarCRM entries from the Calls module
*
* @name GetSugarCalls
* @label Gets SugarCRM entries from the Calls module
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $query | Query
* @param string | $orderBy | Order By
* @param string | $selectedFields | Selected Fields
* @param string | $maxResults=50 | Max Results
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarCalls | Sugar Calls (array or object) |
*
*/
function GetSugarCalls ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array")
{
$module = "Calls";
return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType );
}
/**
*
* @method
*
* Gets SugarCRM entries from the Leads module.
*
* @name GetSugarLeads
* @label Gets SugarCRM entries from the Leads module.
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $query | Query
* @param string | $orderBy | Order By
* @param string | $selectedFields | Selected Fields
* @param string | $maxResults=50 | Max Results
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarLeads | Sugar Leads (array or object) |
*
*/
function GetSugarLeads ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array")
{
$module = "Leads";
return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType );
}
/**
*
* @method
*
* Gets SugarCRM entries from the Contacts module.
*
* @name GetSugarContacts
* @label Gets SugarCRM entries from the Contacts module.
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $query | Query
* @param string | $orderBy | Order By
* @param string | $selectedFields | Selected Fields
* @param string | $maxResults=50 | Max Results
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarContacts | Sugar Contacts (array or object) |
*
*/
function GetSugarContacts ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array")
{
$module = "Contacts";
return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType );
}
/**
*
* @method
*
* Gets SugarCRM entries from the Opportunities module.
*
* @name GetSugarOpportunities
* @label Gets SugarCRM entries from the Opportunities module.
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $query | Query
* @param string | $orderBy | Order By
* @param string | $selectedFields | Selected Fields
* @param string | $maxResults=50 | Max Results
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarAccount | Sugar Opportunities (array or object) |
*
*/
function GetSugarOpportunities ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array")
{
$module = "Opportunities";
return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType );
}
/**
*
* @method
*
* Gets SugarCRM entries from the Account module.
*
* @name GetSugarAccount
* @label Gets SugarCRM entries from the Account module.
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $query | Query
* @param string | $orderBy | Order By
* @param string | $selectedFields | Selected Fields
* @param string | $maxResults=50 | Max Results
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarAccount | Sugar Opportunities (array or object) |
*
*/
function GetSugarAccount ($sugarSoap, $user, $password, $query, $orderBy, $selectedFields, $maxResults, $resultType = "array")
{
$module = "Accounts";
return GetSugarEntries( $sugarSoap, $user, $password, $module, $query, $orderBy, $selectedFields, $maxResults, $resultType );
}
/**
*
* @method
*
* Creates SugarCRM entries from the Account module.
*
* @name CreateSugarAccount
*
* @label Creates SugarCRM entries from the Account module.
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $name | Account name
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarAccount | Sugar Opportunities (array or object) |
*
*/
function CreateSugarAccount ($sugarSoap, $user, $password, $name, $resultType = "array")
{
$module = "Accounts";
$sessionId = sugarLogin( $sugarSoap, $user, $password );
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$request_array = array ('session' => $sessionId,'module_name' => $module,'name_value_list' => array (array ("name" => 'name',"value" => $name)));
$sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array );
$account_id = $sugarEntriesO->id;
switch ($resultType) {
case 'array':
$sugarEntries = objectToArray( $sugarEntriesO );
break;
case 'object':
$sugarEntries = $sugarEntries;
break;
default:
$sugarEntries = objectToArray( $sugarEntries );
}
//return $sugarEntries;
return $account_id;
}
/**
*
* @method
*
* Creates SugarCRM entries from the Contacts module
*
* @name CreateSugarContact
*
* @label Creates SugarCRM entries from the Contacts module
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $first_name | First Name
* @param string | $last_name | Last Name
* @param string | $email | Email
* @param string | $title | Title
* @param string | $phone | Phone Work
* @param string | $account_id | Valid id account
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarContact | Sugar Opportunities (array or object) |
*
*/
function CreateSugarContact ($sugarSoap, $user, $password, $first_name, $last_name, $email, $title, $phone, $account_id, $resultType = "array")
{
$module = "Contacts";
/* $aValue = array(
array("name" => 'id', "value" => G::generateUniqueID()),
array("name" => 'first_name', "value" => $first_name),
array("name" => 'last_name', "value" => $last_name),
);
*/
$sessionId = sugarLogin( $sugarSoap, $user, $password );
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$request_array = array ('session' => $sessionId,'module_name' => $module,array (array ("name" => 'first_name',"value" => $first_name
),array ("name" => 'last_name',"value" => $last_name
),array ("name" => 'email1',"value" => $email
),array ("name" => 'title',"value" => $title
),array ("name" => 'phone_work',"value" => $phone
),
// array("name" => 'account_id',"value" => '8cd10a60-101f-4363-1e0b-4cfd4106bd7e')
array ("name" => 'account_id',"value" => $account_id
)));
$sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array );
switch ($resultType) {
case 'array':
$sugarEntries = objectToArray( $sugarEntriesO );
break;
case 'object':
$sugarEntries = $sugarEntries;
break;
default:
$sugarEntries = objectToArray( $sugarEntries );
}
return $sugarEntries;
}
/**
*
* @method
*
* Creates SugarCRM entries from the Opportunities module.
*
* @name CreateSugarOpportunity
*
* @label Creates SugarCRM entries from the Opportunities module.
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $name | Name
* @param string | $account_id | Valid id account
* @param string | $amount | Amount
* @param string | $date_closed | Date Closed
* @param string | $sales_stage | Prospecting, Qualification, Needs Analysis, Value Proposition, Id. Decision Makers, Perception Analysis, Proposal/Price Quote, Negotiation/Review, Closed Won, Closed Lost
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarOpportunity | Sugar Opportunities (array or object) |
*
*/
function CreateSugarOpportunity ($sugarSoap, $user, $password, $name, $account_id, $amount, $date_closed, $sales_stage, $resultType = "array")
{
// * @param string | $account_id | Account Id
$module = "Opportunities";
/* $aValue = array(
array("name" => 'id', "value" => G::generateUniqueID()),
array("name" => 'name', "value" => $name),
array("name" => 'account_name', "value" => $account_name),
array("name" => 'amount', "value" => $amount),
array("name" => 'date_closed', "value" => $date_closed),
array("name" => 'sales_stage', "value" => $sales_stage)
);*/
$sessionId = sugarLogin( $sugarSoap, $user, $password );
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$request_array = array ('session' => $sessionId,'module_name' => $module,'name_value_list' => array (array ('name' => 'name','value' => $name
),array ("name" => 'account_id',"value" => $account_id
),array ('name' => 'amount','value' => $amount
),array ('name' => 'date_closed','value' => $date_closed
),array ('name' => 'sales_stage','value' => $sales_stage
)
)
);
$sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array );
switch ($resultType) {
case 'array':
$sugarEntries = objectToArray( $sugarEntriesO );
break;
case 'object':
$sugarEntries = $sugarEntries;
break;
default:
$sugarEntries = objectToArray( $sugarEntries );
}
return $sugarEntries;
}
/**
*
* @method
*
* Creates SugarCRM entries from the Leads module
*
* @name CreateSugarLeads
*
* @label Creates SugarCRM entries from the Leads module
*
* @param string | $sugarSoap | Sugar SOAP URL | http://www.example.com/sugar/soap.php?wsdl
* @param string | $user | User
* @param string | $password | Password
* @param string | $first_name | First Name
* @param string | $last_name | Last Name
* @param string | $email | Email
* @param string | $title | Title
* @param string | $phone | Phone Work
* @param string | $account_id | Valid id account
* @param string | $resultType=array | Result type (array or object)
*
* @return array/object | $sugarContact | Sugar Opportunities (array or object) |
*
*/
function CreateSugarLeads ($sugarSoap, $user, $password, $first_name, $last_name, $email, $title, $phone, $account_id, $resultType = "array")
{
$module = "Leads";
$sessionId = sugarLogin( $sugarSoap, $user, $password );
$client = new SoapClient( $sugarSoap, getSoapClientOptions() );
$request_array = array ('session' => $sessionId,'module_name' => $module,array (array ("name" => 'first_name',"value" => $first_name
),array ("name" => 'last_name',"value" => $last_name
),array ("name" => 'email1',"value" => $email
),array ("name" => 'title',"value" => $title
),array ("name" => 'phone_work',"value" => $phone
),
// array("name" => 'account_id',"value" => '8cd10a60-101f-4363-1e0b-4cfd4106bd7e')
array ("name" => 'account_id',"value" => $account_id
)
)
);
$sugarEntriesO = $client->__SoapCall( 'set_entry', $request_array );
switch ($resultType) {
case 'array':
$sugarEntries = objectToArray( $sugarEntriesO );
break;
case 'object':
$sugarEntries = $sugarEntries;
break;
default:
$sugarEntries = objectToArray( $sugarEntries );
}
return $sugarEntries;
}
|