Added a delete button to the Notes in place editor.
[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, len;
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         len = strlen(notetext);
55         for (i=0; i<len; ++i) {
56                 if (isspace(notetext[i])) notetext[i] = ' ';
57         }
58
59         /** Make it HTML-happy and print it. */
60         stresc(display_notetext, SIZ, notetext, 0, 0);
61         if (!IsEmptyStr(eid)) {
62                 wprintf("<span id=\"note%s\">%s</span><br />\n", eid, display_notetext);
63         }
64         else {
65                 wprintf("<span id=\"note%ld\">%s</span><br />\n", msgnum, display_notetext);
66         }
67
68         /** Offer in-place editing. */
69         if (!IsEmptyStr(eid)) {
70                 wprintf("<script type=\"text/javascript\">"
71                         "new Ajax.InPlaceEditor('note%s', 'updatenote?nonce=%ld?eid=%s', {rows:5,cols:72});"
72                         "</script>\n",
73                         eid,
74                         WC->nonce,
75                         eid
76                 );
77         }
78 }
79
80
81 /**
82  * \brief  This gets called by the Ajax.InPlaceEditor when we save a note.
83  */
84 void updatenote(void)
85 {
86         char buf[SIZ];
87         char notetext[SIZ];
88         char display_notetext[SIZ];
89         long msgnum;
90         int in_text = 0;
91         int i, len;
92
93         serv_printf("ENT0 1||0|0||||||%s", bstr("eid"));
94         serv_getln(buf, sizeof buf);
95         if (buf[0] == '4') {
96                 text_to_server(bstr("value"));
97                 serv_puts("000");
98         }
99
100         begin_ajax_response();
101         msgnum = locate_message_by_uid(bstr("eid"));
102         if (msgnum >= 0L) {
103                 serv_printf("MSG0 %ld", msgnum);
104                 serv_getln(buf, sizeof buf);
105                 if (buf[0] == '1') {
106                         strcpy(notetext, "");
107                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
108                 
109                                 /** Fill the buffer */
110                                 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
111                                         strcat(notetext, buf);
112                                 }
113                 
114                                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
115                                         in_text = 1;
116                                 }
117                         }
118                         /** Now sanitize the buffer */
119                         len = strlen(notetext);
120                         for (i=0; i<len; ++i) {
121                                 if (isspace(notetext[i])) notetext[i] = ' ';
122                         }
123                 
124                         /** Make it HTML-happy and print it. */
125                         stresc(display_notetext, SIZ, notetext, 0, 0);
126                         wprintf("%s\n", display_notetext);
127                 }
128         }
129         else {
130                 wprintf("%s", _("An error has occurred."));
131         }
132
133         end_ajax_response();
134 }
135
136
137
138 /*@}*/