Advertisement
dimipan80

Awesome Calendar

Apr 12th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.56 KB | None | 0 0
  1. <!--Write a PHP script AwesomeCalendar.php which creates a calendar in HTML for a given year.
  2. Styling the calendar is optional. Semantic HTML is required. Hint: Embed HTML in your PHP code.
  3. Use tables or divs for structuring the calendar. Look for a way to find the day of the week.-->
  4.  
  5. <!DOCTYPE html>
  6. <html>
  7. <head lang="en">
  8.     <meta content="text/html" charset="UTF-8">
  9.     <title>Awesome Calendar</title>
  10.     <style type="text/css">
  11.         #wrapper {
  12.             margin: auto;
  13.             width: 750px;
  14.             display: block;
  15.         }
  16.  
  17.         header {
  18.             text-align: center;
  19.             border-bottom: 1px solid #000;
  20.         }
  21.  
  22.         h1 {
  23.             font-family: Geneva, sans-serif;
  24.             font-size: 40px;
  25.             margin: 5px;
  26.         }
  27.  
  28.         section {
  29.             padding-top: 15px;
  30.         }
  31.  
  32.         .monthTable {
  33.             display: inline-table;
  34.             margin-right: 20px;
  35.         }
  36.  
  37.         .monthTable:last-child {
  38.             margin-right: 0;
  39.         }
  40.  
  41.         tr th {
  42.             border-bottom: 1px solid #000;
  43.         }
  44.  
  45.         tr:last-child > th:last-child {
  46.             color: #F00;
  47.         }
  48.  
  49.         td {
  50.             font-weight: 600;
  51.         }
  52.     </style>
  53. </head>
  54. <body>
  55. <div id=wrapper>
  56.     <?php
  57.     function buildAwesomeCalendar($givenYear) {
  58.         echo "<header><h1>$givenYear</h1></header><section><table id='outerTable'><tbody><tr><td>";
  59.         $months = array('Януари', 'Февруари', 'Март', 'Април', 'Май', 'Юни', 'Юли', 'Август', 'Септември',
  60.             'Октомври', 'Ноември', 'Декември');
  61.         foreach ($months as $key => $month) {
  62.             echo "<table class='monthTable'><thead><tr><th colspan=\"7\">$months[$key]</th></tr><tr><th>По</th>" .
  63.                 '<th>Вт</th><th>Ср</th><th>Чт</th><th>Пе</th><th>Сб</th><th>Не</th></tr></thead><tbody>';
  64.  
  65.             $currentDay = mktime(0, 0, 0, ((int)$key + 1), 1, $givenYear);
  66.             $daysInMonth = date('t', $currentDay);
  67.             $weekCounter = 0;
  68.             $printedDays = 0;
  69.  
  70.             do {
  71.                 $tableRow = '<tr>';
  72.                 for ($i = 1; $i < 8; $i++) {
  73.                     $dayOfWeek = date('N', $currentDay);
  74.                     if ($i < $dayOfWeek || $i > $dayOfWeek || ($printedDays >= $daysInMonth)) {
  75.                         $tableRow .= "<td>&#32;</td>";
  76.                         continue;
  77.                     }
  78.  
  79.                     $dayOfMonth = date('j', $currentDay);
  80.                     $tableRow .= "<td>$dayOfMonth</td>";
  81.                     $printedDays++;
  82.                     $currentDay = strtotime('+1 day', $currentDay);
  83.                 }
  84.  
  85.                 echo $tableRow . '</tr>';
  86.                 $weekCounter++;
  87.  
  88.             } while ($weekCounter <= 5);
  89.  
  90.             echo '</tbody></table>';
  91.  
  92.             if (((int)$key % 4) == 3) {
  93.                 if ($key < 11) {
  94.                     echo '</td></tr><tr><td>';
  95.                 } else {
  96.                     echo '</td></tr>';
  97.                 }
  98.             }
  99.         }
  100.  
  101.         echo '</tbody></table></section>';
  102.     }
  103.  
  104.     buildAwesomeCalendar(2014);
  105.     ?>
  106. </div>
  107. </body>
  108. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement