Code

Updated size rendering for partitions
[gosa.git] / gosa-core / include / class_session.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class session {
25     public static function get_session_size()
26     {
28     }
30     public static function get_element_size()
31     {
33     }
35     public static function add_channel($name)
36     {
37         /* If there's already such kind of channel, skip... */
38         if (isset($_SESSION[$name])){
39             return (FALSE);
40         }
42         /* Allocate it... */
43         $_SESSION[$name]= array();
44         $_POST["_channel_"]= $name;
45         return (TRUE);
46     }
48     public static function remove_channel($name)
49     {
50         /* If there's already such kind of channel, skip... */
51         if (isset($_SESSION[$name])){
52             unset($_SESSION[$name]);
53             if (isset($_POST["_channel_"])){
54                 unset($_POST["_channel_"]);
55             }
56             return (TRUE);
57         }
59         return (FALSE);
60     }
62     public static function is_set($name)
63     {
64         $channel= "";
65         if (isset($_POST['_channel_'])){
66             $channel= $_POST['_channel_'];
67         }
69         /* Global fallback if not set */
70         if ($channel == ""){
71             return(isset($_SESSION[$name]));
72         }
74         /* Sanity check */
75         if (!session::channel_exists($channel)){
76             msg_dialog::display(_("Internal error"), _("Requested channel does not exist!"), FATAL_ERROR_DIALOG);
77         }
79         $channel= "gch_".$channel;
80         return(isset($_SESSION[$channel][$name]));
81     }
83     public static function global_is_set($name)
84     {
85         return(isset($_SESSION[$name]));
86     }
88     public static function set($name,$value)
89     {
90         $channel= "";
91         if (isset($_POST['_channel_'])){
92             $channel= $_POST['_channel_'];
93         }
95         /* Global fallback if not set */
96         if ($channel == ""){
97             $_SESSION[$name] = $value;
98         } else {
99             /* Sanity check */
100             if (!session::channel_exists($channel)){
101                 msg_dialog::display(_("Internal error"), _("Requested channel does not exist!"), FATAL_ERROR_DIALOG);
102             }
103             $_SESSION[$channel][$name] = $value;
104         }
105     }
107     public static function global_set($name,$value)
108     {
109         $_SESSION[$name] = $value;
110     }
112     public static function &get($name)
113     {
114         $channel= "";
115         if (isset($_POST['_channel_'])){
116             $channel= $_POST['_channel_'];
117         }
119         /* Global fallback if not set */
120         if ($channel == ""){
121             $ret = &$_SESSION[$name];
122             return($ret);
123         }
125         /* Sanity check */
126         if (!session::channel_exists($channel)){
127             msg_dialog::display(_("Internal error"), _("Requested channel does not exist!"), FATAL_ERROR_DIALOG);
128         }
130         $channel= "gch_".$channel;
131         $ret = &$_SESSION[$channel][$name];
132         return($ret);
133     }
135     public static function &global_get($name)
136     {
137         $ret = &$_SESSION[$name];
138         return($ret);
139     }
141     public static function delete($name)
142     {
143         $channel= "";
144         if (isset($_POST['_channel_'])){
145             $channel= $_POST['_channel_'];
146         }
148         /* Global fallback if not set */
149         if ($channel == ""){
150             if(isset($_SESSION[$name])){
151                 unset($_SESSION[$name]);
152             }
153         } else {
154             if(isset($_SESSION[$channel][$name])){
155                 unset($_SESSION[$channel][$name]);
156             }
157         }
158     }
160     public static function global_delete($name)
161     {
162         if($_SESSION[$name]){
163             unset($_SESSION[$name]);
164         }
165     }
167     public static function un_set($name)
168     {
169         return(session::delete($name));
170     }
172     public static function global_un_set($name)
173     {
174         return(session::global_delete($name));
175     }
177     public static function start()
178     {
179         /* Set cookie lifetime to one day (The parameter is in seconds ) */
180         session_set_cookie_params(24*60*60);
182         /* Set cache limter to one day (parameter is minute !!)*/
183         session_cache_expire(60*24);  // default is 180
185         /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
186            !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from
187            the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
188         ini_set("session.gc_maxlifetime",24*60*60);
189         session_name("GOsa");
190         session_start();
192         /* Check for changed browsers and bail out */
193         if (isset($_SESSION['HTTP_USER_AGENT']))
194         {
195             if ($_SESSION['HTTP_USER_AGENT'] !=  md5($_SERVER['HTTP_USER_AGENT'])) {
196                 session_destroy();
197                 session_name("GOsa");
198                 session_start();
199             }
200         } else {
201             $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
202         }
204         /* Regenerate ID to increase security */
205         if (!isset($_SESSION['started'])){
206             session_regenerate_id();
207             $_SESSION['started'] = true;
208         }
209     }
211     public static function destroy()
212     {
213         @session_destroy();
214     }
216     public static function set_lifetime($seconds = -1)
217     {
218         echo "Not implemented yet";
219     }
221     public static function &get_all()
222     {
223         $ret = &$_SESSION;
224         return($ret);
225     }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>