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.
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_db_type(){
51 if ($GLOBALS['db']->dbType=='oci8') {
58 function get_xtpl_edit(){
61 if(isset($this->bean->$name)){
62 $value = $this->bean->$name;
64 if(empty($this->bean->id)){
65 $value= $this->default_value;
68 if(!empty($this->help)){
69 $returnXTPL[strtoupper($this->name . '_help')] = translate($this->help, $this->bean->module_dir);
72 global $app_list_strings;
73 $returnXTPL = array();
75 $returnXTPL[strtoupper($this->name)] = str_replace('^,^', ',', $value);
76 if(empty($this->ext1)){
77 $this->ext1 = $this->options;
79 $returnXTPL[strtoupper('options_'.$this->name)] = get_select_options_with_id($app_list_strings[$this->ext1], unencodeMultienum( $value));
88 function get_xtpl_list(){
89 return $this->get_xtpl_detail();
92 function get_xtpl_detail(){
96 if(isset($this->bean->$name)){
97 $value = $this->bean->$name;
99 if(empty($this->bean->id)){
100 $value= $this->default_value;
103 $returnXTPL = array();
104 if(empty($value)) return $returnXTPL;
105 global $app_list_strings;
107 $values = unencodeMultienum( $value);
108 $translatedValues = array();
110 foreach($values as $val){
111 $translated = translate($this->options, '', $val);
112 if(is_string($translated))$translatedValues[] = $translated;
115 $returnXTPL[strtoupper($this->name)] = implode(', ', $translatedValues);
123 function get_field_def(){
124 $def = parent::get_field_def();
125 if ( !empty ( $this->ext4 ) )
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 ) ;
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 ;
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' ] ;
147 $def['isMultiSelect'] = true;
152 function get_db_default(){
156 function get_db_modify_alter_table($table){
157 return parent::get_db_modify_alter_table($table);
161 if ( isset ( $this->default ) )
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 ;
168 if ( isset ( $this->dependency ) )
169 $this->ext4 = serialize ( array ( 'dependency' => $this->dependency ) ) ;