From 8aa9af93aea1e99966e8a579e44a827899ea5fa0 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 15 Oct 2007 04:22:06 +0000 Subject: [PATCH] Added a mini month calendar to the day view. Day links are hot, but the previous/next month links are not yet working. --- webcit/calendar_view.c | 135 ++++++++++++++++++++++++++++++++++++++- webcit/static/webcit.css | 29 +++++++++ 2 files changed, 162 insertions(+), 2 deletions(-) diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index b9f212a76..cf5414f7b 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -13,6 +13,135 @@ /****************************************************************************/ + +/** + */ +void embeddable_mini_calendar(int year, int month, char *urlformat) +{ + struct tm starting_tm; + struct tm tm; + time_t thetime; + int i; + time_t previous_month; + time_t next_month; + time_t colheader_time; + struct tm colheader_tm; + char colheader_label[32]; + int weekstart = 0; + char weekstart_buf[16]; + char url[256]; + char div_id[256]; + + snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() ); + + /* Determine what day to start. + */ + get_preference("weekstart", weekstart_buf, sizeof weekstart_buf); + weekstart = atoi(weekstart_buf); + + /* + * Now back up to the 1st of the month... + */ + memset(&starting_tm, 0, sizeof(struct tm)); + + starting_tm.tm_year = year - 1900; + starting_tm.tm_mon = month - 1; + starting_tm.tm_mday = 1; + thetime = mktime(&starting_tm); + + memcpy(&tm, &starting_tm, sizeof(struct tm)); + while (tm.tm_mday != 1) { + thetime = thetime - (time_t)86400; /* go back 24 hours */ + localtime_r(&thetime, &tm); + } + + /** Determine previous and next months ... for links */ + previous_month = thetime - (time_t)864000L; /* back 10 days */ + next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */ + + /** Now back up until we're on the user's preferred start day */ + localtime_r(&thetime, &tm); + while (tm.tm_wday != weekstart) { + thetime = thetime - (time_t)86400; /* go back 24 hours */ + localtime_r(&thetime, &tm); + } + + wprintf("
\n", div_id); + + localtime_r(&previous_month, &tm); + + wprintf("«"); + wprintf(" "); +/* previous month + wprintf("", + (int)(tm.tm_year)+1900, tm.tm_mon + 1); + wprintf("\n"); +*/ + + wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm); + wprintf("  " + "" + "%s %d" + "" + "  ", colheader_label, year); + + wprintf(" "); + wprintf("»"); +/* + localtime_r(&next_month, &tm); + wprintf("", + (int)(tm.tm_year)+1900, tm.tm_mon + 1); + wprintf("\n"); +*/ + + wprintf("" + ""); + colheader_time = thetime; + for (i=0; i<7; ++i) { + colheader_time = thetime + (i * 86400) ; + localtime_r(&colheader_time, &colheader_tm); + wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm); + wprintf("", colheader_label[0]); + + } + wprintf("\n"); + + + /** Now do 35 or 42 days */ + for (i = 0; i < 42; ++i) { + localtime_r(&thetime, &tm); + + if (i < 35) { + + /** Before displaying Sunday, start a new row */ + if ((i % 7) == 0) { + wprintf(""); + } + + if (tm.tm_mon == month-1) { + snprintf(url, sizeof url, urlformat, + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday); + wprintf("", url, tm.tm_mday); + } + else { + wprintf(""); + } + + /** After displaying one week, end the row */ + if ((i % 7) == 6) { + wprintf("\n"); + } + + } + + thetime += (time_t)86400; /** ahead 24 hours */ + } + + wprintf("
%c
%d
" /** end of inner table */ + "
\n"); +} + + /** * \brief Display one day of a whole month view of a calendar * \param thetime the month we want to see @@ -882,7 +1011,7 @@ void calendar_day_view(int year, int month, int day) { wprintf(""); /** end extra on the middle */ - wprintf(""); /** begin stuff-on-the-right */ + wprintf(""); /** begin stuff-on-the-right */ /** Begin todays-date-with-left-and-right-arrows */ wprintf("
\n"); /** End todays-date-with-left-and-right-arrows */ - /** \todo In the future we might want to put a month-o-matic here */ + /** Embed a mini month calendar in this space */ + wprintf("
\n"); + embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d"); wprintf("\n"); diff --git a/webcit/static/webcit.css b/webcit/static/webcit.css index 0621de557..466d3d776 100644 --- a/webcit/static/webcit.css +++ b/webcit/static/webcit.css @@ -1190,3 +1190,32 @@ td.events_of_the_day { opacity: 1.0; } +.mini_calendar { + color: #fff; +} + +.mini_calendar a { + color: #fff; +} + +.mini_calendar a: link,.mini_calendar a:visited { + color: #fff; +} + +.mini_calendar a:hover,.mini_calendar a:active { + color: #fff; + background-color: #AD1C00; +} + +.mini_calendar td a { + color: #fff; +} + +.mini_calendar td a: link,.mini_calendar td a:visited { + color: #fff; +} + +.mini_calendar td a:hover,.mini_calendar td a:active { + color: #fff; + background-color: #AD1C00; +} -- 2.30.2