NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/KeepSessionAlive/KeepSessionAlive.widget.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * KeepSessionAlive Widget Class
4  *
5  * @project     IOOS
6  * @revision    $Id: KeepSessionAlive.widget.php,v 1.9 2005/01/11 12:32:19 pspencer Exp $
7  * @purpose     Display a dialog box to type in coordinates to zoom to
8  * @author      DM Solutions Group (spencer@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2002, DM Solutions Group Inc.</b>
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29  
30 /*
31  * This widget is an invisible widget that needs to be placed somewhere
32  * inside the body of the page.  It represents itself as an invisible
33  * 1x1 pixel image.  The widget refreshes the contents of the pixel
34  * on a regular (configurable) basis in order to keep the associated
35  * PHP session alive.
36  */
37
38
39 include_once(dirname(__FILE__)."/../Widget.php");
40
41 /**
42  * KeepSessionAlive
43  *
44  * @desc Keep the current session alive
45  */
46 class KeepSessionAlive extends CWCWidget
47 {
48     var $mnTimeout;
49
50     /**
51      * KeepSessionAlive
52      *
53      * Constctor method for the KeepSessionAlive
54      */
55     function KeepSessionAlive()
56     {
57         parent::CWCWidget();
58
59         $this->maAttributes['TIMEOUT'] = new IntegerAttribute( 'TIMEOUT', false, 0, 1800 );
60
61         // set the description for this widget
62         $this->szWidgetDescription = <<<EOT
63 Allows the current session to be active.
64 EOT;
65
66         $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
67     }
68
69     function InitDefaults()
70     {
71         parent::InitDefaults();
72         if (isset($this->maParams['TIMEOUT']))
73         {
74             $nSeconds = $this->maParams['TIMEOUT'];
75         }
76         else
77             $nSeconds = 60 * 10;
78         
79         $this->mnTimeout = 1000 $nSeconds;
80     }
81
82     function GetJavascriptOnLoadFunctions()
83     {
84         $aReturn = array();
85         
86         $aReturn['Timeout'.$this->mnId] = 'window.setTimeout( "KeepSessionAlive_'.$this->mnId.'()", '. $this->mnTimeout .');'."\n" ;
87     
88         return $aReturn;
89     }
90
91     /**
92      * GetJavascriptFunctions
93      *
94      * Build and return the array of functions needed in the
95      * widget.
96      */
97     function GetJavascriptFunctions()
98     {
99         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
100           $bCWCJSAPI = 1;
101         else
102           $bCWCJSAPI = 0;
103
104         $szImageName = 'KeepSessionAliveImage_'.$this->mnId;
105         $nTimeout = $this->mnTimeout;
106         $szURL = $_SESSION['gszCoreWebPath'].'/widgets/KeepSessionAlive/KeepSessionAlive.php?'.SID;
107         $szJsFunctionName = 'KeepSessionAlive_'.$this->mnId;
108         $szFunction = <<<EOT
109 /**
110  * {$szJsFunctionName}
111  * refresh hidden image to prevent session timeouts
112  */
113 function {$szJsFunctionName}()
114 {
115     //copy of cwc_dhtml.js to keep lightweight
116     var CWCIsNav4 = (document.layers) ? 1:0;
117     var CWCIsIE = (document.all) ? 1:0;
118     var CWCIsNav6 = (document.getElementById && !document.all) ? 1:0;var obj = null;
119     var szImage = "{$szImageName}";
120     if (CWCIsNav4) //Netscape 4.x
121     {
122         obj = document.images[szImage];
123     }
124     else
125     {
126         obj = document.getElementById(szImage);
127     }
128     if (obj != null)
129     {
130         obj.src = "{$szURL}" + "&rand=" + Math.random();
131     }
132     window.status = "last update: " + Date();
133     window.setTimeout( "{$szJsFunctionName}()", {$nTimeout} );
134     return true;
135 }
136 EOT;
137         $aReturn[$szJsFunctionName] = $szFunction;
138
139         return $aReturn;
140     }
141
142     /**
143      * DrawPublish
144      *
145      * Return the HTML code using the name in the map file and the
146      * parameters of the CWC tag.
147      */
148     function DrawPublish()
149     {
150         $szResult = '<img name="KeepSessionAliveImage_'.$this->mnId.'" id="KeepSessionAliveImage_'.$this->mnId.'" src="'.$_SESSION['gszCoreWebPath'].'/widgets/KeepSessionAlive/KeepSessionAlive.php?'.SID.'" border="0" width="1" height="1">';
151         return $szResult;
152     }
153 }
154 ?>
155
Note: See TracBrowser for help on using the browser.