Skip to content

Commit 79dca9d

Browse files
committed
Merge branch 'datefix'
2 parents 2cb5a31 + 5b6908f commit 79dca9d

File tree

11 files changed

+78
-29
lines changed

11 files changed

+78
-29
lines changed

crm/Controllers/TicketsController.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,28 @@ public function index()
5858
}
5959

6060
$search = new Search();
61-
$solrObject = $search->query($_GET, $format=='raw' ? true : false);
61+
$query = $_GET;
62+
63+
if (isset ($query['enteredDate']['start'])) {
64+
if (!empty($query['enteredDate']['start'])) {
65+
try { $query['enteredDate']['start'] = new \DateTime($query['enteredDate']['start'].' 00:00:00'); }
66+
catch (\Exception $e) {
67+
unset($query['enteredDate']['start']);
68+
}
69+
}
70+
else { unset($query['enteredDate']['start']); }
71+
}
72+
if (isset ($query['enteredDate']['end'])) {
73+
if (!empty($query['enteredDate']['end'])) {
74+
try { $query['enteredDate']['end'] = new \DateTime($query['enteredDate']['end'].' 11:59:59'); }
75+
catch (\Exception $e) {
76+
unset($query['enteredDate']['end']);
77+
}
78+
}
79+
else { unset($query['enteredDate']['end']); }
80+
}
81+
82+
$solrObject = $search->query($query, $format=='raw' ? true : false);
6283

6384
$resultBlock = ($format == 'map') ? 'searchResultsMap.inc' : 'searchResults.inc';
6485
$this->template->blocks['panel-one'][] = new Block('tickets/searchForm.inc', ['solrObject'=>$solrObject]);
@@ -315,6 +336,12 @@ public function recordAction()
315336

316337
if (isset($_POST['ticket_id'])) {
317338
try {
339+
$_POST['actionDate'] = \DateTime::createFromFormat(
340+
DATE_FORMAT.' '.TIME_FORMAT,
341+
$_POST['actionDate']['date'].' '.$_POST['actionDate']['time']
342+
);
343+
if (!$_POST['actionDate']) { throw new \Exception('invalidDate'); }
344+
318345
$history->handleUpdate($_POST);
319346
$history->save();
320347
$this->redirectToTicketView($ticket);

crm/Models/Search.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,23 @@ public function query($get, $raw=false)
198198
}
199199
if (!empty($get[$field])) {
200200
if (false !== strpos($field, 'Date')) {
201+
$utc = new \DateTimeZone('UTC');
202+
201203
if (!empty($get[$field]['start']) || !empty($get[$field]['end'])) {
202-
$startDate = !empty($get[$field]['start'])
203-
? date(self::DATE_FORMAT, strtotime($get[$field]['start']))
204-
: '*';
205-
$endDate = !empty($get[$field]['end'])
206-
? date(self::DATE_FORMAT, strtotime($get[$field]['end']))
207-
: '*';
208-
$fq[] = "$field:[$startDate TO $endDate]";
204+
if (!empty( $get[$field]['start'])) {
205+
$get[$field]['start']->setTimezone($utc);
206+
$start = $get[$field]['start']->format(self::DATE_FORMAT);
207+
}
208+
else { $startDate = '*'; }
209+
210+
211+
if (!empty($get[$field]['end'])) {
212+
$get[$field]['end']->setTimezone($utc);
213+
$end = $get[$field]['end']->format(self::DATE_FORMAT);
214+
}
215+
else { $endDate = '*'; }
216+
217+
$fq[] = "$field:[$start TO $end]";
209218
}
210219
}
211220
// coordinates is a not a numeric value but does not need to be quoted.

crm/Models/TicketHistory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function setTicket(Ticket $o) { parent::setForeignKeyObject(__namespace_
132132
public function handleUpdate($post)
133133
{
134134
$this->setAction_id ($post['action_id'] );
135-
$this->setActionDate($post['actionDate']);
135+
$this->setActionDate($post['actionDate']->format(ActiveRecord::MYSQL_DATETIME_FORMAT));
136136
$this->setNotes ($post['notes'] );
137137
$this->setEnteredByPerson($_SESSION['USER']);
138138
$this->setActionPerson ($_SESSION['USER']);

crm/blocks/html/reports/searchForm.inc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,16 @@ $helper = $this->template->getHelper('field');
6262
<h1><?= $this->_('enteredDate'); ?></h1>
6363
<?php
6464
foreach (['start', 'end'] as $d) {
65-
$$d = '';
65+
$value = '';
6666
if (!empty($_GET['enteredDate'][$d])) {
67-
try {
68-
$date = ActiveRecord::parseDate($_GET['enteredDate'][$d], DATE_FORMAT);
69-
$$d = $date->format('U');
70-
}
71-
catch (\Exception $e) { }
67+
$value = self::escape($_GET['enteredDate'][$d]);
7268
}
7369
echo $helper->field([
7470
'name' => "enteredDate[$d]",
7571
'id' => "enteredDate-$d",
7672
'label' => $this->_($d),
7773
'type' => 'date',
78-
'value' => $$d
74+
'value' => $value
7975
]);
8076
}
8177
?>

crm/blocks/html/tickets/actionForm.inc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616
<?php
1717
$helper = $this->template->getHelper('field');
1818
echo $helper->field([
19-
'name' => 'actionDate',
20-
'id' => 'actionDate',
19+
'name' => 'actionDate[date]',
20+
'id' => 'actionDate_date',
2121
'label' => $this->_('date'),
2222
'type' => 'date',
23-
'value' => $this->ticketHistory->getActionDate('U')
23+
'value' => $this->ticketHistory->getActionDate(DATE_FORMAT)
2424
]);
25+
echo $helper->field([
26+
'name' => 'actionDate[time]',
27+
'id' => 'actionDate_time',
28+
'label' =>$this->_('time'),
29+
'type' =>'time',
30+
'value' =>$this->ticketHistory->getActionDate(TIME_FORMAT)
31+
]);
32+
2533
echo $helper->field([
2634
'name' => 'notes',
2735
'id' => 'notes',

crm/blocks/html/tickets/searchForm.inc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,16 @@ $this->template->addToAsset('scripts', BASE_URI.'/js/collapsible.js');
145145
";
146146
$fieldHelper = $this->template->getHelper('field');
147147
foreach (['start', 'end'] as $d) {
148-
$$d = '';
148+
$value = '';
149149
if (!empty($_GET['enteredDate'][$d])) {
150-
try {
151-
$date = ActiveRecord::parseDate($_GET['enteredDate'][$d], DATE_FORMAT);
152-
$$d = $date->format('U');
153-
}
154-
catch (\Exception $e) {
155-
// Ignore incorrectly formatted dates
156-
}
150+
$value = self::escape($_GET['enteredDate'][$d]);
157151
}
158152
$html.= $fieldHelper->field([
159153
'name' => "enteredDate[$d]",
160154
'id' => "enteredDate-$d",
161155
'label' => $this->_($d),
162156
'type' => 'date',
163-
'value' => $$d
157+
'value' => $value
164158
]);
165159
}
166160
$html.= "

crm/language/en_CA/LC_MESSAGES/labels.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ msgstr "Fields to display"
248248
msgid "date"
249249
msgstr "Date"
250250

251+
msgid "time"
252+
msgstr "Time"
253+
251254
msgid "day"
252255
msgid_plural "days"
253256
msgstr[0] "Day"

crm/language/en_US/LC_MESSAGES/labels.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ msgstr "Fields to display"
247247
msgid "date"
248248
msgstr "Date"
249249

250+
msgid "time"
251+
msgstr "Time"
252+
250253
msgid "day"
251254
msgid_plural "days"
252255
msgstr[0] "Day"

crm/language/fr_CA/LC_MESSAGES/labels.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ msgstr "Champs à afficher"
248248
msgid "date"
249249
msgstr "Date"
250250

251+
msgid "time"
252+
msgstr "Temps"
253+
251254
msgid "day"
252255
msgid_plural "days"
253256
msgstr[0] "Jour"

crm/language/nl_NL/LC_MESSAGES/labels.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ msgstr "Zichtbare velden"
247247
msgid "date"
248248
msgstr "Datum"
249249

250+
msgid "time"
251+
msgstr "Tijd"
252+
250253
msgid "day"
251254
msgid_plural "days"
252255
msgstr[0] "Dag"

0 commit comments

Comments
 (0)