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