[PHP] calendario

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
42
Massa, Italy
Salve, ho trovato questo codice dell'area snippet php.
vi posto:
PHP:
<?php

// verifichiamo se è stato scelto un altra data
if (isset($_GET['m']) && isset($_GET['y'])) {
    // qui i controlli sarebbero da aumentare
    if (is_numeric($_GET['m']) && is_numeric($_GET['y'])) {
        echo calendario($_GET['m'], $_GET['y']);
    } else {
        echo calendario(date('m'), date('Y'));
    }
} else {
    //altrimenti impostiamo la data corrente
    echo calendario(date('m'), date('Y'));
}

// funzione che restituisce il nome del mese indicato in italiano
function nome_mese($m) {
    $mesi = array(1, 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio',
        'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
    return $mesi[$m];
}

// Parametri obbligatori : mese e anno
function calendario($month, $year) {
    $time_primo_del_mese = mktime(0, 0, 0, $month, 1, $year);
    $primo_del_mese = date('w', $time_primo_del_mese);

    $giorni_nel_mese = cal_days_in_month(CAL_GREGORIAN, $month, $year);

    echo "<table class='tabcal'>";
    echo "<tr class='bold'>";
    echo "<td class='red' colspan='7'>" . nome_mese((int) $month) . " " . $year . "</td>";
    echo "</tr>";
    echo "<tr class='bold'>";
    echo "<td>D</td>";
    echo "<td>L</td>";
    echo "<td>M</td>";
    echo "<td>M</td>";
    echo "<td>G</td>";
    echo "<td>V</td>";
    echo "<td>S</td>";
    echo "</tr>\n";
    // questo ciclo annidato l'ho trovato in rete tempo fa ma non ricordo dove
    for ($i = 0; $i < 6; $i++) {
        echo "<tr>";
        for ($x = 1; $x <= 7; $x++) {
            $y = $x + ($i * 7) - $primo_del_mese;
            echo "<td";
            if ($y > 0 && $y <= $giorni_nel_mese) {
                if ($y == date('d') && $month == date('m') && $year == date('Y')) {
                    echo " class='daycolor' ";
                }
                echo ">$y";
            } else {
                echo " class='empty'>&nbsp;";
            }
            echo "</td>";
        }
        echo "</tr>";
        if ($y >= $giorni_nel_mese && $i < 6)
            break;
    }
    // creiamo un piccolo menu di navigazione
    $before = explode('-', date('m-Y', mktime(0, 0, 0, $month - 1, 1, $year)));
    $next = explode('-', date('m-Y', mktime(0, 0, 0, $month + 1, 1, $year)));
    $prossimo = nome_mese((int) $next[0]);
    $precedente = nome_mese((int) $before[0]);

    echo "<tr>";
    echo "<td class='red' colspan='7'>";
    echo " <a href='" . $_SERVER['PHP_SELF'] . "?m=" . $before[0] . "&y=" . $before[1] . "'>$precedente</a>";
    echo " << &nbsp; >> <a href='" . $_SERVER['PHP_SELF'] . "?m=" . $next[0] . "&y=" . $next[1] . "'>$prossimo</a>";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
}

vorrei sapere se è possibile far fare al giorno metterci un link tipo blog.php?day=20&yearh=2019

etc..

avete idea se si può fare o no?

grazie mille.
buona serata.
 

Discussioni simili