-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.php
348 lines (314 loc) · 14.9 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php
use Widgets\WidgetArea;
session_start();
/* ========================================================================
* Open eClass 4.0
* E-learning and Course Management System
* ========================================================================
* Copyright 2003-2021 Greek Universities Network - GUnet
* A full copyright notice can be read in "/info/copyright.txt".
* For a full list of contributors, see "credits.txt".
*
* Open eClass is an open platform distributed in the hope that it will
* be useful (without any warranty), under the terms of the GNU (General
* Public License) as published by the Free Software Foundation.
* The full license can be read in "/info/license/license_gpl.txt".
*
* Contact address: GUnet Asynchronous eLearning Group,
* Network Operations Center, University of Athens,
* Panepistimiopolis Ilissia, 15784, Athens, Greece
* e-mail: [email protected]
* ======================================================================== */
/*
* @file index.php
*
* @abstract This file serves as the home page of eclass when the user
* is not logged in.
*
*/
if (isset($_POST['admin_login'])) {
define('MAINTENANCE_PAGE', true);
}
// Handle alias of .../courses/<CODE>/... to index.php for course homes
if (preg_match('|/courses/([a-zA-Z0-9_-]+)/[^/]*$|', $_SERVER['REQUEST_URI'], $matches)) {
$dbname = $matches[1];
if (!is_dir('courses/' . $dbname)) {
header('HTTP/1.0 404 Not Found');
echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head><title>404 Not Found</title></head><body>
<h1>Not Found</h1>
<p>The requested URL ',htmlspecialchars($_SERVER['REQUEST_URI']),' was not found on this server.</p>
</body></html>';
exit;
}
$_SESSION['dbname'] = $dbname;
chdir('modules/course_home');
require_once '../../modules/course_home/course_home.php';
exit;
}
define('HIDE_TOOL_TITLE', 1);
$guest_allowed = true;
require_once 'include/baseTheme.php';
require_once 'modules/auth/login_form.inc.php';
require_once 'include/sendMail.inc.php';
// unset system that records visitor only once by course for statistics
require_once 'include/action.php';
load_js('trunk8');
if (isset($dbname)) {
$action = new action();
$action->record(MODULE_ID_UNITS, 'exit');
}
unset($dbname);
if (isset($_SESSION['uid'])) {
$uid = $_SESSION['uid'];
} else {
$uid = 0;
}
// if we try to login... then authenticate user.
$warning = '';
if(isset($_SESSION['hybridauth_callback'])) {
switch($_SESSION['hybridauth_callback']) {
case 'login':
$_GET['provider'] = $_SESSION['hybridauth_provider'] ?? '';
break;
case 'profile':
$provider = $_SESSION['hybridauth_provider'] ?? '';
header('Location: /main/profile/profile.php?action=connect&provider='.$provider.'&'.$_SERVER['QUERY_STRING']);
exit;
case 'auth_test':
$provider = $_SESSION['hybridauth_provider'] ?? '';
header('Location: /modules/admin/auth_test.php?auth='.$provider.'&'.$_SERVER['QUERY_STRING']);
exit;
}
}
if (isset($_SESSION['shib_uname'])) {
// authenticate via Shibboleth
shib_cas_login('shibboleth');
} elseif (isset($_SESSION['cas_uname'])) {
// authenticate via CAS
shib_cas_login('cas');
} elseif (isset($_SESSION['auth_id'])) {
// authenticate via OAuth 2.0
shib_cas_login('oauth2');
} elseif (isset($_GET['provider'])) {
//hybridauth authentication (Facebook, Twitter, Google, Yahoo, Live, LinkedIn)
hybridauth_login();
} else {
// normal authentication
process_login();
}
$data['warning'] = $warning;
// if the user logged in include the correct language files
// in case he has a different language set in his/her profile
if (isset($language)) {
// include_messages
include "lang/$language/common.inc.php";
$extra_messages = "config/{$language_codes[$language]}.inc.php";
if (file_exists($extra_messages)) {
include $extra_messages;
} else {
$extra_messages = false;
}
include "lang/$language/messages.inc.php";
if (file_exists('config/config.php')) {
if(get_config('show_always_collaboration') and get_config('show_collaboration')){
include "lang/$language/messages_collaboration.inc.php";
}
}
if ($extra_messages) {
include $extra_messages;
}
}
// check if we are guest user
if (!$upgrade_begin and $uid and !isset($_GET['redirect_home'])) {
if (check_guest()) {
// if the user is a guest send him straight to the corresponding lesson
$guest = Database::get()->querySingle("SELECT code FROM course_user, course
WHERE course.id = course_user.course_id AND
user_id = ?d", $uid);
if ($guest) {
$dbname = $guest->code;
$_SESSION['dbname'] = $dbname;
header("Location: {$urlServer}courses/$dbname/index.php");
exit;
}
}
// if user is logged in redirect him to homepage
if(isset($_GET['show_home'])){
header("Location: {$urlServer}?redirect_home=true");
}else{
// if user is not guest redirect him to portfolio
header("Location: {$urlServer}main/portfolio.php");
}
} else {
// check authentication methods
$hybridLinkId = null;
$hybridProviders = array();
$authLinks = array();
if (!$upgrade_begin) {
$loginFormEnabled = false;
$q = Database::get()->queryArray("SELECT auth_id, auth_name, auth_default, auth_title, auth_instructions
FROM auth WHERE auth_default <> 0
ORDER BY auth_default DESC, auth_id");
foreach ($q as $l) {
if (in_array($l->auth_name, $extAuthMethods)) {
$authNameDefault = '';
if(!empty($l->auth_title)){
$authNameDefault = $l->auth_title;
}else{
$authNameDefault = $langEnter;
}
$authLinks[] = array(
'authId' => $l->auth_id,
'is_primary' => $l->auth_default,
'authInstructions' => $l->auth_instructions,
'nameAuth' => $l->auth_name,
'showTitle' => true,
'class' => 'login-option login-option-sso',
'title' => empty($l->auth_title)? "$langLogInWith {$l->auth_name}": q(getSerializedMessage($l->auth_title)),
'html' => "<a class='btn submitAdminBtnDefault sso-btn d-inline-flex' href='" . $urlServer . ($l->auth_name == 'cas'? 'modules/auth/cas.php': 'secure/') . "'>$authNameDefault</a>");
} elseif (in_array($l->auth_name, $hybridAuthMethods)) {
$hybridProviders[] = $l->auth_name;
if (is_null($hybridLinkId)) {
$authLinks[] = array(
'authId' => $l->auth_id,
'is_primary' => $l->auth_default,
'authInstructions' => $l->auth_instructions,
'nameAuth' => $l->auth_name,
'showTitle' => true,
'class' => 'login-option',
'title' => $langViaSocialNetwork);
$hybridLinkId = count($authLinks) - 1;
}
} elseif (!$loginFormEnabled) {
$autofocus = count($authLinks)? '' : 'autofocus' ;
$loginFormEnabled = true;
$authLinks[] = array(
'authId' => $l->auth_id,
'is_primary' => $l->auth_default,
'authInstructions' => $l->auth_instructions,
'nameAuth' => $l->auth_name,
'showTitle' => false,
'class' => 'login-option',
'title' => empty($l->auth_title)? "$langLogInWith {$l->auth_name}": q(getSerializedMessage($l->auth_title)),
'html' => " <form action='$urlServer' method='post'>
<div class='form-group text-start'>
<label for='uname' class='form-label'>$langUsername</label>
<input type='text' id='uname' name='uname' class='login-input w-100' placeholder='' $autofocus>
</div>
<div class='form-group text-start mt-3'>
<label for='pass' class='form-label'>$langPass</label>
<div class='input-group flex-nowrap'>
<input type='password' id='pass' class='login-input border-end-0 w-100 mt-0' name='pass' placeholder='' aria-label='reveal Password'>
<span id='revealPass' class='input-group-text login-input-password-reveal border-start-0 bg-input-default input-border-color'>
<i class='fa-solid fa-eye fa-md'></i>
</span>
</div>
</div>
<button type='submit' name='submit' class='btn w-100 login-form-submit mt-4'>$langEnter</button>
</form>
<div class='col-12 d-flex justify-content-md-start justify-content-center align-items-center mt-4'>
<a class='text-decoration-underline' href='modules/auth/lostpass.php'>$lang_forgot_pass</a>
</div>");
}
}
if (count($hybridProviders)) {
$authLinks[$hybridLinkId]['html'] = '<div class="col-12 d-flex justify-content-center align-items-center gap-3 flex-wrap">';
$beginHybridHTML = true;
$head_content .= "<link rel='stylesheet' type='text/css' href='{$urlServer}template/modern/css/bootstrap-social.css'>";
foreach ($hybridProviders as $provider) {
if ($beginHybridHTML) {
$beginHybridHTML = false;
} else {
$authLinks[$hybridLinkId]['html'] .= '<br>';
}
$provider_link = $provider;
if($provider_link == 'live'){
$provider_link = 'microsoft';
}
$authLinks[$hybridLinkId]['html'] .=
"<a class='btn submitAdminBtnDefault btn-$provider_link social-btn m-2 d-inline-flex' href='{$urlServer}index.php?provider=$provider'><img src='$themeimg/$provider.png' alt='Sign-in with $provider' style='margin-right: 0.5em;'>" . ucfirst($provider) . "</a>";
}
$authLinks[$hybridLinkId]['html'] .= '</div>';
}
$data['authLinks'] = $authLinks;
$head_content .= "
<script>
$(function() {
$('#revealPass').mousedown(function () {
$('#pass').attr('type', 'text');
}).mouseup(function () {
$('#pass').attr('type', 'password');
})
});
</script>
<link rel='alternate' type='application/rss+xml' title='RSS-Feed' href='{$urlServer}rss.php'>";
}
if (!($upgrade_begin or get_config('dont_display_login_form'))) {
if (count($authLinks) > 3) {
// home page login form with more than 3 buttons not supported
$data['authLinks'] = array($authLinks[0]);
}
}
$data['total_collaboration_courses'] = Database::get()->querySingle("SELECT COUNT(*) AS total FROM course WHERE is_collaborative = ?d",1)->total;
$data['popular_courses'] = Database::get()->queryArray('SELECT * FROM `course`
WHERE `popular_course` = ?d AND `visible` != ?d AND lang=?s', 1, 3, $language);
$data['announcements'] = Database::get()->queryArray("SELECT `id`, `date`, `title`, `body`, `order` FROM `admin_announcement`
WHERE `visible` = 1
AND `important` = 0
AND lang=?s
AND (`begin` <= NOW() or `begin` IS null)
AND (NOW() <= `end` or `end` IS null)
ORDER BY `order` DESC", $language);
$data['texts'] = Database::get()->queryArray("SELECT * FROM `homepageTexts` WHERE `lang` = ?s AND `type` = ?d ORDER BY `order` ASC",$language,1);
$data['testimonials'] = Database::get()->queryArray("SELECT * FROM `homepageTexts` WHERE `lang` = ?s AND `type` = ?d ORDER BY `order` ASC",$language,2);
$data['auth_enabled_method'] = 0;
$active_method = Database::get()->queryArray("SELECT * FROM auth WHERE auth_default = ?d OR auth_default = ?d",1,2);
if(count($active_method) > 0){
$data['auth_enabled_method'] = 1;
}
//priotities
$priority_order = 0;
$priorities = Database::get()->queryArray("SELECT `title` FROM `homepagePriorities` ORDER BY `order` ASC");
if(count($priorities) > 0){
foreach($priorities as $p){
if($p->title == 'announcements'){
$data['announcements_priority'] = $priority_order;
}elseif($p->title == 'popular_courses'){
$data['popular_courses_priority'] = $priority_order;
}elseif($p->title == 'texts'){
$data['texts_priority'] = $priority_order;
}elseif($p->title == 'testimonials'){
$data['testimonials_priority'] = $priority_order;
}elseif($p->title == 'statistics'){
$data['statistics_priority'] = $priority_order;
}else{
$data['open_courses_priority'] = $priority_order;
}
$priority_order++;
}
}
$data['dateFormatLong'] = $dateFormatLong;
$data['home_main_area_widgets'] = '';
$home_main_area = new WidgetArea(HOME_PAGE_MAIN);
$data['home_main_area_widgets'] = '';
foreach ($home_main_area->getWidgets() as $key => $widget) {
$data['home_main_area_widgets'] .= $widget->run($key);
}
// display extras right
$data['extra_right'] = $langExtrasRight ?:false;
// display online users
$data['online_users'] = getOnlineUsers();
if (!isset($openCoursesExtraHTML)) {
$openCoursesExtraHTML = '';
setOpenCoursesExtraHTML();
$data['openCoursesExtraHTML'] = $openCoursesExtraHTML;
}
$data['home_page_sidebar_widgets'] = '';
$home_page_sidebar = new WidgetArea(HOME_PAGE_SIDEBAR);
$data['home_page_sidebar_widgets'] = '';
foreach ($home_page_sidebar->getWidgets() as $key => $widget) {
$data['home_page_sidebar_widgets'] .= $widget->run($key);
}
view('home.index', $data);
}