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)
98 if ( isset($this->reporter->all_fields) ) {
99 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
101 $field_def = array();
104 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
106 return parent::_get_column_select($layout_def);
109 // 'fields' are the two fields to concat to create the name
110 if ( ! empty($layout_def['table_alias'])) {
111 $alias = $this->reporter->db->concat($layout_def['table_alias'], $field_def['fields']);
112 } elseif (! empty($layout_def['name'])) {
113 $alias = $layout_def['name'];
121 function _get_column_select($layout_def)
123 global $locale, $current_user;
125 if ( isset($this->reporter->all_fields) ) {
126 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
128 $field_def = array();
131 // 'fields' are the two fields to concat to create the name
132 if(!isset($field_def['fields']))
134 return $this->_get_normal_column_select($layout_def);
136 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
137 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
139 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1])) {
140 return parent::_get_column_select($layout_def);
143 if ( ! empty($layout_def['table_alias'])) {
144 $comps = preg_split("/([fl])/", $localeNameFormat, null, PREG_SPLIT_DELIM_CAPTURE);
146 foreach($comps as $val) {
148 $name[] = $this->reporter->db->convert($layout_def['table_alias'].".".$field_def['fields'][0], 'IFNULL', array("''"));
149 } elseif($val == 'l') {
150 $name[] = $this->reporter->db->convert($layout_def['table_alias'].".".$field_def['fields'][1], 'IFNULL', array("''"));
153 $name[] = $this->reporter->db->quoted($val);
157 $alias = $this->reporter->db->convert($name, "CONCAT");
158 } elseif (! empty($layout_def['name'])) {
159 $alias = $layout_def['name'];
167 function queryFilterIs($layout_def)
169 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
170 $layout_def['name'] = 'id';
171 $layout_def['type'] = 'id';
172 $input_name0 = $layout_def['input_name0'];
174 if ( is_array($layout_def['input_name0']))
176 $input_name0 = $layout_def['input_name0'][0];
178 if ($input_name0 == 'Current User') {
179 global $current_user;
180 $input_name0 = $current_user->id;
183 return SugarWidgetFieldid::_get_column_select($layout_def)."="
184 .$this->reporter->db->quoted($input_name0)."\n";
187 function queryFilteris_not($layout_def)
189 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
190 $layout_def['name'] = 'id';
191 $layout_def['type'] = 'id';
192 $input_name0 = $layout_def['input_name0'];
194 if ( is_array($layout_def['input_name0']))
196 $input_name0 = $layout_def['input_name0'][0];
198 if ($input_name0 == 'Current User') {
199 global $current_user;
200 $input_name0 = $current_user->id;
203 return SugarWidgetFieldid::_get_column_select($layout_def)."<>"
204 .$this->reporter->db->quoted($input_name0)."\n";
207 // $rename_columns, if true then you're coming from reports
208 function queryFilterone_of($layout_def, $rename_columns = true)
210 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
211 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
212 $layout_def['name'] = 'id';
213 $layout_def['type'] = 'id';
217 foreach($layout_def['input_name0'] as $value)
219 if ($value == 'Current User') {
220 global $current_user;
221 array_push($arr,$this->reporter->db->quoted($current_user->id));
224 array_push($arr,$this->reporter->db->quoted($value));
227 $str = implode(",",$arr);
229 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
231 // $rename_columns, if true then you're coming from reports
232 function queryFilternot_one_of($layout_def, $rename_columns = true)
234 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
235 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
236 $layout_def['name'] = 'id';
237 $layout_def['type'] = 'id';
241 foreach($layout_def['input_name0'] as $value)
243 if ($value == 'Current User') {
244 global $current_user;
245 array_push($arr,$this->reporter->db->quoted($current_user->id));
248 array_push($arr,$this->reporter->db->quoted($value));
251 $str = implode(",",$arr);
253 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
256 function &queryGroupBy($layout_def)
258 if($layout_def['name'] == 'full_name') {
259 $layout_def['name'] = 'id';
260 $layout_def['type'] = 'id';
261 require_once('include/generic/SugarWidgets/SugarWidgetFieldid.php');
262 $group_by = SugarWidgetFieldid::_get_column_select($layout_def)."\n";
264 // group by clause for user name passes through here.
265 $group_by = $this->_get_column_select($layout_def)."\n";