]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetFielddate.php
Release 6.2.0
[Github/sugarcrm.git] / include / generic / SugarWidgets / SugarWidgetFielddate.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 require_once('include/generic/SugarWidgets/SugarWidgetFielddatetime.php');
39
40 class SugarWidgetFieldDate extends SugarWidgetFieldDateTime
41 {
42         function & displayList($layout_def)
43         {
44             global $timedate;
45             // i guess qualifier and column_function are the same..
46             if (! empty($layout_def['column_function']))
47              {
48                 $func_name = 'displayList'.$layout_def['column_function'];
49                 if ( method_exists($this,$func_name))
50                 {
51                         $display = $this->$func_name($layout_def);
52                         return $display;
53                 }
54             }
55             $content = $this->displayListPlain($layout_def);
56                 return $content;         
57         }
58
59
60 function get_date_part($date_time_value){
61
62         $date_parts=explode(' ', $date_time_value);
63         if (count($date_parts) == 2) {
64                 $date=$date_parts[0];
65         } else {
66                 $date=$date_time_value;
67         }                
68         return $date;
69 }
70
71 function get_db_date($days,$time) {
72     global $timedate;
73
74     $begin = date($GLOBALS['timedate']->get_db_date_time_format(), time()+(86400 * $days));  //gmt date with day adjustment applied.
75 //      $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
76     
77     if ($time=='start') {
78         $begin_parts = explode(' ', $begin);
79         $begin = $begin_parts[0] . ' 00:00:00';
80     }
81     else if ($time=='end') {
82         $begin_parts = explode(' ', $begin);
83         $begin = $begin_parts[0] . ' 23:59:59';
84     } 
85     return $begin;
86 }
87 function get_time_part($date_time_value) {
88         $date_parts=explode(' ', $date_time_value);
89         if (count($date_parts) == 2) {
90                 $time=$date_parts[1];
91         } else {
92                 $time=$date_time_value;
93         }                
94         return $time;
95
96 }
97  function queryFilterBefore_old(&$layout_def)
98  {
99   global $timedate;
100
101                         return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($layout_def['input_name0'])."'\n";
102  }
103
104  function queryFilterAfter_old(&$layout_def)
105  {
106   global $timedate;
107
108                 return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($layout_def['input_name0'])."'\n";
109  }
110
111  function queryFilterBetween_Dates_old(&$layout_def)
112  {
113   global $timedate;
114
115                         return "(".$this->_get_column_select($layout_def).">='".$this->reporter->db->quote($layout_def['input_name0'])."' AND \n".  $this->_get_column_select($layout_def)."<='".$this->reporter->db->quote($layout_def['input_name1'])."')\n";
116  }
117
118     function queryFilterNot_Equals_str(& $layout_def) {
119         global $timedate;
120         
121         $begin = $layout_def['input_name0'];
122
123         if ($this->reporter->db->dbType == 'oci8') {
124         } elseif($this->reporter->db->dbType == 'mssql') {
125             return "".$this->_get_column_select($layout_def)."!='".$this->reporter->db->quote($begin)."'\n";
126         }else{
127             return "ISNULL(".$this->_get_column_select($layout_def).") OR \n(".$this->_get_column_select($layout_def)."!='".$this->reporter->db->quote($begin)."')\n";
128         }
129
130     }
131     
132
133     function queryFilterOn(& $layout_def) {
134         global $timedate;
135         
136         $begin = $layout_def['input_name0'];
137
138             return $this->_get_column_select($layout_def)."='".$this->reporter->db->quote($begin)."'\n";
139     }
140     function queryFilterBefore(& $layout_def) {
141         global $timedate;
142         
143         $begin = $layout_def['input_name0'];
144
145             return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."'\n";
146
147     }
148     
149     function queryFilterAfter(& $layout_def) {
150         global $timedate;
151
152         $begin = $layout_def['input_name0'];
153
154             return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($begin)."'\n";
155     }
156     function queryFilterBetween_Dates(& $layout_def) {
157         global $timedate;
158         
159         $begin = $layout_def['input_name0'];
160         $end = $layout_def['input_name1'];
161
162             return "(".$this->_get_column_select($layout_def).">='".$this->reporter->db->quote($begin)."' AND \n".$this->_get_column_select($layout_def)."<='".$this->reporter->db->quote($end)."')\n";
163     }
164     
165         function queryFilterTP_yesterday(& $layout_def) {
166                 global $timedate, $current_user;
167                 
168         $begin_timestamp = time() - 86400;
169         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
170                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
171
172         $begin_parts = explode(' ', $begin);
173         $begin = $begin_parts[0] . ' 00:00:00';
174         $end = $begin_parts[0] . ' 23:59:59';
175         return $this->get_start_end_date_filter($layout_def,$begin,$end);
176
177         }
178         function queryFilterTP_today(& $layout_def) {
179                 global $timedate, $current_user;
180         
181         $begin_timestamp = time();
182         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
183                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
184         
185         $begin_parts = explode(' ', $begin);
186         $begin = $begin_parts[0] . ' 00:00:00';
187         $end = $begin_parts[0] . ' 23:59:59';
188         return $this->get_start_end_date_filter($layout_def,$begin,$end);
189
190         }
191
192         function queryFilterTP_tomorrow(& $layout_def) {
193                 global $timedate, $current_user;
194
195         $begin_timestamp = time() + 86400;
196         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
197                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
198
199         $begin_parts = explode(' ', $begin);
200         $begin = $begin_parts[0] . ' 00:00:00';
201         $end = $begin_parts[0] . ' 23:59:59';
202         return $this->get_start_end_date_filter($layout_def,$begin,$end);
203
204
205         }
206         function queryFilterTP_last_7_days(& $layout_def) {
207                 global $timedate, $current_user;
208
209         $begin_timestamp = time() - (6 * 86400);
210         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
211                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
212         $end_timestamp = time();
213         $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
214                 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
215
216         $begin_parts = explode(' ', $begin);
217         $begin = $begin_parts[0] . ' 00:00:00';
218         $end_parts = explode(' ', $end);
219         $end = $end_parts[0] . ' 23:59:59';
220
221         return $this->get_start_end_date_filter($layout_def,$begin,$end);
222
223         }
224
225         function queryFilterTP_next_7_days(& $layout_def) {
226                 global $timedate, $current_user;
227
228         $begin_timestamp = time();
229         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
230                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
231         $end_timestamp = time() + (86400*6);
232         $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
233                 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
234
235         $begin_parts = explode(' ', $begin);
236         $begin = $begin_parts[0] . ' 00:00:00';
237         $end_parts = explode(' ', $end);
238         $end = $end_parts[0] . ' 23:59:59';
239
240         return $this->get_start_end_date_filter($layout_def,$begin,$end);
241         }
242
243         function queryFilterTP_last_month(& $layout_def) {
244
245                 global $timedate;
246
247         $begin_timestamp = time();
248         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
249                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
250
251         $begin_parts = explode(' ', $begin);
252         $curr_date = explode('-',$begin_parts[0]);
253
254                 //Get year and month from time stamp.
255                 $curr_year=$curr_date[0];
256                 $curr_month=$curr_date[1];
257
258                 //get start date for last month and convert it to gmt and db format.
259             $begin=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 month",mktime(0,0,0,$curr_month,1,$curr_year)));
260
261             //get end date for last month  and convert it to gmt and db format.
262         $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
263                 return $this->get_start_end_date_filter($layout_def,$begin,$end);
264         }
265
266         function queryFilterTP_this_month(& $layout_def) {
267
268                 global $timedate;
269
270         $begin_timestamp = time();
271         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
272                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
273
274         $begin_parts = explode(' ', $begin);
275         $curr_date = explode('-',$begin_parts[0]);
276
277                 //Get year and month from time stamp.
278                 $curr_year=$curr_date[0];
279                 $curr_month=$curr_date[1];
280
281                 //get start date for this month and convert it to gmt and db format.
282             $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
283
284             //get end date for this month  and convert it to gmt and db format.
285             //first get the first day of next month and move back by one day.
286                 if ($curr_month==12) {
287                         $curr_month=1;
288                         $curr_year+=1;
289                 } else {
290                         $curr_month+=1;
291                 }
292         $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
293                 return $this->get_start_end_date_filter($layout_def,$begin,$end);
294         }
295
296         function queryFilterTP_next_month(& $layout_def) {
297                 global $timedate;
298
299         $begin_timestamp = time();
300         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
301                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
302
303         $begin_parts = explode(' ', $begin);
304         $curr_date = explode('-',$begin_parts[0]);
305
306                 //Get year and month from time stamp.
307                 $curr_year=$curr_date[0];
308                 $curr_month=$curr_date[1];
309
310                 if ($curr_month==12) {
311                         $curr_month=1;
312                         $curr_year+=1;
313                 } else {
314                         $curr_month+=1;
315                 }
316
317                 //get start date for next month and convert it to gmt and db format.
318             $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
319         $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",(strtotime("1 month",mktime(23,59,59,$curr_month,1,$curr_year)))));
320
321                 return $this->get_start_end_date_filter($layout_def,$begin,$end);
322         }
323
324         function queryFilterTP_last_30_days(& $layout_def) {
325                 global $timedate;
326
327         $begin_timestamp = time() - (29 * 86400);
328         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
329                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
330         $end_timestamp = time();
331         $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
332                 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
333
334         $begin_parts = explode(' ', $begin);
335         $begin = $begin_parts[0] . ' 00:00:00';
336         $end_parts = explode(' ', $end);
337         $end = $end_parts[0] . ' 23:59:59';
338         
339         return $this->get_start_end_date_filter($layout_def,$begin,$end);
340         }
341
342         function queryFilterTP_next_30_days(& $layout_def) {
343                 global $timedate;
344
345         $begin_timestamp = time();
346         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
347                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
348         $end_timestamp = time() + (29 * 86400);
349         $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
350                 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
351
352         $begin_parts = explode(' ', $begin);
353         $begin = $begin_parts[0] . ' 00:00:00';
354         $end_parts = explode(' ', $end);
355         $end = $end_parts[0] . ' 23:59:59';
356
357         return $this->get_start_end_date_filter($layout_def,$begin,$end);
358         }
359
360
361         function queryFilterTP_this_quarter(& $layout_def) {
362         }
363
364         function queryFilterTP_last_year(& $layout_def) {
365
366                 global $timedate;
367
368         $begin_timestamp = time();
369         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
370                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
371
372         $begin_parts = explode(' ', $begin);
373         $curr_date = explode('-',$begin_parts[0]);
374
375                 //Get year and month from time stamp.
376                 $curr_year=$curr_date[0]-1;
377
378                 //get start date for last year and convert it to gmt and db format.
379             $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
380
381             //get end date for last year  and convert it to gmt and db format.
382         $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
383
384                 return $this->get_start_end_date_filter($layout_def,$begin,$end);
385         }
386
387         function queryFilterTP_this_year(& $layout_def) {
388                 global $timedate;
389         $begin_timestamp = time();
390         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
391                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
392
393         $begin_parts = explode(' ', $begin);
394         $curr_date = explode('-',$begin_parts[0]);
395
396                 //Get year and month from time stamp.
397                 $curr_year=$curr_date[0];
398
399                 //get start date for this year and convert it to gmt and db format.
400             $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
401
402             //get end date for this year  and convert it to gmt and db format.
403         $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
404
405                 return $this->get_start_end_date_filter($layout_def,$begin,$end);
406         }
407
408         function queryFilterTP_next_year(& $layout_def) {
409                 global $timedate;
410         $begin_timestamp = time();
411         $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
412                 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
413
414         $begin_parts = explode(' ', $begin);
415         $curr_date = explode('-',$begin_parts[0]);
416
417                 //Get year and month from time stamp.
418                 $curr_year=$curr_date[0]+1;
419
420
421                 //get start date for this year and convert it to gmt and db format.
422             $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
423
424             //get end date for this year  and convert it to gmt and db format.
425         $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
426
427                 return $this->get_start_end_date_filter($layout_def,$begin,$end);
428         }
429
430         
431     
432 }
433
434 ?>