blob: f7ea0f54ee8787bd0be17e77ec718f6f082f9993 [file] [log] [blame]
droye95652e2007-11-27 18:16:36 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2007 Eclipse Foundation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Paul Colton (Aptana)- initial API and implementation
11 * Eclipse Foundation
12*******************************************************************************/
droy10ea8052007-11-27 18:38:06 +000013define('BABEL_BASE_DIR', "../");
14define('USE_PHOENIX', true);
15define("COOKIE_REMEMBER", "cBABEL");
16define("COOKIE_SESSION" , "sBABEL");
droye95652e2007-11-27 18:16:36 +000017
18
19# Load up Phoenix classes
droyfd2bab22007-11-27 21:08:43 +000020global $App;
droye95652e2007-11-27 18:16:36 +000021if(USE_PHOENIX) {
gobrien197d2832007-11-27 18:42:53 +000022 require_once('eclipse.org-common/system/app.class.php');
23 require_once("eclipse.org-common/system/nav.class.php");
24 require_once("eclipse.org-common/system/menu.class.php");
droy974b6af2007-11-27 19:19:49 +000025 $App = new App();
26 $Nav = new Nav();
droye95652e2007-11-27 18:16:36 +000027 $Menu = new Menu();
28}
29$GLOBALS['g_LOADTIME'] = microtime();
droy974b6af2007-11-27 19:19:49 +000030require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
droyfd2bab22007-11-27 21:08:43 +000031require_once(BABEL_BASE_DIR . "classes/system/user.class.php");
droye95652e2007-11-27 18:16:36 +000032session_name(COOKIE_SESSION);
33session_start();
34extract($_SESSION);
35
36
droy2d5fd192007-11-28 14:42:45 +000037function InitPage($login) {
38 $page = $login;
droye95652e2007-11-27 18:16:36 +000039 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000040 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000041
42 if (empty($GLOBALS['page']))
43 $GLOBALS['page'] = '';
44
45 if (($lastPage != $_SERVER['PHP_SELF']) AND ($lastPage != "login"))
droy974b6af2007-11-27 19:19:49 +000046 SetSessionVar('s_pageLast',$lastPage);
47 SetSessionVar('s_pageName',$GLOBALS['page']);
droye95652e2007-11-27 18:16:36 +000048
droy974b6af2007-11-27 19:19:49 +000049 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000050 global $dbh;
droy974b6af2007-11-27 19:19:49 +000051 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000052
droy2d5fd192007-11-28 14:42:45 +000053 if($login == "login" && !$User) {
54 # Login required, but the User object isn't there.
55
56 if(isset($_COOKIE[COOKIE_REMEMBER])) {
57 # Try to fetch username from session
58 require_once(BABEL_BASE_DIR . "classes/system/session.class.php");
59 $Session = new Session();
droye95652e2007-11-27 18:16:36 +000060
droy2d5fd192007-11-28 14:42:45 +000061 if(!$Session->validate()) {
62 SetSessionVar('s_pageLast', $GLOBALS['page']);
63 exitTo("login.php");
64 }
65 else {
66 $User = new User();
67 $User->loadFromID($Session->_userid);
68 SetSessionVar("User", $User);
69 }
70 }
71 else {
72 exitTo("login.php");
73 }
74 }
droye95652e2007-11-27 18:16:36 +000075
76 $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
77 $GLOBALS['g_PAGE'] = $page;
78 $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
79 $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4);
80 $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
81 $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +000082 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +000083}
droye95652e2007-11-27 18:16:36 +000084
droy10ea8052007-11-27 18:38:06 +000085function errorLog($str) {
86
87}
droyfd2bab22007-11-27 21:08:43 +000088
droy10ea8052007-11-27 18:38:06 +000089function exitTo() {
90 # TODO: sqlClose();
91 if (func_num_args() == 1) {
92 $url = func_get_arg(0);
93 header("Location: $url");
94 exit;
95 }
96 else if (func_num_args() == 2) {
97 $url = func_get_arg(0);
98 $arg1 = func_get_arg(1);
99 SetSessionVar("errStr",$arg1);
100 header("Location: $url");
101 exit;
102 }
103 else if (func_num_args() == 3) {
104 $url = func_get_arg(0);
105 $arg1 = func_get_arg(1);
106 $arg2 = func_get_arg(2);
107 SetSessionVar($arg1,$arg2);
108 header("Location: $url");
109 exit;
110 }
droye95652e2007-11-27 18:16:36 +0000111}
droy974b6af2007-11-27 19:19:49 +0000112function GetSessionVar($varName) {
113 if (isset($_SESSION[$varName]))
114 return $_SESSION[$varName];
115 return 0;
116}
droye95652e2007-11-27 18:16:36 +0000117
droy974b6af2007-11-27 19:19:49 +0000118function SetSessionVar($varName,$varVal) {
119 global $_SESSION;
120
121 $GLOBALS[$varName] = $varVal;
122 $_SESSION[$varName] = $varVal;
123 return $varVal;
124}
droye95652e2007-11-27 18:16:36 +0000125
126?>