Repository navigation
Expand file tree
/
Copy pathmotd.php
More file actions
58 lines (50 loc) · 1.94 KB
/
Copy pathmotd.php
File metadata and controls
58 lines (50 loc) · 1.94 KB
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
<?php
if (!defined('index_origin'))
{
http_response_code(404);
die();
}
?>
<?php
$querylastchange = "SELECT quoteid,`change` FROM motd ORDER BY id DESC LIMIT 1;";
$resultlastchange = mysqli_query($db, $querylastchange);
$lastchangerow = mysqli_fetch_array($resultlastchange);
$lastchange = $lastchangerow['change'];
$lastquoteid = $lastchangerow['quoteid'];
$currentdate = date('Y-m-d');
if ($lastchange == $currentdate) {
$querymotd = "SELECT quote FROM quotes INNER JOIN motd ON quotes.id = motd.quoteid WHERE motd.quoteid = ?;";
$prepmotd = mysqli_prepare($db, $querymotd);
mysqli_stmt_bind_param ($prepmotd, 'i', $lastquoteid);
mysqli_stmt_execute($prepmotd);
$resultmotd = mysqli_stmt_get_result($prepmotd);
$motdrow = mysqli_fetch_array($resultmotd);
$motd = $motdrow['quote'];
echo htmlspecialchars($motd);
}
else {
$queryquotes = "SELECT id FROM quotes LIMIT 1;";
$resultquotes = mysqli_query($db, $queryquotes);
$resultquotes_count = mysqli_num_rows($resultquotes);
if ($resultquotes_count == 1)
{
$querysetmotd = "INSERT INTO motd (`change`, quoteid) SELECT curdate(), quotes.id FROM quotes ORDER BY quotes.lastused LIMIT 1;";
$resultsetmotd = mysqli_query($db, $querysetmotd);
$querynewmotd = "SELECT quoteid FROM motd ORDER BY id DESC LIMIT 1;";
$resultnewmotd = mysqli_query($db, $querynewmotd);
$newmotdrow = mysqli_fetch_array($resultnewmotd);
$newmotdid = $newmotdrow['quoteid'];
$queryupdatequote = "UPDATE quotes SET lastused = curdate() WHERE id = ?;";
$prepupdatequote = mysqli_prepare($db, $queryupdatequote);
mysqli_stmt_bind_param ($prepupdatequote, 'i', $newmotdid);
mysqli_stmt_execute($prepupdatequote);
$resultupdatequote = mysqli_stmt_get_result($prepupdatequote);
}
else
{
$queryaddquote = "INSERT INTO quotes (quote) VALUE ('Add your first quote!');";
$resultaddquote = mysqli_query ($db, $queryaddquote);
}
header("Location: http://$_SERVER[HTTP_HOST]");
}
?>