PageRenderTime 55ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/soap/SoapDeprecated.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 968 lines | 644 code | 117 blank | 207 comment | 56 complexity | 309e512eb7592c910a824f991869c4b4 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. if(!defined('sugarEntry'))define('sugarEntry', true);
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. // the types/methods defined in this file are deprecated -- please see SoapSugarUsers.php, SoapPortalUsers.php, SoapStudio.php, etc.
  38. $server->wsdl->addComplexType(
  39. 'contact_detail',
  40. 'complexType',
  41. 'struct',
  42. 'all',
  43. '',
  44. array(
  45. 'email_address' => array('name'=>'email_address','type'=>'xsd:string'),
  46. 'name1' => array('name'=>'name1','type'=>'xsd:string'),
  47. 'name2' => array('name'=>'name2','type'=>'xsd:string'),
  48. 'association' => array('name'=>'association','type'=>'xsd:string'),
  49. 'id' => array('name'=>'id','type'=>'xsd:string'),
  50. 'msi_id' => array('name'=>'id','type'=>'xsd:string'),
  51. 'type' => array('name'=>'type','type'=>'xsd:string'),
  52. )
  53. );
  54. $server->wsdl->addComplexType(
  55. 'contact_detail_array',
  56. 'complexType',
  57. 'array',
  58. '',
  59. 'SOAP-ENC:Array',
  60. array(),
  61. array(
  62. array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:contact_detail[]')
  63. ),
  64. 'tns:contact_detail'
  65. );
  66. $server->wsdl->addComplexType(
  67. 'user_detail',
  68. 'complexType',
  69. 'struct',
  70. 'all',
  71. '',
  72. array(
  73. 'email_address' => array('name'=>'email_address','type'=>'xsd:string'),
  74. 'user_name' => array('name'=>'user_name', 'type'=>'xsd:string'),
  75. 'first_name' => array('name'=>'first_name','type'=>'xsd:string'),
  76. 'last_name' => array('name'=>'last_name','type'=>'xsd:string'),
  77. 'department' => array('name'=>'department','type'=>'xsd:string'),
  78. 'id' => array('name'=>'id','type'=>'xsd:string'),
  79. 'title' => array('name'=>'title','type'=>'xsd:string'),
  80. )
  81. );
  82. $server->wsdl->addComplexType(
  83. 'user_detail_array',
  84. 'complexType',
  85. 'array',
  86. '',
  87. 'SOAP-ENC:Array',
  88. array(),
  89. array(
  90. array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:user_detail[]')
  91. ),
  92. 'tns:user_detail'
  93. );
  94. $server->register(
  95. 'create_session',
  96. array('user_name'=>'xsd:string','password'=>'xsd:string'),
  97. array('return'=>'xsd:string'),
  98. $NAMESPACE);
  99. $server->register(
  100. 'end_session',
  101. array('user_name'=>'xsd:string'),
  102. array('return'=>'xsd:string'),
  103. $NAMESPACE);
  104. $server->register(
  105. 'contact_by_email',
  106. array('user_name'=>'xsd:string','password'=>'xsd:string', 'email_address'=>'xsd:string'),
  107. array('return'=>'tns:contact_detail_array'),
  108. $NAMESPACE);
  109. $server->register(
  110. 'get_contact_relationships',
  111. array('user_name'=>'xsd:string','password'=>'xsd:string', 'id'=>'xsd:string'),
  112. array('return'=>'tns:contact_detail_array'),
  113. $NAMESPACE);
  114. $server->register(
  115. 'user_list',
  116. array('user_name'=>'xsd:string','password'=>'xsd:string'),
  117. array('return'=>'tns:user_detail_array'),
  118. $NAMESPACE);
  119. $server->register(
  120. 'search',
  121. array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string'),
  122. array('return'=>'tns:contact_detail_array'),
  123. $NAMESPACE);
  124. $server->register(
  125. 'track_email',
  126. array('user_name'=>'xsd:string','password'=>'xsd:string','parent_id'=>'xsd:string', 'contact_ids'=>'xsd:string', 'date_sent'=>'xsd:date', 'email_subject'=>'xsd:string', 'email_body'=>'xsd:string'),
  127. array('return'=>'xsd:string'),
  128. $NAMESPACE);
  129. $server->register(
  130. 'create_contact',
  131. array('user_name'=>'xsd:string','password'=>'xsd:string', 'first_name'=>'xsd:string', 'last_name'=>'xsd:string', 'email_address'=>'xsd:string'),
  132. array('return'=>'xsd:string'),
  133. $NAMESPACE);
  134. $server->register(
  135. 'create_lead',
  136. array('user_name'=>'xsd:string','password'=>'xsd:string', 'first_name'=>'xsd:string', 'last_name'=>'xsd:string', 'email_address'=>'xsd:string'),
  137. array('return'=>'xsd:string'),
  138. $NAMESPACE);
  139. $server->register(
  140. 'create_account',
  141. array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string', 'phone'=>'xsd:string', 'website'=>'xsd:string'),
  142. array('return'=>'xsd:string'),
  143. $NAMESPACE);
  144. $server->register(
  145. 'create_opportunity',
  146. array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string', 'amount'=>'xsd:string'),
  147. array('return'=>'xsd:string'),
  148. $NAMESPACE);
  149. $server->register(
  150. 'create_case',
  151. array('user_name'=>'xsd:string','password'=>'xsd:string', 'name'=>'xsd:string'),
  152. array('return'=>'xsd:string'),
  153. $NAMESPACE);
  154. /**
  155. * Create a new session. This method is required before calling any other functions.
  156. *
  157. * @param string $user_name -- the user name for the session
  158. * @param string $password -- MD5 of user password
  159. * @return "Success" if the session is created
  160. * @return "Failed" if the session creation failed.
  161. */
  162. function create_session($user_name, $password)
  163. {
  164. if(validate_user($user_name, $password))
  165. {
  166. return "Success";
  167. }
  168. return "Failed";
  169. }
  170. /**
  171. * End a session. This method will end the SOAP session.
  172. *
  173. * @param string $user_name -- the user name for the session
  174. * @return "Success" if the session is destroyed
  175. * @return "Failed" if the session destruction failed.
  176. */
  177. function end_session($user_name)
  178. {
  179. // get around optimizer warning
  180. $user_name = $user_name;
  181. return "Success";
  182. }
  183. /**
  184. * Validate the user session based on user name and password hash.
  185. *
  186. * @param string $user_name -- The user name to create a session for
  187. * @param string $password -- The MD5 sum of the user's password
  188. * @return true -- If the session is created
  189. * @return false -- If the session is not created
  190. */
  191. function validate_user($user_name, $password){
  192. global $server, $current_user, $sugar_config, $system_config;
  193. $user = new User();
  194. $user->user_name = $user_name;
  195. $system_config = new Administration();
  196. $system_config->retrieveSettings('system');
  197. $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
  198. // Check to see if the user name and password are consistent.
  199. if($user->authenticate_user($password)){
  200. // we also need to set the current_user.
  201. $user->retrieve($user->id);
  202. $current_user = $user;
  203. login_success();
  204. return true;
  205. }else if(function_exists('mcrypt_cbc')){
  206. $password = decrypt_string($password);
  207. if($authController->login($user_name, $password) && isset($_SESSION['authenticated_user_id'])){
  208. $user->retrieve($_SESSION['authenticated_user_id']);
  209. $current_user = $user;
  210. login_success();
  211. return true;
  212. }
  213. }else{
  214. $GLOBALS['log']->fatal("SECURITY: failed attempted login for $user_name using SOAP api");
  215. $server->setError("Invalid username and/or password");
  216. return false;
  217. }
  218. }
  219. /**
  220. * Internal: When building a response to the plug-in for Microsoft Outlook, find
  221. * all contacts that match the email address that was provided.
  222. *
  223. * @param array by ref $output_list -- The list of matching beans. New contacts that match
  224. * the email address are appended to the $output_list
  225. * @param string $email_address -- an email address to search for
  226. * @param Contact $seed_contact -- A template SugarBean. This is a blank Contact
  227. * @param ID $msi_id -- Index Count
  228. */
  229. function add_contacts_matching_email_address(&$output_list, $email_address, &$seed_contact, &$msi_id)
  230. {
  231. // escape the email address
  232. $safe_email_address = addslashes($email_address);
  233. global $current_user;
  234. // Verify that the user has permission to see Contact list views
  235. if(!$seed_contact->ACLAccess('ListView'))
  236. {
  237. return;
  238. }
  239. $contactList = $seed_contact->emailAddress->getBeansByEmailAddress($safe_email_address);
  240. // create a return array of names and email addresses.
  241. foreach($contactList as $contact)
  242. {
  243. if (!is_a($contact, 'Contact')) continue;
  244. $output_list[] = Array("name1" => $contact->first_name,
  245. "name2" => $contact->last_name,
  246. "association" => $contact->account_name,
  247. "type" => 'Contact',
  248. "id" => $contact->id,
  249. "msi_id" => $msi_id,
  250. "email_address" => $contact->email1);
  251. $accounts = $contact->get_linked_beans('accounts','Account');
  252. foreach($accounts as $account)
  253. {
  254. $output_list[] = get_account_array($account, $msi_id);
  255. }
  256. $opps = $contact->get_linked_beans('opportunities','Opportunity');
  257. foreach($opps as $opp)
  258. {
  259. $output_list[] = get_opportunity_array($opp, $msi_id);
  260. }
  261. $cases = $contact->get_linked_beans('cases','aCase');
  262. foreach($cases as $case)
  263. {
  264. $output_list[] = get_case_array($case, $msi_id);
  265. }
  266. $bugs = $contact->get_linked_beans('bugs','Bug');
  267. foreach($bugs as $bug)
  268. {
  269. $output_list[] = get_bean_array($bug, $msi_id, 'Bug');
  270. }
  271. $projects = $contact->get_linked_beans('project','Project');
  272. foreach($projects as $project)
  273. {
  274. $output_list[] = get_bean_array($project, $msi_id, 'Project');
  275. }
  276. $msi_id = $msi_id + 1;
  277. }
  278. }
  279. /**
  280. * Internal: Add Leads that match the specified email address to the result array
  281. *
  282. * @param Array $output_list -- List of matching detail records
  283. * @param String $email_address -- Email address
  284. * @param Bean $seed_lead -- Seed Lead Bean
  285. * @param int $msi_id -- output array offset.
  286. */
  287. function add_leads_matching_email_address(&$output_list, $email_address, &$seed_lead, &$msi_id)
  288. {
  289. $safe_email_address = $GLOBALS['db']->quote($email_address);
  290. if(!$seed_lead->ACLAccess('ListView')){
  291. return;
  292. }
  293. $leadList = $seed_lead->emailAddress->getBeansByEmailAddress($safe_email_address);
  294. // create a return array of names and email addresses.
  295. foreach($leadList as $lead)
  296. {
  297. if (!is_a($lead, 'Lead')) continue;
  298. $output_list[] = Array("name1" => $lead->first_name,
  299. "name2" => $lead->last_name,
  300. "association" => $lead->account_name,
  301. "type" => 'Lead',
  302. "id" => $lead->id,
  303. "msi_id" => $msi_id,
  304. "email_address" => $lead->email1);
  305. $msi_id = $msi_id + 1;
  306. }
  307. }
  308. /**
  309. * Return a list of modules related to the specifed contact record
  310. *
  311. * This function does not require a session be created first.
  312. *
  313. * @param string $user_name -- User name to authenticate with
  314. * @param string $password -- MD5 of the user password
  315. * @param string $id -- the id of the record
  316. * @return contact detail array along with associated objects.
  317. */
  318. function get_contact_relationships($user_name, $password, $id)
  319. {
  320. if(!validate_user($user_name, $password)){
  321. return array();
  322. }
  323. $seed_contact = new Contact();
  324. // Verify that the user has permission to see Contact list views
  325. if(!$seed_contact->ACLAccess('ListView'))
  326. {
  327. return;
  328. }
  329. $msi_id = 1;
  330. $seed_contact->retrieve($id);
  331. $output_list[] = Array("name1" => $seed_contact->first_name,
  332. "name2" => $seed_contact->last_name,
  333. "association" => $seed_contact->account_name,
  334. "type" => 'Contact',
  335. "id" => $seed_contact->id,
  336. "msi_id" => $msi_id,
  337. "email_address" => $seed_contact->email1);
  338. $accounts = $seed_contact->get_linked_beans('accounts','Account');
  339. foreach($accounts as $account)
  340. {
  341. $output_list[] = get_account_array($account, $msi_id);
  342. }
  343. $opps = $seed_contact->get_linked_beans('opportunities','Opportunity');
  344. foreach($opps as $opp)
  345. {
  346. $output_list[] = get_opportunity_array($opp, $msi_id);
  347. }
  348. $cases = $seed_contact->get_linked_beans('cases','aCase');
  349. foreach($cases as $case)
  350. {
  351. $output_list[] = get_case_array($case, $msi_id);
  352. }
  353. $bugs = $seed_contact->get_linked_beans('bugs','Bug');
  354. foreach($bugs as $bug)
  355. {
  356. $output_list[] = get_bean_array($bug, $msi_id, 'Bug');
  357. }
  358. $projects = $seed_contact->get_linked_beans('project','Project');
  359. foreach($projects as $project)
  360. {
  361. $output_list[] = get_bean_array($project, $msi_id, 'Project');
  362. }
  363. return $output_list;
  364. }
  365. // Define a global current user
  366. $current_user = null;
  367. /**
  368. * Return a list of contact and lead detail records based on a single email
  369. * address or a list of email addresses separated by '; '.
  370. *
  371. * This function does not require a session be created first.
  372. *
  373. * @param string $user_name -- User name to authenticate with
  374. * @param string $password -- MD5 of the user password
  375. * @param string $email_address -- Single email address or '; ' separated list of email addresses (e.x "test@example.com; test2@example.com"
  376. * @return contact detail array along with associated objects.
  377. */
  378. function contact_by_email($user_name, $password, $email_address)
  379. {
  380. if(!validate_user($user_name, $password)){
  381. return array();
  382. }
  383. $seed_contact = new Contact();
  384. $seed_lead = new Lead();
  385. $output_list = Array();
  386. $email_address_list = explode("; ", $email_address);
  387. // remove duplicate email addresses
  388. $non_duplicate_email_address_list = Array();
  389. foreach( $email_address_list as $single_address)
  390. {
  391. // Check to see if the current address is a match of an existing address
  392. $found_match = false;
  393. foreach( $non_duplicate_email_address_list as $non_dupe_single)
  394. {
  395. if(strtolower($single_address) == $non_dupe_single)
  396. {
  397. $found_match = true;
  398. break;
  399. }
  400. }
  401. if($found_match == false)
  402. {
  403. $non_duplicate_email_address_list[] = strtolower($single_address);
  404. }
  405. }
  406. // now copy over the non-duplicated list as the original list.
  407. $email_address_list =$non_duplicate_email_address_list;
  408. // Track the msi_id
  409. $msi_id = 1;
  410. foreach( $email_address_list as $single_address)
  411. {
  412. // verify that contacts can be listed
  413. if($seed_contact->ACLAccess('ListView')){
  414. add_contacts_matching_email_address($output_list, $single_address, $seed_contact, $msi_id);
  415. }
  416. // verify that leads can be listed
  417. if($seed_lead->ACLAccess('ListView')){
  418. add_leads_matching_email_address($output_list, $single_address, $seed_lead, $msi_id);
  419. }
  420. }
  421. return $output_list;
  422. }
  423. /**
  424. * Internal: convert a bean into an array
  425. *
  426. * @param Bean $bean -- The bean to convert
  427. * @param int $msi_id -- Russult array index
  428. * @return An associated array containing the detail fields.
  429. */
  430. function get_contact_array($contact, $msi_id = '0'){
  431. $contact->emailAddress->handleLegacyRetrieve($contact);
  432. return Array("name1" => $contact->first_name,
  433. "name2" => $contact->last_name,
  434. "association" => $contact->account_name,
  435. "type" => 'Contact',
  436. "id" => $contact->id,
  437. "msi_id" => $msi_id,
  438. "email_address" => $contact->email1);
  439. }
  440. /**
  441. * Internal: Convert a user into an array
  442. *
  443. * @param User $user -- The user to convert
  444. * @return An associated array containing the detail fields.
  445. */
  446. function get_user_list_array($user) {
  447. return Array('email_address' => $user->email1,
  448. 'user_name' => $user->user_name,
  449. 'first_name' => $user->first_name,
  450. 'last_name' => $user->last_name,
  451. 'department' => $user->department,
  452. 'id' => $user->id,
  453. 'title' => $user->title);
  454. }
  455. /**
  456. * Get a full user list.
  457. *
  458. * This function does not require a session be created first.
  459. *
  460. * @param string $user -- user name for validation
  461. * @param password $password -- MD5 hash of the user password for validation
  462. * @return User Array -- An array of user detail records
  463. */
  464. function user_list($user, $password) {
  465. if(!validate_user($user, $password)){
  466. return array();
  467. }
  468. $seed_user = new User();
  469. $output_list = Array();
  470. if(!$seed_user->ACLAccess('ListView')){
  471. return $output_list;
  472. }
  473. $userList = $seed_user->get_full_list();
  474. foreach($userList as $user) {
  475. $output_list[] = get_user_list_array($user);
  476. }
  477. return $output_list;
  478. }
  479. /**
  480. * Internal: Search for contacts based on the specified name and where clause.
  481. * Currently only the name is used.
  482. *
  483. * @param string $name -- Name to search for.
  484. * @param string $where -- Where clause defaults to ''
  485. * @param int $msi_id -- Response array index
  486. * @return array -- Resturns a list of contacts that have the provided name.
  487. */
  488. function contact_by_search($name, $where = '', $msi_id = '0')
  489. {
  490. $seed_contact = new Contact();
  491. if($where == ''){
  492. $where = $seed_contact->build_generic_where_clause($name);
  493. }
  494. if(!$seed_contact->ACLAccess('ListView')){
  495. return array();
  496. }
  497. $response = $seed_contact->get_list("last_name, first_name", $where, 0);
  498. $contactList = $response['list'];
  499. $output_list = Array();
  500. // create a return array of names and email addresses.
  501. foreach($contactList as $contact)
  502. {
  503. $output_list[] = get_contact_array($contact, $msi_id);
  504. }
  505. return $output_list;
  506. }
  507. /**
  508. * Internal: convert a bean into an array
  509. *
  510. * @param Bean $bean -- The bean to convert
  511. * @param int $msi_id -- Russult array index
  512. * @return An associated array containing the detail fields.
  513. */
  514. function get_lead_array($lead, $msi_id = '0'){
  515. $lead->emailAddress->handleLegacyRetrieve($lead);
  516. return Array("name1" => $lead->first_name,
  517. "name2" => $lead->last_name,
  518. "association" => $lead->account_name,
  519. "type" => 'Lead',
  520. "id" => $lead->id,
  521. "msi_id" => $msi_id,
  522. "email_address" => $lead->email1);
  523. }
  524. function lead_by_search($name, $where = '', $msi_id = '0')
  525. {
  526. $seed_lead = new Lead();
  527. if($where == ''){
  528. $where = $seed_lead->build_generic_where_clause($name);
  529. }
  530. if(!$seed_lead->ACLAccess('ListView')){
  531. return array();
  532. }
  533. $response = $seed_lead->get_list("last_name, first_name", $where, 0);
  534. $lead_list = $response['list'];
  535. $output_list = Array();
  536. // create a return array of names and email addresses.
  537. foreach($lead_list as $lead)
  538. {
  539. $output_list[] = get_lead_array($lead, $msi_id);
  540. }
  541. return $output_list;
  542. }
  543. /**
  544. * Internal: convert a bean into an array
  545. *
  546. * @param Bean $bean -- The bean to convert
  547. * @param int $msi_id -- Russult array index
  548. * @return An associated array containing the detail fields.
  549. */
  550. function get_account_array($account, $msi_id){
  551. return Array("name1" => '',
  552. "name2" => $account->name,
  553. "association" => $account->billing_address_city,
  554. "type" => 'Account',
  555. "id" => $account->id,
  556. "msi_id" => $msi_id,
  557. "email_address" => $account->email1);
  558. }
  559. function account_by_search($name, $where = '', $msi_id = '0')
  560. {
  561. $seed_account = new Account();
  562. if(!$seed_account->ACLAccess('ListView')){
  563. return array();
  564. }
  565. if($where == ''){
  566. $where = $seed_account->build_generic_where_clause($name);
  567. }
  568. $response = $seed_account->get_list("name", $where, 0);
  569. $accountList = $response['list'];
  570. $output_list = Array();
  571. // create a return array of names and email addresses.
  572. foreach($accountList as $account)
  573. {
  574. $output_list[] = get_account_array($account, $msi_id);
  575. }
  576. return $output_list;
  577. }
  578. /**
  579. * Internal: convert a bean into an array
  580. *
  581. * @param Bean $bean -- The bean to convert
  582. * @param int $msi_id -- Russult array index
  583. * @return An associated array containing the detail fields.
  584. */
  585. function get_opportunity_array($value, $msi_id = '0'){
  586. return Array("name1" => '',
  587. "name2" => $value->name,
  588. "association" => $value->account_name,
  589. "type" => 'Opportunity',
  590. "id" => $value->id,
  591. "msi_id" => $msi_id,
  592. "email_address" => '');
  593. }
  594. function opportunity_by_search($name, $where = '', $msi_id = '0')
  595. {
  596. $seed = new Opportunity();
  597. if(!$seed->ACLAccess('ListView')){
  598. return array();
  599. }
  600. if($where == ''){
  601. $where = $seed->build_generic_where_clause($name);
  602. }
  603. $response = $seed->get_list("name", $where, 0);
  604. $list = $response['list'];
  605. $output_list = Array();
  606. // create a return array of names and email addresses.
  607. foreach($list as $value)
  608. {
  609. $output_list[] = get_opportunity_array($value, $msi_id);
  610. }
  611. return $output_list;
  612. }
  613. /**
  614. * Internal: convert a bean into an array
  615. *
  616. * @param Bean $bean -- The bean to convert
  617. * @param int $msi_id -- Russult array index
  618. * @return An associated array containing the detail fields.
  619. */
  620. function get_bean_array($value, $msi_id, $type){
  621. return Array("name1" => '',
  622. "name2" => $value->get_summary_text(),
  623. "association" => '',
  624. "type" => $type,
  625. "id" => $value->id,
  626. "msi_id" => $msi_id,
  627. "email_address" => '');
  628. }
  629. /**
  630. * Internal: convert a bean into an array
  631. *
  632. * @param Bean $bean -- The bean to convert
  633. * @param int $msi_id -- Russult array index
  634. * @return An associated array containing the detail fields.
  635. */
  636. function get_case_array($value, $msi_id){
  637. return Array("name1" => '',
  638. "name2" => $value->get_summary_text(),
  639. "association" => $value->account_name,
  640. "type" => 'Case',
  641. "id" => $value->id,
  642. "msi_id" => $msi_id,
  643. "email_address" => '');
  644. }
  645. function bug_by_search($name, $where = '', $msi_id='0')
  646. {
  647. $seed = new Bug();
  648. if(!$seed->ACLAccess('ListView')){
  649. return array();
  650. }
  651. if($where == ''){
  652. $where = $seed->build_generic_where_clause($name);
  653. }
  654. $response = $seed->get_list("name", $where, 0);
  655. $list = $response['list'];
  656. $output_list = Array();
  657. // create a return array of names and email addresses.
  658. foreach($list as $value)
  659. {
  660. $output_list[] = get_bean_array($value, $msi_id, 'Bug');
  661. }
  662. return $output_list;
  663. }
  664. function case_by_search($name, $where = '', $msi_id='0')
  665. {
  666. $seed = new aCase();
  667. if(!$seed->ACLAccess('ListView')){
  668. return array();
  669. }
  670. if($where == ''){
  671. $where = $seed->build_generic_where_clause($name);
  672. }
  673. $response = $seed->get_list("name", $where, 0);
  674. $list = $response['list'];
  675. $output_list = Array();
  676. // create a return array of names and email addresses.
  677. foreach($list as $value)
  678. {
  679. $output_list[] = get_case_array($value, $msi_id);
  680. }
  681. return $output_list;
  682. }
  683. /**
  684. * Record and email message and associated it with the specified parent bean and contact ids.
  685. *
  686. * This function does not require a session be created first.
  687. *
  688. * @param string $user_name -- Name of the user to authenticate
  689. * @param string $password -- MD5 hash of the user password for authentication
  690. * @param id $parent_id -- [optional] The parent record to link the email to.
  691. * @param unknown_type $contact_ids
  692. * @param string $date_sent -- Date/time the email was sent in Visual Basic Date format. (e.g. '7/22/2004 9:36:31 AM')
  693. * @param string $email_subject -- The subject of the email
  694. * @param string $email_body -- The body of the email
  695. * @return "Invalid username and/or password"
  696. * @return -1 If the authenticated user does not have ACL access to save Email.
  697. */
  698. function track_email($user_name, $password,$parent_id, $contact_ids, $date_sent, $email_subject, $email_body)
  699. {
  700. if(!validate_user($user_name, $password)){
  701. return "Invalid username and/or password";
  702. }
  703. global $current_user;
  704. $GLOBALS['log']->info("In track email: username: $user_name contacts: $contact_ids date_sent: $date_sent");
  705. // translate date sent from VB format 7/22/2004 9:36:31 AM
  706. // to yyyy-mm-dd 9:36:31 AM
  707. $date_sent = preg_replace("@([0-9]*)/([0-9]*)/([0-9]*)( .*$)@", "\\3-\\1-\\2\\4", $date_sent);
  708. $seed_user = new User();
  709. $user_id = $seed_user->retrieve_user_id($user_name);
  710. $seed_user->retrieve($user_id);
  711. $current_user = $seed_user;
  712. $email = new Email();
  713. if(!$email->ACLAccess('Save')){
  714. return -1;
  715. }
  716. $email->description = $email_body;
  717. $email->name = $email_subject;
  718. $email->user_id = $user_id;
  719. $email->assigned_user_id = $user_id;
  720. $email->assigned_user_name = $user_name;
  721. $email->date_start = $date_sent;
  722. // Save one copy of the email message
  723. $parent_id_list = explode(";", $parent_id);
  724. $parent_id = explode(':', $parent_id_list[0]);
  725. // Having a parent object is optional. If it is set, then associate it.
  726. if(isset($parent_id[0]) && isset($parent_id[1]))
  727. {
  728. $email->parent_type = $parent_id[0];
  729. $email->parent_id = $parent_id[1];
  730. }
  731. $email->save();
  732. // for each contact, add a link between the contact and the email message
  733. $id_list = explode(";", $contact_ids);
  734. foreach( $id_list as $id)
  735. {
  736. if(!empty($id)) {
  737. $email->set_emails_contact_invitee_relationship($email->id, $GLOBALS['db']->quote($id));
  738. }
  739. }
  740. return "Succeeded";
  741. }
  742. function create_contact($user_name,$password, $first_name, $last_name, $email_address)
  743. {
  744. if(!validate_user($user_name, $password)){
  745. return 0;
  746. }
  747. $seed_user = new User();
  748. $user_id = $seed_user->retrieve_user_id($user_name);
  749. $seed_user->retrieve($user_id);
  750. $contact = new Contact();
  751. if(!$contact->ACLAccess('Save')){
  752. return -1;
  753. }
  754. $contact->first_name = $first_name;
  755. $contact->last_name = $last_name;
  756. $contact->email1 = $email_address;
  757. $contact->assigned_user_id = $user_id;
  758. $contact->assigned_user_name = $user_name;
  759. return $contact->save();
  760. }
  761. function create_lead($user_name,$password, $first_name, $last_name, $email_address)
  762. {
  763. if(!validate_user($user_name, $password)){
  764. return 0;
  765. }
  766. //todo make the activity body not be html encoded
  767. $seed_user = new User();
  768. $user_id = $seed_user->retrieve_user_id($user_name);
  769. $lead = new Lead();
  770. if(!$lead->ACLAccess('Save')){
  771. return -1;
  772. }
  773. $lead->first_name = $first_name;
  774. $lead->last_name = $last_name;
  775. $lead->email1 = $email_address;
  776. $lead->assigned_user_id = $user_id;
  777. $lead->assigned_user_name = $user_name;
  778. return $lead->save();
  779. }
  780. function create_account($user_name,$password, $name, $phone, $website)
  781. {
  782. if(!validate_user($user_name, $password)){
  783. return 0;
  784. }
  785. //todo make the activity body not be html encoded
  786. $seed_user = new User();
  787. $user_id = $seed_user->retrieve_user_id($user_name);
  788. $account = new Account();
  789. if(!$account->ACLAccess('Save')){
  790. return -1;
  791. }
  792. $account->name = $name;
  793. $account->phone_office = $phone;
  794. $account->website = $website;
  795. $account->assigned_user_id = $user_id;
  796. $account->assigned_user_name = $user_name;
  797. $account->save();
  798. return $account->id;
  799. }
  800. function create_case($user_name,$password, $name)
  801. {
  802. if(!validate_user($user_name, $password)){
  803. return 0;
  804. }
  805. //todo make the activity body not be html encoded
  806. $seed_user = new User();
  807. $user_id = $seed_user->retrieve_user_id($user_name);
  808. $case = new aCase();
  809. if(!$case->ACLAccess('Save')){
  810. return -1;
  811. }
  812. $case->assigned_user_id = $user_id;
  813. $case->assigned_user_name = $user_name;
  814. $case->name = $name;
  815. return $case->save();
  816. }
  817. function create_opportunity($user_name,$password, $name, $amount)
  818. {
  819. if(!validate_user($user_name, $password)){
  820. return 0;
  821. }
  822. $seed_user = new User();
  823. $user_id = $seed_user->retrieve_user_id($user_name);
  824. $opp = new Opportunity();
  825. if(!$opp->ACLAccess('Save')){
  826. return -1;
  827. }
  828. $opp->name = $name;
  829. $opp->amount = $amount;
  830. $opp->assigned_user_id = $user_id;
  831. $opp->assigned_user_name = $user_name;
  832. return $opp->save();
  833. }
  834. function search($user_name, $password,$name){
  835. if(!validate_user($user_name, $password)){
  836. return array();
  837. }
  838. $name_list = explode("; ", $name);
  839. $list = array();
  840. foreach( $name_list as $single_name)
  841. {
  842. $list = array_merge($list, contact_by_search($single_name));
  843. $list = array_merge($list, lead_by_search($single_name));
  844. $list = array_merge($list, account_by_search($single_name));
  845. $list = array_merge($list, case_by_search($single_name));
  846. $list = array_merge($list, opportunity_by_search($single_name));
  847. $list = array_merge($list, bug_by_search($single_name));
  848. }
  849. return $list;
  850. }
  851. ?>