/
coreconfig.php
137 lines (118 loc) · 3.09 KB
/
coreconfig.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* This config file prepares everything for PRODUCTION.
* */
defined("__EXEC") or die;
// Start a session
if (!defined("SESSION_INIT")) {
require IN . "session" . PHP_EX;
}
error_reporting(E_ALL | E_STRICT);
// do not call the mail function directly, because we cant be sure to use it on localhost
$mail = "mail_hooking";
$crypt = "noob";
function noob ($val) {
return $val;
}
require IN . "developer/mailhook" . PHP_EX;
/**
* Create Url to path, needs configuration
* */
function getUrlToPath($path)
{
return "http://localhost/abi_redesign/" . $path;
}
/**
* Get connection to the database
* */
//Only for testing purposes
class mysqltest extends mysqli {
public function __construct() {
parent::__construct("127.0.0.1", "root", "", "abi");
}
/*public function prepare($query) {
$this->_log($query);
return parent::prepare($query);
}
public function query($query, $resultmode = MYSQLI_STORE_RESULT ) {
$this->_log($query);
return parent::query($query, $resultmode);
}
private function _log($query) {
file_put_contents(__DIR__ . "/__queries.sql", $query . "\n", FILE_APPEND);
} */
}
$__DB = null;
function db()
{
global $__DB;
if($__DB === null) {
$__DB = new mysqltest();
$__DB->set_charset("utf8");
}
return $__DB;
}
$pre = "abi_";
define("USER", $pre . "user");
define("USER_DATA", $pre . "user_data");
define("QUOTE", $pre . "quote");
define("COMMENT", $pre . "comment");
define("AWARD", $pre . "award");
define("CATEGORY", $pre . "category");
define("KURS", $pre ."kurs");
define("TERM", $pre . "term");
define("IMAGE", $pre . "images");
define("MARK", $pre . "images_mark");
define("DATA", $pre . "data");
define("RATING", $pre . "rating");
define("TEACHER", $pre . "teacher");
define("TEACHER_AWARD", $pre . "teacher_award");
define("TEACHER_CATEGORY", $pre . "teacher_category");
/**
* Executes a query and tells if it was successful.
* */
function exQuery($query, $affected = 0) {
return $query->execute() && $query->affected_rows > $affected;
}
/**
* Shorthand for header("HTTP/1.1 404 Not Found");
* */
function h404($json = null)
{
header("HTTP/1.1 404 Not Found");
if ($json !== null) {
header("Content-Type: application/json");
echo json_encode($json);
}
}
/**
* Fails with a little message
* */
function fail ($message = null) {
if ($message !== null && !is_array($message)) {
$message = array("message" => $message);
}
h404($message);
exit;
}
function hJSON($json = null)
{
header("Content-Type: application/json");
if ($json !== null) {
echo json_encode($json);
} else {
// Empty string is no valid json, so just respond with empty object
echo "{}";
}
}
function dateChangeFromISO($date) {
if (strlen($date) !== 10) return "00.00.0000";
$date = explode("-", $date);
return $date[2].".".$date[1].".".$date[0];
}
function dateChangeToISO($date) {
if(strlen($date) !== 10) return "0000-00-00";
$date = explode(".", $date);
return $date[2].".".$date[1].".".$date[0];
}
?>