Allow news sorting on main page

pull/9/head
esensar 2016-05-22 23:25:21 +02:00
parent daae4ba6d0
commit 86a0af1c83
5 changed files with 37 additions and 9 deletions

View File

@ -85,10 +85,12 @@
</select>
</li>
<li class="headerItem">
<select id="sort" name="sort" onchange="onSort(this.value)">>
<option value="date">Sortiraj po datumu</option>
<option value="alpha">Sortiraj abecedno</option>
</select>
<form method="post">
<select id="sort" name="sort" onchange="onSortChanged(this)">>
<option value="date" <?php echo (!isset($_POST['sort']) || strpos("date", $_POST['sort'])!==FALSE)?"selected":null?>>Sortiraj po datumu</option>
<option value="alpha" <?php echo (isset($_POST['sort']) && strpos("alpha", $_POST['sort'])!==FALSE)?"selected":null?>>Sortiraj abecedno</option>
</select>
</form>
</li>
<?php endif; ?>
</ul>

View File

@ -4,13 +4,30 @@
<?php include 'header.php'; ?>
<div class="content">
<?php $newsFile = file($openShiftFolder."vijesti.csv");
foreach ($newsFile as $news) {?>
$imagesArray = [];
$newsArray = [];
$timesArray = [];
$counter = 0;
foreach ($newsFile as $news) {
$nesto = str_getcsv($news);
$timesArray[$counter] = $nesto[0];
$imagesArray[$counter] = $nesto[1];
$newsArray[$counter] = $nesto[2];
$counter++;
}
if(isset($_POST['sort'])) {
if($_POST['sort']=='alpha') {
print_r('alpha');
array_multisort($newsArray, SORT_STRING, $imagesArray, $timesArray);
}
}
for($i = 0; $i < $counter; $i++) {
?>
<div class="news">
<?php
$nesto = str_getcsv($news);
$image = $nesto[1];
$timeOfNews = $nesto[0];
$newsContent = $nesto[2];
$image = $imagesArray[$i];
$timeOfNews = $timesArray[$i];
$newsContent = $newsArray[$i];
?>
<img src="<?php echo (strlen($image)!=0)?$image:'no_image.png' ?>"/>
<p>

4
js.js
View File

@ -89,6 +89,10 @@ function onFilter(select) {
}
}
function onSortChanged(thisThing) {
thisThing.parentElement.submit();
}
function validateCountry(countryCodeField) {
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

View File

@ -104,6 +104,11 @@ border-color: transparent transparent transparent #1199CC;
margin: auto;
}
.headerItem form {
display: inline-block;
margin: auto;
}
.logoLinl {
text-decoration: none;
}