Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

generic/SugarWidgets/SugarWidgetFielddatetime.php (17 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
43
44
class SugarWidgetFieldDateTime extends SugarWidgetReportField
45
{
46
	var $reporter;
47
	var $assigned_user=null;
48
49
    function __construct($layout_manager)
50
    {
51
        parent::__construct($layout_manager);
52
    }
53
54
    /**
55
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
56
     */
57
    function SugarWidgetFieldDateTime($layout_manager){
58
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
59
        if(isset($GLOBALS['log'])) {
60
            $GLOBALS['log']->deprecated($deprecatedMessage);
61
        }
62
        else {
63
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
64
        }
65
        self::__construct($layout_manager);
66
    }
67
68
69
	// get the reporter attribute
70
    // deprecated, now called in the constructor
71
    /**
72
     * @deprecated
73
     */
74
	function getReporter() {
75
	}
76
77
	// get the assigned user of the report
78
	function getAssignedUser()
79
	{
80
		$json_obj = getJSONobj();
81
82
		$report_def_str = $json_obj->decode($this->reporter->report_def_str);
83
84
		if(empty($report_def_str['assigned_user_id'])) return null;
85
86
		$this->assigned_user = new User();
87
		$this->assigned_user->retrieve($report_def_str['assigned_user_id']);
88
		return $this->assigned_user;
89
	}
90
91
	function queryFilterOn($layout_def)
92
	{
93
		global $timedate;
94
        $begin = $layout_def['input_name0'];
95
        $hasTime = $this->hasTime($begin);
96
        $date = $timedate->fromString($begin);
97
98
        if (!$hasTime) {
99
            return $this->queryDay(
100
                $layout_def,
101
                $date
102
            );
103
        }
104
105
        return $this->queryDateOp(
106
            $this->_get_column_select($layout_def),
107
            $date,
108
            '=',
109
            "datetime"
110
        );
111
	}
112
113
    /**
114
     * expandDate
115
     *
116
     * This function helps to convert a date only value to have a time value as well.  It first checks
117
     * to see if a time value exists.  If a time value exists, the function just returns the date value
118
     * passed in.  If the date value is the 'Today' macro then some special processing occurs as well.
119
     * Finally the time portion is applied depending on whether or not this date should be for the end
120
     * in which case the 23:59:59 time value is applied otherwise 00:00:00 is used.
121
     *
122
     * @param $date String value of the date value to expand
123
     * @param bool $end Boolean value indicating whether or not this is for an end time period or not
124
     * @return $date TimeDate object with time value applied
0 ignored issues
show
The doc-type $date could not be parsed: Unknown type name "$date" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
125
     */
126
	protected function expandDate($date, $end = false)
127
	{
128
	    global $timedate;
129
	    if($this->hasTime($date)) {
130
	        return $date;
131
	    }
132
133
        //C.L. Bug 48616 - If the $date is set to the Today macro, then adjust accordingly
134
        if(strtolower($date) == 'today')
135
        {
136
           $startEnd = $timedate->getDayStartEndGMT($timedate->getNow(true));
137
           return $end ? $startEnd['end'] : $startEnd['start'];
138
        }
139
140
        $parsed = $timedate->fromDbDate($date);
141
        $date = $timedate->tzUser(new SugarDateTime());
142
        $date->setDate($parsed->year, $parsed->month, $parsed->day);
143
144
	    if($end) {
145
	        return $date->setTime(23, 59, 59);
146
	    } else {
147
	        return $date->setTime(0, 0, 0);
148
	    }
149
	}
150
151
	function queryFilterBefore($layout_def)
152
	{
153
        $begin = $this->expandDate($layout_def['input_name0']);
154
        return $this->queryDateOp($this->_get_column_select($layout_def), $begin, '<', "datetime");
155
	}
156
157
	function queryFilterAfter($layout_def)
158
	{
159
        $begin = $this->expandDate($layout_def['input_name0'], true);
160
        return $this->queryDateOp($this->_get_column_select($layout_def), $begin, '>', "datetime");
161
	}
162
163
	function queryFilterBetween_Dates($layout_def)
164
	{
165
        $begin = $this->expandDate($layout_def['input_name0']);
166
     	$end = $this->expandDate($layout_def['input_name1'], true);
167
        $column = $this->_get_column_select($layout_def);
168
	    return "(".$this->queryDateOp($column, $begin, ">=", "datetime")." AND ".
169
            $this->queryDateOp($column, $end, "<=", "datetime").")\n";
170
	}
171
172
	function queryFilterNot_Equals_str($layout_def)
173
	{
174
		global $timedate;
175
176
        $column = $this->_get_column_select($layout_def);
177
        $begin = $layout_def['input_name0'];
178
        $hasTime = $this->hasTime($begin);
179
        if(!$hasTime){
180
     	    $end = $this->expandDate($begin, true);
181
            $begin = $this->expandDate($begin);
182
            $cond = $this->queryDateOp($column, $begin, "<", "datetime")." OR ".
183
                $this->queryDateOp($column, $end, ">", "datetime");
184
        } else {
185
            $cond =  $this->queryDateOp($column, $begin, "!=", "datetime");
186
        }
187
        return "($column IS NULL OR $cond)";
188
	}
189
190
    /**
191
     * Get assigned or logged in user's current date and time value.
192
     * @param boolean $timestamp Format of return value, if set to true, return unix like timestamp , else a formatted date.
193
     */
194
	function get_users_current_date_time($timestamp=false)
195
	{
196
	 	global $current_user;
197
        global $timedate;
198
199
        $begin = TimeDate::getInstance()->nowDb();
200
        //kbrill bug #13884
201
       	//$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);
202
		$begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
203
204
        if (!$timestamp) {
205
        	return $begin;
206
        } else {
207
        	$begin_parts = explode(' ', $begin);
208
        	$date_parts=explode('-', $begin_parts[0]);
209
        	$time_parts=explode(':', $begin_parts[1]);
210
        	$curr_timestamp=mktime($time_parts[0],$time_parts[1],0,$date_parts[1], $date_parts[2],$date_parts[0]);
211
        	return $curr_timestamp;
212
        }
213
214
	}
215
	/**
216
	 * Get specified date and time for a particalur day, in current user's timezone.
217
	 * @param int $days Adjust date by this number of days, negative values are valid.
218
	 * @param time string falg for desired time value, start: minimum time, end: maximum time, default: current time
219
	 */
220
	function get_db_date($days,$time) {
221
        global $timedate;
222
223
        $begin = date($GLOBALS['timedate']->get_db_date_time_format(), time()+(86400 * $days));  //gmt date with day adjustment applied.
224
        //kbrill bug #13884
225
        //$begin = $timedate->to_display_date_time($begin,true,true,$this->assigned_user);
226
		$begin = $timedate->handle_offset($begin, $timedate->get_db_date_time_format(), false, $this->assigned_user);
227
228
        if ($time=='start') {
229
            $begin_parts = explode(' ', $begin);
230
            $be = $begin_parts[0] . ' 00:00:00';
231
        }
232
        else if ($time=='end') {
233
            $begin_parts = explode(' ', $begin);
234
            $be = $begin_parts[0] . ' 23:59:59';
235
        } else {
236
            $be=$begin;
237
        }
238
239
        //convert date to db format without converting to GMT.
240
        $begin = $timedate->handle_offset($be, $timedate->get_db_date_time_format(), false, $this->assigned_user);
241
242
        return $begin;
243
	}
244
245
	/**
246
	 * Get filter string for a date field.
247
	 * @param array layout_def field def for field being filtered
248
	 * @param string $begin start date value (in DB format)
249
	 * @param string $end End date value (in DB format)
250
	 */
251
	function get_start_end_date_filter(& $layout_def, $begin,$end)
252
	{
253
	    if (isset ($layout_def['rel_field'])) {
254
	        $field_name = $this->reporter->db->convert(
255
	            $this->reporter->db->convert($this->_get_column_select($layout_def), 'date_format', '%Y-%m-%d'),
256
	            "CONCAT",
257
	            array("' '", $this->reporter->db->convert($layout_def['rel_field'], 'time_format'))
258
	        );
259
	    } else {
260
	       $field_name = $this->_get_column_select($layout_def);
261
	    }
262
	    return $field_name.">=".$this->reporter->db->quoted($begin)." AND ".$field_name."<=".$this->reporter->db->quoted($end)."\n";
263
	}
264
265
	/**
266
	 * Create query for binary operation of field of certain type
267
	 * Produces query like:
268
	 * arg1 op to_date(arg2), e.g.:
269
	 * 		date_closed < '2009-12-01'
270
	 * @param string $arg1 1st arg - column name
271
	 * @param string|DateTime $arg2 2nd arg - value to be converted
272
	 * @param string $op
273
	 * @param string $type
274
	 */
275
    protected function queryDateOp($arg1, $arg2, $op, $type)
276
    {
277
        global $timedate;
278
        if($arg2 instanceof DateTime) {
279
            $arg2 = $timedate->asDbType($arg2, $type);
280
        }
281
        return "$arg1 $op ".$this->reporter->db->convert($this->reporter->db->quoted($arg2), $type)."\n";
282
    }
283
284
    /**
285
     * Return current date in required user's TZ
286
     * @return SugarDateTime
287
     */
288
    protected function now()
289
    {
290
        global $timedate;
291
        return $timedate->tzUser($timedate->getNow(), $this->getAssignedUser());
292
    }
293
294
	/**
295
     * Create query from the beginning to the end of certain day
296
     * @param array $layout_def
297
     * @param SugarDateTime $day
298
     */
299
    protected function queryDay($layout_def, SugarDateTime $day)
300
    {
301
        $begin = $day->get_day_begin();
302
        $end = $day->get_day_end();
303
        return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
304
    }
305
306
	function queryFilterTP_yesterday($layout_def)
307
	{
308
		global $timedate;
309
		return $this->queryDay($layout_def, $this->now()->get("-1 day"));
310
	}
311
312
	function queryFilterTP_today($layout_def)
313
	{
314
		global $timedate;
315
		return $this->queryDay($layout_def, $this->now());
316
	}
317
318
	function queryFilterTP_tomorrow(& $layout_def)
319
	{
320
		global $timedate;
321
		return $this->queryDay($layout_def, $this->now()->get("+1 day"));
322
	}
323
324
	function queryFilterTP_last_7_days($layout_def)
325
	{
326
		global $timedate;
327
328
		$begin = $this->now()->get("-6 days")->get_day_begin();
329
		$end = $this->now()->get_day_end();
330
331
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
332
	}
333
334
	function queryFilterTP_next_7_days($layout_def)
335
	{
336
		global $timedate;
337
338
		$begin = $this->now()->get_day_begin();
339
		$end = $this->now()->get("+6 days")->get_day_end();
340
341
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
342
	}
343
344
    /**
345
     * Create query from the beginning to the end of certain month
346
     * @param array $layout_def
347
     * @param SugarDateTime $month
348
     */
349
    protected function queryMonth($layout_def, $month)
350
    {
351
        $begin = $month->setTime(0, 0, 0);
352
        $end = clone($begin);
353
		$end->setDate($begin->year, $begin->month, $begin->days_in_month)->setTime(23, 59, 59);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property month does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property days_in_month does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
354
        return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
355
    }
356
357
    function queryFilterTP_last_month($layout_def)
358
	{
359
		global $timedate;
360
		$month = $this->now();
361
		return $this->queryMonth($layout_def, $month->setDate($month->year, $month->month-1, 1));
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property month does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
362
	}
363
364
	function queryFilterTP_this_month($layout_def)
365
	{
366
		global $timedate;
367
368
        //Bug 62414 - take timezone into account when determining current month
369
        $now = $this->now();
370
        $timezoneOffset = $timedate->getUserUTCOffset();
371
        $timezoneOffset = "$timezoneOffset minutes";
372
        $now->modify($timezoneOffset);
373
374
        return $this->queryMonth($layout_def, $now->get_day_by_index_this_month(0));
375
	}
376
377
	function queryFilterTP_next_month($layout_def)
378
	{
379
		global $timedate;
380
		$month = $this->now();
381
		return $this->queryMonth($layout_def, $month->setDate($month->year, $month->month+1, 1));
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property month does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
382
	}
383
384
	function queryFilterTP_last_30_days($layout_def)
385
	{
386
		global $timedate;
387
		$begin = $this->now()->get("-29 days")->get_day_begin();
388
		$end = $this->now()->get_day_end();
389
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
390
	}
391
392
	function queryFilterTP_next_30_days($layout_def)
393
	{
394
		global $timedate;
395
		$begin = $this->now()->get_day_begin();
396
		$end = $this->now()->get("+29 days")->get_day_end();
397
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
398
	}
399
400
    /**
401
     * Return the between WHERE query for Quarter filter
402
     *
403
     * Find quarter for given date, modify the start/end with $modifyFilter parameter
404
     *
405
     * @param $layout_def - Filter layout_def
406
     * @param string $modifyFilter - Modification to start/end date, used to select previous/next quarter
407
     * @param string $date - Date for which to find the quarter filter, if not set uses current date
408
     * @return string - BETWEEN WHERE query for quarter filter
409
     */
410
    protected function getQuarterFilter($layout_def, $modifyFilter, $date = '')
411
    {
412
        $timedate = TimeDate::getInstance();
413
414
        // See if date is set, if not, use current date
415
        if (empty($date)) {
416
            $begin = $timedate->getNow(true);
417
        } else {
418
            $begin = $timedate->fromString($date);
419
        }
420
421
        $begin->setDate(
422
            $begin->year,
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
423
            floor(($begin->month - 1) / 3) * 3 + 1, // Find starting month of quarter
0 ignored issues
show
The property month does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
424
            1
425
        )->setTime(0, 0);
426
427
        $end = $begin->get("+3 month")->setTime(23, 59, 59)->get("-1 day");
428
429
        // Modify begin/end if filter is set
430
        if (!empty($modifyFilter)) {
431
            $begin->modify($modifyFilter);
432
            $end->modify($modifyFilter);
433
        }
434
435
        return $this->get_start_end_date_filter($layout_def, $begin->asDb(), $end->asDb());
436
    }
437
438
    /**
439
     * Returns part of query for select
440
     *
441
     * @param array $layout_def for field
442
     * @return string part of select query with last quarter only
443
     */
444
    public function queryFilterTP_last_quarter($layout_def)
445
    {
446
        return $this->getQuarterFilter($layout_def, '-3 month');
447
    }
448
449
    /**
450
     * Returns part of query for select
451
     *
452
     * @param array $layout_def for field
453
     * @return string part of select query with this quarter only
454
     */
455
    public function queryFilterTP_this_quarter($layout_def)
456
    {
457
        return $this->getQuarterFilter($layout_def, '');
458
    }
459
460
    /**
461
     * Returns part of query for select
462
     *
463
     * @param array $layout_def for field
464
     * @return string part of select query with next quarter only
465
     */
466
    public function queryFilterTP_next_quarter($layout_def)
467
    {
468
        return $this->getQuarterFilter($layout_def, '+3 month');
469
    }
470
471
	function queryFilterTP_last_year($layout_def)
472
	{
473
		global $timedate;
474
		$begin = $this->now();
475
		$begin->setDate($begin->year-1, 1, 1)->setTime(0, 0);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
476
		$end = clone $begin;
477
		$end->setDate($end->year, 12, 31)->setTime(23, 59, 59);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
478
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
479
	}
480
481
	function queryFilterTP_this_year($layout_def)
482
	{
483
		global $timedate;
484
		$begin = $this->now();
485
		$begin->setDate($begin->year, 1, 1)->setTime(0, 0);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
486
		$end = clone $begin;
487
		$end->setDate($end->year, 12, 31)->setTime(23, 59, 59);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
488
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
489
	}
490
491
	function queryFilterTP_next_year(& $layout_def)
492
	{
493
		global $timedate;
494
		$begin = $this->now();
495
		$begin->setDate($begin->year+1, 1, 1)->setTime(0, 0);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
496
		$end = clone $begin;
497
		$end->setDate($end->year, 12, 31)->setTime(23, 59, 59);
0 ignored issues
show
The property year does not exist on object<SugarDateTime>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
498
		return $this->get_start_end_date_filter($layout_def,$begin->asDb(),$end->asDb());
499
	}
500
501
	function queryGroupBy($layout_def)
502
	{
503
		// i guess qualifier and column_function are the same..
504
		if (!empty ($layout_def['qualifier'])) {
505
			$func_name = 'queryGroupBy'.$layout_def['qualifier'];
506
			if (method_exists($this, $func_name)) {
507
				return $this-> $func_name ($layout_def)." \n";
508
			}
509
		}
510
		return parent :: queryGroupBy($layout_def)." \n";
511
	}
512
513
	function queryOrderBy($layout_def)
514
	{
515
        if (!empty ($layout_def['qualifier'])) {
516
			$func_name ='queryOrderBy'.$layout_def['qualifier'];
517
			if (method_exists($this, $func_name)) {
518
				return $this-> $func_name ($layout_def)."\n";
519
			}
520
		}
521
		$order_by = parent :: queryOrderBy($layout_def)."\n";
522
		return $order_by;
523
	}
524
525
    function displayListPlain($layout_def) {
526
        global $timedate;
527
        $content = parent:: displayListPlain($layout_def);
528
        // awu: this if condition happens only in Reports where group by month comes back as YYYY-mm format
529
        if (count(explode('-',$content)) == 2){
530
            return $content;
531
        // if date field
532
        }elseif(substr_count($layout_def['type'], 'date') > 0){
533
            // if date time field
534
            if(substr_count($layout_def['type'], 'time') > 0 && $this->get_time_part($content)!= false){
535
                $td = $timedate->to_display_date_time($content);
536
                return $td;
537
            }else{// if date only field
538
                $td = $timedate->to_display_date($content, false); // Avoid PHP notice of returning by reference.
539
                return $td;
540
            }
541
        }
542
    }
543
544
    function get_time_part($date_time_value)
545
    {
546
        global $timedate;
547
548
        $date_parts=$timedate->split_date_time($date_time_value);
549
        if (count($date_parts) > 1) {
550
            return $date_parts[1];
551
        } else {
552
            return false;
553
        }
554
    }
555
556
    function displayList($layout_def) {
557
        global $timedate;
558
        // i guess qualifier and column_function are the same..
559
        if (!empty ($layout_def['column_function'])) {
560
            $func_name = 'displayList'.$layout_def['column_function'];
561
            if (method_exists($this, $func_name)) {
562
                return $this-> $func_name ($layout_def);
563
            }
564
        }
565
        $content = parent :: displayListPlain($layout_def);
566
        return $timedate->to_display_date_time($content);
567
    }
568
569
	function querySelect(& $layout_def) {
570
		// i guess qualifier and column_function are the same..
571
		if (!empty ($layout_def['column_function'])) {
572
			$func_name = 'querySelect'.$layout_def['column_function'];
573
			if (method_exists($this, $func_name)) {
574
				return $this-> $func_name ($layout_def)." \n";
575
			}
576
		}
577
		return parent :: querySelect($layout_def)." \n";
578
	}
579
	function & displayListday(& $layout_def) {
580
        $value = parent:: displayListPlain($layout_def);
581
        return $value;
582
	}
583
584
	function & displayListyear(& $layout_def) {
585
		global $app_list_strings;
586
    	$value = parent:: displayListPlain($layout_def);
587
    	return $value;
588
	}
589
590
	function displayListmonth($layout_def)
591
	{
592
		global $app_list_strings;
593
		$display = '';
594
		$match = array();
595
        if (preg_match('/(\d{4})-(\d\d)/', $this->displayListPlain($layout_def), $match)) {
596
			$match[2] = preg_replace('/^0/', '', $match[2]);
597
			$display = $app_list_strings['dom_cal_month_long'][$match[2]]." {$match[1]}";
598
		}
599
		return $display;
600
601
	}
602
603
    /**
604
     * Returns part of query for select
605
     *
606
     * @param array $layout_def for field
607
     * @return string part of select query with year & month only
608
     */
609
    function querySelectmonth($layout_def)
610
    {
611
        $return = $this->_get_column_select($layout_def);
612
        if ($layout_def['type'] == 'datetime')
613
        {
614
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
615
        }
616
        return $this->reporter->db->convert($return, "date_format", array('%Y-%m')) . ' ' . $this->_get_column_alias($layout_def) . "\n";
617
    }
618
619
    /**
620
     * Returns part of query for group by
621
     *
622
     * @param array $layout_def for field
623
     * @return string part of group by query with year & month only
624
     */
625
    function queryGroupByMonth($layout_def)
626
    {
627
        $return = $this->_get_column_select($layout_def);
628
        if ($layout_def['type'] == 'datetime')
629
        {
630
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
631
        }
632
        return $this->reporter->db->convert($return, "date_format", array('%Y-%m')) . "\n";
633
    }
634
635
    /**
636
     * For oracle we have to return order by string like group by string instead of return field alias
637
     *
638
     * @param array $layout_def definition of field
639
     * @return string order by string for field
640
     */
641
    function queryOrderByMonth($layout_def)
642
    {
643
        $return = $this->_get_column_select($layout_def);
644
        if ($layout_def['type'] == 'datetime')
645
        {
646
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
647
        }
648
        $orderBy = $this->reporter->db->convert($return, "date_format", array('%Y-%m'));
649
650
        if (empty($layout_def['sort_dir']) || $layout_def['sort_dir'] == 'a')
651
        {
652
            return $orderBy . " ASC\n";
653
        }
654
        else
655
        {
656
            return $orderBy . " DESC\n";
657
        }
658
    }
659
660
    /**
661
     * Returns part of query for select
662
     *
663
     * @param array $layout_def for field
664
     * @return string part of select query with year & month & day
665
     */
666
    function querySelectday($layout_def)
667
    {
668
        $return = $this->_get_column_select($layout_def);
669
        if ($layout_def['type'] == 'datetime')
670
        {
671
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
672
        }
673
        return $this->reporter->db->convert($return, "date_format", array('%Y-%m-%d')) . ' ' . $this->_get_column_alias($layout_def) . "\n";
674
    }
675
676
    /**
677
     * Returns part of query for group by
678
     *
679
     * @param array $layout_def for field
680
     * @return string part of group by query with year & month & day
681
     */
682
    function queryGroupByDay($layout_def)
683
    {
684
        $return = $this->_get_column_select($layout_def);
685
        if ($layout_def['type'] == 'datetime')
686
        {
687
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
688
        }
689
        return $this->reporter->db->convert($return, "date_format", array('%Y-%m-%d')) . "\n";
690
    }
691
692
    /**
693
     * Returns part of query for select
694
     *
695
     * @param array $layout_def for field
696
     * @return string part of select query with year only
697
     */
698
    function querySelectyear($layout_def)
699
    {
700
        $return = $this->_get_column_select($layout_def);
701
        if ($layout_def['type'] == 'datetime')
702
        {
703
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
704
        }
705
        return $this->reporter->db->convert($return, "date_format", array('%Y')) . ' ' . $this->_get_column_alias($layout_def) . "\n";
706
    }
707
708
    /**
709
     * Returns part of query for group by
710
     *
711
     * @param array $layout_def for field
712
     * @return string part of group by query with year only
713
     */
714
    function queryGroupByYear($layout_def)
715
    {
716
        $return = $this->_get_column_select($layout_def);
717
        if ($layout_def['type'] == 'datetime')
718
        {
719
            $return = $this->reporter->db->convert($return, 'add_tz_offset');
720
        }
721
        return $this->reporter->db->convert($return, "date_format", array('%Y')) . "\n";
722
    }
723
724
	function querySelectquarter($layout_def)
725
	{
726
	    $column = $this->_get_column_select($layout_def);
727
	    return $this->reporter->db->convert($this->reporter->db->convert($column, "date_format", array('%Y')),
728
	        	'CONCAT',
729
	            array("'-'", $this->reporter->db->convert($column, "quarter")))
730
	        ." ".$this->_get_column_alias($layout_def)."\n";
731
	}
732
733
	function displayListquarter(& $layout_def) {
734
		$match = array();
735
        if (preg_match('/(\d{4})-(\d)/', $this->displayListPlain($layout_def), $match)) {
736
			return "Q".$match[2]." ".$match[1];
737
		}
738
		return '';
739
740
	}
741
742
	function queryGroupByQuarter($layout_def)
743
	{
744
		$this->getReporter();
0 ignored issues
show
Deprecated Code introduced by
The method SugarWidgetFieldDateTime::getReporter() has been deprecated.

This method has been deprecated.

Loading history...
745
        $column = $this->_get_column_select($layout_def);
746
	    return $this->reporter->db->convert($this->reporter->db->convert($column, "date_format", array('%Y')),
747
	        	'CONCAT',
748
	            array("'-'", $this->reporter->db->convert($column, "quarter")));
749
	}
750
751
    /**
752
     * For oracle we have to return order by string like group by string instead of return field alias
753
     *
754
     * @param array $layout_def definition of field
755
     * @return string order by string for field
756
     */
757
    public function queryOrderByQuarter($layout_def)
758
    {
759
        $column = $this->_get_column_select($layout_def);
760
        $orderBy = $this->reporter->db->convert(
761
            $this->reporter->db->convert($column, "date_format", array('%Y')),
762
            'CONCAT',
763
            array("'-'", $this->reporter->db->convert($column, "quarter"))
764
        );
765
766
767
        if (empty($layout_def['sort_dir']) || $layout_def['sort_dir'] == 'a')
768
        {
769
            return $orderBy . " ASC\n";
770
        }
771
        else
772
        {
773
            return $orderBy . " DESC\n";
774
        }
775
    }
776
777
    function displayInput(&$layout_def) {
778
    	global $timedate, $current_language, $app_strings;
779
        $home_mod_strings = return_module_language($current_language, 'Home');
780
        $filterTypes = array(' '                 => $app_strings['LBL_NONE'],
781
                             'TP_today'         => $home_mod_strings['LBL_TODAY'],
782
                             'TP_yesterday'     => $home_mod_strings['LBL_YESTERDAY'],
783
                             'TP_tomorrow'      => $home_mod_strings['LBL_TOMORROW'],
784
                             'TP_this_month'    => $home_mod_strings['LBL_THIS_MONTH'],
785
                             'TP_this_year'     => $home_mod_strings['LBL_THIS_YEAR'],
786
                             'TP_last_30_days'  => $home_mod_strings['LBL_LAST_30_DAYS'],
787
                             'TP_last_7_days'   => $home_mod_strings['LBL_LAST_7_DAYS'],
788
                             'TP_last_month'    => $home_mod_strings['LBL_LAST_MONTH'],
789
                             'TP_last_year'     => $home_mod_strings['LBL_LAST_YEAR'],
790
                             'TP_next_30_days'  => $home_mod_strings['LBL_NEXT_30_DAYS'],
791
                             'TP_next_7_days'   => $home_mod_strings['LBL_NEXT_7_DAYS'],
792
                             'TP_next_month'    => $home_mod_strings['LBL_NEXT_MONTH'],
793
                             'TP_next_year'     => $home_mod_strings['LBL_NEXT_YEAR'],
794
                             );
795
796
        $cal_dateformat = $timedate->get_cal_date_format();
797
        $str = "<select name='type_{$layout_def['name']}'>";
798
        $str .= get_select_options_with_id($filterTypes, (empty($layout_def['input_name0']) ? '' : $layout_def['input_name0']));
799
//        foreach($filterTypes as $value => $label) {
800
//            $str .= '<option value="' . $value . '">' . $label. '</option>';
801
//        }
802
        $str .= "</select>";
803
804
805
        return $str;
806
    }
807
808
    /**
809
     * @param  $date
810
     * @return bool false if the date is a only a date, true if the date includes time.
811
     */
812
    protected function hasTime($date)
813
    {
814
        return strlen(trim($date)) < 11 ? false : true;
815
    }
816
817
}
818