summaryrefslogtreecommitdiffabout
path: root/htdocs/examples/calendar.chtml
Unidiff
Diffstat (limited to 'htdocs/examples/calendar.chtml') (more/less context) (ignore whitespace changes)
-rw-r--r--htdocs/examples/calendar.chtml101
1 files changed, 101 insertions, 0 deletions
diff --git a/htdocs/examples/calendar.chtml b/htdocs/examples/calendar.chtml
new file mode 100644
index 0000000..eea20cb
--- a/dev/null
+++ b/htdocs/examples/calendar.chtml
@@ -0,0 +1,101 @@
1<%impl>
2 /* vim:set ft=sitecing: */
3 #include <time.h>
4 #include <konforka/exception.h>
5</%impl>
6<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
7<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
8 <head>
9 <title>really simple page</title>
10 <style type="text/css">
11 table.calendar {
12 font-family: monospace;
13 }
14 table.calendar th.heading {
15 border: double blue 3px;
16 }
17 table.calendar td {
18 text-align: right;
19 margin: 0.5ex; padding: 2px;
20 border: solid 1px black;
21 }
22 table.calendar .wd-0, table.calendar .wd-6 {
23 color: red;
24 }
25 table.calendar td.unexistant {
26 border: none;
27 }
28 table.calendar td.today {
29 background: #ffffc0;
30 color: blue;
31 font-weight: bold;
32 }
33 </style>
34 </head>
35 <body>
36% /* Just call the calendar member function */
37% calendar();
38 </body>
39</html>
40<%method void calendar() %>
41 <%code>
42 time_t tt = time(0);
43 struct tm t;
44 if(!localtime_r(&tt,&t))
45 throw konforka::exception(CODEPOINT,"couldn't fetch current date");
46 char h[16];
47 if(strftime(h,sizeof(h),"%B, %Y",&t)>=sizeof(h))
48 throw konforka::exception(CODEPOINT,"couldn't produce heading for the calendar");
49 int today = t.tm_mday;
50 t.tm_mday = 1;
51 tt=mktime(&t);
52 if(!localtime_r(&tt,&t))
53 throw konforka::exception(CODEPOINT,"couldn't fetch current date");
54 int dim = 31;
55 if(t.tm_mon==3 || t.tm_mon==5 || t.tm_mon==8 || t.tm_mon==10) {
56 dim = 30;
57 }else if(t.tm_mon==1) {
58 dim = (t.tm_year%4)?28:29;
59 }
60 </%code>
61 <table class="calendar">
62 <tr>
63 <th class="heading" colspan="7"><% h %></th>
64 </tr>
65 <tr>
66 <th class="wd-0">Sun</th>
67 <th class="wd-1">Mon</th>
68 <th class="wd-2">Tue</th>
69 <th class="wd-3">Wed</th>
70 <th class="wd-4">Thu</th>
71 <th class="wd-5">Fri</th>
72 <th class="wd-6">Sat</th>
73 </tr>
74 <%code>
75 int dow=0; int dom=1-t.tm_wday;
76 for(;;dom++,dow=(dow+1)%7) {
77 if(!dow) {
78 <%output>
79 <tr>
80 </%output>
81 }
82 bool be = (dom>=1 && dom<=dim);
83 std::string ec = be?" existant":" unexistant";
84 if(dom==today)
85 ec+=" today";
86 <%output><td class="wd-<% dow %><% ec %>"></%output>
87 if(be) {
88 <%output><% dom %></%output>
89 }
90 <%output></td></%output>
91 if(dow==6) {
92 <%output>
93 </tr>
94 </%output>
95 if(dom>=dim)
96 break;
97 }
98 }
99 </%code>
100 </table>
101</%method>