2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 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 * Retrieve field data for a provided SugarBean.
42 * @param SugarBean $value -- The bean to retrieve the field information for.
43 * @return Array -- 'field'=> 'name' -- the name of the field
44 * 'type' -- the data type of the field
45 * 'label' -- the translation key for the label of the field
46 * 'required' -- Is the field required?
47 * 'options' -- Possible values for a drop down field
49 function get_field_list($value, $translate=true){
52 if(!empty($value->field_defs)){
54 foreach($value->field_defs as $var){
55 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue;
57 $options_dom = array();
58 $options_ret = array();
59 // Apparently the only purpose of this check is to make sure we only return fields
60 // when we've read a record. Otherwise this function is identical to get_module_field_list
61 if(!empty($var['required'])) {
64 if(isset($var['options'])){
65 $options_dom = translate($var['options'], $value->module_dir);
66 if(!is_array($options_dom)) $options_dom = array();
67 foreach($options_dom as $key=>$oneOption)
68 $options_ret[] = get_name_value($key,$oneOption);
71 if(!empty($var['dbType']) && $var['type'] == 'bool') {
72 $options_ret[] = get_name_value('type', $var['dbType']);
76 $entry['name'] = $var['name'];
77 $entry['type'] = $var['type'];
79 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
81 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
83 $entry['required'] = $required;
84 $entry['options'] = $options_ret;
85 if(isset($var['default'])) {
86 $entry['default_value'] = $var['default'];
89 $list[$var['name']] = $entry;
93 if($value->module_dir == 'Bugs'){
95 $seedRelease = new Release();
96 $options = $seedRelease->get_releases(TRUE, "Active");
97 $options_ret = array();
98 foreach($options as $name=>$value){
99 $options_ret[] = array('name'=> $name , 'value'=>$value);
101 if(isset($list['fixed_in_release'])){
102 $list['fixed_in_release']['type'] = 'enum';
103 $list['fixed_in_release']['options'] = $options_ret;
105 if(isset($list['release'])){
106 $list['release']['type'] = 'enum';
107 $list['release']['options'] = $options_ret;
109 if(isset($list['release_name'])){
110 $list['release_name']['type'] = 'enum';
111 $list['release_name']['options'] = $options_ret;
115 if(isset($value->assigned_user_name) && isset($list['assigned_user_id'])) {
116 $list['assigned_user_name'] = $list['assigned_user_id'];
117 $list['assigned_user_name']['name'] = 'assigned_user_name';
119 if(isset($list['modified_user_id'])) {
120 $list['modified_by_name'] = $list['modified_user_id'];
121 $list['modified_by_name']['name'] = 'modified_by_name';
123 if(isset($list['created_by'])) {
124 $list['created_by_name'] = $list['created_by'];
125 $list['created_by_name']['name'] = 'created_by_name';
130 function new_get_field_list($value, $translate=true) {
131 $module_fields = array();
132 $link_fields = array();
134 if(!empty($value->field_defs)){
136 foreach($value->field_defs as $var){
137 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'non-db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue;
138 if ($var['source'] == 'non_db' && (isset($var['type']) && $var['type'] != 'link')) {
142 $options_dom = array();
143 $options_ret = array();
144 // Apparently the only purpose of this check is to make sure we only return fields
145 // when we've read a record. Otherwise this function is identical to get_module_field_list
146 if(!empty($var['required'])) {
149 if(isset($var['options'])){
150 $options_dom = translate($var['options'], $value->module_dir);
151 if(!is_array($options_dom)) $options_dom = array();
152 foreach($options_dom as $key=>$oneOption)
153 $options_ret[] = get_name_value($key,$oneOption);
156 if(!empty($var['dbType']) && $var['type'] == 'bool') {
157 $options_ret[] = get_name_value('type', $var['dbType']);
161 $entry['name'] = $var['name'];
162 $entry['type'] = $var['type'];
163 if ($var['type'] == 'link') {
164 $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : '');
165 $entry['module'] = (isset($var['module']) ? $var['module'] : '');
166 $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : '');
167 $link_fields[$var['name']] = $entry;
170 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
172 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
174 $entry['required'] = $required;
175 $entry['options'] = $options_ret;
176 if(isset($var['default'])) {
177 $entry['default_value'] = $var['default'];
179 $module_fields[$var['name']] = $entry;
184 if($value->module_dir == 'Bugs'){
186 $seedRelease = new Release();
187 $options = $seedRelease->get_releases(TRUE, "Active");
188 $options_ret = array();
189 foreach($options as $name=>$value){
190 $options_ret[] = array('name'=> $name , 'value'=>$value);
192 if(isset($module_fields['fixed_in_release'])){
193 $module_fields['fixed_in_release']['type'] = 'enum';
194 $module_fields['fixed_in_release']['options'] = $options_ret;
196 if(isset($module_fields['release'])){
197 $module_fields['release']['type'] = 'enum';
198 $module_fields['release']['options'] = $options_ret;
200 if(isset($module_fields['release_name'])){
201 $module_fields['release_name']['type'] = 'enum';
202 $module_fields['release_name']['options'] = $options_ret;
206 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) {
207 $module_fields['assigned_user_name'] = $module_fields['assigned_user_id'];
208 $module_fields['assigned_user_name']['name'] = 'assigned_user_name';
210 if(isset($module_fields['modified_user_id'])) {
211 $module_fields['modified_by_name'] = $module_fields['modified_user_id'];
212 $module_fields['modified_by_name']['name'] = 'modified_by_name';
214 if(isset($module_fields['created_by'])) {
215 $module_fields['created_by_name'] = $module_fields['created_by'];
216 $module_fields['created_by_name']['name'] = 'created_by_name';
219 return array('module_fields' => $module_fields, 'link_fields' => $link_fields);
222 function setFaultObject($errorObject) {
223 global $soap_server_object;
224 $soap_server_object->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription());
227 function checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject) {
228 if(!validate_authenticated($session)){
229 $errorObject->set_error('invalid_login');
230 setFaultObject($errorObject);
234 global $beanList, $beanFiles;
235 if (!empty($module_name)) {
236 if(empty($beanList[$module_name])){
237 $errorObject->set_error('no_module');
238 setFaultObject($errorObject);
241 global $current_user;
242 if(!check_modules_access($current_user, $module_name, $access_level)){
243 $errorObject->set_error('no_access');
244 setFaultObject($errorObject);
251 function checkACLAccess($bean, $viewType, $errorObject, $error_key) {
252 if(!$bean->ACLAccess($viewType)){
253 $errorObject->set_error($error_key);
254 setFaultObject($errorObject);
260 function get_name_value($field,$value){
261 return array('name'=>$field, 'value'=>$value);
264 function get_user_module_list($user){
265 global $app_list_strings, $current_language, $beanList, $beanFiles;
267 $app_list_strings = return_app_list_strings_language($current_language);
268 $modules = query_module_access_list($user);
269 ACLController :: filterModuleList($modules, false);
270 global $modInvisList;
272 foreach($modInvisList as $invis){
273 $modules[$invis] = 'read_only';
276 $actions = ACLAction::getUserActions($user->id,true);
277 foreach($actions as $key=>$value){
278 if($value['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){
279 if ($value['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED) {
280 unset($modules[$key]);
282 $modules[$key] = 'read_only';
289 //Remove all modules that don't have a beanFiles entry associated with it
290 foreach($modules as $module_name=>$module)
292 $class_name = $beanList[$module_name];
293 if(empty($beanFiles[$class_name]))
295 unset($modules[$module_name]);
303 function check_modules_access($user, $module_name, $action='write'){
304 if(!isset($_SESSION['avail_modules'])){
305 $_SESSION['avail_modules'] = get_user_module_list($user);
307 if(isset($_SESSION['avail_modules'][$module_name])){
308 if($action == 'write' && $_SESSION['avail_modules'][$module_name] == 'read_only'){
309 if(is_admin($user))return true;
318 function get_name_value_list($value, $returnDomValue = false){
319 global $app_list_strings;
321 if(!empty($value->field_defs)){
322 if(isset($value->assigned_user_name)) {
323 $list['assigned_user_name'] = get_name_value('assigned_user_name', $value->assigned_user_name);
325 if(isset($value->modified_by_name)) {
326 $list['modified_by_name'] = get_name_value('modified_by_name', $value->modified_by_name);
328 if(isset($value->created_by_name)) {
329 $list['created_by_name'] = get_name_value('created_by_name', $value->created_by_name);
331 foreach($value->field_defs as $var){
332 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')){
334 if($value->module_dir == 'Emails' && (($var['name'] == 'description') || ($var['name'] == 'description_html') || ($var['name'] == 'from_addr_name') || ($var['name'] == 'reply_to_addr') || ($var['name'] == 'to_addrs_names') || ($var['name'] == 'cc_addrs_names') || ($var['name'] == 'bcc_addrs_names') || ($var['name'] == 'raw_source'))) {
341 if(isset($value->$var['name'])){
342 $val = $value->$var['name'];
343 $type = $var['type'];
345 if(strcmp($type, 'date') == 0){
346 $val = substr($val, 0, 10);
347 }elseif(strcmp($type, 'enum') == 0 && !empty($var['options']) && $returnDomValue){
348 $val = $app_list_strings[$var['options']][$val];
351 $list[$var['name']] = get_name_value($var['name'], $val);
359 function filter_fields($value, $fields) {
360 global $invalid_contact_fields;
361 $filterFields = array();
362 foreach($fields as $field){
363 if (is_array($invalid_contact_fields)) {
364 if (in_array($field, $invalid_contact_fields)) {
368 if (isset($value->field_defs[$field])) {
369 $var = $value->field_defs[$field];
370 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')) {
375 $filterFields[] = $field;
377 return $filterFields;
380 function get_name_value_list_for_fields($value, $fields) {
381 global $app_list_strings;
382 global $invalid_contact_fields;
385 if(!empty($value->field_defs)){
386 if(isset($value->assigned_user_name) && in_array('assigned_user_name', $fields)) {
387 $list['assigned_user_name'] = get_name_value('assigned_user_name', $value->assigned_user_name);
389 if(isset($value->modified_by_name) && in_array('modified_by_name', $fields)) {
390 $list['modified_by_name'] = get_name_value('modified_by_name', $value->modified_by_name);
392 if(isset($value->created_by_name) && in_array('created_by_name', $fields)) {
393 $list['created_by_name'] = get_name_value('created_by_name', $value->created_by_name);
396 $filterFields = filter_fields($value, $fields);
397 foreach($filterFields as $field){
398 $var = $value->field_defs[$field];
399 if(isset($value->$var['name'])){
400 $val = $value->$var['name'];
401 $type = $var['type'];
403 if(strcmp($type, 'date') == 0){
404 $val = substr($val, 0, 10);
405 }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){
406 $val = $app_list_strings[$var['options']][$val];
409 $list[$var['name']] = get_name_value($var['name'], $val);
418 function array_get_name_value_list($array){
420 foreach($array as $name=>$value){
422 $list[$name] = get_name_value($name, $value);
428 function array_get_name_value_lists($array){
430 foreach($array as $name=>$value){
432 if(is_array($value)){
433 $tmp_value = array();
434 foreach($value as $k=>$v){
435 $tmp_value[] = get_name_value($k, $v);
438 $list[] = get_name_value($name, $tmp_value);
443 function name_value_lists_get_array($list){
445 foreach($list as $key=>$value){
446 if(isset($value['value']) && isset($value['name'])){
447 if(is_array($value['value'])){
448 $array[$value['name']]=array();
449 foreach($value['value'] as $v){
450 $array[$value['name']][$v['name']]=$v['value'];
453 $array[$value['name']]=$value['value'];
460 function array_get_return_value($array, $module){
462 return Array('id'=>$array['id'],
463 'module_name'=> $module,
464 'name_value_list'=>array_get_name_value_list($array)
468 function get_return_value_for_fields($value, $module, $fields) {
469 global $module_name, $current_user;
470 $module_name = $module;
471 if($module == 'Users' && $value->id != $current_user->id){
472 $value->user_hash = '';
474 return Array('id'=>$value->id,
475 'module_name'=> $module,
476 'name_value_list'=>get_name_value_list_for_fields($value, $fields)
480 function getRelationshipResults($bean, $link_field_name, $link_module_fields, $optional_where = '') {
481 global $beanList, $beanFiles;
482 $bean->load_relationship($link_field_name);
483 if (isset($bean->$link_field_name)) {
484 // get the query object for this link field
485 $query_array = $bean->$link_field_name->getQuery(true,array(),0,'',true);
487 $params['joined_tables'] = $query_array['join_tables'];
489 // get the related module name and instantiate a bean for that.
490 $submodulename = $bean->$link_field_name->getRelatedModuleName();
491 $submoduleclass = $beanList[$submodulename];
492 require_once($beanFiles[$submoduleclass]);
494 $submodule = new $submoduleclass();
495 $filterFields = filter_fields($submodule, $link_module_fields);
496 $relFields = $bean->$link_field_name->getRelatedFields();
499 if(!empty($relFields)){
500 foreach($link_module_fields as $field){
501 if(!empty($relFields[$field])){
502 $roleSelect .= ', ' . $query_array['join_tables'][0] . '.'. $field;
507 $subquery = $submodule->create_new_list_query('',$optional_where ,$filterFields,$params, 0,'', true,$bean);
508 $query = $subquery['select'].$roleSelect . $subquery['from'].$query_array['join']. $subquery['where'];
510 $result = $submodule->db->query($query, true);
512 while($row = $submodule->db->fetchByAssoc($result)) {
515 return array('rows' => $list, 'fields_set_on_rows' => $filterFields);
522 function get_return_value_for_link_fields($bean, $module, $link_name_to_value_fields_array) {
523 global $module_name, $current_user;
524 $module_name = $module;
525 if($module == 'Users' && $bean->id != $current_user->id){
526 $bean->user_hash = '';
529 if (empty($link_name_to_value_fields_array) || !is_array($link_name_to_value_fields_array)) {
533 $link_output = array();
534 foreach($link_name_to_value_fields_array as $link_name_value_fields) {
535 if (!is_array($link_name_value_fields) || !isset($link_name_value_fields['name']) || !isset($link_name_value_fields['value'])) {
538 $link_field_name = $link_name_value_fields['name'];
539 $link_module_fields = $link_name_value_fields['value'];
540 if (is_array($link_module_fields) && !empty($link_module_fields)) {
541 $result = getRelationshipResults($bean, $link_field_name, $link_module_fields);
543 $link_output[] = array('name' => $link_field_name, 'records' => array());
546 $list = $result['rows'];
547 $filterFields = $result['fields_set_on_rows'];
550 foreach($list as $row) {
551 $nameValueArray = array();
552 foreach ($filterFields as $field) {
553 $nameValue = array();
554 if (isset($row[$field])) {
555 $nameValue['name'] = $field;
556 $nameValue['value'] = $row[$field];
557 $nameValueArray[] = $nameValue;
560 $rowArray[] = $nameValueArray;
562 $link_output[] = array('name' => $link_field_name, 'records' => $rowArray);
571 * @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).
572 * @param String $module_id -- The ID of the bean in the specified module
573 * @param String $link_field_name - The relationship name for which to create realtionships.
574 * @param Array $related_ids -- The array of ids for which we want to create relationships
575 * @return true on success, false on failure
577 function new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids) {
578 global $beanList, $beanFiles;
580 if(empty($beanList[$module_name])) {
583 $class_name = $beanList[$module_name];
584 require_once($beanFiles[$class_name]);
585 $mod = new $class_name();
586 $mod->retrieve($module_id);
587 if(!$mod->ACLAccess('DetailView')){
591 foreach($related_ids as $ids) {
592 $GLOBALS['log']->debug("ids = " . $ids );
595 if ($mod->load_relationship($link_field_name)) {
596 $mod->$link_field_name->add($related_ids);
603 function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
604 global $beanList, $beanFiles, $app_list_strings;
605 global $current_user;
607 $ret_values = array();
609 $class_name = $beanList[$module_name];
610 require_once($beanFiles[$class_name]);
613 $total = sizeof($name_value_lists);
614 foreach($name_value_lists as $name_value_list){
615 $seed = new $class_name();
617 $seed->update_vcal = false;
618 foreach($name_value_list as $value){
619 if($value['name'] == 'id'){
620 $seed->retrieve($value['value']);
625 foreach($name_value_list as $value) {
626 $val = $value['value'];
627 if($seed->field_name_map[$value['name']]['type'] == 'enum'){
628 $vardef = $seed->field_name_map[$value['name']];
629 if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value]) ) {
630 if ( in_array($val,$app_list_strings[$vardef['options']]) ){
631 $val = array_search($val,$app_list_strings[$vardef['options']]);
635 $seed->$value['name'] = $val;
638 if($count == $total){
639 $seed->update_vcal = false;
643 //Add the account to a contact
644 if($module_name == 'Contacts'){
645 $GLOBALS['log']->debug('Creating Contact Account');
646 add_create_account($seed);
647 $duplicate_id = check_for_duplicate_contacts($seed);
648 if($duplicate_id == null){
649 if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
651 if($seed->deleted == 1){
652 $seed->mark_deleted($seed->id);
658 //since we found a duplicate we should set the sync flag
659 if( $seed->ACLAccess('Save')){
660 $seed = new $class_name();
661 $seed->id = $duplicate_id;
662 $seed->contacts_users_id = $current_user->id;
664 $ids[] = $duplicate_id;//we have a conflict
668 else if($module_name == 'Meetings' || $module_name == 'Calls'){
669 //we are going to check if we have a meeting in the system
670 //with the same outlook_id. If we do find one then we will grab that
672 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
673 if(empty($seed->id) && !isset($seed->id)){
674 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
675 //at this point we have an object that does not have
676 //the id set, but does have the outlook_id set
677 //so we need to query the db to find if we already
678 //have an object with this outlook_id, if we do
679 //then we can set the id, otherwise this is a new object
681 $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
682 $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
683 $list = $response['list'];
684 if(count($list) > 0){
685 foreach($list as $value)
687 $seed->id = $value->id;
699 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
705 // if somebody is calling set_entries_detail() and wants fields returned...
706 if ($select_fields !== FALSE) {
707 $ret_values[$count] = array();
709 foreach ($select_fields as $select_field) {
710 if (isset($seed->$select_field)) {
711 $ret_values[$count][] = get_name_value($select_field, $seed->$select_field);
717 // handle returns for set_entries_detail() and set_entries()
718 if ($select_fields !== FALSE) {
720 'name_value_lists' => $ret_values,
730 function get_return_value($value, $module, $returnDomValue = false){
731 global $module_name, $current_user;
732 $module_name = $module;
733 if($module == 'Users' && $value->id != $current_user->id){
734 $value->user_hash = '';
736 return Array('id'=>$value->id,
737 'module_name'=> $module,
738 'name_value_list'=>get_name_value_list($value, $returnDomValue)
743 function get_name_value_xml($val, $module_name){
745 $xml .= '<id>'.$val['id'].'</id>';
746 $xml .= '<module>'.$module_name.'</module>';
747 $xml .= '<name_value_list>';
748 foreach($val['name_value_list'] as $name=>$nv){
749 $xml .= '<name_value>';
750 $xml .= '<name>'.htmlspecialchars($nv['name']).'</name>';
751 $xml .= '<value>'.htmlspecialchars($nv['value']).'</value>';
752 $xml .= '</name_value>';
754 $xml .= '</name_value_list>';
759 function new_get_return_module_fields($value, $module, $translate=true){
761 $module_name = $module;
762 $result = new_get_field_list($value, $translate);
763 return Array('module_name'=>$module,
764 'module_fields'=> $result['module_fields'],
765 'link_fields'=> $result['link_fields'],
769 function get_return_module_fields($value, $module, $error, $translate=true){
771 $module_name = $module;
772 return Array('module_name'=>$module,
773 'module_fields'=> get_field_list($value, $translate),
774 'error'=>get_name_value_list($value)
778 function get_return_error_value($error_num, $error_name, $error_description){
779 return Array('number'=>$error_num,
780 'name'=> $error_name,
781 'description'=> $error_description
785 function filter_field_list(&$field_list, $select_fields, $module_name){
786 return filter_return_list($field_list, $select_fields, $module_name);
791 * Filter the results of a list query. Limit the fields returned.
793 * @param Array $output_list -- The array of list data
794 * @param Array $select_fields -- The list of fields that should be returned. If this array is specfied, only the fields in the array will be returned.
795 * @param String $module_name -- The name of the module this being worked on
796 * @return The filtered array of list data.
798 function filter_return_list(&$output_list, $select_fields, $module_name){
800 for($sug = 0; $sug < sizeof($output_list) ; $sug++){
801 if($module_name == 'Contacts'){
802 global $invalid_contact_fields;
803 if(is_array($invalid_contact_fields)){
804 foreach($invalid_contact_fields as $name=>$val){
805 unset($output_list[$sug]['field_list'][$name]);
806 unset($output_list[$sug]['name_value_list'][$name]);
812 if( !empty($output_list[$sug]['name_value_list']) && is_array($output_list[$sug]['name_value_list']) && !empty($select_fields) && is_array($select_fields)){
813 foreach($output_list[$sug]['name_value_list'] as $name=>$value)
814 if(!in_array($value['name'], $select_fields)){
815 unset($output_list[$sug]['name_value_list'][$name]);
816 unset($output_list[$sug]['field_list'][$name]);
823 function login_success(){
824 global $current_language, $sugar_config, $app_strings, $app_list_strings;
825 $current_language = $sugar_config['default_language'];
826 $app_strings = return_application_language($current_language);
827 $app_list_strings = return_app_list_strings_language($current_language);
832 * Given an account_name, either create the account or assign to a contact.
834 function add_create_account($seed)
836 global $current_user;
837 $account_name = $seed->account_name;
838 $account_id = $seed->account_id;
839 $assigned_user_id = $current_user->id;
841 // check if it already exists
842 $focus = new Account();
843 if( $focus->ACLAccess('Save')){
844 $class = get_class($seed);
845 $temp = new $class();
846 $temp->retrieve($seed->id);
847 if ((! isset($account_name) || $account_name == ''))
851 if (!isset($seed->accounts)){
852 $seed->load_relationship('accounts');
855 if($seed->account_name == '' && isset($temp->account_id)){
856 $seed->accounts->delete($seed->id, $temp->account_id);
864 $query = "select id, deleted from {$focus->table_name} WHERE name='".$seed->db->quote($account_name)."'";
865 $query .=" ORDER BY deleted ASC";
866 $result = $seed->db->query($query) or sugar_die("Error selecting sugarbean: ".mysql_error());
868 $row = $seed->db->fetchByAssoc($result, -1, false);
870 // we found a row with that id
871 if (isset($row['id']) && $row['id'] != -1)
873 // if it exists but was deleted, just remove it entirely
874 if ( isset($row['deleted']) && $row['deleted'] == 1)
876 $query2 = "delete from {$focus->table_name} WHERE id='". $seed->db->quote($row['id'])."'";
877 $result2 = $seed->db->query($query2) or sugar_die("Error deleting existing sugarbean: ".mysql_error());
879 // else just use this id to link the contact to the account
882 $focus->id = $row['id'];
886 // if we didnt find the account, so create it
887 if (! isset($focus->id) || $focus->id == '')
889 $focus->name = $account_name;
891 if ( isset($assigned_user_id))
893 $focus->assigned_user_id = $assigned_user_id;
894 $focus->modified_user_id = $assigned_user_id;
899 if($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id){
900 $seed->accounts->delete($seed->id, $temp->account_id);
903 if(isset($focus->id) && $focus->id != ''){
904 $seed->account_id = $focus->id;
909 function check_for_duplicate_contacts($seed){
912 if(isset($seed->id)){
918 $trimmed_email = trim($seed->email1);
919 $trimmed_last = trim($seed->last_name);
920 $trimmed_first = trim($seed->first_name);
921 if(!empty($trimmed_email)){
923 //obtain a list of contacts which contain the same email address
924 $contacts = $seed->emailAddress->getBeansByEmailAddress($trimmed_email);
925 if(count($contacts) == 0){
928 foreach($contacts as $contact){
929 if(!empty($trimmed_last) && strcmp($trimmed_last, $contact->last_name) == 0){
930 if(!empty($trimmed_email) && strcmp($trimmed_email, $contact->email1) == 0){
931 if(!empty($trimmed_email)){
932 if(strcmp($trimmed_email, $contact->email1) == 0){
933 //bug: 39234 - check if the account names are the same
934 //if the incoming contact's account_name is empty OR it is not empty and is the same
935 //as an existing contact's account name, then find the match.
936 $contact->load_relationship('accounts');
937 if(empty($seed->account_name) || strcmp($seed->account_name, $contact->account_name) == 0){
938 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - duplicte found ' . $contact->id);
951 $query = "contacts.last_name = '".$seed->db->quote($trimmed_last,false)."'";
952 $query .= " AND contacts.first_name = '".$seed->db->quote($trimmed_first,false)."'";
953 $contacts = $seed->get_list('', $query);
954 if (count($contacts) == 0){
957 foreach($contacts['list'] as $contact){
958 if (empty($contact->email1)){
968 * Given a client version and a server version, determine if the right hand side(server version) is greater
970 * @param left the client sugar version
971 * @param right the server version
973 * return true if the server version is greater or they are equal
974 * false if the client version is greater
976 function is_server_version_greater($left, $right){
977 if(count($left) == 0 && count($right) == 0){
980 else if(count($left) == 0 || count($right) == 0){
983 else if($left[0] == $right[0]){
986 return is_server_version_greater($left, $right);
988 else if($left[0] < $right[0]){
995 function getFile( $zip_file, $file_in_zip ){
996 global $sugar_config;
997 $base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
998 $base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
999 $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
1000 unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
1001 return( "$my_zip_dir/$file_in_zip" );
1004 function getManifest( $zip_file ){
1005 ini_set("max_execution_time", "3600");
1006 return( getFile( $zip_file, "manifest.php" ) );
1009 if(!function_exists("get_encoded")){
1010 /*HELPER FUNCTIONS*/
1011 function get_encoded($object){
1012 return base64_encode(serialize($object));
1014 function get_decoded($object){
1015 return unserialize(base64_decode($object));
1020 * decrypt a string use the TripleDES algorithm. This meant to be
1021 * modified if the end user chooses a different algorithm
1023 * @param $string - the string to decrypt
1025 * @return a decrypted string if we can decrypt, the original string otherwise
1027 function decrypt_string($string){
1028 if(function_exists('mcrypt_cbc')){
1030 $focus = new Administration();
1031 $focus->retrieveSettings();
1033 if(!empty($focus->settings['ldap_enc_key'])){
1034 $key = $focus->settings['ldap_enc_key'];
1039 $key = substr(md5($key),0,24);
1041 return mcrypt_cbc(MCRYPT_3DES, $key, pack("H*", $buffer), MCRYPT_DECRYPT, $iv);
1049 function canViewPath( $path, $base ){
1050 $path = realpath( $path );
1051 $base = realpath( $base );
1052 return 0 !== strncmp( $path, $base, strlen( $base ) );