]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetFieldenum.php
Release 6.4.0beta3
[Github/sugarcrm.git] / include / generic / SugarWidgets / SugarWidgetFieldenum.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 class SugarWidgetFieldEnum extends SugarWidgetReportField
40 {
41     public function SugarWidgetFieldEnum($layout_manager) {
42         parent::SugarWidgetReportField($layout_manager);
43     }
44
45         public function queryFilterEmpty($layout_def)
46         {
47             $column = $this->_get_column_select($layout_def);
48             return "($column IS NULL OR $column LIKE '' OR $column = '^^')";
49         }
50
51     public function queryFilterNot_Empty($layout_def)
52         {
53             $reporter = $this->layout_manager->getAttribute("reporter");
54         if( $this->reporter->db->dbType == 'mysql') {
55                         return '( '.$this->_get_column_select($layout_def).' IS NOT NULL'.
56                                 ' AND '.$this->_get_column_select($layout_def)." <> ''".
57                                 ' AND '.$this->_get_column_select($layout_def)." != '^^' )\n";
58         } else {
59                         return '( '.$this->_get_column_select($layout_def).' IS NOT NULL'.
60                                 ' AND '.$this->_get_column_select($layout_def)." != '^^' )\n";
61         }
62         }
63
64         public function queryFilteris($layout_def) {
65                 $input_name0 = $layout_def['input_name0'];
66                 if (is_array($layout_def['input_name0'])) {
67                         $input_name0 = $layout_def['input_name0'][0];
68                 }
69                 return $this->_get_column_select($layout_def)." = ".$this->reporter->db->quoted($input_name0)."\n";
70         }
71
72         public function queryFilteris_not($layout_def) {
73                 $input_name0 = $layout_def['input_name0'];
74                 if (is_array($layout_def['input_name0'])) {
75                         $input_name0 = $layout_def['input_name0'][0];
76                 }
77                 return $this->_get_column_select($layout_def)." <> ".$this->reporter->db->quoted($input_name0)."\n";
78         }
79
80         public function queryFilterone_of($layout_def) {
81                 $arr = array ();
82                 foreach ($layout_def['input_name0'] as $value) {
83                         $arr[] = $this->reporter->db->quoted($value);
84                 }
85                 $str = implode(",", $arr);
86                 return $this->_get_column_select($layout_def)." IN (".$str.")\n";
87         }
88
89         public function queryFilternot_one_of($layout_def) {
90                 $arr = array ();
91                 foreach ($layout_def['input_name0'] as $value) {
92                         $arr[] = $this->reporter->db->quoted($value);
93                 }
94             $reporter = $this->layout_manager->getAttribute("reporter");
95                 $str = implode(",", $arr);
96                 return $this->_get_column_select($layout_def)." NOT IN (".$str.")\n";
97         }
98
99     function & displayList($layout_def) {
100         if(!empty($layout_def['column_key'])){
101             $field_def = $this->reporter->all_fields[$layout_def['column_key']];
102         }else if(!empty($layout_def['fields'])){
103             $field_def = $layout_def['fields'];
104         }
105         $cell = $this->displayListPlain($layout_def);
106         $str = $cell;
107         global $sugar_config;
108         if (isset ($sugar_config['enable_inline_reports_edit']) && $sugar_config['enable_inline_reports_edit']) {
109             $module = $this->reporter->all_fields[$layout_def['column_key']]['module'];
110             $name = $layout_def['name'];
111             $layout_def['name'] = 'id';
112             $key = $this->_get_column_alias($layout_def);
113             $key = strtoupper($key);
114
115             //If the key isn't in the layout fields, skip it
116             if (!empty($layout_def['fields'][$key]))
117             {
118                 $record = $layout_def['fields'][$key];
119                 $field_name = $field_def['name'];
120                 $field_type = $field_def['type'];
121                 $div_id = $field_def['module'] ."&$record&$field_name";
122                 $str = "<div id='$div_id'>" . $cell . "&nbsp;"
123                      . SugarThemeRegistry::current()->getImage(
124                         "edit_inline",
125                         "border='0' alt='Edit Layout' align='bottom' onClick='SUGAR.reportsInlineEdit.inlineEdit(" .
126                         "\"$div_id\",\"$cell\",\"$module\",\"$record\",\"$field_name\",\"$field_type\");'"
127                        ) 
128                      . "</div>";
129             }
130         }
131         return $str;
132     }
133         function & displayListPlain($layout_def) {
134                 if(!empty($layout_def['column_key'])){
135                         $field_def = $this->reporter->all_fields[$layout_def['column_key']];
136                 }else if(!empty($layout_def['fields'])){
137                         $field_def = $layout_def['fields'];
138                 }
139
140                 if (!empty($layout_def['table_key'] ) &&( empty ($field_def['fields']) || empty ($field_def['fields'][0]) || empty ($field_def['fields'][1]))){
141                         $value = $this->_get_list_value($layout_def);
142                 }else if(!empty($layout_def['name']) && !empty($layout_def['fields'])){
143                         $key = strtoupper($layout_def['name']);
144                         $value = $layout_def['fields'][$key];
145                 }
146                 $cell = '';
147
148                         if(isset($field_def['options'])){
149                                 $cell = translate($field_def['options'], $field_def['module'], $value);
150                         }else if(isset($field_def['type']) && $field_def['type'] == 'enum' && isset($field_def['function'])){
151                     global $beanFiles;
152                     if(empty($beanFiles)) {
153                         include('include/modules.php');
154                     }
155                     $bean_name = get_singular_bean_name($field_def['module']);
156                     require_once($beanFiles[$bean_name]);
157                     $list = $field_def['function']();
158                     $cell = $list[$value];
159                 }
160                 if (is_array($cell)) {
161
162                         //#22632
163                         $value = unencodeMultienum($value);
164                         $cell=array();
165                         foreach($value as $val){
166                                 $returnVal = translate($field_def['options'],$field_def['module'],$val);
167                                 if(!is_array($returnVal)){
168                                         array_push( $cell, translate($field_def['options'],$field_def['module'],$val));
169                                 }
170                         }
171                         $cell = implode(", ",$cell);
172                 }
173                 return $cell;
174         }
175
176         public function queryOrderBy($layout_def) {
177                 $field_def = $this->reporter->all_fields[$layout_def['column_key']];
178                 if (!empty ($field_def['sort_on'])) {
179                         $order_by = $layout_def['table_alias'].".".$field_def['sort_on'];
180                 } else {
181                         $order_by = $this->_get_column_select($layout_def);
182                 }
183                 $list = array();
184         if(isset($field_def['options'])) {
185                     $list = translate($field_def['options'], $field_def['module']);
186         } elseif(isset($field_def['type']) && $field_def['type'] == 'enum' && isset($field_def['function'])) {
187                 global $beanFiles;
188                     if(empty($beanFiles)) {
189                         include('include/modules.php');
190                     }
191                     $bean_name = get_singular_bean_name($field_def['module']);
192                     require_once($beanFiles[$bean_name]);
193             $list = $field_def['function']();
194         }
195                 if (empty ($layout_def['sort_dir']) || $layout_def['sort_dir'] == 'a') {
196                         $order_dir = "ASC";
197                 } else {
198                         $order_dir = "DESC";
199                 }
200                 return $this->reporter->db->orderByEnum($order_by, $list, $order_dir);
201     }
202
203     public function displayInput($layout_def) {
204         global $app_list_strings;
205
206         if(!empty($layout_def['remove_blank']) && $layout_def['remove_blank']) {
207             if ( isset($layout_def['options']) &&  is_array($layout_def['options']) ) {
208                 $ops = $layout_def['options'];
209             }
210             elseif (isset($layout_def['options']) && isset($app_list_strings[$layout_def['options']])){
211                 $ops = $app_list_strings[$layout_def['options']];
212                 if(array_key_exists('', $app_list_strings[$layout_def['options']])) {
213                    unset($ops['']);
214                     }
215             }
216             else{
217                 $ops = array();
218             }
219         }
220         else {
221             $ops = $app_list_strings[$layout_def['options']];
222         }
223
224         $str = '<select multiple="true" size="3" name="' . $layout_def['name'] . '[]">';
225         $str .= get_select_options_with_id($ops, $layout_def['input_name0']);
226         $str .= '</select>';
227         return $str;
228     }
229 }
230
231 ?>