summaryrefslogtreecommitdiffabout
path: root/htdocs/examples/calendar.chtml
blob: 85aa7baaedbe2bbb51827983312e6e6a975edecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<%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">
% __SCIF->flush();
<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>