| 1 | <title>PeriodiCalendar</Title> |
| 2 | <h1>PeriodiCal</h1> |
| 3 | <small>Calendar with period highlighting ability</small> |
| 4 | <?php if(!isset($_GET['last'])) { ?> |
| 5 | <form action="?" method="GET"> |
| 6 | Last: <input type="text" name="last" value="2010-01-20" title="YYYY-MM-DD date of last occurence" /> |
| 7 | Periodicity: <input type="text" name="period" value="28" title="Periodicity of cycle in days" /> |
| 8 | Duration: <input type="text" name="len" value="7" title="Days to highlight from beginning of cycle" /> |
| 9 | Months: <input type="text" name="months" value="12" title="How many months you want to draw" /> |
| 10 | <input type="submit" value="DRAW" /> |
| 11 | </form> |
| 12 | |
| 13 | <?php |
| 14 | echo("\n<!-- OPEN SOURCE:\n");readfile(__FILE__);echo("\n-".'->'); |
| 15 | } else { |
| 16 | //init |
| 17 | error_reporting(0); |
| 18 | $day = 60*60*24; |
| 19 | //get numbers |
| 20 | $now = time(); $now = mktime(12, 0, 0, date('n',$now), 1, date('Y',$now)); |
| 21 | $last = date_parse_from_format('Y-m-d', $_GET['last']); |
| 22 | $last = mktime(12, 0, 0, $last['month'], $last['day'], $last['year']); |
| 23 | $period=28; if(isset($_GET['period'])) $period = $_GET['period']; |
| 24 | $length=7; if(isset($_GET['len'])) $length = $_GET['len']; |
| 25 | $months=12; if(isset($_GET['months'])) $months = $_GET['months']; |
| 26 | |
| 27 | echo('<table border=1>'); |
| 28 | $r = 0; |
| 29 | for($i=0;$i<$months;$i++) { |
| 30 | $lm = $m = date('m',$now); |
| 31 | $mo = date('M',$now); |
| 32 | echo("<tr><td bgcolor='lightblue'><b>$m ($mo)</b></td>"); |
| 33 | while($m == $lm) { |
| 34 | if(round(($now-$last)/$day)%($period) == 0) $r = $length; |
| 35 | $c = ''; |
| 36 | if($r>0) $c = '#FF0000'; |
| 37 | if($r==1 || $r==$length) $c = '#FF7777'; |
| 38 | $r--; |
| 39 | echo("<td bgcolor='$c'>".date('d', $now).'</td>'); |
| 40 | $now += $day; |
| 41 | $m = date('m',$now); |
| 42 | } |
| 43 | echo('</tr>'); |
| 44 | } |
| 45 | echo('</table><small>You can bookmark this page it will get updated automatically each month.</small>'); |
| 46 | } |