-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
259 lines (259 loc) · 14.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
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
<?php
session_start();
if (!isset($_SESSION["username"])) {
if ($_SERVER['REMOTE_ADDR'] == "::1") {
header("Location: login.php");
} else {
header("Location: https://x.minet.co/login");
}
}
file_exists("class.php") ? include "class.php" : include "../class.php";
if ($_SERVER['REMOTE_ADDR'] == "::1") {
DB::$user = "root";
DB::$password = "";
DB::$dbName = "minet";
} else {
DB::$user = "classkwo_paya";
DB::$password = "anand01";
DB::$dbName = "classkwo_minet";
}
function _ago($tm, $rcs = 0) {
$cur_tm = time(); $dif = $cur_tm-$tm;
$pds = array('second','minute','hour','day','week','month','year','decade');
$lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
$no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm);
return $x;
}
?><!doctype html>
<html>
<head>
<?php include "backend/header.php"; ?>
</head>
<body class="big">
<div class="update_time"></div>
<header id="masthead">
<div class="container">
<div class="half">
<a href="index.php" class="logo">
MINET
</a>
</div>
<div class="half">
<nav>
<ul>
<li class="active"><a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "index.php" : "https://x.minet.co"; ?>">Dashboard</a></li>
<li><a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "profile.php" : "https://x.minet.co/profile"; ?>">Profile</a></li>
<li><a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "startups.php" : "https://x.minet.co/startups"; ?>">Startups</a></li>
<li><a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "settings.php" : "https://x.minet.co/settings"; ?>">Settings</a></li>
<li><a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "logout.php" : "https://x.minet.co/logout"; ?>">Log out</a></li>
</ul>
</nav>
</div>
</div>
</header>
<div class="container">
<div class="row">
<div class="half">
<div class="card">
<h3>School Info</h3>
<p class="startup-info">
<?php
$results = DB::query("SELECT * FROM teams WHERE username = %s LIMIT 1", $_SESSION["username"]);
foreach ($results as $row) {
$address = $row["school_address"];
$email = $row["email"];
$invitecode = $row["invitecode"];
if (isset($row["slack_email"])) {
$slack_email = $row["slack_email"];
} else {
$slack_email = "Unavailable";
}
$phone = $row["phone"];
}
?>
<strong>Institution</strong><?php echo $_SESSION["school_name"]; ?><br>
<strong>Address</strong><?php echo $address; ?><br>
<strong>Email</strong><a href="mailto:<?php echo $email; ?>"><?php echo $email; ?></a><br>
<strong><a style="color:inherit" href="https://minet-x.slack.com" target="_blank"><img src="https://www.firangana.com/non-wp-includes/favicon.php?url=slack.com" style="margin-right: 10px; vertical-align: middle">Login</a></strong>Username: <?php echo $slack_email; ?><br>
<strong> </strong>Password: <?php echo $invitecode; ?><br>
</p>
<div class="help-link">
<a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "settings.php" : "https://x.minet.co/settings"; ?>">Edit</a>
</div>
</div>
<div class="card">
<div class="eventlog">
<h3>Events</h3>
<?php
$results = DB::query("SELECT * FROM eventlog WHERE username = %s ORDER BY id DESC LIMIT 5", $_SESSION["username"]);
$nResults = 0;
foreach ($results as $row) {
echo '
<div class="event">
<div>
You ' . $row["verb"] . ' your ' . $row["event"] . '.
</div>
<div class="sub">
<span>' . ucfirst($row["category"]) . '</span> ·
' . _ago($row["datetime"]) . ' ago
</div>
</div>
';
}
?>
<div class="help-link">
<a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "events.php" : "https://x.minet.co/events"; ?>">Details</a>
</div>
</div>
</div>
</div>
<div class="half">
<div class="card">
<div class="help-link">
<a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "stock.php" : "https://x.minet.co/stock"; ?>">Details</a>
</div>
<h3 style="margin-bottom: 0">Stock Price</h3>
<div class="big up" id="stock_price">
<?php
$result = DB::query("SELECT stock_price from prices WHERE team_id = %s ORDER BY id DESC LIMIT 1", $_SESSION["id"]);
foreach ($result as $row) {
$price = $row["stock_price"];
$random = mt_rand(1, 99);
$random = $random < 10 ? "0" . $random : $random;
$random_price = mt_rand(0, 5);
if (mt_rand(0, 1) > 0) {
$finalPrice = $price + $random_price;
$class = "up";
} else {
$finalPrice = $price - $random_price;
$class = "down";
}
}
echo $finalPrice . "." . $random;
?>
</div>
<div class="row">
<div class="half">
<p>
Current Average: <strong>₹ <?php
$result = DB::query("SELECT stock_price from prices WHERE team_id = %s ORDER BY id DESC LIMIT 1", $_SESSION["id"]);
foreach ($result as $row) {
echo $row["stock_price"];
}
?></strong>
</p>
</div>
<div class="half">
<p>
All-time Average: <strong>₹ <?php
$result = DB::query("SELECT stock_price from prices WHERE team_id = %s", $_SESSION["id"]);
$sum = 0; $i = 0;
foreach ($result as $row) {
$i++;
$sum += intval($row["stock_price"]);
}
echo $sum / $i;
?></strong>
</p>
</div>
</div>
<div class="row">
<div class="half">
<p style="margin-top: 0">
All-time High: <strong>₹ <?php
$result = DB::query("SELECT stock_price from prices WHERE team_id = %s ORDER BY stock_price DESC LIMIT 1", $_SESSION["id"]);
foreach ($result as $row) {
echo $row["stock_price"];
}
?></strong>
</p>
</div>
<div class="half">
<p style="margin-top: 0">
All-time Low: <strong>₹ <?php
$result = DB::query("SELECT stock_price from prices WHERE team_id = %s ORDER BY stock_price ASC LIMIT 1", $_SESSION["id"]);
foreach ($result as $row) {
echo $row["stock_price"];
}
?></strong>
</p>
</div>
</div>
</div>
<div class="card teams">
<div class="help-link">
<a href="<?php echo $_SERVER['REMOTE_ADDR'] == "::1" ? "team.php" : "https://x.minet.co/team"; ?>">Edit</a>
</div>
<h3>Team</h3>
<div class="row team">
<?php
$result = DB::query("SELECT * FROM teams WHERE id = %s", $_SESSION["id"]);
$n_participants = 0;
foreach ($result as $row) {
$events = array("design", "programming", "quiz", "gaming", "speaking");
foreach ($events as $event) {
for ($i = 1; $i < 4; $i++) {
$i_row = $event . "_participant_" . $i;
if (isset($row[$i_row . "_name"])) {
if ($row[$i_row . "_name"] != "") {
$n_participants++;
echo '
<div class="half">
<p>
<img src="https://www.gravatar.com/avatar/' . md5($row[$i_row . "_email"]) . '?d=retro">
' . $row[$i_row . "_name"] . '
</p>
</div>
';
}
}
}
}
}
if ($n_participants == 0) {
echo "
<div style='text-align:center'>
<p>
<img style='float: none; border-radius: 0; background: none; width: 50%; height: auto; opacity: 0.5' alt='' src='img/sleeper.png'>
</p>
<p style='color:#aaa'>You haven’t added your team yet.</p>
<p>
<a class='button' href='" .
"https://x.minet.co/team"
. "'>Add your Team</a>
</p>
</div>
";
} else {
echo "<div style='width:100%;clear:both'></div>";
echo "<p style='color:#aaa'>There are " . $n_participants . " members in your team.</p>";
}
?>
</div>
</div>
</div>
</div>
</div>
<script>
setInterval(function() {
var request0 = new XMLHttpRequest();
request0.open("POST", "api/stock_price.php?team_id=<?php echo $_SESSION["id"]; ?>", true);
request0.send();
request0.onload = function() {
var previousPrice = document.querySelector("#stock_price").innerHTML;
document.querySelector("#stock_price").innerHTML = request0.responseText;
if (parseInt(request0.responseText) > parseInt(previousPrice)) {
document.querySelector("#stock_price").classList.add("up");
document.querySelector("#stock_price").classList.remove("down");
} else {
document.querySelector("#stock_price").classList.remove("up");
document.querySelector("#stock_price").classList.add("down");
}
}
}, 30000);
</script>
<?php include "backend/footer.php"; ?>
</body>
</html>