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

/service/core/SugarWebServiceImpl.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 1167 lines | 747 code | 119 blank | 301 comment | 172 complexity | bdc0e19d2da95de1637ce71b75b987c8 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  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. /**
  38. * This class is an implemenatation class for all the web services
  39. */
  40. require_once('service/core/SoapHelperWebService.php');
  41. SugarWebServiceImpl::$helperObject = new SoapHelperWebServices();
  42. class SugarWebServiceImpl{
  43. public static $helperObject = null;
  44. /**
  45. * Retrieve a single SugarBean based on ID.
  46. *
  47. * @param String $session -- Session ID returned by a previous call to login.
  48. * @param String $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  49. * @param String $id -- The SugarBean's ID value.
  50. * @param Array $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
  51. * @param Array $link_name_to_fields_array -- A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
  52. * @return Array
  53. * 'entry_list' -- Array - The records name value pair for the simple data types excluding link field data.
  54. * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts email address then return data would look like Array ( [0] => Array ( [name] => email_addresses [records] => Array ( [0] => Array ( [0] => Array ( [name] => id [value] => 3fb16797-8d90-0a94-ac12-490b63a6be67 ) [1] => Array ( [name] => email_address [value] => hr.kid.qa@example.com ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 1 ) ) [1] => Array ( [0] => Array ( [name] => id [value] => 403f8da1-214b-6a88-9cef-490b63d43566 ) [1] => Array ( [name] => email_address [value] => kid.hr@example.name ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 0 ) ) ) ) )
  55. * @exception 'SoapFault' -- The SOAP error, if any
  56. */
  57. function get_entry($session, $module_name, $id,$select_fields, $link_name_to_fields_array){
  58. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entry');
  59. return self::get_entries($session, $module_name, array($id), $select_fields, $link_name_to_fields_array);
  60. $GLOBALS['log']->info('end: SugarWebServiceImpl->get_entry');
  61. }
  62. /**
  63. * Retrieve a list of SugarBean's based on provided IDs. This API will not wotk with report module
  64. *
  65. * @param String $session -- Session ID returned by a previous call to login.
  66. * @param String $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  67. * @param Array $ids -- An array of SugarBean IDs.
  68. * @param Array $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
  69. * @param Array $link_name_to_fields_array -- A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
  70. * @return Array
  71. * 'entry_list' -- Array - The records name value pair for the simple data types excluding link field data.
  72. * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts email address then return data would look like Array ( [0] => Array ( [name] => email_addresses [records] => Array ( [0] => Array ( [0] => Array ( [name] => id [value] => 3fb16797-8d90-0a94-ac12-490b63a6be67 ) [1] => Array ( [name] => email_address [value] => hr.kid.qa@example.com ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 1 ) ) [1] => Array ( [0] => Array ( [name] => id [value] => 403f8da1-214b-6a88-9cef-490b63d43566 ) [1] => Array ( [name] => email_address [value] => kid.hr@example.name ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 0 ) ) ) ) )
  73. * @exception 'SoapFault' -- The SOAP error, if any
  74. */
  75. function get_entries($session, $module_name, $ids, $select_fields, $link_name_to_fields_array){
  76. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entries');
  77. global $beanList, $beanFiles;
  78. $error = new SoapError();
  79. $linkoutput_list = array();
  80. $output_list = array();
  81. $using_cp = false;
  82. if($module_name == 'CampaignProspects'){
  83. $module_name = 'Prospects';
  84. $using_cp = true;
  85. }
  86. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
  87. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries');
  88. return;
  89. } // if
  90. if($module_name == 'Reports'){
  91. $error->set_error('invalid_call_error');
  92. self::$helperObject->setFaultObject($error);
  93. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries');
  94. return;
  95. }
  96. $class_name = $beanList[$module_name];
  97. require_once($beanFiles[$class_name]);
  98. $temp = new $class_name();
  99. foreach($ids as $id) {
  100. $seed = @clone($temp);
  101. if($using_cp){
  102. $seed = $seed->retrieveTarget($id);
  103. }else{
  104. if ($seed->retrieve($id) == null)
  105. $seed->deleted = 1;
  106. }
  107. if ($seed->deleted == 1) {
  108. $list = array();
  109. $list[] = array('name'=>'warning', 'value'=>'Access to this object is denied since it has been deleted or does not exist');
  110. $list[] = array('name'=>'deleted', 'value'=>'1');
  111. $output_list[] = Array('id'=>$id,
  112. 'module_name'=> $module_name,
  113. 'name_value_list'=>$list,
  114. );
  115. continue;
  116. }
  117. if (!self::$helperObject->checkACLAccess($seed, 'DetailView', $error, 'no_access')) {
  118. return;
  119. }
  120. $output_list[] = self::$helperObject->get_return_value_for_fields($seed, $module_name, $select_fields);
  121. if (!empty($link_name_to_fields_array)) {
  122. $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($seed, $module_name, $link_name_to_fields_array);
  123. }
  124. }
  125. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries');
  126. return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
  127. }
  128. /**
  129. * Retrieve a list of beans. This is the primary method for getting list of SugarBeans from Sugar using the SOAP API.
  130. *
  131. * @param String $session -- Session ID returned by a previous call to login.
  132. * @param String $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  133. * @param String $query -- SQL where clause without the word 'where'
  134. * @param String $order_by -- SQL order by clause without the phrase 'order by'
  135. * @param integer $offset -- The record offset to start from.
  136. * @param Array $select_fields -- A list of the fields to be included in the results. This optional parameter allows for only needed fields to be retrieved.
  137. * @param Array $link_name_to_fields_array -- A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
  138. * @param integer $max_results -- The maximum number of records to return. The default is the sugar configuration value for 'list_max_entries_per_page'
  139. * @param integer $deleted -- false if deleted records should not be include, true if deleted records should be included.
  140. * @return Array 'result_count' -- integer - The number of records returned
  141. * 'next_offset' -- integer - The start of the next page (This will always be the previous offset plus the number of rows returned. It does not indicate if there is additional data unless you calculate that the next_offset happens to be closer than it should be.
  142. * 'entry_list' -- Array - The records that were retrieved
  143. * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts email address then return data would look like Array ( [0] => Array ( [name] => email_addresses [records] => Array ( [0] => Array ( [0] => Array ( [name] => id [value] => 3fb16797-8d90-0a94-ac12-490b63a6be67 ) [1] => Array ( [name] => email_address [value] => hr.kid.qa@example.com ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 1 ) ) [1] => Array ( [0] => Array ( [name] => id [value] => 403f8da1-214b-6a88-9cef-490b63d43566 ) [1] => Array ( [name] => email_address [value] => kid.hr@example.name ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 0 ) ) ) ) )
  144. * @exception 'SoapFault' -- The SOAP error, if any
  145. */
  146. function get_entry_list($session, $module_name, $query, $order_by,$offset, $select_fields, $link_name_to_fields_array, $max_results, $deleted ){
  147. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entry_list');
  148. global $beanList, $beanFiles;
  149. $error = new SoapError();
  150. $using_cp = false;
  151. if($module_name == 'CampaignProspects'){
  152. $module_name = 'Prospects';
  153. $using_cp = true;
  154. }
  155. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
  156. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
  157. return;
  158. } // if
  159. // If the maximum number of entries per page was specified, override the configuration value.
  160. if($max_results > 0){
  161. global $sugar_config;
  162. $sugar_config['list_max_entries_per_page'] = $max_results;
  163. } // if
  164. $class_name = $beanList[$module_name];
  165. require_once($beanFiles[$class_name]);
  166. $seed = new $class_name();
  167. if (!self::$helperObject->checkQuery($error, $query, $order_by)) {
  168. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
  169. return;
  170. } // if
  171. if (!self::$helperObject->checkACLAccess($seed, 'Export', $error, 'no_access')) {
  172. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
  173. return;
  174. } // if
  175. if (!self::$helperObject->checkACLAccess($seed, 'list', $error, 'no_access')) {
  176. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
  177. return;
  178. } // if
  179. if($query == ''){
  180. $where = '';
  181. } // if
  182. if($offset == '' || $offset == -1){
  183. $offset = 0;
  184. } // if
  185. if($using_cp){
  186. $response = $seed->retrieveTargetList($query, $select_fields, $offset,-1,-1,$deleted);
  187. }else{
  188. /* @var $seed SugarBean */
  189. $response = $seed->get_list($order_by, $query, $offset,-1,-1,$deleted, false, $select_fields);
  190. } // else
  191. $list = $response['list'];
  192. $output_list = array();
  193. $linkoutput_list = array();
  194. foreach($list as $value) {
  195. if(isset($value->emailAddress)){
  196. $value->emailAddress->handleLegacyRetrieve($value);
  197. } // if
  198. $value->fill_in_additional_detail_fields();
  199. $output_list[] = self::$helperObject->get_return_value_for_fields($value, $module_name, $select_fields);
  200. if(!empty($link_name_to_fields_array)){
  201. $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($value, $module_name, $link_name_to_fields_array);
  202. }
  203. } // foreach
  204. // Calculate the offset for the start of the next page
  205. $next_offset = $offset + sizeof($output_list);
  206. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
  207. return array('result_count'=>sizeof($output_list), 'next_offset'=>$next_offset, 'entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
  208. } // fn
  209. /**
  210. * Set a single relationship between two beans. The items are related by module name and id.
  211. *
  212. * @param String $session -- Session ID returned by a previous call to login.
  213. * @param String $module_name -- name of the module that the primary record is from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  214. * @param String $module_id - The ID of the bean in the specified module_name
  215. * @param String link_field_name -- name of the link field which relates to the other module for which the relationship needs to be generated.
  216. * @param array related_ids -- array of related record ids for which relationships needs to be generated
  217. * @param array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
  218. * @param integer $delete -- Optional, if the value 0 or nothing is passed then it will add the relationship for related_ids and if 1 is passed, it will delete this relationship for related_ids
  219. * @return Array - created - integer - How many relationships has been created
  220. * - failed - integer - How many relationsip creation failed
  221. * - deleted - integer - How many relationships were deleted
  222. * @exception 'SoapFault' -- The SOAP error, if any
  223. */
  224. function set_relationship($session, $module_name, $module_id, $link_field_name, $related_ids, $name_value_list, $delete){
  225. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_relationship');
  226. $error = new SoapError();
  227. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  228. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationship');
  229. return;
  230. } // if
  231. $count = 0;
  232. $deletedCount = 0;
  233. $failed = 0;
  234. $deleted = 0;
  235. $name_value_array = array();
  236. if (is_array($name_value_list)) {
  237. $name_value_array = $name_value_list;
  238. }
  239. if (isset($delete)) {
  240. $deleted = $delete;
  241. }
  242. if (self::$helperObject->new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids,$name_value_array, $deleted)) {
  243. if ($deleted) {
  244. $deletedCount++;
  245. } else {
  246. $count++;
  247. }
  248. } else {
  249. $failed++;
  250. } // else
  251. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationship');
  252. return array('created'=>$count , 'failed'=>$failed, 'deleted' => $deletedCount);
  253. }
  254. /**
  255. * Set a single relationship between two beans. The items are related by module name and id.
  256. *
  257. * @param String $session -- Session ID returned by a previous call to login.
  258. * @param array $module_names -- Array of the name of the module that the primary record is from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  259. * @param array $module_ids - The array of ID of the bean in the specified module_name
  260. * @param array $link_field_names -- Array of the name of the link field which relates to the other module for which the relationships needs to be generated.
  261. * @param array $related_ids -- array of an array of related record ids for which relationships needs to be generated
  262. * @param array $name_value_lists -- Array of Array. The keys of the inner array are the SugarBean attributes, the values of the inner array are the values the attributes should have.
  263. * @param array int $delete_array -- Optional, array of 0 or 1. If the value 0 or nothing is passed then it will add the relationship for related_ids and if 1 is passed, it will delete this relationship for related_ids
  264. * @return Array - created - integer - How many relationships has been created
  265. * - failed - integer - How many relationsip creation failed
  266. * - deleted - integer - How many relationships were deleted
  267. *
  268. * @exception 'SoapFault' -- The SOAP error, if any
  269. */
  270. function set_relationships($session, $module_names, $module_ids, $link_field_names, $related_ids, $name_value_lists, $delete_array) {
  271. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_relationships');
  272. $error = new SoapError();
  273. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  274. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationships');
  275. return;
  276. } // if
  277. if ((empty($module_names) || empty($module_ids) || empty($link_field_names) || empty($related_ids)) ||
  278. (sizeof($module_names) != (sizeof($module_ids) || sizeof($link_field_names) || sizeof($related_ids)))) {
  279. $error->set_error('invalid_data_format');
  280. self::$helperObject->setFaultObject($error);
  281. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationships');
  282. return;
  283. } // if
  284. $count = 0;
  285. $deletedCount = 0;
  286. $failed = 0;
  287. $counter = 0;
  288. $deleted = 0;
  289. foreach($module_names as $module_name) {
  290. $name_value_list = array();
  291. if (is_array($name_value_lists) && isset($name_value_lists[$counter])) {
  292. $name_value_list = $name_value_lists[$counter];
  293. }
  294. if (is_array($delete_array) && isset($delete_array[$counter])) {
  295. $deleted = $delete_array[$counter];
  296. }
  297. if (self::$helperObject->new_handle_set_relationship($module_name, $module_ids[$counter], $link_field_names[$counter], $related_ids[$counter], $name_value_list, $deleted)) {
  298. if ($deleted) {
  299. $deletedCount++;
  300. } else {
  301. $count++;
  302. }
  303. } else {
  304. $failed++;
  305. } // else
  306. $counter++;
  307. } // foreach
  308. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationships');
  309. return array('created'=>$count , 'failed'=>$failed, 'deleted' => $deletedCount);
  310. } // fn
  311. /**
  312. * Retrieve a collection of beans that are related to the specified bean and optionally return relationship data for those related beans.
  313. * So in this API you can get contacts info for an account and also return all those contact's email address or an opportunity info also.
  314. *
  315. * @param String $session -- Session ID returned by a previous call to login.
  316. * @param String $module_name -- The name of the module that the primary record is from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  317. * @param String $module_id -- The ID of the bean in the specified module
  318. * @param String $link_field_name -- The name of the lnk field to return records from. This name should be the name the relationship.
  319. * @param String $related_module_query -- A portion of the where clause of the SQL statement to find the related items. The SQL query will already be filtered to only include the beans that are related to the specified bean. (IGNORED)
  320. * @param Array $related_fields - Array of related bean fields to be returned.
  321. * @param Array $related_module_link_name_to_fields_array - For every related bean returrned, specify link fields name to fields info for that bean to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))).
  322. * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
  323. * @return Array 'entry_list' -- Array - The records that were retrieved
  324. * 'relationship_list' -- Array - The records link field data. The example is if asked about accounts contacts email address then return data would look like Array ( [0] => Array ( [name] => email_addresses [records] => Array ( [0] => Array ( [0] => Array ( [name] => id [value] => 3fb16797-8d90-0a94-ac12-490b63a6be67 ) [1] => Array ( [name] => email_address [value] => hr.kid.qa@example.com ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 1 ) ) [1] => Array ( [0] => Array ( [name] => id [value] => 403f8da1-214b-6a88-9cef-490b63d43566 ) [1] => Array ( [name] => email_address [value] => kid.hr@example.name ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 0 ) ) ) ) )
  325. * @exception 'SoapFault' -- The SOAP error, if any
  326. */
  327. function get_relationships($session, $module_name, $module_id, $link_field_name, $related_module_query, $related_fields, $related_module_link_name_to_fields_array, $deleted){
  328. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_relationships');
  329. global $beanList, $beanFiles;
  330. $error = new SoapError();
  331. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
  332. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
  333. return;
  334. } // if
  335. $class_name = $beanList[$module_name];
  336. require_once($beanFiles[$class_name]);
  337. $mod = new $class_name();
  338. $mod->retrieve($module_id);
  339. if (!self::$helperObject->checkQuery($error, $related_module_query)) {
  340. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
  341. return;
  342. } // if
  343. if (!self::$helperObject->checkACLAccess($mod, 'DetailView', $error, 'no_access')) {
  344. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
  345. return;
  346. } // if
  347. $output_list = array();
  348. $linkoutput_list = array();
  349. // get all the related mmodules data.
  350. $result = self::$helperObject->getRelationshipResults($mod, $link_field_name, $related_fields, $related_module_query);
  351. if (self::$helperObject->isLogLevelDebug()) {
  352. $GLOBALS['log']->debug('SoapHelperWebServices->get_relationships - return data for getRelationshipResults is ' . var_export($result, true));
  353. } // if
  354. if ($result) {
  355. $list = $result['rows'];
  356. $filterFields = $result['fields_set_on_rows'];
  357. if (sizeof($list) > 0) {
  358. // get the related module name and instantiate a bean for that.
  359. $submodulename = $mod->$link_field_name->getRelatedModuleName();
  360. $submoduleclass = $beanList[$submodulename];
  361. require_once($beanFiles[$submoduleclass]);
  362. $submoduletemp = new $submoduleclass();
  363. foreach($list as $row) {
  364. $submoduleobject = @clone($submoduletemp);
  365. // set all the database data to this object
  366. foreach ($filterFields as $field) {
  367. $submoduleobject->$field = $row[$field];
  368. } // foreach
  369. if (isset($row['id'])) {
  370. $submoduleobject->id = $row['id'];
  371. }
  372. $output_list[] = self::$helperObject->get_return_value_for_fields($submoduleobject, $submodulename, $filterFields);
  373. if (!empty($related_module_link_name_to_fields_array)) {
  374. $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($submoduleobject, $submodulename, $related_module_link_name_to_fields_array);
  375. } // if
  376. } // foreach
  377. }
  378. } // if
  379. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
  380. return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
  381. } // fn
  382. /**
  383. * Update or create a single SugarBean.
  384. *
  385. * @param String $session -- Session ID returned by a previous call to login.
  386. * @param String $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  387. * @param Array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
  388. * @return Array 'id' -- the ID of the bean that was written to (-1 on error)
  389. * @exception 'SoapFault' -- The SOAP error, if any
  390. */
  391. function set_entry($session,$module_name, $name_value_list){
  392. global $beanList, $beanFiles, $current_user;
  393. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_entry');
  394. if (self::$helperObject->isLogLevelDebug()) {
  395. $GLOBALS['log']->debug('SoapHelperWebServices->set_entry - input data is ' . var_export($name_value_list, true));
  396. } // if
  397. $error = new SoapError();
  398. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'write', 'no_access', $error)) {
  399. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entry');
  400. return;
  401. } // if
  402. $class_name = $beanList[$module_name];
  403. require_once($beanFiles[$class_name]);
  404. $seed = new $class_name();
  405. foreach($name_value_list as $name=>$value){
  406. if(is_array($value) && $value['name'] == 'id'){
  407. $seed->retrieve($value['value']);
  408. break;
  409. }else if($name === 'id' ){
  410. $seed->retrieve($value);
  411. }
  412. }
  413. foreach($name_value_list as $name=>$value){
  414. if($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $name == 'user_hash'){
  415. continue;
  416. }
  417. if(!is_array($value)){
  418. $seed->$name = $value;
  419. }else{
  420. $seed->$value['name'] = $value['value'];
  421. }
  422. }
  423. if (!self::$helperObject->checkACLAccess($seed, 'Save', $error, 'no_access') || ($seed->deleted == 1 && !self::$helperObject->checkACLAccess($seed, 'Delete', $error, 'no_access'))) {
  424. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entry');
  425. return;
  426. } // if
  427. $seed->save(self::$helperObject->checkSaveOnNotify());
  428. if($seed->deleted == 1){
  429. $seed->mark_deleted($seed->id);
  430. }
  431. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entry');
  432. return array('id'=>$seed->id);
  433. } // fn
  434. /**
  435. * Update or create a list of SugarBeans
  436. *
  437. * @param String $session -- Session ID returned by a previous call to login.
  438. * @param String $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  439. * @param Array $name_value_lists -- Array of Bean specific Arrays where the keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
  440. * @return Array 'ids' -- Array of the IDs of the beans that was written to (-1 on error)
  441. * @exception 'SoapFault' -- The SOAP error, if any
  442. */
  443. function set_entries($session,$module_name, $name_value_lists){
  444. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_entries');
  445. if (self::$helperObject->isLogLevelDebug()) {
  446. $GLOBALS['log']->debug('SoapHelperWebServices->set_entries - input data is ' . var_export($name_value_lists, true));
  447. } // if
  448. $error = new SoapError();
  449. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'write', 'no_access', $error)) {
  450. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entries');
  451. return;
  452. } // if
  453. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entries');
  454. return self::$helperObject->new_handle_set_entries($module_name, $name_value_lists, FALSE);
  455. }
  456. /**
  457. * Log the user into the application
  458. *
  459. * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
  460. * in the right encoding for the type of authentication the user is setup for. For Base
  461. * sugar validation, password is the MD5 sum of the plain text password.
  462. * @param String $application -- The name of the application you are logging in from. (Currently unused).
  463. * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
  464. * @return Array - id - String id is the session_id of the session that was created.
  465. * - module_name - String - module name of user
  466. * - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name
  467. * @exception 'SoapFault' -- The SOAP error, if any
  468. */
  469. public function login($user_auth, $application, $name_value_list){
  470. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
  471. global $sugar_config, $system_config;
  472. $error = new SoapError();
  473. $user = new User();
  474. $success = false;
  475. if(!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN'){
  476. $user_auth['password'] = md5($user_auth['password']);
  477. }
  478. //rrs
  479. $system_config = new Administration();
  480. $system_config->retrieveSettings('system');
  481. $authController = new AuthenticationController((!empty($sugar_config['authenticationClass'])? $sugar_config['authenticationClass'] : 'SugarAuthenticate'));
  482. //rrs
  483. $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
  484. $usr_id=$user->retrieve_user_id($user_auth['user_name']);
  485. if($usr_id) {
  486. $user->retrieve($usr_id);
  487. }
  488. if ($isLoginSuccess) {
  489. if ($_SESSION['hasExpiredPassword'] =='1') {
  490. $error->set_error('password_expired');
  491. $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
  492. LogicHook::initialize();
  493. $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
  494. self::$helperObject->setFaultObject($error);
  495. return;
  496. } // if
  497. if(!empty($user) && !empty($user->id) && !$user->is_group) {
  498. $success = true;
  499. global $current_user;
  500. $current_user = $user;
  501. } // if
  502. } else if($usr_id && isset($user->user_name) && ($user->getPreference('lockout') == '1')) {
  503. $error->set_error('lockout_reached');
  504. $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
  505. LogicHook::initialize();
  506. $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
  507. self::$helperObject->setFaultObject($error);
  508. return;
  509. } else if(function_exists('mcrypt_cbc')){
  510. $password = self::$helperObject->decrypt_string($user_auth['password']);
  511. if($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])){
  512. $success = true;
  513. } // if
  514. } // else if
  515. if($success){
  516. session_start();
  517. global $current_user;
  518. //$current_user = $user;
  519. self::$helperObject->login_success($name_value_list);
  520. $current_user->loadPreferences();
  521. $_SESSION['is_valid_session']= true;
  522. $_SESSION['ip_address'] = query_client_ip();
  523. $_SESSION['user_id'] = $current_user->id;
  524. $_SESSION['type'] = 'user';
  525. $_SESSION['avail_modules']= self::$helperObject->get_user_module_list($current_user);
  526. $_SESSION['authenticated_user_id'] = $current_user->id;
  527. $_SESSION['unique_key'] = $sugar_config['unique_key'];
  528. $current_user->call_custom_logic('after_login');
  529. $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
  530. $nameValueArray = array();
  531. global $current_language;
  532. $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
  533. $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
  534. $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
  535. $cur_id = $current_user->getPreference('currency');
  536. $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
  537. $currencyObject = new Currency();
  538. $currencyObject->retrieve($cur_id);
  539. $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
  540. $_SESSION['user_language'] = $current_language;
  541. return array('id'=>session_id(), 'module_name'=>'Users', 'name_value_list'=>$nameValueArray);
  542. } // if
  543. LogicHook::initialize();
  544. $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
  545. $error->set_error('invalid_login');
  546. self::$helperObject->setFaultObject($error);
  547. $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
  548. }
  549. /**
  550. * Log out of the session. This will destroy the session and prevent other's from using it.
  551. *
  552. * @param String $session -- Session ID returned by a previous call to login.
  553. * @return Empty
  554. * @exception 'SoapFault' -- The SOAP error, if any
  555. */
  556. function logout($session){
  557. global $current_user;
  558. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->logout');
  559. $error = new SoapError();
  560. LogicHook::initialize();
  561. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  562. $GLOBALS['logic_hook']->call_custom_logic('Users', 'after_logout');
  563. $GLOBALS['log']->info('End: SugarWebServiceImpl->logout');
  564. return;
  565. } // if
  566. $current_user->call_custom_logic('before_logout');
  567. session_destroy();
  568. $GLOBALS['logic_hook']->call_custom_logic('Users', 'after_logout');
  569. $GLOBALS['log']->info('End: SugarWebServiceImpl->logout');
  570. } // fn
  571. /**
  572. * Gets server info. This will return information like version, flavor and gmt_time.
  573. * @return Array - flavor - String - Retrieve the specific flavor of sugar.
  574. * - version - String - Retrieve the version number of Sugar that the server is running.
  575. * - gmt_time - String - Return the current time on the server in the format 'Y-m-d H:i:s'. This time is in GMT.
  576. * @exception 'SoapFault' -- The SOAP error, if any
  577. */
  578. function get_server_info(){
  579. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_server_info');
  580. global $sugar_flavor;
  581. require_once('sugar_version.php');
  582. require_once('modules/Administration/Administration.php');
  583. $admin = new Administration();
  584. $admin->retrieveSettings('info');
  585. $sugar_version = '';
  586. if(isset($admin->settings['info_sugar_version'])){
  587. $sugar_version = $admin->settings['info_sugar_version'];
  588. }else{
  589. $sugar_version = '1.0';
  590. }
  591. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_server_info');
  592. return array('flavor' => $sugar_flavor, 'version' => $sugar_version, 'gmt_time' => TimeDate::getInstance()->nowDb());
  593. } // fn
  594. /**
  595. * Return the user_id of the user that is logged into the current session.
  596. *
  597. * @param String $session -- Session ID returned by a previous call to login.
  598. * @return String -- the User ID of the current session
  599. * @exception 'SoapFault' -- The SOAP error, if any
  600. */
  601. function get_user_id($session){
  602. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_user_id');
  603. $error = new SoapError();
  604. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  605. return;
  606. } // if
  607. global $current_user;
  608. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_user_id');
  609. return $current_user->id;
  610. } // fn
  611. /**
  612. * Retrieve vardef information on the fields of the specified bean.
  613. *
  614. * @param String $session -- Session ID returned by a previous call to login.
  615. * @param String $module_name -- The name of the module to return records from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
  616. * @param Array $fields -- Optional, if passed then retrieve vardef information on these fields only.
  617. * @return Array 'module_fields' -- Array - The vardef information on the selected fields.
  618. * 'link_fields' -- Array - The vardef information on the link fields
  619. * @exception 'SoapFault' -- The SOAP error, if any
  620. */
  621. function get_module_fields($session, $module_name, $fields = array()){
  622. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_fields for ' . $module_name);
  623. global $beanList, $beanFiles;
  624. $error = new SoapError();
  625. $module_fields = array();
  626. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
  627. $GLOBALS['log']->error('End: SugarWebServiceImpl->get_module_fields FAILED on checkSessionAndModuleAccess for ' . $module_name);
  628. return;
  629. } // if
  630. $class_name = $beanList[$module_name];
  631. require_once($beanFiles[$class_name]);
  632. $seed = new $class_name();
  633. if($seed->ACLAccess('ListView', true) || $seed->ACLAccess('DetailView', true) || $seed->ACLAccess('EditView', true) ) {
  634. $return = self::$helperObject->get_return_module_fields($seed, $module_name, $fields);
  635. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_fields SUCCESS for ' . $module_name);
  636. return $return;
  637. }
  638. $error->set_error('no_access');
  639. self::$helperObject->setFaultObject($error);
  640. $GLOBALS['log']->error('End: SugarWebServiceImpl->get_module_fields FAILED NO ACCESS to ListView, DetailView or EditView for ' . $module_name);
  641. }
  642. /**
  643. * Perform a seamless login. This is used internally during the sync process.
  644. *
  645. * @param String $session -- Session ID returned by a previous call to login.
  646. * @return 1 -- integer - if the session was authenticated
  647. * @return 0 -- integer - if the session could not be authenticated
  648. */
  649. function seamless_login($session){
  650. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->seamless_login');
  651. if(!self::$helperObject->validate_authenticated($session)){
  652. return 0;
  653. }
  654. $_SESSION['seamless_login'] = true;
  655. $GLOBALS['log']->info('End: SugarWebServiceImpl->seamless_login');
  656. return 1;
  657. }
  658. /**
  659. * Add or replace the attachment on a Note.
  660. * Optionally you can set the relationship of this note to Accounts/Contacts and so on by setting related_module_id, related_module_name
  661. *
  662. * @param String $session -- Session ID returned by a previous call to login.
  663. * @param Array 'note' -- Array String 'id' -- The ID of the Note containing the attachment
  664. * String 'filename' -- The file name of the attachment
  665. * Binary 'file' -- The binary contents of the file.
  666. * String 'related_module_id' -- module id to which this note to related to
  667. * String 'related_module_name' - module name to which this note to related to
  668. *
  669. * @return Array 'id' -- String - The ID of the Note
  670. * @exception 'SoapFault' -- The SOAP error, if any
  671. */
  672. function set_note_attachment($session, $note) {
  673. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_note_attachment');
  674. $error = new SoapError();
  675. $module_name = '';
  676. $module_access = '';
  677. $module_id = '';
  678. if (!empty($note['related_module_id']) && !empty($note['related_module_name'])) {
  679. $module_name = $note['related_module_name'];
  680. $module_id = $note['related_module_id'];
  681. $module_access = 'read';
  682. }
  683. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, $module_access, 'no_access', $error)) {
  684. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_note_attachment');
  685. return;
  686. } // if
  687. require_once('modules/Notes/NoteSoap.php');
  688. $ns = new NoteSoap();
  689. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_note_attachment');
  690. return array('id'=>$ns->newSaveFile($note));
  691. } // fn
  692. /**
  693. * Retrieve an attachment from a note
  694. * @param String $session -- Session ID returned by a previous call to login.
  695. * @param String $id -- The ID of the appropriate Note.
  696. * @return Array 'note_attachment' -- Array String 'id' -- The ID of the Note containing the attachment
  697. * String 'filename' -- The file name of the attachment
  698. * Binary 'file' -- The binary contents of the file.
  699. * String 'related_module_id' -- module id to which this note is related
  700. * String 'related_module_name' - module name to which this note is related
  701. * @exception 'SoapFault' -- The SOAP error, if any
  702. */
  703. function get_note_attachment($session,$id) {
  704. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_note_attachment');
  705. $error = new SoapError();
  706. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  707. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_note_attachment');
  708. return;
  709. } // if
  710. require_once('modules/Notes/Note.php');
  711. $note = new Note();
  712. $note->retrieve($id);
  713. if (!self::$helperObject->checkACLAccess($note, 'DetailView', $error, 'no_access')) {
  714. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_note_attachment');
  715. return;
  716. } // if
  717. require_once('modules/Notes/NoteSoap.php');
  718. $ns = new NoteSoap();
  719. if(!isset($note->filename)){
  720. $note->filename = '';
  721. }
  722. $file= $ns->retrieveFile($id,$note->filename);
  723. if($file == -1){
  724. $file = '';
  725. }
  726. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_note_attachment');
  727. return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file, 'related_module_id' => $note->parent_id, 'related_module_name' => $note->parent_type));
  728. } // fn
  729. /**
  730. * sets a new revision for this document
  731. *
  732. * @param String $session -- Session ID returned by a previous call to login.
  733. * @param Array $document_revision -- Array String 'id' -- The ID of the document object
  734. * String 'document_name' - The name of the document
  735. * String 'revision' - The revision value for this revision
  736. * String 'filename' -- The file name of the attachment
  737. * String 'file' -- The binary contents of the file.
  738. * @return Array - 'id' - String - document revision id
  739. * @exception 'SoapFault' -- The SOAP error, if any
  740. */
  741. function set_document_revision($session, $document_revision) {
  742. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_document_revision');
  743. $error = new SoapError();
  744. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  745. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_document_revision');
  746. return;
  747. } // if
  748. require_once('modules/Documents/DocumentSoap.php');
  749. $dr = new DocumentSoap();
  750. $GLOBALS['log']->info('End: SugarWebServiceImpl->set_document_revision');
  751. return array('id'=>$dr->saveFile($document_revision));
  752. }
  753. /**
  754. * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a
  755. * properly authenticated user to download a document that they have proper rights to download.
  756. *
  757. * @param String $session -- Session ID returned by a previous call to login.
  758. * @param String $id -- ID of the document revision to obtain
  759. * @return new_return_document_revision - Array String 'id' -- The ID of the document revision containing the attachment
  760. * String document_name - The name of the document
  761. * String revision - The revision value for this revision
  762. * String 'filename' -- The file name of the attachment
  763. * Binary 'file' -- The binary contents of the file.
  764. * @exception 'SoapFault' -- The SOAP error, if any
  765. */
  766. function get_document_revision($session, $id) {
  767. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_document_revision');
  768. global $sugar_config;
  769. $error = new SoapError();
  770. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  771. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
  772. return;
  773. } // if
  774. require_once('modules/DocumentRevisions/DocumentRevision.php');
  775. $dr = new DocumentRevision();
  776. $dr->retrieve($id);
  777. if(!empty($dr->filename)){
  778. $filename = "upload://{$dr->id}";
  779. if (filesize($filename) > 0) {
  780. $contents = sugar_file_get_contents($filename);
  781. } else {
  782. $contents = '';
  783. }
  784. $contents = base64_encode($contents);
  785. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
  786. return array('document_revision'=>array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents));
  787. }else{
  788. $error->set_error('no_records');
  789. self::$helperObject->setFaultObject($error);
  790. $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
  791. }
  792. }
  793. /**
  794. * Given a list of modules to search and a search string, return the id, module_name, along with the fields
  795. * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
  796. *
  797. * @param string $session - Session ID returned by a previous call to login.
  798. * @param string $search_string - string to search
  799. * @param string[] $modules - array of modules to query
  800. * @param int $offset - a specified offset in the query
  801. * @param int $max_results - max number of records to return
  802. * @return Array 'entry_list' -- Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
  803. * @exception 'SoapFault' -- The SOAP error, if any
  804. */
  805. function search_by_module($session, $search_string, $modules, $offset, $max_results){
  806. $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
  807. global $beanList, $beanFiles;
  808. global $sugar_config,$current_language;
  809. $error = new SoapError();
  810. $output_list = array();
  811. if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
  812. $error->set_error('invalid_login');
  813. $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
  814. return;
  815. }
  816. global $current_user;
  817. if($max_results > 0){
  818. $sugar_config['list_max_entries_per_page'] = $max_results;
  819. }
  820. require_once('modules/Home/UnifiedSearchAdvanced.php');
  821. require_once 'include/utils.php';
  822. $usa = new UnifiedSearchAdvanced();
  823. if(!file_exists($cachedfile = sugar_cached('modules/unified_search_modules.php'))) {
  824. $usa->buildCache();
  825. }
  826. include($cachedfile);
  827. $modules_to_search = array();
  828. $unified_search_modules['Users'] = array('fields' => array());
  829. $unified_search_modules['ProjectTask'] = array('fields' => array());
  830. foreach($unified_search_modules as $module=>$data) {
  831. if (in_array($module, $modules)) {
  832. $modules_to_search[$module] = $beanList[$module];
  833. } // if
  834. } // foreach
  835. $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
  836. if(!empty($search_string) && isset($search_string)) {
  837. $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
  838. foreach($modules_to_search as $name => $beanName) {
  839. $where_clauses_array = array();
  840. $unifiedSearchFields = array () ;
  841. foreach ($unified_search_modules[$name]['fields'] as $field=>$def ) {
  842. $unifiedSearchFields[$name] [ $field ] = $def ;
  843. $unifiedSearchFields[$name] [ $field ]['value'] = $search_string;
  844. }
  845. require_once $beanFiles[$beanName] ;
  846. $seed = new $beanName();
  847. require_once 'include/SearchForm/SearchForm2.php' ;
  848. if ($beanName == "User"
  849. || $beanName == "ProjectTask"
  850. ) {
  851. if(!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')){
  852. continue;
  853. } // if
  854. if(!$seed->ACLAccess('ListView')) {
  855. continue;
  856. } // if
  857. }
  858. if ($beanName != "User"
  859. && $beanName != "ProjectTask"
  860. ) {
  861. $searchForm = new SearchForm ($seed, $name ) ;
  862. $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
  863. $where_clauses = $searchForm->generateSearchWhere() ;
  864. require_once 'include/SearchForm/SearchForm2.php' ;
  865. $searchForm = new SearchForm ($seed, $name ) ;
  866. $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
  867. $where_clauses = $searchForm->generateSearchWhere() ;
  868. $emailQuery = false;
  869. $where = '';
  870. if (count($where_clauses) > 0 ) {
  871. $where = '('. implode(' ) OR ( ', $where_clauses) . ')';
  872. }
  873. $mod_strings = return_module_language($current_language, $seed->module_dir);
  874. if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php')){
  875. require_once('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
  876. }else{
  877. require_once('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
  878. }
  879. $filterFields = array();
  880. foreach($listViewDefs[$seed->module_dir] as $colName => $param) {
  881. if(!empty($param['default']) && $param['default'] == true) {
  882. $filterFields[] = strtolower($colName);
  883. } // if
  884. } // foreach
  885. if (!in_array('id', $filterFields)) {
  886. $filterFields[] = 'id';
  887. } // if
  888. $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true);
  889. if(empty($params) or !is_array($params)) $params = array();
  890. if(!isset($params['custom_select'])) $params['custom_select'] = '';
  891. if(!isset($params['custom_from'])) $params['custom_from'] = '';
  892. if(!isset($params['custom_where'])) $params['custom_where'] = '';
  893. if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';

Large files files are truncated, but you can click here to view the full file