-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventManager.php
178 lines (138 loc) · 4.53 KB
/
EventManager.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* Description of EventManager
*
* @author osman ozdemir
*/
class EventManager
{
public static $base;
public static $params;
public static $post;
public static $get;
public static $currentModule;
public $css;
public $js;
public static $db;
public function __construct()
{
EventManager::$base = trim(dirname($_SERVER['SCRIPT_NAME']));
if (!(EventManager::$base == '/')) {
EventManager::$base .= "/";
};
$this->css = '';
$this->js = '';
self::$params = explode('/', isset($_GET['q']) ? $_GET['q'] : "");
self::$post = $_POST;
self::$get = $_GET;
self::$db = new DBManager();
self::$db->load();
self::$currentModule = 'Today';
}
public function serve()
{
jsConfig('base', EventManager::$base);
switch(self::$params[0])
{
case '':
return $this->loadModule('Home');
break;
case 'home':
return $this->loadModule('Home');
break;
case 'hakkimizda':
return $this->loadModule('Hakkimizda');
break;
case 'turk-genci-kimdir':
return $this->loadModule('TurkGenciKimdir');
break;
case 'calismalarimiz':
return $this->loadModule('Calismalarimiz');
break;
case 'confirm-user':
return $this->loadModule('ConfirmUser');
break;
case 'bir-derdim-var':
return $this->loadModule('BirDerdimVar');
break;
case 'admin':
return $this->loadModule('Admin');
break;
case 'logout':
return $this->loadModule('Logout');
break;
case 'ajax':
$this->ajax();
break;
}
}
public function loadModule($moduleName)
{
$module = new $moduleName();
self::$currentModule = $module;
if(userExists())
{
self::addAdminStuff();
}
$loaded = $module->load();
$this->addCSS($module->css);
$this->addJS($module->js);
return $loaded;
}
public static function goToLoc($location)
{
header('Location: ' . $location);
die();
}
public function addCSS($css)
{
$this->css .= $css;
}
public function addJS($js)
{
$this->js .= $js;
}
public function ajax()
{
$response = array();
switch(self::$params[1])
{
case 'authenticate':
$response = EventManager::login(self::$post['userName'], self::$post['password']);
break;
case 'signup':
$response = EventManager::signup(self::$post);
break;
case 'add-item':
$response = EventManager::addItem(self::$post);
}
echo json_encode($response);
exit;
}
public static function url($fileURL)
{
return EventManager::$base . $fileURL;
}
public static function login($userName, $password)
{
return self::$db->authenticateUser($userName, sha1(md5($password . PASS_STRING)));
}
public static function signup($nvp)
{
return self::$db->signup($nvp);
}
public static function addItem($params)
{
}
public static function addAdminStuff()
{
self::$currentModule->addJS('js/admin.js');
$panel = new View('panels/panel.view.php');
$addNewItem = new View('panels/addNewItem.view.php');
$blockDetails = new View('panels/blockDetails.view.php');
jsConfig('panel', $panel->createHTML());
jsConfig('addNewItem', $addNewItem->createHTML());
jsConfig('blockDetails', $blockDetails->createHTML());
}
}
?>