Project

General

Profile

Download (5.8 KB) Statistics
| Branch: | Tag: | Revision:
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
require_once("guiconfig.inc");
38

    
39
function getHeadJS() {
40
  global $_SERVER, $HTTP_SERVER_VARS, $g, $use_loader_tab_gif;
41

    
42
  if(!$use_loader_tab_gif)
43
    $loader_gif = "/themes/{$g['theme']}/images/misc/loader.gif";
44
  else
45
    $loader_gif = "/themes/{$g['theme']}/images/misc/loader_tab.gif";
46

    
47
  $headjs = "
48
    var input_errors = '';
49
    Event.observe(window, 'load', init, false);
50
  ";
51
  $_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
52

    
53
  $headjs .= "
54
    {$noajax}
55

    
56
    function init() {
57
      if($('submit') && ! noAjaxOnSubmit) {
58
        // debugging helper
59
        //alert('adding observe event for submit button');
60
        
61
        Event.observe(\"submit\", \"click\", submit_form, false);
62
        $('submit').onclick = function() {return false;};
63
        var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' \/><\/div>\";
64
        new Insertion.Before('submit', to_insert);
65
      }
66
    }
67
    
68
    function submit_form(e){
69
      // debugging helper
70
      //alert(Form.serialize($('iform')));
71
      
72
      if($('inputerrors'))
73
        $('inputerrors').innerHTML = '<center><b><i>Loading...</i></b></center>';
74
        
75
      /* dsh: Introduced because pkg_edit tries to set some hidden fields
76
       *      if executing submit's onclick event. The click gets deleted
77
       *      by Ajax. Hence using onkeydown instead.
78
       */
79
      if($('submit') && $('submit').onkeydown)
80
        $('submit').onkeydown();
81
      if($('submit'))
82
        $('submit').style.visibility = 'hidden';
83
      if($('cancelbutton'))
84
        $('cancelbutton').style.visibility = 'hidden';
85
      $('loading').style.visibility = 'visible';
86
      // submit the form using Ajax
87
    }
88
   
89
    function formSubmitted(resp) {
90
      var responseText = resp.responseText;
91
      
92
      // debugging helper
93
      // alert(responseText);
94
      
95
      if(responseText.indexOf('html') > 0) {
96
        /* somehow we have been fed an html page! */
97
        //alert('Somehow we have been fed an html page! Forwarding to /.');
98
        document.location.href = '/';
99
      }
100
      
101
      eval(responseText);
102
    }
103
    
104
    /* this function will be called if an HTTP error will be triggered */
105
    function formFailure(resp) {
106
	    showajaxmessage(resp.responseText);
107
		if($('submit'))
108
		  $('submit').style.visibility = 'visible';
109
		if($('cancelbutton'))
110
		  $('cancelbutton').style.visibility = 'visible';
111
		if($('loading'))
112
		  $('loading').style.visibility = 'hidden';
113

    
114
    }
115
    
116
    function showajaxmessage(message) {
117
      var message_html;
118

    
119
      if (message == '') {
120
        NiftyCheck();
121
        Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
122
        Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
123

    
124
        if($('submit'))
125
          $('submit').style.visibility = 'visible';
126
        if($('cancelbutton'))
127
          $('cancelbutton').style.visibility = 'visible';
128
        if($('loading'))
129
          $('loading').style.visibility = 'hidden';
130

    
131
        return;
132
      }
133

    
134
      message_html = '<table height=\"32\" width=\"100%\"><tr><td>';
135
      message_html += '<div style=\"background-color:#990000\" id=\"redbox\">';
136
      message_html += '<table width=\"100%\"><tr><td width=\"8%\">';
137
      message_html += '<img style=\"vertical-align:center\" src=\"/themes/{$g['theme']}/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\" \/>';
138
      message_html += '<\/td><td width=\"70%\"><font color=\"white\">';
139
      message_html += '<b>' + message + '<\/b><\/font><\/td>';
140

    
141
      if(message.indexOf('apply') > 0) {
142
        message_html += '<td>';
143
        message_html += '<input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"" . gettext("Apply changes") . "\" \/>';
144
        message_html += '<\/td>';
145
      }
146

    
147
      message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
148
      $('inputerrors').innerHTML = message_html;
149

    
150
      NiftyCheck();
151
      Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
152
      Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
153

    
154
      if($('submit'))
155
        $('submit').style.visibility = 'visible';
156
      if($('cancelbutton'))
157
        $('cancelbutton').style.visibility = 'visible';
158
      if($('loading'))
159
        $('loading').style.visibility = 'hidden';
160
      if($('inputerrors'))
161
        window.scrollTo(0, 0);
162
    }
163
  ";
164

    
165
  return $headjs;
166
}
167

    
168
?>
(83-83/231)