Began making changes to do better handling of character sets.
[citadel.git] / webcit / notes.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup StickyNotes Functions which handle "sticky notes"
6  * \ingroup WebcitDisplayItems
7  */
8 /*@{*/
9 #include "webcit.h"
10 #include "groupdav.h"
11 #include "webserver.h"
12
13 /**
14  * \brief display sticky notes
15  * \param msgnum the citadel mesage number
16  */
17 void display_note(long msgnum)
18 {
19         char buf[SIZ];
20         char notetext[SIZ];
21         char display_notetext[SIZ];
22         char eid[128];
23         int in_text = 0;
24         int i;
25
26         wprintf("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\">\n");
27
28         serv_printf("MSG0 %ld", msgnum);
29         serv_getln(buf, sizeof buf);
30         if (buf[0] != '1') {
31                 wprintf("%s<br />\n", &buf[4]);
32                 return;
33         }
34
35         strcpy(notetext, "");
36         strcpy(eid, "");
37         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
38
39                 /** Fill the buffer */
40                 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
41                         strcat(notetext, buf);
42                 }
43
44                 if ( (!in_text) && (!strncasecmp(buf, "exti=", 5)) ) {
45                         safestrncpy(eid, &buf[5], sizeof eid);
46                 }
47
48                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
49                         in_text = 1;
50                 }
51         }
52
53         /** Now sanitize the buffer */
54         for (i=0; i<strlen(notetext); ++i) {
55                 if (isspace(notetext[i])) notetext[i] = ' ';
56         }
57
58         /** Make it HTML-happy and print it. */
59         stresc(display_notetext, notetext, 0, 0);
60         if (strlen(eid) > 0) {
61                 wprintf("<span id=\"note%s\">%s</span><br />\n", eid, display_notetext);
62         }
63         else {
64                 wprintf("<span id=\"note%ld\">%s</span><br />\n", msgnum, display_notetext);
65         }
66
67         /** Offer in-place editing. */
68         if (strlen(eid) > 0) {
69                 wprintf("<script type=\"text/javascript\">"
70                         " new Ajax.InPlaceEditor('note%s', 'updatenote?eid=%s', {rows:5,cols:72}); "
71                         "</script>\n",
72                         eid,
73                         eid
74                 );
75         }
76 }
77
78
79 /**
80  * \brief  This gets called by the Ajax.InPlaceEditor when we save a note.
81  */
82 void updatenote(void)
83 {
84         char buf[SIZ];
85         char notetext[SIZ];
86         char display_notetext[SIZ];
87         long msgnum;
88         int in_text = 0;
89         int i;
90
91         serv_printf("ENT0 1||0|0||||||%s", bstr("eid"));
92         serv_getln(buf, sizeof buf);
93         if (buf[0] == '4') {
94                 text_to_server(bstr("value"));
95                 serv_puts("000");
96         }
97
98         begin_ajax_response();
99         msgnum = locate_message_by_uid(bstr("eid"));
100         if (msgnum >= 0L) {
101                 serv_printf("MSG0 %ld", msgnum);
102                 serv_getln(buf, sizeof buf);
103                 if (buf[0] == '1') {
104                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
105                 
106                                 /** Fill the buffer */
107                                 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
108                                         strcat(notetext, buf);
109                                 }
110                 
111                                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
112                                         in_text = 1;
113                                 }
114                         }
115                         /** Now sanitize the buffer */
116                         for (i=0; i<strlen(notetext); ++i) {
117                                 if (isspace(notetext[i])) notetext[i] = ' ';
118                         }
119                 
120                         /** Make it HTML-happy and print it. */
121                         stresc(display_notetext, notetext, 0, 0);
122                         wprintf("%s\n", display_notetext);
123                 }
124         }
125         else {
126                 wprintf("%s", _("An error has occurred."));
127         }
128
129         end_ajax_response();
130 }
131
132
133
134 /*@}*/