2 js functions and code common to all pages
5 /* define some global variables for this request */
6 global.page = new Object();
8 /* fill in some defaults */
9 global.page.title = "Samba Web Administration Tool";
11 /* to cope with browsers that don't support cookies we append the sessionid
13 global.SESSIONURI = "";
14 if (request['COOKIE_SUPPORT'] != "True") {
15 global.SESSIONURI="?SwatSessionId=" + request['SESSION_ID'];
19 possibly adjust a local URI to have the session id appended
20 used for browsers that don't support cookies
22 function session_uri(uri) {
23 return uri + global.SESSIONURI;
28 /* if the browser was too dumb to set the HOST header, then
30 if (headers['HOST'] == undefined) {
31 headers['HOST'] = server['SERVER_HOST'] + ":" + server['SERVER_PORT'];
35 show the page header. page types include "plain" and "column"
37 function page_header(pagetype, title) {
38 global.page.pagetype = pagetype;
39 global.page.title = title;
40 include("/scripting/header_" + pagetype + ".esp");
44 show the page footer, getting the page type from page.pagetype
47 function page_footer() {
48 include("/scripting/footer_" + global.page.pagetype + ".esp");
53 check if a uri is one of the 'always allowed' pages, even when not logged in
54 This allows the login page to use the same style sheets and images
56 function always_allowed(uri) {
57 var allowed = new Array("/images/favicon.ico",
58 "/images/linkpad.gif",
64 if (allowed[i] == uri) {
72 create a menu object with the defaults filled in, ready for display_menu()
74 function MenuObj(name, num_elements)
80 o.orientation = "vertical"
81 o.element = new Array(num_elements);
82 for (i in o.element) {
83 o.element[i] = new Object();
89 display a menu object. Currently only the "simple", "vertical" menu style
92 function display_menu(m) {
93 assert(m.style == "simple" && m.orientation == "vertical");
94 write('<div class="' + m.class + '">\n');
95 write("<i>" + m.name + "</i><br /><ul>\n");
96 for (i = 0; i < m.element.length; i++) {
98 write("<li><a href=\"" + e.link + "\">" + e.label + "</a></li>\n");
100 write("</ul></div>\n");
103 function simple_menu() {
104 var m = MenuObj(arguments[0], (arguments.length-1)/2);
105 for (i=0;i<m.element.length;i++) {
106 m.element[i].label = arguments[1+(i*2)];
107 m.element[i].link = arguments[2+(i*2)];
113 display a table element
115 function table_element(i, o) {
116 write("<tr><td>" + i + "</td><td>");
117 if (typeof(o[i]) == "object") {
121 if (first == false) {
130 write("</td></tr>\n");
134 return the number of elements in an object
136 function elcount(o) {
145 display a ejs object as a table. The header is optional
147 function simple_table(v) {
148 if (elcount(v) == 0) {
151 write("<table class=\"data\">\n");
159 display an array of objects, with the header for each element from the given
162 function multi_table(array, header) {
163 if (elcount(v) == 0) {
166 write("<table class=\"data\">\n");
169 write('<tr><th colspan="2">' + v[header] + "</th></tr>\n");
180 create a Form object with the defaults filled in, ready for display_form()
182 function FormObj(name, num_elements, num_submits)
184 var f = new Object();
186 f.element = new Array(num_elements);
187 f.submit = new Array(num_submits);
188 f.action = session_uri(request.REQUEST_URI);
189 f.class = "defaultform";
190 for (i in f.element) {
191 f.element[i] = new Object();
192 f.element[i].type = "text";
193 f.element[i].value = "";
199 display a simple form from a ejs Form object
200 caller should fill in
202 f.action = action to be taken on submit (optional, defaults to current page)
203 f.class = css class (optional, defaults to 'form')
204 f.submit = an array of submit labels
205 f.element[i].label = element label
206 f.element[i].name = element name (defaults to label)
207 f.element[i].type = element type (defaults to text)
208 f.element[i].value = current value (optional, defaults to "")
210 function display_form(f) {
211 write('<form name="' + f.name +
212 '" method="post" action="' + f.action +
213 '" class="' + f.class + '">\n');
214 if (f.element.length > 0) {
217 for (i in f.element) {
218 var e = f.element[i];
219 if (e.name == undefined) {
222 if (e.value == undefined) {
226 write("<td>" + e.label + "</td>");
227 if (e.type == "select") {
228 write('<td><select name="' + e.name + '">\n');
230 if (e.value == e.list[s]) {
231 write('<option selected=selected>' + e.list[s] + '</option>\n');
233 write('<option>' + e.list[s] + '</option>\n');
236 write('</select></td>\n');
238 write('<td><input name="' + e.name + '" type="' +
239 e.type + '" value="' + e.value + '" /></td>\n');
243 if (f.element.length > 0) {
246 for (i in f.submit) {
247 write('<input name="submit" type="submit" value="' + f.submit[i] + '" />\n');