#include #include #define MAX_ENTRIES 10000 typedef struct { /* a simple key=val pair in the text */ char *name; char *val; } entry; char *makeword(char *line, char stop); char *fmakeword(FILE *f, char stop, int *len); char x2c(char *what); void unescape_url(char *url); void plustospace(char *str); main(int argc, char *argv[]) { entry entries[MAX_ENTRIES]; register int x,m=0; int cl, idx1=0, idx2=0, idx3=0, idx4=0, usba=0, sum=0, missing_cat=0; char name[128], tmpname[32], cmd[128], cat[128]; FILE *tmpfile; printf("Content-type: text/html%c%c",10,10); if(strcmp(getenv("REQUEST_METHOD"),"POST")) { printf("This script should be referenced with a METHOD of POST.\n"); printf("If you don't understand this, see this "); printf("forms overview.%c",10); exit(1); } if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { printf("This script can only be used to decode form results. \n"); exit(1); } cl = atoi(getenv("CONTENT_LENGTH")); for(x=0;cl && (!feof(stdin));x++) { /* get text and make key=val */ m=x; entries[x].val = fmakeword(stdin,'&',&cl); plustospace(entries[x].val); unescape_url(entries[x].val); entries[x].name = makeword(entries[x].val,'='); } sprintf(tmpname,"/tmp/dcopenXXXXXX"); mktemp(tmpname); tmpfile = fopen(tmpname,"w"); printf("

Registration Done!

%c",10); for(x=0; x <= m; x++) { if (tmpfile) fprintf(tmpfile,"%s=%s\n",entries[x].name,entries[x].val); if (strcmp(entries[x].name,"fname")==0) { if (strlen(entries[x].val)==0) my_error("No first name supplied"); strcpy(name,entries[x].val); strcat(name," "); continue; } if (strcmp(entries[x].name,"lname")==0) { if (strlen(entries[x].val)==0) my_error("No last name supplied"); strcat(name,entries[x].val); continue; } if(strcmp(entries[x].name,"email")==0) { if (strlen(entries[x].val)==0) my_error("No email supplied"); continue; } if (strcmp(entries[x].name,"event1")==0 && strcmp(entries[x].val,"none")) idx1=x+1; if (strcmp(entries[x].name,"event2")==0 && strcmp(entries[x].val,"none")) idx2=x+1; if (strcmp(entries[x].name,"event3")==0 && strcmp(entries[x].val,"none")) idx3=x+1; if (strcmp(entries[x].name,"event4")==0 && strcmp(entries[x].val,"none")) idx4=x+1; if (strcmp(entries[x].name,"usba")==0 && strlen(entries[x].val) > 0) usba=1; } /* for (x<=m) */ if (idx1+idx2+idx3+idx4 == 0) my_error("You didn't register for any events"); printf("%s, you have registered for the following events:

%c",name,10); printf("

    "); sum = 5; if (idx1) { sum += 10; if (strcmp(entries[idx1+1].name,"cat1")==0) strcat(cat,entries[idx1+1].val); else { missing_cat++; strcpy(cat,"???"); } printf("
  1. $%d %s-%s (w/ %s)%c",sum,entries[idx1-1].val, cat, entries[idx1].val,10); } if (idx2) { sum += 10; if (strcmp(entries[idx2+1].name,"cat2")==0) strcpy(cat,entries[idx2+1].val); else { missing_cat++; strcat(cat,"???"); } printf("
  2. $%d %s-%s (w/ %s)%c",sum,entries[idx2-1].val, cat, entries[idx2].val,10); } if (idx3) { sum += 10; if (strcmp(entries[idx3+1].name,"cat3")==0) strcpy(cat,entries[idx3+1].val); else { missing_cat++; strcat(cat,"???"); } printf("
  3. $%d %s-%s (w/ %s)%c",sum,entries[idx3-1].val, cat, entries[idx3].val,10); } if (idx4) { sum += 10; if (strcmp(entries[idx4+1].name,"cat4")==0) strcat(cat,entries[idx4+1].val); else { missing_cat++; strcpy(cat,"???"); } printf("
  4. $%d %s-%s (w/ %s)%c",sum,entries[idx4-1].val, cat, entries[idx4].val,10); } if (usba==0) { sum += 15; printf("
  5. $%d (extra $15 since you did not supply a USBA number)%c", sum,10); } printf("
%c",10); if (missing_cat) { my_error("You did not select categories in some of your events"); } printf("Total: $%d - please pay before October 20, or add a $5 late fee

%c", sum,10); fclose(tmpfile); sprintf(cmd,"mailx -s \"DCOPEN: %s\" teuben@astro.umd.edu < %s", name,tmpname); if (system(cmd)) { printf("BARF. There was a problem sending data, please try again"); printf("or contact teuben@astro.umd.edu%c",10); } else { printf("OK. If you need to, please resubmit with the exact first "); printf("and last name or add a comment to correct spelling errors. "); printf("Thank you for registering, hope to see you soon!

%c",10); } printf("-- Peter Teuben%c%c",10,10); printf("

P.S.: don't forget to fill out and send in your concent form, "); printf(" for priority checkin%c",10); unlink(tmpname); } my_error(char *s) { printf("OOPS: %s%c",s,10); printf("

Please go back and try again%c",10); exit(0); }