blob: ead3e53c4121e39c53d3941e78aac5d4d3ff75f1 [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);
droy7fcffa72008-06-02 20:33:14 +000032 $MenuItemList[2] = new MenuItem("Recent Translations", "recent.php", "_self", 0);
33 $MenuItemList[3] = new MenuItem("About Babel", "http://www.eclipse.org/babel", "_self", 0);
droy8aedeec2008-01-25 19:04:14 +000034 $Menu->setMenuItemList($MenuItemList);
35
36 # set Phoenix defaults to prevent errors. These can be overridden on the page.
37 $pageTitle = "";
38 $pageAuthor = "";
39 $pageKeywords = "";
droye95652e2007-11-27 18:16:36 +000040}
41$GLOBALS['g_LOADTIME'] = microtime();
droy974b6af2007-11-27 19:19:49 +000042require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
droy3e7f3a82007-11-29 19:35:51 +000043require(BABEL_BASE_DIR . "classes/system/event_log.class.php");
droyfd2bab22007-11-27 21:08:43 +000044require_once(BABEL_BASE_DIR . "classes/system/user.class.php");
droy3e7f3a82007-11-29 19:35:51 +000045
droy24242b82008-01-30 18:43:20 +000046# get context
47if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
48 errorLog("Failed to find/read database conf file - aborting.");
49 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
50}
gobrien0436d992008-01-31 00:08:04 +000051
52$context = "";
53if(isset($ini['context']))
54 $context = $ini['context'];
55
droy24242b82008-01-30 18:43:20 +000056if($context == "") {
57 $context = "staging";
58}
59global $context;
60
droye95652e2007-11-27 18:16:36 +000061session_name(COOKIE_SESSION);
62session_start();
63extract($_SESSION);
64
65
droy2d5fd192007-11-28 14:42:45 +000066function InitPage($login) {
67 $page = $login;
droye95652e2007-11-27 18:16:36 +000068 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000069 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000070
71 if (empty($GLOBALS['page']))
72 $GLOBALS['page'] = '';
73
74 if (($lastPage != $_SERVER['PHP_SELF']) AND ($lastPage != "login"))
droy974b6af2007-11-27 19:19:49 +000075 SetSessionVar('s_pageLast',$lastPage);
76 SetSessionVar('s_pageName',$GLOBALS['page']);
droye95652e2007-11-27 18:16:36 +000077
droy974b6af2007-11-27 19:19:49 +000078 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000079 global $dbh;
droy974b6af2007-11-27 19:19:49 +000080 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000081
droy2d5fd192007-11-28 14:42:45 +000082 if($login == "login" && !$User) {
83 # Login required, but the User object isn't there.
84
85 if(isset($_COOKIE[COOKIE_REMEMBER])) {
86 # Try to fetch username from session
87 require_once(BABEL_BASE_DIR . "classes/system/session.class.php");
88 $Session = new Session();
droye95652e2007-11-27 18:16:36 +000089
droy2d5fd192007-11-28 14:42:45 +000090 if(!$Session->validate()) {
91 SetSessionVar('s_pageLast', $GLOBALS['page']);
droy0ab70092007-12-01 02:14:47 +000092 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +000093 }
94 else {
95 $User = new User();
96 $User->loadFromID($Session->_userid);
97 SetSessionVar("User", $User);
98 }
99 }
100 else {
droy0ab70092007-12-01 02:14:47 +0000101 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000102 }
103 }
droye95652e2007-11-27 18:16:36 +0000104
105 $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
106 $GLOBALS['g_PAGE'] = $page;
107 $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
108 $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4);
109 $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
110 $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000111 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000112}
droye95652e2007-11-27 18:16:36 +0000113
droy10ea8052007-11-27 18:38:06 +0000114function errorLog($str) {
115
116}
droyfd2bab22007-11-27 21:08:43 +0000117
droy10ea8052007-11-27 18:38:06 +0000118function exitTo() {
119 # TODO: sqlClose();
120 if (func_num_args() == 1) {
121 $url = func_get_arg(0);
122 header("Location: $url");
123 exit;
124 }
125 else if (func_num_args() == 2) {
126 $url = func_get_arg(0);
127 $arg1 = func_get_arg(1);
128 SetSessionVar("errStr",$arg1);
129 header("Location: $url");
130 exit;
131 }
132 else if (func_num_args() == 3) {
133 $url = func_get_arg(0);
134 $arg1 = func_get_arg(1);
135 $arg2 = func_get_arg(2);
136 SetSessionVar($arg1,$arg2);
137 header("Location: $url");
138 exit;
139 }
droye95652e2007-11-27 18:16:36 +0000140}
droy974b6af2007-11-27 19:19:49 +0000141function GetSessionVar($varName) {
142 if (isset($_SESSION[$varName]))
143 return $_SESSION[$varName];
144 return 0;
145}
droye95652e2007-11-27 18:16:36 +0000146
droy974b6af2007-11-27 19:19:49 +0000147function SetSessionVar($varName,$varVal) {
148 global $_SESSION;
149
150 $GLOBALS[$varName] = $varVal;
151 $_SESSION[$varName] = $varVal;
152 return $varVal;
153}
droye95652e2007-11-27 18:16:36 +0000154
gobrien35e23782007-11-28 21:37:18 +0000155function getLanguagebyID($id){
156 global $dbh;
157 $query = "select name from languages where language_id = '".addslashes($id)."' limit 1";
158 $res = mysql_query($query,$dbh);
159 $ret = mysql_fetch_array($res, MYSQL_ASSOC);
160 return $ret['name'];
161}
162
163
droye95652e2007-11-27 18:16:36 +0000164?>