source: branches/version-2_4/data/module/Calendar/docs/examples/5.php @ 18734

Revision 18734, 4.2 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

Line 
1<?php
2/**
3* Description: generating elements of a form with PEAR::Calendar, using
4* selections as well as validating the submission
5*/
6function getmicrotime(){
7    list($usec, $sec) = explode(" ",microtime());
8    return ((float)$usec + (float)$sec);
9}
10$start = getmicrotime();
11
12if ( !@include 'Calendar/Calendar.php' ) {
13    define('CALENDAR_ROOT','../../');
14}
15require_once CALENDAR_ROOT.'Year.php';
16require_once CALENDAR_ROOT.'Month.php';
17require_once CALENDAR_ROOT.'Day.php';
18require_once CALENDAR_ROOT.'Hour.php';
19require_once CALENDAR_ROOT.'Minute.php';
20require_once CALENDAR_ROOT.'Second.php';
21
22// Initialize if not set
23if (!isset($_POST['y'])) $_POST['y'] = date('Y');
24if (!isset($_POST['m'])) $_POST['m'] = date('n');
25if (!isset($_POST['d'])) $_POST['d'] = date('j');
26if (!isset($_POST['h'])) $_POST['h'] = date('H');
27if (!isset($_POST['i'])) $_POST['i'] = date('i');
28if (!isset($_POST['s'])) $_POST['s'] = date('s');
29?>
30<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
31<html>
32<head>
33<title> Select and Update </title>
34</head>
35<body>
36<h1>Select and Update</h1>
37<?php
38if ( isset($_POST['update']) ) {
39    $Second = & new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']);
40    if ( !$Second->isValid() ) {
41        $V= & $Second->getValidator();
42        echo ('<p>Validation failed:</p>' );
43        while ( $error = $V->fetch() ) {
44            echo ( $error->toString() .'<br>' );
45        }
46    } else {
47        echo ('<p>Validation success.</p>' );
48        echo ( '<p>New timestamp is: '.$Second->getTimeStamp().' which could be used to update a database, for example');
49    }
50} else {
51$Year = new Calendar_Year($_POST['y']);
52$Month = new Calendar_Month($_POST['y'],$_POST['m']);
53$Day = new Calendar_Day($_POST['y'],$_POST['m'],$_POST['d']);
54$Hour = new Calendar_Hour($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h']);
55$Minute = new Calendar_Minute($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i']);
56$Second = new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']);
57?>
58<p><b>Set the alarm clock</p></p>
59<form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="post">
60Year: <input type="text" name="y" value="<?php echo ( $_POST['y'] ); ?>" size="4">&nbsp;
61Month:<select name="m">
62<?php
63$selection = array($Month);
64$Year->build($selection);
65while ( $Child = & $Year->fetch() ) {
66    if ( $Child->isSelected() ) {
67        echo ( "<option value=\"".$Child->thisMonth()."\" selected>".$Child->thisMonth()."\n" );
68    } else {
69        echo ( "<option value=\"".$Child->thisMonth()."\">".$Child->thisMonth()."\n" );
70    }
71}
72?>
73</select>&nbsp;
74Day:<select name="d">
75<?php
76$selection = array($Day);
77$Month->build($selection);
78while ( $Child = & $Month->fetch() ) {
79    if ( $Child->isSelected() ) {
80        echo ( "<option value=\"".$Child->thisDay()."\" selected>".$Child->thisDay()."\n" );
81    } else {
82        echo ( "<option value=\"".$Child->thisDay()."\">".$Child->thisDay()."\n" );
83    }
84}
85?>
86</select>&nbsp;
87Hour:<select name="h">
88<?php
89$selection = array($Hour);
90$Day->build($selection);
91while ( $Child = & $Day->fetch() ) {
92    if ( $Child->isSelected() ) {
93        echo ( "<option value=\"".$Child->thisHour()."\" selected>".$Child->thisHour()."\n" );
94    } else {
95        echo ( "<option value=\"".$Child->thisHour()."\">".$Child->thisHour()."\n" );
96    }
97}
98?>
99</select>&nbsp;
100Minute:<select name="i">
101<?php
102$selection = array($Minute);
103$Hour->build($selection);
104while ( $Child = & $Hour->fetch() ) {
105    if ( $Child->isSelected() ) {
106        echo ( "<option value=\"".$Child->thisMinute()."\" selected>".$Child->thisMinute()."\n" );
107    } else {
108        echo ( "<option value=\"".$Child->thisMinute()."\">".$Child->thisMinute()."\n" );
109    }
110}
111?>
112</select>&nbsp;
113Second:<select name="s">
114<?php
115$selection = array($Second);
116$Minute->build($selection);
117while ( $Child = & $Minute->fetch() ) {
118    if ( $Child->isSelected() ) {
119        echo ( "<option value=\"".$Child->thisSecond()."\" selected>".$Child->thisSecond()."\n" );
120    } else {
121        echo ( "<option value=\"".$Child->thisSecond()."\">".$Child->thisSecond()."\n" );
122    }
123}
124?>
125</select>&nbsp;
126<input type="submit" name="update" value="Set Alarm"><br>
127<?php
128}
129?>
130<?php echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); ?>
131</body>
132</html>
Note: See TracBrowser for help on using the repository browser.