#native_company# #native_desc#
#native_cta#

Day Chooser

By Edwin Groothuis
on March 6, 2001

Version: 1.0

Type: Full Script

Category: Calendars/Dates

License: BSD License

Description: Easy to use interface to choose a day between two dates.

<?
    //
    // daychooser v1.0 by Edwin Groothuis ([email protected])
    //
    // If you didn't get this file via http://www.mavetju.org, please
    // check there for the availability of newer versions.
    //
    // See LICENSE for distribution issues. If this file isn't in
    // the distribution, please inform me about it.
    //

    $daymonths=array(0,31,28,31,30,31,30,31,31,30,31,30,31);
    $monthnames=array("","Jan","Feb","Mar","Apr","May","Jun",
		      "Jul","Aug","Sep","Oct","Nov","Dec");

    //
    // evil constants, this is the begin of the time.
    //
    $yearbegin=1995;
    $monthbegin=7;
    $daybegin=12;

    $now=date("Y n d");
    $a=explode(" ",$now);

    $yearnow=$a[0];
    $monthnow=$a[1];
    $daynow=$a[2];

    $daygiven=$day;
    $monthgiven=$month;
    $yeargiven=$year;

    if ($day=="" || $month=="" || year=="") {
	$day=$daybegin;
	$month=$monthbegin;
	$year=$yearbegin;
    }

    // leap-year. did you have your Y2K today?
    if ($yeargiven%4==0 && $yeargiven%100!=0 || $yeargiven%400==0)
	$daymonths[2]=29;

    printf(
	"Information avaible from <b>%04d %s %d</b> to <b>%04d %s %d</b><br>n",
        $yearbegin,$monthnames[$monthbegin],$daybegin,
        $yearnow,$monthnames[$monthnow],$daynow);

    if ($daygiven!=0 && $monthgiven!=0 && $yeargiven!=0) {
	printf("You have choosen: %d %s %d.<br>n",
	    $yeargiven,$monthnames[$monthgiven],$daygiven);
    }

    // if nothing is given, only show the years
    if ($yeargiven==0 && $monthgiven==0) {
        echo "<ul>n";
        for ($year=$yearbegin;$year<=$yearnow;$year++) {
            echo "<li><a href="$PHP_SELF?year=$year&month=0&day=0">$year</a><br>n";
        }
        echo "</ul>n";
    // if the only year is given, display years and months
    } elseif ($yeargiven!=0 && $monthgiven==0) {
        echo "<ul>n";
        for ($year=$yearbegin;$year<=$yearnow;$year++) {
            echo "<li><a href="$PHP_SELF?year=$year&month=0&day=0">$year</a><br>n";
            if ($year==$yeargiven) {
                echo "<ul><li>n";
                for ($month=($year==$yearbegin?$monthbegin:1);
                     $month<=($year==$yearnow?$monthnow:12);
                     $month++) {
                    echo "<a href="$PHP_SELF?year=$year&month=$month&day=0">$monthnames[$month]</a>n";
                }
                echo "</li></ul>n";
            }
        }
        echo "</ul>n";
    // if the year and month are given, display years, months and days
    } elseif ($yeargiven!=0 && $monthgiven!=0) {
        echo "<ul>n";
        for ($year=$yearbegin;$year<=$yearnow;$year++) {
            echo "<li><a href="$PHP_SELF?year=$year&month=0&day=0">$year</a><br>n";
            if ($year==$yeargiven) {
                echo "<ul><li>n";
                for ($month=($year==$yearbegin?$monthbegin:1);
                     $month<=($year==$yearnow?$monthnow:12);
                     $month++) {
                    echo "<a href="$PHP_SELF?year=$year&month=$month&day=0">$monthnames[$month]</a>n";
                    if ($month==$monthgiven) {
                        echo "<ul><li>n";
                        for ($day=($year==$yearbegin&&$month==$monthbegin?$daybegin:1);
                             $day<=($year==$yearnow&&$month==$monthnow?$daynow:$daymonths[$month]);
                             $day++) {
                            echo "<a href="$PHP_SELF?year=$year&month=$month&day=$day">$day</a> n";
                            }
                        echo "</li></ul>n";
                    }
                }
                echo "</li></ul>n";
            }
        }
        echo "</ul>n";
    }

?>