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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
40 * This class is an implemenatation class for all the web services
42 require_once('service/core/SoapHelperWebService.php');
43 SugarWebServiceImpl::$helperObject = new SoapHelperWebServices();
45 class SugarWebServiceImpl{
47 public static $helperObject = null;
50 * Retrieve a single SugarBean based on ID.
52 * @param String $session -- Session ID returned by a previous call to login.
53 * @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)..
54 * @param String $id -- The SugarBean's ID value.
55 * @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.
56 * @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')))
58 * 'entry_list' -- Array - The records name value pair for the simple data types excluding link field data.
59 * '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 ) ) ) ) )
60 * @exception 'SoapFault' -- The SOAP error, if any
62 function get_entry($session, $module_name, $id,$select_fields, $link_name_to_fields_array){
63 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entry');
64 return self::get_entries($session, $module_name, array($id), $select_fields, $link_name_to_fields_array);
65 $GLOBALS['log']->info('end: SugarWebServiceImpl->get_entry');
69 * Retrieve a list of SugarBean's based on provided IDs. This API will not wotk with report module
71 * @param String $session -- Session ID returned by a previous call to login.
72 * @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)..
73 * @param Array $ids -- An array of SugarBean IDs.
74 * @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.
75 * @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')))
77 * 'entry_list' -- Array - The records name value pair for the simple data types excluding link field data.
78 * '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 ) ) ) ) )
79 * @exception 'SoapFault' -- The SOAP error, if any
81 function get_entries($session, $module_name, $ids, $select_fields, $link_name_to_fields_array){
82 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entries');
83 global $beanList, $beanFiles;
84 $error = new SoapError();
86 $linkoutput_list = array();
87 $output_list = array();
89 if($module_name == 'CampaignProspects'){
90 $module_name = 'Prospects';
93 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
94 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries');
98 if($module_name == 'Reports'){
99 $error->set_error('invalid_call_error');
100 self::$helperObject->setFaultObject($error);
101 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries');
105 $class_name = $beanList[$module_name];
106 require_once($beanFiles[$class_name]);
108 $temp = new $class_name();
109 foreach($ids as $id) {
110 $seed = @clone($temp);
112 $seed = $seed->retrieveTarget($id);
114 if ($seed->retrieve($id) == null)
118 if ($seed->deleted == 1) {
120 $list[] = array('name'=>'warning', 'value'=>'Access to this object is denied since it has been deleted or does not exist');
121 $list[] = array('name'=>'deleted', 'value'=>'1');
122 $output_list[] = Array('id'=>$id,
123 'module_name'=> $module_name,
124 'name_value_list'=>$list,
128 if (!self::$helperObject->checkACLAccess($seed, 'DetailView', $error, 'no_access')) {
131 $output_list[] = self::$helperObject->get_return_value_for_fields($seed, $module_name, $select_fields);
132 if (!empty($link_name_to_fields_array)) {
133 $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($seed, $module_name, $link_name_to_fields_array);
136 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries');
137 return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
142 * Retrieve a list of beans. This is the primary method for getting list of SugarBeans from Sugar using the SOAP API.
144 * @param String $session -- Session ID returned by a previous call to login.
145 * @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)..
146 * @param String $query -- SQL where clause without the word 'where'
147 * @param String $order_by -- SQL order by clause without the phrase 'order by'
148 * @param integer $offset -- The record offset to start from.
149 * @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.
150 * @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')))
151 * @param integer $max_results -- The maximum number of records to return. The default is the sugar configuration value for 'list_max_entries_per_page'
152 * @param integer $deleted -- false if deleted records should not be include, true if deleted records should be included.
153 * @return Array 'result_count' -- integer - The number of records returned
154 * '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.
155 * 'entry_list' -- Array - The records that were retrieved
156 * '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 ) ) ) ) )
157 * @exception 'SoapFault' -- The SOAP error, if any
159 function get_entry_list($session, $module_name, $query, $order_by,$offset, $select_fields, $link_name_to_fields_array, $max_results, $deleted ){
160 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entry_list');
161 global $beanList, $beanFiles;
162 $error = new SoapError();
164 if($module_name == 'CampaignProspects'){
165 $module_name = 'Prospects';
168 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
169 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
173 // If the maximum number of entries per page was specified, override the configuration value.
174 if($max_results > 0){
175 global $sugar_config;
176 $sugar_config['list_max_entries_per_page'] = $max_results;
179 $class_name = $beanList[$module_name];
180 require_once($beanFiles[$class_name]);
181 $seed = new $class_name();
183 if (!self::$helperObject->checkQuery($error, $query, $order_by)) {
184 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
188 if (!self::$helperObject->checkACLAccess($seed, 'Export', $error, 'no_access')) {
189 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
193 if (!self::$helperObject->checkACLAccess($seed, 'list', $error, 'no_access')) {
194 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
201 if($offset == '' || $offset == -1){
205 $response = $seed->retrieveTargetList($query, $select_fields, $offset,-1,-1,$deleted);
207 /* @var $seed SugarBean */
208 $response = $seed->get_list($order_by, $query, $offset,-1,-1,$deleted, false, $select_fields);
210 $list = $response['list'];
212 $output_list = array();
213 $linkoutput_list = array();
215 foreach($list as $value) {
216 if(isset($value->emailAddress)){
217 $value->emailAddress->handleLegacyRetrieve($value);
219 $value->fill_in_additional_detail_fields();
221 $output_list[] = self::$helperObject->get_return_value_for_fields($value, $module_name, $select_fields);
222 if(!empty($link_name_to_fields_array)){
223 $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($value, $module_name, $link_name_to_fields_array);
227 // Calculate the offset for the start of the next page
228 $next_offset = $offset + sizeof($output_list);
230 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entry_list');
231 return array('result_count'=>sizeof($output_list), 'next_offset'=>$next_offset, 'entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
236 * Set a single relationship between two beans. The items are related by module name and id.
238 * @param String $session -- Session ID returned by a previous call to login.
239 * @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)..
240 * @param String $module_id - The ID of the bean in the specified module_name
241 * @param String link_field_name -- name of the link field which relates to the other module for which the relationship needs to be generated.
242 * @param array related_ids -- array of related record ids for which relationships needs to be generated
243 * @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.
244 * @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
245 * @return Array - created - integer - How many relationships has been created
246 * - failed - integer - How many relationsip creation failed
247 * - deleted - integer - How many relationships were deleted
248 * @exception 'SoapFault' -- The SOAP error, if any
250 function set_relationship($session, $module_name, $module_id, $link_field_name, $related_ids, $name_value_list, $delete){
251 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_relationship');
252 $error = new SoapError();
253 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
254 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationship');
262 $name_value_array = array();
263 if (is_array($name_value_list)) {
264 $name_value_array = $name_value_list;
267 if (isset($delete)) {
270 if (self::$helperObject->new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids,$name_value_array, $deleted)) {
279 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationship');
280 return array('created'=>$count , 'failed'=>$failed, 'deleted' => $deletedCount);
284 * Set a single relationship between two beans. The items are related by module name and id.
286 * @param String $session -- Session ID returned by a previous call to login.
287 * @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)..
288 * @param array $module_ids - The array of ID of the bean in the specified module_name
289 * @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.
290 * @param array $related_ids -- array of an array of related record ids for which relationships needs to be generated
291 * @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.
292 * @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
293 * @return Array - created - integer - How many relationships has been created
294 * - failed - integer - How many relationsip creation failed
295 * - deleted - integer - How many relationships were deleted
297 * @exception 'SoapFault' -- The SOAP error, if any
299 function set_relationships($session, $module_names, $module_ids, $link_field_names, $related_ids, $name_value_lists, $delete_array) {
300 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_relationships');
301 $error = new SoapError();
302 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
303 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationships');
307 if ((empty($module_names) || empty($module_ids) || empty($link_field_names) || empty($related_ids)) ||
308 (sizeof($module_names) != (sizeof($module_ids) || sizeof($link_field_names) || sizeof($related_ids)))) {
309 $error->set_error('invalid_data_format');
310 self::$helperObject->setFaultObject($error);
311 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationships');
320 foreach($module_names as $module_name) {
321 $name_value_list = array();
322 if (is_array($name_value_lists) && isset($name_value_lists[$counter])) {
323 $name_value_list = $name_value_lists[$counter];
325 if (is_array($delete_array) && isset($delete_array[$counter])) {
326 $deleted = $delete_array[$counter];
328 if (self::$helperObject->new_handle_set_relationship($module_name, $module_ids[$counter], $link_field_names[$counter], $related_ids[$counter], $name_value_list, $deleted)) {
339 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_relationships');
340 return array('created'=>$count , 'failed'=>$failed, 'deleted' => $deletedCount);
344 * Retrieve a collection of beans that are related to the specified bean and optionally return relationship data for those related beans.
345 * 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.
347 * @param String $session -- Session ID returned by a previous call to login.
348 * @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)..
349 * @param String $module_id -- The ID of the bean in the specified module
350 * @param String $link_field_name -- The name of the lnk field to return records from. This name should be the name the relationship.
351 * @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)
352 * @param Array $related_fields - Array of related bean fields to be returned.
353 * @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'))).
354 * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
355 * @return Array 'entry_list' -- Array - The records that were retrieved
356 * '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 ) ) ) ) )
357 * @exception 'SoapFault' -- The SOAP error, if any
359 function get_relationships($session, $module_name, $module_id, $link_field_name, $related_module_query, $related_fields, $related_module_link_name_to_fields_array, $deleted){
361 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_relationships');
362 global $beanList, $beanFiles;
363 $error = new SoapError();
364 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
365 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
369 $class_name = $beanList[$module_name];
370 require_once($beanFiles[$class_name]);
371 $mod = new $class_name();
372 $mod->retrieve($module_id);
374 if (!self::$helperObject->checkQuery($error, $related_module_query)) {
375 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
379 if (!self::$helperObject->checkACLAccess($mod, 'DetailView', $error, 'no_access')) {
380 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
384 $output_list = array();
385 $linkoutput_list = array();
387 // get all the related mmodules data.
388 $result = self::$helperObject->getRelationshipResults($mod, $link_field_name, $related_fields, $related_module_query);
389 if (self::$helperObject->isLogLevelDebug()) {
390 $GLOBALS['log']->debug('SoapHelperWebServices->get_relationships - return data for getRelationshipResults is ' . var_export($result, true));
393 $list = $result['rows'];
394 $filterFields = $result['fields_set_on_rows'];
396 if (sizeof($list) > 0) {
397 // get the related module name and instantiate a bean for that.
398 $submodulename = $mod->$link_field_name->getRelatedModuleName();
399 $submoduleclass = $beanList[$submodulename];
400 require_once($beanFiles[$submoduleclass]);
402 $submoduletemp = new $submoduleclass();
403 foreach($list as $row) {
404 $submoduleobject = @clone($submoduletemp);
405 // set all the database data to this object
406 foreach ($filterFields as $field) {
407 $submoduleobject->$field = $row[$field];
409 if (isset($row['id'])) {
410 $submoduleobject->id = $row['id'];
412 $output_list[] = self::$helperObject->get_return_value_for_fields($submoduleobject, $submodulename, $filterFields);
413 if (!empty($related_module_link_name_to_fields_array)) {
414 $linkoutput_list[] = self::$helperObject->get_return_value_for_link_fields($submoduleobject, $submodulename, $related_module_link_name_to_fields_array);
422 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_relationships');
423 return array('entry_list'=>$output_list, 'relationship_list' => $linkoutput_list);
428 * Update or create a single SugarBean.
430 * @param String $session -- Session ID returned by a previous call to login.
431 * @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)..
432 * @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.
433 * @return Array 'id' -- the ID of the bean that was written to (-1 on error)
434 * @exception 'SoapFault' -- The SOAP error, if any
436 function set_entry($session,$module_name, $name_value_list){
437 global $beanList, $beanFiles, $current_user;
439 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_entry');
440 if (self::$helperObject->isLogLevelDebug()) {
441 $GLOBALS['log']->debug('SoapHelperWebServices->set_entry - input data is ' . var_export($name_value_list, true));
443 $error = new SoapError();
444 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'write', 'no_access', $error)) {
445 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entry');
448 $class_name = $beanList[$module_name];
449 require_once($beanFiles[$class_name]);
450 $seed = new $class_name();
451 foreach($name_value_list as $name=>$value){
452 if(is_array($value) && $value['name'] == 'id'){
453 $seed->retrieve($value['value']);
455 }else if($name === 'id' ){
457 $seed->retrieve($value);
461 foreach($name_value_list as $name=>$value){
462 if($module_name == 'Users' && !empty($seed->id) && ($seed->id != $current_user->id) && $name == 'user_hash'){
465 if(!empty($seed->field_name_map[$name]['sensitive'])) {
468 if(!is_array($value)){
469 $seed->$name = $value;
471 $seed->$value['name'] = $value['value'];
474 if (!self::$helperObject->checkACLAccess($seed, 'Save', $error, 'no_access') || ($seed->deleted == 1 && !self::$helperObject->checkACLAccess($seed, 'Delete', $error, 'no_access'))) {
475 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entry');
479 $seed->save(self::$helperObject->checkSaveOnNotify());
480 if($seed->deleted == 1){
481 $seed->mark_deleted($seed->id);
483 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entry');
484 return array('id'=>$seed->id);
488 * Update or create a list of SugarBeans
490 * @param String $session -- Session ID returned by a previous call to login.
491 * @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)..
492 * @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.
493 * @return Array 'ids' -- Array of the IDs of the beans that was written to (-1 on error)
494 * @exception 'SoapFault' -- The SOAP error, if any
496 function set_entries($session,$module_name, $name_value_lists){
497 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_entries');
498 if (self::$helperObject->isLogLevelDebug()) {
499 $GLOBALS['log']->debug('SoapHelperWebServices->set_entries - input data is ' . var_export($name_value_lists, true));
501 $error = new SoapError();
502 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'write', 'no_access', $error)) {
503 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entries');
507 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_entries');
508 return self::$helperObject->new_handle_set_entries($module_name, $name_value_lists, FALSE);
512 * Log the user into the application
514 * @param UserAuth array $user_auth -- Set user_name and password (password needs to be
515 * in the right encoding for the type of authentication the user is setup for. For Base
516 * sugar validation, password is the MD5 sum of the plain text password.
517 * @param String $application -- The name of the application you are logging in from. (Currently unused).
518 * @param array $name_value_list -- Array of name value pair of extra parameters. As of today only 'language' and 'notifyonsave' is supported
519 * @return Array - id - String id is the session_id of the session that was created.
520 * - module_name - String - module name of user
521 * - name_value_list - Array - The name value pair of user_id, user_name, user_language, user_currency_id, user_currency_name
522 * @exception 'SoapFault' -- The SOAP error, if any
524 public function login($user_auth, $application, $name_value_list){
525 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->login');
526 global $sugar_config, $system_config;
527 $error = new SoapError();
530 if(!empty($user_auth['encryption']) && $user_auth['encryption'] === 'PLAIN'){
531 $user_auth['password'] = md5($user_auth['password']);
534 $system_config = new Administration();
535 $system_config->retrieveSettings('system');
536 $authController = new AuthenticationController();
538 $isLoginSuccess = $authController->login($user_auth['user_name'], $user_auth['password'], array('passwordEncrypted' => true));
539 $usr_id=$user->retrieve_user_id($user_auth['user_name']);
541 $user->retrieve($usr_id);
543 if ($isLoginSuccess) {
544 if ($_SESSION['hasExpiredPassword'] =='1') {
545 $error->set_error('password_expired');
546 $GLOBALS['log']->fatal('password expired for user ' . $user_auth['user_name']);
547 LogicHook::initialize();
548 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
549 self::$helperObject->setFaultObject($error);
552 if(!empty($user) && !empty($user->id) && !$user->is_group) {
554 global $current_user;
555 $current_user = $user;
557 } else if($usr_id && isset($user->user_name) && ($user->getPreference('lockout') == '1')) {
558 $error->set_error('lockout_reached');
559 $GLOBALS['log']->fatal('Lockout reached for user ' . $user_auth['user_name']);
560 LogicHook::initialize();
561 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
562 self::$helperObject->setFaultObject($error);
564 } else if(function_exists('mcrypt_cbc')){
565 $password = self::$helperObject->decrypt_string($user_auth['password']);
566 if($authController->login($user_auth['user_name'], $password) && isset($_SESSION['authenticated_user_id'])){
573 global $current_user;
574 //$current_user = $user;
575 self::$helperObject->login_success($name_value_list);
576 $current_user->loadPreferences();
577 $_SESSION['is_valid_session']= true;
578 $_SESSION['ip_address'] = query_client_ip();
579 $_SESSION['user_id'] = $current_user->id;
580 $_SESSION['type'] = 'user';
581 $_SESSION['avail_modules']= self::$helperObject->get_user_module_list($current_user);
582 $_SESSION['authenticated_user_id'] = $current_user->id;
583 $_SESSION['unique_key'] = $sugar_config['unique_key'];
584 $current_user->call_custom_logic('after_login');
585 $GLOBALS['log']->info('End: SugarWebServiceImpl->login - succesful login');
586 $nameValueArray = array();
587 global $current_language;
588 $nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
589 $nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
590 $nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
591 $cur_id = $current_user->getPreference('currency');
592 $nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
593 $currencyObject = new Currency();
594 $currencyObject->retrieve($cur_id);
595 $nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
596 $_SESSION['user_language'] = $current_language;
597 return array('id'=>session_id(), 'module_name'=>'Users', 'name_value_list'=>$nameValueArray);
599 LogicHook::initialize();
600 $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
601 $error->set_error('invalid_login');
602 self::$helperObject->setFaultObject($error);
603 $GLOBALS['log']->info('End: SugarWebServiceImpl->login - failed login');
607 * Log out of the session. This will destroy the session and prevent other's from using it.
609 * @param String $session -- Session ID returned by a previous call to login.
611 * @exception 'SoapFault' -- The SOAP error, if any
613 function logout($session){
614 global $current_user;
616 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->logout');
617 $error = new SoapError();
618 LogicHook::initialize();
619 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
620 $GLOBALS['logic_hook']->call_custom_logic('Users', 'after_logout');
621 $GLOBALS['log']->info('End: SugarWebServiceImpl->logout');
625 $current_user->call_custom_logic('before_logout');
627 $GLOBALS['logic_hook']->call_custom_logic('Users', 'after_logout');
628 $GLOBALS['log']->info('End: SugarWebServiceImpl->logout');
632 * Gets server info. This will return information like version, flavor and gmt_time.
633 * @return Array - flavor - String - Retrieve the specific flavor of sugar.
634 * - version - String - Retrieve the version number of Sugar that the server is running.
635 * - gmt_time - String - Return the current time on the server in the format 'Y-m-d H:i:s'. This time is in GMT.
636 * @exception 'SoapFault' -- The SOAP error, if any
638 function get_server_info(){
639 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_server_info');
640 global $sugar_flavor;
641 require_once('sugar_version.php');
642 require_once('modules/Administration/Administration.php');
644 $admin = new Administration();
645 $admin->retrieveSettings('info');
647 if(isset($admin->settings['info_sugar_version'])){
648 $sugar_version = $admin->settings['info_sugar_version'];
650 $sugar_version = '1.0';
653 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_server_info');
654 return array('flavor' => $sugar_flavor, 'version' => $sugar_version, 'gmt_time' => TimeDate::getInstance()->nowDb());
658 * Return the user_id of the user that is logged into the current session.
660 * @param String $session -- Session ID returned by a previous call to login.
661 * @return String -- the User ID of the current session
662 * @exception 'SoapFault' -- The SOAP error, if any
664 function get_user_id($session){
665 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_user_id');
666 $error = new SoapError();
667 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
670 global $current_user;
671 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_user_id');
672 return $current_user->id;
676 * Retrieve vardef information on the fields of the specified bean.
678 * @param String $session -- Session ID returned by a previous call to login.
679 * @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)..
680 * @param Array $fields -- Optional, if passed then retrieve vardef information on these fields only.
681 * @return Array 'module_fields' -- Array - The vardef information on the selected fields.
682 * 'link_fields' -- Array - The vardef information on the link fields
683 * @exception 'SoapFault' -- The SOAP error, if any
685 function get_module_fields($session, $module_name, $fields = array()){
686 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_module_fields for ' . $module_name);
687 global $beanList, $beanFiles;
688 $error = new SoapError();
689 $module_fields = array();
691 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
692 $GLOBALS['log']->error('End: SugarWebServiceImpl->get_module_fields FAILED on checkSessionAndModuleAccess for ' . $module_name);
696 $class_name = $beanList[$module_name];
697 require_once($beanFiles[$class_name]);
698 $seed = new $class_name();
699 if($seed->ACLAccess('ListView', true) || $seed->ACLAccess('DetailView', true) || $seed->ACLAccess('EditView', true) ) {
700 $return = self::$helperObject->get_return_module_fields($seed, $module_name, $fields);
701 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_module_fields SUCCESS for ' . $module_name);
704 $error->set_error('no_access');
705 self::$helperObject->setFaultObject($error);
706 $GLOBALS['log']->error('End: SugarWebServiceImpl->get_module_fields FAILED NO ACCESS to ListView, DetailView or EditView for ' . $module_name);
710 * Perform a seamless login. This is used internally during the sync process.
712 * @param String $session -- Session ID returned by a previous call to login.
713 * @return 1 -- integer - if the session was authenticated
714 * @return 0 -- integer - if the session could not be authenticated
716 function seamless_login($session){
717 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->seamless_login');
718 if(!self::$helperObject->validate_authenticated($session)){
722 $GLOBALS['log']->info('End: SugarWebServiceImpl->seamless_login');
727 * Add or replace the attachment on a Note.
728 * Optionally you can set the relationship of this note to Accounts/Contacts and so on by setting related_module_id, related_module_name
730 * @param String $session -- Session ID returned by a previous call to login.
731 * @param Array 'note' -- Array String 'id' -- The ID of the Note containing the attachment
732 * String 'filename' -- The file name of the attachment
733 * Binary 'file' -- The binary contents of the file.
734 * String 'related_module_id' -- module id to which this note to related to
735 * String 'related_module_name' - module name to which this note to related to
737 * @return Array 'id' -- String - The ID of the Note
738 * @exception 'SoapFault' -- The SOAP error, if any
740 function set_note_attachment($session, $note) {
741 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_note_attachment');
742 $error = new SoapError();
746 if (!empty($note['related_module_id']) && !empty($note['related_module_name'])) {
747 $module_name = $note['related_module_name'];
748 $module_id = $note['related_module_id'];
749 $module_access = 'read';
751 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, $module_access, 'no_access', $error)) {
752 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_note_attachment');
756 require_once('modules/Notes/NoteSoap.php');
757 $ns = new NoteSoap();
758 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_note_attachment');
759 return array('id'=>$ns->newSaveFile($note));
763 * Retrieve an attachment from a note
764 * @param String $session -- Session ID returned by a previous call to login.
765 * @param String $id -- The ID of the appropriate Note.
766 * @return Array 'note_attachment' -- Array String 'id' -- The ID of the Note containing the attachment
767 * String 'filename' -- The file name of the attachment
768 * Binary 'file' -- The binary contents of the file.
769 * String 'related_module_id' -- module id to which this note is related
770 * String 'related_module_name' - module name to which this note is related
771 * @exception 'SoapFault' -- The SOAP error, if any
773 function get_note_attachment($session,$id) {
774 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_note_attachment');
775 $error = new SoapError();
776 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
777 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_note_attachment');
780 require_once('modules/Notes/Note.php');
783 $note->retrieve($id);
784 if (!self::$helperObject->checkACLAccess($note, 'DetailView', $error, 'no_access')) {
785 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_note_attachment');
789 require_once('modules/Notes/NoteSoap.php');
790 $ns = new NoteSoap();
791 if(!isset($note->filename)){
792 $note->filename = '';
794 $file= $ns->retrieveFile($id,$note->filename);
799 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_note_attachment');
800 return array('note_attachment'=>array('id'=>$id, 'filename'=>$note->filename, 'file'=>$file, 'related_module_id' => $note->parent_id, 'related_module_name' => $note->parent_type));
805 * sets a new revision for this document
807 * @param String $session -- Session ID returned by a previous call to login.
808 * @param Array $document_revision -- Array String 'id' -- The ID of the document object
809 * String 'document_name' - The name of the document
810 * String 'revision' - The revision value for this revision
811 * String 'filename' -- The file name of the attachment
812 * String 'file' -- The binary contents of the file.
813 * @return Array - 'id' - String - document revision id
814 * @exception 'SoapFault' -- The SOAP error, if any
816 function set_document_revision($session, $document_revision) {
817 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_document_revision');
818 $error = new SoapError();
819 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
820 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_document_revision');
824 require_once('modules/Documents/DocumentSoap.php');
825 $dr = new DocumentSoap();
826 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_document_revision');
827 return array('id'=>$dr->saveFile($document_revision));
831 * This method is used as a result of the .htaccess lock down on the cache directory. It will allow a
832 * properly authenticated user to download a document that they have proper rights to download.
834 * @param String $session -- Session ID returned by a previous call to login.
835 * @param String $id -- ID of the document revision to obtain
836 * @return new_return_document_revision - Array String 'id' -- The ID of the document revision containing the attachment
837 * String document_name - The name of the document
838 * String revision - The revision value for this revision
839 * String 'filename' -- The file name of the attachment
840 * Binary 'file' -- The binary contents of the file.
841 * @exception 'SoapFault' -- The SOAP error, if any
843 function get_document_revision($session, $id) {
844 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_document_revision');
845 global $sugar_config;
847 $error = new SoapError();
848 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
849 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
853 require_once('modules/DocumentRevisions/DocumentRevision.php');
854 $dr = new DocumentRevision();
856 if(!empty($dr->filename)){
857 $filename = "upload://{$dr->id}";
858 if (filesize($filename) > 0) {
859 $contents = sugar_file_get_contents($filename);
863 $contents = base64_encode($contents);
864 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
865 return array('document_revision'=>array('id' => $dr->id, 'document_name' => $dr->document_name, 'revision' => $dr->revision, 'filename' => $dr->filename, 'file' => $contents));
867 $error->set_error('no_records');
868 self::$helperObject->setFaultObject($error);
869 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_document_revision');
875 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
876 * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
878 * @param string $session - Session ID returned by a previous call to login.
879 * @param string $search_string - string to search
880 * @param string[] $modules - array of modules to query
881 * @param int $offset - a specified offset in the query
882 * @param int $max_results - max number of records to return
883 * @return Array 'entry_list' -- Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
884 * @exception 'SoapFault' -- The SOAP error, if any
886 function search_by_module($session, $search_string, $modules, $offset, $max_results){
887 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
888 global $beanList, $beanFiles;
889 global $sugar_config,$current_language;
891 $error = new SoapError();
892 $output_list = array();
893 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
894 $error->set_error('invalid_login');
895 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
898 global $current_user;
899 if($max_results > 0){
900 $sugar_config['list_max_entries_per_page'] = $max_results;
903 require_once('modules/Home/UnifiedSearchAdvanced.php');
904 require_once 'include/utils.php';
905 $usa = new UnifiedSearchAdvanced();
906 if(!file_exists($cachedfile = sugar_cached('modules/unified_search_modules.php'))) {
910 include($cachedfile);
911 $modules_to_search = array();
912 $unified_search_modules['Users'] = array('fields' => array());
914 $unified_search_modules['ProjectTask'] = array('fields' => array());
916 foreach($unified_search_modules as $module=>$data) {
917 if (in_array($module, $modules)) {
918 $modules_to_search[$module] = $beanList[$module];
922 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
924 if(!empty($search_string) && isset($search_string)) {
925 $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
926 foreach($modules_to_search as $name => $beanName) {
927 $where_clauses_array = array();
928 $unifiedSearchFields = array () ;
929 foreach ($unified_search_modules[$name]['fields'] as $field=>$def ) {
930 $unifiedSearchFields[$name] [ $field ] = $def ;
931 $unifiedSearchFields[$name] [ $field ]['value'] = $search_string;
934 require_once $beanFiles[$beanName] ;
935 $seed = new $beanName();
936 require_once 'include/SearchForm/SearchForm2.php' ;
937 if ($beanName == "User"
938 || $beanName == "ProjectTask"
940 if(!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')){
943 if(!$seed->ACLAccess('ListView')) {
948 if ($beanName != "User"
949 && $beanName != "ProjectTask"
951 $searchForm = new SearchForm ($seed, $name ) ;
953 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
954 $where_clauses = $searchForm->generateSearchWhere() ;
955 require_once 'include/SearchForm/SearchForm2.php' ;
956 $searchForm = new SearchForm ($seed, $name ) ;
958 $searchForm->setup(array ($name => array()) ,$unifiedSearchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
959 $where_clauses = $searchForm->generateSearchWhere() ;
963 if (count($where_clauses) > 0 ) {
964 $where = '('. implode(' ) OR ( ', $where_clauses) . ')';
967 $mod_strings = return_module_language($current_language, $seed->module_dir);
968 if(file_exists('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php')){
969 require_once('custom/modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
971 require_once('modules/'.$seed->module_dir.'/metadata/listviewdefs.php');
973 $filterFields = array();
974 foreach($listViewDefs[$seed->module_dir] as $colName => $param) {
975 if(!empty($param['default']) && $param['default'] == true) {
976 $filterFields[] = strtolower($colName);
980 if (!in_array('id', $filterFields)) {
981 $filterFields[] = 'id';
983 $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true);
984 if(empty($params) or !is_array($params)) $params = array();
985 if(!isset($params['custom_select'])) $params['custom_select'] = '';
986 if(!isset($params['custom_from'])) $params['custom_from'] = '';
987 if(!isset($params['custom_where'])) $params['custom_where'] = '';
988 if(!isset($params['custom_order_by'])) $params['custom_order_by'] = '';
989 $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
991 if ($beanName == "User") {
992 // $search_string gets cleaned above, so we can use it here
993 $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address');
994 $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users ";
995 $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'
996 LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
997 $main_query = $main_query . "where ((users.first_name like '{$search_string}') or (users.last_name like '{$search_string}') or (users.user_name like '{$search_string}') or (ea.email_address like '{$search_string}')) and users.deleted = 0 and users.is_group = 0 and users.employee_status = 'Active'";
999 if ($beanName == "ProjectTask") {
1000 // $search_string gets cleaned above, so we can use it here
1001 $filterFields = array('id', 'name', 'project_id', 'project_name');
1002 $main_query = "select {$seed->table_name}.project_task_id id,{$seed->table_name}.project_id, {$seed->table_name}.name, project.name project_name from {$seed->table_name} ";
1003 $seed->add_team_security_where_clause($main_query);
1004 $main_query .= "LEFT JOIN teams ON $seed->table_name.team_id=teams.id AND (teams.deleted=0) ";
1005 $main_query .= "LEFT JOIN project ON $seed->table_name.project_id = project.id ";
1006 $main_query .= "where {$seed->table_name}.name like '{$search_string}%'";
1010 $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
1011 if($max_results < -1) {
1012 $result = $seed->db->query($main_query);
1015 if($max_results == -1) {
1016 $limit = $sugar_config['list_max_entries_per_page'];
1018 $limit = $max_results;
1020 $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
1023 $rowArray = array();
1024 while($row = $seed->db->fetchByAssoc($result)) {
1025 $nameValueArray = array();
1026 foreach ($filterFields as $field) {
1027 $nameValue = array();
1028 if (isset($row[$field])) {
1029 $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
1032 $rowArray[] = $nameValueArray;
1034 $output_list[] = array('name' => $name, 'records' => $rowArray);
1037 $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
1038 return array('entry_list'=>$output_list);
1040 return array('entry_list'=>$output_list);
1045 * Retrieve the list of available modules on the system available to the currently logged in user.
1047 * @param String $session -- Session ID returned by a previous call to login.
1048 * @return Array 'modules' -- Array - An array of module names
1049 * @exception 'SoapFault' -- The SOAP error, if any
1051 function get_available_modules($session){
1052 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_available_modules');
1054 $error = new SoapError();
1055 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
1056 $error->set_error('invalid_login');
1057 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
1062 $modules = array_keys($_SESSION['avail_modules']);
1064 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_available_modules');
1065 return array('modules'=> $modules);
1070 * Once we have successfuly done a mail merge on a campaign, we need to notify Sugar of the targets
1071 * and the campaign_id for tracking purposes
1073 * @param String session -- Session ID returned by a previous call to login.
1074 * @param Array targets -- a string array of ids identifying the targets used in the merge
1075 * @param String campaign_id -- the campaign_id used for the merge
1076 * @return - No output
1078 * @exception 'SoapFault' -- The SOAP error, if any
1080 function set_campaign_merge($session,$targets, $campaign_id){
1081 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->set_campaign_merge');
1083 $error = new SoapError();
1084 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
1085 $error->set_error('invalid_login');
1086 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_campaign_merge');
1089 if (empty($campaign_id) or !is_array($targets) or count($targets) == 0) {
1090 $error->set_error('invalid_set_campaign_merge_data');
1091 self::$helperObject->setFaultObject($error);
1092 $GLOBALS['log']->debug('set_campaign_merge: Merge action status will not be updated, because, campaign_id is null or no targets were selected.');
1093 $GLOBALS['log']->info('End: SugarWebServiceImpl->set_campaign_merge');
1096 require_once('modules/Campaigns/utils.php');
1097 campaign_log_mail_merge($campaign_id,$targets);
1101 * Retrieve number of records in a given module
1103 * @param String session -- Session ID returned by a previous call to login.
1104 * @param String module_name -- module to retrieve number of records from
1105 * @param String query -- allows webservice user to provide a WHERE clause
1106 * @param int deleted -- specify whether or not to include deleted records
1108 * @return Array result_count - integer - Total number of records for a given module and query
1109 * @exception 'SoapFault' -- The SOAP error, if any
1111 function get_entries_count($session, $module_name, $query, $deleted) {
1112 $GLOBALS['log']->info('Begin: SugarWebServiceImpl->get_entries_count');
1114 $error = new SoapError();
1115 if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'list', 'no_access', $error)) {
1116 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries_count');
1120 global $beanList, $beanFiles, $current_user;
1122 $class_name = $beanList[$module_name];
1123 require_once($beanFiles[$class_name]);
1124 $seed = new $class_name();
1126 if (!self::$helperObject->checkQuery($error, $query)) {
1127 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries_count');
1131 if (!self::$helperObject->checkACLAccess($seed, 'ListView', $error, 'no_access')) {
1135 $sql = 'SELECT COUNT(*) result_count FROM ' . $seed->table_name . ' ';
1138 $customJoin = $seed->getCustomJoin();
1139 $sql .= $customJoin['join'];
1141 // build WHERE clauses, if any
1142 $where_clauses = array();
1143 if (!empty($query)) {
1144 $where_clauses[] = $query;
1146 if ($deleted == 0) {
1147 $where_clauses[] = $seed->table_name . '.deleted = 0';
1150 // if WHERE clauses exist, add them to query
1151 if (!empty($where_clauses)) {
1152 $sql .= ' WHERE ' . implode(' AND ', $where_clauses);
1155 $res = $GLOBALS['db']->query($sql);
1156 $row = $GLOBALS['db']->fetchByAssoc($res);
1158 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_entries_count');
1160 'result_count' => $row['result_count'],