Page 1 of 1

help on geting day from calendar

Posted: Sat May 20, 2006 10:40 pm
by saranda
what i want is when I click on the day of the calendar the selected day to opear on the page , i can get the month and the year but not the day , when I use $day variable in sttart it opears as an undefinet variable but after i click onse it works... do you know how can i solv the problem..

Code: Select all

<body bgcolor = "#A4B3EE">
<?
echo "Kujtim";
?>
<?

$monthnames = array ( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );
$shortdaynames = array ( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' );
$longdaynames = array ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' );

$templates = array (
'calendar_section' => "<!-- Calendar by http://www.pluggedout.com -->
<style>
 .calendar_heading{font-family:Arial;font-size:11px;font-weight:bold;}
 .calendar_day_heading{font-family:Arial;font-size:11px;}
 .calendar_day_off{font-family:Arial;font-size:11px;}
 .calendar_day_on{font-family:Arial;font-size:11px;}
 .calendar_link{font-family:Arial;fony-size:11px;text-decoration:none;}
</style>
  <table width='200' border='0' cellspacing='1' cellpadding='2' bgcolor='#dddddd'>
   <tr>
    <td colspan='7' bgcolor='#A4B3EE'>
     <table width='100%' border='0' cellspacing='0' cellpadding='0'>
      <tr>
       <td align='center'>
        <span class='calendar_heading'><a class='calendar_link' href='<!--link_month_prev-->'>&laquo;</a></span>
       </td>
       <td align='center'>
        <span class='calendar_heading'><a class='calendar_link' href='<!--link_month_current-->'><!--month_name-->&nbsp;<!--year--></a></span>
       </td>
       <td align='center'>
        <span class='calendar_heading'><a class='calendar_link' href='<!--link_month_next-->'>&raquo;</a></span>
       </td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <!--calendar_day_headings-->
   </tr>
   <tr>
    <!--calendar_days-->
   </tr>
  </table>",
'calendar_day_heading' => "<td width='12%' class='calendar_day_heading' align='center'><!--day--></td>",
'calendar_day_empty' => "<td bgcolor='#ffffff' align='center'><span class='calendar_day'>&nbsp;</span></td>",
'calendar_day_on' => "<td align='center' class='calendar_day_on' bgcolor='#A4B3EE'><!--day--></td>",
'calendar_day_off' => "<td align='center' class='calendar_day_off'><!--day--></td>",
'calendar_sep' => "</tr>
<tr>"
);

function html_calendar ( $month, $year )
{
        global $templates;
        global $monthnames;
        global $shortdaynames;

        define ( 'ADAY', ( 60 * 60 * 24 ) );

        $datearray = getdate ( mktime ( 0, 0, 0, $month, 1, $year ) );
        $start = mktime ( 0, 0, 0, $month, 1, $year);

        $firstdayarray = getdate ( $start );

        $prev_month = ( $month == 1 ? 12 : ( $month - 1 ) );

        $prev_year = ( $month == 1 ? ( $year - 1 ) : $year );

        $next_month = ( $month == 12 ? 1 : ( $month + 1 ) );

        $next_year = ( $month == 12 ? ( $year + 1 ) : $year );

        $url_next = $_SERVER['PHP_SELF'] . "?month=" . $next_month . "&year=" . $next_year ;
        $url_prev = $_SERVER['PHP_SELF'] . "?month=" . $prev_month . "&year=" . $prev_year ;

        $html = $templates['calendar_section'];

        $old = array (
                '<!--link_month_prev-->',
                '<!--link_month_current-->',
                '<!--link_month_next-->',
                '<!--month_name-->',
                '<!--year-->'
        );

        $new = array (
                $_SERVER['PHP_SELF'] . "?month=" . $prev_month . "&year=" . $prev_year,
                $_SERVER['PHP_SELF'] . "?year=" . $year . "&month=" . $month,
                $_SERVER['PHP_SELF'] . "?month=" . $next_month . "&year=" . $next_year,
                $datearray['month'],
                $year
        );

        $html = str_replace ( $old, $new, $html );

        $t_day_heading = $templates['calendar_day_heading'];
        $t_day_empty = $templates['calendar_day_empty'];
        $t_day_on = $templates['calendar_day_on'];
        $t_day_off = $templates['calendar_day_off'];
        $t_calendar_sep = $templates['calendar_sep'];

        $day_headings = '';

        foreach($shortdaynames as $day)
        {
                $day_headings .= str_replace ( '<!--day-->', $day, $t_day_heading );
        }

        $html = str_replace ( '<!--calendar_day_headings-->', $day_headings, $html );

        $html_days = '';

        for( $count = 0; $count < 42; $count++ )
        {
                $dayarray = getdate ( $start );

                if ( ( ( $count ) % 7 ) == 0 )
                {
                        if ( $dayarray['mon'] != $datearray['mon'] )
                        {
                                break;
                        }

                        $html_days .= $t_calendar_sep;
                }

                if ( $count < $firstdayarray['wday'] || $dayarray['mon'] != $month )
                {
                        $html_days .= $t_day_empty;
                }
                else
                {
                        $date_url = $_SERVER['PHP_SELF'] . "?year=" . $dayarray['year'] . "&month=" . $dayarray['mon'] . "&day=" . $dayarray['mday'];

                        $html_days .= str_replace ( '<!--day-->', "<a class='calendar_link' href='" . $date_url . "'>" . $dayarray['mday'] . "</a>", $t_day_on );

                        $start += ADAY;

                        $testday = getdate ( $start );

                        if ( $testday['yday'] == $dayarray['yday'] )
                        {
                                $start += ( ADAY / 2 );
                        }
                }
        }

        return ( str_replace ( '<!--calendar_days-->', $html_days, $html ) );
}

// min, max years allowed, change to the values you want to use....

$min_year = 1999;
$max_year = 2010;



$i_month = ( ! empty ( $_GET['month'] ) && $_GET['month'] >= 1 && $_GET['month'] <= 12 ? $_GET['month'] : date('m') );

$i_year = ( ! empty ( $_GET['year'] ) && $_GET['year'] >= $min_year && $_GET['year'] <= $max_year ? $_GET['year'] : date('Y') );



print html_calendar ( $i_month, $i_year );

echo $start;
echo "-";
echo  $i_month;
echo "-";
echo $i_year;

?>

Posted: Sat May 20, 2006 10:45 pm
by saranda
the

Code: Select all

<? echo $start;?>
thing in the end of the code is there by mistake

thnx....