init.php 3.35 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
defined('INTERNAL') || die();

Nigel McNie's avatar
Nigel McNie committed
24
25
// @todo <nigel> Set up error handling. For now, use trigger_error. I will
// update all calls as necessary once error handling is finalised.
Penny Leach's avatar
Penny Leach committed
26
27

$CFG = new StdClass;
28
$CFG->docroot = dirname(__FILE__) . '/';
Penny Leach's avatar
Penny Leach committed
29

Nigel McNie's avatar
Nigel McNie committed
30
31
// Figure out our include path
if (!empty($_SERVER['MAHARA_LIBDIR'])) {
32
    $CFG->libroot = $_SERVER['MAHARA_LIBDIR'];
Penny Leach's avatar
Penny Leach committed
33
}
Nigel McNie's avatar
Nigel McNie committed
34
else {
35
    $CFG->libroot = dirname(__FILE__) . '/lib/';
Nigel McNie's avatar
Nigel McNie committed
36
37
}
set_include_path('.' . PATH_SEPARATOR . $CFG->libroot);
Penny Leach's avatar
Penny Leach committed
38

39
40
41
// Set up error handling
require 'errors.php';

42
if (!is_readable($CFG->docroot . 'config.php')) {
43
44
45
46
    // @todo Later, this will redirect to the installer script. For now, we
    // just log and exit.
    log_environ('Not installed! Please create config.php from config-dist.php');
    exit;
Penny Leach's avatar
Penny Leach committed
47
48
}

49
require('config.php');
Nigel McNie's avatar
Nigel McNie committed
50
$CFG = (object)array_merge((array)$cfg, (array)$CFG);
Penny Leach's avatar
Penny Leach committed
51

52
// core libraries
53
54
require('mahara.php');
require('dml.php');
55
56
require('constants.php');
require('web.php');
57
ensure_sanity();
58

Nigel McNie's avatar
Nigel McNie committed
59
// Database access functions
60
61
require('adodb/adodb-exceptions.inc.php');
require('adodb/adodb.inc.php');
62

Nigel McNie's avatar
Nigel McNie committed
63
64
65
66
67
68
69
70
71
72
73
74
try {
    // ADODB does not provide the raw driver error message if the connection
    // fails for some reason, so we use output buffering to catch whatever
    // the error is instead.
    ob_start();
    
    $db = &ADONewConnection($CFG->dbtype);
    if (!empty($CFG->dbport)) {
        $CFG->dbhost .= ':'.$CFG->dbport;
    }
    if (!empty($CFG->dbpersist)) {    // Use persistent connection (default)
        $dbconnected = $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
75
76
    } 
    else {                                                     // Use single connection
Nigel McNie's avatar
Nigel McNie committed
77
78
79
        $dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
    }
    
80
81
82
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    configure_dbconnection();

Nigel McNie's avatar
Nigel McNie committed
83
    ob_end_clean();
84
}
Nigel McNie's avatar
Nigel McNie committed
85
catch (Exception $e) {
86
87
    $errormessage = ob_get_contents();
    ob_end_clean();
Nigel McNie's avatar
Nigel McNie committed
88
89
90
91
92
93
94
    // @todo <nigel|penny>: At this point the raw error message can be munged from
    // $errormessage, while the $e object holds some other information (like backtrace,
    // which can be parsed with adodb_backtrace($e->gettrace());). At this point a
    // nice message should be displayed explaining the problem etc. etc.
    echo $e;
    echo $errormessage;
    die;
95
96
}

97
98
load_config();

Penny Leach's avatar
Penny Leach committed
99
100
101
102
103
104
105
106
if (!get_config('theme')) { 
    // if it's not set, we're probably not installed, 
    // so set it in $CFG directly rather than the db which doesn't yet exist
    $CFG->theme = 'default'; 
}

$CFG->themeurl = get_config('wwwroot').'theme/'.get_config('theme').'/static/';

Nigel McNie's avatar
Nigel McNie committed
107
?>