2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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((isset($value->required_fields) && key_exists($var['name'], $value->required_fields)) ||
62 (isset($var['required']) && $var['required'] == '1')){
65 if(isset($var['options'])){
66 $options_dom = translate($var['options'], $value->module_dir);
67 if(!is_array($options_dom)) $options_dom = array();
68 foreach($options_dom as $key=>$oneOption)
69 $options_ret[] = get_name_value($key,$oneOption);
72 if(!empty($var['dbType']) && $var['type'] == 'bool') {
73 $options_ret[] = get_name_value('type', $var['dbType']);
77 $entry['name'] = $var['name'];
78 $entry['type'] = $var['type'];
80 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
82 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
84 $entry['required'] = $required;
85 $entry['options'] = $options_ret;
86 if(isset($var['default'])) {
87 $entry['default_value'] = $var['default'];
90 $list[$var['name']] = $entry;
94 if($value->module_dir == 'Bugs'){
96 $seedRelease = new Release();
97 $options = $seedRelease->get_releases(TRUE, "Active");
98 $options_ret = array();
99 foreach($options as $name=>$value){
100 $options_ret[] = array('name'=> $name , 'value'=>$value);
102 if(isset($list['fixed_in_release'])){
103 $list['fixed_in_release']['type'] = 'enum';
104 $list['fixed_in_release']['options'] = $options_ret;
106 if(isset($list['release'])){
107 $list['release']['type'] = 'enum';
108 $list['release']['options'] = $options_ret;
110 if(isset($list['release_name'])){
111 $list['release_name']['type'] = 'enum';
112 $list['release_name']['options'] = $options_ret;
116 if(isset($value->assigned_user_name) && isset($list['assigned_user_id'])) {
117 $list['assigned_user_name'] = $list['assigned_user_id'];
118 $list['assigned_user_name']['name'] = 'assigned_user_name';
120 if(isset($list['modified_user_id'])) {
121 $list['modified_by_name'] = $list['modified_user_id'];
122 $list['modified_by_name']['name'] = 'modified_by_name';
124 if(isset($list['created_by'])) {
125 $list['created_by_name'] = $list['created_by'];
126 $list['created_by_name']['name'] = 'created_by_name';
131 function new_get_field_list($value, $translate=true) {
132 $module_fields = array();
133 $link_fields = array();
135 if(!empty($value->field_defs)){
137 foreach($value->field_defs as $var){
138 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;
139 if ($var['source'] == 'non_db' && (isset($var['type']) && $var['type'] != 'link')) {
143 $options_dom = array();
144 $options_ret = array();
145 // Apparently the only purpose of this check is to make sure we only return fields
146 // when we've read a record. Otherwise this function is identical to get_module_field_list
147 if((isset($value->required_fields) && key_exists($var['name'], $value->required_fields)) ||
148 (isset($var['required']) && $var['required'] == '1')){
151 if(isset($var['options'])){
152 $options_dom = translate($var['options'], $value->module_dir);
153 if(!is_array($options_dom)) $options_dom = array();
154 foreach($options_dom as $key=>$oneOption)
155 $options_ret[] = get_name_value($key,$oneOption);
158 if(!empty($var['dbType']) && $var['type'] == 'bool') {
159 $options_ret[] = get_name_value('type', $var['dbType']);
163 $entry['name'] = $var['name'];
164 $entry['type'] = $var['type'];
165 if ($var['type'] == 'link') {
166 $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : '');
167 $entry['module'] = (isset($var['module']) ? $var['module'] : '');
168 $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : '');
169 $link_fields[$var['name']] = $entry;
172 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
174 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
176 $entry['required'] = $required;
177 $entry['options'] = $options_ret;
178 if(isset($var['default'])) {
179 $entry['default_value'] = $var['default'];
181 $module_fields[$var['name']] = $entry;
186 if($value->module_dir == 'Bugs'){
188 $seedRelease = new Release();
189 $options = $seedRelease->get_releases(TRUE, "Active");
190 $options_ret = array();
191 foreach($options as $name=>$value){
192 $options_ret[] = array('name'=> $name , 'value'=>$value);
194 if(isset($module_fields['fixed_in_release'])){
195 $module_fields['fixed_in_release']['type'] = 'enum';
196 $module_fields['fixed_in_release']['options'] = $options_ret;
198 if(isset($module_fields['release'])){
199 $module_fields['release']['type'] = 'enum';
200 $module_fields['release']['options'] = $options_ret;
202 if(isset($module_fields['release_name'])){
203 $module_fields['release_name']['type'] = 'enum';
204 $module_fields['release_name']['options'] = $options_ret;
208 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) {
209 $module_fields['assigned_user_name'] = $module_fields['assigned_user_id'];
210 $module_fields['assigned_user_name']['name'] = 'assigned_user_name';
212 if(isset($module_fields['modified_user_id'])) {
213 $module_fields['modified_by_name'] = $module_fields['modified_user_id'];
214 $module_fields['modified_by_name']['name'] = 'modified_by_name';
216 if(isset($module_fields['created_by'])) {
217 $module_fields['created_by_name'] = $module_fields['created_by'];
218 $module_fields['created_by_name']['name'] = 'created_by_name';
221 return array('module_fields' => $module_fields, 'link_fields' => $link_fields);
224 function setFaultObject($errorObject) {
225 global $soap_server_object;
226 $soap_server_object->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription());
229 function checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject) {
230 if(!validate_authenticated($session)){
231 $errorObject->set_error('invalid_login');
232 setFaultObject($errorObject);
236 global $beanList, $beanFiles;
237 if (!empty($module_name)) {
238 if(empty($beanList[$module_name])){
239 $errorObject->set_error('no_module');
240 setFaultObject($errorObject);
243 global $current_user;
244 if(!check_modules_access($current_user, $module_name, $access_level)){
245 $errorObject->set_error('no_access');
246 setFaultObject($errorObject);
253 function checkACLAccess($bean, $viewType, $errorObject, $error_key) {
254 if(!$bean->ACLAccess($viewType)){
255 $errorObject->set_error($error_key);
256 setFaultObject($errorObject);
262 function get_name_value($field,$value){
263 return array('name'=>$field, 'value'=>$value);
266 function get_user_module_list($user){
267 global $app_list_strings, $current_language, $beanList, $beanFiles;
269 $app_list_strings = return_app_list_strings_language($current_language);
270 $modules = query_module_access_list($user);
271 ACLController :: filterModuleList($modules, false);
272 global $modInvisList, $modInvisListActivities;
274 foreach($modInvisList as $invis){
275 $modules[$invis] = 'read_only';
278 if(isset($modules['Calendar']) || $modules['Activities']){
279 foreach($modInvisListActivities as $invis){
280 $modules[$invis] = $invis;
284 $actions = ACLAction::getUserActions($user->id,true);
285 foreach($actions as $key=>$value){
286 if($value['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){
287 if ($value['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED) {
288 unset($modules[$key]);
290 $modules[$key] = 'read_only';
297 //Remove all modules that don't have a beanFiles entry associated with it
298 foreach($modules as $module_name=>$module)
300 $class_name = $beanList[$module_name];
301 if(empty($beanFiles[$class_name]))
303 unset($modules[$module_name]);
311 function check_modules_access($user, $module_name, $action='write'){
312 if(!isset($_SESSION['avail_modules'])){
313 $_SESSION['avail_modules'] = get_user_module_list($user);
315 if(isset($_SESSION['avail_modules'][$module_name])){
316 if($action == 'write' && $_SESSION['avail_modules'][$module_name] == 'read_only'){
317 if(is_admin($user))return true;
326 function get_name_value_list(&$value, $returnDomValue = false){
327 global $app_list_strings;
329 if(!empty($value->field_defs)){
330 if(isset($value->assigned_user_name)) {
331 $list['assigned_user_name'] = get_name_value('assigned_user_name', $value->assigned_user_name);
333 if(isset($value->modified_by_name)) {
334 $list['modified_by_name'] = get_name_value('modified_by_name', $value->modified_by_name);
336 if(isset($value->created_by_name)) {
337 $list['created_by_name'] = get_name_value('created_by_name', $value->created_by_name);
339 foreach($value->field_defs as $var){
340 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')){
342 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'))) {
349 if(isset($value->$var['name'])){
350 $val = $value->$var['name'];
351 $type = $var['type'];
353 if(strcmp($type, 'date') == 0){
354 $val = substr($val, 0, 10);
355 }elseif(strcmp($type, 'enum') == 0 && !empty($var['options']) && $returnDomValue){
356 $val = $app_list_strings[$var['options']][$val];
359 $list[$var['name']] = get_name_value($var['name'], $val);
367 function filter_fields($value, $fields) {
368 global $invalid_contact_fields;
369 $filterFields = array();
370 foreach($fields as $field){
371 if (is_array($invalid_contact_fields)) {
372 if (in_array($field, $invalid_contact_fields)) {
376 if (isset($value->field_defs[$field])) {
377 $var = $value->field_defs[$field];
378 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')) {
383 $filterFields[] = $field;
385 return $filterFields;
388 function get_name_value_list_for_fields($value, $fields) {
389 global $app_list_strings;
390 global $invalid_contact_fields;
393 if(!empty($value->field_defs)){
394 if(isset($value->assigned_user_name) && in_array('assigned_user_name', $fields)) {
395 $list['assigned_user_name'] = get_name_value('assigned_user_name', $value->assigned_user_name);
397 if(isset($value->modified_by_name) && in_array('modified_by_name', $fields)) {
398 $list['modified_by_name'] = get_name_value('modified_by_name', $value->modified_by_name);
400 if(isset($value->created_by_name) && in_array('created_by_name', $fields)) {
401 $list['created_by_name'] = get_name_value('created_by_name', $value->created_by_name);
404 $filterFields = filter_fields($value, $fields);
405 foreach($filterFields as $field){
406 $var = $value->field_defs[$field];
407 if(isset($value->$var['name'])){
408 $val = $value->$var['name'];
409 $type = $var['type'];
411 if(strcmp($type, 'date') == 0){
412 $val = substr($val, 0, 10);
413 }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){
414 $val = $app_list_strings[$var['options']][$val];
417 $list[$var['name']] = get_name_value($var['name'], $val);
426 function array_get_name_value_list($array){
428 foreach($array as $name=>$value){
430 $list[$name] = get_name_value($name, $value);
436 function array_get_name_value_lists($array){
438 foreach($array as $name=>$value){
440 if(is_array($value)){
441 $tmp_value = array();
442 foreach($value as $k=>$v){
443 $tmp_value[] = get_name_value($k, $v);
446 $list[] = get_name_value($name, $tmp_value);
451 function name_value_lists_get_array($list){
453 foreach($list as $key=>$value){
454 if(isset($value['value']) && isset($value['name'])){
455 if(is_array($value['value'])){
456 $array[$value['name']]=array();
457 foreach($value['value'] as $v){
458 $array[$value['name']][$v['name']]=$v['value'];
461 $array[$value['name']]=$value['value'];
468 function array_get_return_value($array, $module){
470 return Array('id'=>$array['id'],
471 'module_name'=> $module,
472 'name_value_list'=>array_get_name_value_list($array)
476 function get_return_value_for_fields($value, $module, $fields) {
477 global $module_name, $current_user;
478 $module_name = $module;
479 if($module == 'Users' && $value->id != $current_user->id){
480 $value->user_hash = '';
482 return Array('id'=>$value->id,
483 'module_name'=> $module,
484 'name_value_list'=>get_name_value_list_for_fields($value, $fields)
488 function getRelationshipResults($bean, $link_field_name, $link_module_fields, $optional_where = '') {
489 global $beanList, $beanFiles;
490 $bean->load_relationship($link_field_name);
491 if (isset($bean->$link_field_name)) {
492 // get the query object for this link field
493 $query_array = $bean->$link_field_name->getQuery(true,array(),0,'',true);
495 $params['joined_tables'] = $query_array['join_tables'];
497 // get the related module name and instantiate a bean for that.
498 $submodulename = $bean->$link_field_name->getRelatedModuleName();
499 $submoduleclass = $beanList[$submodulename];
500 require_once($beanFiles[$submoduleclass]);
502 $submodule = new $submoduleclass();
503 $filterFields = filter_fields($submodule, $link_module_fields);
504 $relFields = $bean->$link_field_name->getRelatedFields();
507 if(!empty($relFields)){
508 foreach($link_module_fields as $field){
509 if(!empty($relFields[$field])){
510 $roleSelect .= ', ' . $query_array['join_tables'][0] . '.'. $field;
515 $subquery = $submodule->create_new_list_query('',$optional_where ,$filterFields,$params, 0,'', true,$bean);
516 $query = $subquery['select'].$roleSelect . $subquery['from'].$query_array['join']. $subquery['where'];
518 $result = $submodule->db->query($query, true);
520 while($row = $submodule->db->fetchByAssoc($result)) {
523 return array('rows' => $list, 'fields_set_on_rows' => $filterFields);
530 function get_return_value_for_link_fields($bean, $module, $link_name_to_value_fields_array) {
531 global $module_name, $current_user;
532 $module_name = $module;
533 if($module == 'Users' && $bean->id != $current_user->id){
534 $bean->user_hash = '';
537 if (empty($link_name_to_value_fields_array) || !is_array($link_name_to_value_fields_array)) {
541 $link_output = array();
542 foreach($link_name_to_value_fields_array as $link_name_value_fields) {
543 if (!is_array($link_name_value_fields) || !isset($link_name_value_fields['name']) || !isset($link_name_value_fields['value'])) {
546 $link_field_name = $link_name_value_fields['name'];
547 $link_module_fields = $link_name_value_fields['value'];
548 if (is_array($link_module_fields) && !empty($link_module_fields)) {
549 $result = getRelationshipResults($bean, $link_field_name, $link_module_fields);
551 $link_output[] = array('name' => $link_field_name, 'records' => array());
554 $list = $result['rows'];
555 $filterFields = $result['fields_set_on_rows'];
558 foreach($list as $row) {
559 $nameValueArray = array();
560 foreach ($filterFields as $field) {
561 $nameValue = array();
562 if (isset($row[$field])) {
563 $nameValue['name'] = $field;
564 $nameValue['value'] = $row[$field];
565 $nameValueArray[] = $nameValue;
568 $rowArray[] = $nameValueArray;
570 $link_output[] = array('name' => $link_field_name, 'records' => $rowArray);
579 * @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).
580 * @param String $module_id -- The ID of the bean in the specified module
581 * @param String $link_field_name - The relationship name for which to create realtionships.
582 * @param Array $related_ids -- The array of ids for which we want to create relationships
583 * @return true on success, false on failure
585 function new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids) {
586 global $beanList, $beanFiles;
588 if(empty($beanList[$module_name])) {
591 $class_name = $beanList[$module_name];
592 require_once($beanFiles[$class_name]);
593 $mod = new $class_name();
594 $mod->retrieve($module_id);
595 if(!$mod->ACLAccess('DetailView')){
599 foreach($related_ids as $ids) {
600 $GLOBALS['log']->debug("ids = " . $ids );
603 if ($mod->load_relationship($link_field_name)) {
604 $mod->$link_field_name->add($related_ids);
611 function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) {
612 global $beanList, $beanFiles;
614 $ret_values = array();
616 global $current_user;
617 $class_name = $beanList[$module_name];
618 require_once($beanFiles[$class_name]);
621 $total = sizeof($name_value_lists);
622 foreach($name_value_lists as $name_value_list){
623 $seed = new $class_name();
625 $seed->update_vcal = false;
626 foreach($name_value_list as $value){
627 if($value['name'] == 'id'){
628 $seed->retrieve($value['value']);
633 foreach($name_value_list as $value) {
634 $val = $value['value'];
635 if($seed->field_name_map[$value['name']]['type'] == 'enum'){
636 $vardef = $seed->field_name_map[$value['name']];
637 if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value]) ) {
638 if ( in_array($val,$app_list_strings[$vardef['options']]) ){
639 $val = array_search($val,$app_list_strings[$vardef['options']]);
643 $seed->$value['name'] = $val;
646 if($count == $total){
647 $seed->update_vcal = false;
651 //Add the account to a contact
652 if($module_name == 'Contacts'){
653 $GLOBALS['log']->debug('Creating Contact Account');
654 add_create_account($seed);
655 $duplicate_id = check_for_duplicate_contacts($seed);
656 if($duplicate_id == null){
657 if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
659 if($seed->deleted == 1){
660 $seed->mark_deleted($seed->id);
666 //since we found a duplicate we should set the sync flag
667 if( $seed->ACLAccess('Save')){
668 $seed = new $class_name();
669 $seed->id = $duplicate_id;
670 $seed->contacts_users_id = $current_user->id;
672 $ids[] = $duplicate_id;//we have a conflict
676 else if($module_name == 'Meetings' || $module_name == 'Calls'){
677 //we are going to check if we have a meeting in the system
678 //with the same outlook_id. If we do find one then we will grab that
680 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
681 if(empty($seed->id) && !isset($seed->id)){
682 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){
683 //at this point we have an object that does not have
684 //the id set, but does have the outlook_id set
685 //so we need to query the db to find if we already
686 //have an object with this outlook_id, if we do
687 //then we can set the id, otherwise this is a new object
689 $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'";
690 $response = $seed->get_list($order_by, $query, 0,-1,-1,0);
691 $list = $response['list'];
692 if(count($list) > 0){
693 foreach($list as $value)
695 $seed->id = $value->id;
707 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){
713 // if somebody is calling set_entries_detail() and wants fields returned...
714 if ($select_fields !== FALSE) {
715 $ret_values[$count] = array();
717 foreach ($select_fields as $select_field) {
718 if (isset($seed->$select_field)) {
719 $ret_values[$count][] = get_name_value($select_field, $seed->$select_field);
725 // handle returns for set_entries_detail() and set_entries()
726 if ($select_fields !== FALSE) {
728 'name_value_lists' => $ret_values,
738 function get_return_value(&$value, $module, $returnDomValue = false){
739 global $module_name, $current_user;
740 $module_name = $module;
741 if($module == 'Users' && $value->id != $current_user->id){
742 $value->user_hash = '';
744 return Array('id'=>$value->id,
745 'module_name'=> $module,
746 'name_value_list'=>get_name_value_list($value, $returnDomValue)
751 function get_name_value_xml($val, $module_name){
753 $xml .= '<id>'.$val['id'].'</id>';
754 $xml .= '<module>'.$module_name.'</module>';
755 $xml .= '<name_value_list>';
756 foreach($val['name_value_list'] as $name=>$nv){
757 $xml .= '<name_value>';
758 $xml .= '<name>'.htmlspecialchars($nv['name']).'</name>';
759 $xml .= '<value>'.htmlspecialchars($nv['value']).'</value>';
760 $xml .= '</name_value>';
762 $xml .= '</name_value_list>';
768 function get_module_field_list(&$value){
770 if(!empty($value->field_defs)){
771 foreach($value->field_defs as $var){
773 $options_dom = array();
774 $translateOptions = false;
776 if(isset($value->required_fields) && key_exists($var['name'], $value->required_fields)){
779 if(isset($var['options'])){
780 $options_dom = $var['options'];
781 $translateOptions = true;
783 if($value->module_dir == 'Bugs'){
784 require_once('modules/Releases/Release.php');
785 $seedRelease = new Release();
786 $options = $seedRelease->get_releases(TRUE, "Active");
787 if($var['name'] == 'fixed_in_release'){
788 $var['type'] = 'enum';
789 $translateOptions = false;
790 foreach($options as $name=>$avalue){
791 $options_dom[$avalue] = $name;
794 if($var['name'] == 'release'){
795 $var['type'] = 'enum';
796 $translateOptions = false;
797 foreach($options as $name=>$avalue){
798 $options_dom[$avalue] = $name;
802 $list[$var['name']] = array('name'=>$var['name'],
803 'type'=>$var['type'],
804 'label'=>translate($var['vname'], $value->module_dir),
805 'required'=>$required,
806 'options'=>get_field_options($options_dom, $translateOptions) );
815 function new_get_return_module_fields($value, $module, $translate=true){
817 $module_name = $module;
818 $result = new_get_field_list($value, $translate);
819 return Array('module_name'=>$module,
820 'module_fields'=> $result['module_fields'],
821 'link_fields'=> $result['link_fields'],
825 function get_return_module_fields(&$value, $module, &$error, $translate=true){
827 $module_name = $module;
828 return Array('module_name'=>$module,
829 'module_fields'=> get_field_list($value, $translate),
830 'error'=>get_name_value_list($value)
834 function get_return_error_value($error_num, $error_name, $error_description){
835 return Array('number'=>$error_num,
836 'name'=> $error_name,
837 'description'=> $error_description
841 function filter_field_list(&$field_list, &$select_fields, $module_name){
842 return filter_return_list($field_list, $select_fields, $module_name);
847 * Filter the results of a list query. Limit the fields returned.
849 * @param Array $output_list -- The array of list data
850 * @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.
851 * @param String $module_name -- The name of the module this being worked on
852 * @return The filtered array of list data.
854 function filter_return_list(&$output_list, $select_fields, $module_name){
856 for($sug = 0; $sug < sizeof($output_list) ; $sug++){
857 if($module_name == 'Contacts'){
858 global $invalid_contact_fields;
859 if(is_array($invalid_contact_fields)){
860 foreach($invalid_contact_fields as $name=>$val){
861 unset($output_list[$sug]['field_list'][$name]);
862 unset($output_list[$sug]['name_value_list'][$name]);
868 if( !empty($output_list[$sug]['name_value_list']) && is_array($output_list[$sug]['name_value_list']) && !empty($select_fields) && is_array($select_fields)){
869 foreach($output_list[$sug]['name_value_list'] as $name=>$value)
870 if(!in_array($value['name'], $select_fields)){
871 unset($output_list[$sug]['name_value_list'][$name]);
872 unset($output_list[$sug]['field_list'][$name]);
879 function login_success(){
880 global $current_language, $sugar_config, $app_strings, $app_list_strings;
881 $current_language = $sugar_config['default_language'];
882 $app_strings = return_application_language($current_language);
883 $app_list_strings = return_app_list_strings_language($current_language);
888 * Given an account_name, either create the account or assign to a contact.
890 function add_create_account(&$seed)
892 global $current_user;
893 $account_name = $seed->account_name;
894 $account_id = $seed->account_id;
895 $assigned_user_id = $current_user->id;
897 // check if it already exists
898 $focus = new Account();
899 if( $focus->ACLAccess('Save')){
900 $class = get_class($seed);
901 $temp = new $class();
902 $temp->retrieve($seed->id);
903 if ((! isset($account_name) || $account_name == ''))
907 if (!isset($seed->accounts)){
908 $seed->load_relationship('accounts');
911 if($seed->account_name == '' && isset($temp->account_id)){
912 $seed->accounts->delete($seed->id, $temp->account_id);
920 $query = "select id, deleted from {$focus->table_name} WHERE name='".$seed->db->quote($account_name)."'";
921 $query .=" ORDER BY deleted ASC";
922 $result = $seed->db->query($query) or sugar_die("Error selecting sugarbean: ".mysql_error());
924 $row = $seed->db->fetchByAssoc($result, -1, false);
926 // we found a row with that id
927 if (isset($row['id']) && $row['id'] != -1)
929 // if it exists but was deleted, just remove it entirely
930 if ( isset($row['deleted']) && $row['deleted'] == 1)
932 $query2 = "delete from {$focus->table_name} WHERE id='". $seed->db->quote($row['id'])."'";
933 $result2 = $seed->db->query($query2) or sugar_die("Error deleting existing sugarbean: ".mysql_error());
935 // else just use this id to link the contact to the account
938 $focus->id = $row['id'];
942 // if we didnt find the account, so create it
943 if (! isset($focus->id) || $focus->id == '')
945 $focus->name = $account_name;
947 if ( isset($assigned_user_id))
949 $focus->assigned_user_id = $assigned_user_id;
950 $focus->modified_user_id = $assigned_user_id;
955 if($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id){
956 $seed->accounts->delete($seed->id, $temp->account_id);
959 if(isset($focus->id) && $focus->id != ''){
960 $seed->account_id = $focus->id;
965 function check_for_duplicate_contacts(&$seed){
968 if(isset($seed->id)){
974 $trimmed_email = trim($seed->email1);
975 $trimmed_last = trim($seed->last_name);
976 $trimmed_first = trim($seed->first_name);
977 if(!empty($trimmed_email)){
979 //obtain a list of contacts which contain the same email address
980 $contacts = $seed->emailAddress->getBeansByEmailAddress($trimmed_email);
981 if(count($contacts) == 0){
984 foreach($contacts as $contact){
985 if(!empty($trimmed_last) && strcmp($trimmed_last, $contact->last_name) == 0){
986 if(!empty($trimmed_email) && strcmp($trimmed_email, $contact->email1) == 0){
987 if(!empty($trimmed_email)){
988 if(strcmp($trimmed_email, $contact->email1) == 0){
989 //bug: 39234 - check if the account names are the same
990 //if the incoming contact's account_name is empty OR it is not empty and is the same
991 //as an existing contact's account name, then find the match.
992 $contact->load_relationship('accounts');
993 if(empty($seed->account_name) || strcmp($seed->account_name, $contact->account_name) == 0){
994 $GLOBALS['log']->info('End: SoapHelperWebServices->check_for_duplicate_contacts - duplicte found ' . $contact->id);
1007 $query = "contacts.last_name = '".$seed->db->quote($trimmed_last,false)."'";
1008 $query .= " AND contacts.first_name = '".$seed->db->quote($trimmed_first,false)."'";
1009 $contacts = $seed->get_list('', $query);
1010 if (count($contacts) == 0){
1013 foreach($contacts['list'] as $contact){
1014 if (empty($contact->email1)){
1015 return $contact->id;
1024 * Given a client version and a server version, determine if the right hand side(server version) is greater
1026 * @param left the client sugar version
1027 * @param right the server version
1029 * return true if the server version is greater or they are equal
1030 * false if the client version is greater
1032 function is_server_version_greater($left, $right){
1033 if(count($left) == 0 && count($right) == 0){
1036 else if(count($left) == 0 || count($right) == 0){
1039 else if($left[0] == $right[0]){
1041 array_shift($right);
1042 return is_server_version_greater($left, $right);
1044 else if($left[0] < $right[0]){
1051 function getFile( $zip_file, $file_in_zip ){
1052 global $sugar_config;
1053 $base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades";
1054 $base_tmp_upgrade_dir = "$base_upgrade_dir/temp";
1055 $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
1056 unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
1057 return( "$my_zip_dir/$file_in_zip" );
1060 function getManifest( $zip_file ){
1061 ini_set("max_execution_time", "3600");
1062 return( getFile( $zip_file, "manifest.php" ) );
1065 if(!function_exists("get_encoded")){
1066 /*HELPER FUNCTIONS*/
1067 function get_encoded($object){
1068 return base64_encode(serialize($object));
1070 function get_decoded($object){
1071 return unserialize(base64_decode($object));
1076 * decrypt a string use the TripleDES algorithm. This meant to be
1077 * modified if the end user chooses a different algorithm
1079 * @param $string - the string to decrypt
1081 * @return a decrypted string if we can decrypt, the original string otherwise
1083 function decrypt_string($string){
1084 if(function_exists('mcrypt_cbc')){
1086 $focus = new Administration();
1087 $focus->retrieveSettings();
1089 if(!empty($focus->settings['ldap_enc_key'])){
1090 $key = $focus->settings['ldap_enc_key'];
1095 $key = substr(md5($key),0,24);
1097 return mcrypt_cbc(MCRYPT_3DES, $key, pack("H*", $buffer), MCRYPT_DECRYPT, $iv);
1105 function canViewPath( $path, $base ){
1106 $path = realpath( $path );
1107 $base = realpath( $base );
1108 return 0 !== strncmp( $path, $base, strlen( $base ) );