]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/DynamicFields/templates/Fields/TemplateMultiEnum.php
Release 6.4.0
[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 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 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_xtpl_edit(){
51                 $name = $this->name;
52                 $value = '';
53                 if(isset($this->bean->$name)){
54                         $value = $this->bean->$name;
55                 }else{
56                         if(empty($this->bean->id)){
57                                 $value= $this->default_value;
58                         }
59                 }
60                 if(!empty($this->help)){
61                     $returnXTPL[strtoupper($this->name . '_help')] = translate($this->help, $this->bean->module_dir);
62                 }
63
64                 global $app_list_strings;
65                 $returnXTPL = array();
66
67                 $returnXTPL[strtoupper($this->name)] = str_replace('^,^', ',', $value);
68                 if(empty($this->ext1)){
69                         $this->ext1 = $this->options;
70                 }
71                 $returnXTPL[strtoupper('options_'.$this->name)] = get_select_options_with_id($app_list_strings[$this->ext1], unencodeMultienum( $value));
72
73                 return $returnXTPL;
74
75
76         }
77         function prepSave(){
78
79         }
80         function get_xtpl_list(){
81                 return $this->get_xtpl_detail();
82
83         }
84         function get_xtpl_detail(){
85
86                 $name = $this->name;
87                 $value = '';
88                 if(isset($this->bean->$name)){
89                         $value = $this->bean->$name;
90                 }else{
91                         if(empty($this->bean->id)){
92                                 $value= $this->default_value;
93                         }
94                 }
95                 $returnXTPL = array();
96                 if(empty($value)) return $returnXTPL;
97                 global $app_list_strings;
98
99         $values = unencodeMultienum( $value);
100         $translatedValues = array();
101
102         foreach($values as $val){
103             $translated = translate($this->options, '', $val);
104             if(is_string($translated))$translatedValues[] = $translated;
105         }
106
107                 $returnXTPL[strtoupper($this->name)] = implode(', ', $translatedValues);
108                 return $returnXTPL;
109
110
111
112
113 }
114
115         function get_field_def(){
116                 $def = parent::get_field_def();
117                 if ( !empty ( $this->ext4 ) )
118                 {
119                         // turn off error reporting in case we are unpacking a value that hasn't been packed...
120                         // this is kludgy, but unserialize doesn't throw exceptions correctly
121                         if($this->ext4[0] == 'a' && $this->ext4[1] == ':') {
122                             $unpacked = @unserialize ( $this->ext4 ) ;
123                         } else {
124                             $unpacked = false;
125                         }
126
127                         // if we have a new error, then unserialize must have failed => we don't have a packed ext4
128                         // 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
129                         if ( $unpacked === false && !isset($this->no_default) ) {
130                                 $def [ 'default' ] = $this->ext4 ;
131                         }
132                         else
133                         {
134                                 // we have a packed representation containing one or both of default and dependency
135                                 if ( isset ( $unpacked [ 'default' ] ) && !isset($this->no_default))
136                                         $def [ 'default' ] = $unpacked [ 'default' ] ;
137                                 if ( isset ( $unpacked [ 'dependency' ] ) )
138                                         $def [ 'dependency' ] = $unpacked [ 'dependency' ] ;
139                         }
140                 }
141                 $def['isMultiSelect'] = true;
142                 unset($def['len']);
143                 return $def;
144         }
145
146         function get_db_default(){
147         return '';
148         }
149
150         function save($df) {
151                 if ( isset ( $this->default ) )
152                 {
153                         if ( is_array ( $this->default ) )
154                                 $this->default = encodeMultienumValue($this->default);
155                         $this->ext4 = ( isset ( $this->dependency ) ) ? serialize ( array ( 'default' => $this->default , 'dependency' => $this->dependency ) )  : $this->default ;
156                 } else
157                 {
158                         if ( isset ( $this->dependency ) )
159                                 $this->ext4 = serialize ( array ( 'dependency' => $this->dependency ) ) ;
160                 }
161                 parent::save($df);
162         }
163 }
164
165
166 ?>