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 ********************************************************************************/
41 require_once('include/generic/SugarWidgets/SugarWidgetFieldvarchar.php');
43 class SugarWidgetFieldName extends SugarWidgetFieldVarchar
46 function SugarWidgetFieldName(&$layout_manager) {
47 parent::SugarWidgetFieldVarchar($layout_manager);
48 $this->reporter = $this->layout_manager->getAttribute('reporter');
51 function displayList(&$layout_def)
53 if(empty($layout_def['column_key']))
55 return $this->displayListPlain($layout_def);
58 $module = $this->reporter->all_fields[$layout_def['column_key']]['module'];
59 $name = $layout_def['name'];
60 $layout_def['name'] = 'id';
61 $key = $this->_get_column_alias($layout_def);
62 $key = strtoupper($key);
64 if(empty($layout_def['fields'][$key]))
66 $layout_def['name'] = $name;
67 return $this->displayListPlain($layout_def);
70 $record = $layout_def['fields'][$key];
71 $layout_def['name'] = $name;
73 if ($module == 'Users' && !is_admin($current_user))
74 $module = 'Employees';
75 $str = "<a target='_blank' href=\"index.php?action=DetailView&module=$module&record=$record\">";
76 $str .= $this->displayListPlain($layout_def);
81 function _get_normal_column_select($layout_def)
84 // if $this->db->dbytpe is empty, then grab dbtype value from global array "$sugar_config[dbconfig]"
85 if(empty($this->db->dbType)){
86 $this->db->dbType = $sugar_config['dbconfig']['db_type'];
88 if ( isset($this->reporter->all_fields) ) {
89 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
94 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
96 return parent::_get_column_select($layout_def);
99 // 'fields' are the two fields to concat to create the name
102 if ( ! empty($layout_def['table_alias']))
104 if ($this->db->dbType == 'mysql')
106 $alias .= "CONCAT(CONCAT(IFNULL("
107 .$layout_def['table_alias']."."
108 .$field_def['fields'][0].",''),' '),"
109 .$layout_def['table_alias']."."
110 .$field_def['fields'][1].")";
112 elseif ( $this->db->dbType == 'mssql' )
114 $alias .= $layout_def['table_alias'] . '.' . $field_def['fields'][0] . " + ' ' + "
115 . $layout_def['table_alias'] . '.' . $field_def['fields'][1]."";
118 elseif (! empty($layout_def['name']))
120 $alias = $layout_def['name'];
131 function _get_column_select($layout_def)
133 global $sugar_config;
134 global $locale, $current_user;
136 // if $this->db->dbytpe is empty, then grab dbtype value from global array "$sugar_config[dbconfig]"
137 if(empty($this->db->dbType)){
138 $this->db->dbType = $sugar_config['dbconfig']['db_type'];
140 if ( isset($this->reporter->all_fields) ) {
141 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
143 $field_def = array();
146 // 'fields' are the two fields to concat to create the name
149 if(!isset($field_def['fields']))
151 $alias = $this->_get_normal_column_select($layout_def);
154 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
155 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
158 $names['f'] = db_convert($layout_def['table_alias'].'.'.$field_def['fields'][0].",''","IFNULL");
159 $names['l'] = $layout_def['table_alias'].'.'.$field_def['fields'][1];
161 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
163 return parent::_get_column_select($layout_def);
166 if ( ! empty($layout_def['table_alias']))
168 if ($this->db->dbType == 'mysql')
170 for($i=0; $i<strlen($localeNameFormat); $i++) {
171 $alias .= array_key_exists($localeNameFormat{$i}, $names) ? $names[$localeNameFormat{$i}] : '\''.$localeNameFormat{$i}.'\'';
172 if($i<strlen($localeNameFormat)-1) $alias .= ',';
174 if(strlen($localeNameFormat)>1)
175 $alias = 'concat('.$alias.')';
178 elseif ( $this->db->dbType == 'mssql' )
180 for($i=0; $i<strlen($localeNameFormat); $i++) {
181 $alias .= array_key_exists($localeNameFormat{$i}, $names) ? $names[$localeNameFormat{$i}] : '\''.$localeNameFormat{$i}.'\'';
182 if($i<strlen($localeNameFormat)-1) $alias .= ' + ';
186 elseif (! empty($layout_def['name']))
188 $alias = $layout_def['name'];
199 function queryFilterIs($layout_def)
201 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
202 $layout_def['name'] = 'id';
203 $layout_def['type'] = 'id';
204 $input_name0 = $layout_def['input_name0'];
206 if ( is_array($layout_def['input_name0']))
208 $input_name0 = $layout_def['input_name0'][0];
210 if ($input_name0 == 'Current User') {
211 global $current_user;
212 $input_name0 = $current_user->id;
215 return SugarWidgetFieldid::_get_column_select($layout_def)."='"
216 .$GLOBALS['db']->quote($input_name0)."'\n";
219 function queryFilteris_not($layout_def)
221 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
222 $layout_def['name'] = 'id';
223 $layout_def['type'] = 'id';
224 $input_name0 = $layout_def['input_name0'];
226 if ( is_array($layout_def['input_name0']))
228 $input_name0 = $layout_def['input_name0'][0];
230 if ($input_name0 == 'Current User') {
231 global $current_user;
232 $input_name0 = $current_user->id;
235 return SugarWidgetFieldid::_get_column_select($layout_def)."<>'"
236 .$GLOBALS['db']->quote($input_name0)."'\n";
238 // $rename_columns, if true then you're coming from reports
239 function queryFilterone_of(&$layout_def, $rename_columns = true)
241 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
242 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
243 $layout_def['name'] = 'id';
244 $layout_def['type'] = 'id';
248 foreach($layout_def['input_name0'] as $value)
250 if ($value == 'Current User') {
251 global $current_user;
252 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
255 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
258 $str = implode(",",$arr);
260 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
262 // $rename_columns, if true then you're coming from reports
263 function queryFilternot_one_of(&$layout_def, $rename_columns = true)
265 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
266 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
267 $layout_def['name'] = 'id';
268 $layout_def['type'] = 'id';
272 foreach($layout_def['input_name0'] as $value)
274 if ($value == 'Current User') {
275 global $current_user;
276 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
279 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
282 $str = implode(",",$arr);
284 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
286 function &queryGroupBy($layout_def)
288 if( $this->reporter->db->dbType == 'mysql') {
289 if($layout_def['name'] == 'full_name') {
290 $layout_def['name'] = 'id';
291 $layout_def['type'] = 'id';
292 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
293 $group_by = SugarWidgetFieldid::_get_column_select($layout_def)."\n";
296 // group by clause for user name passes through here.
297 // $layout_def['name'] = 'name';
298 // $layout_def['type'] = 'name';
299 $group_by = $this->_get_column_select($layout_def)."\n";
302 elseif( $this->reporter->db->dbType == 'mssql') {
303 $group_by = $this->_get_column_select($layout_def);