Merge pull request #9 from esensar/news_sorting

Allow news sorting on main page
master
esensar 2016-05-22 23:25:35 +02:00
commit 064aaec0c3
5 changed files with 37 additions and 9 deletions

View File

@ -85,10 +85,12 @@
</select> </select>
</li> </li>
<li class="headerItem"> <li class="headerItem">
<select id="sort" name="sort" onchange="onSort(this.value)">> <form method="post">
<option value="date">Sortiraj po datumu</option> <select id="sort" name="sort" onchange="onSortChanged(this)">>
<option value="alpha">Sortiraj abecedno</option> <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> </select>
</form>
</li> </li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>

View File

@ -4,13 +4,30 @@
<?php include 'header.php'; ?> <?php include 'header.php'; ?>
<div class="content"> <div class="content">
<?php $newsFile = file($openShiftFolder."vijesti.csv"); <?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"> <div class="news">
<?php <?php
$nesto = str_getcsv($news); $image = $imagesArray[$i];
$image = $nesto[1]; $timeOfNews = $timesArray[$i];
$timeOfNews = $nesto[0]; $newsContent = $newsArray[$i];
$newsContent = $nesto[2];
?> ?>
<img src="<?php echo (strlen($image)!=0)?$image:'no_image.png' ?>"/> <img src="<?php echo (strlen($image)!=0)?$image:'no_image.png' ?>"/>
<p> <p>

4
js.js
View File

@ -89,6 +89,10 @@ function onFilter(select) {
} }
} }
function onSortChanged(thisThing) {
thisThing.parentElement.submit();
}
function validateCountry(countryCodeField) { function validateCountry(countryCodeField) {
var ajax = new XMLHttpRequest(); var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() { 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; margin: auto;
} }
.headerItem form {
display: inline-block;
margin: auto;
}
.logoLinl { .logoLinl {
text-decoration: none; text-decoration: none;
} }