]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarFields/Fields/Enum/SugarFieldEnum.php
Release 6.5.0
[Github/sugarcrm.git] / include / SugarFields / Fields / Enum / SugarFieldEnum.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37 require_once('include/SugarFields/Fields/Base/SugarFieldBase.php');
38
39 class SugarFieldEnum extends SugarFieldBase {
40    
41         function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
42                 if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html')
43                 {
44                   $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
45                   return "<span id='{$vardef['name']}'>" . $this->fetch($this->findTemplate('DetailViewFunction')) . "</span>";
46         } else {
47                   return parent::getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
48         }
49     }
50     
51     function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
52
53         if(empty($displayParams['size'])) {
54                    $displayParams['size'] = 6;
55                 }
56         
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'));
60         }else{
61                   return parent::getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex);
62         }
63     }
64     
65     
66     
67         function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
68                 
69                 if(empty($displayParams['size'])) {
70                    $displayParams['size'] = 6;
71                 }
72                 
73         if(!empty($vardef['function']['returns']) && $vardef['function']['returns']== 'html'){
74                   $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
75                   return $this->fetch($this->findTemplate('EditViewFunction'));
76         }else{
77                   $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
78                   return $this->fetch($this->findTemplate('SearchView'));
79         }
80     }
81     
82
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);
86         }
87
88         $displayTypeFunc = 'get'.$displayType.'Smarty';
89         return $this->$displayTypeFunc($parentFieldArray, $vardef, $displayParams, $tabindex);
90     }
91     
92     /**
93      * @see SugarFieldBase::importSanitize()
94      */
95     public function importSanitize(
96         $value,
97         $vardef,
98         $focus,
99         ImportFieldSanitize $settings
100         )
101     {
102         global $app_list_strings;
103         
104         // Bug 27467 - Trim the value given
105         $value = trim($value);
106         
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) )
116                         $value = $optionkey;
117             }
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) )
122                         $value = $optionkey;
123             }
124             else
125                 return false;
126         }
127         
128         return $value;
129     }
130     
131         public function formatField($rawField, $vardef){
132                 global $app_list_strings;
133                 
134                 if(!empty($vardef['options'])){
135                         $option_array_name = $vardef['options'];
136                         
137                         if(!empty($app_list_strings[$option_array_name][$rawField])){
138                                 return $app_list_strings[$option_array_name][$rawField];
139                         }else {
140                                 return $rawField;
141                         }
142                 } else {
143                         return $rawField;
144                 }
145     }
146 }
147 ?>