Subversion Repositories wimsdev

Rev

Rev 9037 | Rev 9044 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
7673 bpr 18
/* html form simplification routines */
8185 bpr 19
#include "wims.h"
10 reyssat 20
 
21
#define MAX_MENU_ITEMS 256
22
 
23
enum {
24
    FORM_SELECT, FORM_RADIO, FORM_BAR, FORM_CHECKBOX
25
};
26
 
7673 bpr 27
/* Produces <select> and <option>s.
28
 * Parameter string: name from n1 to n2 [prompt plist]
29
 * or name, list slist [prompt plist]
8155 bpr 30
 * Using script to do this is too slow.
31
 */
10 reyssat 32
void _form_menus(char *p,int kind)
33
{
9042 bpr 34
    char *n, *li, *pp, *val, *p0, *p1, *p2, *pc, *s, *hmode;
10 reyssat 35
    char *vlist[MAX_MENU_ITEMS], *plist[MAX_MENU_ITEMS];
36
    char nbuf[MAX_LINELEN+1],vbuf[MAX_LINELEN+1],pbuf[MAX_LINELEN+1];
9042 bpr 37
    char buf[256], pfrb[256], pfre[256];
38
    char input_id[128];
10 reyssat 39
    int i,i1=0,i2,itemcnt,type;
40
    if(!outputing) return;
41
    n=find_word_start(p); if(*n==0) return;
42
    pp=find_word_end(n);
43
    if(*pp!=0) *(pp++)=0;
44
    else {
7673 bpr 45
      syntax: module_error("syntax_error"); return;
10 reyssat 46
    }
47
    li=find_word_start(pp); pp=find_word_end(li);
48
    if(*pp!=0) *(pp++)=0; else goto syntax;
49
    itemcnt=0;
50
    if(strcmp(li,"from")==0) {
7673 bpr 51
      p1=find_word_start(pp);
52
      p2=wordchr(p1,"to"); if(p2==NULL || p2<=p1) goto syntax;
53
      *(p2-1)=0; p2=find_word_start(p2+strlen("to"));
54
      pp=wordchr(p2,"prompt"); if(pp!=NULL) *(pp-1)=0;
55
      i1=evalue(p1); i2=evalue(p2);
56
      if(i1<-100000000 || i1>100000000 || i2<-100000000 || i2>100000000)
57
        goto syntax;
58
      if(i2<i1) return;
59
      if(i2>i1+MAX_MENU_ITEMS-1) i2=i1+MAX_MENU_ITEMS-1;
60
      itemcnt=i2-i1+1;
61
      type=0;
10 reyssat 62
    }
63
    else {
7673 bpr 64
      if(strcmp(li,"list")==0) {
9007 obado 65
        p1=find_word_start(pp);
66
        pp=wordchr(p1,"prompt"); if(pp!=NULL && pp>p1) *(pp-1)=0;
67
        ovlstrcpy(vbuf,p1);substit(vbuf);
68
        itemcnt=cutitems(vbuf,vlist,MAX_MENU_ITEMS);
69
        type=1;
7673 bpr 70
      }
71
      else goto syntax;
10 reyssat 72
    }
73
    for(i=0;i<itemcnt;i++) plist[i]=NULL;
74
    if(pp!=NULL) {
7673 bpr 75
      p1=find_word_start(pp+strlen("prompt"));
76
      ovlstrcpy(pbuf,p1);substit(pbuf);
77
      cutitems(pbuf,plist,MAX_MENU_ITEMS);
10 reyssat 78
    }
3718 reyssat 79
    ovlstrcpy(nbuf,n);substit(nbuf);
10 reyssat 80
    if(kind==FORM_SELECT) {
7673 bpr 81
      char *pp;
82
      pp=getvar("wims_formselect_switch"); if(pp==NULL) pp="";
83
      output("<select %s name=\"%s\" id=\"%s\">\n",pp,nbuf,nbuf);
10 reyssat 84
    }
7515 bpr 85
    if(kind==FORM_BAR) {
86
      s=getvar("wims_ref_class");
87
      if(s!=NULL && *s!=0 && !isspace(*s)) {
9042 bpr 88
        snprintf(pfrb,sizeof(pfrb)," <span class=\"%s\">",s); strcpy(pfre,"</span>");
89
      } else { pfrb[0]=0; pfre[0]=0; }
7515 bpr 90
      output("%s<span style=\"font-weight:bold;\">-</span>",pfrb);
91
    }
10 reyssat 92
    val=getvar(nbuf);if(val==NULL) val="";
9007 obado 93
 
94
    s = getvar("wims_ref_id");
9042 bpr 95
    if(s!=NULL && *s!=0 && !isspace(*s)) { strcpy(input_id,s); }
96
      else { strcpy(input_id,nbuf);}
9007 obado 97
 
10 reyssat 98
    for(i=0;i<itemcnt;i++) {
7673 bpr 99
      if(type==0) {
9007 obado 100
        snprintf(buf,sizeof(buf),"%d",i+i1);
101
        p0=buf;
7673 bpr 102
      }
103
      else p0=vlist[i];
104
      if(*find_word_start(p0)==0) continue;
105
      if(plist[i]==NULL) plist[i]=p0;
106
      if(*val!=0 &&
107
        (strcmp(p0,val)==0 ||
108
         ( (kind==FORM_SELECT || kind==FORM_CHECKBOX)
109
          && itemchr(val,p0)!=NULL))) {
110
         if(kind==FORM_SELECT) pc=" selected=\"selected\"";
111
         else pc=" checked=\"checked\"";
112
      }
113
      else pc="";
9007 obado 114
 
115
      s = getvar("wims_ref_class");
9042 bpr 116
      hmode=getvar("wims_html_mode");
117
      pfrb[0]=0; pfre[0]=0;
9007 obado 118
      if(s!=NULL && *s!=0 && !isspace(*s)) {
9042 bpr 119
        if(hmode==NULL || *hmode==0 || isspace(*hmode)) {
120
          hmode="span";
9007 obado 121
        }
9042 bpr 122
        snprintf(pfrb, sizeof(pfrb), "<%s class=\"%s\">", hmode, s);
123
        snprintf(pfre, sizeof(pfre), "</%s>", hmode);
124
      } else {
125
        if(hmode!=NULL && *hmode!=0) {
126
          snprintf(pfrb, sizeof(pfrb), "<%s>", hmode);
127
          snprintf(pfre, sizeof(pfre), "</%s>", hmode);
128
        }
9007 obado 129
      }
130
 
7673 bpr 131
      switch(kind) {
9007 obado 132
        case FORM_SELECT:
133
         output("<option value=\"%s\"%s>%s</option>\n", p0, pc, plist[i]);
7673 bpr 134
         break;
7515 bpr 135
 
9007 obado 136
        case FORM_RADIO:
7673 bpr 137
         output("%s<input type=\"radio\" name=\"%s\" id=\"%s%d\" value=\"%s\"%s/><label for=\"%s%d\">%s</label>%s",
9007 obado 138
             pfrb,nbuf,input_id,i,p0,pc,input_id,i,plist[i],pfre);
9042 bpr 139
         if(i<itemcnt-1 && itemcnt>2 && (hmode==NULL || *hmode==0)) _output_(",");
7673 bpr 140
         _output_("\n");
141
         break;
7515 bpr 142
 
9007 obado 143
        case FORM_CHECKBOX:
7673 bpr 144
         output("%s<input type=\"checkbox\" name=\"%s\" id=\"%s%d\" value=\"%s\"%s/><label for=\"%s%d\">%s</label>%s",
9007 obado 145
             pfrb,nbuf,input_id,i,p0,pc,input_id,i,plist[i],pfre);
9042 bpr 146
         if(i<itemcnt-1 && itemcnt>2 && (hmode==NULL || *hmode==0)) _output_(",");
7673 bpr 147
         _output_("\n");
148
         break;
7515 bpr 149
 
9007 obado 150
        case FORM_BAR:
9033 bpr 151
         output("<input type=\"radio\" name=\"%s\" id=\"%s%d\" value=\"%s\"%s/>",
9007 obado 152
             nbuf,input_id,i,p0,pc);
7673 bpr 153
         break;
154
      }
10 reyssat 155
    }
9042 bpr 156
    setvar("wims_ref_class","");
157
    setvar("wims_html_mode","");
10 reyssat 158
    if(kind==FORM_SELECT) _output_("</select>");
7515 bpr 159
    if(kind==FORM_BAR) output("<span style=\"font-weight:bold;\">+</span>%s",pfre);
10 reyssat 160
}
161
 
162
void exec_formselect(char *p)
163
{
164
    _form_menus(p,FORM_SELECT);
165
}
166
 
167
void exec_formradio(char *p)
168
{
169
    _form_menus(p,FORM_RADIO);
170
}
171
 
172
void exec_formcheckbox(char *p)
173
{
174
    _form_menus(p,FORM_CHECKBOX);
175
}
176
 
177
void exec_formbar(char *p)
178
{
179
    _form_menus(p,FORM_BAR);
180
}
181