aboutsummaryrefslogtreecommitdiff
path: root/views/default/input/date.php
blob: 828ce55207c81b2d564c99796b614fbed31f2c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
 * Elgg date input
 * Displays a text field with a popup date picker.
 *
 * The elgg.ui JavaScript library initializes the jQueryUI datepicker based
 * on the CSS class .elgg-input-date. It uses the ISO 8601 standard for date
 * representation: yyyy-mm-dd.
 *
 * Unix timestamps are supported by setting the 'timestamp' parameter to true.
 * The date is still displayed to the user in a text format but is submitted as
 * a unix timestamp in seconds.
 *
 * @uses $vars['value']     The current value, if any (as a unix timestamp)
 * @uses $vars['class']     Additional CSS class
 * @uses $vars['timestamp'] Store as a Unix timestamp in seconds. Default = false
 *                          Note: you cannot use an id with the timestamp option.
 */

//@todo popup_calendar deprecated in 1.8.  Remove in 2.0
if (isset($vars['class'])) {
	$vars['class'] = "elgg-input-date popup_calendar {$vars['class']}";
} else {
	$vars['class'] = "elgg-input-date popup_calendar";
}

$defaults = array(
	'value' => '',
	'disabled' => false,
	'timestamp' => false,
);

$vars = array_merge($defaults, $vars);

$timestamp = $vars['timestamp'];
unset($vars['timestamp']);

if ($timestamp) {
	echo elgg_view('input/hidden', array(
		'name' => $vars['name'],
		'value' => $vars['value'],
	));

	$vars['class'] = "{$vars['class']} elgg-input-timestamp";
	$vars['id'] = $vars['name'];
	unset($vars['name']);
	unset($vars['internalname']);
}

// convert timestamps to text for display
if (is_numeric($vars['value'])) {
	$vars['value'] = gmdate('Y-m-d', $vars['value']);
}

$attributes = elgg_format_attributes($vars);
echo "<input type=\"text\" $attributes />";