<?php
  /**
   * Copyright 2011 Zazavi - http://www.zazavi.com
   * Zazavi is free software released under the terms of the GNU General Public License.
   * You should have received a copy of the license.  If not, see <http://www.gnu.org/licenses/>.
   */
  define("_VALID_PHP", true);
  
  require_once("../../init.php");

  require_once(ZAZAVILITE . "admin/modules/events/lang/" . $core->language . ".lang.php");
  require_once(ZAZAVILITE . "admin/modules/events/admin_class.php");
  
  $eventcal = new eventManager();
  $data = $eventcal->getCalendarData("short");
?>
<table class="calendar">
  <thead>    
    <tr>
      <td class="button"><a href="javascript:void(0);" id="item_<?php echo $data['previous_year'];?>" class="tooltip changedate" title="<?php echo $data['previous_year_text'];?>">&lsaquo;&lsaquo;</a></td>
      <td class="button"><a href="javascript:void(0);" id="item_<?php echo $data['previous_month'];?>" class="tooltip changedate" title="<?php echo $data['previous_month_text'];?>">&lsaquo;</a></td>
      <td colspan="3" class="button"><?php echo $data['current_month_text'];?></td>
      <td class="button"><a href="javascript:void(0);" id="item_<?php echo $data['next_month'];?>" class="tooltip changedate" title="<?php echo $data['next_month_text'];?>">&rsaquo;</a></td>
      <td class="button"><a href="javascript:void(0);" id="item_<?php echo $data['next_year'];?>" class="tooltip changedate" title="<?php echo $data['next_year_text'];?>">&rsaquo;&rsaquo;</a></td>
    </tr>
  <tr>
    <th width="14%"><?php echo _SUN;?></th>
    <th width="14%"><?php echo _MON;?></th>
    <th width="14%"><?php echo _TUE;?></th>
    <th width="14%"><?php echo _WED;?></th>
    <th width="14%"><?php echo _THU;?></th>
    <th width="14%"><?php echo _FRI;?></th>
    <th width="14%"><?php echo _SAT;?></th>
  </tr>
  </thead>
<?php
  for ($i = 0; $i < $data['total_rows']; $i++) {
      print "<tr>";
      for ($j = 0; $j < 7; $j++) {
          $data['day']++;
          
          if ($data['day'] > 0 && $data['day'] <= $data['total_days_of_current_month']) {
              $date_form = $data['current_year']. '/' . $data['current_month'] . '/' . $data['day'];
              
              print '<td';
              if ($date_form == $data['today'])
                  print ' class="today"';
              
              if (array_key_exists($data['day'], $data['events'])) {
                  print ' class="event button" onclick="$(\'#viewevent-' . $data['day'] . '\').dialog(\'open\'); return false"><div id="event-wrap">' . $data['day'];
                  print '<div id="viewevent-' . $data['day'] . '" style="display:none" class="viewevent" title="' . MOD_EM_EVENT_FOR . ' ' . $date_form . '">';
                  print '<ul id="event-list">';
                  $x = 0; $class1 = "event-even"; $class2 = "event-odd";
                  foreach ($data['events'] as $key => $event) {
					  
                      if ($key == $data['day']) {
                          foreach ($event as $k => $val) {
							  $x++;
                              print '<li class="'.(($x % 2 == 0) ? $class1 : $class2).'">';
                              print '<h3 class="event-title"><span>' . MOD_EM_TSE . ': ' . $val['stime'] . '/' . $val['etime'] . '</span>' . $val['title'.$core->dblang] . '</h3>';
							  if ($val['venue'.$core->dblang]) print '<h6 class="event-venue">' . $val['venue'.$core->dblang] . '</h6>';
							  print '<div class="event-desc">' . cleanOut($val['body'.$core->dblang]) . '</div>';
							  
							  print '<span class="contact-info-toggle" onclick="$(\'#eventid-' . $val['id'] . '\').toggle(\'normal\')" >' . MOD_EM_CONTACT . '</span>';
							  print '<div class="event-contact" id="eventid-' . $val['id'] . '">';
							  print '<ul>';
								if ($val['venue'.$core->dblang]) print '<li>' . $val['contact_person'] . '</li>';
								if ($val['venue'.$core->dblang]) print '<li>' . $val['contact_email'] . '</li>';
								if ($val['venue'.$core->dblang]) print '<li>' . $val['contact_phone'] . '</li>';
							  print '</ul>';
							  print '</div>';
                              print '</li>';
                          }
                      }
                  }
                  
                  print '</ul>';
                  print '</div>';
              } else
                  print '> ' . $data['day'];
              
              print "</td>";
          } else
              print '<td>&nbsp;</td>';
      }
      print "</tr>";
  }
?>
</table>
<script type="text/javascript">
$(document).ready(function () {
    $(".viewevent").dialog({
        bgiframe: true,
        autoOpen: false,
        width: 450,
        height: "auto",
        zindex: 9998,
        modal: false,
		resizable: false
    });
});
</script>