1 |
fab7ff44
|
Bill Marquette
|
<?php
|
2 |
|
|
|
3 |
|
|
function getHeadJS() {
|
4 |
|
|
global $_SERVER, $HTTP_SERVER_VARS, $g, $use_loader_tab_gif;
|
5 |
|
|
|
6 |
|
|
if(!$use_loader_tab_gif)
|
7 |
|
|
$loader_gif = "/themes/{$g['theme']}/images/misc/loader.gif";
|
8 |
|
|
else
|
9 |
|
|
$loader_gif = "/themes/{$g['theme']}/images/misc/loader_tab.gif";
|
10 |
|
|
|
11 |
|
|
$headjs = "
|
12 |
|
|
var input_errors = '';
|
13 |
|
|
Event.observe(window, 'load', init, false);
|
14 |
|
|
";
|
15 |
|
|
$_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
|
16 |
|
|
|
17 |
|
|
$headjs .= "
|
18 |
|
|
{$noajax}
|
19 |
|
|
|
20 |
|
|
function init() {
|
21 |
|
|
if($('submit') && ! noAjaxOnSubmit) {
|
22 |
|
|
// debugging helper
|
23 |
|
|
//alert('adding observe event for submit button');
|
24 |
|
|
|
25 |
|
|
Event.observe(\"submit\", \"click\", submit_form, false);
|
26 |
|
|
$('submit').onclick = function() {return false;};
|
27 |
|
|
var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' \/><\/div>\";
|
28 |
|
|
new Insertion.Before('submit', to_insert);
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
function submit_form(e){
|
33 |
|
|
// debugging helper
|
34 |
|
|
//alert(Form.serialize($('iform')));
|
35 |
|
|
|
36 |
|
|
if($('inputerrors'))
|
37 |
859e12ed
|
Scott Ullrich
|
$('inputerrors').innerHTML = '<center><b><i>Loading...</i></b></center>';
|
38 |
fab7ff44
|
Bill Marquette
|
|
39 |
|
|
/* dsh: Introduced because pkg_edit tries to set some hidden fields
|
40 |
|
|
* if executing submit's onclick event. Tho click gets deleted
|
41 |
|
|
* by Ajax. Hence using onkeydown instead.
|
42 |
|
|
*/
|
43 |
|
|
if($('submit') && $('submit').onkeydown)
|
44 |
|
|
$('submit').onkeydown();
|
45 |
|
|
if($('submit'))
|
46 |
|
|
$('submit').style.visibility = 'hidden';
|
47 |
|
|
if($('cancelbutton'))
|
48 |
|
|
$('cancelbutton').style.visibility = 'hidden';
|
49 |
|
|
$('loading').style.visibility = 'visible';
|
50 |
|
|
// submit the form using Ajax
|
51 |
|
|
";
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
isset($HTTP_SERVER_VARS['AUTH_USER']) ? $scriptName = split("/", $_SERVER["SCRIPT_FILENAME"]) : $scriptName = split("/", "/index.php");
|
55 |
|
|
isset($HTTP_SERVER_VARS['AUTH_USER']) ? $loggedin = "var isLoggedIn = true;" : $loggedin = "var isLoggedIn = false;";
|
56 |
|
|
$scriptElms = count($scriptName);
|
57 |
|
|
$scriptName = $scriptName[$scriptElms-1];
|
58 |
0ab7198a
|
Scott Ullrich
|
$realScriptName = str_replace("/", "", $_SERVER["SCRIPT_NAME"]);
|
59 |
|
|
|
60 |
fab7ff44
|
Bill Marquette
|
$headjs .= "
|
61 |
|
|
{$loggedin}
|
62 |
|
|
|
63 |
|
|
if (! isLoggedIn) {
|
64 |
|
|
var newInput = document.createElement('input');
|
65 |
|
|
newInput.setAttribute('id', 'scriptname');
|
66 |
|
|
newInput.setAttribute('name', 'scriptname');
|
67 |
0ab7198a
|
Scott Ullrich
|
newInput.setAttribute('value', '{$realScriptName}');
|
68 |
fab7ff44
|
Bill Marquette
|
newInput.setAttribute('type', 'hidden');
|
69 |
|
|
|
70 |
|
|
$('iform').appendChild(newInput);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
new Ajax.Request('{$scriptName}', {
|
74 |
|
|
method : 'post',
|
75 |
|
|
parameters : Form.serialize($('iform')),
|
76 |
|
|
onSuccess : formSubmitted,
|
77 |
|
|
onFailure : formFailure
|
78 |
|
|
});
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
function formSubmitted(resp) {
|
82 |
|
|
var responseText = resp.responseText;
|
83 |
|
|
|
84 |
|
|
// debugging helper
|
85 |
be23be5a
|
Scott Ullrich
|
// alert(responseText);
|
86 |
fab7ff44
|
Bill Marquette
|
|
87 |
|
|
if(responseText.indexOf('html') > 0) {
|
88 |
|
|
/* somehow we have been fed an html page! */
|
89 |
|
|
//alert('Somehow we have been fed an html page! Forwarding to /.');
|
90 |
|
|
document.location.href = '/';
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
eval(responseText);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
/* this function will be called if an HTTP error will be triggered */
|
97 |
|
|
function formFailure(resp) {
|
98 |
950f0f9e
|
Scott Ullrich
|
showajaxmessage(resp.responseText);
|
99 |
|
|
if($('submit'))
|
100 |
|
|
$('submit').style.visibility = 'visible';
|
101 |
|
|
if($('cancelbutton'))
|
102 |
|
|
$('cancelbutton').style.visibility = 'visible';
|
103 |
|
|
if($('loading'))
|
104 |
|
|
$('loading').style.visibility = 'hidden';
|
105 |
|
|
|
106 |
fab7ff44
|
Bill Marquette
|
}
|
107 |
|
|
|
108 |
|
|
function showajaxmessage(message) {
|
109 |
|
|
var message_html;
|
110 |
|
|
|
111 |
|
|
if (message == '') {
|
112 |
|
|
NiftyCheck();
|
113 |
|
|
Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
|
114 |
|
|
Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
|
115 |
|
|
|
116 |
|
|
if($('submit'))
|
117 |
|
|
$('submit').style.visibility = 'visible';
|
118 |
|
|
if($('cancelbutton'))
|
119 |
|
|
$('cancelbutton').style.visibility = 'visible';
|
120 |
|
|
if($('loading'))
|
121 |
|
|
$('loading').style.visibility = 'hidden';
|
122 |
|
|
|
123 |
|
|
return;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
message_html = '<table height=\"32\" width=\"100%\"><tr><td>';
|
127 |
|
|
message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
|
128 |
|
|
message_html += '<table width=\"100%\"><tr><td width=\"8%\">';
|
129 |
859e12ed
|
Scott Ullrich
|
message_html += '<img style=\"vertical-align:center\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" \/>';
|
130 |
fab7ff44
|
Bill Marquette
|
message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
|
131 |
|
|
message_html += '<b>' + message + '<\/b><\/font><\/td>';
|
132 |
|
|
|
133 |
|
|
if(message.indexOf('apply') > 0) {
|
134 |
|
|
message_html += '<td>';
|
135 |
|
|
message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
|
136 |
|
|
message_html += '<\/td>';
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
|
140 |
|
|
$('inputerrors').innerHTML = message_html;
|
141 |
|
|
|
142 |
|
|
NiftyCheck();
|
143 |
|
|
Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
|
144 |
|
|
Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
|
145 |
|
|
|
146 |
|
|
if($('submit'))
|
147 |
|
|
$('submit').style.visibility = 'visible';
|
148 |
|
|
if($('cancelbutton'))
|
149 |
|
|
$('cancelbutton').style.visibility = 'visible';
|
150 |
|
|
if($('loading'))
|
151 |
|
|
$('loading').style.visibility = 'hidden';
|
152 |
|
|
if($('inputerrors'))
|
153 |
|
|
window.scrollTo(0, 0);
|
154 |
|
|
}
|
155 |
|
|
";
|
156 |
|
|
|
157 |
|
|
return $headjs;
|
158 |
|
|
}
|
159 |
|
|
|
160 |
950f0f9e
|
Scott Ullrich
|
?>
|