-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
217 lines (188 loc) · 8.3 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
<!DOCTYPE html>
<html>
<head>
<?php include 'assets/partials/head.php' ?>
</head>
<body>
<?php
$pg = ($_GET["pg"] == NULL)? 1: $_GET["pg"];
$obj = new ArchiveDatabase(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE);
$res = $obj->getImages(True, 12, 12 * ($pg - 1));
$count = $res[1]; // Advance search return an array, with the number of results in #1 and the data on #0
$data = $res[0];
$picsCounter = $obj->getObservationCount();
?>
<!-- Navigation -->
<?php include 'assets/partials/navbar.php'?>
<div class="jumbotron jumbotron-fluid my-jumbotron">
<div class="container">
<div class="float-right" style="width: 18rem;">
<div class="alert stats" role="alert" data-toggle="tooltip" data-placement="top" title="<?php echo JUMBO_IM_TOOLTIP; ?>">
<?php
$length = count($picsCounter);
$total = ($length == 1)?$picsCounter[0][1]:0;
if($length > 1){
for($i = 0; $i < $length; $i++){
echo "<b>" . $picsCounter[$i][0] . "</b>: " . $picsCounter[$i][1] . " images <br>";
$total += $picsCounter[$i][1];
}
}
echo "<b>" . JUMBO_IM . "</b>: " . $total . "<br>";
?>
</div>
</div>
<h1 class="display-4">Archive Viewer</h1>
<p class="lead"><?php echo JUMBOTRON; ?></p>
</div>
</div>
<!-- Page Content -->
<div class="container mt-3">
<!-- Page Features -->
<div class="row text-center main-block">
<?php
if($res != NULL){
foreach($data as $pic){
$avrRate = $pic->getRate();
$formatedRate = ($avrRate != "")?number_format($avrRate, 1): "";
$rateText = MODAL_RATE;
if(substr ( $_SERVER [ "HTTP_ACCEPT_LANGUAGE" ], 0 , 2 ) == "es"){
$modalTitle = MODAL_TITLE1 . " " . $pic->getMetadata()->getSource() . " " . MODAL_TITLE2 . " " . $pic->getObservatory()->getName();
} else {
$modalTitle = $pic->getMetadata()->getSource() . " " . MODAL_TITLE . " " . $pic->getObservatory()->getName();
}
echo <<<END
<div class="col-lg-3 col-md-6">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#imageModal" data-title="{$modalTitle}" data-image-id="{$pic->getId()}" data-image-src={$pic->getExtSrc()} data-date-obs="{$pic->getDateObs()}"
data-date-updated="{$pic->getDateUpdated()}" data-observatory="{$pic->getObservatory()->getName()}" data-observatory-lat="{$pic->getMetadata()->getLatitude()}"
data-observatory-long="{$pic->getMetadata()->getLongitud()}" data-observatory-alt="{$pic->getMetadata()->getAltitude()}" data-telecop="{$pic->getMetadata()->getTelescop()}" data-instrume="{$pic->getMetadata()->getInstrume()}"
data-exposure="{$pic->getMetadata()->getExposure()}" data-filter="{$pic->getMetadata()->getFilter()}" data-source="{$pic->getMetadata()->getSource()}" data-rate="{$formatedRate}" data-rate-text="{$rateText}">
<div class="card" style="width: 15rem;">
<img class="card-img-top" src="{$pic->getExtSrc()}" alt="Card image cap">
<div class="card-body">
<p class="card-text"> {$pic->getMetadata()->getSource()} - {$pic->getDateObs()}</p>
</div>
</div>
</button>
</div>
END;
}
} else { // There is no coincidences
echo "There is no coincidences";
}
?>
</div>
<!-- /.row -->
<?php // Pagination scripts
$displayPagination = ceil($count/12) > 1;
if($displayPagination){
$pgCounterPerPage = ($ismobile)? 5: 1; // Var on head for detect mobile
// With count put the number above
$pgCounter = ($pg < $pgCounterPerPage + 1)? 1: $pg - $pgCounterPerPage;
$maxCounter = ceil($count/12);
// Next Button
$query = $_GET;
$query['pg'] = $pg + 1;
$nextPg = "?" . http_build_query($query);
// Previous Button
$query = $_GET;
$query['pg'] = $pg - 1;
$prevPg = "?" . http_build_query($query);
$previousDisabled = ($pg == 1)? "disabled":"";
$nextDisabled = ($pg == $maxCounter)? "disabled":"";
echo "<nav aria-label=\"Page navigation example\">
<ul class=\"pagination justify-content-center\">
<li class=\"page-item {$previousDisabled}\">
<a class=\"page-link\" href=\"{$prevPg}\" tabindex=\"-1\">" . PAGINATION_PREV . "</a>
</li>";
// Last index button link
$query = $_GET;
$query['pg'] = $maxCounter;
$lastlink = "?" . http_build_query($query);
// First index button link
$query = $_GET;
$query['pg'] = 1;
$firstlink = "?" . http_build_query($query);
for(; $pgCounter <= $maxCounter ; $pgCounter++){
$query = $_GET;
$query['pg'] = $pgCounter;
$link = "?" . http_build_query($query);
//If there are a lot of results then put a button and exit
if($pgCounter > $pg + $pgCounterPerPage){
echo <<<END
<li class="page-item"><a class="page-link">...</a></li>
END;
echo <<<END
<li class="page-item"><a class="page-link" href="{$lastlink}">{$maxCounter}</a></li>
END;
break;
}
if($pgCounter == $pg - $pgCounterPerPage){
echo <<<END
<li class="page-item"><a class="page-link" href="{$firstlink}">1</a></li>
END;
echo <<<END
<li class="page-item"><a class="page-link">...</a></li>
END;
} elseif ($pg == $pgCounter) {
echo <<<END
<li class="page-item active"><a class="page-link" href="{$link}">{$pgCounter}</a></li>
END;
} elseif($pgCounter != $pg + $pgCounterPerPage){
echo <<<END
<li class="page-item"><a class="page-link" href="{$link}">{$pgCounter}</a></li>
END;
}
}
echo "<li class=\"page-item {$nextDisabled}\">
<a class=\"page-link\" href=\"{$nextPg}\">" . PAGINATION_NEXT . "</a>
</li>
</ul>
</nav>";
}
?>
<!-- /.container -->
</div>
<!-- Footer -->
<?php include 'assets/partials/footer.php'?>
<!-- Modal -->
<div class="modal fade" id="imageModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md">
<img class="card-img-top" src="#" alt="">
<div class="rate-item" id="ratecont">
<div class="rate"></div>
</div>
</div>
<div class="col-sm">
<ul class="list-group list-group-flush" id="properties">
<li class="list-group-item"><b><?php echo MODAL_DATE;?>: </b> <a id="date-uploaded"></a></li>
<li class="list-group-item"><b><?php echo MODAL_TELESCOPE;?>:</b> <a id="telescope"></a> </li>
<li class="list-group-item"><b><?php echo MODAL_FILTER;?>:</b> <a id="filter"></a> </li>
<li class="list-group-item"><b><?php echo MODAL_CAMERA;?>:</b> <a id="instrume"></a></li>
<li class="list-group-item"><b><?php echo MODAL_TIME_EXP;?>:</b> <a id="exposure"></a></li>
<li class="list-group-item"><b><?php echo MODAL_LAT;?>:</b> <a id="lat"></a></li>
<li class="list-group-item"><b><?php echo MODAL_LONG;?>:</b> <a id="long"></a></li>
<li class="list-group-item"><b><?php echo MODAL_ALT;?>:</b> <a id="alt"></a></li>
<li class="list-group-item" id="rateitem"><b><?php echo MODAL_RATE;?>:</b> <a id="ratetext"></a></li>
</ul>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo MODAL_CLOSE; ?></button>
<a href="#" class="btn btn-primary" tabindex="-1" role="button" aria-disabled="true"><?php echo MODAL_MOREINFO; ?></a>
</div>
</div>
</div>
</div>
</body>
</html>