Subversion Repositories wimsdev

Rev

Rev 9930 | Rev 13029 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9930 Rev 12241
Line 19... Line 19...
19
#include "wims.h"
19
#include "wims.h"
20
 
20
 
21
#define MAX_MENU_ITEMS 256
21
#define MAX_MENU_ITEMS 256
22
 
22
 
23
enum {
23
enum {
24
    FORM_SELECT, FORM_RADIO, FORM_BAR, FORM_CHECKBOX
24
  FORM_SELECT, FORM_RADIO, FORM_BAR, FORM_CHECKBOX
25
};
25
};
26
 
26
 
27
/* Produces <select> and <option>s.
27
/* Produces <select> and <option>s.
28
 * Parameter string: name from n1 to n2 [prompt plist]
28
 * Parameter string: name from n1 to n2 [prompt plist]
29
 * or name, list slist [prompt plist]
29
 * or name, list slist [prompt plist]
30
 * Using script to do this is too slow.
30
 * Using script to do this is too slow.
31
 */
31
 */
32
void _form_menus(char *p,int kind)
32
void _form_menus(char *p,int kind)
33
{
33
{
34
    char *n, *li, *pp, *val, *p0, *p1, *p2, *pc, *s, *hmode, *name;
34
  char *n, *li, *pp, *val, *p0, *p1, *p2, *pc, *s, *hmode, *name;
35
    char *vlist[MAX_MENU_ITEMS], *plist[MAX_MENU_ITEMS];
35
  char *vlist[MAX_MENU_ITEMS], *plist[MAX_MENU_ITEMS];
36
    char nbuf[MAX_LINELEN+1],vbuf[MAX_LINELEN+1],pbuf[MAX_LINELEN+1];
36
  char nbuf[MAX_LINELEN+1],vbuf[MAX_LINELEN+1],pbuf[MAX_LINELEN+1];
37
    char buf[256], pfrb[256], pfre[256], input_id[128];
37
  char buf[256], pfrb[256], pfre[256], input_id[128];
38
    int i,i1=0,i2,itemcnt,type;
38
  int i,i1=0,i2,itemcnt,type;
39
    if(!outputing) return;
39
  if(!outputing) return;
40
    n=find_word_start(p); if(*n==0) return;
40
  n=find_word_start(p); if(*n==0) return;
41
    pp=find_word_end(n);
41
  pp=find_word_end(n);
42
    if(*pp!=0) *(pp++)=0;
42
  if(*pp!=0) *(pp++)=0;
43
    else {
43
  else {
44
      syntax: module_error("syntax_error"); return;
44
    syntax: module_error("syntax_error"); return;
45
    }
45
  }
46
    li=find_word_start(pp); pp=find_word_end(li);
46
  li=find_word_start(pp); pp=find_word_end(li);
47
    if(*pp!=0) *(pp++)=0; else goto syntax;
47
  if(*pp!=0) *(pp++)=0; else goto syntax;
48
    itemcnt=0;
48
  itemcnt=0;
49
    if(strcmp(li,"from")==0) {
49
  if(strcmp(li,"from")==0) {
-
 
50
    p1=find_word_start(pp);
-
 
51
    p2=wordchr(p1,"to"); if(p2==NULL || p2<=p1) goto syntax;
-
 
52
    *(p2-1)=0; p2=find_word_start(p2+strlen("to"));
-
 
53
    pp=wordchr(p2,"prompt"); if(pp!=NULL) *(pp-1)=0;
-
 
54
    i1=evalue(p1); i2=evalue(p2);
-
 
55
    if(i1<-100000000 || i1>100000000 || i2<-100000000 || i2>100000000)
-
 
56
      goto syntax;
-
 
57
    if(i2<i1) return;
-
 
58
    if(i2>i1+MAX_MENU_ITEMS-1) i2=i1+MAX_MENU_ITEMS-1;
-
 
59
    itemcnt=i2-i1+1;
-
 
60
    type=0;
-
 
61
  }
-
 
62
  else {
-
 
63
    if(strcmp(li,"list")==0) {
50
      p1=find_word_start(pp);
64
      p1=find_word_start(pp);
51
      p2=wordchr(p1,"to"); if(p2==NULL || p2<=p1) goto syntax;
-
 
52
      *(p2-1)=0; p2=find_word_start(p2+strlen("to"));
-
 
53
      pp=wordchr(p2,"prompt"); if(pp!=NULL) *(pp-1)=0;
65
      pp=wordchr(p1,"prompt"); if(pp!=NULL && pp>p1) *(pp-1)=0;
54
      i1=evalue(p1); i2=evalue(p2);
66
      ovlstrcpy(vbuf,p1);substit(vbuf);
55
      if(i1<-100000000 || i1>100000000 || i2<-100000000 || i2>100000000)
-
 
56
        goto syntax;
-
 
57
      if(i2<i1) return;
-
 
58
      if(i2>i1+MAX_MENU_ITEMS-1) i2=i1+MAX_MENU_ITEMS-1;
67
      itemcnt=cutitems(vbuf,vlist,MAX_MENU_ITEMS);
59
      itemcnt=i2-i1+1;
-
 
60
      type=0;
68
      type=1;
61
    }
69
    }
62
    else {
-
 
63
      if(strcmp(li,"list")==0) {
-
 
64
        p1=find_word_start(pp);
-
 
65
        pp=wordchr(p1,"prompt"); if(pp!=NULL && pp>p1) *(pp-1)=0;
-
 
66
        ovlstrcpy(vbuf,p1);substit(vbuf);
-
 
67
        itemcnt=cutitems(vbuf,vlist,MAX_MENU_ITEMS);
-
 
68
        type=1;
-
 
69
      }
-
 
70
      else goto syntax;
70
    else goto syntax;
71
    }
71
  }
72
    for(i=0;i<itemcnt;i++) plist[i]=NULL;
72
  for(i=0;i<itemcnt;i++) plist[i]=NULL;
73
    if(pp!=NULL) {
73
  if(pp!=NULL) {
74
      p1=find_word_start(pp+strlen("prompt"));
74
    p1=find_word_start(pp+strlen("prompt"));
75
      ovlstrcpy(pbuf,p1);substit(pbuf);
75
    ovlstrcpy(pbuf,p1);substit(pbuf);
76
      cutitems(pbuf,plist,MAX_MENU_ITEMS);
76
    cutitems(pbuf,plist,MAX_MENU_ITEMS);
77
    }
77
  }
78
    ovlstrcpy(nbuf,n);substit(nbuf);
78
  ovlstrcpy(nbuf,n);substit(nbuf);
79
    if(kind==FORM_SELECT) {
79
  if(kind==FORM_SELECT) {
80
      char *pp;
80
    char *pp;
81
      pp=getvar("wims_formselect_switch"); if(pp==NULL) pp="";
81
    pp=getvar("wims_formselect_switch"); if(pp==NULL) pp="";
82
      output("<select %s name=\"%s\" id=\"%s\">\n",pp,nbuf,nbuf);
82
    output("<select %s name=\"%s\" id=\"%s\">\n",pp,nbuf,nbuf);
83
    }
83
  }
84
    if(kind==FORM_BAR) {
84
  if(kind==FORM_BAR) {
85
      s=getvar("wims_ref_class");
85
    s=getvar("wims_ref_class");
86
      if(s!=NULL && *s!=0 && !isspace(*s)) {
86
    if(s!=NULL && *s!=0 && !isspace(*s)) {
87
        snprintf(pfrb,sizeof(pfrb)," <span class=\"%s\">",s); strcpy(pfre,"</span>");
87
      snprintf(pfrb,sizeof(pfrb)," <span class=\"%s\">",s); strcpy(pfre,"</span>");
88
      } else { pfrb[0]=0; pfre[0]=0; }
88
    } else { pfrb[0]=0; pfre[0]=0; }
89
      output("%s<span style=\"font-weight:bold;\">-</span>",pfrb);
89
    output("%s<span style=\"font-weight:bold;\">-</span>",pfrb);
-
 
90
  }
-
 
91
  val=getvar(nbuf);if(val==NULL) val="";
-
 
92
 
-
 
93
  s = getvar("wims_ref_id");
-
 
94
  if(s!=NULL && *s!=0 && !isspace(*s)) { strcpy(input_id,s); }
-
 
95
  else { strcpy(input_id,nbuf);}
-
 
96
 
-
 
97
  for(i=0;i<itemcnt;i++) {
-
 
98
    if(type==0) {
-
 
99
      snprintf(buf,sizeof(buf),"%d",i+i1);
-
 
100
      p0=buf;
90
    }
101
    }
-
 
102
    else p0=vlist[i];
-
 
103
    if(*find_word_start(p0)==0) continue;
91
    val=getvar(nbuf);if(val==NULL) val="";
104
    if(plist[i]==NULL) plist[i]=p0;
-
 
105
    if(*val!=0 &&
-
 
106
        (strcmp(p0,val)==0 ||
-
 
107
        ( (kind==FORM_SELECT || kind==FORM_CHECKBOX)
-
 
108
        && itemchr(val,p0)!=NULL))) {
-
 
109
      if(kind==FORM_SELECT) pc=" selected=\"selected\"";
-
 
110
      else pc=" checked=\"checked\"";
-
 
111
    }
-
 
112
    else pc="";
92
 
113
 
93
    s = getvar("wims_ref_id");
114
    s = getvar("wims_ref_class");
94
    if(s!=NULL && *s!=0 && !isspace(*s)) { strcpy(input_id,s); }
-
 
95
      else { strcpy(input_id,nbuf);}
115
    hmode=getvar("wims_html_mode");
96
 
-
 
97
    for(i=0;i<itemcnt;i++) {
116
    pfrb[0]=0; pfre[0]=0;
98
      if(type==0) {
117
    if(s!=NULL && *s!=0 && !isspace(*s)) {
99
        snprintf(buf,sizeof(buf),"%d",i+i1);
118
      if(hmode==NULL || *hmode==0 || isspace(*hmode)) {
100
        p0=buf;
119
        hmode="span";
101
      }
120
      }
102
      else p0=vlist[i];
-
 
103
      if(*find_word_start(p0)==0) continue;
-
 
104
      if(plist[i]==NULL) plist[i]=p0;
-
 
105
      if(*val!=0 &&
-
 
106
        (strcmp(p0,val)==0 ||
-
 
107
         ( (kind==FORM_SELECT || kind==FORM_CHECKBOX)
-
 
108
          && itemchr(val,p0)!=NULL))) {
-
 
109
         if(kind==FORM_SELECT) pc=" selected=\"selected\"";
121
      snprintf(pfrb, sizeof(pfrb), "<%s class=\"%s\">", hmode, s);
110
         else pc=" checked=\"checked\"";
122
      snprintf(pfre, sizeof(pfre), "</%s>", hmode);
111
      }
-
 
112
      else pc="";
123
    } else {
113
 
-
 
114
      s = getvar("wims_ref_class");
-
 
115
      hmode=getvar("wims_html_mode");
-
 
116
      pfrb[0]=0; pfre[0]=0;
-
 
117
      if(s!=NULL && *s!=0 && !isspace(*s)) {
-
 
118
        if(hmode==NULL || *hmode==0 || isspace(*hmode)) {
124
      if(hmode!=NULL && *hmode!=0) {
119
          hmode="span";
-
 
120
        }
-
 
121
        snprintf(pfrb, sizeof(pfrb), "<%s class=\"%s\">", hmode, s);
125
        snprintf(pfrb, sizeof(pfrb), "<%s>", hmode);
122
        snprintf(pfre, sizeof(pfre), "</%s>", hmode);
126
        snprintf(pfre, sizeof(pfre), "</%s>", hmode);
123
      } else {
-
 
124
        if(hmode!=NULL && *hmode!=0) {
-
 
125
          snprintf(pfrb, sizeof(pfrb), "<%s>", hmode);
-
 
126
          snprintf(pfre, sizeof(pfre), "</%s>", hmode);
-
 
127
        }
-
 
128
      }
-
 
129
      switch(kind) {
-
 
130
        case FORM_RADIO: name="radio"; break;
-
 
131
        case FORM_CHECKBOX: name="checkbox"; break;
-
 
132
        default: name="";
-
 
133
      }
-
 
134
      switch(kind) {
-
 
135
        case FORM_SELECT:
-
 
136
         output("<option value=\"%s\"%s>%s</option>\n", p0, pc, plist[i]);
-
 
137
         break;
-
 
138
 
-
 
139
        case FORM_RADIO:
-
 
140
        case FORM_CHECKBOX:
-
 
141
         if (itemcnt > 1) {
-
 
142
         output("%s<input type=\"%s\" name=\"%s\" id=\"%s_%d\" value=\"%s\"%s/><label for=\"%s_%d\">%s</label>%s",
-
 
143
             pfrb,name,nbuf,input_id,i+1,p0,pc,input_id,i+1,plist[i],pfre);
-
 
144
         } else {
-
 
145
         output("%s<input type=\"%s\" name=\"%s\" id=\"%s\" value=\"%s\"%s/><label for=\"%s\">%s</label>%s",
-
 
146
             pfrb,name,nbuf,input_id,p0,pc,input_id,plist[i],pfre);
-
 
147
         }
-
 
148
         if(i<itemcnt-1 && itemcnt>2 && (hmode==NULL || *hmode==0)) _output_(",");
-
 
149
         _output_("\n");
-
 
150
         break;
-
 
151
        case FORM_BAR:
-
 
152
         output("<input type=\"radio\" name=\"%s\" id=\"%s_%d\" value=\"%s\"%s/>",
-
 
153
             nbuf,input_id,i+1,p0,pc);
-
 
154
         break;
-
 
155
      }
127
      }
156
    }
128
    }
-
 
129
    switch(kind) {
-
 
130
      case FORM_RADIO: name="radio"; break;
-
 
131
      case FORM_CHECKBOX: name="checkbox"; break;
-
 
132
      default: name="";
-
 
133
    }
-
 
134
    switch(kind) {
-
 
135
      case FORM_SELECT:
-
 
136
        output("<option value=\"%s\"%s>%s</option>\n", p0, pc, plist[i]);
-
 
137
        break;
-
 
138
 
-
 
139
      case FORM_RADIO:
-
 
140
      case FORM_CHECKBOX:
-
 
141
        if (itemcnt > 1) {
-
 
142
          output("%s<input type=\"%s\" name=\"%s\" id=\"%s_%d\" value=\"%s\"%s/><label for=\"%s_%d\">%s</label>%s",
-
 
143
           pfrb,name,nbuf,input_id,i+1,p0,pc,input_id,i+1,plist[i],pfre);
-
 
144
        } else {
-
 
145
          output("%s<input type=\"%s\" name=\"%s\" id=\"%s\" value=\"%s\"%s/><label for=\"%s\">%s</label>%s",
-
 
146
           pfrb,name,nbuf,input_id,p0,pc,input_id,plist[i],pfre);
-
 
147
        }
-
 
148
        if(i<itemcnt-1 && itemcnt>2 && (hmode==NULL || *hmode==0)) _output_(",");
-
 
149
        _output_("\n");
-
 
150
        break;
-
 
151
      case FORM_BAR:
-
 
152
        output("<input type=\"radio\" name=\"%s\" id=\"%s_%d\" value=\"%s\"%s/>",
-
 
153
           nbuf,input_id,i+1,p0,pc);
-
 
154
        break;
-
 
155
    }
-
 
156
  }
157
    setvar("wims_ref_class","");
157
  setvar("wims_ref_class","");
158
    setvar("wims_ref_id","");
158
  setvar("wims_ref_id","");
159
    setvar("wims_html_mode","");
159
  setvar("wims_html_mode","");
160
    if(kind==FORM_SELECT) _output_("</select>");
160
  if(kind==FORM_SELECT) _output_("</select>");
161
    if(kind==FORM_BAR) output("<span style=\"font-weight:bold;\">+</span>%s",pfre);
161
  if(kind==FORM_BAR) output("<span style=\"font-weight:bold;\">+</span>%s",pfre);
162
}
162
}
163
 
163
 
164
void exec_formselect(char *p)
164
void exec_formselect(char *p)
165
{
165
{
166
    _form_menus(p,FORM_SELECT);
166
  _form_menus(p,FORM_SELECT);
167
}
167
}
168
 
168
 
169
void exec_formradio(char *p)
169
void exec_formradio(char *p)
170
{
170
{
171
    _form_menus(p,FORM_RADIO);
171
  _form_menus(p,FORM_RADIO);
172
}
172
}
173
 
173
 
174
void exec_formcheckbox(char *p)
174
void exec_formcheckbox(char *p)
175
{
175
{
176
    _form_menus(p,FORM_CHECKBOX);
176
   _form_menus(p,FORM_CHECKBOX);
177
}
177
}
178
 
178
 
179
void exec_formbar(char *p)
179
void exec_formbar(char *p)
180
{
180
{
181
    _form_menus(p,FORM_BAR);
181
  _form_menus(p,FORM_BAR);
182
}
182
}
183
 
-