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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('modules/DynamicFields/templates/Fields/TemplateEnum.php');
39 require_once('include/utils/array_utils.php');
40 class TemplateMultiEnum extends TemplateEnum{
43 function get_html_edit(){
45 $xtpl_var = strtoupper( $this->name);
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>";
50 function get_xtpl_edit(){
53 if(isset($this->bean->$name)){
54 $value = $this->bean->$name;
56 if(empty($this->bean->id)){
57 $value= $this->default_value;
60 if(!empty($this->help)){
61 $returnXTPL[strtoupper($this->name . '_help')] = translate($this->help, $this->bean->module_dir);
64 global $app_list_strings;
65 $returnXTPL = array();
67 $returnXTPL[strtoupper($this->name)] = str_replace('^,^', ',', $value);
68 if(empty($this->ext1)){
69 $this->ext1 = $this->options;
71 $returnXTPL[strtoupper('options_'.$this->name)] = get_select_options_with_id($app_list_strings[$this->ext1], unencodeMultienum( $value));
80 function get_xtpl_list(){
81 return $this->get_xtpl_detail();
84 function get_xtpl_detail(){
88 if(isset($this->bean->$name)){
89 $value = $this->bean->$name;
91 if(empty($this->bean->id)){
92 $value= $this->default_value;
95 $returnXTPL = array();
96 if(empty($value)) return $returnXTPL;
97 global $app_list_strings;
99 $values = unencodeMultienum( $value);
100 $translatedValues = array();
102 foreach($values as $val){
103 $translated = translate($this->options, '', $val);
104 if(is_string($translated))$translatedValues[] = $translated;
107 $returnXTPL[strtoupper($this->name)] = implode(', ', $translatedValues);
115 function get_field_def(){
116 $def = parent::get_field_def();
117 if ( !empty ( $this->ext4 ) )
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 ) ;
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 ;
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' ] ;
141 $def['isMultiSelect'] = true;
146 function get_db_default(){
151 if ( isset ( $this->default ) )
153 if ( is_array ( $this->default ) )
154 $this->default = encodeMultienumValue($this->default);
155 $this->ext4 = ( isset ( $this->dependency ) ) ? serialize ( array ( 'default' => $this->default , 'dependency' => html_entity_decode($this->dependency) ) ) : $this->default ;
158 if ( isset ( $this->dependency ) )
159 $this->ext4 = serialize ( array ( 'dependency' => html_entity_decode($this->dependency) ) ) ;