Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di Frankos
    Registrato dal
    Nov 2002
    Messaggi
    505

    Errore incomprensibile in calendario

    Ciao a tutti,

    ho trovato uno script per creare un calendario perpetuo.
    Lo script funziona perfettamente.
    Poi ho provato a modificarlo creando una tabella e mettendo in ogni cella il calendario di ogni mese.
    Cosi facendo mi funziona correttamente per i primi 4 mesi dell'anno e poi mi da degli errori incomprensibili: per alcuni mesi, dopo l'ultimo gionro del mese me ne visualizza ancora qualcuno e non so perché.
    Allego il codice cosi potete provarlo di persona.

    <?
    //----------------- This function is to do the HTML header chore---------------------
    function print_HTML_header()
    {
    echo "<HTML>\n<HEAD>\n<STYLE>\n".
    "\n</STYLE>".
    "<TITLE>Calendar\n</TITLE>\n</HEAD>\n<BODY BACKGROUND='images/bg.gif'>\n\n";
    }


    //----------------- This function is to do the HTML footer chore---------------------
    function print_HTML_footer()
    {
    echo "</BODY></HTML>";
    }



    //----------------- This function prints calendar---------------------
    function print_calendar($mon,$year)
    {
    global $dates, $first_day, $start_day;

    $first_day = mktime(0,0,0,$mon,1,$year);
    $start_day = date("w",$first_day);
    $res = getdate($first_day);
    $month_name = $res["month"];
    $no_days_in_month = date("t",$first_day);

    //If month's first day does not start with first Sunday, fill table cell with a space
    for ($i = 1; $i <= $start_day;$i++)
    $dates[1][$i] = " ";

    $row = 1;
    $col = $start_day+1;
    $num = 1;
    while($num<=31)
    {
    if ($num > $no_days_in_month)
    break;
    else
    {
    $dates[$row][$col] = $num;
    if (($col + 1) > 7)
    {
    $row++;
    $col = 1;
    }
    else
    $col++;
    $num++;
    }//if-else
    }//while
    $mon_num = date("n",$first_day);
    $temp_yr = $next_yr = $prev_yr = $year;

    $prev = $mon_num - 1;
    $next = $mon_num + 1;

    //If January is currently displayed, month previous is December of previous year
    if ($mon_num == 1)
    {
    $prev_yr = $year - 1;
    $prev = 12;
    }

    //If December is currently displayed, month next is January of next year
    if ($mon_num == 12)
    {
    $next_yr = $year + 1;
    $next = 1;
    }

    echo "<TABLE BORDER=1 WIDTH=150 CELLSPACING=0 BORDERCOLOR='silver'>";

    echo "\n<TR ALIGN='center'><TD BGCOLOR='white'> ".
    "<< </TD>".
    "<TD COLSPAN=5 BGCOLOR='#99CCFF'>".date("F",$first_day)." ".$temp_yr."</TD>".
    "<TD BGCOLOR='white'> ".
    ">> </TD></TR>";

    echo "\n<TR ALIGN='center'><TD>D</TD><TD>L</TD><TD>M</TD>";
    echo "<TD>M</TD><TD>G</TD><TD>V</TD><TD>S</TD></TR>";
    echo "<TR><TD COLSPAN=7> </TR><TR ALIGN='center'>";

    $end = ($start_day > 4)? 6:5;
    for ($row=1;$row<=$end;$row++)
    {
    for ($col=1;$col<=7;$col++)
    {
    if ($dates[$row][$col] == "")
    $dates[$row][$col] = " ";

    if (!strcmp($dates[$row][$col]," "))
    $count++;

    $t = $dates[$row][$col];

    //If date is today, highlight it
    if (($t == date("j")) && ($mon == date("n")) && ($year == date("Y"))){
    echo "\n<TD BGCOLOR='#C6FFB3'>".$t."</TD>";
    }else{
    //If the date is absent ie after 31, print space
    echo "\n<TD>".(($t == " " )? "" :$t)."</TD>";
    }
    }// for -col

    if (($row + 1) != ($end+1))
    echo "</TR>\n<TR ALIGN='center'>";
    else
    echo "</TR>";
    }// for - row
    echo "\n</TABLE>
    ";

    // verifica se il giorno da scrivere in tabella é occupato oppure no (da utilizzare per coloraree sfondo cella)
    //$giorno_attuale=$year.$mon.$t;
    //echo "$giorno_attuale";

    }


    //----------Main Loop-----------

    print_HTML_header();

    //If $month is not present, set it to current month.
    $month = (empty($month)) ? date("n") : $month;

    //If $year is not present, set it to current year.
    $year = (empty($year)) ? date("Y") : $year;
    ?>
    <table width="800" cellpadding="0" cellspacing="0">
    <tr>
    <td width="200"><div align="center"><?=print_calendar($month,$year)?></div></td>
    <td width="200"><div align="center"><?=print_calendar($month+1,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+2,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+3,$year)?> </div></td>
    </tr>
    <tr>
    <td width="200"><div align="center"><?=print_calendar($month+4,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+5,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+6,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+7,$year)?> </div></td>
    </tr>
    <tr>
    <td width="200"><div align="center"><?=print_calendar($month+8,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+9,$year)?> </div></td>
    <td width="200"><div align="center"><?=print_calendar($month+10,$year)? ></div></td>
    <td width="200"><div align="center"><?=print_calendar($month+11,$year)? ></div></td>
    </tr>
    </table>
    Sempre più in alto...
    www.webdition.com

  2. #2
    Utente di HTML.it L'avatar di Frankos
    Registrato dal
    Nov 2002
    Messaggi
    505
    Sempre più in alto...
    www.webdition.com

  3. #3
    Utente di HTML.it L'avatar di Frankos
    Registrato dal
    Nov 2002
    Messaggi
    505
    risolto
    Sempre più in alto...
    www.webdition.com

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.