]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetFieldname.php
Release 6.4.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         if ( isset($this->reporter->all_fields) ) {
99             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
100         } else {
101             $field_def = array();
102         }
103
104                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
105                 {
106                         return parent::_get_column_select($layout_def);
107                 }
108
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'];
114                 } else {
115                         $alias = "*";
116                 }
117
118                 return $alias;
119         }
120
121         function _get_column_select($layout_def)
122         {
123                 global $locale, $current_user;
124
125         if ( isset($this->reporter->all_fields) ) {
126             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
127         } else {
128             $field_def = array();
129         }
130
131         //       'fields' are the two fields to concat to create the name
132         if(!isset($field_def['fields']))
133         {
134                         return $this->_get_normal_column_select($layout_def);
135         }
136                 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
137                 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
138
139                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1])) {
140                         return parent::_get_column_select($layout_def);
141                 }
142
143                 if ( ! empty($layout_def['table_alias'])) {
144                     $comps = preg_split("/([fl])/", $localeNameFormat, null, PREG_SPLIT_DELIM_CAPTURE);
145                     $name = array();
146                     foreach($comps as $val) {
147                         if($val == 'f') {
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("''"));
151                         } else {
152                             if(!empty($val)) {
153                                 $name[] = $this->reporter->db->quoted($val);
154                             }
155                         }
156                     }
157                     $alias = $this->reporter->db->convert($name, "CONCAT");
158                 } elseif (! empty($layout_def['name'])) {
159                         $alias = $layout_def['name'];
160                 } else {
161                         $alias = "*";
162                 }
163
164                 return $alias;
165         }
166
167         function queryFilterIs($layout_def)
168         {
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'];
173
174                 if ( is_array($layout_def['input_name0']))
175                 {
176                         $input_name0 = $layout_def['input_name0'][0];
177                 }
178                 if ($input_name0 == 'Current User') {
179                         global $current_user;
180                         $input_name0 = $current_user->id;
181                 }
182
183                 return SugarWidgetFieldid::_get_column_select($layout_def)."="
184                         .$this->reporter->db->quoted($input_name0)."\n";
185         }
186
187         function queryFilteris_not($layout_def)
188         {
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'];
193
194                 if ( is_array($layout_def['input_name0']))
195                 {
196                         $input_name0 = $layout_def['input_name0'][0];
197                 }
198                 if ($input_name0 == 'Current User') {
199                         global $current_user;
200                         $input_name0 = $current_user->id;
201                 }
202
203                 return SugarWidgetFieldid::_get_column_select($layout_def)."<>"
204                         .$this->reporter->db->quoted($input_name0)."\n";
205         }
206
207     // $rename_columns, if true then you're coming from reports
208         function queryFilterone_of($layout_def, $rename_columns = true)
209         {
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';
214         }
215                 $arr = array();
216
217                 foreach($layout_def['input_name0'] as $value)
218                 {
219                         if ($value == 'Current User') {
220                                 global $current_user;
221                                 array_push($arr,$this->reporter->db->quoted($current_user->id));
222                         }
223                         else
224                                 array_push($arr,$this->reporter->db->quoted($value));
225                 }
226
227                 $str = implode(",",$arr);
228
229                 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
230         }
231     // $rename_columns, if true then you're coming from reports
232         function queryFilternot_one_of($layout_def, $rename_columns = true)
233         {
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';
238         }
239                 $arr = array();
240
241                 foreach($layout_def['input_name0'] as $value)
242                 {
243                         if ($value == 'Current User') {
244                                 global $current_user;
245                                 array_push($arr,$this->reporter->db->quoted($current_user->id));
246                         }
247                         else
248                                 array_push($arr,$this->reporter->db->quoted($value));
249                 }
250
251                 $str = implode(",",$arr);
252
253                 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
254         }
255
256         function &queryGroupBy($layout_def)
257         {
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";
263         } else {
264             // group by clause for user name passes through here.
265              $group_by = $this->_get_column_select($layout_def)."\n";
266         }
267         return $group_by;
268         }
269 }
270
271 ?>