PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/include/generic/SugarWidgets/SugarWidgetFielddatetime.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 818 lines | 534 code | 161 blank | 123 comment | 108 complexity | ef8b68006510a82183ca5f09cee12d59 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, AGPL-3.0, LGPL-2.1
  1. <?php
  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.
  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. class SugarWidgetFieldDateTime extends SugarWidgetReportField {
  38. var $reporter;
  39. var $assigned_user=null;
  40. function SugarWidgetFieldDateTime(&$layout_manager) {
  41. parent::SugarWidgetReportField($layout_manager);
  42. $this->reporter = $this->layout_manager->getAttribute('reporter');
  43. }
  44. // get the reporter attribute
  45. // deprecated, now called in the constructor
  46. function getReporter() {
  47. // $this->reporter = $this->layout_manager->getAttribute('reporter');
  48. }
  49. // get the assigned user of the report
  50. function getAssignedUser() {
  51. $json_obj = getJSONobj();
  52. $report_def_str = $json_obj->decode($this->reporter->report_def_str);
  53. if(empty($report_def_str['assigned_user_id'])) return false;
  54. $this->assigned_user = new User();
  55. $this->assigned_user->retrieve($report_def_str['assigned_user_id']);
  56. return true;
  57. }
  58. function queryFilterOn(& $layout_def) {
  59. global $timedate;
  60. $begin = $layout_def['input_name0'];
  61. $end = $begin;
  62. $hasTime = $this->hasTime($begin);
  63. if(!$hasTime){
  64. $begin .= " 00:00:00";
  65. $end .= " 23:59:59";
  66. }
  67. if($this->getAssignedUser()) {
  68. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  69. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  70. }
  71. 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";
  72. }
  73. function queryFilterBefore(& $layout_def) {
  74. global $timedate;
  75. $begin = $layout_def['input_name0'];
  76. $hasTime = $this->hasTime($begin);
  77. if(!$hasTime){
  78. $begin .= " 00:00:00";
  79. }
  80. if($this->getAssignedUser()) {
  81. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  82. }
  83. return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."'\n";
  84. }
  85. function queryFilterAfter(& $layout_def) {
  86. global $timedate;
  87. $begin = $layout_def['input_name0'];
  88. $hasTime = $this->hasTime($begin);
  89. if(!$hasTime){
  90. $begin .= ' 23:59:59';
  91. }
  92. if($this->getAssignedUser()) {
  93. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  94. }
  95. return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($begin)."'\n";
  96. }
  97. function queryFilterBetween_Dates(& $layout_def) {
  98. global $timedate;
  99. $begin = $layout_def['input_name0'];
  100. $end = $layout_def['input_name1'];
  101. $beginHasTime = $this->hasTime($begin);
  102. $endHasTime = $this->hasTime($end);
  103. if(!$beginHasTime){
  104. $begin .= " 00:00:00";
  105. }
  106. if(!$endHasTime){
  107. $end .= " 23:59:59";
  108. }
  109. if($this->getAssignedUser()) {
  110. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  111. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  112. }
  113. 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";
  114. }
  115. function queryFilterNot_Equals_str(& $layout_def) {
  116. global $timedate;
  117. $begin = $layout_def['input_name0'];
  118. $end = $begin;
  119. $hasTime = $this->hasTime($begin);
  120. if(!$hasTime){
  121. $begin .= " 00:00:00";
  122. $end .= " 23:59:59";
  123. }
  124. if($this->getAssignedUser()) {
  125. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  126. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  127. }
  128. if ($this->reporter->db->dbType == 'oci8') {
  129. } elseif ($this->reporter->db->dbType == 'mssql'){
  130. 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";
  131. }else{
  132. 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";
  133. }
  134. }
  135. function queryFilterTP_yesterday(& $layout_def) {
  136. global $timedate, $current_user;
  137. $begin_timestamp = time() - 86400;
  138. // begin conversion (same code as queryFilterTP_today)
  139. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  140. //kbrill bug #13884
  141. //$begin = $timedate->to_display_date_time($begin);
  142. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  143. $begin_parts = explode(' ', $begin);
  144. $be = $begin_parts[0] . ' 00:00:00';
  145. $en = $begin_parts[0] . ' 23:59:59';
  146. if($this->getAssignedUser()) {
  147. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  148. $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  149. }
  150. else{
  151. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user); // convert to GMT today relative to assigned_user
  152. $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);
  153. }
  154. if ($this->reporter->db->dbType == 'oci8') {
  155. }
  156. if ($this->reporter->db->dbType == 'mysql')
  157. {
  158. if (isset ($layout_def['rel_field'])) {
  159. $field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";
  160. } else {
  161. $field_name = $this->_get_column_select($layout_def);
  162. }
  163. return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
  164. }
  165. if ($this->reporter->db->dbType == 'mssql')
  166. {
  167. if (isset ($layout_def['rel_field'])) {
  168. $field_name = $this->_get_column_select($layout_def) . " + ' ' + " . $layout_def['rel_field'].")";
  169. } else {
  170. $field_name = $this->_get_column_select($layout_def);
  171. }
  172. return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
  173. }
  174. }
  175. function queryFilterTP_today(& $layout_def) {
  176. global $timedate, $current_user;
  177. $begin_timestamp = time();
  178. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp); // get GMT today
  179. //kbrill bug #13884
  180. //$begin = $timedate->to_display_date_time($begin); // convert and handle offset to user's 'display' today
  181. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  182. $begin_parts = explode(' ', $begin);
  183. $be = $begin_parts[0] . ' 00:00:00';
  184. $en = $begin_parts[0] . ' 23:59:59';
  185. if($this->getAssignedUser()) {
  186. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user); // convert to GMT today relative to assigned_user
  187. $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  188. }
  189. else{
  190. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user); // convert to GMT today relative to assigned_user
  191. $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);
  192. }
  193. if ($this->reporter->db->dbType == 'oci8') {
  194. }elseif($this->reporter->db->dbType == 'mssql'){
  195. if (isset ($layout_def['rel_field'])) {
  196. $field_name = "(".$this->_get_column_select($layout_def)." + ' ' + ".$layout_def['rel_field'].")";
  197. } else {
  198. $field_name = $this->_get_column_select($layout_def);
  199. }
  200. return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
  201. } else {
  202. if (isset ($layout_def['rel_field'])) {
  203. $field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";
  204. } else {
  205. $field_name = $this->_get_column_select($layout_def);
  206. }
  207. return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
  208. }
  209. }
  210. function queryFilterTP_tomorrow(& $layout_def) {
  211. global $timedate, $current_user;
  212. // get tomorrow
  213. $begin_timestamp =time()+ 86400;
  214. // begin conversion (same code as queryFilterTP_today)
  215. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  216. //kbrill bug #13884
  217. //$begin = $timedate->to_display_date_time($begin);
  218. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  219. $begin_parts = explode(' ', $begin);
  220. $be = $begin_parts[0] . ' 00:00:00';
  221. $en = $begin_parts[0] . ' 23:59:59';
  222. if($this->getAssignedUser()) {
  223. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  224. $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  225. }
  226. else{
  227. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $current_user);
  228. $end = $timedate->handle_offset($en, $timedate->get_db_date_time_format(), false, $current_user);
  229. }
  230. if ($this->reporter->db->dbType == 'oci8') {
  231. } else {
  232. 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";
  233. }
  234. }
  235. /**
  236. * Get assigned or logged in user's current date and time value.
  237. * @param boolean $timestamp Format of return value, if set to true, return unix like timestamp , else a formatted date.
  238. */
  239. function get_users_current_date_time($timestamp=false) {
  240. global $current_user;
  241. global $timedate;
  242. $begin = TimeDate::getInstance()->nowDb();
  243. //kbrill bug #13884
  244. //$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);
  245. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  246. if (!$timestamp) {
  247. return $begin;
  248. } else {
  249. $begin_parts = explode(' ', $begin);
  250. $date_parts=explode('-', $begin_parts[0]);
  251. $time_parts=explode(':', $begin_parts[1]);
  252. $curr_timestamp=mktime($time_parts[0],$time_parts[1],0,$date_parts[1], $date_parts[2],$date_parts[0]);
  253. return $curr_timestamp;
  254. }
  255. }
  256. /**
  257. * Get specified date and time for a particalur day, in current user's timezone.
  258. * @param int $days Adjust date by this number of days, negative values are valid.
  259. * @param time string falg for desired time value, start: minimum time, end: maximum time, default: current time
  260. */
  261. function get_db_date($days,$time) {
  262. global $timedate;
  263. $begin = date($GLOBALS['timedate']->get_db_date_time_format(), time()+(86400 * $days)); //gmt date with day adjustment applied.
  264. //kbrill bug #13884
  265. //$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);
  266. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  267. if ($time=='start') {
  268. $begin_parts = explode(' ', $begin);
  269. $be = $begin_parts[0] . ' 00:00:00';
  270. }
  271. else if ($time=='end') {
  272. $begin_parts = explode(' ', $begin);
  273. $be = $begin_parts[0] . ' 23:59:59';
  274. } else {
  275. $be=$begin;
  276. }
  277. //convert date to db format without converting to GMT.
  278. $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  279. return $begin;
  280. }
  281. /**
  282. * Get filter string for a date field.
  283. * @param array layout_def field def for field being filtered
  284. * @param string $begin start date value.
  285. * @param string $end End date value.
  286. */
  287. function get_start_end_date_filter(& $layout_def, $begin,$end) {
  288. if ($this->reporter->db->dbType == 'oci8') {
  289. }elseif($this->reporter->db->dbType == 'mssql'){
  290. if (isset ($layout_def['rel_field'])) {
  291. $field_name = "(".$this->_get_column_select($layout_def)." + ' ' + ".$layout_def['rel_field'].")";
  292. } else {
  293. $field_name = $this->_get_column_select($layout_def);
  294. }
  295. return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
  296. } else {
  297. if (isset ($layout_def['rel_field'])) {
  298. $field_name = "CONCAT(".$this->_get_column_select($layout_def).",' ',".$layout_def['rel_field'].")";
  299. } else {
  300. $field_name = $this->_get_column_select($layout_def);
  301. }
  302. return $field_name.">='".$this->reporter->db->quote($begin)."' AND ".$field_name."<='".$this->reporter->db->quote($end)."'\n";
  303. }
  304. }
  305. function queryFilterTP_last_7_days(& $layout_def) {
  306. $begin=$this->get_db_date(-6,'start');
  307. $end=$this->get_db_date(0,'end');
  308. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  309. }
  310. function queryFilterTP_next_7_days(& $layout_def) {
  311. $begin=$this->get_db_date(0,'start');
  312. $end=$this->get_db_date(6,'end');
  313. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  314. }
  315. function queryFilterTP_last_month(& $layout_def) {
  316. global $timedate;
  317. $curr_timestamp= $this->get_users_current_date_time(true);
  318. //Get year and month from time stamp.
  319. $curr_year=date('Y',$curr_timestamp);
  320. $curr_month=date('m',$curr_timestamp);
  321. //get start date for last month and convert it to gmt and db format.
  322. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 month",mktime(0,0,0,$curr_month,1,$curr_year)));
  323. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  324. //get end date for last month and convert it to gmt and db format.
  325. $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
  326. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  327. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  328. }
  329. function queryFilterTP_this_month(& $layout_def) {
  330. global $timedate;
  331. $curr_timestamp= $this->get_users_current_date_time(true);
  332. //Get year and month from time stamp.
  333. $curr_year=date('Y',$curr_timestamp);
  334. $curr_month=date('m',$curr_timestamp);
  335. //get start date for this month and convert it to gmt and db format.
  336. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
  337. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  338. //get end date for this month and convert it to gmt and db format.
  339. //first get the first day of next month and move back by one day.
  340. if ($curr_month==12) {
  341. $curr_month=1;
  342. $curr_year+=1;
  343. } else {
  344. $curr_month+=1;
  345. }
  346. $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
  347. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  348. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  349. }
  350. function queryFilterTP_next_month(& $layout_def) {
  351. global $timedate;
  352. $curr_timestamp= $this->get_users_current_date_time(true);
  353. //Get year and month from time stamp.
  354. $curr_year=date('Y',$curr_timestamp);
  355. $curr_month=date('m',$curr_timestamp);
  356. if ($curr_month==12) {
  357. $curr_month=1;
  358. $curr_year+=1;
  359. } else {
  360. $curr_month+=1;
  361. }
  362. //get start date for next month and convert it to gmt and db format.
  363. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
  364. $begin=$timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  365. //get end date for next month and convert it to gmt and db format.
  366. //first get first day of the month after and move back by 1 day.
  367. if ($curr_month==12) {
  368. $curr_month=1;
  369. $curr_year+=1;
  370. } else {
  371. $curr_month+=1;
  372. }
  373. $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",(strtotime("1 month",mktime(23,59,59,$curr_month,1,$curr_year)))));
  374. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  375. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  376. }
  377. function queryFilterTP_last_30_days(& $layout_def) {
  378. $begin=$this->get_db_date(-29,'start');
  379. $end=$this->get_db_date(0,'end');
  380. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  381. }
  382. function queryFilterTP_next_30_days(& $layout_def) {
  383. $begin=$this->get_db_date(0,'start');
  384. $end=$this->get_db_date(29,'end');
  385. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  386. }
  387. function queryFilterTP_last_quarter(& $layout_def) {
  388. // return "LEFT(".$this->_get_column_select($layout_def).",10) BETWEEN (current_date + interval '1' month) AND current_date";
  389. }
  390. function queryFilterTP_this_quarter(& $layout_def) {
  391. }
  392. function queryFilterTP_last_year(& $layout_def) {
  393. global $timedate;
  394. $curr_timestamp= $this->get_users_current_date_time(true);
  395. //Get year and month from time stamp.
  396. $curr_year=date('Y',$curr_timestamp);
  397. $curr_year-=1;
  398. //get start date for last year and convert it to gmt and db format.
  399. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
  400. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  401. //get end date for last year and convert it to gmt and db format.
  402. $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
  403. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  404. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  405. }
  406. function queryFilterTP_this_year(& $layout_def) {
  407. global $timedate;
  408. $curr_timestamp= $this->get_users_current_date_time(true);
  409. //Get year and month from time stamp.
  410. $curr_year=date('Y',$curr_timestamp);
  411. //get start date for this year and convert it to gmt and db format.
  412. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
  413. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  414. //get end date for this year and convert it to gmt and db format.
  415. $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
  416. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  417. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  418. }
  419. function queryFilterTP_next_year(& $layout_def) {
  420. global $timedate;
  421. $curr_timestamp= $this->get_users_current_date_time(true);
  422. //Get year and month from time stamp.
  423. $curr_year=date('Y',$curr_timestamp);
  424. $curr_year+=1;
  425. //get start date for this year and convert it to gmt and db format.
  426. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
  427. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  428. //get end date for this year and convert it to gmt and db format.
  429. $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
  430. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  431. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  432. }
  433. function queryGroupBy($layout_def) {
  434. // i guess qualifier and column_function are the same..
  435. if (!empty ($layout_def['qualifier'])) {
  436. $func_name = 'queryGroupBy'.$layout_def['qualifier'];
  437. //print_r($layout_def);
  438. //print $func_name;
  439. if (method_exists($this, $func_name)) {
  440. return $this-> $func_name ($layout_def)." \n";
  441. }
  442. }
  443. return parent :: queryGroupBy($layout_def)." \n";
  444. }
  445. function queryOrderBy($layout_def) {
  446. // i guess qualifier and column_function are the same..
  447. if ($this->reporter->db->dbType == 'mssql'){
  448. //do nothing if this is for mssql, do not run group by
  449. }
  450. elseif (!empty ($layout_def['qualifier'])) {
  451. $func_name ='queryGroupBy'.$layout_def['qualifier'];
  452. if (method_exists($this, $func_name)) {
  453. return $this-> $func_name ($layout_def)."\n";
  454. }
  455. }
  456. $order_by = parent :: queryOrderBy($layout_def)."\n";
  457. return $order_by;
  458. }
  459. function displayListPlain($layout_def) {
  460. global $timedate;
  461. $content = parent:: displayListPlain($layout_def);
  462. // awu: this if condition happens only in Reports where group by month comes back as YYYY-mm format
  463. if (count(explode('-',$content)) == 2){
  464. return $content;
  465. // if date field
  466. }elseif(substr_count($layout_def['type'], 'date') > 0){
  467. // if date time field
  468. if(substr_count($layout_def['type'], 'time') > 0 && $this->get_time_part($content)!= false){
  469. $td = $timedate->to_display_date_time($content);
  470. return $td;
  471. }else{// if date only field
  472. $td = $timedate->to_display_date($content, false); // avoid php notice of returing by reference
  473. return $td;
  474. }
  475. }
  476. }
  477. function get_time_part($date_time_value) {
  478. $date_parts=explode(' ', $date_time_value);
  479. if (count($date_parts) == 2) {
  480. $time=$date_parts[1];
  481. } else {
  482. $time=false;
  483. }
  484. return $time;
  485. }
  486. function displayList($layout_def) {
  487. global $timedate;
  488. // i guess qualifier and column_function are the same..
  489. if (!empty ($layout_def['column_function'])) {
  490. $func_name = 'displayList'.$layout_def['column_function'];
  491. if (method_exists($this, $func_name)) {
  492. return $this-> $func_name ($layout_def);
  493. }
  494. }
  495. $content = parent :: displayListPlain($layout_def);
  496. return $timedate->to_display_date_time($content);
  497. }
  498. function querySelect(& $layout_def) {
  499. // i guess qualifier and column_function are the same..
  500. if (!empty ($layout_def['column_function'])) {
  501. $func_name = 'querySelect'.$layout_def['column_function'];
  502. if (method_exists($this, $func_name)) {
  503. return $this-> $func_name ($layout_def)." \n";
  504. }
  505. }
  506. return parent :: querySelect($layout_def)." \n";
  507. }
  508. function & displayListday(& $layout_def) {
  509. return parent:: displayListPlain($layout_def);
  510. }
  511. function & displayListyear(& $layout_def) {
  512. global $app_list_strings;
  513. //if ($this->reporter->db->dbType == 'oci8' || $this->reporter->db->dbType == 'mssql') {
  514. return parent:: displayListPlain($layout_def);
  515. //}
  516. /*else{
  517. $match = array();
  518. if (preg_match('/(\d{4})/', $this->displayListPlain($layout_def), $match)) {
  519. return $match[1];
  520. }
  521. $temp = null; // avoid notices
  522. return $temp;
  523. }*/
  524. }
  525. function & displayListmonth(& $layout_def) {
  526. global $app_list_strings;
  527. $display = '';
  528. $match = array();
  529. if (preg_match('/(\d{4})-(\d\d)/', $this->displayListPlain($layout_def), $match)) {
  530. $match[2] = preg_replace('/^0/', '', $match[2]);
  531. $display = $app_list_strings['dom_cal_month_long'][$match[2]]." {$match[1]}";
  532. }
  533. return $display;
  534. }
  535. function querySelectmonth(& $layout_def) {
  536. if ($this->reporter->db->dbType == 'oci8') {
  537. }elseif($this->reporter->db->dbType == 'mssql') {
  538. //return "LEFT( ".$this->_get_column_select($layout_def).",6 ) ".$this->_get_column_alias($layout_def)." \n";
  539. return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),7)".$this->_get_column_alias($layout_def)." \n";
  540. } else {
  541. return "LEFT( ".$this->_get_column_select($layout_def).",7 ) ".$this->_get_column_alias($layout_def)." \n";
  542. }
  543. }
  544. function queryGroupByMonth($layout_def) {
  545. if ($this->reporter->db->dbType == 'oci8') {
  546. }elseif($this->reporter->db->dbType == 'mssql') {
  547. //return "LEFT(".$this->_get_column_select($layout_def).", 6) \n";
  548. return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ", 121),7) \n";
  549. }else {
  550. return "LEFT(".$this->_get_column_select($layout_def).", 7) \n";
  551. }
  552. }
  553. function querySelectday($layout_def) {
  554. if ($this->reporter->db->dbType == 'oci8') {
  555. }elseif($this->reporter->db->dbType == 'mssql') {
  556. //return "LEFT(".$this->_get_column_select($layout_def).", 6) \n";
  557. return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),10)".$this->_get_column_alias($layout_def)." \n";
  558. }else {
  559. return "LEFT(".$this->_get_column_select($layout_def).", 10)".$this->_get_column_alias($layout_def)." \n";
  560. }
  561. }
  562. function queryGroupByDay($layout_def) {
  563. if ($this->reporter->db->dbType == 'oci8') {
  564. }elseif($this->reporter->db->dbType == 'mssql') {
  565. //return "LEFT(".$this->_get_column_select($layout_def).", 6) \n";
  566. return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ", 121),10) \n";
  567. }else {
  568. return "LEFT(".$this->_get_column_select($layout_def).", 10) \n";
  569. }
  570. }
  571. function querySelectyear(& $layout_def) {
  572. if ($this->reporter->db->dbType == 'oci8') {
  573. }elseif($this->reporter->db->dbType == 'mssql') {
  574. //return "LEFT( ".$this->_get_column_select($layout_def).",5 ) ".$this->_get_column_alias($layout_def)." \n";
  575. return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),4) ".$this->_get_column_alias($layout_def)." \n";
  576. } else {
  577. return "LEFT( ".$this->_get_column_select($layout_def).",4 ) ".$this->_get_column_alias($layout_def)." \n";
  578. }
  579. }
  580. function queryGroupByYear($layout_def) {
  581. if ($this->reporter->db->dbType == 'oci8') {
  582. }elseif($this->reporter->db->dbType == 'mssql') {
  583. //return "LEFT(".$this->_get_column_select($layout_def).", 5) \n";
  584. return "LEFT(CONVERT (varchar(20), ". $this->_get_column_select($layout_def). ",121),4) \n";
  585. } else {
  586. return "LEFT(".$this->_get_column_select($layout_def).", 4) \n";
  587. }
  588. }
  589. function querySelectquarter(& $layout_def) {
  590. if ($this->reporter->db->dbType == 'oci8') {
  591. }
  592. elseif ($this->reporter->db->dbType == 'mysql')
  593. {
  594. return "CONCAT(LEFT(".$this->_get_column_select($layout_def).", 4), '-', QUARTER(".$this->_get_column_select($layout_def).") )".$this->_get_column_alias($layout_def)."\n";
  595. }
  596. elseif ($this->reporter->db->dbType == 'mssql')
  597. {
  598. //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";
  599. 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";
  600. }
  601. }
  602. function displayListquarter(& $layout_def) {
  603. $match = array();
  604. if (preg_match('/(\d{4})-(\d)/', $this->displayListPlain($layout_def), $match)) {
  605. return "Q".$match[2]." ".$match[1];
  606. }
  607. return '';
  608. }
  609. function queryGroupByQuarter($layout_def) {
  610. $this->getReporter();
  611. if ($this->reporter->db->dbType == 'oci8') {
  612. }elseif ($this->reporter->db->dbType == 'mysql')
  613. {
  614. return "CONCAT(LEFT(".$this->_get_column_select($layout_def).", 4), '-', QUARTER(".$this->_get_column_select($layout_def).") )\n";
  615. }
  616. elseif ($this->reporter->db->dbType == 'mssql')
  617. {
  618. //return "LEFT(".$this->_get_column_select($layout_def).", 4) + '-' + convert(varchar(20), DatePart(q," . $this->_get_column_select($layout_def).") )\n";
  619. 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";
  620. }
  621. }
  622. function displayInput(&$layout_def) {
  623. global $timedate, $current_language, $app_strings;
  624. $home_mod_strings = return_module_language($current_language, 'Home');
  625. $filterTypes = array(' ' => $app_strings['LBL_NONE'],
  626. 'TP_today' => $home_mod_strings['LBL_TODAY'],
  627. 'TP_yesterday' => $home_mod_strings['LBL_YESTERDAY'],
  628. 'TP_tomorrow' => $home_mod_strings['LBL_TOMORROW'],
  629. 'TP_this_month' => $home_mod_strings['LBL_THIS_MONTH'],
  630. 'TP_this_year' => $home_mod_strings['LBL_THIS_YEAR'],
  631. 'TP_last_30_days' => $home_mod_strings['LBL_LAST_30_DAYS'],
  632. 'TP_last_7_days' => $home_mod_strings['LBL_LAST_7_DAYS'],
  633. 'TP_last_month' => $home_mod_strings['LBL_LAST_MONTH'],
  634. 'TP_last_year' => $home_mod_strings['LBL_LAST_YEAR'],
  635. 'TP_next_30_days' => $home_mod_strings['LBL_NEXT_30_DAYS'],
  636. 'TP_next_7_days' => $home_mod_strings['LBL_NEXT_7_DAYS'],
  637. 'TP_next_month' => $home_mod_strings['LBL_NEXT_MONTH'],
  638. 'TP_next_year' => $home_mod_strings['LBL_NEXT_YEAR'],
  639. );
  640. $cal_dateformat = $timedate->get_cal_date_format();
  641. $str = "<select name='type_{$layout_def['name']}'>";
  642. $str .= get_select_options_with_id($filterTypes, (empty($layout_def['input_name0']) ? '' : $layout_def['input_name0']));
  643. // foreach($filterTypes as $value => $label) {
  644. // $str .= '<option value="' . $value . '">' . $label. '</option>';
  645. // }
  646. $str .= "</select>";
  647. return $str;
  648. }
  649. /**
  650. * @param $date
  651. * @return bool false if the date is a only a date, true if the date includes time.
  652. */
  653. protected function hasTime($date)
  654. {
  655. return strlen(trim($date)) < 11 ? false : true;
  656. }
  657. }