dd2f1d1999-11-17Per Hedbor #include <config.h> #include <roxen.h>
cf2dec2000-07-11Martin Nilsson 
23414a2000-07-21Andreas Lange //<locale-token project="roxen_config">LOCALE</locale-token> #define LOCALE(X,Y) _STR_LOCALE("roxen_config",X,Y) #define CALL(X,Y) _LOCALE_FUN("roxen_config",X,Y)
cf2dec2000-07-11Martin Nilsson 
dd2f1d1999-11-17Per Hedbor int __lt; string describe_time(int t) { int full; if(localtime(__lt)->yday != localtime(t)->yday) { __lt = t; full=1; } if(full)
b9a7022000-07-15Andreas Lange  return capitalize(roxen->language(roxen.locale->get(),"date")(t));
dd2f1d1999-11-17Per Hedbor  else return sprintf("%02d:%02d",localtime(t)->hour,localtime(t)->min); }
3e3bab2001-01-19Per Hedbor string _units(string unit, int num) {
715d3c2000-07-11Martin Nilsson  if(num==1) return "one "+unit; return num+" "+unit+"s"; }
dd2f1d1999-11-17Per Hedbor string describe_interval(int i) {
715d3c2000-07-11Martin Nilsson  switch(i) { case 0..50:
1c783c2000-07-15Andreas Lange  return CALL("units", _units)("second", i);
715d3c2000-07-11Martin Nilsson  case 51..3560:
1c783c2000-07-15Andreas Lange  return CALL("units", _units)("minute", ((i+20)/60));
715d3c2000-07-11Martin Nilsson  default:
1c783c2000-07-15Andreas Lange  return CALL("units", _units)("hour", ((i+300)/3600));
dd2f1d1999-11-17Per Hedbor  } } string describe_times(array (int) times) { __lt=0; if(sizeof(times) < 6)
3e3bab2001-01-19Per Hedbor  return String.implode_nicely(map(times, describe_time), LOCALE("cw", "and"));
dd2f1d1999-11-17Per Hedbor  int d, every=1; int ot = times[0]; foreach(times[1..], int t) if(d) { if(abs(t-ot-d)>(d/4)) { every=0; break; } ot=t; } else d = t-ot; if(every && (times[-1]+d) >= time(1)-10)
23414a2000-07-21Andreas Lange  return (LOCALE(207, "every") +" " +describe_interval(d)+" "+LOCALE(208, "since")+" "+
dd2f1d1999-11-17Per Hedbor  describe_time(times[0])); return String.implode_nicely(map(times[..4], describe_time)+({"..."})+ map(times[sizeof(times)-3..], describe_time),
ea0a982000-07-17Andreas Lange  LOCALE("cw", "and"));
dd2f1d1999-11-17Per Hedbor } string fix_err(string s) { sscanf(reverse(s), "%*[ \t\n]%s", s); s=reverse(s); if(s=="") return s; if(!(<'.','!','?'>)[s[-1]]) s+=".";
715d3c2000-07-11Martin Nilsson  return Roxen.html_encode_string(capitalize(s));
dd2f1d1999-11-17Per Hedbor } int last_time;
c60cae2000-02-02Johan Sundström string describe_error(string err, array (int) times, string lang, int|void no_links)
dd2f1d1999-11-17Per Hedbor { int code, nt;
c60cae2000-02-02Johan Sundström  string links = "", reference, server;
23414a2000-07-21Andreas Lange  array(string) codetext=({ LOCALE(209, "Notice"), LOCALE(210, "Warning"), LOCALE(211, "Error") });
c60cae2000-02-02Johan Sundström 
dd2f1d1999-11-17Per Hedbor  if(sizeof(times)==1 && times[0]/60==last_time) nt=1; last_time=times[0]/60;
c60cae2000-02-02Johan Sundström  sscanf(err, "%d,%[^,],%s", code, reference, err); switch(no_links) { Configuration conf; RoxenModule module; case 2: sscanf(reference, "%[^/]", server); if(conf = roxen->find_configuration( server )) links += sprintf("<a href=\"%s\">%s</a> : ", @get_conf_url_to_virtual_server( conf, lang )); case 1: // find_configuration(configinterface)->query_name() == realname
715d3c2000-07-11Martin Nilsson  if(module = Roxen.get_module( reference ))
c60cae2000-02-02Johan Sundström  links += sprintf("<a href=\"%s\">%s</a> : ", @get_conf_url_to_module( module, lang )); }
ea99352003-04-30Anders Johansson  return "<table><tr><td valign=\"top\"><imgs src=&usr.err-"+code+"; \n"
2bf3362000-02-16Martin Nilsson  "alt=\"" + codetext[code-1] + "\" />" "</td><td>" + links + (nt?"":describe_times(times)+"<br />") + replace(fix_err(err), "\n", "<br />\n") + "</table>";
c60cae2000-02-02Johan Sundström } // Returns ({ URL to module config page, human-readable (full) module name })
3e3bab2001-01-19Per Hedbor array(string) get_conf_url_to_module(string|RoxenModule m, string|void lang) { // module is either a RoxenModule object or a string as returned by
c60cae2000-02-02Johan Sundström  // get_modname(some RoxenModule), eg "ConfigInterface/piketag#0"
715d3c2000-07-11Martin Nilsson  RoxenModule module = stringp(m) ? Roxen.get_module(m) : m;
c60cae2000-02-02Johan Sundström  Configuration conf = module->my_configuration(); string url_modname = replace(conf->otomod[module], "#", "!"), url_confname = conf->name;
9d477e2001-05-16Per Hedbor  return ({ sprintf("/sites/site.html/%s/-!-/%s/?section=Information", Roxen.http_encode_string(url_confname), Roxen.http_encode_string(url_modname)),
715d3c2000-07-11Martin Nilsson  Roxen.get_modfullname(module) });
c60cae2000-02-02Johan Sundström } // Returns ({ URL to virtual server config page, virtual server name })
3e3bab2001-01-19Per Hedbor array(string) get_conf_url_to_virtual_server(string|Configuration conf,
51bfad2000-04-04Johan Sundström  string|void lang)
3e3bab2001-01-19Per Hedbor { // conf is either a conf object or the configuration's real name, // eg "ConfigInterface"
c60cae2000-02-02Johan Sundström  string url_confname; if(stringp(conf)) conf = roxen->find_configuration(url_confname = conf); else url_confname = conf->name;
9d477e2001-05-16Per Hedbor  return ({ sprintf("/sites/site.html/%s/", Roxen.http_encode_string(url_confname)), conf->query_name() });
dd2f1d1999-11-17Per Hedbor }
9d477e2001-05-16Per Hedbor