]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetFieldname.php
Release 6.3.0
[Github/sugarcrm.git] / include / generic / SugarWidgets / SugarWidgetFieldname.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38
39
40
41 require_once('include/generic/SugarWidgets/SugarWidgetFieldvarchar.php');
42
43 class SugarWidgetFieldName extends SugarWidgetFieldVarchar
44 {
45
46     function SugarWidgetFieldName(&$layout_manager) {
47         parent::SugarWidgetFieldVarchar($layout_manager);
48         $this->reporter = $this->layout_manager->getAttribute('reporter');
49     }
50
51         function displayList(&$layout_def)
52         {
53                 if(empty($layout_def['column_key']))
54                 {
55                         return $this->displayListPlain($layout_def);
56                 }
57
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);
63
64                 if(empty($layout_def['fields'][$key]))
65                 {
66                   $layout_def['name'] = $name;
67                         return $this->displayListPlain($layout_def);
68                 }
69
70                 $record = $layout_def['fields'][$key];
71                 $layout_def['name'] = $name;
72                 global $current_user;
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);
77                 $str .= "</a>";
78
79
80         global $sugar_config;
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);
85             $str .= $value;
86             $field_name = $layout_def['name'];
87             $field_type = $field_def['type'];
88             $str .= "</a>";
89             if ($field_name == 'name')
90                 $str .= "&nbsp;" .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\");'");
91             $str .= "</div>";
92         }
93                 return $str;
94         }
95
96         function _get_normal_column_select($layout_def)
97         {
98                 global $sugar_config;
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'];
102                 }
103         if ( isset($this->reporter->all_fields) ) {
104             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
105         } else {
106             $field_def = array();
107         }
108
109                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
110                 {
111                         return parent::_get_column_select($layout_def);
112                 }
113
114                 //       'fields' are the two fields to concat to create the name
115                 $alias = '';
116                 $endalias = '';
117                 if ( ! empty($layout_def['table_alias']))
118                 {
119                         if ($this->db->dbType == 'mysql')
120                         {
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].")";
126                         }
127                         elseif ( $this->db->dbType == 'mssql' )
128                         {
129                                 $alias .= $layout_def['table_alias'] . '.' . $field_def['fields'][0] . " + ' ' + "
130                                 . $layout_def['table_alias'] . '.' . $field_def['fields'][1]."";
131                         }
132                 }
133                 elseif (! empty($layout_def['name']))
134                 {
135                         $alias = $layout_def['name'];
136                 }
137                 else
138                 {
139                         $alias .= "*";
140                 }
141
142                 $alias .= $endalias;
143                 return $alias;
144         }
145
146         function _get_column_select($layout_def)
147         {
148                 global $sugar_config;
149                 global $locale, $current_user;
150
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'];
154                 }
155         if ( isset($this->reporter->all_fields) ) {
156             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
157         } else {
158             $field_def = array();
159         }
160
161         //       'fields' are the two fields to concat to create the name
162                 $alias = '';
163                 $endalias = '';
164         if(!isset($field_def['fields']))
165         {
166                         $alias = $this->_get_normal_column_select($layout_def);
167                         return $alias;
168         }
169                 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
170                 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
171
172                 $names = array();
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];
175
176                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
177                 {
178                         return parent::_get_column_select($layout_def);
179                 }
180
181                 if ( ! empty($layout_def['table_alias']))
182                 {
183                         if ($this->db->dbType == 'mysql')
184                         {
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 .= ',';
188                                 }
189                                 if(strlen($localeNameFormat)>1)
190                                 $alias = 'concat('.$alias.')';
191
192                         }
193                         elseif ( $this->db->dbType == 'mssql' )
194                         {
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 .= ' + ';
198                                 }
199                         }
200                 }
201                 elseif (! empty($layout_def['name']))
202                 {
203                         $alias = $layout_def['name'];
204                 }
205                 else
206                 {
207                         $alias .= "*";
208                 }
209
210                 $alias .= $endalias;
211                 return $alias;
212         }
213
214         function queryFilterIs($layout_def)
215         {
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'];
220
221                 if ( is_array($layout_def['input_name0']))
222                 {
223                         $input_name0 = $layout_def['input_name0'][0];
224                 }
225                 if ($input_name0 == 'Current User') {
226                         global $current_user;
227                         $input_name0 = $current_user->id;
228                 }
229
230                 return SugarWidgetFieldid::_get_column_select($layout_def)."='"
231                         .$GLOBALS['db']->quote($input_name0)."'\n";
232         }
233
234         function queryFilteris_not($layout_def)
235         {
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'];
240
241                 if ( is_array($layout_def['input_name0']))
242                 {
243                         $input_name0 = $layout_def['input_name0'][0];
244                 }
245                 if ($input_name0 == 'Current User') {
246                         global $current_user;
247                         $input_name0 = $current_user->id;
248                 }
249
250                 return SugarWidgetFieldid::_get_column_select($layout_def)."<>'"
251                         .$GLOBALS['db']->quote($input_name0)."'\n";
252         }
253     // $rename_columns, if true then you're coming from reports
254         function queryFilterone_of(&$layout_def, $rename_columns = true)
255         {
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';
260         }
261                 $arr = array();
262
263                 foreach($layout_def['input_name0'] as $value)
264                 {
265                         if ($value == 'Current User') {
266                                 global $current_user;
267                                 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
268                         }
269                         else
270                                 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
271                 }
272
273                 $str = implode(",",$arr);
274
275                 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
276         }
277     // $rename_columns, if true then you're coming from reports
278         function queryFilternot_one_of(&$layout_def, $rename_columns = true)
279         {
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';
284         }
285                 $arr = array();
286
287                 foreach($layout_def['input_name0'] as $value)
288                 {
289                         if ($value == 'Current User') {
290                                 global $current_user;
291                                 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
292                         }
293                         else
294                                 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
295                 }
296
297                 $str = implode(",",$arr);
298
299                 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
300         }
301         function &queryGroupBy($layout_def)
302         {
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";
309          }
310          else {
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";
315          }
316         }
317                 elseif( $this->reporter->db->dbType == 'mssql') {
318                         $group_by = $this->_get_column_select($layout_def);
319                 }
320
321         return $group_by;
322         }
323 }
324
325 ?>