2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once('service/v3/SugarWebServiceUtilv3.php');
38 class SugarWebServiceUtilv3_1 extends SugarWebServiceUtilv3
41 function get_return_module_fields($value, $module,$fields, $translate=true)
43 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_return_module_fields');
45 $module_name = $module;
46 $result = $this->get_field_list($value,$fields, $translate);
47 $GLOBALS['log']->info('End: SoapHelperWebServices->get_return_module_fields');
49 $tableName = $value->getTableName();
51 return Array('module_name'=>$module, 'table_name' => $tableName,
52 'module_fields'=> $result['module_fields'],
53 'link_fields'=> $result['link_fields'],
59 * Track a view for a particular bean.
61 * @param SugarBean $seed
62 * @param string $current_view
64 function trackView($seed, $current_view)
66 $trackerManager = TrackerManager::getInstance();
67 if($monitor = $trackerManager->getMonitor('tracker'))
69 $monitor->setValue('date_modified', TimeDate::getInstance()->nowDb());
70 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
71 $monitor->setValue('module_name', $seed->module_dir);
72 $monitor->setValue('action', $current_view);
73 $monitor->setValue('item_id', $seed->id);
74 $monitor->setValue('item_summary', $seed->get_summary_text());
75 $monitor->setValue('visible',true);
76 $trackerManager->saveMonitor($monitor, TRUE, TRUE);
81 * Convert modules list to Web services result
83 * @param array $list List of module candidates (only keys are used)
84 * @param array $availModules List of module availability from Session
86 public function getModulesFromList($list, $availModules)
88 global $app_list_strings;
89 $enabled_modules = array();
90 $availModulesKey = array_flip($availModules);
91 foreach ($list as $key=>$value)
93 if( isset($availModulesKey[$key]) )
95 $label = !empty( $app_list_strings['moduleList'][$key] ) ? $app_list_strings['moduleList'][$key] : '';
96 $acl = self::checkModuleRoleAccess($key);
97 $enabled_modules[] = array('module_key' => $key,'module_label' => $label, 'acls' => $acl);
100 return $enabled_modules;
105 * Examine the application to determine which modules have been enabled..
107 * @param array $availModules An array of all the modules the user already has access to.
108 * @return array Modules enabled within the application.
110 function get_visible_modules($availModules)
112 require_once("modules/MySettings/TabController.php");
113 $controller = new TabController();
114 $tabs = $controller->get_tabs_system();
115 return $this->getModulesFromList($tabs[0], $availModules);
119 * Generate unifed search fields for a particular module even if the module does not participate in the unified search.
121 * @param string $moduleName
122 * @return array An array of fields to be searched against.
124 function generateUnifiedSearchFields($moduleName)
126 global $beanList, $beanFiles, $dictionary;
128 if(!isset($beanList[$moduleName]))
131 $beanName = $beanList[$moduleName];
133 if (!isset($beanFiles[$beanName]))
136 $beanName = BeanFactory::getObjectName($moduleName);
138 $manager = new VardefManager ( );
139 $manager->loadVardef( $moduleName , $beanName ) ;
141 // obtain the field definitions used by generateSearchWhere (duplicate code in view.list.php)
142 if(file_exists('custom/modules/'.$moduleName.'/metadata/metafiles.php')){
143 require('custom/modules/'.$moduleName.'/metadata/metafiles.php');
144 }elseif(file_exists('modules/'.$moduleName.'/metadata/metafiles.php')){
145 require('modules/'.$moduleName.'/metadata/metafiles.php');
148 if(!empty($metafiles[$moduleName]['searchfields']))
149 require $metafiles[$moduleName]['searchfields'] ;
150 elseif(file_exists("modules/{$moduleName}/metadata/SearchFields.php"))
151 require "modules/{$moduleName}/metadata/SearchFields.php" ;
154 foreach ( $dictionary [ $beanName ][ 'fields' ] as $field => $def )
156 if (strpos($field,'email') !== false)
159 //bug: 38139 - allow phone to be searched through Global Search
160 if (strpos($field,'phone') !== false)
163 if ( isset($def['unified_search']) && $def['unified_search'] && isset ( $searchFields [ $moduleName ] [ $field ] ))
165 $fields [ $field ] = $searchFields [ $moduleName ] [ $field ] ;
169 //If no fields with the unified flag have been set then lets add a default field.
172 if( isset($dictionary[$beanName]['fields']['name']) && isset($searchFields[$moduleName]['name']) )
173 $fields['name'] = $searchFields[$moduleName]['name'];
176 if( isset($dictionary[$beanName]['fields']['first_name']) && isset($searchFields[$moduleName]['first_name']) )
177 $fields['first_name'] = $searchFields[$moduleName]['first_name'];
178 if( isset($dictionary[$beanName]['fields']['last_name']) && isset($searchFields[$moduleName]['last_name']) )
179 $fields['last_name'] = $searchFields[$moduleName]['last_name'];
187 * Check a module for acces to a set of available actions.
189 * @param string $module
190 * @return array results containing access and boolean indicating access
192 function checkModuleRoleAccess($module)
195 $actions = array('edit','delete','list','view','import','export');
196 foreach ($actions as $action)
198 $access = ACLController::checkAccess($module, $action, true);
199 $results[] = array('action' => $action, 'access' => $access);
205 function get_field_list($value,$fields, $translate=true) {
207 $GLOBALS['log']->info('Begin: SoapHelperWebServices->get_field_list');
208 $module_fields = array();
209 $link_fields = array();
210 if(!empty($value->field_defs)){
212 foreach($value->field_defs as $var){
213 if(!empty($fields) && !in_array( $var['name'], $fields))continue;
214 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;
215 if ((isset($var['source']) && $var['source'] == 'non_db') && (isset($var['type']) && $var['type'] != 'link')) {
219 $options_dom = array();
220 $options_ret = array();
221 // Apparently the only purpose of this check is to make sure we only return fields
222 // when we've read a record. Otherwise this function is identical to get_module_field_list
223 if( isset($var['required']) && ($var['required'] || $var['required'] == 'true' ) ){
227 if($var['type'] == 'bool')
228 $var['options'] = 'checkbox_dom';
230 if(isset($var['options'])){
231 $options_dom = translate($var['options'], $value->module_dir);
232 if(!is_array($options_dom)) $options_dom = array();
233 foreach($options_dom as $key=>$oneOption)
234 $options_ret[$key] = $this->get_name_value($key,$oneOption);
237 if(!empty($var['dbType']) && $var['type'] == 'bool') {
238 $options_ret['type'] = $this->get_name_value('type', $var['dbType']);
242 $entry['name'] = $var['name'];
243 $entry['type'] = $var['type'];
244 $entry['group'] = isset($var['group']) ? $var['group'] : '';
245 $entry['id_name'] = isset($var['id_name']) ? $var['id_name'] : '';
247 if ($var['type'] == 'link') {
248 $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : '');
249 $entry['module'] = (isset($var['module']) ? $var['module'] : '');
250 $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : '');
251 $link_fields[$var['name']] = $entry;
254 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name'];
256 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name'];
258 $entry['required'] = $required;
259 $entry['options'] = $options_ret;
260 $entry['related_module'] = (isset($var['id_name']) && isset($var['module'])) ? $var['module'] : '';
261 $entry['calculated'] = (isset($var['calculated']) && $var['calculated']) ? true : false;
262 if(isset($var['default'])) {
263 $entry['default_value'] = $var['default'];
265 if( $var['type'] == 'parent' && isset($var['type_name']) )
266 $entry['type_name'] = $var['type_name'];
268 $module_fields[$var['name']] = $entry;
273 if($value->module_dir == 'Meetings' || $value->module_dir == 'Calls')
275 if( isset($module_fields['duration_minutes']) && isset($GLOBALS['app_list_strings']['duration_intervals']))
277 $options_dom = $GLOBALS['app_list_strings']['duration_intervals'];
278 $options_ret = array();
279 foreach($options_dom as $key=>$oneOption)
280 $options_ret[$key] = $this->get_name_value($key,$oneOption);
282 $module_fields['duration_minutes']['options'] = $options_ret;
286 if($value->module_dir == 'Bugs'){
287 require_once('modules/Releases/Release.php');
288 $seedRelease = new Release();
289 $options = $seedRelease->get_releases(TRUE, "Active");
290 $options_ret = array();
291 foreach($options as $name=>$value){
292 $options_ret[] = array('name'=> $name , 'value'=>$value);
294 if(isset($module_fields['fixed_in_release'])){
295 $module_fields['fixed_in_release']['type'] = 'enum';
296 $module_fields['fixed_in_release']['options'] = $options_ret;
298 if(isset($module_fields['found_in_release'])){
299 $module_fields['found_in_release']['type'] = 'enum';
300 $module_fields['found_in_release']['options'] = $options_ret;
302 if(isset($module_fields['release'])){
303 $module_fields['release']['type'] = 'enum';
304 $module_fields['release']['options'] = $options_ret;
306 if(isset($module_fields['release_name'])){
307 $module_fields['release_name']['type'] = 'enum';
308 $module_fields['release_name']['options'] = $options_ret;
312 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) {
313 $module_fields['assigned_user_name'] = $module_fields['assigned_user_id'];
314 $module_fields['assigned_user_name']['name'] = 'assigned_user_name';
316 if(isset($value->assigned_name) && isset($module_fields['team_id'])) {
317 $module_fields['team_name'] = $module_fields['team_id'];
318 $module_fields['team_name']['name'] = 'team_name';
320 if(isset($module_fields['modified_user_id'])) {
321 $module_fields['modified_by_name'] = $module_fields['modified_user_id'];
322 $module_fields['modified_by_name']['name'] = 'modified_by_name';
324 if(isset($module_fields['created_by'])) {
325 $module_fields['created_by_name'] = $module_fields['created_by'];
326 $module_fields['created_by_name']['name'] = 'created_by_name';
329 $GLOBALS['log']->info('End: SoapHelperWebServices->get_field_list');
330 return array('module_fields' => $module_fields, 'link_fields' => $link_fields);
334 * Return the contents of a file base64 encoded
336 * @param string $filename - Full path of filename
337 * @param bool $remove - Indicates if the file should be removed after the contents is retrieved.
339 * @return string - Contents base64'd.
341 function get_file_contents_base64($filename, $remove = FALSE)
344 if( file_exists($filename) )
346 $contents = base64_encode(file_get_contents($filename));
354 function get_module_view_defs($module_name, $type, $view){
355 require_once('include/MVC/View/SugarView.php');
356 $metadataFile = null;
358 $view = strtolower($view);
359 switch (strtolower($type)){
362 if ($view == 'subpanel')
363 $results = $this->get_subpanel_defs($module_name, $type);
366 $v = new SugarView(null,array());
367 $v->module = $module_name;
369 $fullView = ucfirst($view) . 'View';
370 $metadataFile = $v->getMetaDataFile();
371 require_once($metadataFile);
373 $results = $listViewDefs[$module_name];
375 $results = $viewdefs[$module_name][$fullView];
383 * Equivalent of get_list function within SugarBean but allows the possibility to pass in an indicator
384 * if the list should filter for favorites. Should eventually update the SugarBean function as well.
387 function get_data_list($seed, $order_by = "", $where = "", $row_offset = 0, $limit=-1, $max=-1, $show_deleted = 0, $favorites = false, $singleSelect=false)
389 $GLOBALS['log']->debug("get_list: order_by = '$order_by' and where = '$where' and limit = '$limit'");
390 if(isset($_SESSION['show_deleted']))
394 $order_by=$seed->process_order_by($order_by, null);
396 if($seed->bean_implements('ACL') && ACLController::requireOwner($seed->module_dir, 'list') )
398 global $current_user;
399 $owner_where = $seed->getOwnerWhere($current_user->id);
400 if(!empty($owner_where)){
402 $where = $owner_where;
404 $where .= ' AND '. $owner_where;
410 $params['favorites'] = true;
412 $query = $seed->create_new_list_query($order_by, $where,array(),$params, $show_deleted,'',false,null,$singleSelect);
413 return $seed->process_list_query($query, $row_offset, $limit, $max, $where);
417 * Add ACL values to metadata files.
419 * @param String $module_name
420 * @param String $view_type
421 * @param String $view (list, detail,edit, etc)
422 * @param array $metadata The metadata for the view type and view.
425 function addFieldLevelACLs($module_name,$view_type, $view, $metadata)
427 $functionName = "metdataAclParser" . ucfirst($view_type) . ucfirst($view);
428 if( method_exists($this, $functionName) )
429 return $this->$functionName($module_name, $metadata);
436 * Return the field level acl raw value. We cannot use the hasAccess call as we do not have a valid bean
437 * record at the moment and therefore can not specify the is_owner flag. We need the raw access value so we
438 * can do the computation on the client side. TODO: Move function into ACLField class.
440 * @param String $module Name of the module
441 * @param String $field Name of the field
444 function getFieldLevelACLValue($module, $field, $current_user = null)
446 if($current_user == null)
447 $current_user = $GLOBALS['current_user'];
449 if( is_admin($current_user) )
452 if(!isset($_SESSION['ACL'][$current_user->id][$module]['fields'][$field])){
456 return $_SESSION['ACL'][$current_user->id][$module]['fields'][$field];