login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Kalenders > Kalender 2

Kalender 2

Auteur: DenMette - 16 december 2008 - 00:32 - Gekeurd door: Gerard - Hits: 5789 - 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:
  1. <?php
  2. if ((!isset ($_GET['m']) || empty ($_GET['m']) || !is_numeric ($_GET['m'])) || (!isset ($_GET['y']) || empty ($_GET['y']) || !is_numeric ($_GET['y'])))
  3. {
  4. $iMonth = date ("n", time ());
  5. $iYear = date ("Y", time ());
  6. }
  7. else
  8. {
  9. $iMonth = $_GET['m'];
  10. $iYear = $_GET['y'];
  11. }
  12. printHtmlCalendar ("index.php?page=".$_GET['page'], $iMonth, $iYear);
  13.  
  14. function printHtmlCalendar ($sUrl, $iMonth, $iYear)
  15. {
  16. if (ereg ("[?]", $sUrl))
  17. {
  18. $sUrl .= "&amp;";
  19. }
  20. else
  21. {
  22. $sUrl .= "?";
  23. }
  24.  
  25. $aMonths = array (1 => "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
  26.  
  27. $iToday = mktime (0, 0, 0, $iMonth, 1, $iYear);
  28.  
  29. $iTotalMonthDays = date ("t", $iToday);
  30. $iStartMonthWeekDay = date ("w", $iToday);
  31. $iLastMonthWeekDay = date ("w", mktime (0, 0, 0, date ("n", $iToday), $iTotalMonthDays, date ("Y", $iToday)));
  32.  
  33. if ($iStartMonthWeekDay == 0) $iStartMonthWeekDay = 7;
  34. if ($iLastMonthWeekDay == 0) $iLastMonthWeekDay = 7;
  35.  
  36. $iPlusTr = $iStartMonthWeekDay;
  37. ?>
  38. <table summary='Kalender'>
  39. <caption>
  40. <?php echo $aMonths[date ("n", $iToday)]; ?>&nbsp;<?php echo date ("Y", $iToday); ?>
  41. </caption>
  42. <colgroup span='7' align='center' width='30px'></colgroup>
  43. <thead>
  44. <tr>
  45. <th scope='col' title='Maandag'>M</th>
  46. <th scope='col' title='Dinsdag'>D</th>
  47. <th scope='col' title='Woensdag'>W</th>
  48. <th scope='col' title='Donderdag'>D</th>
  49. <th scope='col' title='Vrijdag'>V</th>
  50. <th scope='col' title='Zaterdag'>Z</th>
  51. <th scope='col' title='Zondag'>Z</th>
  52. </tr>
  53. </thead>
  54. <?php
  55. // Footer of table
  56. $iPrevMonth = $iMonth - 1;
  57. $iNextMonth = $iMonth + 1;
  58. $iPrevYear = $iYear;
  59. $iNextYear = $iYear;
  60. if ($iPrevMonth == 0)
  61. {
  62. $iPrevMonth = 12;
  63. $iPrevYear = $iYear - 1;
  64. }
  65. if ($iNextMonth == 13)
  66. {
  67. $iNextMonth = 1;
  68. $iNextYear = $iYear + 1;
  69. }
  70. ?>
  71. <tfoot>
  72. <tr>
  73. <td colspan='3' id='prev' title='<?php echo $aMonths[$iPrevMonth]; ?>'><a href='<?php echo $sUrl; ?>m=<?php echo $iPrevMonth; ?>&amp;y=<?php echo $iPrevYear; ?>'>&laquo; <?php echo substr ($aMonths[$iPrevMonth], 0, 3); ?></a></td>
  74. <td class='pad'>&nbsp;</td>
  75. <td colspan='3' id='next' title='<?php echo $aMonths[$iNextMonth]; ?>'><a href='<?php echo $sUrl; ?>m=<?php echo $iNextMonth; ?>&amp;y=<?php echo $iNextYear; ?>'><?php echo substr ($aMonths[$iNextMonth], 0, 3); ?> &raquo;</a></td>
  76. </tr>
  77. </tfoot>
  78. <tbody>
  79. <tr>
  80. <?php
  81. // Empty Days @ the front
  82. if ($iStartMonthWeekDay != 1)
  83. {
  84. ?>
  85. <td class='pad' colspan='<?php echo ($iStartMonthWeekDay - 1); ?>'>&nbsp;</td>
  86. <?php
  87. }
  88. // Days in the month
  89. for ($iDay = 1; $iDay <= $iTotalMonthDays; $iDay++, $iPlusTr++)
  90. {
  91. if (date ("j-n-Y", time ()) == ($iDay."-".$iMonth."-".$iYear))
  92. {
  93. ?>
  94. <td id='today'><?php echo $iDay; ?></td>
  95. <?php
  96. }
  97. else
  98. {
  99. ?>
  100. <td><?php echo $iDay; ?></td>
  101. <?php
  102. }
  103. if (($iPlusTr % 7) == 0)
  104. {
  105. ?>
  106. </tr>
  107. <tr>
  108. <?php
  109. }
  110. }
  111. // Empty Days @ the end
  112. if ($iLastMonthWeekDay != 7)
  113. {
  114. ?>
  115. <td class='pad' colspan='<?php echo (7 - $iLastMonthWeekDay); ?>'>&nbsp;</td>
  116. <?php
  117. }
  118. ?>
  119. </tr>
  120. </tbody>
  121. </table>
  122. <?php
  123. }
  124. ?>



Dit is dezelfde code alleen met de HTML in de PHP. Dus niet zoals hierboven.
  1. <?php
  2. if ((!isset ($_GET['m']) || empty ($_GET['m']) || !is_numeric ($_GET['m'])) || (!isset ($_GET['y']) || empty ($_GET['y']) || !is_numeric ($_GET['y'])))
  3. {
  4. $iMonth = date ("n", time ());
  5. $iYear = date ("Y", time ());
  6. }
  7. else
  8. {
  9. $iMonth = $_GET['m'];
  10. $iYear = $_GET['y'];
  11. }
  12. printHtmlCalendar ("index.php?page=".$_GET['page'], $iMonth, $iYear);
  13.  
  14. function printHtmlCalendar ($sUrl, $iMonth, $iYear)
  15. {
  16. if (ereg ("[?]", $sUrl))
  17. {
  18. $sUrl .= "&amp;";
  19. }
  20. else
  21. {
  22. $sUrl .= "?";
  23. }
  24.  
  25. $aMonths = array (1 => "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December");
  26.  
  27. $iToday = mktime (0, 0, 0, $iMonth, 1, $iYear);
  28.  
  29. $iTotalMonthDays = date ("t", $iToday);
  30. $iStartMonthWeekDay = date ("w", $iToday);
  31. $iLastMonthWeekDay = date ("w", mktime (0, 0, 0, date ("n", $iToday), $iTotalMonthDays, date ("Y", $iToday)));
  32.  
  33. if ($iStartMonthWeekDay == 0) $iStartMonthWeekDay = 7;
  34. if ($iLastMonthWeekDay == 0) $iLastMonthWeekDay = 7;
  35.  
  36. $iPlusTr = $iStartMonthWeekDay;
  37.  
  38. print ("<table summary='Kalender'>");
  39. // Month & Year
  40. print ("\n <caption>");
  41. print ("\n ". $aMonths[date ("n", $iToday)] ."&nbsp;". date ("Y", $iToday));
  42. print ("\n </caption>");
  43. // Colgroup
  44. print ("\n <colgroup span='7' align='center' width='30px'></colgroup>");
  45. // Day of the week
  46. print ("\n <thead>");
  47. print ("\n <tr>");
  48. print ("\n <th scope='col' title='Maandag'>M</th>");
  49. print ("\n <th scope='col' title='Dinsdag'>D</th>");
  50. print ("\n <th scope='col' title='Woensdag'>W</th>");
  51. print ("\n <th scope='col' title='Donderdag'>D</th>");
  52. print ("\n <th scope='col' title='Vrijdag'>V</th>");
  53. print ("\n <th scope='col' title='Zaterdag'>Z</th>");
  54. print ("\n <th scope='col' title='Zondag'>Z</th>");
  55. print ("\n </tr>");
  56. print ("\n </thead>");
  57. // Footer of table
  58. $iPrevMonth = $iMonth - 1;
  59. $iNextMonth = $iMonth + 1;
  60. $iPrevYear = $iYear;
  61. $iNextYear = $iYear;
  62. if ($iPrevMonth == 0)
  63. {
  64. $iPrevMonth = 12;
  65. $iPrevYear = $iYear - 1;
  66. }
  67. if ($iNextMonth == 13)
  68. {
  69. $iNextMonth = 1;
  70. $iNextYear = $iYear + 1;
  71. }
  72. print ("\n <tfoot>");
  73. print ("\n <tr>");
  74. print ("\n <td colspan='3' id='prev' title='". $aMonths[$iPrevMonth] ."'><a href='". $sUrl ."m=". $iPrevMonth ."&amp;y=". $iPrevYear ."'>&laquo; ". substr ($aMonths[$iPrevMonth], 0, 3) ."</a></td>");
  75. print ("\n <td class='pad'>&nbsp;</td>");
  76. print ("\n <td colspan='3' id='next' title='". $aMonths[$iNextMonth] ."'><a href='". $sUrl ."m=". $iNextMonth ."&amp;y=". $iNextYear ."'>". substr ($aMonths[$iNextMonth], 0, 3) ." &raquo;</a></td>");
  77. print ("\n </tr>");
  78. print ("\n </tfoot>");
  79. // Table Content
  80. print ("\n <tbody>");
  81. print ("\n <tr>");
  82. // Empty Days @ the front
  83. if ($iStartMonthWeekDay != 1)
  84. {
  85. print ("\n <td class='pad' colspan='". ($iStartMonthWeekDay - 1) ."'>&nbsp;</td>");
  86. }
  87. // Days in the month
  88. for ($iDay = 1; $iDay <= $iTotalMonthDays; $iDay++, $iPlusTr++)
  89. {
  90. if (date ("d-n-Y", time ()) == ($iDay."-".$iMonth."-".$iYear))
  91. {
  92. print ("\n <td id='today'>". $iDay ."</td>");
  93. }
  94. else
  95. {
  96. print ("\n <td>". $iDay ."</td>");
  97. }
  98. if (($iPlusTr % 7) == 0)
  99. {
  100. print ("\n </tr>");
  101. print ("\n <tr>");
  102. }
  103. }
  104. // Empty Days @ the end
  105. if ($iLastMonthWeekDay != 7)
  106. {
  107. print ("\n <td class='pad' colspan='". (7 - $iLastMonthWeekDay) ."'>&nbsp;</td>");
  108. }
  109. print ("\n </tr>");
  110. print ("\n </tbody>");
  111. print ("\n</table>\n");
  112. }
  113. ?>

Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Geen reacties (0)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.056s