<?php 
$titles = __('error_titles', true);
$bodies = __('error_bodies', true);
$months = __('months', true);
ksort($months);
$short_days = __('short_days', true);
$date_format = pjUtil::toBootstrapDate($tpl['option_arr']['o_date_format']);
?>
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-sm-12">
		<div class="row">
			<div class="col-sm-10">
				<h2><?php echo $titles['AP09']; ?></h2>
			</div>
		</div><!-- /.row -->

		<p class="m-b-none"><i class="fa fa-info-circle"></i> <?php echo $bodies['AP09'];?></p>
	</div><!-- /.col-md-12 -->
</div>

<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-lg-12">
			<?php
	    	$error_code = $controller->_get->toString('err');
	    	if (!empty($error_code))
	    	{
	    	    $titles = __('error_titles', true);
	    	    $bodies = __('error_bodies', true);
	    	    ?>
	    	    <div class="alert alert-success">
					<i class="fa fa-check m-r-xs"></i>
					<strong><?php echo @$titles[$error_code]; ?></strong>
					<?php echo @$bodies[$error_code]?>
				</div>
	    	    <?php 
	    	}
	    	?>
		</div>
	</div>
	<div class="tabs-container tabs-reservations m-b-lg">
		<ul class="nav nav-tabs" role="tablist">
			<li role="presentation" class="active"><a href="javascript:void(0);"><?php __('tabRegular'); ?></a></li>
			<?php if (pjAuth::factory('pjAdminPrices', 'pjActionDiscount')->hasAccess()) { ?>
				<li role="presentation"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminPrices&amp;action=pjActionDiscount"><?php __('tabDiscounts'); ?></a></li>
			<?php } ?>
		</ul>

		<div class="tab-content">
			<div role="tabpanel" class="tab-pane active" id="regular">
				<div class="panel-body">
					<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminPrices&amp;action=pjActionIndex" method="post" id="frmUpdatePrice">
						<input type="hidden" name="price_update" value="1" />
						<input type="hidden" name="csrf_token" value="<?php echo pjAppController::getCsrfToken(); ?>" />
						<div class="m-b-md">
							<a href="javascript:void(0);" class="btn btn-primary cpAddPrice"><i class="fa fa-plus"></i> <?php __('btnAddPrice'); ?></a>
						</div>
						<div id="datePickerOptions" style="display:none;" data-wstart="<?php echo (int) $tpl['option_arr']['o_week_start']; ?>" data-format="<?php echo $date_format; ?>" data-months="<?php echo implode("_", $months);?>" data-days="<?php echo implode("_", $short_days);?>"></div>
						<div class="table-responsive table-responsive-secondary">
							<table class="table table-striped table-hover" id="tblPrices">
								<thead>
									<tr>
										<th><?php __('lblSpace'); ?></th>
										<th><?php __('lblFromDate'); ?></th>
										<th><?php __('lblToDate'); ?></th>
										<th><?php __('lblPrice'); ?></th>
										<th>&nbsp;</th>
									</tr>
								</thead>

								<tbody>
									<?php if(!empty($tpl['price_arr'])) { ?>
										<?php foreach ($tpl['price_arr'] as $price) { ?>
											<tr data-id="<?php echo $price['id']; ?>">
												<td>
													<input type="hidden" name="id[<?php echo $price['id']; ?>]" value="<?php echo $price['id']; ?>" />
													<div class="form-group">
														<div>
															<select class="form-control required" name="space_id[<?php echo $price['id'];?>]" data-msg-required="<?php __('lblFieldRequired');?>">
																<option value="">-- <?php __('lblChoose'); ?>--</option>
																<?php
																foreach ($tpl['space_arr'] as $space)
																{
																	?><option value="<?php echo $space['id']; ?>"<?php echo $space['id'] == $price['space_id'] ? ' selected="selected"' : null;?>><?php echo pjSanitize::html($space['name']); ?></option><?php
																}
																?>
															</select>
														</div>   
													</div>
												</td>
		
												<td>
													<div class="form-group">
														<div class="input-group"> 
															<input type="text" name="date_from[<?php echo $price['id'];?>]" id="date_from_<?php echo $price['id'];?>" value="<?php echo pjDateTime::formatDate($price['date_from'], 'Y-m-d', $tpl['option_arr']['o_date_format']);?>" class="form-control datepick required" readonly="readonly" data-msg-required="<?php __('lblFieldRequired');?>" /> 
															<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
														</div>
													</div>
												</td>
												
												<td>
													<div class="form-group">
														<div class="input-group"> 
															<input type="text" name="date_to[<?php echo $price['id'];?>]" id="date_to_<?php echo $price['id'];?>" value="<?php echo pjDateTime::formatDate($price['date_to'], 'Y-m-d', $tpl['option_arr']['o_date_format']);?>" class="form-control datepick required" readonly="readonly" data-msg-required="<?php __('lblFieldRequired');?>" /> 
															<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
														</div>
													</div>
												</td>
		
												<td>
													<div class="form-group">
														<div class="input-group">
															<span class="input-group-addon"><?php echo pjCurrency::getCurrencySign($tpl['option_arr']['o_currency'], false);?></span> 
			
															<input type="text" name="price[<?php echo $price['id'];?>]" id="price_<?php echo $price['id'];?>" value="<?php echo $price['price'];?>" class="form-control required number" data-msg-required="<?php __('lblFieldRequired');?>" data-msg-number="<?php __('prices_invalid_price', false, true);?>"> 
														</div>
													</div>
												</td>
		
												<td>
													<div class="text-right form-group">
														<a href="javascript:void(0);" class="btn btn-danger btn-outline btn-sm cpRemovePrice"><i class="fa fa-trash"></i></a>
													</div>
												</td>
											</tr>
										<?php } ?>
									<?php } else { ?>
										<tr>
											<td colspan="5" class="cpNoPrices"><?php __('lblNoPricesDefined');?></td>
										</tr>
									<?php } ?>									
								</tbody>
							</table>
						</div>

						<div class="hr-line-dashed"></div>

						<button type="submit" class="ladda-button btn btn-primary btn-lg btn-phpjabbers-loader" data-style="zoom-in">
							<span class="ladda-label"><?php __('btnSave', false, true); ?></span>
							<?php include $controller->getConstant('pjBase', 'PLUGIN_VIEWS_PATH') . 'pjLayouts/elements/button-animation.php'; ?>
						</button>
					</form>
				</div>
			</div>			
		</div>
	</div>
</div>
<?php include_once PJ_VIEWS_PATH . 'pjAdminPrices/elements/price_clone.php';?>

<div class="modal fade" id="duplicatePricesModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  	<div class="modal-dialog modal-md" role="document">
	    <div class="modal-content">
		      <div class="modal-header">
		        	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        	<h4 class="modal-title"><?php __('lblDuplicatedPeriodTitle');?></h4>
		      </div>
		      <div class="modal-body"><?php __('lblDuplicatedPeriodDesc');?></div>
		      <div class="modal-footer">
		        	<button type="button" id="btnShowDuplicatePrice" class="btn btn-primary"><?php __('btnOk');?></button>
		      </div>
	    </div><!-- /.modal-content -->
  	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<div class="modal fade" id="emptyPriceModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  	<div class="modal-dialog modal-md" role="document">
	    <div class="modal-content">
		      <div class="modal-header">
		        	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        	<h4 class="modal-title"><?php __('lblPricesSavedTitle');?></h4>
		      </div>
		      <div class="modal-body"><?php __('lblPricesSavedDesc');?></div>
		      <div class="modal-footer">
		        	<button type="button" class="btn btn-primary" data-dismiss="modal"><?php __('btnOk');?></button>
		      </div>
	    </div><!-- /.modal-content -->
  	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script type="text/javascript">
	var myLabel = myLabel || {};
	myLabel.no_prices_defined = "<?php __('lblNoPricesDefined');?>";
</script>