init.php 2.16 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
    trigger_error("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
require('mahara.php');
45
ensure_sanity();
46
47
48
49
50
51

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

ob_start();
if (!empty($CFG->dbport)) {
52
    $CFG->dbhost .= ':'.$CFG->dbport;
53
54
55
56
57
58
59
60
61
}
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();
62
    trigger_error(get_string('dbconnfailed','error',$errormessage));
63
64
65
66
}
ob_end_clean();


Penny Leach's avatar
Penny Leach committed
67
?>