<?php
	function getCopy($key)
	{
		switch ($key) {
			case 'Tuesday':
				return '<img alt="copy" src="/admin/img/edit-paste-6.png">&nbsp;<a class="copy" id="copyTuesday" href="Monday">copy monday</a><br><br>';
				break;
			case 'Wednesday':
				return '<img alt="copy" src="/admin/img/edit-paste-6.png">&nbsp;<a class="copy" id="copyWednesday" href="Tuesday">copy tuesday</a><br><br>';
				break;
			case 'Thursday':
				return '<img alt="copy" src="/admin/img/edit-paste-6.png">&nbsp;<a class="copy" id="copyThursday" href="Wednesday">copy wednesday</a><br><br>';
				break;
			case 'Friday':
				return '<img alt="copy" src="/admin/img/edit-paste-6.png">&nbsp;<a class="copy" id="copyFriday" href="Thursday">copy thursday</a><br><br>';
				break;
			case 'Saturday':
				return '<img alt="copy" src="/admin/img/edit-paste-6.png">&nbsp;<a class="copy" id="copySaturday" href="Friday">copy friday</a><br><br>';
				break;
			case 'Sunday':
				return '<img alt="copy" src="/admin/img/edit-paste-6.png">&nbsp;<a class="copy" id="copySunday" href="Friday">copy saturday</a><br><br>';
				break;
		}
	}
?>

<h1>Opening Times</h1>

<p>Setup opening times for your restaurant. Click on 'Add new service time' to add multiple service times for a particular day. To remove a service time, leave the opening, closing or name fields blank (all fields are required for a time to get saved).</p>
<br>
<?php if (isset ($_POST['submit'])): ?>
	<?php if (isset ($this->view->error)): ?>

		<div class="error_message">Error: <?php echo $this->view->error; ?></div>

	<?php else: ?>
		<div class="success_message">Your times were saved successfully.</div>
	<?php endif; ?>
<?php endif; ?>

<form action="" method="post">
<div id="times-div">
<?php foreach ($this->view->bookings as $key => $val): ?>

	<?php if (empty ($val)): ?>
		<div class="box">
		<div class="box-header"><?php echo $key; ?></div>
		<div class="padd" style="min-height: 70px;">
		<?php echo getCopy($key) ?>

			<!-- serviceMonday -->
			<div id="service<?php echo $key ?>">

				<!-- timesMonday0 -->
				<div class="times" id="times<?php echo $key ?>0">

					<div>

						<label class="inline">Name</label>
						<div class="input" style="margin-right: 30px;">
						<?php echo $this->input('name' . $key . '0', array('class' => 'name', 'style' => 'float: left; height: 20px; padding: 3px', 'placeholder' => 'eg Lunch')); ?>
						&nbsp;
						<?php // echo $this->input('name' . $key . '0', array('class' => 'name', 'style' => 'height: 20px; padding: 3px;')); ?>
						</div>
					</div>

					<div class="times-left">

						<label class="inline">Open</label>
						<div class="input">

							<?php echo $this->input('open' . $key . '0', array('class' => 'inputtime', 'style' => 'height: 20px; padding: 3px;')); ?>

						</div>
						<div style="clear: both;"></div>
					</div>



					<div class="times-right">
						<label class="inline">Close</label>
						<div class="input">

							<?php echo $this->input('close' . $key . '0', array('class' => 'inputtime', 'style' => 'height: 20px; padding: 3px;')); ?>

						</div>
						<div style="clear: both;"></div>

					</div>
				<div style="clear: both;"></div>
			</div><!--  end times div -->


			<div style="clear: both;"></div>


		</div><!-- end service div -->
		<div style="clear: both;"></div>
		<br>
		<a class="new-service" href="<?php echo $key ?>">+Add new service time</a>


		</div>

	</div>




	<?php else: ?>

		<div class="box">
		<div class="box-header"><?php echo $key; ?></div>
		<div class="padd" style="min-height: 70px;">
		<?php echo getCopy($key) ?>

			<!-- serviceMonday -->
			<div id="service<?php echo $key ?>">

				<?php foreach ($val as $b => $booking): ?>


				<!-- timesMonday0 -->
				<div class="times" id="times<?php echo $key . $b ?>">

					<div>

						<label class="inline">Name</label>
						<div class="input" style="margin-right: 30px;">

							<?php echo $this->input('name' . $key . $b, array('class' => 'name', 'value' => $booking['name'], 'style' => 'float: left; height: 20px; padding: 3px;', 'placeholder' => 'eg Lunch')); ?>

						&nbsp;
						</div>
					</div>

					<div class="times-left">

						<label class="inline">Open</label>
						<div class="input">
							<?php echo $this->input('open' . $key . $b, array('value' => date('h:i A', strtotime($booking['open'])), 'class' => 'inputtime', 'style' => 'height: 20px; padding: 3px;')); ?>
						</div>
						<div style="clear: both;"></div>
					</div>

					<div class="times-right">
						<label class="inline">Close</label>
						<div class="input">
							<?php echo $this->input('close' . $key . $b, array('value' => date('h:i A', strtotime($booking['close'])), 'class' => 'inputtime', 'style' => 'height: 20px; padding: 3px;')); ?>
						</div>
						<div style="clear: both;"></div>
					</div>
				<div style="clear: both;"></div>
			</div><!--  end times div -->
				<?php endforeach; ?>



			<div style="clear: both;"></div>


		</div><!-- end service div -->
		<div style="clear: both;"></div>
		<br>
		<a class="new-service" href="<?php echo $key ?>">+Add new service time</a>


		</div>

	</div>



	<?php endif; ?>

<?php endforeach; ?>

</div>

<br><br>
<div class="box" id="exceptions-div">
	<div class="box-header">
		Exceptions<br>
		<p style="font-weight: normal">Exceptions cover closing on days such as public holidays where your restaurant would otherwise be open, or times you are open that you would ordinarily be closed. Note that closing times take precedence over opening times ie if you have two exceptions for a single day, one opening and one closing the restaurant, the restaurant will be closed and you won't be able to take bookings in that period. To open or close for en entire day, set 'from' time to 12:00 AM and 'to' time to 11:59 PM.</p>
	</div>


		<div class="padd" id="exceptions" style="min-height: 20px;">

			<?php $current = 0; ?>

			<?php if (! empty ($this->exceptions)): ?>

				<?php foreach ($this->exceptions as $key => $val): ?>

				<script>
					exception = <?php echo $key ?>;
				</script>
				<?php $current = $key; ?>

				<?php if ($key > 0): ?>
					<div style="clear: both;">&nbsp;</div>
				<?php endif; ?>



				<div id="exception<?php echo $key ?>">

					<?php
						list($date, $start) = explode(' ', $val['from_date']);
						list($date, $end) = explode(' ', $val['to_date']);
						$datephp = date($this->dateformatphp, strtotime($date));
						$start = date('h:i A', strtotime($start));
						$end = date('h:i A', strtotime($end));
					?>


					<label class="inline">Name</label>
					<div class="input">
						<?php echo $this->input('exception[name][' . $key . ']', array('class' => 'exception', 'value' => $val['name'], 'style' => 'float: left; height: 20px; width: 130px; padding: 0px;', 'placeholder' => 'eg Christmas day')) ?>
					</div>
					<div style="width: 50px; float: left;">&nbsp;</div>
					<label class="inline">Date</label>
					<div class="input">
						<?php echo $this->input('exception[date][' . $key . ']', array('value' => $datephp, 'style' => 'float: left; height: 20px; width: 100px;', 'class' => 'datepicker', 'id' => 'date' . $key)); ?>
						<?php echo $this->hidden('exception[alt][' . $key . ']', array('value' => $date, 'id' => 'alt' . $key)); ?>
					</div>
					<div style="width: 50px; float: left;">&nbsp;</div>

					<label class="inline">Type</label>
					<div class="input">
						<?php echo $this->select('exception[type][' . $key . ']', array('style' => 'height: 20px; padding: 0px;'), array('close' => 'close', 'open' => 'open'), $val['type']); ?>
					</div>
					<div style="width: 50px; float: left;">&nbsp;</div>


					<label class="inline">From</label>
					<div class="input">
							<?php echo $this->input('exception[from][' . $key . ']', array('value' => $start, 'style' => 'float: left; height: 20px;', 'class' => 'inputtime')) ?>
					</div>
					<div style="width: 50px; float: left;">&nbsp;</div>

					<label class="inline">To</label>
					<div class="input">
						<?php echo $this->input('exception[to][' . $key . ']', array('value' => $end, 'style' => 'float: left; height: 20px;', 'class' => 'inputtime')) ?>
					</div>


			</div>



				<?php endforeach; ?>

			<?php else: ?>

				<div id="exception0">


				<label class="inline">Name</label>
				<div class="input">
					<?php echo $this->input('exception[name][0]', array('class' => 'exception', 'style' => 'float: left; height: 20px; width: 130px; padding: 3px;', 'placeholder' => 'eg Christmas day')) ?>
				</div>
				<div style="width: 50px; float: left;">&nbsp;</div>
				<label class="inline">Date</label>
				<div class="input">
					<?php echo $this->input('exception[date][0]', array('style' => 'float: left; height: 20px; width: 100px;', 'class' => 'datepicker', 'id' => 'date0')) ?>
					<?php echo $this->hidden('exception[alt][0]', array('id' => 'alt0')); ?>
				</div>
				<div style="width: 50px; float: left;">&nbsp;</div>

				<label class="inline">Type</label>
				<div class="input">
					<?php echo $this->select('exception[type][0]', array('style' => 'height: 20px; padding: 0px;'), array('close' => 'close', 'open' => 'open')); ?>
				</div>
				<div style="width: 50px; float: left;">&nbsp;</div>


				<label class="inline">From</label>
				<div class="input">
						<?php echo $this->input('exception[from][0]', array('value' => '12:00 AM', 'style' => 'float: left; height: 20px;', 'class' => 'inputtime')) ?>
				</div>
				<div style="width: 50px; float: left;">&nbsp;</div>

				<label class="inline">To</label>
				<div class="input">
					<?php echo $this->input('exception[to][0]', array('value' => '11:59 PM', 'style' => 'float: left; height: 20px;', 'class' => 'inputtime')) ?>
				</div>



			</div>

			<?php endif; ?>



		</div>


	<div class="clear: both;">&nbsp;</div><br>
	<a class="new-exception" href="">+ Add new exception</a><br><br>

</div>


<div>
	<br>
	<input type="submit" name="submit" value="Save Opening times" style="width: 150px;">

</div>
</form>

<br>
