summaryrefslogtreecommitdiffabout
path: root/htdocs/examples/calendar.chtml
Side-by-side diff
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 @@
+<%impl>
+ /* vim:set ft=sitecing: */
+ #include <time.h>
+ #include <konforka/exception.h>
+</%impl>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+ <head>
+ <title>really simple page</title>
+ <style type="text/css">
+ table.calendar {
+ font-family: monospace;
+ }
+ table.calendar th.heading {
+ border: double blue 3px;
+ }
+ table.calendar td {
+ text-align: right;
+ margin: 0.5ex; padding: 2px;
+ border: solid 1px black;
+ }
+ table.calendar .wd-0, table.calendar .wd-6 {
+ color: red;
+ }
+ table.calendar td.unexistant {
+ border: none;
+ }
+ table.calendar td.today {
+ background: #ffffc0;
+ color: blue;
+ font-weight: bold;
+ }
+ </style>
+ </head>
+ <body>
+% /* Just call the calendar member function */
+% calendar();
+ </body>
+</html>
+<%method void calendar() %>
+ <%code>
+ time_t tt = time(0);
+ struct tm t;
+ if(!localtime_r(&tt,&t))
+ throw konforka::exception(CODEPOINT,"couldn't fetch current date");
+ char h[16];
+ if(strftime(h,sizeof(h),"%B, %Y",&t)>=sizeof(h))
+ throw konforka::exception(CODEPOINT,"couldn't produce heading for the calendar");
+ int today = t.tm_mday;
+ t.tm_mday = 1;
+ tt=mktime(&t);
+ if(!localtime_r(&tt,&t))
+ throw konforka::exception(CODEPOINT,"couldn't fetch current date");
+ int dim = 31;
+ if(t.tm_mon==3 || t.tm_mon==5 || t.tm_mon==8 || t.tm_mon==10) {
+ dim = 30;
+ }else if(t.tm_mon==1) {
+ dim = (t.tm_year%4)?28:29;
+ }
+ </%code>
+ <table class="calendar">
+ <tr>
+ <th class="heading" colspan="7"><% h %></th>
+ </tr>
+ <tr>
+ <th class="wd-0">Sun</th>
+ <th class="wd-1">Mon</th>
+ <th class="wd-2">Tue</th>
+ <th class="wd-3">Wed</th>
+ <th class="wd-4">Thu</th>
+ <th class="wd-5">Fri</th>
+ <th class="wd-6">Sat</th>
+ </tr>
+ <%code>
+ int dow=0; int dom=1-t.tm_wday;
+ for(;;dom++,dow=(dow+1)%7) {
+ if(!dow) {
+ <%output>
+ <tr>
+ </%output>
+ }
+ bool be = (dom>=1 && dom<=dim);
+ std::string ec = be?" existant":" unexistant";
+ if(dom==today)
+ ec+=" today";
+ <%output><td class="wd-<% dow %><% ec %>"></%output>
+ if(be) {
+ <%output><% dom %></%output>
+ }
+ <%output></td></%output>
+ if(dow==6) {
+ <%output>
+ </tr>
+ </%output>
+ if(dom>=dim)
+ break;
+ }
+ }
+ </%code>
+ </table>
+</%method>