]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/DynamicFields/templates/Fields/TemplateRange.php
Release 6.4.0
[Github/sugarcrm.git] / modules / DynamicFields / templates / Fields / TemplateRange.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 class TemplateRange extends TemplateText
40 {
41
42         /**
43          * __construct
44          *
45          * Constructor for class.  This constructor ensures that TemplateRanage instances have the
46          * enable_range_search vardef value.
47          */
48         function __construct()
49         {
50                 $this->vardef_map['enable_range_search'] = 'enable_range_search';
51                 $this->vardef_map['options'] = 'options';
52         }
53
54
55         /**
56          * populateFromPost
57          *
58          * @see parent::populateFromPost
59          * This method checks to see if enable_range_search is set.  If so, ensure that the
60          * searchdefs for the module include the additional range fields.
61          */
62         function populateFromPost() {
63                 parent::populateFromPost();
64                 //If we are enabling range search, make sure we add the start and end range fields
65                 if (!empty($this->enable_range_search))
66                 {
67                         //If range search is enabled, set the options attribute for the dropdown choice selections
68                         $this->options = ($this->type == 'date' || $this->type == 'datetimecombo' || $this->type == 'datetime') ? 'date_range_search_dom' : 'numeric_range_search_dom';
69
70                         if(isset($_REQUEST['view_module']))
71                         {
72                                 $module = $_REQUEST['view_module'];
73                 if (file_exists('modules/'.$module.'/metadata/SearchFields.php')) 
74                 {
75                         require('modules/'.$module.'/metadata/SearchFields.php');
76                 }
77                 
78                             if(file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
79                             {
80                     require('custom/modules/'.$module.'/metadata/SearchFields.php');
81                             }                
82                 
83                 $field_name = $this->get_field_name($module, $_REQUEST['name']);
84
85                 if(isset($searchFields[$module]))
86                 {
87                         $field_name_range = 'range_' . $field_name;
88                         $field_name_start = 'start_range_' . $field_name;
89                         $field_name_end = 'end_range_' . $field_name;
90
91                         $isDateField = $this->type == 'date' || $this->type == 'datetimecombo' || $this->type == 'datetime';
92
93
94                     $searchFields[$module][$field_name_range] = array('query_type'=>'default', 'enable_range_search'=>true);
95                     if($isDateField)
96                     {
97                            $searchFields[$module][$field_name_range]['is_date_field'] = true;
98                     }
99
100                     $searchFields[$module][$field_name_start] = array('query_type'=>'default', 'enable_range_search'=>true);
101                     if($isDateField)
102                     {
103                            $searchFields[$module][$field_name_start]['is_date_field'] = true;
104                     }
105
106                     $searchFields[$module][$field_name_end] = array('query_type'=>'default', 'enable_range_search'=>true);
107                     if($isDateField)
108                     {
109                            $searchFields[$module][$field_name_end]['is_date_field'] = true;
110                     }
111
112                         if(!file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
113                         {
114                            mkdir_recursive('custom/modules/'.$module.'/metadata');
115                         }
116                         write_array_to_file("searchFields['{$module}']", $searchFields[$module], 'custom/modules/'.$module.'/metadata/SearchFields.php');
117                 }
118
119                             if(file_exists($cachefile = sugar_cached("modules/$module/SearchForm_basic.tpl")))
120                 {
121                    unlink($cachefile);
122                 }
123
124                 if(file_exists($cachefile = sugar_cached("modules/$module/SearchForm_advanced.tpl")))
125                 {
126                    unlink($cachefile );
127                 }
128                         }
129                 } else {
130                 //Otherwise, try to restore the searchFields to their state prior to being enabled
131                         if(isset($_REQUEST['view_module']))
132                         {
133                                 $module = $_REQUEST['view_module'];
134                 if (file_exists('modules/'.$module.'/metadata/SearchFields.php')) {
135                         require('modules/'.$module.'/metadata/SearchFields.php');
136                 }
137                 
138                             if(file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
139                             {
140                     require('custom/modules/'.$module.'/metadata/SearchFields.php');
141                             }                
142
143                 $field_name = $this->get_field_name($module, $_REQUEST['name']);
144
145                 if(isset($searchFields[$module]))
146                 {
147                         $field_name_range = 'range_' . $field_name;
148                         $field_name_start = 'start_range_' . $field_name;
149                         $field_name_end = 'end_range_' . $field_name;
150
151
152                     if(isset($searchFields[$module][$field_name_range]))
153                         {
154                            unset($searchFields[$module][$field_name_range]);
155                         }
156
157                         if(isset($searchFields[$module][$field_name_start]))
158                         {
159                            unset($searchFields[$module][$field_name_start]);
160                         }
161
162                     if(isset($searchFields[$module][$field_name_end]))
163                         {
164                            unset($searchFields[$module][$field_name_end]);
165                         }
166
167                     if(!file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
168                         {
169                            mkdir_recursive('custom/modules/'.$module.'/metadata');
170                         }
171                         write_array_to_file("searchFields['{$module}']", $searchFields[$module], 'custom/modules/'.$module.'/metadata/SearchFields.php');
172                 }
173
174                             if(file_exists($cachefile = sugar_cached("modules/$module/SearchForm_basic.tpl")))
175                 {
176                    unlink($cachefile);
177                 }
178
179                 if(file_exists($cachefile = sugar_cached("modules/$module/SearchForm_advanced.tpl")))
180                 {
181                    unlink($cachefile );
182                 }
183                         }
184                 }
185         }
186
187
188         /**
189          * get_field_def
190          *
191          * @see parent::get_field_def
192          * This method checks to see if the enable_range_search key/value entry should be
193          * added to the vardef entry representing the module
194          */
195     function get_field_def()
196     {
197                 $vardef = parent::get_field_def();
198         if(!empty($this->enable_range_search))
199         {
200                    $vardef['enable_range_search'] = $this->enable_range_search;
201                    $vardef['options'] = ($this->type == 'date' || $this->type == 'datetimecombo' || $this->type == 'datetime') ? 'date_range_search_dom' : 'numeric_range_search_dom';
202                 } else {
203                    $vardef['enable_range_search'] = false;
204                 }
205                 return $vardef;
206     }
207
208
209     public static function repairCustomSearchFields($vardefs, $module, $package='')
210     {
211
212         $fields = array();
213
214         //Find any range search enabled fields
215                 foreach($vardefs as $key=>$field)
216                 {
217                         if(!empty($field['enable_range_search'])) {
218                            $fields[$field['name']] = $field;
219                         }
220                 }
221
222                 if(!empty($fields))
223                 {
224                                 if(file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
225                             {
226                     require('custom/modules/'.$module.'/metadata/SearchFields.php');
227                 } else if (file_exists('modules/'.$module.'/metadata/SearchFields.php')) {
228                         require('modules/'.$module.'/metadata/SearchFields.php');
229                 } else if (file_exists('custom/modulebuilder/' . $package . '/modules/' . $module . '/metadata/SearchFields.php')) {
230                         require('custom/modulebuilder/' . $package . '/modules/' . $module . '/metadata/SearchFields.php');
231                 }
232
233                         foreach($fields as $field_name=>$field)
234                         {
235                         $field_name_range = 'range_' . $field_name;
236                         $field_name_start = 'start_range_' . $field_name;
237                         $field_name_end = 'end_range_' . $field_name;
238
239                         $type = $field['type'];
240
241                         $isDateField = $type == 'date' || $type == 'datetimecombo' || $type == 'datetime';
242
243                             $searchFields[$module][$field_name_range] = array('query_type'=>'default', 'enable_range_search'=>true);
244                     if($isDateField)
245                     {
246                            $searchFields[$module][$field_name_range]['is_date_field'] = true;
247                     }
248
249                     $searchFields[$module][$field_name_start] = array('query_type'=>'default', 'enable_range_search'=>true);
250                     if($isDateField)
251                     {
252                            $searchFields[$module][$field_name_start]['is_date_field'] = true;
253                     }
254
255                     $searchFields[$module][$field_name_end] = array('query_type'=>'default', 'enable_range_search'=>true);
256                     if($isDateField)
257                     {
258                            $searchFields[$module][$field_name_end]['is_date_field'] = true;
259                     }
260                         }
261
262                 if(!file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
263                 {
264                    mkdir_recursive('custom/modules/'.$module.'/metadata');
265                 }
266
267                 write_array_to_file("searchFields['{$module}']", $searchFields[$module], 'custom/modules/'.$module.'/metadata/SearchFields.php');
268
269                 }
270     }
271
272
273 }
274 ?>