Calendario in PHP

« Older   Newer »
 
  Share  
.
  1. Marchack
        +1   -1
     
    .

    User deleted


    Ecco uno Script per creare un calendario in PHP, è molto semplice ma efficace.
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <?


    /*

    Please keep the following lines if you will use this script. Thanks!
    ---------------------------------------------------------------------------
    CALENDAR SCRIPT
    Developed by : Steven Rebello ([email protected])
    Developed on : 15 September 2001
    Description : Prints a calendar for specified month and year in HTML

    ---------------------------------------------------------------------------


    To use this calendar script, just add the following function


    print_calendar($mon,$year);


    into your code and
    place the function call print_calendar($month,$year) where you want the calendar to be printed.
    The function get_month_as_array

    $month and $year are integers.
    For eg. the following will print calendar for December 2001.

    print_calendar(12,2001);

    You can tweak the table properties as you like.
    I did not want to complicate the function call with table property parameters like bordercolor etc..

    */

    //----------------- This function is to do the HTML header chore---------------------
    function print_HTML_header()
    {
    echo "<html>\n<head>\n<style>\n".
    "<!--\nTD{ FONT-FAMILY:arial; FONT-SIZE:20px; }\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 "
    ";

    echo "\n".
    "".
    "";

    echo "\n";
    echo "";
    echo "";

    $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";
    else
    //If the date is absent ie after 31, print space
    echo "\n";
    }// for -col

    if (($row + 1) != ($end+1))
    echo "\n";
    else
    echo "";
    }// for - row
    echo "\n
    ".
    "<<
    ".date("F",$first_day)." ".$temp_yr."".
    ">>
    SunMonTueWedThuFriSat
    ".$t."".(($t == " " )? " " :$t)."


    Show Current month
    ";
    }




    //----------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;

    print_calendar($month,$year);

    print_HTML_footer();

    ?>

    </body>
    </html>

    Download file PHP


    Edited by Marchack - 13/6/2011, 10:52
     
    Top
    .
  2.     +1   -1
     
    .
    Avatar

    Senior Member

    Group
    Member
    Posts
    10,796
    Grazie ricevuti
    +3

    Status
    Anonymous
    Ma non utilizzate i tag code? Così è molto meno leggibile...

    Comunque sembra piuttosto semplice, anche se non conosco il PHP; ma dove hai trovato il codice?
     
    Top
    .
  3. Marchack
        +1   -1
     
    .

    User deleted


    Aspetta metto il Download, comunque non l'ho programmato io, io uso un'impostazione un pò diversa, ma è facile da comprendere.
     
    Top
    .
2 replies since 12/6/2011, 19:29   46 views
  Share  
.
Top