Mailing list header changes (fuck you Google)
[citadel.git] / webcit / summary.c
1 /*
2  * Displays the "Summary Page"
3  *
4  * Copyright (c) 1996-2012 by the citadel.org team
5  *
6  * This program is open source software.  You can redistribute it and/or
7  * modify it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include "webcit.h"
16 #include "calendar.h"
17
18 extern int calendar_summary_view(void);
19
20 /*
21  * Display today's date in a friendly format
22  */
23 void output_date(void) {
24         struct tm tm;
25         time_t now;
26         char buf[128];
27
28         time(&now);
29         localtime_r(&now, &tm);
30
31         wc_strftime(buf, 32, "%A, %x", &tm);
32         wc_printf("%s", buf);
33 }
34
35 void tmplput_output_date(StrBuf *Target, WCTemplputParams *TP)
36 {
37         struct tm tm;
38         time_t now;
39         char buf[128];
40         size_t n;
41
42         time(&now);
43         localtime_r(&now, &tm);
44
45         n = wc_strftime(buf, 32, "%A, %x", &tm);
46         StrBufAppendBufPlain(Target, buf, n, 0);
47 }
48
49
50 /*
51  * New messages section
52  */
53 void new_messages_section(void) {
54         char buf[SIZ];
55         char room[SIZ];
56         int i;
57         int number_of_rooms_to_check;
58         char *rooms_to_check = "Mail|Lobby";
59
60
61         number_of_rooms_to_check = num_tokens(rooms_to_check, '|');
62         if (number_of_rooms_to_check == 0) return;
63
64         wc_printf("<table border=\"0\" width=\"100%%\">\n");
65         for (i=0; i<number_of_rooms_to_check; ++i) {
66                 extract_token(room, rooms_to_check, i, '|', sizeof room);
67
68                 serv_printf("GOTO %s", room);
69                 serv_getln(buf, sizeof buf);
70                 if (buf[0] == '2') {
71                         extract_token(room, &buf[4], 0, '|', sizeof room);
72                         wc_printf("<tr><td><a href=\"dotgoto?room=");
73                         urlescputs(room);
74                         wc_printf("\">");
75                         escputs(room);
76                         wc_printf("</a></td><td>%d/%d</td></tr>\n",
77                                 extract_int(&buf[4], 1),
78                                 extract_int(&buf[4], 2)
79                         );
80                 }
81         }
82         wc_printf("</table>\n");
83
84 }
85
86
87 /*
88  * Task list section
89  */
90 void tasks_section(void) {
91         int num_msgs = 0;
92         HashPos *at;
93         const char *HashKey;
94         long HKLen;
95         void *vMsg;
96         message_summary *Msg;
97         wcsession *WCC = WC;
98         StrBuf *Buf;
99         SharedMessageStatus Stat;
100
101         memset(&Stat, 0, sizeof(SharedMessageStatus));
102         Stat.maxload = 10000;
103         Stat.lowest_found = (-1);
104         Stat.highest_found = (-1);
105
106         Buf = NewStrBufPlain(HKEY("_TASKS_"));
107         gotoroom(Buf);
108         FreeStrBuf(&Buf);
109
110         if (WCC->CurRoom.view != VIEW_TASKS) {
111                 num_msgs = 0;
112         }
113         else {
114                 num_msgs = load_msg_ptrs("MSGS ALL", NULL, NULL, &Stat, NULL, NULL, NULL, NULL, 0);
115         }
116
117         if (num_msgs > 0) {
118                 at = GetNewHashPos(WCC->summ, 0);
119                 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
120                         Msg = (message_summary*) vMsg;          
121                         tasks_LoadMsgFromServer(NULL, NULL, Msg, 0, 0);
122                 }
123                 DeleteHashPos(&at);
124         }
125
126         if (calendar_summary_view() < 1) {
127                 wc_printf("<i>");
128                 wc_printf(_("(None)"));
129                 wc_printf("</i><br>\n");
130         }
131 }
132
133
134 /*
135  * Calendar section
136  */
137 void calendar_section(void) {
138         char cmd[SIZ];
139         char filter[SIZ];
140         int num_msgs = 0;
141         HashPos *at;
142         const char *HashKey;
143         long HKLen;
144         void *vMsg;
145         message_summary *Msg;
146         wcsession *WCC = WC;
147         StrBuf *Buf;
148         void *v = NULL;
149         SharedMessageStatus Stat;
150
151         memset(&Stat, 0, sizeof(SharedMessageStatus));
152         Stat.maxload = 10000;
153         Stat.lowest_found = (-1);
154         Stat.highest_found = (-1);
155         
156         Buf = NewStrBufPlain(HKEY("_CALENDAR_"));
157         gotoroom(Buf);
158         FreeStrBuf(&Buf);
159         if ( (WC->CurRoom.view != VIEW_CALENDAR) && (WC->CurRoom.view != VIEW_CALBRIEF) ) {
160                 num_msgs = 0;
161         }
162         else {
163                 num_msgs = load_msg_ptrs("MSGS ALL", NULL, NULL, &Stat, NULL, NULL, NULL, NULL, 0);
164         }
165         calendar_GetParamsGetServerCall(&Stat, 
166                                         &v,
167                                         readnew, 
168                                         cmd, 
169                                         sizeof(cmd),
170                                         filter,
171                                         sizeof(filter));
172
173
174         if (num_msgs > 0) {
175                 at = GetNewHashPos(WCC->summ, 0);
176                 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
177                         Msg = (message_summary*) vMsg;          
178                         calendar_LoadMsgFromServer(NULL, &v, Msg, 0, 0);
179                 }
180                 DeleteHashPos(&at);
181         }
182         if (calendar_summary_view() < 1) {
183                 wc_printf("<i>");
184                 wc_printf(_("(Nothing)"));
185                 wc_printf("</i><br>\n");
186         }
187         __calendar_Cleanup(&v);
188 }
189
190 void tmplput_new_messages_section(StrBuf *Target, WCTemplputParams *TP) {
191         new_messages_section();
192 }
193 void tmplput_tasks_section(StrBuf *Target, WCTemplputParams *TP) {
194         tasks_section();
195 }
196 void tmplput_calendar_section(StrBuf *Target, WCTemplputParams *TP) {
197         calendar_section();
198 }
199
200
201 /*
202  * summary page
203  */
204 void display_summary_page(void)
205 {
206         output_headers(1, 1, 1, 0, 0, 0); 
207         do_template("summary_page");
208         wDumpContent(1);
209 }
210
211
212 void 
213 InitModule_SUMMARY
214 (void)
215 {
216         RegisterNamespace("TIME:NOW", 0, 0, tmplput_output_date, NULL, CTX_NONE);
217         WebcitAddUrlHandler(HKEY("summary"), "", 0, display_summary_page, ANONYMOUS);
218         WebcitAddUrlHandler(HKEY("new_messages_html"), "", 0, new_messages_section, AJAX);
219         WebcitAddUrlHandler(HKEY("tasks_inner_html"), "", 0, tasks_section, AJAX);
220         WebcitAddUrlHandler(HKEY("calendar_inner_html"), "", 0, calendar_section, AJAX);
221 }
222