<?php 
$titles = __('error_titles', true);
$bodies = __('error_bodies', true);
?>
<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['AP10']; ?></h2>
			</div>
		</div><!-- /.row -->

		<p class="m-b-none"><i class="fa fa-info-circle"></i> <?php echo $bodies['AP10'];?></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">
			<?php if (pjAuth::factory('pjAdminPrices', 'pjActionIndex')->hasAccess()) { ?>
				<li role="presentation"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminPrices&amp;action=pjActionIndex"><?php __('tabRegular'); ?></a></li>
			<?php } ?>
			<li role="presentation" class="active"><a href="javascript:void(0);"><?php __('tabDiscounts'); ?></a></li>
		</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=pjActionDiscount" method="post" id="frmUpdateDiscount">
						<input type="hidden" name="discount_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 cpAddDiscount"><i class="fa fa-plus"></i> <?php __('btnAddDiscount'); ?></a>
						</div>
						<div class="table-responsive table-responsive-secondary">
							<table class="table table-striped table-hover" id="tblDiscounts">
								<thead>
									<tr>
										<th><?php __('lblSpace'); ?></th>
										<th><?php __('lblDateRange'); ?></th>
										<th><?php __('lblMinDays'); ?></th>
										<th><?php __('lblMaxDays'); ?></th>
										<th><?php __('lblPricePerDay'); ?></th>
										<th>&nbsp;</th>
									</tr>
								</thead>

								<tbody>
									<?php if(!empty($tpl['discount_arr'])) { ?>
										<?php foreach ($tpl['discount_arr'] as $discount) { 
											$index = $discount['id'];
											?>
											<tr data-id="<?php echo $index;?>">
												<td>
													<input type="hidden" name="id[<?php echo $index; ?>]" value="<?php echo $index; ?>" />
													<div class="form-group">
														<div>
															<select class="form-control required cpSpace" name="space_id[<?php echo $index;?>]" id="space_id_<?php echo $index;?>" data-index="<?php echo $index;?>" data-msg-required="<?php __('lblFieldRequired');?>">
																<option value="">-- <?php __('lblChoose'); ?>--</option>
																<?php
																foreach ($tpl['space_arr'] as $k => $v)
																{
																	?><option value="<?php echo $v['id']; ?>" <?php echo $discount['space_id'] == $v['id'] ? 'selected="selected"' : null;?>><?php echo pjSanitize::html($v['name']); ?></option><?php
																}
																?>
															</select>
														</div>
													</div>   
												</td>
											
												<td>
													<div class="form-group">
														<span id="cpPrice_<?php echo $index;?>" class="inline-block">
															<select class="form-control required" name="price_id[<?php echo $index;?>]" id="price_id_<?php echo $index;?>" data-msg-required="<?php __('lblFieldRequired');?>">
																<option value="">-- <?php __('lblChoose'); ?>--</option>
																<?php 
																foreach ($tpl['price_arr'] as $price)
																{
																	if ($price['space_id'] == $discount['space_id'])
																	{
																		?><option value="<?php echo $price['id']; ?>"<?php echo $discount['price_id'] == $price['id'] ? ' selected="selected"' : NULL; ?>><?php echo date($tpl['option_arr']['o_date_format'], strtotime($price['date_from'])); ?> - <?php echo date($tpl['option_arr']['o_date_format'], strtotime($price['date_to'])); ?></option><?php
																	}
																}
																?>
															</select>
														</span>
													</div>
												</td>
												
												<td>
													<div class="form-group">
														<div>
															<input class="required touchspin3" type="text" name="min_days[<?php echo $index;?>]" id="min_days_<?php echo $index;?>" value="<?php echo pjSanitize::html($discount['min_days']);?>" data-msg-required="<?php __('lblFieldRequired');?>">
														</div>
													</div>
												</td>
											
												<td>
													<div class="form-group">
														<div>
															<input class="required touchspin3" type="text" name="max_days[<?php echo $index;?>]" id="max_days_<?php echo $index;?>" value="<?php echo pjSanitize::html($discount['max_days']);?>" data-msg-required="<?php __('lblFieldRequired');?>">
														</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 class="form-control required number" name="price[<?php echo $index;?>]" id="price_<?php echo $index;?>" value="<?php echo pjSanitize::html($discount['price']);?>" data-msg-required="<?php __('lblFieldRequired');?>" data-msg-number="<?php __('prices_invalid_price', false, true);?>">
														</div>
													</div>
												</td>
											
												<td>
													<div class="form-group">
														<div class="text-right">
															<a href="javascript:void(0);" class="btn btn-danger btn-outline btn-sm cpRemoveDiscount"><i class="fa fa-trash"></i></a>
														</div>
													</div>
												</td>
											</tr>
										<?php } ?>
									<?php } else { ?>
										<tr>
											<td colspan="6" class="cpNoDiscounts"><?php __('lblNoDiscountsDefined');?></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/discount_clone.php';?>

<div class="modal fade" id="duplicateDiscountsModal" 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 __('lblDuplicatedDiscountTitle');?></h4>
		      </div>
		      <div class="modal-body"><?php __('lblDuplicatedDiscountDesc');?></div>
		      <div class="modal-footer">
		        	<button type="button" id="btnShowDuplicateDiscount" class="btn btn-primary"><?php __('btnOk');?></button>
		      </div>
	    </div><!-- /.modal-content -->
  	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
	var myLabel = myLabel || {};
	myLabel.no_discounts_defined = "<?php __('lblNoDiscountsDefined');?>";
</script>