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;
27 like printf, but to the web page
31 write(vsprintf(arguments));
35 like writef with a <br>
39 write(vsprintf(arguments));
44 /* if the browser was too dumb to set the HOST header, then
46 if (headers['HOST'] == undefined) {
47 headers['HOST'] = server['SERVER_HOST'] + ":" + server['SERVER_PORT'];
51 show the page header. page types include "plain" and "column"
53 function page_header(pagetype, title) {
54 global.page.pagetype = pagetype;
55 global.page.title = title;
56 include("/scripting/header_" + pagetype + ".esp");
60 show the page footer, getting the page type from page.pagetype
63 function page_footer() {
64 include("/scripting/footer_" + global.page.pagetype + ".esp");
69 check if a uri is one of the 'always allowed' pages, even when not logged in
70 This allows the login page to use the same style sheets and images
72 function always_allowed(uri) {
73 var allowed = new Array("/images/favicon.ico",
74 "/images/linkpad.gif",
79 if (allowed[i] == uri) {
87 create a menu object with the defaults filled in, ready for display_menu()
89 function MenuObj(name, num_elements)
95 o.orientation = "vertical"
96 o.element = new Array(num_elements);
97 for (i in o.element) {
98 o.element[i] = new Object();
104 display a menu object. Currently only the "simple", "vertical" menu style
107 function display_menu(m) {
108 assert(m.style == "simple" && m.orientation == "vertical");
109 write('<div class="' + m.class + '">\n');
110 write("<i>" + m.name + "</i><br /><ul>\n");
111 for (i = 0; i < m.element.length; i++) {
112 var e = m.element[i];
113 write("<li><a href=\"" + e.link + "\">" + e.label + "</a></li>\n");
115 write("</ul></div>\n");
118 function simple_menu() {
119 var i, m = MenuObj(arguments[0], (arguments.length-1)/2);
120 for (i=0;i<m.element.length;i++) {
122 m.element[i].label = arguments[ndx+1];
123 m.element[i].link = arguments[ndx+2];
129 display a table element
131 function table_element(i, o) {
132 write("<tr><td>" + i + "</td><td>");
133 if (typeof(o[i]) == "object") {
137 if (first == false) {
146 write("</td></tr>\n");
150 display a ejs object as a table. The header is optional
152 function simple_table(v) {
156 write("<table class=\"data\">\n");
165 display an array of objects, with the header for each element from the given
168 function multi_table(array, header) {
170 write("<table class=\"data\">\n");
171 for (i=0;i<array.length;i++) {
173 write('<tr><th colspan="2">' + v[header] + "</th></tr>\n");
184 create a Form object with the defaults filled in, ready for display_form()
186 function FormObj(name, num_elements, num_submits)
188 var f = new Object();
190 f.element = new Array(num_elements);
191 f.submit = new Array(num_submits);
192 f.action = session_uri(request.REQUEST_URI);
193 f.class = "defaultform";
194 for (i in f.element) {
195 f.element[i] = new Object();
196 f.element[i].type = "text";
197 f.element[i].value = "";
203 display a simple form from a ejs Form object
204 caller should fill in
206 f.action = action to be taken on submit (optional, defaults to current page)
207 f.class = css class (optional, defaults to 'form')
208 f.submit = an array of submit labels
209 f.element[i].label = element label
210 f.element[i].name = element name (defaults to label)
211 f.element[i].type = element type (defaults to text)
212 f.element[i].value = current value (optional, defaults to "")
214 function display_form(f) {
216 write('<form name="' + f.name +
217 '" method="post" action="' + f.action +
218 '" class="' + f.class + '">\n');
219 if (f.element.length > 0) {
222 for (i in f.element) {
223 var e = f.element[i];
224 if (e.name == undefined) {
227 if (e.value == undefined) {
230 if (strlen(e.value) > size) {
231 size = strlen(e.value) + 4;
234 for (i in f.element) {
235 var e = f.element[i];
237 write("<td>" + e.label + "</td>");
238 if (e.type == "select") {
239 write('<td><select name="' + e.name + '">\n');
241 if (e.value == e.list[s]) {
242 write('<option selected=selected>' + e.list[s] + '</option>\n');
244 write('<option>' + e.list[s] + '</option>\n');
247 write('</select></td>\n');
250 if (e.type == "text" || e.type == "password") {
251 sizestr = sprintf('size="%d"', size);
253 writef('<td><input name="%s" type="%s" value="%s" %s /></td>\n',
254 e.name, e.type, e.value, sizestr);
258 if (f.element.length > 0) {
261 for (i in f.submit) {
262 write('<input name="submit" type="submit" value="' + f.submit[i] + '" />\n');