<?php
include("../../../functions.inc.php");
include("../functions.inc.php");

dbConnect();

checkLogin('adm');
checkEnteService($_GET['serv']);

//modifico
if(isset($_POST['anno'])){

	$anno = intval($_POST['anno']);

	$result = $mysqli->query("UPDATE enti SET anno = ".$anno." WHERE ente_id = ".$_SESSION['user']['ente_id']);
	if($result){
		$_SESSION['user']['ente_anno'] = $anno;
		Js("window.location.reload();");
	}else
		printMsg("Errore durante il salvataggio",'danger');

	die();
}


?>
<div>
    <div class="modal-d-title">Imposta anno corrente</div>
    <form id="formAnno" role="form" class="form-horizontal" action="<?php echo $_SERVER['REQUEST_URI'];?>" onSubmit="return post(this,'f-anno-result')">
        <div class="modal-body modal-body-diag">    
            
            <div class="form-group">
                <label class="control-label col-xs-4">Seleziona</label>
                <div class="col-xs-6">
                    <select class="form-control" name="anno">
					<?php
                    for($i=date("Y")+1;$i>=2014;$i--){
                        $sel = $i == $_SESSION['user']['ente_anno'] ? ' selected' : '';
                        echo '<option value="'.$i.'"'.$sel.'>'.$i.'</option>';
                    }
                    ?>
                    </select>
                </div>
            </div>        
			<div id="f-anno-result"></div>
        </div>
        
        <div class="modal-footer">
            <button type="button" class="btn btn-primary submit" onClick="confirm('Sei sicuro di voler cambiare l\'anno corrente?',function(){$('#formAnno').submit(); closeDialog();})">Salva</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Annulla</button>
        </div>
    </form>

</div>