Exemple #1
0
<caption>
    <?php 
echo $MonthDecorator->thisMonth() . ' / ' . $MonthDecorator->thisYear();
?>
</caption>
<tr>
    <th>Monday</th>
    <th>Tuesday</th>
    <th>Wednesday</th>
    <th>Thursday</th>
    <th>Friday</th>
    <th>Saturday</th>
    <th>Sunday</th>
</tr>
<?php 
while ($Day = $MonthDecorator->fetch()) {
    if ($Day->isFirst()) {
        echo "<tr>\n";
    }
    echo '<td class="calCell';
    if ($Day->isSelected()) {
        echo ' calCellBusy';
    } elseif ($Day->isEmpty()) {
        echo ' calCellEmpty';
    }
    echo '">';
    echo '<div class="dayNumber">' . $Day->thisDay() . '</div>';
    if ($Day->isEmpty()) {
        echo '&#160;';
    } else {
        echo '<div class="dayContents"><ul>';
function smarty_function_calendar($params, &$smarty){

        require_once $smarty->_get_plugin_filepath('function','html_select_date');
  $days = array('Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 'Jueves', 'Viernes', 'S&aacute;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 '&nbsp;';
    } 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">&lt;&lt; '.$months[$PMonth->thisMonth()].' '.$PMonth->thisYear().'</a></td><td class="next"><a href="'.$next.'" class="option">'.$months[$NMonth->thisMonth()].' '.$NMonth->thisYear().' &gt;&gt;</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>';
}