]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/DynamicFields/templates/Fields/TemplateEnum.php
Release 6.5.0
[Github/sugarcrm.git] / modules / DynamicFields / templates / Fields / TemplateEnum.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-2012 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
39 require_once('include/utils/array_utils.php');
40 class TemplateEnum extends TemplateText{
41     var $max_size = 100;
42     var $len = 100;
43     var $type='enum';
44     var $ext1 = '';
45     var $default_value = '';
46     var $dependency ; // any dependency information
47     var $supports_unified_search = true;
48
49     function __construct ()
50     {
51         // ensure that the field dependency information is read in from any _REQUEST
52         $this->localVardefMap = array (
53                 'trigger' => 'trigger',
54                 'action' => 'action' ,
55             'visibility_grid' => 'visibility_grid',
56         ) ;
57         $this->vardef_map = array_merge ( $this->vardef_map , $this->localVardefMap ) ;
58     }
59
60     function populateFromPost ()
61     {
62         parent::populateFromPost();
63         if (!empty($this->visibility_grid) && is_string($this->visibility_grid))
64         {
65             $this->visibility_grid = json_decode(html_entity_decode($this->visibility_grid), true);
66         }
67         // now convert trigger,action pairs into a dependency array representation
68         // we expect the dependencies in the following format:
69         // trigger = [ trigger for action 1 , trigger for action 2 , ... , trigger for action n ]
70         // action = [ action 1 , action 2 , ... , action n ]
71
72         // check first if we have the component parts of a dependency
73         $dependencyPresent = true ;
74         foreach ( $this->localVardefMap as $def )
75         {
76                 $dependencyPresent &= isset ( $this->$def ) ;
77         }
78
79         if ( $dependencyPresent )
80         {
81                 $dependencies = array () ;
82
83                 if ( is_array ( $this->trigger ) && is_array ( $this->action ) )
84                 {
85                                 for ( $i = 0 ; $i < count ( $this->action ) ; $i++ )
86                                 {
87                                         $dependencies [ $this->trigger [ $i ] ] = $this->action [ $i ] ;
88                                 }
89                                 $this->dependency = $dependencies ;
90                 }
91                 else
92                 {
93                         if ( ! is_array ( $this->trigger ) && ! is_array ( $this->action ) )
94                                 $this->dependency = array ( $this->trigger => $this->action ) ;
95                 }
96                 // tidy up
97                 unset ( $this->trigger ) ;
98                 unset ( $this->action ) ;
99         }
100     }
101         function get_xtpl_edit(){
102                 $name = $this->name;
103                 $value = '';
104                 if(isset($this->bean->$name)){
105                         $value = $this->bean->$name;
106                 }else{
107                         if(empty($this->bean->id)){
108                                 $value= $this->default_value;
109                         }
110                 }
111                 if(!empty($this->help)){
112                     $returnXTPL[strtoupper($this->name . '_help')] = translate($this->help, $this->bean->module_dir);
113                 }
114
115                 global $app_list_strings;
116                 $returnXTPL = array();
117                 $returnXTPL[strtoupper($this->name)] = $value;
118                 if(empty($this->ext1)){
119                         $this->ext1 = $this->options;
120                 }
121                 $returnXTPL[strtoupper('options_'.$this->name)] = get_select_options_with_id($app_list_strings[$this->ext1], $value);
122
123                 return $returnXTPL;
124
125
126         }
127
128         function get_xtpl_search(){
129                 $searchFor = '';
130                 if(!empty($_REQUEST[$this->name])){
131                         $searchFor = $_REQUEST[$this->name];
132                 }
133                 global $app_list_strings;
134                 $returnXTPL = array();
135                 $returnXTPL[strtoupper($this->name)] = $searchFor;
136                 if(empty($this->ext1)){
137                         $this->ext1 = $this->options;
138                 }
139                 $returnXTPL[strtoupper('options_'.$this->name)] = get_select_options_with_id(add_blank_option($app_list_strings[$this->ext1]), $searchFor);
140                 return $returnXTPL;
141
142         }
143
144         function get_field_def(){
145                 $def = parent::get_field_def();
146                 $def['options'] = !empty($this->options) ? $this->options : $this->ext1;
147                 $def['default'] = !empty($this->default) ? $this->default : $this->default_value;
148                 $def['len'] = $this->max_size;
149                 $def['studio'] = 'visible';
150                 // this class may be extended, so only do the unserialize for genuine TemplateEnums
151                 if (get_class( $this ) == 'TemplateEnum' && empty($def['dependency']) )
152                         $def['dependency'] = isset($this->ext4)? unserialize(html_entity_decode($this->ext4)) : null ;
153         if (!empty($this->visibility_grid))
154             $def['visibility_grid'] = $this->visibility_grid;
155
156                 return $def;
157         }
158
159         function get_xtpl_detail(){
160                 $name = $this->name;
161
162                 // awu: custom fields are not being displayed on the detail view because $this->ext1 is always empty, adding this to get the options
163                 if(empty($this->ext1)){
164                         if(!empty($this->options))
165                                 $this->ext1 = $this->options;
166                 }
167
168                 if(isset($this->bean->$name)){
169                         $key = $this->bean->$name;
170                         global $app_list_strings;
171                         if(preg_match('/&amp;/s', $key)) {
172                            $key = str_replace('&amp;', '&', $key);
173                         }
174                         if(isset($app_list_strings[$this->ext1])){
175                 if(isset($app_list_strings[$this->ext1][$key])) {
176                     return $app_list_strings[$this->ext1][$key];
177                 }
178
179                                 if(isset($app_list_strings[$this->ext1][$this->bean->$name])){
180                                         return $app_list_strings[$this->ext1][$this->bean->$name];
181                                 }
182                         }
183                 }
184                 return '';
185         }
186
187         function save($df){
188                 if (!empty($this->default_value) && is_array($this->default_value)) {
189                         $this->default_value = $this->default_value[0];
190                 }
191                 if (!empty($this->default) && is_array($this->default)) {
192                         $this->default = $this->default[0];
193                 }
194         if (!empty($this->visibility_grid) && is_string($this->visibility_grid))
195         {
196             $this->visibility_grid = json_decode($this->visibility_grid, true);
197         }
198                 parent::save($df);
199         }
200
201     /**
202      * @param DynamicField $df
203      */
204     function delete($df){
205         parent::delete($df);
206     }
207 }
208
209
210 ?>