-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
57 lines (49 loc) · 1.75 KB
/
config.php
File metadata and controls
57 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
const AUDIO_EXTENSIONS = ["mp3", "m4a", "wav"];
// Configuration file stored one directory above web root
$config = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . "/../FieldnotesConfig.ini");
if ($config === false) http500();
foreach (["CONFIG_DIR", "PROJECT_FILE_DIR", "BACKUP_DIR", "AUDIO_DIR"] as $dir) {
if (!array_key_exists($dir, $config)) http500();
define($dir, $config[$dir]);
}
define("LOGIN_PROMPT", $config["LOGIN_PROMPT"]);
// Determine the file name based on language and semester/year
$month = intval(date("n"));
$semester = ($month <= 5 ? "Spring" : ($month <= 7 ? "Summer" : "Fall"));
define("FIELDNOTES_FILE", PROJECT_FILE_DIR . "/" . readConfigFile("LanguageName")[0] . "Fieldnotes-" . $semester . date("Y") . ".txt");
function requireLogin() {
session_start();
if (!isset($_SESSION["approved"]) || $_SESSION["approved"] !== true) {
$_SESSION["timedout"] = true;
header("Location: ./");
exit;
}
}
function verifyId($id) {
return in_array($id, readConfigFile("StudentIDs"), true);
}
function getAnnotations() {
return implode("<br>", readConfigFile("Annotations"));
}
// Returns a config file as an array of lines
function readConfigFile($file) {
$file = file_get_contents(CONFIG_DIR . "/" . $file . ".txt");
if ($file === false) http500();
$lines = explode("\n", $file);
foreach ($lines as $i => $line) {
// Remove lines that are empty (only whitespace) or begin with a # (comment)
if ($line == "" || ctype_space($line) || $line[0] == "#") {
unset($lines[$i]);
} else {
// Remove undesired characters
$lines[$i] = str_replace(["\n", "\t", "\r"], '', $line);
}
}
return array_values($lines);
}
function http500() {
header("HTTP/1.1 500 Internal Server Error");
exit;
}
?>