droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 1 | <?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 | *******************************************************************************/ |
gobrien | da3a450 | 2008-01-28 23:43:26 +0000 | [diff] [blame] | 13 | if(!defined('BABEL_BASE_DIR')){ |
| 14 | define('BABEL_BASE_DIR', "../"); |
| 15 | } |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 16 | define('USE_PHOENIX', true); |
| 17 | define("COOKIE_REMEMBER", "cBABEL"); |
| 18 | define("COOKIE_SESSION" , "sBABEL"); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 19 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 20 | # Load up Phoenix classes |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 21 | global $App; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 22 | if(USE_PHOENIX) { |
gobrien | 197d283 | 2007-11-27 18:42:53 +0000 | [diff] [blame] | 23 | 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"); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 26 | $App = new App(); |
| 27 | $Nav = new Nav(); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 28 | $Menu = new Menu(); |
droy | 8aedeec | 2008-01-25 19:04:14 +0000 | [diff] [blame] | 29 | $MenuItemList = array(); |
| 30 | $MenuItemList[0] = new MenuItem("Home", "./", "_self", 0); |
| 31 | $MenuItemList[1] = new MenuItem("For committers", "map_files.php", "_self", 0); |
droy | 7fcffa7 | 2008-06-02 20:33:14 +0000 | [diff] [blame^] | 32 | $MenuItemList[2] = new MenuItem("Recent Translations", "recent.php", "_self", 0); |
| 33 | $MenuItemList[3] = new MenuItem("About Babel", "http://www.eclipse.org/babel", "_self", 0); |
droy | 8aedeec | 2008-01-25 19:04:14 +0000 | [diff] [blame] | 34 | $Menu->setMenuItemList($MenuItemList); |
| 35 | |
| 36 | # set Phoenix defaults to prevent errors. These can be overridden on the page. |
| 37 | $pageTitle = ""; |
| 38 | $pageAuthor = ""; |
| 39 | $pageKeywords = ""; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 40 | } |
| 41 | $GLOBALS['g_LOADTIME'] = microtime(); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 42 | require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php"); |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 43 | require(BABEL_BASE_DIR . "classes/system/event_log.class.php"); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 44 | require_once(BABEL_BASE_DIR . "classes/system/user.class.php"); |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 45 | |
droy | 24242b8 | 2008-01-30 18:43:20 +0000 | [diff] [blame] | 46 | # get context |
| 47 | if (!($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 | } |
gobrien | 0436d99 | 2008-01-31 00:08:04 +0000 | [diff] [blame] | 51 | |
| 52 | $context = ""; |
| 53 | if(isset($ini['context'])) |
| 54 | $context = $ini['context']; |
| 55 | |
droy | 24242b8 | 2008-01-30 18:43:20 +0000 | [diff] [blame] | 56 | if($context == "") { |
| 57 | $context = "staging"; |
| 58 | } |
| 59 | global $context; |
| 60 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 61 | session_name(COOKIE_SESSION); |
| 62 | session_start(); |
| 63 | extract($_SESSION); |
| 64 | |
| 65 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 66 | function InitPage($login) { |
| 67 | $page = $login; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 68 | $lastPage = GetSessionVar('s_pageName'); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 69 | $User = GetSessionVar('User'); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 70 | |
| 71 | if (empty($GLOBALS['page'])) |
| 72 | $GLOBALS['page'] = ''; |
| 73 | |
| 74 | if (($lastPage != $_SERVER['PHP_SELF']) AND ($lastPage != "login")) |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 75 | SetSessionVar('s_pageLast',$lastPage); |
| 76 | SetSessionVar('s_pageName',$GLOBALS['page']); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 77 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 78 | $dbc = new DBConnection(); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 79 | global $dbh; |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 80 | $dbh = $dbc->connect(); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 81 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 82 | 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(); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 89 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 90 | if(!$Session->validate()) { |
| 91 | SetSessionVar('s_pageLast', $GLOBALS['page']); |
droy | 0ab7009 | 2007-12-01 02:14:47 +0000 | [diff] [blame] | 92 | exitTo("login.php"); |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 93 | } |
| 94 | else { |
| 95 | $User = new User(); |
| 96 | $User->loadFromID($Session->_userid); |
| 97 | SetSessionVar("User", $User); |
| 98 | } |
| 99 | } |
| 100 | else { |
droy | 0ab7009 | 2007-12-01 02:14:47 +0000 | [diff] [blame] | 101 | exitTo("login.php"); |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 104 | |
| 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("","","","","","","","","","","",); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 111 | $GLOBALS['DEBUG'] = ""; |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 112 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 113 | |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 114 | function errorLog($str) { |
| 115 | |
| 116 | } |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 117 | |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 118 | function 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 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 140 | } |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 141 | function GetSessionVar($varName) { |
| 142 | if (isset($_SESSION[$varName])) |
| 143 | return $_SESSION[$varName]; |
| 144 | return 0; |
| 145 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 146 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 147 | function SetSessionVar($varName,$varVal) { |
| 148 | global $_SESSION; |
| 149 | |
| 150 | $GLOBALS[$varName] = $varVal; |
| 151 | $_SESSION[$varName] = $varVal; |
| 152 | return $varVal; |
| 153 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 154 | |
gobrien | 35e2378 | 2007-11-28 21:37:18 +0000 | [diff] [blame] | 155 | function 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 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 164 | ?> |