<?php 
/*
 * http://wordpress.org/extend/plugins/events-manager/
 *
 * Modified 30/03/13 by David Churchill
 * This changes the Full Calendar into a Monthly List of Events, with Next/Previous Month Links. Also excludes days with no events.
 * Replaced Tables with div/class and removed code the show empty dates
 * 
 * Copy to YOURTHEMEFOLDER > plugins > events-manager > calendar-full.php
 * 
 * Live example: http://corfe-castle.co.uk/events
 *
 *
 * 
 * There are two variables made available to you: 
 * 
 *  $calendar - contains an array of information regarding the calendar and is used to generate the content
 *  $args - the arguments passed to EM_Calendar::output()
 * 
 * Note that leaving the class names for the previous/next links will keep the AJAX navigation working.
 */

$cal_count = count($calendar['cells']); //to prevent an extra tr
$col_count = $tot_count = 1; //this counts collumns in the $calendar_array['cells'] array
$col_max = count($calendar['row_headers']); //each time this collumn number is reached, we create a new collumn, the number of cells should divide evenly by the number of row_headers
?>
<div class="css-events-list"><a class="em-calnav full-link em-calnav-prev" href="<?php echo $calendar['links']['previous_url']; ?>">&lt;&lt;</a> | <h2><?php echo ucfirst(date_i18n('F Y', $calendar['month_start'])); ?></h2> | <a class="em-calnav full-link em-calnav-next" href="<?php echo $calendar['links']['next_url']; ?>">&gt;&gt;</a></div>

			<?php
			foreach($calendar['cells'] as $date => $cell_data ){
				$class = ( !empty($cell_data['events']) && count($cell_data['events']) > 0 ) ? 'eventful':'eventless';
				if(!empty($cell_data['type'])){
					$class .= "-".$cell_data['type']; 
				}
				?>

					<?php if ( $class != 'eventful-post' ){ ?>
					<?php if ( $class != 'eventful-pre' ){ ?>
					
					<?php if( !empty($cell_data['events']) && count($cell_data['events']) > 0 ): ?>
					<div class="cal-list-day">
					<h2 class="cal-list-date"><?php echo date('jS',$cell_data['date']); ?></h2>
						<?php 
						$cell_events = array();
						if( get_option('dbem_display_calendar_events_limit') ){
							$count = 0;
							foreach($cell_data['events'] as $cell_event){
								$cell_events[] = $cell_event;
								$count++;
								if($count > get_option('dbem_display_calendar_events_limit')) break;
							}
						}else{
							$cell_events = $cell_data['events'];
						}
						?>
						<?php echo EM_Events::output($cell_events,array('format'=>get_option('dbem_full_calendar_event_format'))); ?>
						<?php if( count($cell_events) > get_option('dbem_display_calendar_events_limit',3) && get_option('dbem_display_calendar_events_limit_msg') != '' ): ?>
						<a href="<?php echo esc_url($cell_data['link']); ?>"><?php echo get_option('dbem_display_calendar_events_limit_msg'); ?></a>
						<?php endif; ?>
						</div>
					<?php else:?>
					<?php endif; ?>

					<?php } ?>
					<?php } ?>

				<?php
				//create a new row once we reach the end of a table collumn
				$col_count= ($col_count == $col_max ) ? 1 : $col_count+1;
				echo ($col_count == 1 && $tot_count < $cal_count) ? '':'';
				$tot_count ++; 
			}
			?>
			
<div class="cal-list-month"><a class="em-calnav full-link em-calnav-prev" href="<?php echo $calendar['links']['previous_url']; ?>">&lt;&lt;</a> | <?php echo ucfirst(date_i18n('F Y', $calendar['month_start'])); ?> | <a class="em-calnav full-link em-calnav-next" href="<?php echo $calendar['links']['next_url']; ?>">&gt;&gt;</a></div>