]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetFieldname.php
Release 6.2.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                 return $str;
79         }
80
81         function _get_normal_column_select($layout_def)
82         {
83                 global $sugar_config;
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'];
87                 }
88         if ( isset($this->reporter->all_fields) ) {
89             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
90         } else {
91             $field_def = array();
92         }
93                 
94                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
95                 {
96                         return parent::_get_column_select($layout_def);
97                 }
98                 
99                 //       'fields' are the two fields to concat to create the name
100                 $alias = '';
101                 $endalias = '';
102                 if ( ! empty($layout_def['table_alias']))
103                 {
104                         if ($this->db->dbType == 'mysql')
105                         {
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].")";
111                         }
112                         elseif ( $this->db->dbType == 'mssql' )
113                         {
114                                 $alias .= $layout_def['table_alias'] . '.' . $field_def['fields'][0] . " + ' ' + "
115                                 . $layout_def['table_alias'] . '.' . $field_def['fields'][1]."";
116                         }
117                 }
118                 elseif (! empty($layout_def['name']))
119                 {
120                         $alias = $layout_def['name'];
121                 }
122                 else
123                 {
124                         $alias .= "*";
125                 }
126                 
127                 $alias .= $endalias;
128                 return $alias;
129         }
130
131         function _get_column_select($layout_def)
132         {
133                 global $sugar_config;
134                 global $locale, $current_user;
135                         
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'];
139                 }
140         if ( isset($this->reporter->all_fields) ) {
141             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
142         } else {
143             $field_def = array();
144         }
145                 
146         //       'fields' are the two fields to concat to create the name
147                 $alias = '';
148                 $endalias = '';
149         if(!isset($field_def['fields']))
150         {
151                         $alias = $this->_get_normal_column_select($layout_def);
152                         return $alias;
153         }
154                 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
155                 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
156
157                 $names = array();
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];
160                 
161                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
162                 {
163                         return parent::_get_column_select($layout_def);
164                 }               
165                 
166                 if ( ! empty($layout_def['table_alias']))
167                 {
168                         if ($this->db->dbType == 'mysql')
169                         {               
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 .= ',';
173                                 }
174                                 if(strlen($localeNameFormat)>1)
175                                 $alias = 'concat('.$alias.')';
176
177                         }
178                         elseif ( $this->db->dbType == 'mssql' )
179                         {
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 .= ' + ';
183                                 }
184                         }
185                 }
186                 elseif (! empty($layout_def['name']))
187                 {
188                         $alias = $layout_def['name'];
189                 }
190                 else
191                 {
192                         $alias .= "*";
193                 }
194                 
195                 $alias .= $endalias;
196                 return $alias;
197         }
198
199         function queryFilterIs($layout_def)
200         {
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'];
205                 
206                 if ( is_array($layout_def['input_name0']))
207                 {
208                         $input_name0 = $layout_def['input_name0'][0];
209                 }
210                 if ($input_name0 == 'Current User') {
211                         global $current_user;
212                         $input_name0 = $current_user->id;
213                 }
214
215                 return SugarWidgetFieldid::_get_column_select($layout_def)."='"
216                         .$GLOBALS['db']->quote($input_name0)."'\n";
217         }
218
219         function queryFilteris_not($layout_def)
220         {
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'];
225                 
226                 if ( is_array($layout_def['input_name0']))
227                 {
228                         $input_name0 = $layout_def['input_name0'][0];
229                 }
230                 if ($input_name0 == 'Current User') {
231                         global $current_user;
232                         $input_name0 = $current_user->id;
233                 }
234
235                 return SugarWidgetFieldid::_get_column_select($layout_def)."<>'"
236                         .$GLOBALS['db']->quote($input_name0)."'\n";
237         }
238     // $rename_columns, if true then you're coming from reports
239         function queryFilterone_of(&$layout_def, $rename_columns = true)
240         {
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';
245         }
246                 $arr = array();
247                 
248                 foreach($layout_def['input_name0'] as $value)
249                 {
250                         if ($value == 'Current User') {
251                                 global $current_user;
252                                 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
253                         }
254                         else
255                                 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
256                 }
257                 
258                 $str = implode(",",$arr);
259         
260                 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
261         }
262     // $rename_columns, if true then you're coming from reports
263         function queryFilternot_one_of(&$layout_def, $rename_columns = true)
264         {
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';
269         }
270                 $arr = array();
271
272                 foreach($layout_def['input_name0'] as $value)
273                 {
274                         if ($value == 'Current User') {
275                                 global $current_user;
276                                 array_push($arr,"'".$GLOBALS['db']->quote($current_user->id)."'");
277                         }
278                         else
279                                 array_push($arr,"'".$GLOBALS['db']->quote($value)."'");
280                 }
281
282                 $str = implode(",",$arr);
283
284                 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
285         }
286         function &queryGroupBy($layout_def)
287         {
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";
294          }
295          else {
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";
300          }
301         }
302                 elseif( $this->reporter->db->dbType == 'mssql') {
303                         $group_by = $this->_get_column_select($layout_def);
304                 }
305         
306         return $group_by;
307         }
308 }
309
310 ?>