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-2013 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 ********************************************************************************/
43 class SugarWidgetFieldName extends SugarWidgetFieldVarchar
45 protected static $moduleSavePermissions = array();
47 function SugarWidgetFieldName(&$layout_manager) {
48 parent::SugarWidgetFieldVarchar($layout_manager);
49 $this->reporter = $this->layout_manager->getAttribute('reporter');
52 function displayList(&$layout_def)
54 if(empty($layout_def['column_key']))
56 return $this->displayListPlain($layout_def);
59 $module = $this->reporter->all_fields[$layout_def['column_key']]['module'];
60 $name = $layout_def['name'];
61 $layout_def['name'] = 'id';
62 $key = $this->_get_column_alias($layout_def);
63 $key = strtoupper($key);
65 if(empty($layout_def['fields'][$key]))
67 $layout_def['name'] = $name;
68 return $this->displayListPlain($layout_def);
71 $record = $layout_def['fields'][$key];
72 $layout_def['name'] = $name;
74 if ($module == 'Users' && !is_admin($current_user))
75 $module = 'Employees';
76 $str = "<a target='_blank' href=\"index.php?action=DetailView&module=$module&record=$record\">";
77 $str .= $this->displayListPlain($layout_def);
82 if (isset ($sugar_config['enable_inline_reports_edit']) && $sugar_config['enable_inline_reports_edit'] && !empty($record)) {
83 $div_id = "$module&$record&$name";
84 $str = "<div id='$div_id'><a target='_blank' href=\"index.php?action=DetailView&module=$module&record=$record\">";
85 $value = $this->displayListPlain($layout_def);
87 $field_name = $layout_def['name'];
88 $field_type = $field_def['type'];
90 if ($field_name == 'name')
91 $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\");'");
97 function _get_normal_column_select($layout_def)
99 if ( isset($this->reporter->all_fields) ) {
100 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
102 $field_def = array();
105 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
107 return parent::_get_column_select($layout_def);
110 // 'fields' are the two fields to concatenate to create the name.
111 if ( ! empty($layout_def['table_alias'])) {
112 $alias = $this->reporter->db->concat($layout_def['table_alias'], $field_def['fields']);
113 } elseif (! empty($layout_def['name'])) {
114 $alias = $layout_def['name'];
122 function _get_column_select($layout_def)
124 global $locale, $current_user;
126 if ( isset($this->reporter->all_fields) ) {
127 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
129 $field_def = array();
132 // 'fields' are the two fields to concatenate to create the name
133 if(!isset($field_def['fields']))
135 return $this->_get_normal_column_select($layout_def);
137 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
138 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
140 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1])) {
141 return parent::_get_column_select($layout_def);
144 if ( ! empty($layout_def['table_alias'])) {
145 $comps = preg_split("/([fl])/", $localeNameFormat, null, PREG_SPLIT_DELIM_CAPTURE);
147 foreach($comps as $val) {
149 $name[] = $this->reporter->db->convert($layout_def['table_alias'].".".$field_def['fields'][0], 'IFNULL', array("''"));
150 } elseif($val == 'l') {
151 $name[] = $this->reporter->db->convert($layout_def['table_alias'].".".$field_def['fields'][1], 'IFNULL', array("''"));
154 $name[] = $this->reporter->db->quoted($val);
158 $alias = $this->reporter->db->convert($name, "CONCAT");
159 } elseif (! empty($layout_def['name'])) {
160 $alias = $layout_def['name'];
168 function queryFilterIs($layout_def)
171 $layout_def['name'] = 'id';
172 $layout_def['type'] = 'id';
173 $input_name0 = $layout_def['input_name0'];
175 if ( is_array($layout_def['input_name0']))
177 $input_name0 = $layout_def['input_name0'][0];
179 if ($input_name0 == 'Current User') {
180 global $current_user;
181 $input_name0 = $current_user->id;
184 return SugarWidgetFieldid::_get_column_select($layout_def)."="
185 .$this->reporter->db->quoted($input_name0)."\n";
188 function queryFilteris_not($layout_def)
191 $layout_def['name'] = 'id';
192 $layout_def['type'] = 'id';
193 $input_name0 = $layout_def['input_name0'];
195 if ( is_array($layout_def['input_name0']))
197 $input_name0 = $layout_def['input_name0'][0];
199 if ($input_name0 == 'Current User') {
200 global $current_user;
201 $input_name0 = $current_user->id;
204 return SugarWidgetFieldid::_get_column_select($layout_def)."<>"
205 .$this->reporter->db->quoted($input_name0)."\n";
208 // $rename_columns, if true then you're coming from reports
209 function queryFilterone_of($layout_def, $rename_columns = true)
212 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
213 $layout_def['name'] = 'id';
214 $layout_def['type'] = 'id';
218 foreach($layout_def['input_name0'] as $value)
220 if ($value == 'Current User') {
221 global $current_user;
222 array_push($arr,$this->reporter->db->quoted($current_user->id));
225 array_push($arr,$this->reporter->db->quoted($value));
228 $str = implode(",",$arr);
230 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
232 // $rename_columns, if true then you're coming from reports
233 function queryFilternot_one_of($layout_def, $rename_columns = true)
236 if($rename_columns) { // this was a hack to get reports working, sugarwidgets should not be renaming $name!
237 $layout_def['name'] = 'id';
238 $layout_def['type'] = 'id';
242 foreach($layout_def['input_name0'] as $value)
244 if ($value == 'Current User') {
245 global $current_user;
246 array_push($arr,$this->reporter->db->quoted($current_user->id));
249 array_push($arr,$this->reporter->db->quoted($value));
252 $str = implode(",",$arr);
254 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
257 function &queryGroupBy($layout_def)
259 if($layout_def['name'] == 'full_name') {
260 $layout_def['name'] = 'id';
261 $layout_def['type'] = 'id';
263 $group_by = SugarWidgetFieldid::_get_column_select($layout_def)."\n";
265 // group by clause for user name passes through here.
266 $group_by = $this->_get_column_select($layout_def)."\n";