#include "webcit.h"
#include "webserver.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, char *urlformat)
+void embeddable_mini_calendar(int year, int month)
{
struct tm starting_tm;
struct tm tm;
time_t thetime;
- int i, len;
+ int i;
time_t previous_month;
time_t next_month;
time_t colheader_time;
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.
}
if (tm.tm_mon == month-1) {
- snprintf(url, sizeof url, urlformat,
+ snprintf(url, sizeof url, "readfwd?calview=day&year=%d&month=%d&day=%d",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
}
wprintf("</table>" /* end of inner table */
"</div>\n");
- /* javascript for previous and next month */
- len = strlen(urlformat);
- for (i=0; i<len; ++i) {
- sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
- }
-
StrBufAppendPrintf(WC->trailing_javascript,
" function minical_change_month(year, month) { \n"
" p = 'year=' + year + '&month=' + month \n"
- " + '&urlformat=%s&r=' + CtdlRandomString(); \n"
+ " + '&r=' + CtdlRandomString(); \n"
" new Ajax.Updater('%s', 'mini_calendar', \n"
" { method: 'get', parameters: p, evalScripts: true } ); \n"
" } \n"
"",
- escaped_urlformat, div_id
+ div_id
);
}
/*
* ajax embedder for the above mini calendar
*/
-void ajax_mini_calendar(void) {
- char urlformat[256];
- int i, len;
- char *escaped_urlformat;
-
- escaped_urlformat = bstr("urlformat");
- len = strlen(escaped_urlformat) * 2 ;
- for (i=0; i<len; ++i) {
- urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
- urlformat[i+1] = 0;
- }
-
- embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
+void ajax_mini_calendar(void)
+{
+ embeddable_mini_calendar( ibstr("year"), ibstr("month"));
}
int all_day_event = 0;
int show_event = 0;
char buf[256];
- struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ wcsession *WCC = WC;
time_t tt;
if (GetCount(WCC->disp_cal_items) == 0) {
/*
* Now loop through our list of events to see which ones occur today.
*/
- Pos = GetNewHashPos();
+ Pos = GetNewHashPos(WCC->disp_cal_items, 0);
while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
Cal = (disp_cal*)vCal;
all_day_event = 0;
}
else {
tt = icaltime_as_timet(t);
- webcit_fmt_date(buf, tt, 1);
+ webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>",
_("Starting date/time:"), buf);
if (q != NULL) {
t = icalproperty_get_dtend(q);
tt = icaltime_as_timet(t);
- webcit_fmt_date(buf, tt, 1);
+ webcit_fmt_date(buf, tt, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
}
time_t event_tt;
time_t event_tts;
time_t event_tte;
- struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ wcsession *WCC = WC;
struct tm event_tms;
struct tm event_tme;
struct tm today_tm;
day = today_tm.tm_mday;
year = today_tm.tm_year + 1900;
- Pos = GetNewHashPos();
+ Pos = GetNewHashPos(WCC->disp_cal_items, 0);
while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
Cal = (disp_cal*)vCal;
p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
int show_event = 0;
int all_day_event = 0;
int ongoing_event = 0;
- struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ wcsession *WCC = WC;
disp_cal *Cal;
struct icaltimetype t;
struct icaltimetype end_t;
/* Now loop through our list of events to see which ones occur today.
*/
- Pos = GetNewHashPos();
+ Pos = GetNewHashPos(WCC->disp_cal_items, 0);
while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
Cal = (disp_cal*)vCal;
escputs((char *)icalproperty_get_comment(q));
wprintf("<br />");
}
- webcit_fmt_date(buf, event_tt, 1);
+ webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
- webcit_fmt_date(buf, event_tte, 1);
+ webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
if (q) {
/* Calculate the location of the top of the box */
if (event_te.tm_hour < dstart) {
startmin = diffmin = event_te.tm_min / 6;
- top = (event_te.tm_hour * 10) + startmin;
+ top = (event_te.tm_hour * EXTRATIMELINE) + startmin;
}
else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
startmin = diffmin = (event_te.tm_min / 2);
- top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
+ top = (dstart * EXTRATIMELINE) + ((event_te.tm_hour - dstart) * TIMELINE) + startmin;
}
else if (event_te.tm_hour >dend) {
startmin = diffmin = event_te.tm_min / 6;
- top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
+ top = (dstart * EXTRATIMELINE) + ((dend - dstart - 1) * TIMELINE) + ((event_tm.tm_hour - dend + 1) * EXTRATIMELINE) + startmin ;
}
else {
/* should never get here */
/* Calculate the location of the bottom of the box */
if (event_tm.tm_hour < dstart) {
endmin = diffmin = event_tm.tm_min / 6;
- bottom = (event_tm.tm_hour * 10) + endmin;
+ bottom = (event_tm.tm_hour * EXTRATIMELINE) + endmin;
}
else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
endmin = diffmin = (event_tm.tm_min / 2);
- bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
+ bottom = (dstart * EXTRATIMELINE) + ((event_tm.tm_hour - dstart) * TIMELINE) + endmin ;
}
else if (event_tm.tm_hour >dend) {
endmin = diffmin = event_tm.tm_min / 6;
- bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
+ bottom = (dstart * EXTRATIMELINE) + ((dend - dstart + 1) * TIMELINE) + ((event_tm.tm_hour - dend - 1) * EXTRATIMELINE) + endmin;
}
else {
/* should never get here */
escputs((char *)icalproperty_get_comment(q));
wprintf("<br />");
}
- webcit_fmt_date(buf, event_tt, 1);
+ webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
- webcit_fmt_date(buf, event_tte, 1);
+ webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF);
wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
if (q) {
char d_str[128];
int time_format;
time_t today_t;
- int timeline = 30;
- int extratimeline = 0;
+ int timeline = TIMELINE;
+ int extratimeline = EXTRATIMELINE;
int gap = 0;
+ int hourlabel;
+ int extrahourlabel;
time_format = get_time_format_cached ();
get_pref_long("daystart", &daystart, 8);
/* Now the middle of the day... */
- extratimeline = timeline / 3;
+ extrahourlabel = extratimeline - 2;
+ hourlabel = extrahourlabel * 150 / 100;
+ if (hourlabel > (timeline - 2)) hourlabel = timeline - 2;
for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
wprintf("<dt class=\"extrahour\" "
"style=\" "
"position: absolute; "
"top: %dpx; left: 0px; "
- "height: %dpx; "
+ "height: %dpx; "
+ "font-size: %dpx; "
"\" > "
"<a href=\"display_edit_event?msgnum=0"
"?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
- (hour * extratimeline ), extratimeline,
+ (hour * extratimeline ),
+ extratimeline,
+ extrahourlabel,
year, month, day, hour
);
}
else {
wprintf("%d:00%s</a> ",
- (hour <= 12 ? hour : hour-12),
+ ((hour == 0) ? 12 : (hour <= 12 ? hour : hour-12)),
(hour < 12 ? "am" : "pm")
);
}
wprintf("<dt class=\"hour\" "
"style=\" "
"position: absolute; "
- "top: %ldpx; left: 0px; "
+ "top: %ldpx; left: 0px; "
"height: %dpx; "
+ "font-size: %dpx; "
"\" > "
"<a href=\"display_edit_event?msgnum=0?calview=day"
"?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
- gap + ((hour - daystart) * timeline ), timeline,
+ gap + ((hour - daystart) * timeline ),
+ timeline,
+ hourlabel,
year, month, day, hour
);
"position: absolute; "
"top: %ldpx; left: 0px; "
"height: %dpx; "
+ "font-size: %dpx; "
"\" > "
"<a href=\"display_edit_event?msgnum=0?calview=day"
"?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
- gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
+ gap + ((hour - dayend - 1) * extratimeline ),
+ extratimeline,
+ extrahourlabel,
year, month, day, hour
);
/* Embed a mini month calendar in this space */
wprintf("<br />\n");
- embeddable_mini_calendar(year, month, "readfwd?calview=day?year=%d?month=%d?day=%d");
+ embeddable_mini_calendar(year, month);
wprintf("</font></center>\n");
/*
- * Display today's events.
+ * Display today's events. Returns the number of items displayed.
*/
-void calendar_summary_view(void) {
+int calendar_summary_view(void) {
long hklen;
const char *HashKey;
void *vCal;
time_t now;
int all_day_event = 0;
char timestring[SIZ];
- struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ wcsession *WCC = WC;
+ int num_displayed = 0;
if (GetCount(WC->disp_cal_items) == 0) {
- return;
+ return(0);
}
now = time(NULL);
localtime_r(&now, &today_tm);
- Pos = GetNewHashPos();
+ Pos = GetNewHashPos(WCC->disp_cal_items, 0);
while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
Cal = (disp_cal*)vCal;
- p = icalcomponent_get_first_property(Cal->cal,
- ICAL_DTSTART_PROPERTY);
+ p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
if (p != NULL) {
t = icalproperty_get_dtstart(p);
event_tt = icaltime_as_timet(t);
if ( (event_tm.tm_year == today_tm.tm_year)
&& (event_tm.tm_mon == today_tm.tm_mon)
- && (event_tm.tm_mday == today_tm.tm_mday)
+ && (event_tm.tm_mday == today_tm.tm_mday)
) {
+ p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
+ if (p != NULL) {
- p = icalcomponent_get_first_property(
- Cal->cal,
- ICAL_SUMMARY_PROPERTY);
- if (p != NULL) {
- escputs((char *)
- icalproperty_get_comment(p));
- wprintf(" (%s)<br />\n", timestring);
- }
+
+ if (WCC->wc_view == VIEW_TASKS) {
+ wprintf("<a href=\"display_edit_task"
+ "?msgnum=%ld"
+ "?return_to_summary=1"
+ "?gotofirst=",
+ Cal->cal_msgnum
+ );
+ escputs(ChrPtr(WCC->wc_roomname));
+ wprintf("\">");
+ }
+ else {
+ wprintf("<a href=\"display_edit_event"
+ "?msgnum=%ld"
+ "?calview=summary"
+ "?year=%d"
+ "?month=%d"
+ "?day=%d"
+ "?gotofirst=",
+ Cal->cal_msgnum,
+ today_tm.tm_year + 1900,
+ today_tm.tm_mon + 1,
+ today_tm.tm_mday
+ );
+ escputs(ChrPtr(WCC->wc_roomname));
+ wprintf("\">");
+ }
+ escputs((char *) icalproperty_get_comment(p));
+ if (!all_day_event) {
+ wprintf(" (%s)", timestring);
+ }
+ wprintf("</a><br />\n");
+ ++num_displayed;
+ }
}
}
}
DeleteHashPos(&Pos);
DeleteHash(&WC->disp_cal_items);
+ return(num_displayed);
}
-
/*
* Parse the URL variables in order to determine the scope and display of a calendar view
*/
time_t now;
struct tm tm;
char calview[32];
+ int span = 3888000;
/* In case no date was specified, go with today */
now = time(NULL);
else if (!strcasecmp(calview, "week")) {
c->view = calview_week;
}
+ else if (!strcasecmp(calview, "summary")) { /* shouldn't ever happen, but just in case */
+ c->view = calview_day;
+ }
else {
if (WC->wc_view == VIEW_CALBRIEF) {
c->view = calview_brief;
tm.tm_mday = c->day;
now = mktime(&tm);
- int span = 3888000;
if (c->view == calview_month) span = 3888000;
if (c->view == calview_brief) span = 3888000;
if (c->view == calview_week) span = 604800;
if (c->view == calview_day) span = 86400;
+ if (c->view == calview_summary) span = 86400;
c->lower_bound = now - span;
c->upper_bound = now + span;
/*
* Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
*/
-time_t get_task_due_date(icalcomponent *vtodo) {
+time_t get_task_due_date(icalcomponent *vtodo, int *is_date) {
icalproperty *p;
if (vtodo == NULL) {
return get_task_due_date(
icalcomponent_get_first_component(
vtodo, ICAL_VTODO_COMPONENT
- )
+ ), is_date
);
}
p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
if (p != NULL) {
- return(icaltime_as_timet(icalproperty_get_due(p)));
+ struct icaltimetype t = icalproperty_get_due(p);
+
+ if (is_date)
+ *is_date = t.is_date;
+ return(icaltime_as_timet(t));
}
else {
return(0L);
time_t t1;
time_t t2;
- t1 = get_task_due_date(Task1->cal);
- t2 = get_task_due_date(Task2->cal);
+ t1 = get_task_due_date(Task1->cal, NULL);
+ t2 = get_task_due_date(Task2->cal, NULL);
if (t1 < t2) return(-1);
if (t1 > t2) return(1);
return(0);
*/
int task_completed_cmp(const void *vtask1, const void *vtask2) {
disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
-// disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
+/* disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
- // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
+ /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
if (t1 == ICAL_STATUS_COMPLETED)
return 1;
time_t due;
char buf[SIZ];
icalproperty *p;
- struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ wcsession *WCC = WC;
wprintf("<div class=\"fix_scrollbar_bug\">"
"<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
task_completed_cmp);
}
- Pos = GetNewHashPos();
+ Pos = GetNewHashPos(WCC->disp_cal_items, 0);
while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
+ icalproperty_status todoStatus;
+ int is_date;
+
Cal = (disp_cal*)vCal;
wprintf("<tr><td>");
- icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
+ todoStatus = icalcomponent_get_status(Cal->cal);
wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
if (todoStatus == ICAL_STATUS_COMPLETED) {
wprintf("checked=\"checked\" ");
wprintf("disabled=\"disabled\">\n</td><td>");
p = icalcomponent_get_first_property(Cal->cal,
ICAL_SUMMARY_PROPERTY);
- wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
- Cal->cal_msgnum );
- urlescputs(WC->wc_roomname);
+ wprintf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
+ urlescputs(ChrPtr(WC->wc_roomname));
wprintf("\">");
/* wprintf("<img align=middle "
"src=\"static/taskmanag_16x.gif\" border=0> "); */
wprintf("</a>\n");
wprintf("</td>\n");
- due = get_task_due_date(Cal->cal);
+ due = get_task_due_date(Cal->cal, &is_date);
wprintf("<td><span");
if (due > 0) {
- webcit_fmt_date(buf, due, 0);
+ webcit_fmt_date(buf, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
wprintf(">%s",buf);
}
else {