-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_paperpaging.php
98 lines (79 loc) · 4.65 KB
/
json_paperpaging.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
<?php
require_once("configuration.php");
header('Content-Type: application/json');
if (!isset($_SESSION["LOGIN_USER"]))
{
header('HTTP/1.1 401 Unauthorized');
echo(json_encode(array('error' => 'authentication-needed')));
exit();
}
$page_number = intval($_POST["page"]);
$paper = mysqli_real_escape_string($dataconnection, $_POST["paper"]);
$paperYear = mysqli_real_escape_string($dataconnection, @$_POST["paperPublishYear"]);
$paperMonth = mysqli_real_escape_string($dataconnection, @$_POST["paperPublishMonth"]);
$paperDay = mysqli_real_escape_string($dataconnection, @$_POST["paperPublishDay"]);
$dateLimiter = "";
$dateLimiter2 = "";
$sqllimiter = "";
if (isset($paperYear) && !isset($paperMonth) && !isset($paperDay))
{
$dateLimiter = strtotime('01-01-' . $paperYear);
$dateLimiter2 = strtotime('01-01-' . ($paperYear + 1));
}
else if (isset($paperYear) && isset($paperMonth) && !isset($paperDay))
{
$dateLimiter = strtotime('01-' . $paperMonth . '-' . $paperYear);
$dateLimiter2 = strtotime('01-' . ($paperMonth + 1) . '-' . $paperYear);
}
else if (isset($paperYear) && isset($paperMonth) && isset($paperDay))
{
$dateLimiter = strtotime($paperDay . '-' . $paperMonth . '-' . $paperYear);
$dateLimiter2 = @strtotime(($paperDay + 1) . '-' . $paperMonth . '-' . $paperYear);
$sqllimiter = "LIMIT 1";
}
$position = ($page_number * 20);
$lastPap = $dataconnection->query("SELECT paperID FROM papers WHERE paperBrand = '$paper' ORDER BY paperID DESC LIMIT 1")->fetch_object()->paperID;
$secondCOLOR = $dataconnection->query("SELECT * FROM paper_brands WHERE brandCode = '$paper' LIMIT 1")->fetch_object()->secondColor;
if ($dateLimiter != "")
{
$results = $dataconnection->prepare("SELECT paperID, paperPublished, paperTitle FROM papers WHERE paperBrand = '$paper' AND paperPublished BETWEEN $dateLimiter AND '$dateLimiter2' ");
}
else
{
$results = $dataconnection->prepare("SELECT paperID, paperPublished, paperTitle FROM papers WHERE paperBrand = '$paper' ORDER BY paperID DESC LIMIT $position, 24");
}
$results->execute(); //Execute prepared Query
$results->bind_result($paperID, $paperPublished, $paperTitle); //bind variables to prepared statement
$pageItems = Array();
while($results->fetch()){ //fetch values
$pageItems[] = array("id" => $paperID, "published" => $paperPublished);
/* echo '<a class="paperbutton" style="text-decoration: none; color: white;" href="/paper/' . $paper . '/read/' . $paperID . '" title="' . $paperTitle . '" data-toggle="popover" data-trigger="hover" data-content="Klikkaa lehteä lukeaksesi sitä."><img id="classi" class="paperimage" src="http://www.e-pages.dk/' . $paper . '/' . $paperID . '/pic/tm1.jpg" border="1">
' . ($paperID == $lastPap ? '<div style="position:relative;
text-align:center; height: 30px; top: -125px; background-color: ' . $secondCOLOR . '; font-size: 20px; opacity: 0.95;">uusin</div>' : '<div style="position:relative;
text-align:center; height: 30px; top: -125px; background-color: ' . $secondCOLOR . '; font-size: 20px; opacity: 0.95; text-decoration: none;">' . date('j.n.Y', $paperPublished) . '</div>') . '
</a>';
*/
/*echo '<div class="col-lg-2 col-md-4 col-xs-6 thumb">
<a class="thumbnail" href="/paper/' . $paper . '/read/' . $paperID . '" style="text-decoration: none;">
<img class="img-responsive" src="http://www.e-pages.dk/' . $paper . '/' . $paperID . '/pic/tm1.jpg" onerror="imageError(this);" alt=""><div style="font-family: Open Sans Condensed; font-weight: 300; position:relative;
text-align:center; height: 30px; width: 100px; left: 42px; top: -125px; background-color: ' . $secondCOLOR . '; font-size: 20px; opacity: 0.95; color: white; -webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;">' . date('j.n.Y', $paperPublished) . '</div>
</a>
</div>';
*/
}
$pageArray = Array("paperBrand" => $paper, "page" => $page_number, "brandColor" => $secondCOLOR, "lastPaper" => $lastPap, "items" => $pageItems);
echo json_encode($pageArray, JSON_PRETTY_PRINT);
/*$kohta = $maara-$position;
for ($i = $kohta ; $i >= $kohta-19; $i--) {
if ($i <= 0)
{
continue;
}
echo '<a class="paperbutton" href="/paper/' . $brandCODE . '/read/' . $i . '" title="' . $brandNAME . ' (nro. ' . $i . ')" data-toggle="popover" data-trigger="hover" data-content="Klikkaa lehteä lukeaksesi sitä."><img id="classi" class="paperimage" src="http://www.e-pages.dk/' . $brandCODE . '/' . $i . '/pic/tm1.jpg" border="1">
' . ($maara == $i ? '<div class="paperheader" style="background-color: ' . $secondCOLOR . ';">uusin</div>' : "") . '
</a>';
}
*/
?>