ffd6f33af9ce8a9e67d9f9723764cd9122652302
[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         serv_printf("MSG0 %ld", msgnum);
28         serv_getln(buf, sizeof buf);
29         if (buf[0] != '1') {
30                 wprintf("%s<br />\n", &buf[4]);
31                 return;
32         }
33
34         strcpy(notetext, "");
35         strcpy(eid, "");
36         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
37
38                 /** Fill the buffer */
39                 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
40                         strcat(notetext, buf);
41                 }
42
43                 if ( (!in_text) && (!strncasecmp(buf, "exti=", 5)) ) {
44                         safestrncpy(eid, &buf[5], sizeof eid);
45                 }
46
47                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
48                         in_text = 1;
49                 }
50         }
51
52         /** Now sanitize the buffer */
53         len = strlen(notetext);
54         for (i=0; i<len; ++i) {
55                 if (isspace(notetext[i])) notetext[i] = ' ';
56         }
57
58         /** Make it HTML-happy and print it. */
59         stresc(display_notetext, SIZ, notetext, 0, 0);
60 /* Lets try it as a draggable */
61         if (!IsEmptyStr(eid)) {
62                 wprintf ("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\" id=\"note_%s\" alt=\"Note\" ", eid); 
63                 wprintf ("class=\"notes\">\n");
64                 wprintf ("<script type=\"text/javascript\">\n");
65 //              wprintf ("//<![CDATA[\n");
66                 wprintf ("new Draggable (\"note_%s\", {revert:true})\n", eid);
67 //              wprintf ("//]]>\n");
68                 wprintf ("</script>\n");
69         }
70         else {
71                 wprintf ("<IMG ALIGN=MIDDLE src=\"static/storenotes_48x.gif\" id=\"note_%s\" ", msgnum); 
72                 wprintf ("class=\"notes\">\n");
73                 wprintf ("<script type=\"text/javascript\">\n");
74 //              wprintf ("//<![CDATA[\n");
75                 wprintf ("new Draggable (\"note_%s\", {revert:true})\n", msgnum);
76 //              wprintf ("//]]>\n");
77                 wprintf ("</script>\n");
78         }
79         
80         if (!IsEmptyStr(eid)) {
81                 wprintf("<span id=\"note%s\">%s</span><br />\n", eid, display_notetext);
82         }
83         else {
84                 wprintf("<span id=\"note%ld\">%s</span><br />\n", msgnum, display_notetext);
85         }
86
87         /** Offer in-place editing. */
88         if (!IsEmptyStr(eid)) {
89                 wprintf("<script type=\"text/javascript\">"
90                         "new Ajax.InPlaceEditor('note%s', 'updatenote?nonce=%ld?eid=%s', {rows:5,cols:72});"
91                         "</script>\n",
92                         eid,
93                         WC->nonce,
94                         eid
95                 );
96         }
97 }
98
99
100 /**
101  * \brief  This gets called by the Ajax.InPlaceEditor when we save a note.
102  */
103 void updatenote(void)
104 {
105         char buf[SIZ];
106         char notetext[SIZ];
107         char display_notetext[SIZ];
108         long msgnum;
109         int in_text = 0;
110         int i, len;
111
112         serv_printf("ENT0 1||0|0||||||%s", bstr("eid"));
113         serv_getln(buf, sizeof buf);
114         if (buf[0] == '4') {
115                 text_to_server(bstr("value"));
116                 serv_puts("000");
117         }
118
119         begin_ajax_response();
120         msgnum = locate_message_by_uid(bstr("eid"));
121         if (msgnum >= 0L) {
122                 serv_printf("MSG0 %ld", msgnum);
123                 serv_getln(buf, sizeof buf);
124                 if (buf[0] == '1') {
125                         strcpy(notetext, "");
126                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
127                 
128                                 /** Fill the buffer */
129                                 if ( (in_text) && (strlen(notetext) < SIZ-256) ) {
130                                         strcat(notetext, buf);
131                                 }
132                 
133                                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
134                                         in_text = 1;
135                                 }
136                         }
137                         /** Now sanitize the buffer */
138                         len = strlen(notetext);
139                         for (i=0; i<len; ++i) {
140                                 if (isspace(notetext[i])) notetext[i] = ' ';
141                         }
142                 
143                         /** Make it HTML-happy and print it. */
144                         stresc(display_notetext, SIZ, notetext, 0, 0);
145                         wprintf("%s\n", display_notetext);
146                 }
147         }
148         else {
149                 wprintf("%s", _("An error has occurred."));
150         }
151
152         end_ajax_response();
153 }
154
155
156
157 /*@}*/