reset($this->children); return false; } } } // Calendar instance used to get the dates in the preferred format: // you can switch Calendar Engine and the example still works $cal = new Calendar(); $events = array(); //add some events $events[] = array('start' => $cal->cE->dateToStamp(2004, 6, 1, 10), 'end' => $cal->cE->dateToStamp(2004, 6, 1, 12), 'desc' => 'Important meeting'); $events[] = array('start' => $cal->cE->dateToStamp(2004, 6, 1, 21), 'end' => $cal->cE->dateToStamp(2004, 6, 1, 23, 59), 'desc' => 'Dinner with the boss'); $events[] = array('start' => $cal->cE->dateToStamp(2004, 6, 5), 'end' => $cal->cE->dateToStamp(2004, 6, 10, 23, 59), 'desc' => 'Holidays!'); $Month =& new Calendar_Month_Weekdays(2004, 6); $MonthDecorator = new MonthPayload_Decorator($Month); $MonthDecorator->build($events); ?> <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> Calendar </title> <style text="text/css"> table { border-collapse: collapse; } caption { font-family: verdana; font-size: 14pt; padding-bottom: 4pt; } th {
function smarty_function_calendar($params, &$smarty){ require_once $smarty->_get_plugin_filepath('function','html_select_date'); $days = array('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'); $months = array(1=>'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'); $start = 'start'; $end = 'end'; $desc = 'desc'; $year = ''; $month = ''; $id = null; // Month is required if (!isset($params['month'])) $month = date("m"); else $month = $params['month']; // Year is required if (!isset($params['year'])) $year = date("Y"); else $year = $params['year']; // Name of day of the week if(isset($params['days'])){ unset($days); $days = $params['days']; } if(isset($params['months'])){ unset($months); $months = $params['months']; } if(isset($params['events'])){ // This param describe who is the field that // contain the info of star date, if there's not // is the same name if(isset($params['start'])){ $start = $params['start']; } // Describe name field of the end date if(isset($params['end'])){ $end = $params['end']; } // Field describe the description of event if(isset($params['desc'])){ $desc = $params['desc']; } // Field id is number unique of the event if(isset($params['id'])){ $id = $params['id']; } $events = array(); // add the events for($i=0;$i<count($params['events']);$i++){ $events[] = array( 'id' => $params['events'][$i][$id], 'start' => $params['events'][$i][$start], 'end' => $params['events'][$i][$end], 'desc' => $params['events'][$i][$desc] ); } } $Month = & new Calendar_Month_Weekdays($year, $month); $MonthDecorator = new MonthPayload_Decorator($Month); $MonthDecorator->build($events); echo '<table class="calendar" cellspacing="0" cellpadding="0" border="0">'; echo '<caption class="caption">'; echo $months[$MonthDecorator->thisMonth()].' / '.$MonthDecorator->thisYear(); echo '</caption>'; echo '<tr>'; // Days of weeks for($i=0;$i<count($days);$i++) echo '<th class="day_week">'.$days[$i].'</th>'; echo '</tr>'; while ($Day = $MonthDecorator->fetch()) { if ($Day->isFirst()) { echo "<tr>\n"; } echo '<td class="general calCell'; if ($Day->isSelected()) { echo ' calCellBusy'; } elseif ($Day->isEmpty()) { echo ' calCellEmpty'; } echo '">'; if($Day->isEmpty()) echo '<div class="dayNumber2">'.$Day->thisDay().'</div>'; else echo '<div class="dayNumber">'.$Day->thisDay().'</div>'; if ($Day->isEmpty()) { echo ' '; } else { echo '<div class="dayContents"><ul>'; while ($entry = $Day->getEntry()) { echo '<li>'; if(isset($entry['id'])) echo '<a href="?'.$id.'='.$entry['id'].'" class="event">'.$entry['desc'].'</a>'; else echo $entry['desc']; echo '</li>'; //you can print the time range as well } echo '</ul></div>'; } echo '</td>'; if ($Day->isLast()) { echo "</tr>\n"; } } echo '</table>'; $PMonth = $Month->prevMonth('object'); $prev = $_SERVER['PHP_SELF'].'?year='.$PMonth->thisYear().'&month='.$PMonth->thisMonth(); $NMonth = $Month->nextMonth('object'); $next = $_SERVER['PHP_SELF'].'?year='.$NMonth->thisYear().'&month='.$NMonth->thisMonth(); echo '<table class="calendar_option"><tr><td class="prev"><a href="'.$prev.'" class="option"><< '.$months[$PMonth->thisMonth()].' '.$PMonth->thisYear().'</a></td><td class="next"><a href="'.$next.'" class="option">'.$months[$NMonth->thisMonth()].' '.$NMonth->thisYear().' >></a></td></tr></table>'; echo '<form method="GET"><table><tr><td>'.smarty_function_html_select_date(array('prefix'=>'','start_year'=>'-5','end_year'=>'+5','display_days'=>false),$smarty).'</td><td></td>'.'<td><input type="submit" value="Mostrar"/></td></table></form>'; }