PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/include/generic/SugarWidgets/SugarWidgetFielddate.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 434 lines | 274 code | 106 blank | 54 comment | 20 complexity | fd743d90553bb939b2fd5e8c47064e60 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. require_once('include/generic/SugarWidgets/SugarWidgetFielddatetime.php');
  38. class SugarWidgetFieldDate extends SugarWidgetFieldDateTime
  39. {
  40. function & displayList($layout_def)
  41. {
  42. global $timedate;
  43. // i guess qualifier and column_function are the same..
  44. if (! empty($layout_def['column_function']))
  45. {
  46. $func_name = 'displayList'.$layout_def['column_function'];
  47. if ( method_exists($this,$func_name))
  48. {
  49. $display = $this->$func_name($layout_def);
  50. return $display;
  51. }
  52. }
  53. $content = $this->displayListPlain($layout_def);
  54. return $content;
  55. }
  56. function get_date_part($date_time_value){
  57. $date_parts=explode(' ', $date_time_value);
  58. if (count($date_parts) == 2) {
  59. $date=$date_parts[0];
  60. } else {
  61. $date=$date_time_value;
  62. }
  63. return $date;
  64. }
  65. function get_db_date($days,$time) {
  66. global $timedate;
  67. $begin = date($GLOBALS['timedate']->get_db_date_time_format(), time()+(86400 * $days)); //gmt date with day adjustment applied.
  68. // $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
  69. if ($time=='start') {
  70. $begin_parts = explode(' ', $begin);
  71. $begin = $begin_parts[0] . ' 00:00:00';
  72. }
  73. else if ($time=='end') {
  74. $begin_parts = explode(' ', $begin);
  75. $begin = $begin_parts[0] . ' 23:59:59';
  76. }
  77. return $begin;
  78. }
  79. function get_time_part($date_time_value) {
  80. $date_parts=explode(' ', $date_time_value);
  81. if (count($date_parts) == 2) {
  82. $time=$date_parts[1];
  83. } else {
  84. $time=$date_time_value;
  85. }
  86. return $time;
  87. }
  88. function queryFilterBefore_old(&$layout_def)
  89. {
  90. global $timedate;
  91. return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($layout_def['input_name0'])."'\n";
  92. }
  93. function queryFilterAfter_old(&$layout_def)
  94. {
  95. global $timedate;
  96. return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($layout_def['input_name0'])."'\n";
  97. }
  98. function queryFilterBetween_Dates_old(&$layout_def)
  99. {
  100. global $timedate;
  101. 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";
  102. }
  103. function queryFilterNot_Equals_str(& $layout_def) {
  104. global $timedate;
  105. $begin = $layout_def['input_name0'];
  106. if ($this->reporter->db->dbType == 'oci8') {
  107. } elseif($this->reporter->db->dbType == 'mssql') {
  108. return "".$this->_get_column_select($layout_def)."!='".$this->reporter->db->quote($begin)."'\n";
  109. }else{
  110. return "ISNULL(".$this->_get_column_select($layout_def).") OR \n(".$this->_get_column_select($layout_def)."!='".$this->reporter->db->quote($begin)."')\n";
  111. }
  112. }
  113. function queryFilterOn(& $layout_def) {
  114. global $timedate;
  115. $begin = $layout_def['input_name0'];
  116. return $this->_get_column_select($layout_def)."='".$this->reporter->db->quote($begin)."'\n";
  117. }
  118. function queryFilterBefore(& $layout_def) {
  119. global $timedate;
  120. $begin = $layout_def['input_name0'];
  121. return $this->_get_column_select($layout_def)."<'".$this->reporter->db->quote($begin)."'\n";
  122. }
  123. function queryFilterAfter(& $layout_def) {
  124. global $timedate;
  125. $begin = $layout_def['input_name0'];
  126. return $this->_get_column_select($layout_def).">'".$this->reporter->db->quote($begin)."'\n";
  127. }
  128. function queryFilterBetween_Dates(& $layout_def) {
  129. global $timedate;
  130. $begin = $layout_def['input_name0'];
  131. $end = $layout_def['input_name1'];
  132. 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";
  133. }
  134. function queryFilterTP_yesterday(& $layout_def) {
  135. global $timedate, $current_user;
  136. $begin_timestamp = time() - 86400;
  137. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  138. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  139. $begin_parts = explode(' ', $begin);
  140. $begin = $begin_parts[0] . ' 00:00:00';
  141. $end = $begin_parts[0] . ' 23:59:59';
  142. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  143. }
  144. function queryFilterTP_today(& $layout_def) {
  145. global $timedate, $current_user;
  146. $begin_timestamp = time();
  147. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  148. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  149. $begin_parts = explode(' ', $begin);
  150. $begin = $begin_parts[0] . ' 00:00:00';
  151. $end = $begin_parts[0] . ' 23:59:59';
  152. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  153. }
  154. function queryFilterTP_tomorrow(& $layout_def) {
  155. global $timedate, $current_user;
  156. $begin_timestamp = time() + 86400;
  157. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  158. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  159. $begin_parts = explode(' ', $begin);
  160. $begin = $begin_parts[0] . ' 00:00:00';
  161. $end = $begin_parts[0] . ' 23:59:59';
  162. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  163. }
  164. function queryFilterTP_last_7_days(& $layout_def) {
  165. global $timedate, $current_user;
  166. $begin_timestamp = time() - (6 * 86400);
  167. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  168. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  169. $end_timestamp = time();
  170. $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
  171. $end = $timedate->handle_offset($end, $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_parts = explode(' ', $end);
  175. $end = $end_parts[0] . ' 23:59:59';
  176. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  177. }
  178. function queryFilterTP_next_7_days(& $layout_def) {
  179. global $timedate, $current_user;
  180. $begin_timestamp = time();
  181. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  182. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  183. $end_timestamp = time() + (86400*6);
  184. $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
  185. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  186. $begin_parts = explode(' ', $begin);
  187. $begin = $begin_parts[0] . ' 00:00:00';
  188. $end_parts = explode(' ', $end);
  189. $end = $end_parts[0] . ' 23:59:59';
  190. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  191. }
  192. function queryFilterTP_last_month(& $layout_def) {
  193. global $timedate;
  194. $begin_timestamp = time();
  195. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  196. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  197. $begin_parts = explode(' ', $begin);
  198. $curr_date = explode('-',$begin_parts[0]);
  199. //Get year and month from time stamp.
  200. $curr_year=$curr_date[0];
  201. $curr_month=$curr_date[1];
  202. //get start date for last month and convert it to gmt and db format.
  203. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 month",mktime(0,0,0,$curr_month,1,$curr_year)));
  204. //get end date for last month and convert it to gmt and db format.
  205. $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
  206. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  207. }
  208. function queryFilterTP_this_month(& $layout_def) {
  209. global $timedate;
  210. $begin_timestamp = time();
  211. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  212. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  213. $begin_parts = explode(' ', $begin);
  214. $curr_date = explode('-',$begin_parts[0]);
  215. //Get year and month from time stamp.
  216. $curr_year=$curr_date[0];
  217. $curr_month=$curr_date[1];
  218. //get start date for this month and convert it to gmt and db format.
  219. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
  220. //get end date for this month and convert it to gmt and db format.
  221. //first get the first day of next month and move back by one day.
  222. if ($curr_month==12) {
  223. $curr_month=1;
  224. $curr_year+=1;
  225. } else {
  226. $curr_month+=1;
  227. }
  228. $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",mktime(23,59,59,$curr_month,1,$curr_year)));
  229. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  230. }
  231. function queryFilterTP_next_month(& $layout_def) {
  232. global $timedate;
  233. $begin_timestamp = time();
  234. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  235. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  236. $begin_parts = explode(' ', $begin);
  237. $curr_date = explode('-',$begin_parts[0]);
  238. //Get year and month from time stamp.
  239. $curr_year=$curr_date[0];
  240. $curr_month=$curr_date[1];
  241. if ($curr_month==12) {
  242. $curr_month=1;
  243. $curr_year+=1;
  244. } else {
  245. $curr_month+=1;
  246. }
  247. //get start date for next month and convert it to gmt and db format.
  248. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,$curr_month,1,$curr_year));
  249. $end=date($GLOBALS['timedate']->get_db_date_time_format(),strtotime("-1 day",(strtotime("1 month",mktime(23,59,59,$curr_month,1,$curr_year)))));
  250. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  251. }
  252. function queryFilterTP_last_30_days(& $layout_def) {
  253. global $timedate;
  254. $begin_timestamp = time() - (29 * 86400);
  255. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  256. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  257. $end_timestamp = time();
  258. $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
  259. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  260. $begin_parts = explode(' ', $begin);
  261. $begin = $begin_parts[0] . ' 00:00:00';
  262. $end_parts = explode(' ', $end);
  263. $end = $end_parts[0] . ' 23:59:59';
  264. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  265. }
  266. function queryFilterTP_next_30_days(& $layout_def) {
  267. global $timedate;
  268. $begin_timestamp = time();
  269. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  270. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  271. $end_timestamp = time() + (29 * 86400);
  272. $end = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $end_timestamp);
  273. $end = $timedate->handle_offset($end, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  274. $begin_parts = explode(' ', $begin);
  275. $begin = $begin_parts[0] . ' 00:00:00';
  276. $end_parts = explode(' ', $end);
  277. $end = $end_parts[0] . ' 23:59:59';
  278. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  279. }
  280. function queryFilterTP_this_quarter(& $layout_def) {
  281. }
  282. function queryFilterTP_last_year(& $layout_def) {
  283. global $timedate;
  284. $begin_timestamp = time();
  285. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  286. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  287. $begin_parts = explode(' ', $begin);
  288. $curr_date = explode('-',$begin_parts[0]);
  289. //Get year and month from time stamp.
  290. $curr_year=$curr_date[0]-1;
  291. //get start date for last year and convert it to gmt and db format.
  292. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
  293. //get end date for last year and convert it to gmt and db format.
  294. $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
  295. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  296. }
  297. function queryFilterTP_this_year(& $layout_def) {
  298. global $timedate;
  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. $begin_parts = explode(' ', $begin);
  303. $curr_date = explode('-',$begin_parts[0]);
  304. //Get year and month from time stamp.
  305. $curr_year=$curr_date[0];
  306. //get start date for this year and convert it to gmt and db format.
  307. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
  308. //get end date for this year and convert it to gmt and db format.
  309. $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
  310. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  311. }
  312. function queryFilterTP_next_year(& $layout_def) {
  313. global $timedate;
  314. $begin_timestamp = time();
  315. $begin = gmdate($GLOBALS['timedate']->get_db_date_time_format(), $begin_timestamp);
  316. $begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), true, $this->assigned_user);
  317. $begin_parts = explode(' ', $begin);
  318. $curr_date = explode('-',$begin_parts[0]);
  319. //Get year and month from time stamp.
  320. $curr_year=$curr_date[0]+1;
  321. //get start date for this year and convert it to gmt and db format.
  322. $begin=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(0,0,0,1,1,$curr_year));
  323. //get end date for this year and convert it to gmt and db format.
  324. $end=date($GLOBALS['timedate']->get_db_date_time_format(),mktime(23,59,59,12,31,$curr_year));
  325. return $this->get_start_end_date_filter($layout_def,$begin,$end);
  326. }
  327. }
  328. ?>