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 ********************************************************************************/
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 if (isset ($sugar_config['enable_inline_reports_edit']) && $sugar_config['enable_inline_reports_edit'] && !empty($record)) {
82 $div_id = "$module&$record&$name";
83 $str = "<div id='$div_id'><a target='_blank' href=\"index.php?action=DetailView&module=$module&record=$record\">";
84 $value = $this->displayListPlain($layout_def);
86 $field_name = $layout_def['name'];
87 $field_type = $field_def['type'];
89 if ($field_name == 'name')
90 $str .= " " .SugarThemeRegistry::current()->getImage("edit_inline","border='0' alt='Edit Layout' align='bottom' onClick='SUGAR.reportsInlineEdit.inlineEdit(\"$div_id\",\"$value\",\"$module\",\"$record\",\"$field_name\",\"$field_type\");'");
96 function _get_normal_column_select($layout_def)
99 // if $this->db->dbytpe is empty, then grab dbtype value from global array "$sugar_config[dbconfig]"
100 if(empty($this->db->dbType)){
101 $this->db->dbType = $sugar_config['dbconfig']['db_type'];
103 if ( isset($this->reporter->all_fields) ) {
104 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
106 $field_def = array();
109 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
111 return parent::_get_column_select($layout_def);
114 // 'fields' are the two fields to concat to create the name
117 if ( ! empty($layout_def['table_alias']))
119 if ($this->db->dbType == 'mysql')
121 $alias .= "CONCAT(CONCAT(IFNULL("
122 .$layout_def['table_alias']."."
123 .$field_def['fields'][0].",''),' '),"
124 .$layout_def['table_alias']."."
125 .$field_def['fields'][1].")";
127 elseif ( $this->db->dbType == 'mssql' )
129 $alias .= $layout_def['table_alias'] . '.' . $field_def['fields'][0] . " + ' ' + "
130 . $layout_def['table_alias'] . '.' . $field_def['fields'][1]."";
133 elseif (! empty($layout_def['name']))
135 $alias = $layout_def['name'];
146 function _get_column_select($layout_def)
148 global $sugar_config;
149 global $locale, $current_user;
151 // if $this->db->dbytpe is empty, then grab dbtype value from global array "$sugar_config[dbconfig]"
152 if(empty($this->db->dbType)){
153 $this->db->dbType = $sugar_config['dbconfig']['db_type'];
155 if ( isset($this->reporter->all_fields) ) {
156 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
158 $field_def = array();
161 // 'fields' are the two fields to concat to create the name
164 if(!isset($field_def['fields']))
166 $alias = $this->_get_normal_column_select($layout_def);
169 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
170 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
173 $names['f'] = db_convert($layout_def['table_alias'].'.'.$field_def['fields'][0].",''","IFNULL");
174 $names['l'] = $layout_def['table_alias'].'.'.$field_def['fields'][1];
176 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
178 return parent::_get_column_select($layout_def);
181 if ( ! empty($layout_def['table_alias']))
183 if ($this->db->dbType == 'mysql')
185 for($i=0; $i<strlen($localeNameFormat); $i++) {
186 $alias .= array_key_exists($localeNameFormat{$i}, $names) ? $names[$localeNameFormat{$i}] : '\''.$localeNameFormat{$i}.'\'';
187 if($i<strlen($localeNameFormat)-1) $alias .= ',';
189 if(strlen($localeNameFormat)>1)
190 $alias = 'concat('.$alias.')';
193 elseif ( $this->db->dbType == 'mssql' )
195 for($i=0; $i<strlen($localeNameFormat); $i++) {
196 $alias .= array_key_exists($localeNameFormat{$i}, $names) ? $names[$localeNameFormat{$i}] : '\''.$localeNameFormat{$i}.'\'';
197 if($i<strlen($localeNameFormat)-1) $alias .= ' + ';
201 elseif (! empty($layout_def['name']))
203 $alias = $layout_def['name'];
214 function queryFilterIs($layout_def)
216 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
217 $layout_def['name'] = 'id';
218 $layout_def['type'] = 'id';
219 $input_name0 = $layout_def['input_name0'];
221 if ( is_array($layout_def['input_name0']))
223 $input_name0 = $layout_def['input_name0'][0];
225 if ($input_name0 == 'Current User') {
226 global $current_user;
227 $input_name0 = $current_user->id;
230 return SugarWidgetFieldid::_get_column_select($layout_def)."='"
231 .$GLOBALS['db']->quote($input_name0)."'\n";
234 function queryFilteris_not($layout_def)
236 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
237 $layout_def['name'] = 'id';
238 $layout_def['type'] = 'id';
239 $input_name0 = $layout_def['input_name0'];
241 if ( is_array($layout_def['input_name0']))
243 $input_name0 = $layout_def['input_name0'][0];
245 if ($input_name0 == 'Current User') {
246 global $current_user;
247 $input_name0 = $current_user->id;
250 return SugarWidgetFieldid::_get_column_select($layout_def)."<>'"
251 .$GLOBALS['db']->quote($input_name0)."'\n";
253 // $rename_columns, if true then you're coming from reports
254 function queryFilterone_of(&$layout_def, $rename_columns = true)
256 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
257 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
258 $layout_def['name'] = 'id';
259 $layout_def['type'] = 'id';
263 foreach($layout_def['input_name0'] as $value)
265 if ($value == 'Current User') {
266 global $current_user;
267 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
270 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
273 $str = implode(",",$arr);
275 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
277 // $rename_columns, if true then you're coming from reports
278 function queryFilternot_one_of(&$layout_def, $rename_columns = true)
280 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
281 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
282 $layout_def['name'] = 'id';
283 $layout_def['type'] = 'id';
287 foreach($layout_def['input_name0'] as $value)
289 if ($value == 'Current User') {
290 global $current_user;
291 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
294 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
297 $str = implode(",",$arr);
299 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
301 function &queryGroupBy($layout_def)
303 if( $this->reporter->db->dbType == 'mysql') {
304 if($layout_def['name'] == 'full_name') {
305 $layout_def['name'] = 'id';
306 $layout_def['type'] = 'id';
307 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
308 $group_by = SugarWidgetFieldid::_get_column_select($layout_def)."\n";
311 // group by clause for user name passes through here.
312 // $layout_def['name'] = 'name';
313 // $layout_def['type'] = 'name';
314 $group_by = $this->_get_column_select($layout_def)."\n";
317 elseif( $this->reporter->db->dbType == 'mssql') {
318 $group_by = $this->_get_column_select($layout_def);