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