X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fcalendar_view.c;h=0af1842ec1d2ec48c207c3cf76322130f4d67ec9;hb=808f3be91dd6b6677e380695e2f16e6473141a7e;hp=ec9d274fb85d4b6ed6f06a78dde1dd426489d639;hpb=56507b33b546f937f45407602e01148705fd4788;p=citadel.git diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index ec9d274fb..0af1842ec 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -1,235 +1,375 @@ /* * $Id$ + * + * Handles the HTML display of calendar items. */ -/** - * \defgroup CalHtmlHandles Handles the HTML display of calendar items. - * \ingroup Calendaring - */ -/*@{*/ + #include "webcit.h" #include "webserver.h" -#ifdef WEBCIT_WITH_CALENDAR_SERVICE -/****************************************************************************/ +void embeddable_mini_calendar(int year, int month, char *urlformat) +{ + struct tm starting_tm; + struct tm tm; + time_t thetime; + int i, len; + time_t previous_month; + time_t next_month; + time_t colheader_time; + struct tm colheader_tm; + char colheader_label[32]; + long weekstart = 0; + char url[256]; + char div_id[256]; + char escaped_urlformat[256]; + + snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() ); + + /* Determine what day to start. If an impossible value is found, start on Sunday. + */ + get_pref_long("weekstart", &weekstart, 17); + if (weekstart > 6) weekstart = 0; + + /* + * 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("
%c | ", colheader_label[0]); -/** - * \brief Display one day of a whole month view of a calendar - * \param thetime the month we want to see + } + wprintf("|
---|---|
%d | ", url, tm.tm_mday); + } + else { + wprintf(""); + } + + /* After displaying one week, end the row */ + if ((i % 7) == 6) { + wprintf(" |