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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('include/generic/SugarWidgets/SugarWidgetFielddatetime.php');
40 class SugarWidgetFieldDate extends SugarWidgetFieldDateTime
42 function & displayList($layout_def)
45 // i guess qualifier and column_function are the same..
46 if (! empty($layout_def['column_function']))
48 $func_name = 'displayList'.$layout_def['column_function'];
49 if ( method_exists($this,$func_name))
51 $display = $this->$func_name($layout_def);
55 $content = $this->displayListPlain($layout_def);
60 function get_date_part($date_time_value){
62 $date_parts=explode(' ', $date_time_value);
63 if (count($date_parts) == 2) {
66 $date=$date_time_value;
71 function get_db_date($days,$time) {
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);
78 $begin_parts = explode(' ', $begin);
79 $begin = $begin_parts[0] . ' 00:00:00';
81 else if ($time=='end') {
82 $begin_parts = explode(' ', $begin);
83 $begin = $begin_parts[0] . ' 23:59:59';
87 function get_time_part($date_time_value) {
88 $date_parts=explode(' ', $date_time_value);
89 if (count($date_parts) == 2) {
92 $time=$date_time_value;
97 function queryFilterBefore_old(&$layout_def)
101 return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($layout_def['input_name0'])."'\n";
104 function queryFilterAfter_old(&$layout_def)
108 return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($layout_def['input_name0'])."'\n";
111 function queryFilterBetween_Dates_old(&$layout_def)
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";
118 function queryFilterNot_Equals_str(& $layout_def) {
121 $begin = $layout_def['input_name0'];
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";
127 return "ISNULL(".$this->_get_column_select($layout_def).") OR \n(".$this->_get_column_select($layout_def)."!='".$this->reporter->db->quote($begin)."')\n";
133 function queryFilterOn(& $layout_def) {
136 $begin = $layout_def['input_name0'];
138 return $this->_get_column_select($layout_def)."='".$this->reporter->db->quote($begin)."'\n";
140 function queryFilterBefore(& $layout_def) {
143 $begin = $layout_def['input_name0'];
145 return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."'\n";
149 function queryFilterAfter(& $layout_def) {
152 $begin = $layout_def['input_name0'];
154 return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($begin)."'\n";
156 function queryFilterBetween_Dates(& $layout_def) {
159 $begin = $layout_def['input_name0'];
160 $end = $layout_def['input_name1'];
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";
165 function queryFilterTP_yesterday(& $layout_def) {
166 global $timedate, $current_user;
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);
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);
178 function queryFilterTP_today(& $layout_def) {
179 global $timedate, $current_user;
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);
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);
192 function queryFilterTP_tomorrow(& $layout_def) {
193 global $timedate, $current_user;
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);
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);
206 function queryFilterTP_last_7_days(& $layout_def) {
207 global $timedate, $current_user;
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);
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';
221 return $this->get_start_end_date_filter($layout_def,$begin,$end);
225 function queryFilterTP_next_7_days(& $layout_def) {
226 global $timedate, $current_user;
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);
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';
240 return $this->get_start_end_date_filter($layout_def,$begin,$end);
243 function queryFilterTP_last_month(& $layout_def) {
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);
251 $begin_parts = explode(' ', $begin);
252 $curr_date = explode('-',$begin_parts[0]);
254 //Get year and month from time stamp.
255 $curr_year=$curr_date[0];
256 $curr_month=$curr_date[1];
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)));
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);
266 function queryFilterTP_this_month(& $layout_def) {
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);
274 $begin_parts = explode(' ', $begin);
275 $curr_date = explode('-',$begin_parts[0]);
277 //Get year and month from time stamp.
278 $curr_year=$curr_date[0];
279 $curr_month=$curr_date[1];
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));
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) {
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);
296 function queryFilterTP_next_month(& $layout_def) {
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);
303 $begin_parts = explode(' ', $begin);
304 $curr_date = explode('-',$begin_parts[0]);
306 //Get year and month from time stamp.
307 $curr_year=$curr_date[0];
308 $curr_month=$curr_date[1];
310 if ($curr_month==12) {
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)))));
321 return $this->get_start_end_date_filter($layout_def,$begin,$end);
324 function queryFilterTP_last_30_days(& $layout_def) {
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);
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';
339 return $this->get_start_end_date_filter($layout_def,$begin,$end);
342 function queryFilterTP_next_30_days(& $layout_def) {
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);
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';
357 return $this->get_start_end_date_filter($layout_def,$begin,$end);
361 function queryFilterTP_this_quarter(& $layout_def) {
364 function queryFilterTP_last_year(& $layout_def) {
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);
372 $begin_parts = explode(' ', $begin);
373 $curr_date = explode('-',$begin_parts[0]);
375 //Get year and month from time stamp.
376 $curr_year=$curr_date[0]-1;
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));
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));
384 return $this->get_start_end_date_filter($layout_def,$begin,$end);
387 function queryFilterTP_this_year(& $layout_def) {
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);
393 $begin_parts = explode(' ', $begin);
394 $curr_date = explode('-',$begin_parts[0]);
396 //Get year and month from time stamp.
397 $curr_year=$curr_date[0];
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));
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));
405 return $this->get_start_end_date_filter($layout_def,$begin,$end);
408 function queryFilterTP_next_year(& $layout_def) {
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);
414 $begin_parts = explode(' ', $begin);
415 $curr_date = explode('-',$begin_parts[0]);
417 //Get year and month from time stamp.
418 $curr_year=$curr_date[0]+1;
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));
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));
427 return $this->get_start_end_date_filter($layout_def,$begin,$end);