forked from maellak/openeclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
220 lines (199 loc) · 8.5 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
<?php
session_start();
/* ========================================================================
* Open eClass 3.0
* E-learning and Course Management System
* ========================================================================
* Copyright 2003-2014 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: info@openeclass.org
* ======================================================================== */
/*
* @file index.php
*
* @abstract This file serves as the home page of eclass when the user
* is not logged in.
*
*/
define('HIDE_TOOL_TITLE', 1);
$guest_allowed = true;
require_once 'include/baseTheme.php';
require_once 'include/CAS/CAS.php';
require_once 'modules/auth/auth.inc.php';
require_once 'include/lib/textLib.inc.php';
require_once 'include/phpass/PasswordHash.php';
// $homePage is used by baseTheme.php to parse correctly the breadcrumb
$homePage = true;
// check if we can connect to database. If not then eclass is most likely not installed
if (isset($mysqlServer) and isset($mysqlUser) and isset($mysqlPassword) && !Database::get()) {
require_once 'include/not_installed.php';
}
// unset system that records visitor only once by course for statistics
require_once 'include/action.php';
if (isset($dbname)) {
$action = new action();
$action->record('MODULE_ID_UNITS', 'exit');
}
unset($dbname);
// if we try to login... then authenticate user.
$warning = '';
if (isset($_SESSION['shib_uname'])) {
// authenticate via shibboleth
shib_cas_login('shibboleth');
} elseif (isset($_SESSION['cas_uname']) && !isset($_GET['logout'])) {
// authenticate via cas
shib_cas_login('cas');
} else {
// normal authentication
process_login();
}
if (isset($_SESSION['uid'])) {
$uid = $_SESSION['uid'];
} else {
$uid = 0;
}
if (isset($_GET['logout']) and $uid) {
Database::get()->query("INSERT INTO loginout (loginout.id_user,
loginout.ip, loginout.when, loginout.action)
VALUES (?d, ?s, NOW(), 'LOGOUT')", $uid, $_SERVER['REMOTE_ADDR']);
if (isset($_SESSION['cas_uname'])) { // if we are CAS user
define('CAS', true);
}
foreach (array_keys($_SESSION) as $key) {
unset($_SESSION[$key]);
}
session_destroy();
$uid = 0;
if (defined('CAS')) {
$cas = get_auth_settings(7);
if (isset($cas['cas_ssout']) and intval($cas['cas_ssout']) === 1) {
phpCAS::client(SAML_VERSION_1_1, $cas['cas_host'], intval($cas['cas_port']), $cas['cas_context'], FALSE);
phpCAS::logoutWithRedirectService($urlServer);
}
}
}
// 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 ($extra_messages) {
include $extra_messages;
}
}
// check if we are guest user
if ($uid AND !isset($_GET['logout'])) {
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 not guest redirect him to portfolio
header("Location: {$urlServer}main/portfolio.php");
} else {
$rss_link = "<link rel='alternate' type='application/rss+xml' title='RSS-Feed' href='" .
$urlServer . "rss.php'>";
$tool_content .= "<p align='justify'>$langInfoAbout</p>";
$announceArr = Database::get()->queryArray("SELECT `id`, `date`, `title`, `body`, `order` FROM `admin_announcement`
WHERE `visible` = 1
AND lang=?s
AND (`begin` <= NOW() or `begin` IS null)
AND (NOW() <= `end` or `end` IS null)
ORDER BY `order` DESC", $language);
if ($announceArr && sizeof($announceArr) > 0) {
$tool_content .= "
<br />
<table width='100%' class='tbl_alt'>
<tr>
<th colspan='2'>$langAnnouncements <a href='${urlServer}rss.php'>
<img src='$themeimg/feed.png' alt='RSS Feed' title='RSS Feed' />
</a>
</th>
</tr>";
$numOfAnnouncements = sizeof($announceArr);
for ($i = 0; $i < $numOfAnnouncements; $i++) {
$aid = $announceArr[$i]->id;
$tool_content .= "
<tr>
<td width='1'><img style='border:0px;' src='$themeimg/arrow.png' alt='' /></td>
<td>
<b><a href='modules/announcements/main_ann.php?aid=$aid'>" . q($announceArr[$i]->title) . "</a></b>
<span class='smaller'>(" . claro_format_locale_date($dateFormatLong, strtotime($announceArr[$i]->date)) . ")</span>
" . standard_text_escape(ellipsize_html($announceArr[$i]->body, 500, "<strong> <a href='modules/announcements/main_ann.php?aid=$aid'>... <span class='smaller'>[$langMore]</span></a></strong>")) . "
</td>
</tr>";
}
$tool_content .= "</table>";
}
// check for shibboleth authentication
$shibactive = Database::get()->querySingle("SELECT auth_default FROM auth WHERE auth_name='shibboleth'")->auth_default;
if ($shibactive == 1) {
$shibboleth_link = "<a href='{$urlSecure}secure/index.php'>$langShibboleth</a><br />";
} else {
$shibboleth_link = "";
}
// check for CAS authentication
$casactive = Database::get()->querySingle("SELECT auth_default FROM auth WHERE auth_name='cas'")->auth_default;
if ($casactive == 1) {
$cas_link = "<a href='{$urlServer}secure/cas.php'>$langViaCAS</a><br />";
} else {
$cas_link = "";
}
$tool_content .= "</div><div id='rightbar'>";
if (!get_config('dont_display_login_form')) {
$tool_content .= "
<form action='$urlSecure' method='post'>
<table width='100%' class='tbl'>
<tr>
<th class='LoginHead'><b>$langUserLogin </b></th>
</tr>
<tr>
<td class='LoginData'>
$langUsername <br />
<input class='Login' name='uname' size='17' /><br />
$langPass <br />
<input class='Login' name='pass' type = 'password' size = '17' autocomplete='off' /><br /><br />
<input class='Login' name='submit' type = 'submit' size = '17' value = '" . q($langEnter) . "' autocomplete='off' /><br />
$warning</td></tr>
<tr><td><p class='smaller'><a href='modules/auth/lostpass.php'>$lang_forgot_pass</a></p>
</td>
</tr>";
if (!empty($shibboleth_link) or !empty($cas_link)) {
$tool_content .= "<tr><th class='LoginHead'><b>$langAlternateLogin </b></th></tr>";
}
$tool_content .= "<tr><td class='LoginData'>
$shibboleth_link
$cas_link</td></tr>";
$online_users = getOnlineUsers();
if ($online_users > 0) {
$tool_content .= "<th class='LoginHead'><br />$langOnlineUsers: $online_users</th>";
}
$tool_content .= "</table></form>";
}
$tool_content .= "<div id='extra'>{%ECLASS_HOME_EXTRAS_RIGHT%}</div>";
draw($tool_content, 0, null, $rss_link);
}