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 | */ |
16 | function 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 | */ |
42 | function 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 | } |
d100b8a0 |
58 | } |
59 | |
60 | // Make sure a .htaccess file is here, JUST IN CASE the files area is in the open |
61 | if (!file_exists($currdir.'/.htaccess')) { |
d3f9f1f8 |
62 | if ($handle = fopen($currdir.'/.htaccess', 'w')) { // For safety |
d389b128 |
63 | @fwrite($handle, "deny from all\r\nAllowOverride None\r\n"); |
d3f9f1f8 |
64 | @fclose($handle); |
65 | } |
66 | } |
67 | |
68 | $dirarray = explode('/', $directory); |
69 | |
70 | foreach ($dirarray as $dir) { |
71 | $currdir = $currdir .'/'. $dir; |
72 | if (! file_exists($currdir)) { |
73 | if (! mkdir($currdir, $CFG->directorypermissions)) { |
74 | if ($shownotices) { |
75 | echo '<div class="notifyproblem" align="center">ERROR: Could not find or create a directory ('. |
76 | $currdir .')</div>'."<br />\n"; |
77 | } |
78 | return false; |
79 | } |
80 | //@chmod($currdir, $CFG->directorypermissions); // Just in case mkdir didn't do it |
81 | } |
82 | } |
83 | |
84 | return $currdir; |
85 | } |
86 | |
7104d80d |
87 | /** |
88 | * This function will introspect inside DB to detect it it's a UTF-8 DB or no |
89 | * Used from setup.php to set correctly "set names" when the installation |
90 | * process is performed without the initial and beautiful installer |
91 | */ |
92 | function setup_is_unicodedb() { |
93 | |
7ddf8aa5 |
94 | global $CFG, $db, $INSTALL; |
7104d80d |
95 | |
96 | $unicodedb = false; |
7ddf8aa5 |
97 | |
98 | // Since this function is also used during installation process, i.e. during install.php before $CFG->dbtype is set. |
99 | // we need to get dbtype from the right variable |
100 | if (!empty($INSTALL['dbtype'])) { |
101 | $dbtype = $INSTALL['dbtype']; |
102 | } else { |
103 | $dbtype = $CFG->dbtype; |
104 | } |
7104d80d |
105 | |
7ddf8aa5 |
106 | switch ($dbtype) { |
7104d80d |
107 | case 'mysql': |
7104d80d |
108 | $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); |
109 | if ($rs && $rs->RecordCount() > 0) { |
110 | $records = $rs->GetAssoc(true); |
111 | $encoding = $records['character_set_database']['Value']; |
112 | if (strtoupper($encoding) == 'UTF8') { |
113 | $unicodedb = true; |
114 | } |
115 | } |
116 | break; |
117 | case 'postgres7': |
118 | /// Get PostgreSQL server_encoding value |
119 | $rs = $db->Execute("SHOW server_encoding"); |
120 | if ($rs && $rs->RecordCount() > 0) { |
121 | $encoding = $rs->fields['server_encoding']; |
2544a80d |
122 | if (strtoupper($encoding) == 'UNICODE' || strtoupper($encoding) == 'UTF8') { |
7104d80d |
123 | $unicodedb = true; |
124 | } |
125 | } |
126 | break; |
bf052299 |
127 | case 'mssql': |
b2ad0336 |
128 | case 'mssql_n': |
97ab73aa |
129 | case 'odbc_mssql': |
bf052299 |
130 | /// MSSQL only runs under UTF8 + the proper ODBTP driver (both for Unix and Win32) |
131 | $unicodedb = true; |
010f2a39 |
132 | break; |
0700134d |
133 | case 'oci8po': |
134 | /// Get Oracle DB character set value |
135 | $rs = $db->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'"); |
136 | if ($rs && $rs->RecordCount() > 0) { |
137 | $encoding = $rs->fields['value']; |
138 | if (strtoupper($encoding) == 'AL32UTF8') { |
139 | $unicodedb = true; |
140 | } |
141 | } |
142 | break; |
7104d80d |
143 | } |
144 | return $unicodedb; |
145 | } |
146 | |
d3f9f1f8 |
147 | ?> |