-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.date.class.php
More file actions
83 lines (70 loc) · 1.52 KB
/
input.date.class.php
File metadata and controls
83 lines (70 loc) · 1.52 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* 日付入力
*/
class NyaaFormInputDate extends NyaaFormInput
{
public $template = ':html';
public $from = '1980-01-01';
public $to = '1982-12-01';
public $parseFormat = '([0-9]+)-([0-9]+)-([0-9]+)';
public function __construct( )
{
$this->to = date('Y-m-d');
}
function setFrom( $from )
{
$this->from = $from;
}
function setTo( $to )
{
$this->to = $to;
}
function parseDate( $text )
{
if(preg_match('/'.$this->parseFormat.'/', $text, $m))
{
$ret['year'] = $m[1];
$ret['month'] = $m[2];
$ret['day'] = $m[3];
}
return $ret;
}
function toHtml( )
{
$from = $this->parseDate( $this->from );
$to = $this->parseDate( $this->to );
$optYear = array();
$optMonth = array();
$optDay = array();
for($i=$from['year']; $i <= $to['year']; $i++) $optYear[$i]=$i;
for($i=1; $i <= 12; $i++) $optMonth[$i]=$i;
for($i=1; $i <= 31; $i++) $optDay[$i]=$i;
$year = NyaaFormInput::factory(
array(
'type'=>'select',
'name'=>$this->getProp('name').'[year]',
'options'=>$optYear
)
);
$month = NyaaFormInput::factory(
array(
'type'=>'select',
'name'=>$this->getProp('name').'[month]',
'options'=>$optMonth
)
);
$day = NyaaFormInput::factory(
array(
'type'=>'select',
'name'=>$this->getProp('name').'[day]',
'options'=>$optDay
)
);
$year->setValue( $this->value['year'] );
$month->setValue( $this->value['month'] );
$day->setValue( $this->value['day'] );
return sprintf('%s %s %s', $year, $month, $day);
}
}
?>