2 /*********************************************************************************
3 * SugarCRM is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
39 class SugarFieldEnum extends SugarFieldBase {
41 function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
42 if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html')
44 $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
45 return "<span id='{$vardef['name']}'>" . $this->fetch($this->findTemplate('DetailViewFunction')) . "</span>";
47 return parent::getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
51 function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
53 if(empty($displayParams['size'])) {
54 $displayParams['size'] = 6;
57 if(isset($vardef['function']) && !empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
58 $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
59 return $this->fetch($this->findTemplate('EditViewFunction'));
61 return parent::getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
67 function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
69 if(empty($displayParams['size'])) {
70 $displayParams['size'] = 6;
73 if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
74 $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
75 return $this->fetch($this->findTemplate('EditViewFunction'));
77 $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
78 return $this->fetch($this->findTemplate('SearchView'));
83 function displayFromFunc( $displayType, $parentFieldArray, $vardef, $displayParams, $tabindex ) {
84 if ( isset($vardef['function']['returns']) && $vardef['function']['returns'] == 'html' ) {
85 return parent::displayFromFunc($displayType, $parentFieldArray, $vardef, $displayParams, $tabindex);
88 $displayTypeFunc = 'get'.$displayType.'Smarty';
89 return $this->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
93 * @see SugarFieldBase::importSanitize()
95 public function importSanitize(
99 ImportFieldSanitize $settings
102 global $app_list_strings;
104 // Bug 27467 - Trim the value given
105 $value = trim($value);
107 if ( isset($app_list_strings[$vardef['options']])
108 && !isset($app_list_strings[$vardef['options']][$value]) ) {
109 // Bug 23485/23198 - Check to see if the value passed matches the display value
110 if ( in_array($value,$app_list_strings[$vardef['options']]) )
111 $value = array_search($value,$app_list_strings[$vardef['options']]);
112 // Bug 33328 - Check for a matching key in a different case
113 elseif ( in_array(strtolower($value), array_keys(array_change_key_case($app_list_strings[$vardef['options']]))) ) {
114 foreach ( $app_list_strings[$vardef['options']] as $optionkey => $optionvalue )
115 if ( strtolower($value) == strtolower($optionkey) )
118 // Bug 33328 - Check for a matching value in a different case
119 elseif ( in_array(strtolower($value), array_map('strtolower', $app_list_strings[$vardef['options']])) ) {
120 foreach ( $app_list_strings[$vardef['options']] as $optionkey => $optionvalue )
121 if ( strtolower($value) == strtolower($optionvalue) )
131 public function formatField($rawField, $vardef){
132 global $app_list_strings;
134 if(!empty($vardef['options'])){
135 $option_array_name = $vardef['options'];
137 if(!empty($app_list_strings[$option_array_name][$rawField])){
138 return $app_list_strings[$option_array_name][$rawField];