Ejemplo n.º 1
0
 /**
  * A function to generate week view of a set of events
  * @param array $day day to show
  * @param integer $month month to show
  * @param integer $year year to show
  * @param array $weekdaynames
  * @return object with `count` attribute containing the number of associated events with the item
  */
 public static function week_calendar($day, $month, $year)
 {
     global $langEvents, $langActions, $langCalendar, $langDateNow, $is_editor, $dateFormatLong, $langNoEvents, $langDay, $langWeek, $langMonth, $langView;
     $calendar_content = "";
     if (is_null($day)) {
         $day = 1;
     }
     $nextweekdate = new DateTime("{$year}-{$month}-{$day}");
     $nextweekdate->add(new DateInterval('P1W'));
     $previousweekdate = new DateTime("{$year}-{$month}-{$day}");
     $previousweekdate->sub(new DateInterval('P1W'));
     $thisweekday = new DateTime("{$year}-{$month}-{$day}");
     $difffromMonday = $thisweekday->format('w') == 0 ? 6 : $thisweekday->format('w') - 1;
     $monday = $thisweekday->sub(new DateInterval('P' . $difffromMonday . 'D'));
     //Sunday->1, ..., Saturday->7
     $weekdescription = ucfirst(claro_format_locale_date($dateFormatLong, $monday->getTimestamp()));
     $sunday = $thisweekday->add(new DateInterval('P6D'));
     $weekdescription .= ' - ' . ucfirst(claro_format_locale_date($dateFormatLong, $sunday->getTimestamp()));
     $cursorday = $thisweekday->sub(new DateInterval('P6D'));
     $backward = array('day' => $previousweekdate->format('d'), 'month' => $previousweekdate->format('m'), 'year' => $previousweekdate->format('Y'));
     $foreward = array('day' => $nextweekdate->format('d'), 'month' => $nextweekdate->format('m'), 'year' => $nextweekdate->format('Y'));
     $calendar_content .= '<div class="right" style="width:100%">' . $langView . ':&nbsp;' . '<a href="#" onclick="show_day(selectedday, selectedmonth, selectedyear);return false;">' . $langDay . '</a>&nbsp;|&nbsp;' . '<a href="#" onclick="show_week(selectedday, selectedmonth, selectedyear);return false;">' . $langWeek . '</a>&nbsp;|&nbsp;' . '<a href="#" onclick="show_month(selectedday, selectedmonth, selectedyear);return false;">' . $langMonth . '</a></div>';
     $calendar_content .= "<table class='table-default'>";
     $calendar_content .= "<tr>";
     $calendar_content .= '<td width="25"><a href="#" onclick="show_week(' . $backward['day'] . ',' . $backward['month'] . ',' . $backward['year'] . '); return false;">&laquo;</a></td>';
     $calendar_content .= "<td class='center'><b>{$weekdescription}</b></td>";
     $calendar_content .= '<td width="25" class="right"><a href="#" onclick="show_week(' . $foreward['day'] . ',' . $foreward['month'] . ',' . $foreward['year'] . '); return false;">&raquo;</a></td>';
     $calendar_content .= "</tr>";
     $calendar_content .= "</table>";
     $eventlist = Calendar_Events::get_calendar_events("week", "{$year}-{$month}-{$day}");
     //$dateNow = date("j-n-Y", time());
     $numLine = 0;
     $calendar_content .= "<table width='100%' class='tbl_alt'>";
     //                <tr><th colspan='2' class='left'>$langEvents</th>";
     //$calendar_content .= "<th width='50'><b>$langActions</b></th>";
     //$calendar_content .= "</tr>";
     $curday = 0;
     $now = getdate();
     $today = new DateTime($now['year'] . '-' . $now['mon'] . '-' . $now['mday']);
     $curstartddate = "";
     foreach ($eventlist as $thisevent) {
         if ($curstartddate != $thisevent->startdate) {
             //event date changed
             $thiseventdatetime = new DateTime($thisevent->startdate);
             while ($cursorday < $thiseventdatetime) {
                 if ($cursorday == $today) {
                     $class = 'today';
                 } else {
                     $class = 'monthLabel';
                 }
                 $calendar_content .= "<tr><td colspan='3' class='{$class}'>" . "&nbsp;<b>" . ucfirst(claro_format_locale_date($dateFormatLong, $cursorday->getTimestamp())) . "</b></td></tr>";
                 $calendar_content .= "<tr><td colspan='3'>{$langNoEvents}</td></tr>";
                 $cursorday->add(new DateInterval('P1D'));
                 $curday++;
             }
             /*if ($numLine % 2 == 0) {
                   $classvis = "class='even'";
               } else {
                   $classvis = "class='odd'";
               }*/
             if ($thiseventdatetime == $today) {
                 $class = 'today';
             } else {
                 $class = 'monthLabel';
             }
             $calendar_content .= "<tr><td colspan='3' class='{$class}'>" . "&nbsp;<b>" . ucfirst(claro_format_locale_date($dateFormatLong, strtotime($thisevent->startdate))) . "</b></td></tr>";
             if ($cursorday <= $thiseventdatetime) {
                 $cursorday->add(new DateInterval('P1D'));
                 $curday++;
             }
         }
         $calendar_content .= Calendar_Events::week_calendar_item($thisevent, 'even');
         $curstartddate = $thisevent->startdate;
         //$numLine++;
     }
     /* Fill with empty days*/
     for ($i = $curday; $i < 7; $i++) {
         if ($cursorday == $today) {
             $class = 'today';
         } else {
             $class = 'monthLabel';
         }
         $calendar_content .= "<tr><td colspan='3' class='{$class}'>" . "&nbsp;<b>" . ucfirst(claro_format_locale_date($dateFormatLong, $cursorday->getTimestamp())) . "</b></td></tr>";
         $calendar_content .= "<tr><td colspan='3'>{$langNoEvents}</td></tr>";
         $cursorday->add(new DateInterval('P1D'));
     }
     $calendar_content .= "</table>";
     /* Legend */
     $calendar_content .= Calendar_Events::calendar_legend();
     return $calendar_content;
 }