X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fcalendar_view.c;h=0e8ac9843385bc217f6326014f2110af9c2033cd;hb=fb6f6fa4ec4e3277e30d84326d48e6850822d318;hp=2a25ec14b18bb7d58211d2007acc2d2d3512647b;hpb=b96a67c49b200c54af8a944dc3f0722843916ceb;p=citadel.git diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 2a25ec14b..0e8ac9843 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -1,253 +1,438 @@ /* - * $Id$ + * Handles the HTML display of calendar items. + * + * Copyright (c) 1996-2012 by the citadel.org team + * + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ -/** - * \defgroup CalHtmlHandles Handles the HTML display of calendar items. - * \ingroup Calendaring - */ -/*@{*/ + #include "webcit.h" #include "webserver.h" +#include "calendar.h" + +/* These define how high the hour rows are in the day view */ +#define TIMELINE 30 +#define EXTRATIMELINE (TIMELINE / 2) + +void embeddable_mini_calendar(int year, int month) +{ + 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]; + long weekstart = 0; + char url[256]; + char div_id[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); + } + + wc_printf("
%c | ", colheader_label[0]); -#ifdef WEBCIT_WITH_CALENDAR_SERVICE + } + wc_printf("|
---|---|
%d | ", url, tm.tm_mday); + } + else { + wc_printf(""); + } + + /* After displaying one week, end the row */ + if ((i % 7) == 6) { + wc_printf(" |