more bugs! incompatibility with php 5.1.2 (presumably earlier versions as well) fixed
[moodle.git] / lib / setuplib.php
CommitLineData
d3f9f1f8 1<?php // $Id$
2 // These functions are required very early in the Moodle
3 // setup process, before any of the main libraries are
4 // loaded.
5
6
7/**
8 * Initializes our performance info early.
9 *
10 * Pairs up with get_performance_info() which is actually
11 * in moodlelib.php. This function is here so that we can
12 * call it before all the libs are pulled in.
13 *
14 * @uses $PERF
15 */
16function init_performance_info() {
17
18 global $PERF;
19
20 $PERF = new Object;
21 $PERF->dbqueries = 0;
22 $PERF->logwrites = 0;
23 if (function_exists('microtime')) {
24 $PERF->starttime = microtime();
25 }
26 if (function_exists('memory_get_usage')) {
27 $PERF->startmemory = memory_get_usage();
28 }
29 if (function_exists('posix_times')) {
30 $PERF->startposixtimes = posix_times();
31 }
32}
33
34/**
35 * Create a directory.
36 *
37 * @uses $CFG
38 * @param string $directory a string of directory names under $CFG->dataroot eg stuff/assignment/1
39 * param bool $shownotices If true then notification messages will be printed out on error.
40 * @return string|false Returns full path to directory if successful, false if not
41 */
42function make_upload_directory($directory, $shownotices=true) {
43
44 global $CFG;
45
46 $currdir = $CFG->dataroot;
47
48 umask(0000);
49
50 if (!file_exists($currdir)) {
51 if (! mkdir($currdir, $CFG->directorypermissions)) {
52 if ($shownotices) {
53 echo '<div class="notifyproblem" align="center">ERROR: You need to create the directory '.
54 $currdir .' with web server write access</div>'."<br />\n";
55 }
56 return false;
57 }
58 if ($handle = fopen($currdir.'/.htaccess', 'w')) { // For safety
59 @fwrite($handle, "deny from all\r\n");
60 @fclose($handle);
61 }
62 }
63
64 $dirarray = explode('/', $directory);
65
66 foreach ($dirarray as $dir) {
67 $currdir = $currdir .'/'. $dir;
68 if (! file_exists($currdir)) {
69 if (! mkdir($currdir, $CFG->directorypermissions)) {
70 if ($shownotices) {
71 echo '<div class="notifyproblem" align="center">ERROR: Could not find or create a directory ('.
72 $currdir .')</div>'."<br />\n";
73 }
74 return false;
75 }
76 //@chmod($currdir, $CFG->directorypermissions); // Just in case mkdir didn't do it
77 }
78 }
79
80 return $currdir;
81}
82
7104d80d 83/**
84 * This function will introspect inside DB to detect it it's a UTF-8 DB or no
85 * Used from setup.php to set correctly "set names" when the installation
86 * process is performed without the initial and beautiful installer
87 */
88function setup_is_unicodedb() {
89
90 global $CFG, $db;
91
92 $unicodedb = false;
93
94 switch ($CFG->dbtype) {
95 case 'mysql':
96 /// Get MySQL character_set_database value
97 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
98 if ($rs && $rs->RecordCount() > 0) {
99 $records = $rs->GetAssoc(true);
100 $encoding = $records['character_set_database']['Value'];
101 if (strtoupper($encoding) == 'UTF8') {
102 $unicodedb = true;
103 }
104 }
105 break;
106 case 'postgres7':
107 /// Get PostgreSQL server_encoding value
108 $rs = $db->Execute("SHOW server_encoding");
109 if ($rs && $rs->RecordCount() > 0) {
110 $encoding = $rs->fields['server_encoding'];
2544a80d 111 if (strtoupper($encoding) == 'UNICODE' || strtoupper($encoding) == 'UTF8') {
7104d80d 112 $unicodedb = true;
113 }
114 }
115 break;
116 }
117 return $unicodedb;
118}
119
120
d3f9f1f8 121?>