-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
201 lines (147 loc) · 7.06 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
<?php
/**
* File: routing.php
* Created by Yiannis Kiranis <[email protected]>
* http://www.apps4net.eu
* Date: 17/04/16
* Time: 01:17
*/
use apps4net\framework\Language;
use apps4net\framework\MyDB;
use apps4net\framework\User;
use apps4net\framework\Page;
use apps4net\framework\Logs;
use apps4net\framework\Utilities;
require_once('src/boot.php');
session_start();
MyDB::checkMySqlTables(); // Έλεγχος των tables στην βάση
MyDB::checkMySqlForTypeChanges(); // Έλεγχος για αλλαγμένα πεδία στην βάση
$lang = new Language();
// Έλεγχος αν τρέχουν τα routing rules, αναλόγως τον web server
Utilities::checkWebServerForRoutingRules();
$phrasesForJavascript = json_encode($lang->getPhrasesTable());
// έλεγχος αν έχει πατηθεί link για αλλαγής της γλώσσας
if (isset($_GET['ChangeLang'])) {
$targetPage='Location:index.php';
$lang->change_lang($_GET['ChangeLang']);
header($targetPage);
}
$MainPage = new Page();
$user = new User();
// Τίτλος της σελίδας
$MainPage->tittle = APP_NAME;
$scripts = array (
'src/javascript/framework/jquery-3.2.1.min.js', // jquery
'src/javascript/framework/variables.js', // Javascript public variables
'src/javascript/framework/_jqueryExtensions.js', // jQuery extensions
'src/javascript/framework/_utilities.js', // Utility functions
'src/javascript/framework/_forms.js', // Forms functions
'src/javascript/framework/_users.js', // Users management functions
'src/javascript/framework/scripts.js', // framework scripts
'src/javascript/app/scripts.js', // app scripts
'src/javascript/app/_shortcuts.js', // Shortcut actions
'src/javascript/app/_video.js', // Video element management
'src/javascript/app/_youtube.js', // Youtube downloading
'src/javascript/app/_progressAnimation.js', // Το progress animation
'src/javascript/app/_uploadFiles.js', // Uploading αρχείων
// TODO να φύγει το polyfill κάποια στιγμή που θα το υποστηρίζουν κανονικά όλοι οι browsers
'src/javascript/framework/details.js', // polyfill για το summary/details
'src/javascript/framework/jquery.validate.min.js', // extension του jquery για form validation
'src/javascript/framework/nodep-date-input-polyfill.dist.js', // date input type polyfill. https://github.com/brianblakely/nodep-date-input-polyfill
'src/javascript/framework/pattern.js', // extension για το validate. ενεργοποιεί το validation των patterns
// 'styles/external/popper.js', // popper js @source https://popper.js.org/
'styles/external/bootstrap-4.0.0/js/bootstrap.js' // Bootstrap @source https://getbootstrap.com/
);
$css = array(
// Bootstrap @source https://getbootstrap.com/
'styles/external/bootstrap-4.0.0/css/bootstrap.css',
// Material Design icons @source https://materialdesignicons.com/
'styles/external/MaterialDesign/css/materialdesignicons.css',
'styles/layouts/basic.css'
);
// TODO remove it in the end
$_SESSION['mobile']=false;
// Έλεγχος αν είναι σε mobile ή όχι
//if (!isset($_GET['mobile'])) {
// $css = array('styles/layouts/basic.css');
// $_SESSION['mobile']=false;
//} else {
// $css = array('styles/layouts/mobile.css');
// $_SESSION['mobile']=true;
//}
$MainPage->setScript($scripts);
$MainPage->setCSS($css);
$MainPage->showHeader();
// Αποθηκεύει την IP σε session για τις περιπτώσεις που αλλάζει συνέχεια η IP του χρήστη (π.χ. σε 3g network)
if(!isset($_SESSION['user_IP'])) {
$_SESSION['user_IP'] = $_SERVER['REMOTE_ADDR'];
}
if (isset($_GET['logout'])) {
Logs::insertLog('User Logout'); // Προσθήκη της κίνησης στα logs
$user->logout();
}
// δημιουργεί έναν μοναδικό αριθμό που χρησιμοποιείται στην υπόλοιπη εφαρμογή σαν tab id
define('TAB_ID', date('YmdHis'));
// Περνάει βασικές μεταβλητές στην javascript
?>
<input name='tabID' id='tabID' type='hidden' value='<?php echo TAB_ID; ?>'>
<script type="text/javascript">
var AJAX_path="<?php echo AJAX_PATH; ?>"; // ο κατάλογος των AJAX files
var DIR_PREFIX="<?php echo DIR_PREFIX; ?>";
var Album_covers_path="<?php echo ALBUM_COVERS_DIR; ?>";
var WebFolderPath="<?php echo WEB_FOLDER_PATH; ?>";
var ParrotVersionFile="<?php echo APP_VERSION_FILE; ?>";
var AppVersion="<?php echo APP_VERSION; ?>";
var changeLogUrl="<?php echo CHANGE_LOG_URL; ?>";
var TimePercentTrigger=parseInt(<?php echo PLAY_PERCENTAGE; ?>);
var fwStep=parseInt("<?php echo FW_STEP; ?>");
// Τα κείμενα του site παιρνούνται στην javascript
var phrases=<?php echo $phrasesForJavascript; ?>;
// Το id του τρέχοντος tab
var tabID=document.querySelector('#tabID').value;
</script>
<?php
$logged_in=false;
$userName = null;
// Έλεγχος αν υπάρχει cookie. Αν δεν υπάρχει ψάχνει session
if(!$user->CheckCookiesForLoggedUser()) {
if (User::checkIfUserIsLegit())
{
$userName=$conn->getSession('username');
// session_regenerate_id(true);
$logged_in=true;
}
}
else {
$userName = MyDB::getACookie('username');
$logged_in = true;
if (!isset($_SESSION["username"]))
$conn->setSession('username', $userName);
}
// Αν είναι login κάποιος χρήστης
if($logged_in) {
$LoginNameText = '<div class="row mx-2"><span class="mdi mdi-account-circle mdi-light mdi-24px mdi-form"><span class="px-1">' . $userName . '</span>';
$LoginNameText .= '<a href="?logout=true" title=' . __('logout') . '>
<span id="logout" class="mdi mdi-export mdi-light mdi-24px hasCursorPointer my-auto ">
</a></span></div>';
$MainPage->showMainBar($LoginNameText);
// Αν η σελίδα δεν έχει τρέξει την τελευταία μέρα
if(Page::checkNewPageRunning()) {
if(!MyDB::checkMySQLEventScheduler()) { // Αν δεν είναι ενεργοποιημένος ήδη ο event scheduler
MyDB::enableMySQLEventScheduler(); // Ενεργοποιεί τα scheduler events στην mysql
}
}
$MainPage->DisplayMainPage();
$MainPage->showFooter();
}
// Αν δεν είναι login κάποιος χρήστης
if(!$logged_in) {
if ($user->CheckIfThereIsUsers()) {
$user->showLoginWindow();
} else {
$user->ShowRegisterUser();
}
}
// Δημιουργεί event που σβήνει logs που είναι παλιότερα των 30 ημερών και τρέχει κάθε μέρα
//$eventQuery='DELETE FROM logs WHERE log_date<DATE_SUB(NOW(), INTERVAL 30 DAY)';
//MyDB::createMySQLEvent('logsManage', $eventQuery, '1 DAY');