-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·195 lines (154 loc) · 6.25 KB
/
index.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
session_start();
require 'include/config.php';
if(file_exists('include/local.config.php')) include 'include/local.config.php';
require 'include/main_func.php';
$dbh = new PDO($config['bd']['db_connect'], $config['bd']['user'], $config['bd']['passwoord']);
if(isset($_COOKIE['auth_key']) AND !isset($_SESSION['user'])) {
turn_on_session();
}
if (isset($_SESSION['user'])) {
online();
}
require_once __DIR__.'/vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/templates/'.$config['settings']['template'].'/views',
));
$app['twig'] = $app->share($app->extend('twig', function($twig, $app) {
$twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use ($app) {
return sprintf('%s/%s', trim($app['request']->getBasePath()), ltrim($asset, '/'));
}));
return $twig;
}));
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request;
use Silex\Provider\SwiftmailerServiceProvider;
$app->register(new Silex\Provider\SwiftmailerServiceProvider());
$transport = Swift_SmtpTransport::newInstance($config['mail']['host'], $config['mail']['port'], $config['mail']['encryption'])
->setUsername($config['mail']['user'])
->setPassword($config['mail']['password']);
$mailer = Swift_Mailer::newInstance($transport);
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->before(function ($request) use ($app) {
$app['twig']->addGlobal('active', $request->get("_route"));
$app['twig']->addGlobal('session_user', @$_SESSION['user']);
});
$app->error(
function (Exception $e) use ($app) {
if ($e instanceof NotFoundHttpException) {
return $app['twig']->render('error.twig', array('code' => 404, 'session_user' => @$_SESSION['user']));
}
$code = ($e instanceof HttpException) ? $e->getStatusCode() : 500;
return $app['twig']->render('error.twig', array('code' => $code, 'session_user' => @$_SESSION['user']));
}
);
//for app
$app->match('/app/exam/connect', function(Request $request) use ($app) {
$response = array('status' => 11);
if(isset($_GET['callback'])) {
return $_GET['callback'] . '(' . json_encode($response) . ')';
}
});
$app->match('/app/authorization/site', function(Request $request) use ($app) {
if(isset($_GET['user_email']) && isset($_GET['user_password'])) {
$answ = app_authorization($request);
return $_GET['callback'] . '(' . json_encode($answ) . ')';
}
});
$app->match('/app/upload/task', function(Request $request) use ($app) {
if(isset($_GET['key_auth'])) {
$answ = app_upload_task($request);
return $_GET['callback'] . '(' . json_encode($answ) . ')';
}
});
$app->match('/app/import/task', function(Request $request) use ($app) {
if(isset($_GET['key_auth'])) {
$answ = app_import_task($request);
return $_GET['callback'] . '(' . json_encode($answ) . ')';
}
});
//for script
$app->match('/logout', function() use ($app) {
logout();
$redirect_url = "/";
header('HTTP/1.1 200 OK');
header('Location: http://'.$_SERVER['HTTP_HOST'].$redirect_url);
exit;
});
$app->match('/task/do/create', function(Request $request) use ($app) {
return create_task($app, $request);
});
$app->match('/task/list/right', function(Request $request) use ($app) {
return task_list_right($request);
});
$app->match('/task/list/content', function(Request $request) use ($app) {
return task_list_content($request);
});
$app->match('/task/information/content', function(Request $request) use ($app) {
return task_information_render($request);
});
$app->match('/task/update/status', function(Request $request) use ($app) {
return update_task_status($request);
});
$app->match('/task/update/accept', function(Request $request) use ($app) {
return update_task_accept($request);
});
$app->match('/task/update/raiting', function(Request $request) use ($app) {
return update_task_raiting($request);
});
$app->match('/task/update/archive', function(Request $request) use ($app) {
return update_task_archive($request);
});
$app->match('/task/update/cancel', function(Request $request) use ($app) {
return update_task_cancel($request);
});
$app->match('/task/update/delete', function(Request $request) use ($app) {
return update_task_delete($request);
});
$app->match('/task/statistics/select', function(Request $request) use ($app) {
return statistics_tasks($request);
});
//for web
$app->match('/', function(Request $request) use ($app) {
$registration = $request->get('message');
$in_email = $request->get('in_email');
$in_password = $request->get('in_password');
if (isset($in_email) or isset($in_password)) $code = authorization($request);
if (isset($registration)) $code = $registration;
return $app['twig']->render('home.twig', array('code' => @$code));
})->bind('home');
$app->match('/registration', function(Request $request) use ($app) {
$reg_name = $request->get('reg_name');
$reg_password = $request->get('reg_password');
if (isset($reg_name) or isset($reg_password)) $code = registration($request, $app);
return $app['twig']->render('registration.twig', array('code' => @$code));
})->bind('registration');
$app->match('/community', function() use ($app) {
return $app['twig']->render('community.twig');
});
$app->match('/news', function() use ($app) {
return $app['twig']->render('news.twig');
});
$app->match('/application', function() use ($app) {
return $app['twig']->render('application.twig');
});
$app->match('/activation/{activation}', function($activation) use ($app) {
$activation_user = activation($activation);
return $app['twig']->render('activation.twig', array('activation' => $activation_user));
});
$app->match('/admin', function() use ($app) {
return $app['twig']->render('admin.twig');
});
$app->match('/id{u_id}', function(Request $request, $u_id) use ($app) {
if (exam_user($u_id)) return $app->abort(404, $app['twig']->render('error.twig', array('code' => 404)));
$role = analyzer($u_id);
if ($role == 404) {
return $app['twig']->render('error.twig', array('code' => $role));
exit();
}
return $app['twig']->render('user.twig', array('template' => $role['template'], 'user' => $role));
})->assert('u_id', '\d+');
$app->run();