Changeset 453 for trunk


Ignore:
Timestamp:
Apr 5, 2025, 1:07:00 AM (8 months ago)
Author:
roby
Message:
  • CLIENT

-- Sistemate la scheda principale, quella del riepilogo per sezione dei referendum, dei grafici di lista e di gruppo
-- Aggiunta una funzione per il cambio veloce della consultazione in caso di election day
-- Cambiata la funzione per la gestione degli opendata (da completare)
-- Sistemati alcuni grafici

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/versione.php

    r452 r453  
    11<?php
    22
    3 $versione = "3.0 rev 452";
     3$versione = "3.0 rev 453";
    44$version_number = $versione;
    55$datarel = "04 aprile 2025";
  • trunk/client/temi/bootstrap/pagine/grafici/affluenza.php

    r450 r453  
    6767        <h4 class="fw-semibold text-primary mobile-expanded mt-2">Affluenza</h4>
    6868    </div>
     69        <?php include 'temi/bootstrap/pagine/tab_link_opendata.php'; ?>
    6970        <div class="table-responsive overflow-x">
    7071        <table class="table  mb-0">
  • trunk/client/temi/bootstrap/pagine/grafici/votanti_referendum.php

    r451 r453  
    33$quesiti=elenco_gruppi('gruppo');
    44if(isset($_GET['num_gruppo'])) $num_gruppo=intval($_GET['num_gruppo']); else $num_gruppo=1;
    5 foreach($quesiti as $val) if($val['num_gruppo']==$num_gruppo) {$id_gruppo=$val['id_gruppo']; $nome_quesito=$val['descrizione'];}
     5foreach($quesiti as $val) if($val['num_gruppo']==$num_gruppo) {$id_gruppo=$val['id_gruppo']; $nome_quesito='Quesito '. $val['num_gruppo'];}
    66$rowscrutinate=voti_referendum($id_gruppo);
    77$sezionitotali=sezioni_totali();
  • trunk/client/temi/bootstrap/pagine/grafici/voti_referendum.php

    r450 r453  
    11<?php
    2 $quesiti=elenco_gruppi('gruppo');
    3 if(isset($_GET['num_gruppo'])) $num_gruppo=intval($_GET['num_gruppo']); else $num_gruppo=1;
    4 foreach($quesiti as $val) if($val['num_gruppo']==$num_gruppo) {$id_gruppo=$val['id_gruppo']; $nome_quesito=$val['descrizione'];}
    5 $rowscrutinate=voti_referendum($id_gruppo);
    6 $sezionitotali=sezioni_totali();
    7 $scrutinate=0;
    8 $si=0;
    9 $no=0;
    10 foreach($rowscrutinate as $val)
    11         if($val['si']+$val['no']!=0) {
    12                 $scrutinate++;
    13                 $si+=$val['si'];
    14                 $no+=$val['no'];
    15         }
    16 $si=number_format($si,0,'','.');
    17 $no=number_format($no,0,'','.');
    18 $tot=$si+$no;
    19 $perc_si=number_format($si/$tot*100,2);
    20 $perc_no=number_format($no/$tot*100,2);
     2$quesiti = elenco_gruppi('gruppo');
     3$num_gruppo = isset($_GET['num_gruppo']) ? intval($_GET['num_gruppo']) : 1;
     4
     5$id_gruppo = null;
     6$nome_quesito = '';
     7
     8foreach ($quesiti as $val) {
     9    if ($val['num_gruppo'] == $num_gruppo) {
     10        $id_gruppo = $val['id_gruppo'];
     11        $nome_quesito = $val['descrizione'];
     12        break;
     13    }
     14}
     15
     16$rowscrutinate = voti_referendum($id_gruppo);
     17$sezionitotali = sezioni_totali();
     18$scrutinate = $si_raw = $no_raw = 0;
     19
     20foreach ($rowscrutinate as $val) {
     21    if ($val['si'] + $val['no'] != 0) {
     22        $scrutinate++;
     23        $si_raw += $val['si'];
     24        $no_raw += $val['no'];
     25    }
     26}
     27
     28$tot = $si_raw + $no_raw;
     29$perc_si = $tot > 0 ? number_format($si_raw / $tot * 100, 2) : 0;
     30$perc_no = $tot > 0 ? number_format($no_raw / $tot * 100, 2) : 0;
     31
     32$si = number_format($si_raw, 0, '', '.');
     33$no = number_format($no_raw, 0, '', '.');
    2134
    2235$quesito = [
    23     'Quesito '.$num_gruppo => [[$perc_si, $si], [$perc_no, $no]],
     36    'Quesito ' . $num_gruppo => [[$perc_si, $si], [$perc_no, $no]],
    2437];
    2538
    2639$labels = array_keys($quesito);
    27 $scrutinate =10;
    28 $sezionitotali=15;
    2940?>
    3041
     
    3546    #chartContainer {
    3647        width: 100%;
    37         height: 500px;  /* Altezza fissa che si adatta con le barre */
     48        height: 500px;
    3849        margin: 0 auto;
    3950    }
     
    4152    @media (max-width: 768px) {
    4253        #chartContainer {
    43             height: 700px;  /* Maggiore altezza per dispositivi mobili */
     54            height: 700px;
    4455        }
    4556    }
    4657</style>
    47 <!-- Blocco select quesito referndum-->
    48                 <div class="container pb-2">
    49                         <label for="defaultSelect">Seleziona Quesito</label>
    50                         <select id="defaultSelect" onchange="location = this.value;">
    51                                 <!-- option selected>Selezione Quesito</option -->
    52                                 <?php
    53                                 $desc='';
    54                                 foreach($quesiti as $key=>$val) {
    55                                 if ($num_gruppo==$val[1]) {$id_gruppo=$val['id_gruppo']; $sel='selected';} else {$sel='';}
    56                                 ?>
    57                                         <option <?php echo $sel; ?> value=" <?php echo "modules.php?op=53&id_comune=$id_comune&file=index&id_cons_gen=$id_cons_gen&num_gruppo=".$val[1];?>">Quesito <?php echo $val['num_gruppo'];?></option>
    58                                 <?php }?>
    59                         </select>
    60                 </div>
    61                 <!-- fine Blocco select quesito referndum-->
     58
     59<!-- Blocco select quesito referendum -->
     60<div class="container pb-2">
     61    <label for="defaultSelect">Seleziona Quesito</label>
     62    <select id="defaultSelect" onchange="location = this.value;">
     63        <?php foreach ($quesiti as $val) : ?>
     64            <option value="modules.php?op=53&id_comune=<?= $id_comune; ?>&file=index&id_cons_gen=<?= $id_cons_gen; ?>&num_gruppo=<?= $val['num_gruppo']; ?>"
     65                <?= $num_gruppo == $val['num_gruppo'] ? 'selected' : ''; ?>>
     66                Quesito <?= $val['num_gruppo']; ?>
     67            </option>
     68        <?php endforeach; ?>
     69    </select>
     70</div>
     71
     72<!-- Tabella risultati -->
    6273<div class="container">
    6374    <div class="row text-center">
    6475        <h4 class="fw-semibold text-primary mobile-expanded mt-2">Risultati Referendum</h4>
    6576    </div>
    66         <div class="table-responsive overflow-x">
    67         <table class="table  mb-0">
    68                 <thead class="title-content">
    69                         <tr>
    70                                 <th>Risultati Referendum</th>
    71                                 <?php if ($scrutinate == $sezionitotali) {?>
    72                                         <th class="text-end">Dati finali</th>
    73                                 <?php } else {?>
    74                                         <th class="text-end"><span>Sezioni scrutinate: <?php echo $scrutinate; ?> su <?php echo $sezionitotali; ?></span>
    75                                         </th>
    76                                 <?php }?>
    77                         </tr>
    78                 </thead>
    79         </table>
    80 </div> 
     77    <div class="table-responsive overflow-x">
     78        <table class="table mb-0">
     79            <thead class="title-content">
     80                <tr>
     81                    <th>Risultati Referendum</th>
     82                    <th class="text-end">
     83                        <?= $scrutinate == $sezionitotali ? 'Dati finali' : "Sezioni scrutinate: $scrutinate su $sezionitotali"; ?>
     84                    </th>
     85                </tr>
     86            </thead>
     87        </table>
     88    </div>
     89   
    8190    <div id="chartContainer">
    8291        <canvas id="risultatiChart"></canvas>
     
    8796    var ctx = document.getElementById('risultatiChart').getContext('2d');
    8897
    89     var labels = <?php echo json_encode($labels); ?>;
    90     var quesiti = <?php echo json_encode($quesito); ?>;
    91 
     98    var labels = <?= json_encode($labels); ?>;
     99    var quesiti = <?= json_encode($quesito); ?>;
    92100    const predefinedColors = ['rgb(54, 162, 235)', 'rgb(255, 99, 132)'];
    93101
     
    107115    ];
    108116
    109     var chartHeight = Math.max(500, labels.length * 80);  // Altezza del grafico dinamica
     117    var chartHeight = Math.max(500, labels.length * 80);
    110118    document.getElementById('chartContainer').style.height = chartHeight + 'px';
    111119
    112     var risultatiChart = new Chart(ctx, {
    113         type: 'bar',
    114         data: {
    115             labels: labels,
    116             datasets: datasets
     120   var risultatiChart = new Chart(ctx, {
     121    type: 'bar',
     122    data: {
     123        labels: labels,
     124        datasets: datasets
     125    },
     126    options: {
     127        responsive: true,
     128        maintainAspectRatio: false,
     129        indexAxis: 'y',
     130        scales: {
     131            x: { beginAtZero: true, max: 100 },
     132            y: {
     133    ticks: { stepSize: 1 },
     134    barThickness: "flex",  // Adatta lo spessore automaticamente
     135    maxBarThickness: 50  // Imposta un limite massimo per evitare che le barre diventino troppo grandi
     136}
     137
    117138        },
    118         options: {
    119             responsive: true,
    120             maintainAspectRatio: false,
    121             indexAxis: 'y',
    122             scales: {
    123                 x: {
    124                     beginAtZero: true,
    125                     max: 100
    126                 },
    127                 y: {
    128                     ticks: {
    129                         stepSize: 1
    130                     },
    131                     barThickness: 60,  // Maggiore spessore delle barre
    132                 }
    133             },
    134             plugins: {
    135                 legend: {
    136                     display: true
    137                 },
    138                 tooltip: {
    139                     callbacks: {
    140                         label: function (context) {
    141                             var datasetIndex = context.datasetIndex;
    142                             var dataIndex = context.dataIndex;
    143 
    144                             var tipoVoto = context.dataset.label;
    145                             var percentuale = context.raw;
    146                             var voti = quesiti[context.label][datasetIndex][1];
    147 
    148                             return tipoVoto + ': ' + percentuale + '% (' + voti + ' voti)';
    149                         }
     139        plugins: {
     140            legend: { display: true },
     141            tooltip: {
     142                callbacks: {
     143                    label: function (context) {
     144                        var datasetIndex = context.datasetIndex;
     145                        var dataIndex = context.dataIndex;
     146                        var tipoVoto = context.dataset.label;
     147                        var percentuale = context.raw;
     148                        var voti = quesiti[context.label][datasetIndex][1];
     149                        return tipoVoto + ': ' + percentuale + '% (' + voti + ' voti)';
    150150                    }
    151151                }
    152152            }
    153         },
    154         plugins: [
    155             {
    156                 id: 'insideBarPercentage',
    157                 afterDatasetDraw: function (chart) {
    158                     const ctx = chart.ctx;
    159                     chart.data.datasets.forEach(function (dataset, datasetIndex) {
    160                         if (!chart.isDatasetVisible(datasetIndex)) return;
     153        }
     154    },
     155    plugins: [{
     156        id: 'outsideBarLabels',
     157        afterDatasetDraw: function (chart) {
     158            const ctx = chart.ctx;
     159            chart.data.datasets.forEach(function (dataset, datasetIndex) {
     160                if (!chart.isDatasetVisible(datasetIndex)) return;
    161161
    162                         dataset.data.forEach(function (value, index) {
    163                             const meta = chart.getDatasetMeta(datasetIndex).data[index];
    164                             const x = meta.base + (meta.width / 2);
    165                             const y = meta.y;
     162                dataset.data.forEach(function (value, index) {
     163                    const meta = chart.getDatasetMeta(datasetIndex).data[index];
     164                    const x = meta.x + 10; // Sposta il testo fuori dalla barra
     165                    const y = meta.y;
    166166
    167                             const text = value + '% (' + quesiti[chart.data.labels[index]][datasetIndex][1] + ' voti)';
    168                             const isSmallBar = value < 10;
    169                             const fontSize = isSmallBar ? 10 : 16;
     167                    const text = value + '% (' + quesiti[chart.data.labels[index]][datasetIndex][1] + ' voti)';
    170168
    171                             ctx.save();
    172                             ctx.fillStyle = '#000000';
    173                             ctx.font = `bold ${fontSize}px Titillium Web, Arial`;
    174                             ctx.textAlign = 'center';
    175                             ctx.textBaseline = 'middle';
    176                             ctx.fillText(text, x, y);
    177                             ctx.restore();
    178                         });
    179                     });
    180                 }
    181             }
    182         ]
    183     });
     169                    ctx.save();
     170                    ctx.fillStyle = '#000000';
     171                    ctx.font = 'bold 16px Titillium Web, Arial';
     172                    ctx.textAlign = 'left'; // Allinea il testo fuori dalla barra
     173                    ctx.textBaseline = 'middle';
     174                    ctx.fillText(text, x, y);
     175                    ctx.restore();
     176                });
     177            });
     178        }
     179    }]
     180});
     181
    184182</script>
  • trunk/client/temi/bootstrap/pagine/grafici/votidigruppo.php

    r448 r453  
    33$scrutinate = scrutinate('gruppo');
    44$sezionitotali = sezioni_totali();
    5 $dati = voti_tot_gruppo();
     5$dati = voti_gruppo_graf();
    66# t2.num_gruppo,t2.descrizione,sum(t1.voti)
    77$descr = [];
  • trunk/client/temi/bootstrap/pagine/grafici/votidilista.php

    r447 r453  
    33$scrutinate=scrutinate('lista');
    44$sezionitotali=sezioni_totali();
    5 $dati = voti_tot_lista();
     5$dati = voti_lista_graf(); #voti_tot_lista();
    66# t1.id_lista,t2.num_gruppo,t2.num_lista,t2.descrizione,sum(t1.voti)
    77$descr = [];
  • trunk/client/temi/bootstrap/pagine/listaecandidati.php

    r441 r453  
    1717$row=scrutinio_schede($tab);
    1818$schede_scrutinate=$row[0][0];
     19include 'electionday.php'; //Pagina Election Day
    1920if(!$schede_scrutinate) $schede_scrutinate=0;
    2021// Blocco affluenza mettere spoglioattivo==0 dopo aver sistemato le affluenze $tab
     
    4647                $numeroorari=count($rowora);
    4748                $giorno=array('domenica','lunedì','martedì','mercoledì','giovedì','venerdì','sabato');
     49               
    4850                #<!--Tabella affluenza -->
    4951                #<!--mettere $spoglioattivo==0 dopo aver sistemato tutto e funzionante-->
     
    157159                <thead class="title-content">
    158160                        <tr>
    159                                 <th>Voti per <?php echo _GRUPPO;?> e Preferenze</th>
     161                                <th>Voti per <?php echo _GRUPPO;?> e Preferenze </th>
    160162                                <?php if ($spoglioattivo==1) {?>
    161163                                        <?php if ($scrutinate == $sezionitotali) {?>
     
    429431                        <div class="col-auto me-2">
    430432                                <strong>Elettori:</strong>
    431                                 <?php if(!isset($elet[0][2])) $elet[0][2]=0; number_format($elet[0][2], 0, ".", ".") ?>
     433                                <?php if(!isset($elet[0][2])) $elet[0][2]=0; echo number_format($elet[0][2], 0, ".", ".") ?>
    432434                        </div>
    433435                        <!-- Votanti -->
     
    444446                        </div>
    445447                        <!-- Schede -->
    446                         <?php  if (($row[0][0] + $row[0][1] + $row[0][3]) > 0): ?>
     448                        <?php  $row=voti_totali(); if (($row[0][0] + $row[0][1] + $row[0][3]) > 0): ?>
    447449                                <?php
    448450                                $schede = ['valide' => 0, 'nulle' => 1, 'bianche' => 2, 'contestate' => 3];
     
    453455                                <div class="col-auto me-2">
    454456                                        <strong>Schede <?= $nome ?>:</strong>
    455                                         <?php number_format($conteggio, 0, ".", ".") ?>
    456                                         (<?php number_format($percentuale, 2) ?>%)
     457                                        <?php echo number_format($conteggio, 0, ".", ".") ?>
     458                                        (<?php echo number_format($percentuale, 2) ?>%)
    457459                                </div>
    458460                                <?php endforeach; ?>
  • trunk/client/temi/bootstrap/pagine/referendumpersezioni.php

    r442 r453  
    8383                <tbody>
    8484                        <?php
    85                         $totuomini=0;$totdonne=0;$totespressi=0;$totvalidi=0;$totnulli=0;$totbianchi=0;$totcontestati=0;
     85                        $totsi=0;$totno=0;$totuomini=0;$totdonne=0;$totespressi=0;$totvalidi=0;$totnulli=0;$totbianchi=0;$totcontestati=0;
    8686                        $seztemp=elenco_sezioni(0);
    8787                        foreach($seztemp as $sez) $sezioni[$sez['num_sez']]=$sez['id_sez'];
     
    9595                                else
    9696                                        $aff=ultime_affluenze_sezione($row[$sezioni[$i]]['id_sez']);
    97                                 $totuomini+=$aff[0]['voti_uomini'];$totdonne+=$aff[0]['voti_donne'];$totespressi+=$aff[0]['voti_complessivi'];$totvalidi+=$row[$sezioni[$i]]['validi'];$totnulli+=$row[$sezioni[$i]]['nulli'];$totbianchi+=$row[$sezioni[$i]]['bianchi'];$totcontestati+=$row[$sezioni[$i]]['contestati'];      ?>
     97                                $totsi+=$row[$sezioni[$i]]['si'];$totno+=$row[$sezioni[$i]]['no'];$totuomini+=$aff[0]['voti_uomini'];$totdonne+=$aff[0]['voti_donne'];$totespressi+=$aff[0]['voti_complessivi'];$totvalidi+=$row[$sezioni[$i]]['validi'];$totnulli+=$row[$sezioni[$i]]['nulli'];$totbianchi+=$row[$sezioni[$i]]['bianchi'];$totcontestati+=$row[$sezioni[$i]]['contestati'];    ?>
    9898                                <tr>
    9999                                        <th scope="row"><?php echo $i;?></th>
     
    110110                        <tr class="primary-bg-c4 white-color align-middle text-end">
    111111                                <td scope="row">Totale</td>
    112                                 <td><?php echo $totuomini ?></th>
    113                                 <th><?php echo $totdonne ?></th>
     112                                <td><?php echo $totsi ?></th>
     113                                <th><?php echo $totno ?></th>
    114114                                <th><?php echo $totvalidi ?></th>
    115115                                <th><?php echo $totnulli ?></th>
  • trunk/client/temi/bootstrap/query.php

    r452 r453  
    605605        global $id_cons,$prefix,$dbi,$circo,$idcirc;
    606606        if($idlista) $filtro="and t2.id_lista=$idlista"; else $filtro='';
    607         $sql="select t2.id_cand, t2.num_lista,t2.num_cand,concat(t2.cognome,' ', t2.nome) as descrizione,sum(t1.voti) as votisum,t2.id_lista,t2.eletto from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' $filtro group by t2.id_cand,t2.num_lista,t2.num_cand,descrizione,t2.id_lista,t2.eletto order by votisum desc";
     607        $sql="select t2.id_cand, t2.num_lista,t2.num_cand,concat(t2.cognome,' ', t2.nome) as descrizione,sum(t1.voti) as votisum,t2.id_lista,t2.eletto from ".$prefix."_ele_voti_candidati as t1 left join ".$prefix."_ele_candidati as t2 on t1.id_cand=t2.id_cand where t1.id_cons='$id_cons' $filtro group by t2.id_cand,t2.num_lista,t2.num_cand,descrizione,t2.id_lista,t2.eletto order by votisum desc,t2.num_cand";
    608608        $sth = $dbi->prepare("$sql");
    609609        $sth->execute();
     
    912912        }else
    913913                $filtro='';
    914         $sql="SELECT sum(validi),sum(nulli),sum(bianchi),sum(contestati) FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' $filtro";
     914        $sql="SELECT sum(validi) as valide,sum(nulli) as nulle,sum(bianchi) as bianche,sum(contestati) as contestate FROM ".$prefix."_ele_sezioni where id_cons='$id_cons' $filtro";
    915915        $sth = $dbi->prepare("$sql");
    916916        $sth->execute();
     
    944944}
    945945
     946function voti_lista_graf()
     947{
     948        global $id_cons,$prefix,$dbi,$circo,$idcirc;
     949        if($circo) $cond="and t2.id_circ='$idcirc'"; else $cond='';
     950        $sql="select t1.id_lista,t2.num_gruppo,t2.num_lista,t2.descrizione,sum(t1.voti) as votisum from ".$prefix."_ele_voti_lista as t1 left join ".$prefix."_ele_lista as t2 on t1.id_lista=t2.id_lista where t1.id_cons='$id_cons' $cond group by t1.id_lista,t2.num_gruppo,t2.num_lista,t2.descrizione order by votisum desc,t2.num_lista";
     951        $sth = $dbi->prepare("$sql");
     952        $sth->execute();
     953        $row = $sth->fetchAll();
     954        return($row);   
     955
     956}
     957
    946958function voti_tot_gruppo()
    947959{
     
    956968}
    957969
     970function voti_gruppo_graf()
     971{
     972        global $id_cons,$prefix,$dbi,$circo,$idcirc;
     973        if($circo) $cond="and t2.id_circ='$idcirc'"; else $cond='';
     974        $sql="select t2.num_gruppo,t2.descrizione,sum(t1.voti) as votisum from ".$prefix."_ele_voti_gruppo as t1 left join ".$prefix."_ele_gruppo as t2 on t1.id_gruppo=t2.id_gruppo where t1.id_cons='$id_cons' $cond group by t2.num_gruppo,t2.descrizione order by votisum desc,t2.num_gruppo";
     975        $sth = $dbi->prepare("$sql");
     976        $sth->execute();
     977        $row = $sth->fetchAll();
     978        return($row);   
     979
     980}
     981
    958982function voti_tot_referendum()
    959983{
  • trunk/client/variabili.php

    r431 r453  
    55### Variabili di programma
    66#
    7 $offsetliste=16;           # Risultati numero di liste visualizzate nella pagina
    8 $offsetgruppi=15;          # Risultati numero di gruppi visualizzati nella pagina
    9 $numcandvis=16;            # Numero di candidati visualizzati per pagina
    10 $numsezvis=26;            # Numero di sezioni visualizzate per pagina
    11 $datigenvis=20;            # Elementi visualizzati in scheda Dati generali
    12 
     7$offsetliste=16;                # Risultati numero di liste visualizzate nella pagina
     8$offsetgruppi=15;               # Risultati numero di gruppi visualizzati nella pagina
     9$numcandvis=16;                 # Numero di candidati visualizzati per pagina
     10$numsezvis=26;                  # Numero di sezioni visualizzate per pagina
     11$datigenvis=20;                 # Elementi visualizzati in scheda Dati generali
     12$giorniviselday=29;                     # Massimo numero di giorni in cui viene visualizzata la sezione Election day
     13                                                        # (visualizza i pulsanti di accesso diretto alle singole consultazioni)
    1314
    1415#La variabile $arcon stabilisce l'ordine di visualizzazione delle consultazioni nel menu bootstrap
  • trunk/client/versione.php

    r452 r453  
    11<?php
    2 $versione = "3.0 rev 452";
     2$versione = "3.0 rev 453";
    33$version_number = $versione;
    44$datarel = "04 aprile 2025";
Note: See TracChangeset for help on using the changeset viewer.