<?
	$this->title = 'Drivers';
	$this->titleicon = 'road';
	$this->titleLink = '/drivers';
	$this->title2 = 'Shift';
	$this->title2icon = 'time';

	$id_community = $this->id_community;
	$year = $this->year;
	$week = $this->week;
	$segments = $this->segments;

	$ajax = ( $this->ajax ) ? true : false;

?>

<?php if( !$ajax ) { ?>
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="box">
			<div class="box-header"><span class="title">Select a Community</span></div>
			<div class="box-content padded">
				<select id="community-id" class="chosen-select" style="width:480px;">
					<option value="" selected></option>
					<?php
					$communities = Crunchbutton_Community_Shift::communitiesWithDeliveryService();
					foreach ( $communities as $community ) {
						$selected = ( $id_community == $community->id_community ) ? 'selected="selected"' : '';
						?><option <?php echo $selected; ?> value="<?php echo $community->id_community; ?>"><?php echo $community->name; ?></option><?php
					}
					?>
				</select>
				<div class="divider"></div>
			</div>
		</div>
	</div>
	<?php } ?>

	<?php if( $id_community ) { ?>
		<div class="row-fluid">
			<?php if( !$ajax ) { ?>
			<div class="box">
				<div class="box-header">
						<div class="row-fluid">
								<div class="span2 padded">
									<br/>
									<a class="shift-previous" href="/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->link_prev; ?>"><strong><i class="icon icon-angle-left"></i> previous</strong></a>
								</div>
									<div class="span8 padded" style="text-align:center;">
										<h5>
											From <?php echo $this->from->format('M jS Y') ?> to <?php echo $this->to->format('M jS Y'); ?>
										</h5>
									</div>
								<div class="span2 padded" style="text-align:right;">
									<br/>
									<a class="shift-next" href="/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->link_next; ?>"><strong>next <i class="icon icon-angle-right"></i></strong></a>
								</div>
						</div>
			</div>
			<?php } ?>
				<div class="box-content">
						<div>

			<?php if( $ajax ) { ?>
			<div class="box">
				<div class="box-header">
						<div class="row-fluid">
							<div style="text-align:center;">
								<h5>
									From <?php echo $this->from->format('M jS Y') ?> to <?php echo $this->to->format('M jS Y'); ?>
								</h5>
							</div>
						</div>
				</div>
			<?php } ?>

						<table width="100%">
						<tr>
							<?php foreach( $this->days as $day ) {
								$dark = ( $dark == '#F5F5F5' ) ? '' : '#F5F5F5';
							?>
								<th width="14%" style="background:<?php echo $dark; ?>">
									<div class="row-fluid padded">
										<div class="span12">
											<strong style="font-size:16px;color:#666;">
												<?php echo $day->format( 'l' ); ?>
												<div style="font-size:10px;font-weight:normal;color:#CCC;"><?php echo $day->format( 'M' ); ?> <?php echo $day->format( 'd' ); ?></div>
											</strong>
										</div>
									</div>
								</th>
							<?php } ?>
						</tr>
						<?php $dark = ''; ?>
						<tr>
							<?php foreach( $this->days as $day ) {
								$dark = ( $dark == '#F5F5F5' ) ? '' : '#F5F5F5';
								$segments = Crunchbutton_Community_Shift::shiftByCommunityDay( $id_community, $day->format( 'Y-m-d' ) );
							?>
								<td width="14%" style="background:<?php echo $dark; ?>" valign="top">
									<div class="row-fluid padded">
										<?php
										foreach( $segments as $segment ) {
											?><div class="row-fluid">
											<a class="modal-hours-edit" href="/drivers/shift/community/edit/<?php echo $segment->id_community_shift; ?>" title="Edit hours">
												<?php if( $segment->id_community_shift_father || $segment->recurring > 0 ){ ?>
													<i class="icon-retweet" title="It is a recurring event"></i>&nbsp;
												<?php } ?>
												<span class="community-timezone" title="<?php echo $segment->fullDate(); ?>">
													<strong><?php echo $segment->startEndToString(); ?></strong> (<?php echo $segment->timezoneAbbr(); ?>)
												</span>
												<span class="pst-timezone" title="<?php echo $segment->fullDate( c::config()->timezone ); ?>">
													<strong><?php echo $segment->startEndToString( c::config()->timezone ); ?></strong> (PST)
												</span>
											</a>
											<br/><br/>
											</div><?php
										} ?>
										<button class="btn btn-default modal-hours-open" href="/drivers/shift/community/add/<?php echo $id_community ?>/<?php echo $day->format( 'Y/m/d' ); ?>/<?php echo $this->week; ?>" style="width:80%;" title="Add hours to <?php echo $day->format( 'M' ); ?> <?php echo $day->format( 'd' ); ?> (<?php echo $day->format( 'D' ); ?>)">
											<i class="icon-plus icon-2x"></i>
										</button>
									</div>
								</td>
						<?php } ?>
						</tr>
					</table>
					<div class="divider"></div>
				</div>
			<?php if( !$ajax ) { ?>
			</div>
			<?php } ?>

			<div class="padded">

			<!-- <button class="btn btn-blue" onclick="shift.community.copyAll( '<?php echo $id_community; ?>', '<?php echo $this->week; ?>', '<?php echo $this->year; ?>' );"><i class="icon-copy"></i> Copy the hours from the previous week</button> -->

			<button style="margin-left:20px;" class="btn btn-default" onclick="shift.community.toggleTimezone();"><i class="icon-time"></i> Show hours in&nbsp;
			<span class="pst-timezone">community timezone</span>
			<span class="community-timezone">PST timezone</span>
			</button>

		</div>
	<?php } ?>
</div>

</div>

<div class="modal hide fade" id="modal-hours" style="display: none;">
	<div class="modal-header">
		<button class="close" data-dismiss="modal" type="button">×</button>
		<h6 id="modal-hours-title"></h6>
	</div>
	<div class="modal-body" id="modal-hours-body"></div>
	<div class="modal-footer">
		<button class="btn btn-default" data-dismiss="modal">Close</button>
	</div>
</div>

<style type="text/css">
	label{
		text-align: right;
	}
</style>
<script type="text/javascript" src="/assets/js/admin.shift.js"></script>
<script type="text/javascript">
$( document ).ready( function(){
	shift.community.start_date = '<?php echo $this->start_date; ?>';
	<?php if( $ajax ) { ?>
		shift.community.ajax = true;
		shift.community.url = '/drivers/shift/community/<?php echo $id_community ?>/<?php echo $this->year; ?>/<?php echo $this->week; ?>?ajax=1';
	<?php } ?>
	shift.community.init();

} );
</script>