Project

General

Profile

Download (5.99 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / headjs.php @ a1b66bec

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 $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
    jQuery(document).ready(init);
50
  ";
51
  if (!session_id())
52
	session_start();
53
  $_SESSION['NO_AJAX'] == "True" ? $noajax = "var noAjaxOnSubmit = true;" : $noajax = "var noAjaxOnSubmit = false;";
54
  session_commit();
55

    
56
  $headjs .= "
57
    {$noajax}
58

    
59
    function init() {
60
      if(jQuery('#submit') && ! noAjaxOnSubmit) {
61
        // debugging helper
62
        //alert('adding observe event for submit button');
63
        
64
        jQuery(\"#submit\").click(submit_form);
65
        jQuery('#submit').click(function() {return false;});
66
        var to_insert = \"<div style='visibility:hidden' id='loading' name='loading'><img src='{$loader_gif}' alt='loader' \/><\/div>\";
67
        jQuery('#submit').before(to_insert);
68
      }
69
    }
70
    
71
    function submit_form(e){
72
      // debugging helper
73
      //alert(Form.serialize($('iform')));
74

    
75
      if(jQuery('#inputerrors'))
76
        jQuery('#inputerrors').html('<center><b><i>Loading...<\/i><\/b><\/center>');
77
        
78
      /* dsh: Introduced because pkg_edit tries to set some hidden fields
79
       *      if executing submit's onclick event. The click gets deleted
80
       *      by Ajax. Hence using onkeydown instead.
81
       */
82
      if(jQuery('#submit').prop('keydown')) {
83
        jQuery('#submit').keydown();
84
        jQuery('#submit').css('visibility','hidden');
85
      }
86
      if(jQuery('#cancelbutton'))
87
        jQuery('#cancelbutton').css('visibility','hidden');
88
      jQuery('#loading').css('visibility','visible');
89
      // submit the form using Ajax
90
    }
91
   
92
    function formSubmitted(resp) {
93
      var responseText = resp.responseText;
94
      
95
      // debugging helper
96
      // alert(responseText);
97
      
98
      if(responseText.indexOf('html') > 0) {
99
        /* somehow we have been fed an html page! */
100
        //alert('Somehow we have been fed an html page! Forwarding to /.');
101
        document.location.href = '/';
102
      }
103
      
104
      eval(responseText);
105
    }
106
    
107
    /* this function will be called if an HTTP error will be triggered */
108
    function formFailure(resp) {
109
	    showajaxmessage(resp.responseText);
110
		if(jQuery('#submit'))
111
		  jQuery('#submit').css('visibility','visible');
112
		if(jQuery('#cancelbutton'))
113
		  jQuery('#cancelbutton').css('visibility','visible');
114
		if(jQuery('#loading'))
115
		  jQuery('#loading').css('visibility','hidden');
116

    
117
    }
118
    
119
    function showajaxmessage(message) {
120
      var message_html;
121

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

    
127
        if(jQuery('#submit'))
128
          jQuery('#submit').css('visibility','visible');
129
        if(jQuery('#cancelbutton'))
130
          jQuery('#cancelbutton').css('visibility','visible');
131
        if(jQuery('#loading'))
132
          jQuery('#loading').css('visibility','hidden');
133

    
134
        return;
135
      }
136

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

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

    
150
      message_html += '<\/tr><\/table><\/div><\/td><\/table><br \/>';
151
      jQuery('#inputerrors').html(message_html);
152

    
153
      NiftyCheck();
154
      Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");
155
      Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");
156

    
157
      if(jQuery('#submit'))
158
        jQuery('#submit').css('visibility','visible');
159
      if(jQuery('#cancelbutton'))
160
        jQuery('#cancelbutton').css('visibility','visible');
161
      if(jQuery('#loading'))
162
        jQuery('#loading').css('visibility','hidden');
163
      if(jQuery('#inputerrors'))
164
        window.scrollTo(0, 0);
165
    }
166
  ";
167

    
168
  return $headjs;
169
}
170

    
171
?>
(91-91/256)