-
Notifications
You must be signed in to change notification settings - Fork 2
/
topics.php
106 lines (85 loc) · 2.3 KB
/
topics.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
<?php
// Copyright © 2014 Max Penrose
?>
<?php
include 'private/pwds.php';
function get_json($path){
$subjectsFile = fopen($path,'r');
$json = fread($subjectsFile,filesize($path));
$subjectsObj = json_decode($json,true);
fclose($subjectsFile);
return $subjectsObj;
}
$email = $_COOKIE['email'];
$topics = get_json("private/topics.json");
$usersTopics = $topics[$email];
if(isset($_GET['s'])){
$currentSubject = $_GET['s'];
} else {
header('Location: index.php');
}
$currentTopic = $usersTopics[$currentSubject];
?>
<?php
include "layouts.php";
$l = getLayout("basic.layout");
$l->writeHeader();
?>
<style>body{
width: auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}</style>
<h1 class='title'>Your Topics</h1>
<div id='topics'>
<?php
foreach($currentTopic as $topicUID){
$conn = mysqli_connect('localhost',$mysqlUsername,$mysqlPassword, 'revise');
$q = "SELECT * FROM topics WHERE uid = '$topicUID';";
$query = mysqli_query($conn, $q);
// if(is_null($query)){
// header('Location: index.php');
// }
$result = mysqli_fetch_array($query, MYSQLI_ASSOC);
mysqli_close($conn);
$name = $result['name'];
$img = $result['img'];
$creator = $result['email'];
$desc = $result['descr'];
$uid = $result['uid'];
$ids = explode($result['ids'], ',');
$idLen = sizeof($ids);
$abilities = get_json('private/abilities.json');
$usersAbilities = $abilities[$email];
$topicsAbility = $usersAbilities[$uid];
$timesDone = $topicsAbility['done'];
$timesCorrect = $topicsAbility['right'];
if($timesDone != 0){
$percentage = ($timesCorrect/$timesDone) * 100;
} else {
$percentage = 213;
}
$bgColor = "hsla(".floor($percentage * 1.30).", 63%, 53%, 1)";
$s = ($idLen != 1 ? 's' : '');
echo $s;
echo "
<div class='topic thin' style='background-color: $bgColor;'>
<img src='$img' alt='' height='30vh' width='30vh'>
<h4>$name</h4>
<p class='topicDesc fade'>$desc</p>
<h5 class='topicCourses fade'>$idLen Course$s</h5>
<a href='quiz.php?u=$uid' class='fade'>Play Quiz</a>
</div>
";
}
?>
<a class='topic new' href='newtopic.php?s=<?php echo $currentSubject; ?>'>
<img src='images/plus.png' height='30vh' width='30vh'>
<h4>New</h4>
</a>
</div>
<script src='topicExpander.js' type='text/javascript'></script>
<?php
$l->writeFooter();
?>