init.php 2.23 KB
Newer Older
Penny Leach's avatar
Penny Leach committed
1 2
<?php
/**
3
 * Copyright 2006,2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
Penny Leach's avatar
Penny Leach committed
4
 *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * This file is part of maraha.
 *
 * maraha is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * maraha is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with maraha; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Penny Leach's avatar
Penny Leach committed
20 21 22 23 24 25 26 27 28 29 30 31
 */

// set up basic error handling here


unset($CFG);
$CFG = new StdClass;
$CFG->docroot = dirname(__FILE__);

// figure out our include path
$CFG->libroot = dirname(dirname(__FILE__)).'/lib/';
if (array_key_exists('MAHARA_LIBDIR',$_SERVER) && !empty($_SERVER['MAHARA_LIBDIR'])) {
32
    $CFG->libroot = $_SERVER['MAHARA_LIBDIR'];
Penny Leach's avatar
Penny Leach committed
33 34 35 36 37
}

set_include_path('.'.PATH_SEPARATOR.$CFG->libroot);

if (!file_exists($CFG->libroot.'config.php') || !is_readable($CFG->libroot.'config.php')) {
38
    throw new Exception("Not installed! Please create config.php from config-dist.php");
Penny Leach's avatar
Penny Leach committed
39 40 41 42 43
}

require('config.php');
$CFG = (object)array_merge((array)$cfg,(array)$CFG);

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
require('mahara.php');
ensure_config_sanity();
ensure_php_sanity();

require('adodb/adodb.inc.php'); // Database access functions
$db = &ADONewConnection($CFG->dbtype);

ob_start();
if (!empty($CFG->dbport)) {
    $CFG->dbhost .= ':'.$CFG->dbhost;
}
if (!isset($CFG->dbpersist) or !empty($CFG->dbpersist)) {    // Use persistent connection (default)
    $dbconnected = $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
} else {                                                     // Use single connection
    $dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
}
if (empty($dbconnected)) {
    $errormessage = ob_get_contents();
    ob_end_clean();
    throw new Exception("Database connection failed with error: ".$db->ErrorMsg()." (".$errormessage.")");
}
ob_end_clean();



Penny Leach's avatar
Penny Leach committed
69
?>