f26aee2000-01-31Per Hedbor #include <config_interface.h> #include <module.h>
f0a70e2000-07-21Martin Nilsson #include <module_constants.h>
0c694f2000-07-23Martin Nilsson #include <roxen.h>
10745b2001-01-29Per Hedbor int no_reload() { if( sizeof( already_added ) ) return 1; // Reloading this script now would destroy state. }
0c694f2000-07-23Martin Nilsson //<locale-token project="roxen_config">LOCALE</locale-token> #define LOCALE(X,Y) _STR_LOCALE("roxen_config",X,Y)
f26aee2000-01-31Per Hedbor 
ab9b6d2000-02-11Per Hedbor // Class is the name of the directory.
c2b2722000-05-22Martin Nilsson array(string) class_description( string d, RequestID id )
ab9b6d2000-02-11Per Hedbor { string name, doc;
14bc712000-02-11Henrik Grubbström (Grubba)  while(!(< "", "/" >)[d] && !file_stat( d+"/INFO" ))
ab9b6d2000-02-11Per Hedbor  d = dirname(d);
14bc712000-02-11Henrik Grubbström (Grubba)  if((< "", "/" >)[d])
ab9b6d2000-02-11Per Hedbor  return ({"Local modules", "" }); string n = Stdio.read_bytes( d+"/INFO" ); sscanf( n, "<"+id->misc->config_locale+">%s" "</"+id->misc->config_locale+">", n ); sscanf( n, "%*s<name>%s</name>", name ); sscanf( n, "%*s<doc>%s</doc>", doc );
d39c492000-03-28Per Hedbor  if( search(n, "<noshow/>" ) != -1 ) return ({ "", "" });
ab9b6d2000-02-11Per Hedbor  if(!name) return ({"Local modules", "" }); if(!doc) doc =""; return ({ name, doc }); }
c2b2722000-05-22Martin Nilsson array(string) module_class( object m, RequestID id )
ab9b6d2000-02-11Per Hedbor { return class_description( m->filename, id ); }
f26aee2000-01-31Per Hedbor object module_nomore(string name, object modinfo, object conf) { mapping module; object o; if(!modinfo) return 0; if(!modinfo->multiple_copies && (module = conf->modules[name]) && sizeof(module->copies) ) return modinfo; if(((modinfo->type & MODULE_DIRECTORIES) && (o=conf->dir_module)) || ((modinfo->type & MODULE_AUTH) && (o=conf->auth_module)) || ((modinfo->type & MODULE_TYPES) && (o=conf->types_module)))
a38da12000-08-20Per Hedbor  return roxen.find_module( conf->otomod[o] );
f26aee2000-01-31Per Hedbor } // To redirect to when done with module addition string site_url( RequestID id, string site ) {
c170ce2001-01-28Per Hedbor  return "/sites/site.html/"+site+"/";
f26aee2000-01-31Per Hedbor } string page_base( RequestID id, string content ) {
10745b2001-01-29Per Hedbor  return sprintf( "<use file='/template' />\n"
e3aab72000-07-25Andreas Lange  "<tmpl title=' %s'>"
10745b2001-01-29Per Hedbor  "<topmenu base='/' selected='sites'/>\n"
ab9b6d2000-02-11Per Hedbor  "<content><cv-split>"
9e4a012000-04-06Per Hedbor  "<subtablist width='100%%'>"
f26aee2000-01-31Per Hedbor  "<st-tabs></st-tabs>" "<st-page>"
cc75f52000-10-21Martin Nilsson  "<if not='1' variable='form.initial'>"
b411b32000-08-25Andreas Lange  "<gbutton href='add_module.pike?config=&form.config:http;" "&reload_module_list=yes' > %s </gbutton> " "<gbutton href='site.html/&form.config;'> %s </gbutton>"
f599d92000-09-03Per Hedbor  "<p>\n</if>%s\n</p>\n"
f26aee2000-01-31Per Hedbor  "</st-page></subtablist></td></tr></table>"
e3aab72000-07-25Andreas Lange  "</cv-split></content></tmpl>", LOCALE(258,"Add module"),
f599d92000-09-03Per Hedbor  LOCALE(272,"Reload module list"),
b411b32000-08-25Andreas Lange  LOCALE(202,"Cancel"), content );
f26aee2000-01-31Per Hedbor }
1577242000-08-19Per Hedbor  string module_name_from_file( string file ) { string data, name; catch(data = Stdio.read_bytes( file )); if( data && sscanf( data, "%*smodule_name%*s=%[^;];", name ) && sscanf( name, "%*[^\"]\"%s\"", name ) )
6b394a2000-10-13Martin Nilsson  return Roxen.html_encode_string(name); return Roxen.html_encode_string(((file/"/")[-1]/".")[0]);
1577242000-08-19Per Hedbor } string pafeaw( string errors, string warnings ) // Parse And Format Errors And Warnings. // Your ordinary prettyprinting function. { mapping by_module = ([]); int cnt = 0; foreach( (errors+warnings)/"\n", string e ) { string file; int row; string type, error; sscanf( e, "%s:%d%s", file, row, error ); if( error ) { sscanf( error, "%*[ \t]%s", error ); sscanf( error, "%s: %s", type, error ); if( by_module[ file ] ) by_module[ file ] += ({ ({ row*10000 + cnt++, row, type, error }) }); else by_module[ file ] = ({ ({ row*10000 + cnt++, row, type, error }) }); } } string da_string = ""; int header_added; foreach( sort((array)by_module), [string module, array errors] ) { array res = ({ }); int remove_suspicious = 0; sort( errors ); foreach( errors, array e ) { if( e[2] == "Error" ) { remove_suspicious = 1; switch( e[3] ) { case "Must return a value for a non-void function.": case "Class definition failed.": case "Illegal program pointer.": case "Illegal program identifier": continue; } } res += ({ e }); } if( sizeof( res ) ) { string he( string what ) { if( what == "Error" )
ab05fb2000-08-23Per Hedbor  return "<font color='&usr.warncolor;'>"+what+"</font>";
1577242000-08-19Per Hedbor  return what; }; string hc( string what ) { return what; }; string trim_name( string what ) { array q = (what / "/"); return q[sizeof(q)-2..]*"/"; }; #define RELOAD(X) sprintf("<gbutton " \ "href='add_module.pike?config=&form.config:http;" \
7efa4d2000-08-20Per Hedbor  "&random=%d&only=%s&reload_module_list=yes#" \
1577242000-08-19Per Hedbor  "errors_and_warnings'> %s </gbutton>", \ random(4711111), \
7efa4d2000-08-20Per Hedbor  (X), \
1577242000-08-19Per Hedbor  LOCALE(253, "Reload")) if( !header_added++ ) da_string += "<p><a name='errors_and_warnings'><br />"
cc75f52000-10-21Martin Nilsson  "<font size='+2'><b><font color='&usr.warncolor;'>"
1577242000-08-19Per Hedbor  "Compile errors and warnings</font></b><br />" "<table width=100% cellpadding='3' cellspacing='0' border='0'>"; da_string += "<tr><td></td>"
cc75f52000-10-21Martin Nilsson  "<td colspan='3' bgcolor='&usr.content-titlebg;'>"
1577242000-08-19Per Hedbor  + "<b><font color='&usr.content-titlefg;' size='+1'>" + module_name_from_file(module)+"</font></b></td>" + "<td align='right' bgcolor='&usr.content-titlebg;'>" "<font color='&usr.content-titlefg;' size='+1'>" + trim_name(module) + "</font>&nbsp;"+RELOAD(module)+"</td><td></td></tr>"; foreach( res, array e ) da_string +=
99710c2000-12-18Martin Nilsson  "<tr valign='top'><td></td><td><img src='/internal-roxen-unit' width='30' height='1' alt='' />"
cc75f52000-10-21Martin Nilsson  "</td><td align='right'>" "<tt>"+e[1]+":</tt></td><td align='right'><tt>"+
1577242000-08-19Per Hedbor  he(e[2])+":</tt></td><td><tt>"+hc(e[3])+"</tt></td></tr>\n";
cc75f52000-10-21Martin Nilsson  da_string += "<tr valign='top'><td colspan='5'>&nbsp;</td><td></td></tr>\n";
1577242000-08-19Per Hedbor  } } if( strlen( da_string ) ) da_string += "</table>"; // "<pre>"+Roxen.html_encode_string( sprintf( "%O", by_module ) )+"</pre>"; return da_string; }
ab9b6d2000-02-11Per Hedbor array(string) get_module_list( function describe_module, function class_visible, RequestID id )
f26aee2000-01-31Per Hedbor { object conf = roxen.find_configuration( id->variables->config ); object ec = roxenloader.LowErrorContainer();
f150252000-04-04Per Hedbor  int do_reload;
f26aee2000-01-31Per Hedbor  master()->set_inhibit_compile_errors( ec );
f150252000-04-04Per Hedbor  if( id->variables->reload_module_list ) roxen->clear_all_modules_cache();
f599d92000-09-03Per Hedbor  array(ModuleInfo) mods;
f26aee2000-01-31Per Hedbor  roxenloader.push_compile_error_handler( ec ); mods = roxen->all_modules(); roxenloader.pop_compile_error_handler();
f599d92000-09-03Per Hedbor  foreach( mods, ModuleInfo m ) if( module_nomore( m->sname, m, conf ) ) mods -= ({ m });
ab9b6d2000-02-11Per Hedbor 
f599d92000-09-03Per Hedbor  string res = "";
f26aee2000-01-31Per Hedbor  string doubles="", already="";
ab9b6d2000-02-11Per Hedbor  array w = map(mods, module_class, id);
ad28082000-11-18Martin Nilsson  mapping classes = ([]);
ab9b6d2000-02-11Per Hedbor  sort(w,mods); for(int i=0; i<sizeof(w); i++)
f26aee2000-01-31Per Hedbor  {
ab9b6d2000-02-11Per Hedbor  mixed r = w[i]; if(!classes[r[0]]) classes[r[0]] = ([ "doc":r[1], "modules":({}) ]);
4d32e52001-07-31Per Hedbor  if( mods[i]->get_description() ) classes[r[0]]->modules += ({ mods[i] });
ab9b6d2000-02-11Per Hedbor  } foreach( sort(indices(classes)), string c ) { mixed r;
d39c492000-03-28Per Hedbor  if( c == "" ) continue;
ab9b6d2000-02-11Per Hedbor  if( (r = class_visible( c, classes[c]->doc, id )) && r[0] ) { res += r[1];
1577242000-08-19Per Hedbor  array m = classes[c]->modules; array q = m->get_name(); sort( q, m ); foreach(m, object q)
ab9b6d2000-02-11Per Hedbor  { if( q->get_description() == "Undocumented" && q->type == 0 ) continue; object b = module_nomore(q->sname, q, conf); res += describe_module( q, b ); } } else res += r[1];
f26aee2000-01-31Per Hedbor  }
5704c22000-02-02Per Hedbor  master()->set_inhibit_compile_errors( 0 );
1577242000-08-19Per Hedbor  return ({ res, pafeaw( ec->get(), ec->get_warnings() ) });
f26aee2000-01-31Per Hedbor } string module_image( int type ) { return ""; }
94ebf52001-03-04Per Hedbor  string strip_leading( LocaleString what )
f7bd0d2001-03-03Per Hedbor {
94ebf52001-03-04Per Hedbor  if( !what ) return 0;
8183cc2001-08-09Martin Stjernholm  sscanf( (string)what, "%*s:%*[ \t]%s", what );
f7bd0d2001-03-03Per Hedbor  return what; }
f26aee2000-01-31Per Hedbor  function describe_module_normal( int image ) { return lambda( object module, object block) { if(!block) { return sprintf( #"
9e4a012000-04-06Per Hedbor  <tr> <td colspan='2'> <table width='100%%'> <tr> <td><font size='+2'>%s</font></td>
8183cc2001-08-09Martin Stjernholm  <td align='right'>(%s) %s</td>
9e4a012000-04-06Per Hedbor  </tr> </table> </td> </tr> <tr> <td valign='top'> <form method='post' action='add_module.pike'> <input type='hidden' name='module_to_add' value='%s'> <input type='hidden' name='config' value='&form.config;'>
cc75f52000-10-21Martin Nilsson  <submit-gbutton preparse='1'>%s</submit-gbutton>
9e4a012000-04-06Per Hedbor  </form> </td>
cc75f52000-10-21Martin Nilsson  <td valign='top'>
9e4a012000-04-06Per Hedbor  %s <p> %s </p> </td> </tr>
f26aee2000-01-31Per Hedbor ",
f7bd0d2001-03-03Per Hedbor  Roxen.html_encode_string(strip_leading(module->get_name())),
8183cc2001-08-09Martin Stjernholm  Roxen.html_encode_string (module->sname),
f26aee2000-01-31Per Hedbor  (image?module_image(module->type):""), module->sname,
e3aab72000-07-25Andreas Lange  LOCALE(251, "Add Module"),
4d32e52001-07-31Per Hedbor  module->get_description(),
e3aab72000-07-25Andreas Lange  LOCALE(266, "Will be loaded from: ")+module->filename
f26aee2000-01-31Per Hedbor ); } else { if( block == module ) return "";
ab9b6d2000-02-11Per Hedbor  return "";
f26aee2000-01-31Per Hedbor  } }; }
c2b2722000-05-22Martin Nilsson array(int|string) class_visible_normal( string c, string d, RequestID id )
ab9b6d2000-02-11Per Hedbor {
0b04292000-07-23Martin Nilsson  int x;
9e4a012000-04-06Per Hedbor  string header = ("<tr><td colspan='2'><table width='100%' " "cellspacing='0' border='0' cellpadding='3' "
0b04292000-07-23Martin Nilsson  "bgcolor='&usr.content-titlebg;'><tr><td>"); if( id->variables->unfolded == c ) {
86e5a42001-08-28Per Hedbor  header+=("<a name="+Roxen.http_encode_string(c)+ "></a><gbutton "
10745b2001-01-29Per Hedbor  "href='add_module.pike?config=&form.config;" "#"+Roxen.http_encode_string(c)+"' > "+
6150972001-01-29Per Hedbor  LOCALE(168, "Hide")+" </gbutton>");
0b04292000-07-23Martin Nilsson  x=1; } else
86e5a42001-08-28Per Hedbor  header+=("<a name="+Roxen.http_encode_string(c)+ "></a><gbutton "
0b04292000-07-23Martin Nilsson  "href='add_module.pike?config=&form.config;" "&unfolded="+Roxen.http_encode_string(c)+ "#"+Roxen.http_encode_string(c)+"' > "+
e3aab72000-07-25Andreas Lange  LOCALE(267, "View")+" </gbutton>");
0b04292000-07-23Martin Nilsson  header+=("</td><td width='100%'>" "<font color='&usr.content-titlefg;' size='+2'>"+c+"</font>" "<br />"+d+"</td></tr></table></td></tr>\n"); return ({ x, header });
ab9b6d2000-02-11Per Hedbor }
f26aee2000-01-31Per Hedbor string page_normal( RequestID id, int|void noimage ) {
ab9b6d2000-02-11Per Hedbor  string content = ""; content += "<table>";
f26aee2000-01-31Per Hedbor  string desc, err;
ab9b6d2000-02-11Per Hedbor  [desc,err] = get_module_list( describe_module_normal(!noimage), class_visible_normal, id );
1577242000-08-19Per Hedbor  content += (desc+"</table>"+err);
f26aee2000-01-31Per Hedbor  return page_base( id, content ); } string page_fast( RequestID id ) { return page_normal( id, 1 ); }
5876e82000-04-01Martin Bähr string describe_module_faster( object module, object block) { if(!block) { return sprintf( #"
8183cc2001-08-09Martin Stjernholm  <tr><td colspan='2'><table width='100%%'> <td><font size='+2'>%s</font></td> <td align='right'>(%s) %s</td></table></td></tr>
0b04292000-07-23Martin Nilsson  <tr><td valign='top'><select multiple='multiple' name='module_to_add'>
5876e82000-04-01Martin Bähr  <option value='%s'>%s</option></select>
9e4a012000-04-06Per Hedbor  </td><td valign='top'>%s<p>%s</p></td>
5876e82000-04-01Martin Bähr  </tr> ",
f7bd0d2001-03-03Per Hedbor  Roxen.html_encode_string(strip_leading(module->get_name())),
8183cc2001-08-09Martin Stjernholm  Roxen.html_encode_string (module->sname),
5876e82000-04-01Martin Bähr  module_image(module->type), module->sname,
f7bd0d2001-03-03Per Hedbor  Roxen.html_encode_string(strip_leading(module->get_name())),
5876e82000-04-01Martin Bähr  module->get_description(),
e3aab72000-07-25Andreas Lange  LOCALE(266, "Will be loaded from: ")+module->filename
5876e82000-04-01Martin Bähr  ); } else { if( block == module ) return ""; return ""; } }
c2b2722000-05-22Martin Nilsson array(int|string) class_visible_faster( string c, string d, RequestID id )
5876e82000-04-01Martin Bähr {
0b04292000-07-23Martin Nilsson  int x;
9e4a012000-04-06Per Hedbor  string header = ("<tr><td colspan='2'><table width='100%' cellspacing='0' " "border='0' cellpadding='3' bgcolor='&usr.content-titlebg;'>"
0b04292000-07-23Martin Nilsson  "<tr><td>"); if( id->variables->unfolded == c ) { header+=("<a name="+Roxen.http_encode_string(c)+
cc75f52000-10-21Martin Nilsson  "></a><gbutton dim='1'> "+LOCALE(267, "View")+" </gbutton>"
e3aab72000-07-25Andreas Lange  "<tr><td><submit-gbutton> "+LOCALE(251, "Add Module")+
0b04292000-07-23Martin Nilsson  " </submit-gbutton></td></tr>"); x=1; } else
86e5a42001-08-28Per Hedbor  header+=("<a name="+Roxen.http_encode_string(c)+ "></a><gbutton "
0b04292000-07-23Martin Nilsson  "href='add_module.pike?config=&form.config;" "&unfolded="+Roxen.http_encode_string(c)+ "#"+Roxen.http_encode_string(c)+"' > "+
e3aab72000-07-25Andreas Lange  LOCALE(267, "View")+" </gbutton>");
0b04292000-07-23Martin Nilsson  header+=("</td><td width='100%'>" "<font color='&usr.content-titlefg;' size='+2'>"+c+"</font>" "<br />"+d+"</td></tr></table></td></tr>\n"); return ({ x, header });
5876e82000-04-01Martin Bähr } string page_faster( RequestID id ) { string content = "";
9e4a012000-04-06Per Hedbor  content += "<form method='post' action='add_module.pike'>" "<input type='hidden' name='config' value='&form.config;'>"
5876e82000-04-01Martin Bähr  "<table>"; string desc, err; [desc,err] = get_module_list( describe_module_faster, class_visible_faster, id );
1577242000-08-19Per Hedbor  content += (desc+"</table></form>"+err);
5876e82000-04-01Martin Bähr  return page_base( id, content ); }
ab9b6d2000-02-11Per Hedbor int first;
c2b2722000-05-22Martin Nilsson array(int|string) class_visible_compact( string c, string d, RequestID id )
ab9b6d2000-02-11Per Hedbor { string res=""; if(first++)
e3aab72000-07-25Andreas Lange  res = "</select><br /><submit-gbutton> "+LOCALE(251, "Add Module")+" </submit-gbutton> ";
86e5a42001-08-28Per Hedbor  res += "<p><a name="+Roxen.http_encode_string(c)+ "></a><font size='+2'>"+c+"</font><br />"+d+"<p><select multiple name='module_to_add'>";
ab9b6d2000-02-11Per Hedbor  return ({ 1, res }); } string describe_module_compact( object module, object block ) {
8183cc2001-08-09Martin Stjernholm  if(!block) { string modname = strip_leading (module->get_name()); return "<option value='"+module->sname+"'>"+ Roxen.html_encode_string( modname + "\0240" * max (0, (int) ((40 - sizeof (modname)) * 1.4)) + " (" + module->sname + ")")+ "</option>\n"; }
59d5e62000-02-23Martin Nilsson  return "";
ab9b6d2000-02-11Per Hedbor }
f26aee2000-01-31Per Hedbor string page_compact( RequestID id ) {
ab9b6d2000-02-11Per Hedbor  first=0; string desc, err; [desc,err] = get_module_list( describe_module_compact, class_visible_compact, id ); return page_base(id,
9e4a012000-04-06Per Hedbor  "<form action='add_module.pike' method='POST'>" "<input type='hidden' name='config' value='&form.config;'>"+ desc+"</select><br /><submit-gbutton> "
1577242000-08-19Per Hedbor  +LOCALE(251, "Add Module")+" </submit-gbutton><p>" +err+"</form>",
ab9b6d2000-02-11Per Hedbor  );
f26aee2000-01-31Per Hedbor }
17041f2000-03-01Martin Nilsson string page_really_compact( RequestID id ) { first=0; object conf = roxen.find_configuration( id->variables->config ); object ec = roxenloader.LowErrorContainer(); master()->set_inhibit_compile_errors( ec );
958ad82000-08-15Martin Stjernholm  if( id->variables->reload_module_list )
7efa4d2000-08-20Per Hedbor  { if( id->variables->only ) { master()->clear_compilation_failures(); m_delete( roxen->modules, (((id->variables->only/"/")[-1])/".")[0] ); roxen->all_modules_cache = 0; } else roxen->clear_all_modules_cache(); }
958ad82000-08-15Martin Stjernholm 
17041f2000-03-01Martin Nilsson  array mods; roxenloader.push_compile_error_handler( ec ); mods = roxen->all_modules(); roxenloader.pop_compile_error_handler();
8a4cef2001-04-10Martin Nilsson  sort(map(mods->get_name(), lambda(LocaleString in) { in = lower_case((string)in); sscanf(in, "%*s: %s", in); return in;
979e802000-11-26Martin Nilsson  }), mods);
17041f2000-03-01Martin Nilsson  string res = ""; mixed r;
e3aab72000-07-25Andreas Lange  if( (r = class_visible_compact( LOCALE(258,"Add module"), LOCALE(273,"Select one or several modules to add.") , id )) && r[0] ) {
17041f2000-03-01Martin Nilsson  res += r[1]; foreach(mods, object q) {
4d32e52001-07-31Per Hedbor  if( (!q->get_description() || (q->get_description() == "Undocumented")) &&
17041f2000-03-01Martin Nilsson  q->type == 0 ) continue; object b = module_nomore(q->sname, q, conf); res += describe_module_compact( q, b ); } } else res += r[1]; master()->set_inhibit_compile_errors( 0 ); return page_base(id, "<form action=\"add_module.pike\" method=\"post\">" "<input type=\"hidden\" name=\"config\" value=\"&form.config;\" />"+
ad28082000-11-18Martin Nilsson  res+"</select><br /><submit-gbutton> "
1577242000-08-19Per Hedbor  +LOCALE(251, "Add Module")+" </submit-gbutton><br />" +pafeaw(ec->get(),ec->get_warnings())+"</form>",
17041f2000-03-01Martin Nilsson  ); }
9ba17a2000-03-24Per Hedbor string decode_site_name( string what ) { if( (int)what ) return (string)((array(int))(what/","-({""}))); return what; }
f26aee2000-01-31Per Hedbor 
2e07c32000-03-09Martin Stjernholm 
f599d92000-09-03Per Hedbor array initial_form( RequestID id, Configuration conf, array modules ) {
10745b2001-01-29Per Hedbor  id->variables->initial = "1"; id->real_variables->initial = ({ "1" });
f599d92000-09-03Per Hedbor  string res = ""; int num;
10745b2001-01-29Per Hedbor 
f599d92000-09-03Per Hedbor  foreach( modules, string mod )
1577242000-08-19Per Hedbor  {
f599d92000-09-03Per Hedbor  ModuleInfo mi = roxen.find_module( (mod/"!")[0] ); RoxenModule moo = conf->find_module( replace(mod,"!","#") ); foreach( indices(moo->query()), string v )
1577242000-08-19Per Hedbor  {
f599d92000-09-03Per Hedbor  if( moo->getvar( v )->get_flags() & VAR_INITIAL ) { num++; res += "<tr><td colspan='3'><h2>"
c183182000-09-09Andreas Lange  +LOCALE(1,"Initial variables for ")+
f7bd0d2001-03-03Per Hedbor  Roxen.html_encode_string(strip_leading(mi->get_name())) +"</h2></td></tr>"
d672ca2001-01-29Per Hedbor  "<emit source='module-variables' " " configuration=\""+conf->name+"\"" " module=\""+mod+#"\"/> <emit noset='1' source='module-variables' " " configuration=\""+conf->name+"\""
f599d92000-09-03Per Hedbor  " module=\""+mod+#"\">
d672ca2001-01-29Per Hedbor  <tr> <td width='150' valign='top' colspan='2'><b>&_.name;</b></td> <td valign='top'><eval>&_.form:none;</eval></td></tr> <tr> <td width='30'><img src='/internal-roxen-unit' width=50 height=1 alt='' /></td> <td colspan=2>&_.doc:none;</td></tr>
f599d92000-09-03Per Hedbor </emit>"; break; }
a38da12000-08-20Per Hedbor  }
c2b2722000-05-22Martin Nilsson  }
f599d92000-09-03Per Hedbor  return ({res,num}); }
f26aee2000-01-31Per Hedbor 
10745b2001-01-29Per Hedbor mapping already_added = ([]);
f599d92000-09-03Per Hedbor mixed do_it_pass_2( array modules, Configuration conf, RequestID id ) { id->misc->do_not_goto = 1; foreach( modules, string mod )
a38da12000-08-20Per Hedbor  {
10745b2001-01-29Per Hedbor  if( already_added[mod] ) mod = already_added[ mod ];
f599d92000-09-03Per Hedbor  if( !has_value(mod, "!") || !conf->find_module( replace(mod,"!","#") ) )
a38da12000-08-20Per Hedbor  {
f599d92000-09-03Per Hedbor  RoxenModule mm = conf->enable_module( mod,0,0,1 );
eac60f2001-01-26Per Hedbor  if( !mm || !conf->otomod[mm] ) {
c96d642001-03-05Martin Nilsson  report_error(LOCALE(382,"Failed to enable %s")+"\n");
eac60f2001-01-26Per Hedbor  return Roxen.http_redirect( site_url(id,conf->name), id ); }
f599d92000-09-03Per Hedbor  conf->call_low_start_callbacks( mm, roxen.find_module( (mod/"!")[0] ), conf->modules[ mod ] );
10745b2001-01-29Per Hedbor  modules = replace( modules, mod, (already_added[mod]=(mod/"!")[0]+"!"+ (conf->otomod[mm]/"#")[-1]) );
a38da12000-08-20Per Hedbor  }
f599d92000-09-03Per Hedbor  remove_call_out( roxen.really_save_it );
a38da12000-08-20Per Hedbor  }
f599d92000-09-03Per Hedbor  [string cf_form, int num] = initial_form( id, conf, modules ); if( !num || id->variables["ok.x"] ) { // set initial variables from form variables... if( num ) Roxen.parse_rxml( cf_form, id ); foreach( modules, string mod ) conf->call_start_callbacks( conf->find_module( replace(mod,"!","#") ), roxen.find_module( (mod/"!")[0] ), conf->modules[ mod ] );
10745b2001-01-29Per Hedbor  already_added = ([ ]);
f599d92000-09-03Per Hedbor  conf->save( ); // save it all in one go
3aa8fd2001-12-19Anders Johansson  conf->forcibly_added = ([]);
2df9212001-10-08Per Hedbor  return Roxen.http_redirect( site_url(id,conf->name)+"-!-/"+modules[-1]+"/" , id);
f599d92000-09-03Per Hedbor  } return page_base(id,"<table>"+ map( modules, lambda( string q ) {
cc75f52000-10-21Martin Nilsson  return "<input type='hidden' "
f599d92000-09-03Per Hedbor  "name='module_to_add' " "value='"+q+"' />"; } )*"\n"
cc75f52000-10-21Martin Nilsson  +"<input type='hidden' name='config' "
10745b2001-01-29Per Hedbor  "value='"+conf->name+"' />"+cf_form+"</table><p><cf-ok />");
f599d92000-09-03Per Hedbor } mixed do_it( RequestID id ) { if( id->variables->encoded ) id->variables->config = decode_site_name( id->variables->config );
ea41952002-03-06Henrik Grubbström (Grubba)  Configuration conf; foreach(id->variables->config/"\0", string config) { if (conf = roxen.find_configuration( id->variables->config )) { id->variables->config = config; break; } }
f599d92000-09-03Per Hedbor  if( !conf->inited ) conf->enable_all_modules();
10745b2001-01-29Per Hedbor 
f599d92000-09-03Per Hedbor  array modules = (id->variables->module_to_add/"\0")-({""}); if( !sizeof( modules ) ) return Roxen.http_redirect( site_url(id,conf->name ), id ); return do_it_pass_2( modules, conf, id );
f26aee2000-01-31Per Hedbor } mixed parse( RequestID id ) { if( !config_perm( "Add Module" ) )
e3aab72000-07-25Andreas Lange  return LOCALE(226, "Permission denied");
f26aee2000-01-31Per Hedbor  if( id->variables->module_to_add ) return do_it( id );
ea41952002-03-06Henrik Grubbström (Grubba)  Configuration conf; foreach(id->variables->config/"\0", string config) { if (conf = roxen.find_configuration( id->variables->config )) { id->variables->config = config; break; } }
62e1bb2000-11-08Per Hedbor  if( !config_perm( "Site:"+conf->name ) ) return LOCALE(226,"Permission denied");
f150252000-04-04Per Hedbor  if( !conf->inited ) conf->enable_all_modules();
17041f2000-03-01Martin Nilsson  return this_object()["page_"+replace(config_setting( "addmodulemethod" )," ","_")]( id );
f26aee2000-01-31Per Hedbor }