1
|
<?php
|
2
|
/*
|
3
|
headjs.php
|
4
|
|
5
|
Redistribution and use in source and binary forms, with or without
|
6
|
modification, are permitted provided that the following conditions are met:
|
7
|
|
8
|
1. Redistributions of source code must retain the above copyright notice,
|
9
|
this list of conditions and the following disclaimer.
|
10
|
|
11
|
2. Redistributions in binary form must reproduce the above copyright
|
12
|
notice, this list of conditions and the following disclaimer in the
|
13
|
documentation and/or other materials provided with the distribution.
|
14
|
|
15
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
16
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
17
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
18
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
19
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
20
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
21
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
22
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
23
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
24
|
POSSIBILITY OF SUCH DAMAGE.
|
25
|
*/
|
26
|
/*
|
27
|
pfSense_MODULE: header
|
28
|
*/
|
29
|
|
30
|
##|+PRIV
|
31
|
##|*IDENT=page-requiredforjavascript
|
32
|
##|*NAME=Required for javascript page
|
33
|
##|*DESCR=Allow access to the 'Required for javascript' page.
|
34
|
##|*MATCH=headjs.php*
|
35
|
##|-PRIV
|
36
|
|
37
|
function getHeadJS() {
|
38
|
global $_SERVER, $HTTP_SERVER_VARS, $g, $use_loader_tab_gif;
|
39
|
|
40
|
if(!$use_loader_tab_gif)
|
41
|
$loader_gif = "/themes/{$g['theme']}/images/misc/loader.gif";
|
42
|
else
|
43
|
$loader_gif = "/themes/{$g['theme']}/images/misc/loader_tab.gif";
|
44
|
|
45
|
$headjs = "
|
46
|
var input_errors = '';
|
47
|
Event.observe(window, 'load', init, false);
|
48
|
";
|
49
|
$_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
|
50
|
|
51
|
$headjs .= "
|
52
|
{$noajax}
|
53
|
|
54
|
function init() {
|
55
|
if($('submit') && ! noAjaxOnSubmit) {
|
56
|
// debugging helper
|
57
|
//alert('adding observe event for submit button');
|
58
|
|
59
|
Event.observe(\"submit\", \"click\", submit_form, false);
|
60
|
$('submit').onclick = function() {return false;};
|
61
|
var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' \/><\/div>\";
|
62
|
new Insertion.Before('submit', to_insert);
|
63
|
}
|
64
|
}
|
65
|
|
66
|
function submit_form(e){
|
67
|
// debugging helper
|
68
|
//alert(Form.serialize($('iform')));
|
69
|
|
70
|
if($('inputerrors'))
|
71
|
$('inputerrors').innerHTML = '<center><b><i>Loading...</i></b></center>';
|
72
|
|
73
|
/* dsh: Introduced because pkg_edit tries to set some hidden fields
|
74
|
* if executing submit's onclick event. The click gets deleted
|
75
|
* by Ajax. Hence using onkeydown instead.
|
76
|
*/
|
77
|
if($('submit') && $('submit').onkeydown)
|
78
|
$('submit').onkeydown();
|
79
|
if($('submit'))
|
80
|
$('submit').style.visibility = 'hidden';
|
81
|
if($('cancelbutton'))
|
82
|
$('cancelbutton').style.visibility = 'hidden';
|
83
|
$('loading').style.visibility = 'visible';
|
84
|
// submit the form using Ajax
|
85
|
}
|
86
|
|
87
|
function formSubmitted(resp) {
|
88
|
var responseText = resp.responseText;
|
89
|
|
90
|
// debugging helper
|
91
|
// alert(responseText);
|
92
|
|
93
|
if(responseText.indexOf('html') > 0) {
|
94
|
/* somehow we have been fed an html page! */
|
95
|
//alert('Somehow we have been fed an html page! Forwarding to /.');
|
96
|
document.location.href = '/';
|
97
|
}
|
98
|
|
99
|
eval(responseText);
|
100
|
}
|
101
|
|
102
|
/* this function will be called if an HTTP error will be triggered */
|
103
|
function formFailure(resp) {
|
104
|
showajaxmessage(resp.responseText);
|
105
|
if($('submit'))
|
106
|
$('submit').style.visibility = 'visible';
|
107
|
if($('cancelbutton'))
|
108
|
$('cancelbutton').style.visibility = 'visible';
|
109
|
if($('loading'))
|
110
|
$('loading').style.visibility = 'hidden';
|
111
|
|
112
|
}
|
113
|
|
114
|
function showajaxmessage(message) {
|
115
|
var message_html;
|
116
|
|
117
|
if (message == '') {
|
118
|
NiftyCheck();
|
119
|
Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
|
120
|
Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
|
121
|
|
122
|
if($('submit'))
|
123
|
$('submit').style.visibility = 'visible';
|
124
|
if($('cancelbutton'))
|
125
|
$('cancelbutton').style.visibility = 'visible';
|
126
|
if($('loading'))
|
127
|
$('loading').style.visibility = 'hidden';
|
128
|
|
129
|
return;
|
130
|
}
|
131
|
|
132
|
message_html = '<table height=\"32\" width=\"100%\"><tr><td>';
|
133
|
message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
|
134
|
message_html += '<table width=\"100%\"><tr><td width=\"8%\">';
|
135
|
message_html += '<img style=\"vertical-align:center\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" \/>';
|
136
|
message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
|
137
|
message_html += '<b>' + message + '<\/b><\/font><\/td>';
|
138
|
|
139
|
if(message.indexOf('apply') > 0) {
|
140
|
message_html += '<td>';
|
141
|
message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
|
142
|
message_html += '<\/td>';
|
143
|
}
|
144
|
|
145
|
message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
|
146
|
$('inputerrors').innerHTML = message_html;
|
147
|
|
148
|
NiftyCheck();
|
149
|
Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
|
150
|
Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
|
151
|
|
152
|
if($('submit'))
|
153
|
$('submit').style.visibility = 'visible';
|
154
|
if($('cancelbutton'))
|
155
|
$('cancelbutton').style.visibility = 'visible';
|
156
|
if($('loading'))
|
157
|
$('loading').style.visibility = 'hidden';
|
158
|
if($('inputerrors'))
|
159
|
window.scrollTo(0, 0);
|
160
|
}
|
161
|
";
|
162
|
|
163
|
return $headjs;
|
164
|
}
|
165
|
|
166
|
?>
|