Kalender 2
Auteur: DenMette - 16 december 2008 - 00:32 - Gekeurd door: Gerard - Hits: 5891 - Aantal punten: (0 stemmen)
Beste gebruiker,
Dit is mijn tweede kalender dat ik hier plaats ondertussen. Deze is iets anders dan de andere. Deze kalender heb ik gemaakt voor mijn eigen site en ik dacht laat ik hem hier zetten want soms heb je gewoon een kalender nodig.
Hoe werkt de kalender nu eigenlijk. Het is een functie met 3 parameters.
Eerste parameter is de URL, deze kan bijvoorbeeld zijn : index.php?page=test of contact.php.
Tweede parameter is de maand, als numerieke waarde.
Derde parameter is het jaar, als numerieke waarde.
Veel succes ermee. Het script zal voor u rechtstreeks een mooie en propere link generen.
|
Code: |
<?php
if ((!isset ($_GET['m']) || empty ($_GET['m']) || !is_numeric ($_GET['m'])) || (!isset ($_GET['y']) || empty ($_GET['y']) || !is_numeric ($_GET['y'])))
{
$iMonth = date ("n", time ());
$iYear = date ("Y", time ());
}
else
{
$iMonth = $_GET['m'];
$iYear = $_GET['y'];
}
printHtmlCalendar ("index.php?page=".$_GET['page'], $iMonth, $iYear);
function printHtmlCalendar ($sUrl, $iMonth, $iYear)
{
if (ereg ("[?]", $sUrl))
{
$sUrl .= "&";
}
else
{
$sUrl .= "?";
}
$aMonths = array (1 => "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
$iToday = mktime (0, 0, 0, $iMonth, 1, $iYear);
$iTotalMonthDays = date ("t", $iToday);
$iStartMonthWeekDay = date ("w", $iToday);
$iLastMonthWeekDay = date ("w", mktime (0, 0, 0, date ("n", $iToday), $iTotalMonthDays, date ("Y", $iToday)));
if ($iStartMonthWeekDay == 0) $iStartMonthWeekDay = 7;
if ($iLastMonthWeekDay == 0) $iLastMonthWeekDay = 7;
$iPlusTr = $iStartMonthWeekDay;
?>
<table summary='Kalender'>
<caption>
<?php echo $aMonths[date ("n", $iToday)]; ?> <?php echo date ("Y", $iToday); ?>
</caption>
<colgroup span='7' align='center' width='30px'></colgroup>
<thead>
<tr>
<th scope='col' title='Maandag'>M</th>
<th scope='col' title='Dinsdag'>D</th>
<th scope='col' title='Woensdag'>W</th>
<th scope='col' title='Donderdag'>D</th>
<th scope='col' title='Vrijdag'>V</th>
<th scope='col' title='Zaterdag'>Z</th>
<th scope='col' title='Zondag'>Z</th>
</tr>
</thead>
<?php
// Footer of table
$iPrevMonth = $iMonth - 1;
$iNextMonth = $iMonth + 1;
$iPrevYear = $iYear;
$iNextYear = $iYear;
if ($iPrevMonth == 0)
{
$iPrevMonth = 12;
$iPrevYear = $iYear - 1;
}
if ($iNextMonth == 13)
{
$iNextMonth = 1;
$iNextYear = $iYear + 1;
}
?>
<tfoot>
<tr>
<td colspan='3' id='prev' title='<?php echo $aMonths[$iPrevMonth]; ?>'><a href='<?php echo $sUrl; ?>m=<?php echo $iPrevMonth; ?>&y=<?php echo $iPrevYear; ?>'>« <?php echo substr ($aMonths[$iPrevMonth], 0, 3); ?></a></td>
<td class='pad'> </td>
<td colspan='3' id='next' title='<?php echo $aMonths[$iNextMonth]; ?>'><a href='<?php echo $sUrl; ?>m=<?php echo $iNextMonth; ?>&y=<?php echo $iNextYear; ?>'><?php echo substr ($aMonths[$iNextMonth], 0, 3); ?> »</a></td>
</tr>
</tfoot>
<tbody>
<tr>
<?php
// Empty Days @ the front
if ($iStartMonthWeekDay != 1)
{
?>
<td class='pad' colspan='<?php echo ($iStartMonthWeekDay - 1); ?>'> </td>
<?php
}
// Days in the month
for ($iDay = 1; $iDay <= $iTotalMonthDays; $iDay++, $iPlusTr++)
{
if (date ("j-n-Y", time ()) == ($iDay."-".$iMonth."-".$iYear))
{
?>
<td id='today'><?php echo $iDay; ?></td>
<?php
}
else
{
?>
<td><?php echo $iDay; ?></td>
<?php
}
if (($iPlusTr % 7) == 0)
{
?>
</tr>
<tr>
<?php
}
}
// Empty Days @ the end
if ($iLastMonthWeekDay != 7)
{
?>
<td class='pad' colspan='<?php echo (7 - $iLastMonthWeekDay); ?>'> </td>
<?php
}
?>
</tr>
</tbody>
</table>
<?php
}
?>
<?php { } else { $iMonth = $_GET['m']; $iYear = $_GET['y']; } printHtmlCalendar ("index.php?page=".$_GET['page'], $iMonth, $iYear); function printHtmlCalendar ($sUrl, $iMonth, $iYear) { { $sUrl .= "&"; } else { $sUrl .= "?"; } $aMonths = array (1 => "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"); $iToday = mktime (0, 0, 0, $iMonth, 1, $iYear); $iTotalMonthDays = date ("t", $iToday); $iStartMonthWeekDay = date ("w", $iToday); $iLastMonthWeekDay = date ("w", mktime (0, 0, 0, date ("n", $iToday), $iTotalMonthDays, date ("Y", $iToday))); if ($iStartMonthWeekDay == 0) $iStartMonthWeekDay = 7; if ($iLastMonthWeekDay == 0) $iLastMonthWeekDay = 7; $iPlusTr = $iStartMonthWeekDay; ?> <table summary='Kalender'> <caption> <?php echo $aMonths[date ("n", $iToday)]; ?> <?php echo date ("Y", $iToday); ?> </caption> <colgroup span='7' align='center' width='30px'></colgroup> <thead> <tr> <th scope='col' title='Maandag'>M</th> <th scope='col' title='Dinsdag'>D</th> <th scope='col' title='Woensdag'>W</th> <th scope='col' title='Donderdag'>D</th> <th scope='col' title='Vrijdag'>V</th> <th scope='col' title='Zaterdag'>Z</th> <th scope='col' title='Zondag'>Z</th> </tr> </thead> <?php // Footer of table $iPrevMonth = $iMonth - 1; $iNextMonth = $iMonth + 1; $iPrevYear = $iYear; $iNextYear = $iYear; if ($iPrevMonth == 0) { $iPrevMonth = 12; $iPrevYear = $iYear - 1; } if ($iNextMonth == 13) { $iNextMonth = 1; $iNextYear = $iYear + 1; } ?> <tfoot> <tr> <td colspan='3' id='prev' title=' <?php echo $aMonths[$iPrevMonth]; ?>'><a href=' <?php echo $sUrl; ?>m= <?php echo $iPrevMonth; ?>&y= <?php echo $iPrevYear; ?>'>« <?php echo substr ($aMonths[$iPrevMonth], 0, 3); ?></a></td> <td class='pad'> </td> <td colspan='3' id='next' title=' <?php echo $aMonths[$iNextMonth]; ?>'><a href=' <?php echo $sUrl; ?>m= <?php echo $iNextMonth; ?>&y= <?php echo $iNextYear; ?>'> <?php echo substr ($aMonths[$iNextMonth], 0, 3); ?> »</a></td> </tr> </tfoot> <tbody> <tr> <?php // Empty Days @ the front if ($iStartMonthWeekDay != 1) { ?> <td class='pad' colspan=' <?php echo ($iStartMonthWeekDay - 1); ?>'> </td> <?php } // Days in the month for ($iDay = 1; $iDay <= $iTotalMonthDays; $iDay++, $iPlusTr++) { if (date ("j-n-Y", time ()) == ($iDay."-".$iMonth."-".$iYear)) { ?> <td id='today'> <?php echo $iDay; ?></td> <?php } else { ?> <td> <?php echo $iDay; ?></td> <?php } if (($iPlusTr % 7) == 0) { ?> </tr> <tr> <?php } } // Empty Days @ the end if ($iLastMonthWeekDay != 7) { ?> <td class='pad' colspan=' <?php echo (7 - $iLastMonthWeekDay); ?>'> </td> <?php } ?> </tr> </tbody> </table> <?php } ?>
Dit is dezelfde code alleen met de HTML in de PHP. Dus niet zoals hierboven.
<?php
if ((!isset ($_GET['m']) || empty ($_GET['m']) || !is_numeric ($_GET['m'])) || (!isset ($_GET['y']) || empty ($_GET['y']) || !is_numeric ($_GET['y'])))
{
$iMonth = date ("n", time ());
$iYear = date ("Y", time ());
}
else
{
$iMonth = $_GET['m'];
$iYear = $_GET['y'];
}
printHtmlCalendar ("index.php?page=".$_GET['page'], $iMonth, $iYear);
function printHtmlCalendar ($sUrl, $iMonth, $iYear)
{
if (ereg ("[?]", $sUrl))
{
$sUrl .= "&";
}
else
{
$sUrl .= "?";
}
$aMonths = array (1 => "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
$iToday = mktime (0, 0, 0, $iMonth, 1, $iYear);
$iTotalMonthDays = date ("t", $iToday);
$iStartMonthWeekDay = date ("w", $iToday);
$iLastMonthWeekDay = date ("w", mktime (0, 0, 0, date ("n", $iToday), $iTotalMonthDays, date ("Y", $iToday)));
if ($iStartMonthWeekDay == 0) $iStartMonthWeekDay = 7;
if ($iLastMonthWeekDay == 0) $iLastMonthWeekDay = 7;
$iPlusTr = $iStartMonthWeekDay;
print ("<table summary='Kalender'>");
// Month & Year
print ("\n <caption>");
print ("\n ". $aMonths[date ("n", $iToday)] ." ". date ("Y", $iToday));
print ("\n </caption>");
// Colgroup
print ("\n <colgroup span='7' align='center' width='30px'></colgroup>");
// Day of the week
print ("\n <thead>");
print ("\n <tr>");
print ("\n <th scope='col' title='Maandag'>M</th>");
print ("\n <th scope='col' title='Dinsdag'>D</th>");
print ("\n <th scope='col' title='Woensdag'>W</th>");
print ("\n <th scope='col' title='Donderdag'>D</th>");
print ("\n <th scope='col' title='Vrijdag'>V</th>");
print ("\n <th scope='col' title='Zaterdag'>Z</th>");
print ("\n <th scope='col' title='Zondag'>Z</th>");
print ("\n </tr>");
print ("\n </thead>");
// Footer of table
$iPrevMonth = $iMonth - 1;
$iNextMonth = $iMonth + 1;
$iPrevYear = $iYear;
$iNextYear = $iYear;
if ($iPrevMonth == 0)
{
$iPrevMonth = 12;
$iPrevYear = $iYear - 1;
}
if ($iNextMonth == 13)
{
$iNextMonth = 1;
$iNextYear = $iYear + 1;
}
print ("\n <tfoot>");
print ("\n <tr>");
print ("\n <td colspan='3' id='prev' title='". $aMonths[$iPrevMonth] ."'><a href='". $sUrl ."m=". $iPrevMonth ."&y=". $iPrevYear ."'>« ". substr ($aMonths[$iPrevMonth], 0, 3) ."</a></td>");
print ("\n <td class='pad'> </td>");
print ("\n <td colspan='3' id='next' title='". $aMonths[$iNextMonth] ."'><a href='". $sUrl ."m=". $iNextMonth ."&y=". $iNextYear ."'>". substr ($aMonths[$iNextMonth], 0, 3) ." »</a></td>");
print ("\n </tr>");
print ("\n </tfoot>");
// Table Content
print ("\n <tbody>");
print ("\n <tr>");
// Empty Days @ the front
if ($iStartMonthWeekDay != 1)
{
print ("\n <td class='pad' colspan='". ($iStartMonthWeekDay - 1) ."'> </td>");
}
// Days in the month
for ($iDay = 1; $iDay <= $iTotalMonthDays; $iDay++, $iPlusTr++)
{
if (date ("d-n-Y", time ()) == ($iDay."-".$iMonth."-".$iYear))
{
print ("\n <td id='today'>". $iDay ."</td>");
}
else
{
print ("\n <td>". $iDay ."</td>");
}
if (($iPlusTr % 7) == 0)
{
print ("\n </tr>");
print ("\n <tr>");
}
}
// Empty Days @ the end
if ($iLastMonthWeekDay != 7)
{
print ("\n <td class='pad' colspan='". (7 - $iLastMonthWeekDay) ."'> </td>");
}
print ("\n </tr>");
print ("\n </tbody>");
print ("\n</table>\n");
}
?>
<?php { } else { $iMonth = $_GET['m']; $iYear = $_GET['y']; } printHtmlCalendar ("index.php?page=".$_GET['page'], $iMonth, $iYear); function printHtmlCalendar ($sUrl, $iMonth, $iYear) { { $sUrl .= "&"; } else { $sUrl .= "?"; } $aMonths = array (1 => "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"); $iToday = mktime (0, 0, 0, $iMonth, 1, $iYear); $iTotalMonthDays = date ("t", $iToday); $iStartMonthWeekDay = date ("w", $iToday); $iLastMonthWeekDay = date ("w", mktime (0, 0, 0, date ("n", $iToday), $iTotalMonthDays, date ("Y", $iToday))); if ($iStartMonthWeekDay == 0) $iStartMonthWeekDay = 7; if ($iLastMonthWeekDay == 0) $iLastMonthWeekDay = 7; $iPlusTr = $iStartMonthWeekDay; print ("<table summary='Kalender'>"); // Month & Year print ("\n ". $aMonths[date ("n", $iToday)] ." ". date ("Y", $iToday)); // Colgroup print ("\n <colgroup span='7' align='center' width='30px'></colgroup>"); // Day of the week print ("\n <th scope='col' title='Maandag'>M</th>"); print ("\n <th scope='col' title='Dinsdag'>D</th>"); print ("\n <th scope='col' title='Woensdag'>W</th>"); print ("\n <th scope='col' title='Donderdag'>D</th>"); print ("\n <th scope='col' title='Vrijdag'>V</th>"); print ("\n <th scope='col' title='Zaterdag'>Z</th>"); print ("\n <th scope='col' title='Zondag'>Z</th>"); // Footer of table $iPrevMonth = $iMonth - 1; $iNextMonth = $iMonth + 1; $iPrevYear = $iYear; $iNextYear = $iYear; if ($iPrevMonth == 0) { $iPrevMonth = 12; $iPrevYear = $iYear - 1; } if ($iNextMonth == 13) { $iNextMonth = 1; $iNextYear = $iYear + 1; } print ("\n <td colspan='3' id='prev' title='". $aMonths[$iPrevMonth] ."'><a href='". $sUrl ."m=". $iPrevMonth ."&y=". $iPrevYear ."'>« ". substr ($aMonths[$iPrevMonth], 0, 3) ."</a></td>"); print ("\n <td class='pad'> </td>"); print ("\n <td colspan='3' id='next' title='". $aMonths[$iNextMonth] ."'><a href='". $sUrl ."m=". $iNextMonth ."&y=". $iNextYear ."'>". substr ($aMonths[$iNextMonth], 0, 3) ." »</a></td>"); // Table Content // Empty Days @ the front if ($iStartMonthWeekDay != 1) { print ("\n <td class='pad' colspan='". ($iStartMonthWeekDay - 1) ."'> </td>"); } // Days in the month for ($iDay = 1; $iDay <= $iTotalMonthDays; $iDay++, $iPlusTr++) { if (date ("d-n-Y", time ()) == ($iDay."-".$iMonth."-".$iYear)) { print ("\n <td id='today'>". $iDay ."</td>"); } else { print ("\n <td>". $iDay ."</td>"); } if (($iPlusTr % 7) == 0) { } } // Empty Days @ the end if ($iLastMonthWeekDay != 7) { print ("\n <td class='pad' colspan='". (7 - $iLastMonthWeekDay) ."'> </td>"); } } ?>
Download code (.txt)
|
|
|
Stemmen |
Niet ingelogd. |
|