817fd21998-11-09Marcus Comstedt /* $Id: wizard.pike,v 1.76 1998/11/09 22:01:03 marcus Exp $
2da8471997-08-20Per Hedbor  * name="Wizard generator";
fc94331997-10-25Per Hedbor  * doc="This file generats all the nice wizards";
2da8471997-08-20Per Hedbor  */ inherit "roxenlib";
fc94331997-10-25Per Hedbor string wizard_tag_var(string n, mapping m, mixed a, mixed b)
2da8471997-08-20Per Hedbor {
fc94331997-10-25Per Hedbor  object id; if(n=="cvar") // Container. Default value in 'a', id in 'b'. { id = b;
e8f6df1998-05-22Per Hedbor  if(m->type == "select" || m->type == "select_multiple")
2f40281998-06-01Mattias Wingstedt  if (m->parse)
4e17dc1998-07-17Fredrik Noring  m->options = (replace(parse_rxml( a, id ), ",", "__CoMma__") / "\n" - ({ "" })) * ",";
2f40281998-06-01Mattias Wingstedt  else m->options = (a / "\n") * ","; else if (m->parse)
2dc9141998-05-29Mattias Wingstedt  m["default"] = parse_rxml( a, id );
2f40281998-06-01Mattias Wingstedt  else m["default"] = a;
5c5ace1998-07-23Per Hedbor  } else // tag. No contents, id in 'a'.
fc94331997-10-25Per Hedbor  id = a;
2da8471997-08-20Per Hedbor  string current = id->variables[m->name] || m["default"];
3df2f51997-11-13David Hedbor  if(current) current = current +"";
2da8471997-08-20Per Hedbor  switch(m->type) {
8442681998-08-31Honza Petrous  default: // String or password field or hidden value.... if((m->type != "password") && (m->type != "hidden"))
f0907f1997-11-03David Hedbor  m->type = "string";
2da8471997-08-20Per Hedbor  m_delete(m,"default");
a2316f1998-03-12Mirar (Pontus Hagland)  m->value = current||m->value||"";
78d67d1997-08-20Per Hedbor  if(!m->size)m->size="60,1";
2da8471997-08-20Per Hedbor  return make_tag("input", m);
6796b01997-08-20Per Hedbor  case "list": // String.... string n = m->name, res="<table cellpadding=0 cellspacing=0 border=0>"; if(!id->variables[n]) id->variables[n]=current; m->type = "string"; if(!m->size)m->size="60,1"; m_delete(m,"default"); foreach((current||"")/"\0"-({""}), string v) { res+="<tr><td>"+v+"</td><td><font size=-2>"; m->name="_delete_"+n+":"+v; m->value = " Remove "; m->type = "submit"; res+=make_tag("input",m)+"</td></tr>"; } m->name = "_new_"+n; m->type = "string"; m->value = ""; res+= "<tr><td>"+make_tag("input", m)+"</td><td><font size=-2>"; m->name="_Add"; m->value = " Add "; m->type = "submit"; res+=make_tag("input",m)+"</font></td></tr>"; res+="</table>"; return res;
78d67d1997-08-20Per Hedbor  case "text": m_delete(m,"type"); m_delete(m,"default");
d382391997-10-29Per Hedbor  m_delete(m, "value");
75ebae1997-08-20Per Hedbor  if(!m->rows)m->rows="6"; if(!m->cols)m->cols="40";
57bd8f1997-08-20Per Hedbor  return make_container("textarea", m, html_encode_string(current||""));
78d67d1997-08-20Per Hedbor 
9cc6771997-08-20Fredrik Noring  case "radio": m_delete(m,"default");
489ff51998-07-19Per Hedbor  if((!id->variables[m->name] && current) || (current==m->value)) m->checked="checked"; return make_tag("input",m);
9cc6771997-08-20Fredrik Noring  case "checkbox":
2ebb571997-08-21Per Hedbor  string res;
9cc6771997-08-20Fredrik Noring  m_delete(m,"default"); m_delete(m, m->name); m_delete(id->variables, m->name);
e3e8441997-08-22Per Hedbor  if(current && current!="0") m->checked="checked";
2ebb571997-08-21Per Hedbor  res=make_tag("input", m); m->type="hidden"; m->value="0"; return res+make_tag("input", m);
78d67d1997-08-20Per Hedbor 
2da8471997-08-20Per Hedbor  case "int": m->type = "number"; m_delete(m,"default");
78d67d1997-08-20Per Hedbor  m->value = (string)((int)current); if(!m->size)m->size="8,1"; return make_tag("input", m); case "float": m->type = "number"; m_delete(m,"default"); m->value = (string)((float)current); if(!m->size)m->size="14,1";
2da8471997-08-20Per Hedbor  return make_tag("input", m);
fc94331997-10-25Per Hedbor  case "color": int h, s, v; if(id->variables[m->name+".hsv"]) sscanf(id->variables[m->name+".hsv"], "%d,%d,%d", h, s, v); else { array tmp = rgb_to_hsv(@parse_color(current||"black")); h = tmp[0]; s = tmp[1]; v = tmp[2];
3d03581997-11-05David Hedbor  }
a62ee71998-07-22Johan Schön  if(id->variables[m->name+".foo.x"]) { h = (int)id->variables[m->name+".foo.x"]; v = 255-(int)id->variables[m->name+".foo.y"]; } else if(id->variables[m->name+".bar.y"]) s=255-(int)id->variables[m->name+".bar.y"];
3d03581997-11-05David Hedbor  else if(id->variables[m->name+".entered"] && strlen(current=id->variables[m->name+".entered"]))
fc94331997-10-25Per Hedbor  { array tmp = rgb_to_hsv(@parse_color(current||"black")); h = tmp[0]; s = tmp[1]; v = tmp[2]; }
3d03581997-11-05David Hedbor 
a62ee71998-07-22Johan Schön  m_delete(id->variables, m->name+".foo.x"); m_delete(id->variables, m->name+".foo.y"); m_delete(id->variables, m->name+".bar.x"); m_delete(id->variables, m->name+".bar.y");
fc94331997-10-25Per Hedbor  id->variables[m->name+".hsv"] = h+","+s+","+v; array a=hsv_to_rgb(h,s,v); string bgcol=sprintf("#%02x%02x%02x",a[0],a[1],a[2]); id->variables[m->name] = bgcol; return ("<table><tr>\n" "<td width=258 rowspan=2>\n" " <table bgcolor=black cellpadding=1 border=0 cellspacing=0 width=258><tr><td>\n"
4f24fe1998-09-16Marcus Wellhardh  " <input type=image name='"+m->name+".foo' src=/internal-roxen-colsel width=256 height=256 border=0></td>" "</table>\n"
fc94331997-10-25Per Hedbor  "</td>\n" "<td width=30 rowspan=2></td>\n" "<td width=32 rowspan=2>\n" " <table bgcolor=black cellpadding=1 border=0 cellspacing=0 width=32><tr><td>\n" "<input type=image src=\"/internal-roxen-colorbar:"+ (string)h+","+(string)v+","+(string)s+"\" "
4f24fe1998-09-16Marcus Wellhardh  "name='"+m->name+".bar' width=30 height=256 border=0></td>" "</table>\n"
fc94331997-10-25Per Hedbor  "</td>\n" "<td width=32 rowspan=2></td>\n" "<td width=120>\n" " <table bgcolor=black cellpadding=1 border=3 cellspacing=0 width=90>\n" " <tr><td height=90 width=90 bgcolor="+bgcol+">&nbsp;"+ (m->tt?"<font color='"+m->tc+"'>"+m->tt+"</font>":"") +"</td></table>\n" "</td><tr>\n" "<td width=120>\n" "<b>R:</b> "+(string)a[0]+"<br>\n" "<b>G:</b> "+(string)a[1]+"<br>\n" "<b>B:</b> "+(string)a[2]+"<br>\n" "<hr size=2 align=left noshade width=70>\n" "<b>H:</b> "+(string)h+"<br>\n" "<b>S:</b> "+(string)s+"<br>\n" "<b>V:</b> "+(string)v+"<br>\n" "<hr size=2 align=left noshade width=70>\n"+ "<font size=-1><input type=string name="+ m->name+".entered size=8 value='"+
0b58f11997-11-05David Hedbor  color_name(a)+"'> <input type=submit value=Ok></font></td></table>\n");
fc94331997-10-25Per Hedbor 
4f24fe1998-09-16Marcus Wellhardh  case "color-small": int h, s, v; if(id->variables[m->name+".hsv"]) sscanf(id->variables[m->name+".hsv"], "%d,%d,%d", h, s, v); else { array tmp = rgb_to_hsv(@parse_color(current||"black")); h = tmp[0]; s = tmp[1]; v = tmp[2]; } if(id->variables[m->name+".foo.x"]) { h = ((int)id->variables[m->name+".foo.x"])*2; v = 255-((int)id->variables[m->name+".foo.y"])*2; } else if(id->variables[m->name+".bar.y"]) s = 255-((int)id->variables[m->name+".bar.y"])*2; else if(id->variables[m->name+".entered"] && strlen(current=id->variables[m->name+".entered"])) { array tmp = rgb_to_hsv(@parse_color(current||"black")); h = tmp[0]; s = tmp[1]; v = tmp[2]; } m_delete(id->variables, m->name+".foo.x"); m_delete(id->variables, m->name+".foo.y"); m_delete(id->variables, m->name+".bar.x"); m_delete(id->variables, m->name+".bar.y"); id->variables[m->name+".hsv"] = h+","+s+","+v; array a=hsv_to_rgb(h,s,v); string bgcol=sprintf("#%02x%02x%02x",a[0],a[1],a[2]); id->variables[m->name] = bgcol; return ("<table border=0 cellpadding=0 cellspacing=0><tr>\n" "<td rowspan=2>\n" " <table bgcolor=black cellpadding=1 border=0 cellspacing=0><tr><td>\n" " <input type=image name='"+m->name+".foo' " " src=/internal-roxen-colsel-small " " width=128 height=128 border=0></td>" " </table>\n" "</td>\n" "<td width=8 rowspan=2><img src=/internal-roxen-unit width=8></td>\n" "<td width=18 rowspan=2>\n" " <table bgcolor=black cellpadding=1 border=0 cellspacing=0><tr><td>\n" " <input type=image src=\"/internal-roxen-colorbar:"+ (string)h+","+(string)v+","+(string)s+"\" " " name='"+m->name+".bar' width=16 height=128 border=0></td>" " </table>\n" "</td>\n" "<td width=8 rowspan=2><img src=/internal-roxen-unit width=8></td>\n" "<td>\n" " <table bgcolor=black width=64 border=3 " " cellpadding=1 cellspacing=0><tr>\n" " <td height=64 width=64 bgcolor="+bgcol+">&nbsp;"+ (m->tt?"<font color='"+m->tc+"'>"+m->tt+"</font>":"")+"\n" " </td></tr>\n" " </table>\n" "</td>\n" "<tr><td width=110>\n" "<font size=-1><input type=string name="+ m->name+".entered size=8 value='"+ color_name(a)+"'> <input type=submit value=Ok></font>" "</td></tr>\n" "</table>\n");
fc94331997-10-25Per Hedbor  case "font": string res=""; m->type = "select"; m->choices = roxen->available_fonts(1)*",";
4f24fe1998-09-16Marcus Wellhardh  if(id->conf && id->conf->modules["graphic_text"] && !m->noexample)
fc94331997-10-25Per Hedbor  res = ("<input type=submit value='Example'><br>"+ ((current&&strlen(current))? "<gtext nfont='"+current+"'>Example Text</gtext><br>" :""));
4f24fe1998-09-16Marcus Wellhardh  m_delete(m, "noexample");
fc94331997-10-25Per Hedbor  return make_tag("var", m)+res;
2da8471997-08-20Per Hedbor  case "toggle": m_delete(m,"default"); return make_container("select", m, "<option"+((int)current?" selected":"")+" value=1>Yes" "<option"+(!(int)current?" selected":"")+" value=0>No"); case "select":
fc94331997-10-25Per Hedbor  if(!m->choices && m->options) m->choices = m->options; m_delete(m,"default"); m_delete(m,"type"); mapping m2 = copy_value(m); m_delete(m2, "choices"); m_delete(m2, "options");
b950c11998-03-13Francesco Chemolli  //escape the characters we need for internal purposes.. m->choices=replace(m->choices, ({"\\,", "\\:"}), ({"__CoMma__", "__CoLon__"}));
fc94331997-10-25Per Hedbor  return make_container("select", m2, Array.map(m->choices/",", lambda(string s, string c) {
d382391997-10-29Per Hedbor  string t; if(sscanf(s, "%s:%s", s, t) != 2) t = s;
b950c11998-03-13Francesco Chemolli  s=replace(s,({"__CoMma__", "__CoLon__"}),({",",":"})); //can't be done before. t=replace(t,({"__CoMma__", "__CoLon__"}),({",",":"}));
d382391997-10-29Per Hedbor  return "<option value='"+s+"' "+(s==c?" selected":"")+">"+html_encode_string(t)+"\n";
fc94331997-10-25Per Hedbor  },current)*"");
2da8471997-08-20Per Hedbor  case "select_multiple":
fc94331997-10-25Per Hedbor  if(!m->choices && m->options) m->choices = m->options;
2da8471997-08-20Per Hedbor  m_delete(m,"default"); m_delete(m,"type");
fc94331997-10-25Per Hedbor  m2 = copy_value(m); m_delete(m2, "choices"); m_delete(m2, "options"); m2->multiple="1";
b950c11998-03-13Francesco Chemolli  //escape the characters we need for internal purposes.. m->choices=replace(m->choices, ({"\\,", "\\:"}), ({"__CoMma__", "__CoLon__"}));
fc94331997-10-25Per Hedbor  return make_container("select", m2, Array.map(m->choices/",",
d382391997-10-29Per Hedbor  lambda(string s, array c) { string t; if(sscanf(s, "%s:%s", s, t) != 2) t = s;
b950c11998-03-13Francesco Chemolli  s=replace(s,({"__CoMma__", "__CoLon__"}),({",",":"})); //can't be done before. t=replace(t,({"__CoMma__", "__CoLon__"}),({",",":"}));
d382391997-10-29Per Hedbor  return "<option value='"+s+"' "+(search(c,s)!=-1?"selected":"")+">"+html_encode_string(t)+"\n";
fc94331997-10-25Per Hedbor  },(current||"")/"\0")*"");
2da8471997-08-20Per Hedbor  } } mapping decompress_state(string from) { if(!from) return ([]); from = MIME.decode_base64(from); catch { object gz = Gz; if(sizeof(indices(gz))) from = gz->inflate()->inflate(from); }; return decode_value(from); } string compress_state(mapping state) { state = copy_value(state); m_delete(state,"_state"); m_delete(state,"next_page"); m_delete(state,"prev_page"); m_delete(state,"help"); m_delete(state,"action"); m_delete(state,"unique");
2ebb571997-08-21Per Hedbor // werror(sprintf("State=%O\n", state));
2da8471997-08-20Per Hedbor  string from = encode_value(state); object gz = Gz; if(sizeof(indices(gz))) { string from2 = gz->deflate()->deflate(from);
ad86d41998-05-28Per Hedbor  /*if(strlen(from2)<strlen(from))*/ from=from2;
2da8471997-08-20Per Hedbor  } return MIME.encode_base64( from ); }
0582051997-08-20Per Hedbor string parse_wizard_help(string t, mapping m, string contents, object id, mapping v)
2da8471997-08-20Per Hedbor {
0582051997-08-20Per Hedbor  v->help=1;
2da8471997-08-20Per Hedbor  if(!id->variables->help) return ""; return contents; }
2ebb571997-08-21Per Hedbor string make_title()
1e5ee81997-08-21Per Hedbor {
b950c11998-03-13Francesco Chemolli  string s = (this_object()->wizard_name||this_object()->name||"No name") - "<p>";
2ebb571997-08-21Per Hedbor  sscanf(s, "%*s//%s", s); sscanf(s, "%*d:%s", s); return s;
1e5ee81997-08-21Per Hedbor }
cb2fef1997-08-23Marcus Comstedt  int num_pages(string wiz_name)
62d8c41997-10-16Per Hedbor {
2da8471997-08-20Per Hedbor  int max_page; for(int i=0; i<100; i++) if(!this_object()[wiz_name+i]) { max_page=i-1; break; }
cb2fef1997-08-23Marcus Comstedt  return max_page+1; }
41d0f91998-02-20Per Hedbor #define Q(X) replace(X,({"<",">","&","\""}),({"&lt;","&gt;","&amp;","&quote;"}))
32c6fa1998-02-27Per Hedbor #define PAGE Q((this_object()->page_label?this_object()->page_label:"Page "))
41d0f91998-02-20Per Hedbor #define OK Q((this_object()->ok_label?this_object()->ok_label:"Ok")) #define CANCEL Q((this_object()->cancel_label?this_object()->cancel_label:"Cancel")) #define NEXT Q((this_object()->next_label?this_object()->next_label:"Next ->")) #define PREVIOUS Q((this_object()->previous_label?this_object()->previous_label:"<- Previous")) #define COMPLETED Q((this_object()->completed_label?this_object()->completed_label:"Completed"))
2da8471997-08-20Per Hedbor 
cb2fef1997-08-23Marcus Comstedt string parse_wizard_page(string form, object id, string wiz_name) { int max_page = num_pages(wiz_name)-1;
2da8471997-08-20Per Hedbor  string res; int page = ((int)id->variables->_page);
0582051997-08-20Per Hedbor  mapping foo = ([]);
2da8471997-08-20Per Hedbor  // Cannot easily be inlined below, believe me... Side-effects.
817fd21998-11-09Marcus Comstedt  form = parse_html(form,(id->misc->extra_wizard_tags||([]))+ ([ "var":wizard_tag_var, ]), (id->misc->extra_wizard_container||([]))+
fc94331997-10-25Per Hedbor  ([ "cvar":wizard_tag_var, "help":parse_wizard_help]), id, foo );
2da8471997-08-20Per Hedbor  res = ("<!--Wizard-->\n"
53404e1998-02-28Mirar (Pontus Hagland)  "<form method=get>\n"
2da8471997-08-20Per Hedbor  " <input type=hidden name=action value=\""+id->variables->action+"\">\n" " <input type=hidden name=_page value=\""+page+"\">\n"
0582051997-08-20Per Hedbor  " <input type=hidden name=_state value=\""+compress_state(id->variables)+"\">\n" "<table bgcolor=black cellpadding=1 border=0 cellspacing=0 width=80%>\n"
6796b01997-08-20Per Hedbor  " <tr><td><table bgcolor=#eeeeee cellpadding=0 "
2da8471997-08-20Per Hedbor  " cellspacing=0 border=0 width=100%>\n"
2ebb571997-08-21Per Hedbor  " <tr><td valign=top><table width=100% height=100% cellspacing=0 cellpadding=5>\n<tr><td valign=top>\n" "<font size=+2>"+make_title()+"</font>"
6ad3161997-08-20Per Hedbor  " </td>\n<td align=right>"+
8492171998-02-19Mirar (Pontus Hagland)  (wiz_name=="done"
41d0f91998-02-20Per Hedbor  ?COMPLETED :(max_page?PAGE+(page+1)+"/"+(max_page+1):""))+
8492171998-02-19Mirar (Pontus Hagland)  "</td>\n"
2da8471997-08-20Per Hedbor  " \n<td align=right>"+
822f431997-08-20Per Hedbor  (foo->help && !id->variables->help?
06cc931997-08-20Per Hedbor  "<font size=-1><input type=image name=help src="+ (id->conf?"/internal-roxen-help":"/image/help.gif")+ " border=0 value=\"Help\"></font>":"")
2da8471997-08-20Per Hedbor  +"</td>\n"
9cc6771997-08-20Fredrik Noring  " </tr><tr><td colspan=3><table cellpadding=0 cellspacing=0 border=0 width=100%><tr bgcolor=#000000><td><img src="+
06cc931997-08-20Per Hedbor  (id->conf?"/internal-roxen-unit":"/image/unit.gif")+
70e7cc1998-07-08Henrik Grubbström (Grubba)  " width=1 height=1 alt=\"\"></td></tr></table></td></tr>\n"
2da8471997-08-20Per Hedbor  " </table><table cellpadding=6><tr><td>\n" "<!-- The output from the page function -->\n" +form+ "\n<!-- End of the output from the page function -->\n" "\n</td></tr></table>\n" " <table width=100%><tr><td width=33%>"+
8492171998-02-19Mirar (Pontus Hagland)  ((page>0 && wiz_name!="done")?
41d0f91998-02-20Per Hedbor  " <input type=submit name=prev_page value=\""+PREVIOUS+"\">":"")+
2da8471997-08-20Per Hedbor  "</td><td width=33% align=center >"+
8492171998-02-19Mirar (Pontus Hagland)  (wiz_name!="done" ?((page==max_page
41d0f91998-02-20Per Hedbor  ?" <input type=submit name=ok value=\" "+OK+" \">"
8492171998-02-19Mirar (Pontus Hagland)  :"")+
41d0f91998-02-20Per Hedbor  " <input type=submit name=cancel value=\" "+CANCEL+" \">") :" <input type=submit name=cancel value=\" "+OK+" \">")+
8492171998-02-19Mirar (Pontus Hagland)  "</td>"
2da8471997-08-20Per Hedbor  "</td><td width=33% align=right >"+
8492171998-02-19Mirar (Pontus Hagland)  ((page!=max_page && wiz_name!="done")?
41d0f91998-02-20Per Hedbor  " <input type=submit name=next_page value=\""+NEXT+"\">":"")+
2da8471997-08-20Per Hedbor  "</td></tr></table>" " </td><tr>\n" " </table>\n" " </td></tr>\n"
0582051997-08-20Per Hedbor  "</table>\n"
2da8471997-08-20Per Hedbor  " </form>\n"
0582051997-08-20Per Hedbor  );
2da8471997-08-20Per Hedbor  return res; } #define PAGE(X) ((string)(((int)v->_page)+(X)))
6796b01997-08-20Per Hedbor mapping|string wizard_for(object id,string cancel,mixed ... args)
2da8471997-08-20Per Hedbor { string data; int offset = 1; mapping v=id->variables;
6796b01997-08-20Per Hedbor  string wiz_name = "page_";
7c1ccb1997-08-22Per Hedbor 
acf6eb1998-07-30Johan Schön  mapping s = decompress_state(v->_state);
5cfe0d1998-03-12Mirar (Pontus Hagland)  if(v->cancel) {
acf6eb1998-07-30Johan Schön  return http_redirect(s->cancel_url||cancel||id->not_query, @(id->conf?({id}):({})));
5cfe0d1998-03-12Mirar (Pontus Hagland)  }
2fec621997-11-23Mirar (Pontus Hagland)  foreach(indices(s), string q) v[q] = v[q]||s[q];
2da8471997-08-20Per Hedbor  if(v->next_page)
7c1ccb1997-08-22Per Hedbor  { function c;
2d72561997-08-22Per Hedbor  if(!functionp(c=this_object()["verify_"+v->_page]) || (!c( id, @args )))
7c1ccb1997-08-22Per Hedbor  v->_page = PAGE(1); }
2da8471997-08-20Per Hedbor  else if(v->prev_page) {
0a1b801997-08-24Per Hedbor  v->_page = PAGE(-1);
2da8471997-08-20Per Hedbor  offset=-1; } else if(v->ok)
7c1ccb1997-08-22Per Hedbor  { function c;
0a1b801997-08-24Per Hedbor 
2d72561997-08-22Per Hedbor  if(!functionp(c=this_object()["verify_"+v->_page]) || (!c( id, @args )))
beaca01998-02-20Per Hedbor  { mixed res; if(c=this_object()->wizard_done) res = c(id,@args); if(res != -1) return (res
acf6eb1998-07-30Johan Schön  || http_redirect(s->cancel_url||cancel||id->not_query,
beaca01998-02-20Per Hedbor  @(id->conf?({id}):({})))); }
7c1ccb1997-08-22Per Hedbor  }
2da8471997-08-20Per Hedbor  else if(v["help.x"]) { m_delete(v, "help.x"); m_delete(v, "help.y"); v->help="1";
5cfe0d1998-03-12Mirar (Pontus Hagland)  }
6796b01997-08-20Per Hedbor  foreach(indices(id->variables), string n) { string q,on=n; if(sscanf(n, "_new_%s", n)) { if((v->_Add) && strlen(v[on]-"\r")) { if(v[n]) v[n]+="\0"+v[on]; else v[n]=v[on]; m_delete(v, on); m_delete(v, "_Add"); } } else if(sscanf(n, "_delete_%s:%s", n,q)==2) { if(v[n]) v[n]=replace(replace(v[n]/"\0",q,"")*"\0","\0\0","\0"); m_delete(v, on);
2ebb571997-08-21Per Hedbor  }
6796b01997-08-20Per Hedbor  } for(; !data; v->_page=PAGE(offset))
2da8471997-08-20Per Hedbor  {
b26e8a1998-06-29Marcus Comstedt  function c, pg=this_object()[wiz_name+((int)v->_page)]; if(!pg && functionp(c=this_object()["wizard_done"])) { mixed res = c(id,@args); if(res != -1) return (res || http_redirect(cancel||id->not_query, @(id->conf?({id}):({})))); }
56ea981998-02-24Per Hedbor  if(!pg) return "Internal error in wizard code: Invalid page ("+v->_page+")!";
2319be1997-08-20Per Hedbor  if(data = pg(id,@args)) break;
2da8471997-08-20Per Hedbor  }
b950c11998-03-13Francesco Chemolli  // If it's a mapping we can presume it is an http response, and return // it directly. if (mappingp(data)) return data;
2da8471997-08-20Per Hedbor  return parse_wizard_page(data,id,wiz_name); }
4bb6411997-08-20Per Hedbor  mapping wizards = ([]);
62d8c41997-10-16Per Hedbor string err;
2319be1997-08-20Per Hedbor object get_wizard(string act, string dir, mixed ... args)
4bb6411997-08-20Per Hedbor {
7c1ccb1997-08-22Per Hedbor  act-="/";
56ea981998-02-24Per Hedbor  if(!wizards[dir+act]) wizards[dir+act]=compile_file(dir+act)(@args);
4bb6411997-08-20Per Hedbor  return wizards[dir+act]; }
7c1ccb1997-08-22Per Hedbor 
6cc9811997-08-20Per Hedbor int zonk=time();
fc83ef1998-02-21Johan Schön mapping get_actions(object id, string base,string dir, array args)
6cc9811997-08-20Per Hedbor { mapping acts = ([ ]);
8988661998-11-09Marcus Comstedt  if(id->pragma["no-cache"]) wizards=([]);
6cc9811997-08-20Per Hedbor  foreach(get_dir(dir), string act) { mixed err;
8492171998-02-19Mirar (Pontus Hagland)  _master->set_inhibit_compile_errors(0);
6cc9811997-08-20Per Hedbor  err = catch { if(act[0]!='#' && act[-1]=='e') { string sm,rn = (get_wizard(act,dir,@args)->name||act), name; if(sscanf(rn, "%*s:%s", name) != 2) name = rn; sscanf(name, "%s//%s", sm, name);
fc83ef1998-02-21Johan Schön  if(!acts[sm]) acts[sm] = ({ ([]) }); if(id->misc->raw_wizard_actions) acts[sm][0][name]= ({ name, base, (["action":act,"unique":(string)(zonk++) ]), (get_wizard(act,dir,@args)->doc||"") }); else acts[sm]+= ({"<!-- "+rn+" --><dt><font size=\"+2\">"
6cc9811997-08-20Per Hedbor  "<a href=\""+base+"?action="+act+"&unique="+(zonk++)+"\">"+ name+"</a></font><dd>"+(get_wizard(act,dir,@args)->doc||"")}); } };
62d8c41997-10-16Per Hedbor  if(err) report_error(describe_backtrace(err));
6cc9811997-08-20Per Hedbor  } return acts; }
6796b01997-08-20Per Hedbor string act_describe_submenues(array menues, string base,string sel)
4bb6411997-08-20Per Hedbor {
6cc9811997-08-20Per Hedbor  if(sizeof(menues)==1) return "";
6796b01997-08-20Per Hedbor  string res = "<font size=+3>";
6cc9811997-08-20Per Hedbor  foreach(sort(menues), string s)
6796b01997-08-20Per Hedbor  res+= (s==sel?"<li>":"<font color=#eeeeee><li></font><a href=\""+base+"?sm="+replace(s||"Misc"," ","%20")+ "&uniq="+(++zonk)+"\">")+(s||"Misc")+ (s==sel?"<br>":"</a><br>")+""; return res + "</font>";
6cc9811997-08-20Per Hedbor } string focused_wizard_menu; mixed wizard_menu(object id, string dir, string base, mixed ... args) { mapping acts;
2ebb571997-08-21Per Hedbor  if(id->pragma["no-cache"]) wizards=([]);
6cc9811997-08-20Per Hedbor  if(!id->variables->sm) id->variables->sm = focused_wizard_menu; else focused_wizard_menu = id->variables->sm=="0"?0:id->variables->sm;
4bb6411997-08-20Per Hedbor  if(!id->variables->action) {
4b7b611997-10-24Fredrik Noring  mixed wizbug; wizbug = catch {
fc83ef1998-02-21Johan Schön  mapping acts = get_actions(id, base, dir, args); if(id->misc->raw_wizard_actions) return acts[id->variables->sm];
62d8c41997-10-16Per Hedbor  string res; res= ("<table cellpadding=3><tr><td valign=top bgcolor=#eeeeee>"+
6796b01997-08-20Per Hedbor  act_describe_submenues(indices(acts),base,id->variables->sm)+ "</td>\n\n<td valign=top>"+
2ebb571997-08-21Per Hedbor  (sizeof(acts)>1 && acts[id->variables->sm]?"<font size=+3>"+
6796b01997-08-20Per Hedbor  (id->variables->sm||"Misc")+"</font><dl>":"<dl>")+ (sort(acts[id->variables->sm]||({}))*"\n")+
62d8c41997-10-16Per Hedbor  "</dl></td></tr></table>"+
4b7b611997-10-24Fredrik Noring  (err && strlen(err)?"<pre>"+err+"</pre>":""));
62d8c41997-10-16Per Hedbor  err=""; return res; };
4b7b611997-10-24Fredrik Noring  if(wizbug) err = describe_backtrace(wizbug);
94d5321997-10-24Fredrik Noring  if(err && strlen(err)) {
62d8c41997-10-16Per Hedbor  string res="<pre>"+err+"</pre>"; err=""; return res; }
4b7b611997-10-24Fredrik Noring  } else { object o = get_wizard(id->variables->action,dir); if(!o) { mixed res = "<pre>"+err+"</pre>"; err=""; return res; } mixed res= o->wizard_for(id,base,@args);
62d8c41997-10-16Per Hedbor  err=""; return res; }
4b7b611997-10-24Fredrik Noring  return "<pre>The Wizard is confused.</pre>";
4bb6411997-08-20Per Hedbor }
1c5e031997-08-20Fredrik Noring  /*** Additional Action Functions ***/
8b10b91998-02-15Fredrik Noring string format_numeric(string s, string|void sep)
1c5e031997-08-20Fredrik Noring {
8b10b91998-02-15Fredrik Noring  sep = reverse(sep||"&nbsp;"); array(string) as = s/" "; string t = ""; string s = reverse(as[0]); while(sizeof(s)) { if(sizeof(s) > 3) t += s[0..2]+sep; else t += s; s = s[3..]; } return (({reverse(t)})+as[1..])*" "; } string html_table(array(string) subtitles, array(array(string)) table, mapping|void opt) { /* Options: * bgcolor, titlebgcolor, titlecolor, fgcolor0, fgcolor1, modulo * Containers: * <fields>[num|text, ...]</fields> */
1c5e031997-08-20Fredrik Noring  string r = "";
8b10b91998-02-15Fredrik Noring  if(!opt) opt = ([]); int m = (int)(opt->modulo?opt->modulo:1); r += ("<table bgcolor="+(opt->bgcolor||"black")+" border=0 " "cellspacing=0 cellpadding=1>\n"
2ebb571997-08-21Per Hedbor  "<tr><td>\n");
9cc6771997-08-20Fredrik Noring  r += "<table border=0 cellspacing=0 cellpadding=4>\n";
8b10b91998-02-15Fredrik Noring  r += "<tr bgcolor="+(opt->titlebgcolor||"#113377")+">\n";
6420831997-08-21Per Hedbor  int cols; foreach(subtitles, mixed s) { if(stringp(s)) {
8b10b91998-02-15Fredrik Noring  r+=("<th nowrap align=left><font color="+ (opt->titlecolor||"#ffffff")+">"+s+" &nbsp; </font></th>");
6420831997-08-21Per Hedbor  cols++; } else {
8b10b91998-02-15Fredrik Noring  r+=("</tr><tr bgcolor="+(opt->titlebgcolor||"#113377")+">" "<th nowrap align=left colspan="+cols+">" "<font color="+(opt->titlecolor||"#ffffff")+">"+s[0]+ " &nbsp; </font></th>");
6420831997-08-21Per Hedbor  }
88c98b1997-08-21Per Hedbor  }
1c5e031997-08-20Fredrik Noring  r += "</tr>";
8b10b91998-02-15Fredrik Noring 
1c5e031997-08-20Fredrik Noring  for(int i = 0; i < sizeof(table); i++) {
8b10b91998-02-15Fredrik Noring  string tr; r += tr = "<tr bgcolor="+((i/m)%2?opt->fgcolor1||"#ddeeff": opt->fgcolor0||"#ffffff")+">"; for(int j = 0; j < sizeof(table[i]); j++) { mixed s = table[i][j];
8609241997-08-23Henrik Grubbström (Grubba)  if(arrayp(s))
c45ecb1998-03-21Johan Schön  r += "</tr>"+tr+"<td colspan="+cols+">"+s[0]+" &nbsp;</td>";
8b10b91998-02-15Fredrik Noring  else { string type = "text"; if(arrayp(opt->fields) && j < sizeof(opt->fields)) type = opt->fields[j]; switch(type) { case "num": array a = s/"."; r += "<td nowrap align=right>"; if(sizeof(a) > 1) { r += (format_numeric(a[0])+"."+ reverse(format_numeric(reverse(a[1]), ";psbn&"))); } else r += format_numeric(s, "&nbsp;"); break; case "text": default: r += "<td nowrap>"+s; } r += "&nbsp;&nbsp;</td>"; } }
1c5e031997-08-20Fredrik Noring  r += "</tr>\n"; }
1e5ee81997-08-21Per Hedbor  r += "</table></td></tr>\n";
1c5e031997-08-20Fredrik Noring  r += "</table><br>\n"; return r; }
6796b01997-08-20Per Hedbor 
2ebb571997-08-21Per Hedbor  string html_notice(string notice, object id) {
56d2e11997-08-26Peter Bortas  return ("<table><tr><td valign=top><img \nalt=Notice: src=\""+
2ebb571997-08-21Per Hedbor  (id->conf?"/internal-roxen-":"/image/") +"err_1.gif\"></td><td valign=top>"+notice+"</td></tr></table>"); } string html_warning(string notice, object id) {
56d2e11997-08-26Peter Bortas  return ("<table><tr><td valign=top><img \nalt=Warning: src=\""+
2ebb571997-08-21Per Hedbor  (id->conf?"/internal-roxen-":"/image/") +"err_2.gif\"></td><td valign=top>"+notice+"</td></tr></table>"); } string html_error(string notice, object id) {
56d2e11997-08-26Peter Bortas  return ("<table><tr><td valign=top><img \nalt=Error: src=\""+
2ebb571997-08-21Per Hedbor  (id->conf?"/internal-roxen-":"/image/") +"err_3.gif\"></td><td valign=top>"+notice+"</td></tr></table>"); }
a683e81997-08-24Per Hedbor 
3d03581997-11-05David Hedbor string html_border(string what, int|void width, int|void ww, string|void bgcolor, string|void bdcolor)
a683e81997-08-24Per Hedbor { return ("<table border=0 cellpadding="+(width+1)+" cellspacing=0 "
3d03581997-11-05David Hedbor  "bgcolor="+(bdcolor||"black")+ "><tr><td><table border=0 cellpadding="+(ww)+ " cellspacing=0 bgcolor="+(bgcolor||"white")+ "><tr><td>"+what+"</tr></td></table>"
4013561997-08-24Per Hedbor  "</td></tr></table>"); } void filter_checkbox_variables(mapping v) {
f0e2861998-05-14H. William Welliver III  foreach(indices(v), string s) { if(!v[s] || (v[s]=="0")) m_delete(v,s); else v[s]-="\00"; }
a683e81997-08-24Per Hedbor }