]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/DynamicFields/templates/Fields/TemplateMultiEnum.php
Release 6.1.4
[Github/sugarcrm.git] / modules / DynamicFields / templates / Fields / TemplateMultiEnum.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM 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 require_once('modules/DynamicFields/templates/Fields/TemplateEnum.php');
39 require_once('include/utils/array_utils.php');
40 class TemplateMultiEnum extends TemplateEnum{
41         var $type = 'text';
42
43         function get_html_edit(){
44                 $this->prepare();
45                 $xtpl_var = strtoupper( $this->name);
46                 // MFH BUG#13645
47                 return "<input type='hidden' name='". $this->name. "' value='0'><select name='". $this->name . "[]' size='5' title='{" . $xtpl_var ."_HELP}' MULTIPLE=true>{OPTIONS_".$xtpl_var. "}</select>";
48         }
49
50         function get_db_type(){
51                 if ($GLOBALS['db']->dbType=='oci8') {
52                         return " CLOB ";
53                 } else {
54                         return " TEXT ";
55                 }
56         }
57
58         function get_xtpl_edit(){
59                 $name = $this->name;
60                 $value = '';
61                 if(isset($this->bean->$name)){
62                         $value = $this->bean->$name;
63                 }else{
64                         if(empty($this->bean->id)){
65                                 $value= $this->default_value;
66                         }
67                 }
68                 if(!empty($this->help)){
69                     $returnXTPL[strtoupper($this->name . '_help')] = translate($this->help, $this->bean->module_dir);
70                 }
71
72                 global $app_list_strings;
73                 $returnXTPL = array();
74
75                 $returnXTPL[strtoupper($this->name)] = str_replace('^,^', ',', $value);
76                 if(empty($this->ext1)){
77                         $this->ext1 = $this->options;
78                 }
79                 $returnXTPL[strtoupper('options_'.$this->name)] = get_select_options_with_id($app_list_strings[$this->ext1], unencodeMultienum( $value));
80
81                 return $returnXTPL;
82
83
84         }
85         function prepSave(){
86
87         }
88         function get_xtpl_list(){
89                 return $this->get_xtpl_detail();
90
91         }
92         function get_xtpl_detail(){
93
94                 $name = $this->name;
95                 $value = '';
96                 if(isset($this->bean->$name)){
97                         $value = $this->bean->$name;
98                 }else{
99                         if(empty($this->bean->id)){
100                                 $value= $this->default_value;
101                         }
102                 }
103                 $returnXTPL = array();
104                 if(empty($value)) return $returnXTPL;
105                 global $app_list_strings;
106
107         $values = unencodeMultienum( $value);
108         $translatedValues = array();
109
110         foreach($values as $val){
111             $translated = translate($this->options, '', $val);
112             if(is_string($translated))$translatedValues[] = $translated;
113         }
114
115                 $returnXTPL[strtoupper($this->name)] = implode(', ', $translatedValues);
116                 return $returnXTPL;
117
118
119
120
121 }
122
123         function get_field_def(){
124                 $def = parent::get_field_def();
125                 if ( !empty ( $this->ext4 ) )
126                 {
127                         // turn off error reporting in case we are unpacking a value that hasn't been packed...
128                         // this is kludgy, but unserialize doesn't throw exceptions correctly
129                         $oldErrorReporting = error_reporting ( 0 );
130                         $unpacked = unserialize ( $this->ext4 ) ;
131                         error_reporting ( $oldErrorReporting ) ;
132
133                         // if we have a new error, then unserialize must have failed => we don't have a packed ext4
134                         // safe to assume that false means the unpack failed, as ext4 will either contain an imploded string of default values, or an array, not a boolean false value
135                         if ( $unpacked === false ) {
136                                 $def [ 'default' ] = $this->ext4 ;
137                         }
138                         else
139                         {
140                                 // we have a packed representation containing one or both of default and dependency
141                                 if ( isset ( $unpacked [ 'default' ] ) )
142                                         $def [ 'default' ] = $unpacked [ 'default' ] ;
143                                 if ( isset ( $unpacked [ 'dependency' ] ) )
144                                         $def [ 'dependency' ] = $unpacked [ 'dependency' ] ;
145                         }
146                 }
147                 $def['isMultiSelect'] = true;
148                 unset($def['len']);
149                 return $def;
150         }
151
152         function get_db_default(){
153         return '';
154         }
155
156     function get_db_modify_alter_table($table){
157         return parent::get_db_modify_alter_table($table);
158         }
159
160         function save($df) {
161                 if ( isset ( $this->default ) )
162                 {
163                         if ( is_array ( $this->default ) )
164                                 $this->default = encodeMultienumValue($this->default);
165                         $this->ext4 = ( isset ( $this->dependency ) ) ? serialize ( array ( 'default' => $this->default , 'dependency' => $this->dependency ) )  : $this->default ;
166                 } else
167                 {
168                         if ( isset ( $this->dependency ) )
169                                 $this->ext4 = serialize ( array ( 'dependency' => $this->dependency ) ) ;
170                 }
171                 parent::save($df);
172         }
173 }
174
175
176 ?>