]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetFieldname.php
Release 6.5.16
[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-2013 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
42
43 class SugarWidgetFieldName extends SugarWidgetFieldVarchar
44 {
45     protected static $moduleSavePermissions = array();
46
47     function SugarWidgetFieldName(&$layout_manager) {
48         parent::SugarWidgetFieldVarchar($layout_manager);
49         $this->reporter = $this->layout_manager->getAttribute('reporter');
50     }
51
52         function displayList(&$layout_def)
53         {
54                 if(empty($layout_def['column_key']))
55                 {
56                         return $this->displayListPlain($layout_def);
57                 }
58
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);
64
65                 if(empty($layout_def['fields'][$key]))
66                 {
67                   $layout_def['name'] = $name;
68                         return $this->displayListPlain($layout_def);
69                 }
70
71                 $record = $layout_def['fields'][$key];
72                 $layout_def['name'] = $name;
73                 global $current_user;
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);
78                 $str .= "</a>";
79
80
81         global $sugar_config;
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);
86             $str .= $value;
87             $field_name = $layout_def['name'];
88             $field_type = $field_def['type'];
89             $str .= "</a>";
90             if ($field_name == 'name')
91                 $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\");'");
92             $str .= "</div>";
93         }
94                 return $str;
95         }
96
97         function _get_normal_column_select($layout_def)
98         {
99         if ( isset($this->reporter->all_fields) ) {
100             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
101         } else {
102             $field_def = array();
103         }
104
105                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1]))
106                 {
107                         return parent::_get_column_select($layout_def);
108                 }
109
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'];
115                 } else {
116                         $alias = "*";
117                 }
118
119                 return $alias;
120         }
121
122         function _get_column_select($layout_def)
123         {
124                 global $locale, $current_user;
125
126         if ( isset($this->reporter->all_fields) ) {
127             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
128         } else {
129             $field_def = array();
130         }
131
132         //       'fields' are the two fields to concatenate to create the name
133         if(!isset($field_def['fields']))
134         {
135                         return $this->_get_normal_column_select($layout_def);
136         }
137                 $localeNameFormat = $locale->getLocaleFormatMacro($current_user);
138                 $localeNameFormat = trim(preg_replace('/s/i', '', $localeNameFormat));
139
140                 if (empty($field_def['fields']) || empty($field_def['fields'][0]) || empty($field_def['fields'][1])) {
141                         return parent::_get_column_select($layout_def);
142                 }
143
144                 if ( ! empty($layout_def['table_alias'])) {
145                     $comps = preg_split("/([fl])/", $localeNameFormat, null, PREG_SPLIT_DELIM_CAPTURE);
146                     $name = array();
147                     foreach($comps as $val) {
148                         if($val == 'f') {
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("''"));
152                         } else {
153                             if(!empty($val)) {
154                                 $name[] = $this->reporter->db->quoted($val);
155                             }
156                         }
157                     }
158                     $alias = $this->reporter->db->convert($name, "CONCAT");
159                 } elseif (! empty($layout_def['name'])) {
160                         $alias = $layout_def['name'];
161                 } else {
162                         $alias = "*";
163                 }
164
165                 return $alias;
166         }
167
168         function queryFilterIs($layout_def)
169         {
170
171                 $layout_def['name'] = 'id';
172                 $layout_def['type'] = 'id';
173                 $input_name0 = $layout_def['input_name0'];
174
175                 if ( is_array($layout_def['input_name0']))
176                 {
177                         $input_name0 = $layout_def['input_name0'][0];
178                 }
179                 if ($input_name0 == 'Current User') {
180                         global $current_user;
181                         $input_name0 = $current_user->id;
182                 }
183
184                 return SugarWidgetFieldid::_get_column_select($layout_def)."="
185                         .$this->reporter->db->quoted($input_name0)."\n";
186         }
187
188         function queryFilteris_not($layout_def)
189         {
190
191                 $layout_def['name'] = 'id';
192                 $layout_def['type'] = 'id';
193                 $input_name0 = $layout_def['input_name0'];
194
195                 if ( is_array($layout_def['input_name0']))
196                 {
197                         $input_name0 = $layout_def['input_name0'][0];
198                 }
199                 if ($input_name0 == 'Current User') {
200                         global $current_user;
201                         $input_name0 = $current_user->id;
202                 }
203
204                 return SugarWidgetFieldid::_get_column_select($layout_def)."<>"
205                         .$this->reporter->db->quoted($input_name0)."\n";
206         }
207
208     // $rename_columns, if true then you're coming from reports
209         function queryFilterone_of($layout_def, $rename_columns = true)
210         {
211
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';
215         }
216                 $arr = array();
217
218                 foreach($layout_def['input_name0'] as $value)
219                 {
220                         if ($value == 'Current User') {
221                                 global $current_user;
222                                 array_push($arr,$this->reporter->db->quoted($current_user->id));
223                         }
224                         else
225                                 array_push($arr,$this->reporter->db->quoted($value));
226                 }
227
228                 $str = implode(",",$arr);
229
230                 return SugarWidgetFieldid::_get_column_select($layout_def)." IN (".$str.")\n";
231         }
232     // $rename_columns, if true then you're coming from reports
233         function queryFilternot_one_of($layout_def, $rename_columns = true)
234         {
235
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';
239         }
240                 $arr = array();
241
242                 foreach($layout_def['input_name0'] as $value)
243                 {
244                         if ($value == 'Current User') {
245                                 global $current_user;
246                                 array_push($arr,$this->reporter->db->quoted($current_user->id));
247                         }
248                         else
249                                 array_push($arr,$this->reporter->db->quoted($value));
250                 }
251
252                 $str = implode(",",$arr);
253
254                 return SugarWidgetFieldid::_get_column_select($layout_def)." NOT IN (".$str.")\n";
255         }
256
257         function &queryGroupBy($layout_def)
258         {
259         if($layout_def['name'] == 'full_name') {
260              $layout_def['name'] = 'id';
261              $layout_def['type'] = 'id';
262
263              $group_by =  SugarWidgetFieldid::_get_column_select($layout_def)."\n";
264         } else {
265             // group by clause for user name passes through here.
266              $group_by = $this->_get_column_select($layout_def)."\n";
267         }
268         return $group_by;
269         }
270 }
271
272 ?>