]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetField.php
Release 6.4.0
[Github/sugarcrm.git] / include / generic / SugarWidgets / SugarWidgetField.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry)
3         die('Not A Valid Entry Point');
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7  * 
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Affero General Public License version 3 as published by the
10  * Free Software Foundation with the addition of the following permission added
11  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14  * 
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18  * details.
19  * 
20  * You should have received a copy of the GNU Affero General Public License along with
21  * this program; if not, see http://www.gnu.org/licenses or write to the Free
22  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA.
24  * 
25  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27  * 
28  * The interactive user interfaces in modified source and object code versions
29  * of this program must display Appropriate Legal Notices, as required under
30  * Section 5 of the GNU Affero General Public License version 3.
31  * 
32  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33  * these Appropriate Legal Notices must retain the display of the "Powered by
34  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35  * technical reasons, the Appropriate Legal Notices must display the words
36  * "Powered by SugarCRM".
37  ********************************************************************************/
38
39
40
41
42 require_once ('include/generic/SugarWidgets/SugarWidget.php');
43
44 class SugarWidgetField extends SugarWidget {
45
46         function SugarWidgetField(&$layout_manager) {
47         parent::SugarWidget($layout_manager);
48     }
49
50         function display($layout_def) {
51                 //print $layout_def['start_link_wrapper']."===";
52                 $context = $this->layout_manager->getAttribute('context'); //_ppd($context);
53                 $func_name = 'display'.$context;
54
55                 if (!empty ($context) && method_exists($this, $func_name)) {
56                         return $this-> $func_name ($layout_def);
57                 } else {
58                         return 'display not found:'.$func_name;
59                 }
60         }
61
62         function _get_column_alias($layout_def) {
63                 $alias_arr = array ();
64
65                 if (!empty ($layout_def['name']) && $layout_def['name'] == 'count') {
66                         return 'count';
67                 }
68
69                 if (!empty ($layout_def['table_alias'])) {
70                         array_push($alias_arr, $layout_def['table_alias']);
71                 }
72
73                 if (!empty ($layout_def['name'])) {
74                         array_push($alias_arr, $layout_def['name']);
75                 }
76
77                 return $this->getTruncatedColumnAlias(implode("_", $alias_arr));
78         }
79
80         function & displayDetailLabel(& $layout_def) {
81
82                 return '';
83         }
84
85         function & displayDetail($layout_def) {
86
87                 return '';
88         }
89         
90         function displayHeaderCellPlain($layout_def) 
91         {
92                 if (!empty ($layout_def['label'])) {
93                         return $layout_def['label'];
94                 }
95                 if (!empty ($layout_def['vname'])) {
96                         return translate($layout_def['vname'], $this->layout_manager->getAttribute('module_name'));
97                 }
98                 return '';
99         }
100
101         function displayHeaderCell($layout_def) {
102                 $module_name = $this->layout_manager->getAttribute('module_name');
103
104                 $this->local_current_module = $_REQUEST['module'];
105                 $this->is_dynamic = true;
106                 // don't show sort links if name isn't defined
107                 if ((empty ($layout_def['name']) || (isset ($layout_def['sortable']) && !$layout_def['sortable']))
108         && !empty ($layout_def['label'])) {
109                         return $layout_def['label'];
110                 }
111                 if (isset ($layout_def['sortable']) && !$layout_def['sortable']) {
112                         return $this->displayHeaderCellPlain($layout_def);
113                 }
114
115                 $header_cell_text = $this->displayHeaderCellPlain($layout_def);
116
117                 $subpanel_module = $layout_def['subpanel_module'];
118                 $html_var = $subpanel_module . "_CELL";
119                 if (empty ($this->base_URL)) {
120                         $this->base_URL = ListView :: getBaseURL($html_var);
121                         $split_url = explode('&to_pdf=true&action=SubPanelViewer&subpanel=', $this->base_URL);
122                         $this->base_URL = $split_url[0];
123                         $this->base_URL .= '&inline=true&to_pdf=true&action=SubPanelViewer&subpanel=';
124                 }
125                 $sort_by_name = $layout_def['name'];
126                 if (isset ($layout_def['sort_by'])) {
127                         $sort_by_name = $layout_def['sort_by'];
128                 }
129
130                 $sort_by = ListView :: getSessionVariableName($html_var, "ORDER_BY").'='.$sort_by_name;
131
132                 $start = (empty ($layout_def['start_link_wrapper'])) ? '' : $layout_def['start_link_wrapper'];
133                 $end = (empty ($layout_def['end_link_wrapper'])) ? '' : $layout_def['end_link_wrapper'];
134
135                 $header_cell = "<a class=\"listViewThLinkS1\" href=\"".$start.$this->base_URL.$subpanel_module.'&'.$sort_by.$end."\">";
136                 $header_cell .= $header_cell_text;
137
138                 $imgArrow = '';
139
140                 if (isset ($layout_def['sort'])) {
141                         $imgArrow = $layout_def['sort'];
142                 }
143
144                 $arrow_start = ListView::getArrowUpDownStart($imgArrow);
145                 $arrow_end = ListView::getArrowUpDownEnd($imgArrow);
146                 $header_cell .= " ".$arrow_start.$arrow_end."</a>";
147
148                 return $header_cell;
149
150         }
151
152         function displayList($layout_def) {
153                 return $this->displayListPlain($layout_def);
154         }
155
156         function displayListPlain($layout_def) {
157                 $value= $this->_get_list_value($layout_def);
158                 if (isset($layout_def['widget_type']) && $layout_def['widget_type'] =='checkbox') {
159                         if ($value != '' &&  ($value == 'on' || intval($value) == 1 || $value == 'yes'))
160                         {
161                                 return "<input name='checkbox_display' class='checkbox' type='checkbox' disabled='true' checked>";
162                         }
163                         return "<input name='checkbox_display' class='checkbox' type='checkbox' disabled='true'>";
164                 }
165                 return $value;
166         }
167
168         function _get_list_value(& $layout_def) 
169         {
170                 $key = '';
171                 if ( isset($layout_def['varname']) ) {
172                     $key = strtoupper($layout_def['varname']);
173                 } 
174                 else {
175                         $key = strtoupper($this->_get_column_alias($layout_def));
176                 }
177
178                 if ( isset($layout_def['fields'][$key]) ) {
179                         return $layout_def['fields'][$key];
180                 }
181                 
182                 return '';
183         }
184
185         function & displayEditLabel($layout_def) {
186                 return '';
187         }
188
189         function & displayEdit($layout_def) {
190                 return '';
191         }
192
193         function & displaySearchLabel($layout_def) {
194                 return '';
195         }
196
197         function & displaySearch($layout_def) {
198                 return '';
199         }
200
201         function displayInput($layout_def) {
202                 return ' -- Not Implemented --';
203         }
204
205     function getVardef($layout_def) {
206         $myName = $layout_def['column_key'];
207         $vardef = $this->layout_manager->defs['reporter']->all_fields[$myName];
208
209         if ( !isset($vardef) ) {
210             // No vardef, return an empty array
211             return array();
212         } else {
213             return $vardef;
214         }
215     }
216 }