Project

General

Profile

1 5129 cjones
/*
2
  *   '$RCSfile$'
3
  *     Purpose: Default javascript library for PARC project web pages
4
  *              Using this library rather than placing javascript directly in
5
  *              the PARC web documents allows us to globally change the
6
  *              functions of the entire site in one easy place.
7
  *   Copyright: 2000 Regents of the University of California and the
8
  *               National Center for Ecological Analysis and Synthesis
9
  *     Authors: Matt Jones, Christopher Jones
10
  *
11
  *    '$Author: leinfelder $'
12
  *      '$Date: 2008-06-17 14:16:32 -0600 (Tue, 17 Jun 2008) $'
13
  *  '$Revision: 4006 $'
14
  *
15
  * This program is free software; you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
17
  * the Free Software Foundation; either version 2 of the License, or
18
  * (at your option) any later version.
19
  *
20
  * This program is distributed in the hope that it will be useful,
21
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
  * GNU General Public License for more details.
24
  *
25
  * You should have received a copy of the GNU General Public License
26
  * along with this program; if not, write to the Free Software
27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
  */
29
30
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
31
 * * * * * *  CONFIGURATION SETTINGS - EDIT THESE FOR YOUR ENVIRONMENT * * * *
32
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
33
34
35
/* loginStatus: Uses XHR request to check for current session login status */
36
function loginStatus(servletPath, cgiPrefix){
37
    var httpRequest = false;
38
    try {
39
          httpRequest = new XMLHttpRequest();
40
    } catch (trymicrosoft) {
41
        try {
42
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
43
        } catch (othermicrosoft) {
44
            try {
45
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
46
            } catch (failed) {
47
                request = null;
48
            }
49
        }
50
    }
51
52
    if (!httpRequest){
53
        alert("no httpRequest object");
54
        return false;
55
    }
56
57
    httpRequest.onreadystatechange = function() {
58
        if(httpRequest.readyState == 4) {
59
            if (httpRequest.status == 200) {
60
                var response = httpRequest.responseText;
61
                var login_block = document.getElementById('login_block');
62
63
                if (response.indexOf("public") > 0) {
64
                    login_block.innerHTML = '<a href="' + cgiPrefix + '/register-dataset.cgi?cfg=parc&' +
65
                                            'stage=loginform">Login</a>';
66
                }
67
                else
68
                {
69
                    login_block.innerHTML = '<a href="' + cgiPrefix + '/register-dataset.cgi?cfg=parc&' +
70
                                            'stage=logout">Logout</a>';
71
                }
72
            }
73
        }
74
    }
75
76
    httpRequest.open("GET", servletPath + "?action=getloggedinuserinfo", true);
77
    httpRequest.send(null);
78
}