2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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 ********************************************************************************/
41 class SugarWidgetFieldDateTime extends SugarWidgetReportField {
43 var $assigned_user=null;
45 function SugarWidgetFieldDateTime(&$layout_manager) {
46 parent::SugarWidgetReportField($layout_manager);
47 $this->reporter = $this->layout_manager->getAttribute('reporter');
50 // get the reporter attribute
51 // deprecated, now called in the constructor
52 function getReporter() {
53 // $this->reporter = $this->layout_manager->getAttribute('reporter');
56 // get the assigned user of the report
57 function getAssignedUser() {
58 $json_obj = getJSONobj();
60 $report_def_str = $json_obj->decode($this->reporter->report_def_str);
62 if(empty($report_def_str['assigned_user_id'])) return false;
64 $this->assigned_user = new User();
65 $this->assigned_user->retrieve($report_def_str['assigned_user_id']);
69 function queryFilterOn(& $layout_def) {
71 if($this->getAssignedUser()) {
72 $begin = $timedate->handle_offset($layout_def['input_name0'] . ' 00:00:00', $timedate->get_db_date_time_format(), false, $this->assigned_user);
73 $end = $timedate->handle_offset($layout_def['input_name0'] . ' 23:59:59', $timedate->get_db_date_time_format(), false, $this->assigned_user);
76 $begin = $layout_def['input_name0']." 00:00:00";
77 $end = $layout_def['input_name0']." 23:59:59";
80 return $this->_get_column_select($layout_def).">='".$this->reporter->db->quote($begin)."' AND ".$this->_get_column_select($layout_def)."<='".$this->reporter->db->quote($end)."'\n";
83 function queryFilterBefore(& $layout_def) {
86 if($this->getAssignedUser()) {
87 $begin = $timedate->handle_offset($layout_def['input_name0'] . ' 00:00:00', $timedate->get_db_date_time_format(), false, $this->assigned_user);
90 $begin = $layout_def['input_name0']." 00:00:00";
93 return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."'\n";
97 function queryFilterAfter(& $layout_def) {
100 if($this->getAssignedUser()) {
101 $begin = $timedate->handle_offset($layout_def['input_name0'] . ' 23:59:59', $timedate->get_db_date_time_format(), false, $this->assigned_user);
104 $begin = $layout_def['input_name0']." 23:59:59";
107 return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($begin)."'\n";
110 function queryFilterBetween_Dates(& $layout_def) {
113 if($this->getAssignedUser()) {
114 $begin = $timedate->handle_offset($layout_def['input_name0'] . ' 00:00:00', $timedate->get_db_date_time_format(), false, $this->assigned_user);
115 $end = $timedate->handle_offset($layout_def['input_name1'] . ' 23:59:59', $timedate->get_db_date_time_format(), false, $this->assigned_user);
118 $begin = $layout_def['input_name0']." 00:00:00";
119 $end = $layout_def['input_name1']." 23:59:59";
122 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";
125 function queryFilterNot_Equals_str(& $layout_def) {
128 if($this->getAssignedUser()) {
129 $begin = $timedate->handle_offset($layout_def['input_name0'] . ' 00:00:00', $timedate->get_db_date_time_format(), false, $this->assigned_user);
130 $end = $timedate->handle_offset($layout_def['input_name0'] . ' 23:59:59', $timedate->get_db_date_time_format(), false, $this->assigned_user);
133 $begin = $layout_def['input_name0']." 00:00:00";
134 $end = $layout_def['input_name0']." 23:59:59";
137 if ($this->reporter->db->dbType == 'oci8') {
139 } elseif ($this->reporter->db->dbType == 'mssql'){
140 return "(".$this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."' OR ".$this->_get_column_select($layout_def).">'".$this->reporter->db->quote($end)."')\n";
143 return "ISNULL(".$this->_get_column_select($layout_def).") OR \n(".$this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."' OR ".$this->_get_column_select($layout_def).">'".$this->reporter->db->quote($end)."')\n";
147 function queryFilterTP_yesterday(& $layout_def) {
148 global $timedate, $current_user;
150 $begin_timestamp = time() - 86400;
152 // begin conversion (same code as queryFilterTP_today)
153 $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
155 //$begin = $timedate->to_display_date_time($begin);
156 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
158 $begin_parts = explode(' ', $begin);
160 $be = $begin_parts[0] . ' 00:00:00';
161 $en = $begin_parts[0] . ' 23:59:59';
163 if($this->getAssignedUser()) {
164 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
165 $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);
168 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user); // convert to GMT today relative to assigned_user
169 $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);
172 if ($this->reporter->db->dbType == 'oci8') {
176 if ($this->reporter->db->dbType == 'mysql')
178 if (isset ($layout_def['rel_field'])) {
179 $field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";
181 $field_name = $this->_get_column_select($layout_def);
183 return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
186 if ($this->reporter->db->dbType == 'mssql')
188 if (isset ($layout_def['rel_field'])) {
189 $field_name = $this->_get_column_select($layout_def) . " + ' ' + " . $layout_def['rel_field'].")";
191 $field_name = $this->_get_column_select($layout_def);
193 return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
196 function queryFilterTP_today(& $layout_def) {
197 global $timedate, $current_user;
199 $begin_timestamp = time();
200 $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp); // get GMT today
202 //$begin = $timedate->to_display_date_time($begin); // convert and handle offset to user's 'display' today
203 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
205 $begin_parts = explode(' ', $begin);
207 $be = $begin_parts[0] . ' 00:00:00';
208 $en = $begin_parts[0] . ' 23:59:59';
210 if($this->getAssignedUser()) {
211 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user); // convert to GMT today relative to assigned_user
212 $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);
215 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user); // convert to GMT today relative to assigned_user
216 $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);
219 if ($this->reporter->db->dbType == 'oci8') {
221 }elseif($this->reporter->db->dbType == 'mssql'){
222 if (isset ($layout_def['rel_field'])) {
223 $field_name = "(".$this->_get_column_select($layout_def)." + ' ' + ".$layout_def['rel_field'].")";
225 $field_name = $this->_get_column_select($layout_def);
227 return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
230 if (isset ($layout_def['rel_field'])) {
231 $field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";
233 $field_name = $this->_get_column_select($layout_def);
235 return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
239 function queryFilterTP_tomorrow(& $layout_def) {
240 global $timedate, $current_user;
243 $begin_timestamp =time()+ 86400;
245 // begin conversion (same code as queryFilterTP_today)
246 $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
248 //$begin = $timedate->to_display_date_time($begin);
249 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
251 $begin_parts = explode(' ', $begin);
253 $be = $begin_parts[0] . ' 00:00:00';
254 $en = $begin_parts[0] . ' 23:59:59';
256 if($this->getAssignedUser()) {
257 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
258 $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);
261 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user);
262 $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);
265 if ($this->reporter->db->dbType == 'oci8') {
267 return $this->_get_column_select($layout_def).">='".$this->reporter->db->quote($begin)."' AND ".$this->_get_column_select($layout_def)."<='".$this->reporter->db->quote($end)."'\n";
272 * Get assigned or logged in user's current date and time value.
273 * @param boolean $timestamp Format of return value, if set to true, return unix like timestamp , else a formatted date.
275 function get_users_current_date_time($timestamp=false) {
276 global $current_user;
279 $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format());
281 //$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);
282 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
287 $begin_parts = explode(' ', $begin);
288 $date_parts=explode('-', $begin_parts[0]);
289 $time_parts=explode(':', $begin_parts[1]);
290 $curr_timestamp=mktime($time_parts[0],$time_parts[1],0,$date_parts[1], $date_parts[2],$date_parts[0]);
291 return $curr_timestamp;
296 * Get specified date and time for a particalur day, in current user's timezone.
297 * @param int $days Adjust date by this number of days, negative values are valid.
298 * @param time string falg for desired time value, start: minimum time, end: maximum time, default: current time
300 function get_db_date($days,$time) {
303 $begin = date($GLOBALS['timedate']->get_db_date_time_format(), time()+(86400 * $days)); //gmt date with day adjustment applied.
305 //$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);
306 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
308 if ($time=='start') {
309 $begin_parts = explode(' ', $begin);
310 $be = $begin_parts[0] . ' 00:00:00';
312 else if ($time=='end') {
313 $begin_parts = explode(' ', $begin);
314 $be = $begin_parts[0] . ' 23:59:59';
319 //convert date to db format without converting to GMT.
320 $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
326 * Get filter string for a date field.
327 * @param array layout_def field def for field being filtered
328 * @param string $begin start date value.
329 * @param string $end End date value.
331 function get_start_end_date_filter(& $layout_def, $begin,$end) {
333 if ($this->reporter->db->dbType == 'oci8') {
335 }elseif($this->reporter->db->dbType == 'mssql'){
336 if (isset ($layout_def['rel_field'])) {
337 $field_name = "(".$this->_get_column_select($layout_def)." + ' ' + ".$layout_def['rel_field'].")";
339 $field_name = $this->_get_column_select($layout_def);
341 return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
344 if (isset ($layout_def['rel_field'])) {
345 $field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";
347 $field_name = $this->_get_column_select($layout_def);
349 return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
353 function queryFilterTP_last_7_days(& $layout_def) {
355 $begin=$this->get_db_date(-6,'start');
356 $end=$this->get_db_date(0,'end');
359 return $this->get_start_end_date_filter($layout_def,$begin,$end);
363 function queryFilterTP_next_7_days(& $layout_def) {
365 $begin=$this->get_db_date(0,'start');
366 $end=$this->get_db_date(6,'end');
368 return $this->get_start_end_date_filter($layout_def,$begin,$end);
371 function queryFilterTP_last_month(& $layout_def) {
374 $curr_timestamp= $this->get_users_current_date_time(true);
376 //Get year and month from time stamp.
377 $curr_year=date('Y',$curr_timestamp);
378 $curr_month=date('m',$curr_timestamp);
380 //get start date for last month and convert it to gmt and db format.
381 $begin=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 month",mktime(0,0,0,$curr_month,1,$curr_year)));
382 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
384 //get end date for last month and convert it to gmt and db format.
385 $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
386 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
388 return $this->get_start_end_date_filter($layout_def,$begin,$end);
391 function queryFilterTP_this_month(& $layout_def) {
394 $curr_timestamp= $this->get_users_current_date_time(true);
396 //Get year and month from time stamp.
397 $curr_year=date('Y',$curr_timestamp);
398 $curr_month=date('m',$curr_timestamp);
400 //get start date for this month and convert it to gmt and db format.
401 $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
402 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
404 //get end date for this month and convert it to gmt and db format.
405 //first get the first day of next month and move back by one day.
406 if ($curr_month==12) {
412 $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
413 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
416 return $this->get_start_end_date_filter($layout_def,$begin,$end);
419 function queryFilterTP_next_month(& $layout_def) {
422 $curr_timestamp= $this->get_users_current_date_time(true);
424 //Get year and month from time stamp.
425 $curr_year=date('Y',$curr_timestamp);
426 $curr_month=date('m',$curr_timestamp);
427 if ($curr_month==12) {
434 //get start date for next month and convert it to gmt and db format.
435 $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
436 $begin=$timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
438 //get end date for next month and convert it to gmt and db format.
439 //first get first day of the month after and move back by 1 day.
440 if ($curr_month==12) {
446 $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",(strtotime("1 month",mktime(23,59,59,$curr_month,1,$curr_year)))));
447 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
450 return $this->get_start_end_date_filter($layout_def,$begin,$end);
453 function queryFilterTP_last_30_days(& $layout_def) {
455 $begin=$this->get_db_date(-29,'start');
456 $end=$this->get_db_date(0,'end');
458 return $this->get_start_end_date_filter($layout_def,$begin,$end);
461 function queryFilterTP_next_30_days(& $layout_def) {
462 $begin=$this->get_db_date(0,'start');
463 $end=$this->get_db_date(29,'end');
465 return $this->get_start_end_date_filter($layout_def,$begin,$end);
468 function queryFilterTP_last_quarter(& $layout_def) {
469 // return "LEFT(".$this->_get_column_select($layout_def).",10) BETWEEN (current_date + interval '1' month) AND current_date";
472 function queryFilterTP_this_quarter(& $layout_def) {
475 function queryFilterTP_last_year(& $layout_def) {
478 $curr_timestamp= $this->get_users_current_date_time(true);
480 //Get year and month from time stamp.
481 $curr_year=date('Y',$curr_timestamp);
484 //get start date for last year and convert it to gmt and db format.
485 $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
486 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
488 //get end date for last year and convert it to gmt and db format.
489 $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
490 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
492 return $this->get_start_end_date_filter($layout_def,$begin,$end);
495 function queryFilterTP_this_year(& $layout_def) {
497 $curr_timestamp= $this->get_users_current_date_time(true);
499 //Get year and month from time stamp.
500 $curr_year=date('Y',$curr_timestamp);
502 //get start date for this year and convert it to gmt and db format.
503 $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
504 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
506 //get end date for this year and convert it to gmt and db format.
507 $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
508 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
510 return $this->get_start_end_date_filter($layout_def,$begin,$end);
513 function queryFilterTP_next_year(& $layout_def) {
515 $curr_timestamp= $this->get_users_current_date_time(true);
517 //Get year and month from time stamp.
518 $curr_year=date('Y',$curr_timestamp);
521 //get start date for this year and convert it to gmt and db format.
522 $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
523 $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
525 //get end date for this year and convert it to gmt and db format.
526 $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
527 $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
529 return $this->get_start_end_date_filter($layout_def,$begin,$end);
532 function queryGroupBy($layout_def) {
533 // i guess qualifier and column_function are the same..
534 if (!empty ($layout_def['qualifier'])) {
535 $func_name = 'queryGroupBy'.$layout_def['qualifier'];
536 //print_r($layout_def);
538 if (method_exists($this, $func_name)) {
539 return $this-> $func_name ($layout_def)." \n";
542 return parent :: queryGroupBy($layout_def)." \n";
545 function queryOrderBy($layout_def) {
546 // i guess qualifier and column_function are the same..
547 if ($this->reporter->db->dbType == 'mssql'){
548 //do nothing if this is for mssql, do not run group by
551 elseif (!empty ($layout_def['qualifier'])) {
552 $func_name ='queryGroupBy'.$layout_def['qualifier'];
553 if (method_exists($this, $func_name)) {
554 return $this-> $func_name ($layout_def)."\n";
557 $order_by = parent :: queryOrderBy($layout_def)."\n";
561 function displayListPlain($layout_def) {
563 $content = parent:: displayListPlain($layout_def);
564 // awu: this if condition happens only in Reports where group by month comes back as YYYY-mm format
565 if (count(explode('-',$content)) == 2){
568 }elseif(substr_count($layout_def['type'], 'date') > 0){
569 // if date time field
570 if(substr_count($layout_def['type'], 'time') > 0 && $this->get_time_part($content)!= false){
571 $td = $timedate->to_display_date_time($content);
573 }else{// if date only field
574 $td = $timedate->to_display_date($content, false); // avoid php notice of returing by reference
579 function get_time_part($date_time_value) {
580 $date_parts=explode(' ', $date_time_value);
581 if (count($date_parts) == 2) {
582 $time=$date_parts[1];
589 function displayList($layout_def) {
591 // i guess qualifier and column_function are the same..
592 if (!empty ($layout_def['column_function'])) {
593 $func_name = 'displayList'.$layout_def['column_function'];
594 if (method_exists($this, $func_name)) {
595 return $this-> $func_name ($layout_def);
598 $content = parent :: displayListPlain($layout_def);
599 return $timedate->to_display_date_time($content);
602 function querySelect(& $layout_def) {
603 // i guess qualifier and column_function are the same..
604 if (!empty ($layout_def['column_function'])) {
605 $func_name = 'querySelect'.$layout_def['column_function'];
606 if (method_exists($this, $func_name)) {
607 return $this-> $func_name ($layout_def)." \n";
610 return parent :: querySelect($layout_def)." \n";
612 function & displayListday(& $layout_def) {
613 return parent:: displayListPlain($layout_def);
616 function & displayListyear(& $layout_def) {
617 global $app_list_strings;
618 //if ($this->reporter->db->dbType == 'oci8' || $this->reporter->db->dbType == 'mssql') {
619 return parent:: displayListPlain($layout_def);
623 if (preg_match('/(\d{4})/', $this->displayListPlain($layout_def), $match)) {
626 $temp = null; // avoid notices
631 function & displayListmonth(& $layout_def) {
632 global $app_list_strings;
635 if (preg_match('/(\d{4})-(\d\d)/', $this->displayListPlain($layout_def), $match)) {
636 $match[2] = preg_replace('/^0/', '', $match[2]);
637 $display = $app_list_strings['dom_cal_month_long'][$match[2]]." {$match[1]}";
642 function querySelectmonth(& $layout_def) {
643 if ($this->reporter->db->dbType == 'oci8') {
644 }elseif($this->reporter->db->dbType == 'mssql') {
645 //return "LEFT( ".$this->_get_column_select($layout_def).",6 ) ".$this->_get_column_alias($layout_def)." \n";
646 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),7)".$this->_get_column_alias($layout_def)." \n";
649 return "LEFT( ".$this->_get_column_select($layout_def).",7 ) ".$this->_get_column_alias($layout_def)." \n";
653 function queryGroupByMonth($layout_def) {
654 if ($this->reporter->db->dbType == 'oci8') {
655 }elseif($this->reporter->db->dbType == 'mssql') {
656 //return "LEFT(".$this->_get_column_select($layout_def).", 6) \n";
657 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ", 121),7) \n";
660 return "LEFT(".$this->_get_column_select($layout_def).", 7) \n";
664 function querySelectday($layout_def) {
665 if ($this->reporter->db->dbType == 'oci8') {
666 }elseif($this->reporter->db->dbType == 'mssql') {
667 //return "LEFT(".$this->_get_column_select($layout_def).", 6) \n";
668 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),10)".$this->_get_column_alias($layout_def)." \n";
671 return "LEFT(".$this->_get_column_select($layout_def).", 10)".$this->_get_column_alias($layout_def)." \n";
675 function queryGroupByDay($layout_def) {
676 if ($this->reporter->db->dbType == 'oci8') {
677 }elseif($this->reporter->db->dbType == 'mssql') {
678 //return "LEFT(".$this->_get_column_select($layout_def).", 6) \n";
679 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ", 121),10) \n";
682 return "LEFT(".$this->_get_column_select($layout_def).", 10) \n";
687 function querySelectyear(& $layout_def) {
688 if ($this->reporter->db->dbType == 'oci8') {
689 }elseif($this->reporter->db->dbType == 'mssql') {
690 //return "LEFT( ".$this->_get_column_select($layout_def).",5 ) ".$this->_get_column_alias($layout_def)." \n";
691 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),4) ".$this->_get_column_alias($layout_def)." \n";
694 return "LEFT( ".$this->_get_column_select($layout_def).",4 ) ".$this->_get_column_alias($layout_def)." \n";
698 function queryGroupByYear($layout_def) {
699 if ($this->reporter->db->dbType == 'oci8') {
700 }elseif($this->reporter->db->dbType == 'mssql') {
701 //return "LEFT(".$this->_get_column_select($layout_def).", 5) \n";
702 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),4) \n";
705 return "LEFT(".$this->_get_column_select($layout_def).", 4) \n";
709 function querySelectquarter(& $layout_def) {
710 if ($this->reporter->db->dbType == 'oci8') {
713 elseif ($this->reporter->db->dbType == 'mysql')
715 return "CONCAT(LEFT(".$this->_get_column_select($layout_def).", 4), '-', QUARTER(".$this->_get_column_select($layout_def).") )".$this->_get_column_alias($layout_def)."\n";
718 elseif ($this->reporter->db->dbType == 'mssql')
720 //return "LEFT(".$this->_get_column_select($layout_def).", 4) + '-' + convert(varchar(20), DatePart(q," . $this->_get_column_select($layout_def).") ) ".$this->_get_column_alias($layout_def)."\n";
721 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),4)+ '-' + convert(varchar(20), DatePart(q," . $this->_get_column_select($layout_def).") ) ".$this->_get_column_alias($layout_def)."\n";
728 function displayListquarter(& $layout_def) {
730 if (preg_match('/(\d{4})-(\d)/', $this->displayListPlain($layout_def), $match)) {
731 return "Q".$match[2]." ".$match[1];
737 function queryGroupByQuarter($layout_def) {
738 $this->getReporter();
740 if ($this->reporter->db->dbType == 'oci8') {
742 }elseif ($this->reporter->db->dbType == 'mysql')
744 return "CONCAT(LEFT(".$this->_get_column_select($layout_def).", 4), '-', QUARTER(".$this->_get_column_select($layout_def).") )\n";
746 elseif ($this->reporter->db->dbType == 'mssql')
748 //return "LEFT(".$this->_get_column_select($layout_def).", 4) + '-' + convert(varchar(20), DatePart(q," . $this->_get_column_select($layout_def).") )\n";
749 return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),4) + '-' + convert(varchar(20), DatePart(q," . $this->_get_column_select($layout_def).") )\n";
756 function displayInput(&$layout_def) {
757 global $timedate, $current_language, $app_strings;
758 $home_mod_strings = return_module_language($current_language, 'Home');
759 $filterTypes = array(' ' => $app_strings['LBL_NONE'],
760 'TP_today' => $home_mod_strings['LBL_TODAY'],
761 'TP_yesterday' => $home_mod_strings['LBL_YESTERDAY'],
762 'TP_tomorrow' => $home_mod_strings['LBL_TOMORROW'],
763 'TP_this_month' => $home_mod_strings['LBL_THIS_MONTH'],
764 'TP_this_year' => $home_mod_strings['LBL_THIS_YEAR'],
765 'TP_last_30_days' => $home_mod_strings['LBL_LAST_30_DAYS'],
766 'TP_last_7_days' => $home_mod_strings['LBL_LAST_7_DAYS'],
767 'TP_last_month' => $home_mod_strings['LBL_LAST_MONTH'],
768 'TP_last_year' => $home_mod_strings['LBL_LAST_YEAR'],
769 'TP_next_30_days' => $home_mod_strings['LBL_NEXT_30_DAYS'],
770 'TP_next_7_days' => $home_mod_strings['LBL_NEXT_7_DAYS'],
771 'TP_next_month' => $home_mod_strings['LBL_NEXT_MONTH'],
772 'TP_next_year' => $home_mod_strings['LBL_NEXT_YEAR'],
775 $cal_dateformat = $timedate->get_cal_date_format();
776 $str = "<select name='type_{$layout_def['name']}'>";
777 $str .= get_select_options_with_id($filterTypes, (empty($layout_def['input_name0']) ? '' : $layout_def['input_name0']));
778 // foreach($filterTypes as $value => $label) {
779 // $str .= '<option value="' . $value . '">' . $label. '</option>';