Back to index

webcit  8.12-dfsg
summary.c
Go to the documentation of this file.
00001 /*
00002  * Displays the "Summary Page"
00003  *
00004  * Copyright (c) 1996-2012 by the citadel.org team
00005  *
00006  * This program is open source software.  You can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 #include "calendar.h"
00017 
00018 extern int calendar_summary_view(void);
00019 
00020 /*
00021  * Display today's date in a friendly format
00022  */
00023 void output_date(void) {
00024        struct tm tm;
00025        time_t now;
00026        char buf[128];
00027 
00028        time(&now);
00029        localtime_r(&now, &tm);
00030 
00031        wc_strftime(buf, 32, "%A, %x", &tm);
00032        wc_printf("%s", buf);
00033 }
00034 
00035 void tmplput_output_date(StrBuf *Target, WCTemplputParams *TP)
00036 {
00037        struct tm tm;
00038        time_t now;
00039        char buf[128];
00040        size_t n;
00041 
00042        time(&now);
00043        localtime_r(&now, &tm);
00044 
00045        n = wc_strftime(buf, 32, "%A, %x", &tm);
00046        StrBufAppendBufPlain(Target, buf, n, 0);
00047 }
00048 
00049 
00050 /*
00051  * New messages section
00052  */
00053 void new_messages_section(void) {
00054        char buf[SIZ];
00055        char room[SIZ];
00056        int i;
00057        int number_of_rooms_to_check;
00058        char *rooms_to_check = "Mail|Lobby";
00059 
00060 
00061        number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
00062        if (number_of_rooms_to_check == 0) return;
00063 
00064        wc_printf("<table border=\"0\" width=\"100%%\">\n");
00065        for (i=0; i<number_of_rooms_to_check; ++i) {
00066               extract_token(room, rooms_to_check, i, '|', sizeof room);
00067 
00068               serv_printf("GOTO %s", room);
00069               serv_getln(buf, sizeof buf);
00070               if (buf[0] == '2') {
00071                      extract_token(room, &buf[4], 0, '|', sizeof room);
00072                      wc_printf("<tr><td><a href=\"dotgoto?room=");
00073                      urlescputs(room);
00074                      wc_printf("\">");
00075                      escputs(room);
00076                      wc_printf("</a></td><td>%d/%d</td></tr>\n",
00077                             extract_int(&buf[4], 1),
00078                             extract_int(&buf[4], 2)
00079                      );
00080               }
00081        }
00082        wc_printf("</table>\n");
00083 
00084 }
00085 
00086 
00087 /*
00088  * Task list section
00089  */
00090 void tasks_section(void) {
00091        int num_msgs = 0;
00092        HashPos *at;
00093        const char *HashKey;
00094        long HKLen;
00095        void *vMsg;
00096        message_summary *Msg;
00097        wcsession *WCC = WC;
00098        StrBuf *Buf;
00099        SharedMessageStatus Stat;
00100 
00101        memset(&Stat, 0, sizeof(SharedMessageStatus));
00102        Stat.maxload = 10000;
00103        Stat.lowest_found = (-1);
00104        Stat.highest_found = (-1);
00105 
00106        Buf = NewStrBufPlain(HKEY("_TASKS_"));
00107        gotoroom(Buf);
00108        FreeStrBuf(&Buf);
00109 
00110        if (WCC->CurRoom.view != VIEW_TASKS) {
00111               num_msgs = 0;
00112        }
00113        else {
00114               num_msgs = load_msg_ptrs("MSGS ALL", NULL, &Stat, NULL);
00115        }
00116 
00117        if (num_msgs > 0) {
00118               at = GetNewHashPos(WCC->summ, 0);
00119               while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
00120                      Msg = (message_summary*) vMsg;            
00121                      tasks_LoadMsgFromServer(NULL, NULL, Msg, 0, 0);
00122               }
00123               DeleteHashPos(&at);
00124        }
00125 
00126        if (calendar_summary_view() < 1) {
00127               wc_printf("<i>");
00128               wc_printf(_("(None)"));
00129               wc_printf("</i><br>\n");
00130        }
00131 }
00132 
00133 
00134 /*
00135  * Calendar section
00136  */
00137 void calendar_section(void) {
00138        char cmd[SIZ];
00139        char filter[SIZ];
00140        int num_msgs = 0;
00141        HashPos *at;
00142        const char *HashKey;
00143        long HKLen;
00144        void *vMsg;
00145        message_summary *Msg;
00146        wcsession *WCC = WC;
00147        StrBuf *Buf;
00148        void *v = NULL;
00149        SharedMessageStatus Stat;
00150 
00151        memset(&Stat, 0, sizeof(SharedMessageStatus));
00152        Stat.maxload = 10000;
00153        Stat.lowest_found = (-1);
00154        Stat.highest_found = (-1);
00155        
00156        Buf = NewStrBufPlain(HKEY("_CALENDAR_"));
00157        gotoroom(Buf);
00158        FreeStrBuf(&Buf);
00159        if ( (WC->CurRoom.view != VIEW_CALENDAR) && (WC->CurRoom.view != VIEW_CALBRIEF) ) {
00160               num_msgs = 0;
00161        }
00162        else {
00163               num_msgs = load_msg_ptrs("MSGS ALL", NULL, &Stat, NULL);
00164        }
00165        calendar_GetParamsGetServerCall(&Stat, 
00166                                    &v,
00167                                    readnew, 
00168                                    cmd, 
00169                                    sizeof(cmd),
00170                                    filter,
00171                                    sizeof(filter));
00172 
00173 
00174        if (num_msgs > 0) {
00175               at = GetNewHashPos(WCC->summ, 0);
00176               while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
00177                      Msg = (message_summary*) vMsg;            
00178                      calendar_LoadMsgFromServer(NULL, &v, Msg, 0, 0);
00179               }
00180               DeleteHashPos(&at);
00181        }
00182        if (calendar_summary_view() < 1) {
00183               wc_printf("<i>");
00184               wc_printf(_("(Nothing)"));
00185               wc_printf("</i><br>\n");
00186        }
00187        __calendar_Cleanup(&v);
00188 }
00189 
00190 void tmplput_new_messages_section(StrBuf *Target, WCTemplputParams *TP) {
00191        new_messages_section();
00192 }
00193 void tmplput_tasks_section(StrBuf *Target, WCTemplputParams *TP) {
00194        tasks_section();
00195 }
00196 void tmplput_calendar_section(StrBuf *Target, WCTemplputParams *TP) {
00197        calendar_section();
00198 }
00199 
00200 
00201 /*
00202  * summary page
00203  */
00204 void display_summary_page(void)
00205 {
00206        output_headers(1, 1, 1, 0, 0, 0); 
00207        do_template("summary_page");
00208        wDumpContent(1);
00209 }
00210 
00211 
00212 void 
00213 InitModule_SUMMARY
00214 (void)
00215 {
00216        RegisterNamespace("TIME:NOW", 0, 0, tmplput_output_date, NULL, CTX_NONE);
00217        WebcitAddUrlHandler(HKEY("summary"), "", 0, display_summary_page, ANONYMOUS);
00218        WebcitAddUrlHandler(HKEY("new_messages_html"), "", 0, new_messages_section, AJAX);
00219        WebcitAddUrlHandler(HKEY("tasks_inner_html"), "", 0, tasks_section, AJAX);
00220        WebcitAddUrlHandler(HKEY("calendar_inner_html"), "", 0, calendar_section, AJAX);
00221 }
00222