00001
00002
00003
00009 #include "webcit.h"
00010 #include "webserver.h"
00011
00013 char *hourname[] = {
00014 "12am", "1am", "2am", "3am", "4am", "5am", "6am",
00015 "7am", "8am", "9am", "10am", "11am", "12pm",
00016 "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
00017 "7pm", "8pm", "9pm", "10pm", "11pm"
00018 };
00019
00020 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
00021
00043 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
00044 int i;
00045 time_t now;
00046 struct tm tm_now;
00047 int this_year;
00048 time_t tt;
00049 struct tm tm;
00050 const int span = 10;
00051 int all_day_event = 0;
00052 time_t monthselect_time;
00053 struct tm monthselect_tm;
00054 char monthselect_str[32];
00055 char calhourformat[16];
00056
00057 get_preference("calhourformat", calhourformat, sizeof calhourformat);
00058
00059 now = time(NULL);
00060 localtime_r(&now, &tm_now);
00061 this_year = tm_now.tm_year + 1900;
00062
00063 if (t == NULL) return;
00064 if (t->is_date) all_day_event = 1;
00065 tt = icaltime_as_timet(*t);
00066 if (all_day_event) {
00067 gmtime_r(&tt, &tm);
00068 }
00069 else {
00070 localtime_r(&tt, &tm);
00071 }
00072
00073 wprintf(_("Month: "));
00074 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
00075 for (i=0; i<=11; ++i) {
00076 monthselect_time = 1137997451 + (i * 2592000);
00077 localtime_r(&monthselect_time, &monthselect_tm);
00078 wc_strftime(monthselect_str, sizeof monthselect_str, "%B", &monthselect_tm);
00079 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
00080 ((tm.tm_mon == i) ? "SELECTED" : ""),
00081 i+1,
00082 monthselect_str
00083 );
00084 }
00085 wprintf("</SELECT>\n");
00086
00087 wprintf(_("Day: "));
00088 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
00089 for (i=1; i<=31; ++i) {
00090 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
00091 ((tm.tm_mday == i) ? "SELECTED" : ""),
00092 i, i
00093 );
00094 }
00095 wprintf("</SELECT>\n");
00096
00097 wprintf(_("Year: "));
00098 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
00099 if ((this_year - t->year) > span) {
00100 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
00101 t->year, t->year);
00102 }
00103 for (i=(this_year-span); i<=(this_year+span); ++i) {
00104 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
00105 ((t->year == i) ? "SELECTED" : ""),
00106 i, i
00107 );
00108 }
00109 if ((t->year - this_year) > span) {
00110 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
00111 t->year, t->year);
00112 }
00113 wprintf("</SELECT>\n");
00114
00115 wprintf(_("Hour: "));
00116 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
00117 for (i=0; i<=23; ++i) {
00118
00119 if (!strcasecmp(calhourformat, "24")) {
00120 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
00121 ((tm.tm_hour == i) ? "SELECTED" : ""),
00122 i, i
00123 );
00124 }
00125 else {
00126 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
00127 ((tm.tm_hour == i) ? "SELECTED" : ""),
00128 i, hourname[i]
00129 );
00130 }
00131
00132 }
00133 wprintf("</SELECT>\n");
00134
00135 wprintf(_("Minute: "));
00136 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
00137 for (i=0; i<=59; ++i) {
00138 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
00139 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
00140 ((tm.tm_min == i) ? "SELECTED" : ""),
00141 i, i
00142 );
00143 }
00144 }
00145 wprintf("</SELECT>\n");
00146 }
00147
00154 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
00155 char vname[32];
00156 struct icaltimetype t2;
00157 char timestr[32];
00158 int month, mday, year, hour, minute;
00159
00160 sprintf(vname, "%s_month", prefix); month = atoi(bstr(vname));
00161 sprintf(vname, "%s_day", prefix); mday = atoi(bstr(vname));
00162 sprintf(vname, "%s_year", prefix); year = atoi(bstr(vname));
00163 sprintf(vname, "%s_hour", prefix); hour = atoi(bstr(vname));
00164 sprintf(vname, "%s_minute", prefix); minute = atoi(bstr(vname));
00165
00166 sprintf(timestr, "%04d%02d%02dT%02d%02d00", year, month, mday, hour, minute);
00167 t2 = icaltime_from_string(timestr);
00168 memcpy(t, &t2, sizeof(struct icaltimetype));
00169 }
00170
00171
00179 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
00180 char vname[32];
00181
00182 memset(t, 0, sizeof(struct icaltimetype));
00183
00184 sprintf(vname, "%s_month", prefix); t->month = atoi(bstr(vname));
00185 sprintf(vname, "%s_day", prefix); t->day = atoi(bstr(vname));
00186 sprintf(vname, "%s_year", prefix); t->year = atoi(bstr(vname));
00187 t->is_utc = 1;
00188 t->is_date = 1;
00189 }
00190
00191
00198 void partstat_as_string(char *buf, icalproperty *attendee) {
00199 icalparameter *partstat_param;
00200 icalparameter_partstat partstat;
00201
00202 strcpy(buf, _("(status unknown)"));
00203
00204 partstat_param = icalproperty_get_first_parameter(
00205 attendee,
00206 ICAL_PARTSTAT_PARAMETER
00207 );
00208 if (partstat_param == NULL) {
00209 return;
00210 }
00211
00212 partstat = icalparameter_get_partstat(partstat_param);
00213 switch(partstat) {
00214 case ICAL_PARTSTAT_X:
00215 strcpy(buf, "(x)");
00216 break;
00217 case ICAL_PARTSTAT_NEEDSACTION:
00218 strcpy(buf, _("(needs action)"));
00219 break;
00220 case ICAL_PARTSTAT_ACCEPTED:
00221 strcpy(buf, _("(accepted)"));
00222 break;
00223 case ICAL_PARTSTAT_DECLINED:
00224 strcpy(buf, _("(declined)"));
00225 break;
00226 case ICAL_PARTSTAT_TENTATIVE:
00227 strcpy(buf, _("(tenative)"));
00228 break;
00229 case ICAL_PARTSTAT_DELEGATED:
00230 strcpy(buf, _("(delegated)"));
00231 break;
00232 case ICAL_PARTSTAT_COMPLETED:
00233 strcpy(buf, _("(completed)"));
00234 break;
00235 case ICAL_PARTSTAT_INPROCESS:
00236 strcpy(buf, _("(in process)"));
00237 break;
00238 case ICAL_PARTSTAT_NONE:
00239 strcpy(buf, _("(none)"));
00240 break;
00241 }
00242 }
00243
00244
00251 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
00252 icalcomponent *encaps;
00253
00254
00255
00256 if (subcomp == NULL) {
00257 lprintf(3, "ERROR: called with NULL argument!\n");
00258 return NULL;
00259 }
00260
00265 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
00266 return subcomp;
00267 }
00268
00270 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
00271 if (encaps == NULL) {
00272 lprintf(3, "%s:%d: Error - could not allocate component!\n",
00273 __FILE__, __LINE__);
00274 return NULL;
00275 }
00276
00278 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
00279
00281 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
00282
00284
00285 icalcomponent_add_component(encaps, subcomp);
00286
00290 ical_dezonify(encaps);
00291
00293 return(encaps);
00294 }
00295
00296
00297
00298
00299 #endif
00300