comparison _xampp/biorhythm.php @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b12c99b7c3f0
1 <?php
2 include("langsettings.php");
3
4 // Biorhythm by Till Gerken
5 // http://www.zend.com/zend/tut/dynamic.php
6 //
7 // Multi-language support by Kai Oswald Seidler, 2003
8 //
9 // Print a standard page header
10 //
11 function pageHeader()
12 {
13 global $TEXT;
14
15 print("<html><head>");
16 print("<title>Biorhythm with PHP</title>");
17 print('<link href="xampp.css" rel="stylesheet" type="text/css">');
18 print("</head><body>");
19
20 print("&nbsp;<p><h1>".$TEXT['bio-head']."</h1>");
21 print($TEXT['bio-by']." Till Gerken<br><a class=black href=http://www.zend.com/zend/tut/dynamic.php>http://www.zend.com/zend/tut/dynamic.php</a><p>");
22
23 }
24
25 //
26 // Print a standard page footer
27 //
28 function pageFooter()
29 {
30
31 include("lang/".file_get_contents("lang.tmp").".php");
32 include("showcode.php");
33
34 print("</body></html>");
35
36 }
37
38 //
39 // Function to draw a curve of the biorythm
40 // Parameters are the day number for which to draw,
41 // period of the specific curve and its color
42 //
43 function drawRhythm($daysAlive, $period, $color)
44 {
45 global $daysToShow, $image, $diagramWidth, $diagramHeight;
46
47 // get day on which to center
48 $centerDay = $daysAlive - ($daysToShow / 2);
49
50 // calculate diagram parameters
51 $plotScale = ($diagramHeight - 25) / 2;
52 $plotCenter = ($diagramHeight - 25) / 2;
53
54 // draw the curve
55 for($x = 0; $x <= $daysToShow; $x++)
56 {
57 // calculate phase of curve at this day, then Y value
58 // within diagram
59 $phase = (($centerDay + $x) % $period) / $period * 2 * pi();
60 $y = 1 - sin($phase) * (float)$plotScale + (float)$plotCenter;
61
62 // draw line from last point to current point
63 if($x > 0)
64 imageLine($image, $oldX, $oldY,
65 $x * $diagramWidth / $daysToShow, $y, $color);
66
67 // save current X/Y coordinates as start point for next line
68 $oldX = $x * $diagramWidth / $daysToShow;
69 $oldY = $y;
70 }
71
72 }
73
74 //
75 // ---- MAIN PROGRAM START ----
76
77 // check if we already have a date to work with,
78 // if not display a form for the user to enter one
79 if(!isset($_REQUEST['birthdate']))
80 {
81 pageHeader();
82
83 ?>
84 <form method="get" action="biorhythm.php">
85 <!-- Please enter your birthday: -->
86 <?=$TEXT['bio-ask']?>:
87 <br>
88 <input type="text" name="birthdate" value="MM/DD/YYYY"><p>
89 <input type=submit value="<?=$TEXT['bio-ok']?>">
90 <input type="hidden" name="showpng" value=1>
91 </form>
92 <?php
93
94 pageFooter();
95
96 exit();
97 }
98
99 // get different parts of the date
100 $birthMonth = substr($_REQUEST['birthdate'], 0, 2);
101 $birthDay = substr($_REQUEST['birthdate'], 3, 2);
102 $birthYear = substr($_REQUEST['birthdate'], 6, 4);
103
104 // check date for validity, display error message if invalid
105 if(!checkDate($birthMonth, $birthDay, $birthYear))
106 {
107 pageHeader();
108
109 //print("The date '$birthMonth/$birthDay/$birthYear' is invalid.");
110 print("<h2>".$TEXT['bio-error1']." '$birthMonth/$birthDay/$birthYear' ".$TEXT['bio-error2'].".</h2>");
111
112 pageFooter();
113
114 exit();
115 }
116
117 if(@$_REQUEST['showpng']==1)
118 {
119 pageHeader();
120
121 echo "<img src=\"biorhythm.php?birthdate=".urlencode($_REQUEST['birthdate'])."\">";
122 pageFooter();
123 exit();
124 }
125 // specify diagram parameters (these are global)
126 $diagramWidth = 710;
127 $diagramHeight = 400;
128 $daysToShow = 30;
129
130 // calculate the number of days this person is alive
131 // this works because Julian dates specify an absolute number
132 // of days -> the difference between Julian birthday and
133 // "Julian today" gives the number of days alive
134 $daysGone = abs(gregorianToJD($birthMonth, $birthDay, $birthYear)
135 - gregorianToJD(date( "m"), date( "d"), date( "Y")));
136
137 // create image
138 $image = imageCreate($diagramWidth, $diagramHeight);
139
140 // allocate all required colors
141 $colorBackgr = imageColorAllocate($image, 192, 192, 192);
142 $colorForegr = imageColorAllocate($image, 255, 255, 255);
143 $colorGrid = imageColorAllocate($image, 0, 0, 0);
144 $colorCross = imageColorAllocate($image, 0, 0, 0);
145 $colorPhysical = imageColorAllocate($image, 0, 0, 255);
146 $colorEmotional = imageColorAllocate($image, 255, 0, 0);
147 $colorIntellectual = imageColorAllocate($image, 0, 255, 0);
148
149 // clear the image with the background color
150 imageFilledRectangle($image, 0, 0, $diagramWidth - 1, $diagramWidth - 1, $colorBackgr);
151
152 // calculate start date for diagram and start drawing
153 $nrSecondsPerDay = 60 * 60 * 24;
154 $diagramDate = time() - ($daysToShow / 2 * $nrSecondsPerDay)
155 + $nrSecondsPerDay;
156
157 for ($i = 1; $i < $daysToShow; $i++)
158 {
159 $thisDate = getDate($diagramDate);
160 $xCoord = ($diagramWidth / $daysToShow) * $i;
161
162 // draw day mark and day number
163 imageLine($image, $xCoord, $diagramHeight - 25, $xCoord,
164 $diagramHeight - 20, $colorGrid);
165 imageString($image, 3, $xCoord - 5, $diagramHeight - 16,
166 $thisDate[ "mday"], $colorGrid);
167
168 $diagramDate += $nrSecondsPerDay;
169 }
170
171 // draw rectangle around diagram (marks its boundaries)
172 imageRectangle($image, 0, 0, $diagramWidth - 1, $diagramHeight - 20,
173 $colorGrid);
174
175 // draw middle cross
176 imageLine($image, 0, ($diagramHeight - 20) / 2, $diagramWidth,
177 ($diagramHeight - 20) / 2, $colorCross);
178 imageLine($image, $diagramWidth / 2, 0, $diagramWidth / 2, $diagramHeight - 20,
179 $colorCross);
180
181 // print descriptive text into the diagram
182 imageString($image, 3, 10, 10, $TEXT['bio-birthday'].": $birthDay.$birthMonth.$birthYear",
183 $colorCross);
184 imageString($image, 3, 10, 26, $TEXT['bio-today'].": ". date( "d.m.Y"), $colorCross);
185 imageString($image, 3, 10, $diagramHeight - 42, $TEXT['bio-physical'], $colorPhysical);
186 imageString($image, 3, 10, $diagramHeight - 58, $TEXT['bio-emotional'], $colorEmotional);
187 imageString($image, 3, 10, $diagramHeight - 74, $TEXT['bio-intellectual'], $colorIntellectual);
188
189 // now draw each curve with its appropriate parameters
190 drawRhythm($daysGone, 23, $colorPhysical);
191 drawRhythm($daysGone, 28, $colorEmotional);
192 drawRhythm($daysGone, 33, $colorIntellectual);
193
194 // set the content type
195 header("Content-type: image/png");
196
197 // create an interlaced image for better loading in the browser
198 imageInterlace($image, 1);
199
200 // mark background color as being transparent
201 imageColorTransparent($image, $colorBackgr);
202
203 // now send the picture to the client (this outputs all image data directly)
204 imagePNG($image);
205
206 ?>