Files
fdn2/public/archivio.php
T

272 lines
7.1 KiB
PHP

<?php
require_once(dirname(__FILE__)."/load.php");
try {
AnalyticsHelper::logPageImpression();
GUIHandler::generateHtmlHeaders();
$mesi = array(1=>'Gennaio', 'Febbraio', 'Marzo', 'Aprile',
'Maggio', 'Giugno', 'Luglio', 'Agosto',
'Settembre', 'Ottobre', 'Novembre','Dicembre');
$currentYear=date("Y");
$post=false;
$found = false;
$day = "";
$month= "";
$year = "";
if(array_key_exists("submit", $_POST) && strcmp($_POST["submit"], "Invia")==0){
$post = true;
$day = $_POST["day"];
$month= $_POST["month"];
$year = $_POST["year"];
$limit=1;
$page = 1;
$numPages = 1;
if(array_key_exists("page", $_POST)){
$page = intval($_POST["page"]);
}
$skip =($page - 1) * $limit;
// var_dump($skip);
$dateString = $_POST["year"]."-".$_POST["month"]."-".$_POST["day"];
$notizieDateAll = GlobalVariables::get("dao")->count("NotiziaModel",
array("status"=>NotiziaModel::STATUS_ACCEPTED,"about.data"=>array('$gt'=>new MongoDate(strtotime($dateString)),
'$lt'=>new MongoDate(strtotime($dateString." +1 day"))))
);
if($notizieDateAll>0){
// $dim = count($notizieDateAll);
$numPages = ceil($notizieDateAll/$limit);
$found = true;
}
else{
$found = false;
}
$notizieDate = GlobalVariables::get("dao")->query("NotiziaModel",
array("status"=>NotiziaModel::STATUS_ACCEPTED, "about.data"=>array('$gt'=>new MongoDate(strtotime($dateString)),
'$lt'=>new MongoDate(strtotime($dateString." +1 day")))),
array("limit"=>$limit,"skip"=>$skip)
);
if (sizeof($notizieDate)>0){
$found=true;
$notizieDate = array_map(function($ele){$ele->testo = strip_tags($ele->testo);$ele->sottotitolo = strip_tags($ele->sottotitolo); return $ele; }, $notizieDate);
}
// var_dump($notizieDate);
}
}catch(GUIException $ex){
$error = $ex->getMessage();
}catch (Exception $exec){
$msg = LogModel::fromException($exec);
GlobalVariables::get("dao")->save($msg);
GUIHandler::redirect("index.php");
}
?>
<div style="width:1000px;margin-left:auto;margin-right:auto;">
<?php
GUIHandler::generateHeadPublic();
GUIHandler::generateMenu();?>
<div class="archivioDate">
<form method="POST" id="formData">
<select name="day">
<?php
for($i=1;$i<=31;$i++){
if($post && ($i == intval($day))){
?>
<option value="<?php echo $i;?>" selected><?php echo $i;?></option>
<?php }
else{
?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php
}
}
?>
</select>
<select name="month">
<?php
foreach ($mesi as $key=>$value){
if($post && ($key == intval($month))){
?>
<option value="<?php echo $key;?>" selected><?php echo $value;?></option>
<?php }
else{
?>
<option value="<?php echo $key;?>"><?php echo $value;?></option>
<?php
}
}
?>
</select>
<select name="year">
<?php
for($i=2009;$i<=$currentYear;$i++){
if($post && ($i == intval($year))){
?>
<option value="<?php echo $i;?>" selected><?php echo $i;?></option>
<?php }
else{
?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php
}
}
?>
</select>
<input id ="pageSend" type="hidden" name="page" value="1" />
<input id="sendForm" type="submit" name="submit" value="Invia" />
</form>
</div>
<div class="archivioResults">
<?php if(!$post){
?>
<div>Selezionate una data per la ricerca, e premere il tasto Invia.</div>
<?php
}
else{
if ($found){
$i=0;
foreach ($notizieDate as $notizia){
$i++;
$stringTitolo = (strlen($notizia->titolo) > 103) ? substr($notizia->titolo,0,100).'...' : $notizia->titolo;
$stringSottotitolo = (strlen($notizia->sottotitolo) > 73) ? substr($notizia->sottotitolo,0,70).'...' : $notizia->sottotitolo;
$stringTesto = (strlen($notizia->testo) > 33) ? substr($notizia->testo,0,30).'...' : $notizia->testo;
$media = DaoMediaHandler::getMainMediaFromModel($notizia);
?>
<div class="notiziaContainer">
<div class="notiziaImage mediaContent"><?php (!is_null($media))?$media->renderMedia(array("size"=>MediaRenderer::SIZE_SMALL)):"" ;?></div>
<a href="articolo.php?id=<?php echo $notizia->id;?>" id="notizia_<?php echo $i;?>" class="notiziaInfo">
<div class="notiziaTitolo"><?php echo $stringTitolo;?></div>
<div class="notiziaSottotitolo"><?php echo$stringSottotitolo;?></div>
<div class="notiziaTesto"><?php echo $stringTesto;?></div>
</a>
</div>
<?php
}
?>
<div class="paging">
<?php
if($page-2>1){
?>
<div id ="page_first" class="page">
Inizio
</div>
<div class="page noSelection">...</div>
<script type="text/javascript">
$(document).ready(function(){
$("#page_first").click(function(){
$("input#pageSend").val('1');
$("input#sendForm").click();
});
});
</script>
<?php
}
$j = 1;
$last = $page +2;
if($page-2<1){
if($page-1 == 1){
$j=$page-1;
}
else{
$j = $page;
}
}
else{
$j = $page - 2;
}
if($page+2 >$numPages){
// $j=page-2;
if($page +1 == $numPages){
$last = $page+1;;
}
else{
$last = $page;
}
}
for($j;$j<=$last;$j++){
if($j == $page){
?>
<div id ="page_<?php echo $j;?>" class="page current" >
<?php echo $j;?>
</div>
<?php
}
else{
?>
<div id ="page_<?php echo $j;?>" class="page" >
<?php echo $j;?>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#page_<?php echo $j;?>").click(function(){
$("input#pageSend").val(<?php echo $j;?>);
$("input#sendForm").click();
});
});
</script>
<?php
}
}
if($page+2<$numPages){
?>
<div class="page noSelection">...</div>
<div id ="page_last" class="page">
Ultima (<?php echo $numPages;?>)
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#page_last").click(function(){
$("input#pageSend").val('<?php echo $numPages;?>');
$("input#sendForm").click();
});
});
</script>
<?php
}
?>
<!-- <input id="pageSend" type="hidden" name="page" form="changePage"/> -->
<!-- </form> -->
</div>
<?php
}
else{
?>
<div style="color:red;">Nessun articolo trovato nella data selezionata.</div>
<?php
}
}
?>
</div>
<div class="summaryRightBar">
<?php GUIHandler::generateRightBannerBlock();?>
</div>
<?php
GUIHandler::generateFooter();
GUIHandler::generateGoogleAnalyticsScripts();
?>
</div>