blob: fcd4a96558fb86b94e9f4d6ca97667193b23c214 [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*******************************************************************************/
gobrienda3a4502008-01-28 23:43:26 +000013if(!defined('BABEL_BASE_DIR')){
14 define('BABEL_BASE_DIR', "../");
15}
droy10ea8052007-11-27 18:38:06 +000016define('USE_PHOENIX', true);
17define("COOKIE_REMEMBER", "cBABEL");
18define("COOKIE_SESSION" , "sBABEL");
droye95652e2007-11-27 18:16:36 +000019
droye95652e2007-11-27 18:16:36 +000020# Load up Phoenix classes
droyfd2bab22007-11-27 21:08:43 +000021global $App;
droye95652e2007-11-27 18:16:36 +000022if(USE_PHOENIX) {
gobrien197d2832007-11-27 18:42:53 +000023 require_once('eclipse.org-common/system/app.class.php');
24 require_once("eclipse.org-common/system/nav.class.php");
25 require_once("eclipse.org-common/system/menu.class.php");
droy974b6af2007-11-27 19:19:49 +000026 $App = new App();
27 $Nav = new Nav();
droye95652e2007-11-27 18:16:36 +000028 $Menu = new Menu();
droy8aedeec2008-01-25 19:04:14 +000029 $MenuItemList = array();
30 $MenuItemList[0] = new MenuItem("Home", "./", "_self", 0);
31 $MenuItemList[1] = new MenuItem("For committers", "map_files.php", "_self", 0);
32 $MenuItemList[2] = new MenuItem("About Babel", "http://www.eclipse.org/babel", "_self", 0);
33 $Menu->setMenuItemList($MenuItemList);
34
35 # set Phoenix defaults to prevent errors. These can be overridden on the page.
36 $pageTitle = "";
37 $pageAuthor = "";
38 $pageKeywords = "";
droye95652e2007-11-27 18:16:36 +000039}
40$GLOBALS['g_LOADTIME'] = microtime();
droy974b6af2007-11-27 19:19:49 +000041require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
droy3e7f3a82007-11-29 19:35:51 +000042require(BABEL_BASE_DIR . "classes/system/event_log.class.php");
droyfd2bab22007-11-27 21:08:43 +000043require_once(BABEL_BASE_DIR . "classes/system/user.class.php");
droy3e7f3a82007-11-29 19:35:51 +000044
droy24242b82008-01-30 18:43:20 +000045# get context
46if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
47 errorLog("Failed to find/read database conf file - aborting.");
48 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
49}
50
51$context = $ini['context'];
52if($context == "") {
53 $context = "staging";
54}
55global $context;
56
droye95652e2007-11-27 18:16:36 +000057session_name(COOKIE_SESSION);
58session_start();
59extract($_SESSION);
60
61
droy2d5fd192007-11-28 14:42:45 +000062function InitPage($login) {
63 $page = $login;
droye95652e2007-11-27 18:16:36 +000064 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000065 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000066
67 if (empty($GLOBALS['page']))
68 $GLOBALS['page'] = '';
69
70 if (($lastPage != $_SERVER['PHP_SELF']) AND ($lastPage != "login"))
droy974b6af2007-11-27 19:19:49 +000071 SetSessionVar('s_pageLast',$lastPage);
72 SetSessionVar('s_pageName',$GLOBALS['page']);
droye95652e2007-11-27 18:16:36 +000073
droy974b6af2007-11-27 19:19:49 +000074 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000075 global $dbh;
droy974b6af2007-11-27 19:19:49 +000076 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000077
droy2d5fd192007-11-28 14:42:45 +000078 if($login == "login" && !$User) {
79 # Login required, but the User object isn't there.
80
81 if(isset($_COOKIE[COOKIE_REMEMBER])) {
82 # Try to fetch username from session
83 require_once(BABEL_BASE_DIR . "classes/system/session.class.php");
84 $Session = new Session();
droye95652e2007-11-27 18:16:36 +000085
droy2d5fd192007-11-28 14:42:45 +000086 if(!$Session->validate()) {
87 SetSessionVar('s_pageLast', $GLOBALS['page']);
droy0ab70092007-12-01 02:14:47 +000088 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +000089 }
90 else {
91 $User = new User();
92 $User->loadFromID($Session->_userid);
93 SetSessionVar("User", $User);
94 }
95 }
96 else {
droy0ab70092007-12-01 02:14:47 +000097 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +000098 }
99 }
droye95652e2007-11-27 18:16:36 +0000100
101 $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
102 $GLOBALS['g_PAGE'] = $page;
103 $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
104 $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4);
105 $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
106 $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000107 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000108}
droye95652e2007-11-27 18:16:36 +0000109
droy10ea8052007-11-27 18:38:06 +0000110function errorLog($str) {
111
112}
droyfd2bab22007-11-27 21:08:43 +0000113
droy10ea8052007-11-27 18:38:06 +0000114function exitTo() {
115 # TODO: sqlClose();
116 if (func_num_args() == 1) {
117 $url = func_get_arg(0);
118 header("Location: $url");
119 exit;
120 }
121 else if (func_num_args() == 2) {
122 $url = func_get_arg(0);
123 $arg1 = func_get_arg(1);
124 SetSessionVar("errStr",$arg1);
125 header("Location: $url");
126 exit;
127 }
128 else if (func_num_args() == 3) {
129 $url = func_get_arg(0);
130 $arg1 = func_get_arg(1);
131 $arg2 = func_get_arg(2);
132 SetSessionVar($arg1,$arg2);
133 header("Location: $url");
134 exit;
135 }
droye95652e2007-11-27 18:16:36 +0000136}
droy974b6af2007-11-27 19:19:49 +0000137function GetSessionVar($varName) {
138 if (isset($_SESSION[$varName]))
139 return $_SESSION[$varName];
140 return 0;
141}
droye95652e2007-11-27 18:16:36 +0000142
droy974b6af2007-11-27 19:19:49 +0000143function SetSessionVar($varName,$varVal) {
144 global $_SESSION;
145
146 $GLOBALS[$varName] = $varVal;
147 $_SESSION[$varName] = $varVal;
148 return $varVal;
149}
droye95652e2007-11-27 18:16:36 +0000150
gobrien35e23782007-11-28 21:37:18 +0000151function getLanguagebyID($id){
152 global $dbh;
153 $query = "select name from languages where language_id = '".addslashes($id)."' limit 1";
154 $res = mysql_query($query,$dbh);
155 $ret = mysql_fetch_array($res, MYSQL_ASSOC);
156 return $ret['name'];
157}
158
159
droye95652e2007-11-27 18:16:36 +0000160?>