forked from pinico42/revi.se
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
108 lines (87 loc) · 2.72 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
<?php
// Copyright © 2014 Max Penrose
?>
<?php
include 'private/pwds.php';
if(!isset($_COOKIE['email']) || !isset($_COOKIE['pwd'])){ // not logged in
header('Location: login.php'); // to login screen
} else { // security - check cookie details are correct
$conn = mysqli_connect('localhost',$mysqlUsername,$mysqlPassword,'revise');
$q = 'SELECT * FROM accounts WHERE email = "'.$_COOKIE['email'].'" AND pwd = "'.$_COOKIE['pwd'].'";';
$query = mysqli_query($conn, $q);
$qArray = mysqli_fetch_array($query, MYSQLI_ASSOC);
if(is_null($qArray)){
header('Location: login.php'); //to login screen
setcookie("email", "", time()-3600);
setcookie("pwd", "", time()-3600);
}
}
?>
<?php // basic header
include "layouts.php";
$l = getLayout("basic.layout");
$l->writeHeader();
?>
<?php
function get_json($path){
$subjectsFile = fopen($path,'r');
$json = fread($subjectsFile,filesize($path));
$subjectsObj = json_decode($json,true);
fclose($subjectsFile);
return $subjectsObj;
}
$subjectsObj = get_json("private/subjects.json"); // contains the users subjects
$email = $_COOKIE['email'];
$usersSubjects = $subjectsObj[$email];
$topics = get_json("private/topics.json");
$usersTopics = $topics[$email];
$subjectImages = array(
"Art" => "images/subjects/art.png",
"Biology" => "images/subjects/biology.png",
"Chemistry" => "images/subjects/chemistry.png",
"English Language" => "images/subjects/englishlang.png",
"English Literature" => "images/subjects/englishlit.png",
"French" => "images/subjects/french.png",
"Geography" => "images/subjects/geography.png",
"German" => "images/subjects/german.png",
"Greek" => "images/subjects/greek.png",
"History" => "images/subjects/history.png",
"Latin" => "images/subjects/latin.png",
"Maths" => "images/subjects/maths.png",
"Music" => "images/subjects/music.png",
"Physics" => "images/subjects/physics.png",
"Religious Studies" => "images/subjects/relegiousstudies.png",
"Spanish" => "images/subjects/spanish.png",
);
?>
<h1 class='title'>Your Subjects</h1>
<div id='subjects'>
<?php
foreach($usersSubjects as $subject){
$r = rand(1,4);
if($r == 4){ $r = 5; }
$s = "";
if(sizeof($usersTopics[$subject['Name']]) != 1){
$s = "s";
}
echo "
<a class='flip-container' href='topics.php?s=".$subject['Name']."'>
<div class='flipper'>
<div class='front c$r' style='background-image:url(".$subjectImages[$subject["Name"]].")'>
<!--<img src='".$subjectImages[$subject["Name"]]."' width='40%' height='40%'>-->
</div>
<div class='back c$r'>
<div class='fContent'>
<h3>".$subject['Name']."</h3>
<h4>".sizeof($usersTopics[$subject['Name']])." Topic$s</h4>
</div>
</div>
</div>
</a>
";
}
?>
</div>
<?php
$l->writeFooter();
?>