/*
js functions and code common to all pages
*/
/* define some global variables for this request */
global.page = new Object();
/* fill in some defaults */
global.page.title = "Samba Web Administration Tool";
/* to cope with browsers that don't support cookies we append the sessionid
to the URI */
global.SESSIONURI = "";
if (request['COOKIE_SUPPORT'] != "True") {
global.SESSIONURI="?SwatSessionId=" + request['SESSION_ID'];
}
/*
possibly adjust a local URI to have the session id appended
used for browsers that don't support cookies
*/
function session_uri(uri) {
return uri + global.SESSIONURI;
}
/* if the browser was too dumb to set the HOST header, then
set it now */
if (headers['HOST'] == undefined) {
headers['HOST'] = server['SERVER_HOST'] + ":" + server['SERVER_PORT'];
}
/*
show the page header. page types include "plain" and "column"
*/
function page_header(pagetype, title) {
global.page.pagetype = pagetype;
global.page.title = title;
include("/scripting/header_" + pagetype + ".esp");
}
/*
show the page footer, getting the page type from page.pagetype
set in page_header()
*/
function page_footer() {
include("/scripting/footer_" + global.page.pagetype + ".esp");
}
/*
check if a uri is one of the 'always allowed' pages, even when not logged in
This allows the login page to use the same style sheets and images
*/
function always_allowed(uri) {
var allowed = new Array("/images/favicon.ico",
"/images/linkpad.gif",
"/images/logo.png",
"/images/logo.gif",
"/style/main.css",
"/style/common.css");
for (i in allowed) {
if (allowed[i] == uri) {
return true;
}
}
return false;
}
/*
display a simple menu. First argument is menu title, followed by
pairs of menu item name and link
*/
function simple_menu() {
write("" + arguments[0] + "
\n");
}
/*
display a ejs object as a table
*/
function simple_table(v) {
write("\n");
for (r in v) {
write("" + r + " | " + v[r] + " |
\n");
}
write("
\n");
}
/*
display an array of objects, with the header for each element from the given
attribute
*/
function multi_table(array, header) {
write("\n");
for (i in array) {
var v = array[i];
write("" + v[header] + " |
\n");
for (r in v) {
if (r != header) {
write("" + r +
" | " + v[r] + " |
\n");
}
}
}
write("
\n");
}
/*
create a Form object with the defaults filled in, ready for display_form()
*/
function Form(name, num_elements, num_submits)
{
var f = new Object();
f.name = name;
f.element = new Array(num_elements);
f.submit = new Array(num_submits);
f.action = session_uri(request.REQUEST_URI);
f.class = "form";
for (i in f.element) {
f.element[i] = new Object();
f.element[i].type = "text";
f.element[i].value = "";
}
return f;
}
/*
display a simple form from a ejs Form object
caller should fill in
f.name = form name
f.action = action to be taken on submit (optional, defaults to current page)
f.class = css class (optional, defaults to 'form')
f.submit = an array of submit labels
f.element[i].label = element label
f.element[i].name = element name (defaults to label)
f.element[i].type = element type (defaults to text)
f.element[i].value = current value (optional, defaults to "")
*/
function display_form(f) {
write('\n");
}