|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Form element to select a date. |
|
6
|
|
|
* |
|
7
|
|
|
* Class DatePicker |
|
8
|
|
|
*/ |
|
9
|
|
|
class DateTimeRangePicker extends DateRangePicker |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* HTML code to display this datepicker. |
|
13
|
|
|
* |
|
14
|
|
|
* @return string |
|
15
|
|
|
*/ |
|
16
|
|
|
public function toHtml() |
|
17
|
|
|
{ |
|
18
|
|
|
if ($this->_flagFrozen) { |
|
19
|
|
|
return $this->getFrozenHtml(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$id = $this->getAttribute('id'); |
|
23
|
|
|
$dateRange = $this->getValue(); |
|
24
|
|
|
|
|
25
|
|
|
$value = ''; |
|
26
|
|
|
if (!empty($dateRange)) { |
|
27
|
|
|
$dates = $this->parseDateRange($dateRange); |
|
28
|
|
|
$value = api_format_date($dates['date'], DATE_FORMAT_LONG_NO_DAY); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return ' |
|
32
|
|
|
<div class="input-group"> |
|
33
|
|
|
<span class="input-group-addon cursor-pointer"> |
|
34
|
|
|
<input '.$this->_getAttrString($this->_attributes).'> |
|
35
|
|
|
</span> |
|
36
|
|
|
<p class="form-control disabled" id="'.$id.'_alt_text">'.$value.'</p> |
|
37
|
|
|
<input class="form-control" type="hidden" id="'.$id.'_alt" value="'.$value.'"> |
|
38
|
|
|
<span class="input-group-btn"> |
|
39
|
|
|
<button class="btn btn-default" type="button" |
|
40
|
|
|
title="'.sprintf(get_lang('ResetFieldX'), $this->_label).'"> |
|
41
|
|
|
<span class="fa fa-trash text-danger" aria-hidden="true"></span> |
|
42
|
|
|
<span class="sr-only">'.sprintf(get_lang('ResetFieldX'), $this->_label).'</span> |
|
43
|
|
|
</button> |
|
44
|
|
|
</span> |
|
45
|
|
|
</div> |
|
46
|
|
|
'.$this->getElementJS(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $layout |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getTemplate($layout) |
|
55
|
|
|
{ |
|
56
|
|
|
$size = $this->getColumnsSize(); |
|
57
|
|
|
|
|
58
|
|
|
if (empty($size)) { |
|
59
|
|
|
$sizeTemp = $this->getInputSize(); |
|
60
|
|
|
if (empty($size)) { |
|
61
|
|
|
$sizeTemp = 8; |
|
62
|
|
|
} |
|
63
|
|
|
$size = [2, $sizeTemp, 2]; |
|
64
|
|
|
} else { |
|
65
|
|
|
if (is_array($size)) { |
|
66
|
|
|
if (count($size) != 3) { |
|
67
|
|
|
$sizeTemp = $this->getInputSize(); |
|
68
|
|
|
if (empty($size)) { |
|
69
|
|
|
$sizeTemp = 8; |
|
70
|
|
|
} |
|
71
|
|
|
$size = [2, $sizeTemp, 2]; |
|
72
|
|
|
} |
|
73
|
|
|
// else just keep the $size array as received |
|
74
|
|
|
} else { |
|
75
|
|
|
$size = [2, (int) $size, 2]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$id = $this->getAttribute('id'); |
|
80
|
|
|
|
|
81
|
|
|
switch ($layout) { |
|
82
|
|
|
case FormValidator::LAYOUT_INLINE: |
|
83
|
|
|
return ' |
|
84
|
|
|
<div class="form-group {error_class}"> |
|
85
|
|
|
<label {label-for} > |
|
86
|
|
|
<!-- BEGIN required --><span class="form_required">*</span><!-- END required --> |
|
87
|
|
|
{label} |
|
88
|
|
|
</label> |
|
89
|
|
|
{element} |
|
90
|
|
|
</div>'; |
|
91
|
|
|
break; |
|
|
|
|
|
|
92
|
|
|
case FormValidator::LAYOUT_HORIZONTAL: |
|
93
|
|
|
return ' |
|
94
|
|
|
<span id="'.$id.'_date_time_wrapper"> |
|
95
|
|
|
<div class="form-group {error_class}"> |
|
96
|
|
|
<label {label-for} class="col-sm-'.$size[0].' control-label" > |
|
97
|
|
|
<!-- BEGIN required --><span class="form_required">*</span><!-- END required --> |
|
98
|
|
|
{label} |
|
99
|
|
|
</label> |
|
100
|
|
|
<div class="col-sm-'.$size[1].'"> |
|
101
|
|
|
{icon} |
|
102
|
|
|
{element} |
|
103
|
|
|
|
|
104
|
|
|
<!-- BEGIN label_2 --> |
|
105
|
|
|
<p class="help-block">{label_2}</p> |
|
106
|
|
|
<!-- END label_2 --> |
|
107
|
|
|
|
|
108
|
|
|
<!-- BEGIN error --> |
|
109
|
|
|
<span class="help-inline help-block">{error}</span> |
|
110
|
|
|
<!-- END error --> |
|
111
|
|
|
</div> |
|
112
|
|
|
<div class="col-sm-'.$size[2].'"> |
|
113
|
|
|
<!-- BEGIN label_3 --> |
|
114
|
|
|
{label_3} |
|
115
|
|
|
<!-- END label_3 --> |
|
116
|
|
|
</div> |
|
117
|
|
|
</div> |
|
118
|
|
|
<div class="form-group {error_class}"> |
|
119
|
|
|
<label class="col-sm-'.$size[0].' control-label" > |
|
120
|
|
|
<!-- BEGIN required --><span class="form_required">*</span><!-- END required --> |
|
121
|
|
|
'.get_lang('Hour').' |
|
122
|
|
|
</label> |
|
123
|
|
|
<div class="col-sm-'.$size[1].'"> |
|
124
|
|
|
<div class="input-group"> |
|
125
|
|
|
<p id="'.$id.'_time_range"> |
|
126
|
|
|
<input type="text" id="'.$id.'_time_range_start" name="'.$id.'_time_range_start" class="time start" autocomplete="off"> |
|
127
|
|
|
'.get_lang('To').' |
|
128
|
|
|
<input type="text" id="'.$id.'_time_range_end" name="'.$id.'_time_range_end" class="time end " autocomplete="off"> |
|
129
|
|
|
</p> |
|
130
|
|
|
</div> |
|
131
|
|
|
</div> |
|
132
|
|
|
</div> |
|
133
|
|
|
</span> |
|
134
|
|
|
'; |
|
135
|
|
|
break; |
|
136
|
|
|
case FormValidator::LAYOUT_BOX_NO_LABEL: |
|
137
|
|
|
return ' |
|
138
|
|
|
<label {label-for}>{label}</label> |
|
139
|
|
|
<div class="input-group"> |
|
140
|
|
|
|
|
141
|
|
|
{icon} |
|
142
|
|
|
{element} |
|
143
|
|
|
</div>'; |
|
144
|
|
|
break; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param array $dateRange |
|
150
|
|
|
* |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
|
|
public function parseDateRange($dateRange) |
|
154
|
|
|
{ |
|
155
|
|
|
$dateRange = Security::remove_XSS($dateRange); |
|
156
|
|
|
$dates = explode('@@', $dateRange); |
|
157
|
|
|
$dates = array_map('trim', $dates); |
|
158
|
|
|
$start = isset($dates[0]) ? $dates[0] : ''; |
|
159
|
|
|
$end = isset($dates[1]) ? $dates[1] : ''; |
|
160
|
|
|
|
|
161
|
|
|
$date = substr($start, 0, 10); |
|
162
|
|
|
$start = isset($dates[0]) ? $dates[0] : ''; |
|
163
|
|
|
//$start = substr($start, 11, strlen($start)); |
|
164
|
|
|
//$end = substr($end, 11, strlen($end)); |
|
165
|
|
|
|
|
166
|
|
|
return [ |
|
167
|
|
|
'date' => $date, |
|
168
|
|
|
'start_time' => $start, |
|
169
|
|
|
'end_time' => $end, |
|
170
|
|
|
]; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param string $value |
|
175
|
|
|
*/ |
|
176
|
|
|
public function setValue($value) |
|
177
|
|
|
{ |
|
178
|
|
|
$this->updateAttributes( |
|
179
|
|
|
[ |
|
180
|
|
|
'value' => $value, |
|
181
|
|
|
] |
|
182
|
|
|
); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Get the necessary javascript for this datepicker. |
|
187
|
|
|
* |
|
188
|
|
|
* @return string |
|
189
|
|
|
*/ |
|
190
|
|
|
private function getElementJS() |
|
191
|
|
|
{ |
|
192
|
|
|
$js = null; |
|
193
|
|
|
$id = $this->getAttribute('id'); |
|
194
|
|
|
|
|
195
|
|
|
$dateRange = $this->getValue(); |
|
196
|
|
|
|
|
197
|
|
|
$defaultDate = ''; |
|
198
|
|
|
$startTime = ''; |
|
199
|
|
|
$endTime = ''; |
|
200
|
|
|
if (!empty($dateRange)) { |
|
201
|
|
|
$dates = $this->parseDateRange($dateRange); |
|
202
|
|
|
$defaultDate = $dates['date']; |
|
203
|
|
|
$startTime = $dates['start_time']; |
|
204
|
|
|
$endTime = $dates['end_time']; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
$js .= "<script> |
|
208
|
|
|
$(function() { |
|
209
|
|
|
var txtDate = $('#$id'), |
|
210
|
|
|
inputGroup = txtDate.parents('.input-group'), |
|
211
|
|
|
txtDateAlt = $('#{$id}_alt'), |
|
212
|
|
|
txtDateAltText = $('#{$id}_alt_text'); |
|
213
|
|
|
|
|
214
|
|
|
txtDate |
|
215
|
|
|
.hide() |
|
216
|
|
|
.datepicker({ |
|
217
|
|
|
defaultDate: '".$defaultDate."', |
|
218
|
|
|
dateFormat: 'yy-mm-dd', |
|
219
|
|
|
altField: '#{$id}_alt', |
|
220
|
|
|
altFormat: \"".get_lang('DateFormatLongNoDayJS')."\", |
|
221
|
|
|
showOn: 'both', |
|
222
|
|
|
buttonImage: '".Display::return_icon('attendance.png', null, [], ICON_SIZE_TINY, true, true)."', |
|
223
|
|
|
buttonImageOnly: true, |
|
224
|
|
|
buttonText: '".get_lang('SelectDate')."', |
|
225
|
|
|
changeMonth: true, |
|
226
|
|
|
changeYear: true, |
|
227
|
|
|
yearRange: 'c-60y:c+5y' |
|
228
|
|
|
}) |
|
229
|
|
|
.on('change', function (e) { |
|
230
|
|
|
txtDateAltText.text(txtDateAlt.val()); |
|
231
|
|
|
}); |
|
232
|
|
|
|
|
233
|
|
|
txtDateAltText.on('click', function () { |
|
234
|
|
|
txtDate.datepicker('show'); |
|
235
|
|
|
}); |
|
236
|
|
|
|
|
237
|
|
|
inputGroup |
|
238
|
|
|
.find('button') |
|
239
|
|
|
.on('click', function (e) { |
|
240
|
|
|
e.preventDefault(); |
|
241
|
|
|
$('#$id, #{$id}_alt').val(''); |
|
242
|
|
|
$('#{$id}_alt_text').html(''); |
|
243
|
|
|
}); |
|
244
|
|
|
|
|
245
|
|
|
$('#".$id."_time_range .time').timepicker({ |
|
246
|
|
|
'showDuration': true, |
|
247
|
|
|
'timeFormat': 'H:i:s', |
|
248
|
|
|
'scrollDefault': 'now', |
|
249
|
|
|
}); |
|
250
|
|
|
|
|
251
|
|
|
$('#".$id."_time_range_start').timepicker('setTime', new Date('".$startTime."')); |
|
252
|
|
|
$('#".$id."_time_range_end').timepicker('setTime', new Date('".$endTime."')); |
|
253
|
|
|
|
|
254
|
|
|
var timeOnlyExampleEl = document.getElementById('".$id."_time_range'); |
|
255
|
|
|
var timeOnlyDatepair = new Datepair(timeOnlyExampleEl); |
|
256
|
|
|
}); |
|
257
|
|
|
</script>"; |
|
258
|
|
|
|
|
259
|
|
|
return $js; |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.