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