<?php 
$titles = __('error_titles', true);
$bodies = __('error_bodies', true);
$months = __('months', true);
ksort($months);
$short_days = __('short_days', true);
?>	
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-sm-12">
		<div class="row">
			<div class="col-lg-9 col-md-8 col-sm-6">
				<h2><?php echo $titles['AS11']; ?></h2>
			</div>
			<div class="col-lg-3 col-md-4 col-sm-6 btn-group-languages">
				<?php if ($tpl['is_flag_ready']) : ?>
				<div class="multilang"></div>
				<?php endif; ?>    
			</div>
		</div>
		<p class="m-b-none"><i class="fa fa-info-circle"></i><?php echo $bodies['AS11']; ?></p>
	</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminSpaces&amp;action=pjActionUpdate" method="post" id="frmUpdate">
						<input type="hidden" name="action_update" value="1" />
						<input type="hidden" name="csrf_token" value="<?php echo pjAppController::getCsrfToken(); ?>" />
						<input type="hidden" name="id" value="<?php echo $tpl['arr']['id'];?>" />
						<div class="row">
							<div class="col-md-7">
								<div class="row">
									<div class="col-md-6">
										<div class="form-group">
											<label class="control-label"><?php __('lblName'); ?></label>
																	
											<?php
											foreach ($tpl['lp_arr'] as $v)
											{
												?>
												<div class="<?php echo $tpl['is_flag_ready'] ? 'input-group' : '';?> pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 1 ? NULL : 'none'; ?>">
													<input type="text" class="form-control field-name <?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>" name="i18n[<?php echo $v['id']; ?>][name]" value="<?php echo htmlspecialchars(stripslashes(@$tpl['arr']['i18n'][$v['id']]['name'])); ?>" data-msg-required="<?php __('lblFieldRequired');?>" />	
													<?php if ($tpl['is_flag_ready']) : ?>
													<span class="input-group-addon pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="<?php echo pjSanitize::html($v['name']); ?>"></span>
													<?php endif; ?>
												</div>
												<?php 
											}
											?>
										</div><!-- /.col-sm-6 -->
									</div><!-- /.col-md-6 -->

									<div class="col-md-4">
										<div class="form-group">
											<label class="control-label"><?php __('lblStatus'); ?></label>
											
											<select class="form-control required" name="status" id="status" data-msg-required="<?php __('lblFieldRequired');?>">
												<option value="">-- <?php __('lblChoose'); ?>--</option>
												<?php
												foreach (__('u_statarr', true) as $k => $v)
												{
													?><option value="<?php echo $k; ?>"<?php echo $k == $tpl['arr']['status'] ? ' selected="selected"' : null;?>><?php echo $v; ?></option><?php
												}
												?>
											</select>                  
										</div>
									</div><!-- /.col-md-6 -->
								</div><!-- /.row -->

								<div class="hr-line-dashed"></div>
									
								<div class="m-b-md">
									<label class="control-label"><?php __('lblSpacesAvailable'); ?></label>
								</div>
								<?php
								$index = 'cp_' . rand(1, 999999);
								$date_format = pjUtil::toBootstrapDate($tpl['option_arr']['o_date_format']);
								$today = date($tpl['option_arr']['o_date_format'], time());
								$next_year = date($tpl['option_arr']['o_date_format'], strtotime('+1 years'));
								?>
								<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 hideEm" id="tblSpaces">
										<thead>
											<tr>
												<th><?php __('lblFrom'); ?></th>
												<th><?php __('lblTo'); ?></th>
												<th><?php __('lblSpaces'); ?></th>
												<th>&nbsp;</th>
											</tr>
										</thead>

										<tbody>
											<?php foreach($tpl['sd_arr'] as $k => $v) { 
												$index = $v['id'];
												?>
												<tr data-idx="<?php echo $index;?>">
													<td>
														<div class="form-group">
															<div class="input-group"> 
																<input type="text" name="date_from[<?php echo $index;?>]" id="date_from_<?php echo $index;?>" value="<?php echo pjDateTime::formatDate($v['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 $index;?>]" id="date_to_<?php echo $index;?>" value="<?php echo pjDateTime::formatDate($v['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">
															<input class="touchspin3 required" type="text" name="spaces[<?php echo $index;?>]" id="spaces_<?php echo $index;?>" value="<?php echo $v['spaces'];?>" data-msg-required="<?php __('lblFieldRequired');?>" />
														</div>
													</td>
	
													<td>
														<div class="m-t-xs text-right">
															<div class="form-group">
																<a href="javascript:void(0);" class="btn btn-danger btn-outline btn-sm cpRemoveDate"><i class="fa fa-trash"></i></a>
															</div>
														</div>
													</td>
												</tr>
											<?php } ?>
										</tbody>
									</table>
								</div>

								<a href="javascript:void(0);" class="btn btn-primary btn-outline cpAddDate"><i class="fa fa-plus"></i> <?php __('btnAddPeriod'); ?></a>
							</div><!-- /.col-md-8 -->
							
							<div class="col-md-5">
								<div class="form-group job-desc-mce">
									<label class="control-label"><?php __('lblDescription'); ?></label>
															
									<?php
									foreach ($tpl['lp_arr'] as $v)
									{
										?>
										<div class="<?php echo $tpl['is_flag_ready'] ? 'input-group' : '';?> pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 1 ? NULL : 'none'; ?>">
											<textarea name="i18n[<?php echo $v['id']; ?>][description]" class="form-control mceEditor" cols="30" rows="10"><?php echo htmlspecialchars(stripslashes(@$tpl['arr']['i18n'][$v['id']]['description'])); ?></textarea>	
											<?php if ($tpl['is_flag_ready']) : ?>
											<span class="input-group-addon pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="<?php echo pjSanitize::html($v['name']); ?>"></span>
											<?php endif; ?>
										</div>
										<?php 
									}
									?>
								</div>
							</div><!-- /.col-md-4 -->
						</div><!-- /.row -->

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

						<div class="clearfix">
							<button type="submit" class="ladda-button btn btn-primary btn-lg btn-phpjabbers-loader pull-left" 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>
							<button type="button" class="btn btn-white btn-lg pull-right" onclick="window.location.href='<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjAdminSpaces&action=pjActionIndex';"><?php __('btnCancel'); ?></button>
						</div><!-- /.clearfix -->
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<?php include_once PJ_VIEWS_PATH . 'pjAdminSpaces/elements/clone.php';?>
<script type="text/javascript">
var myLabel = myLabel || {};
myLabel.isFlagReady = "<?php echo $tpl['is_flag_ready'] ? 1 : 0;?>";
<?php if ($tpl['is_flag_ready']) : ?>
	var pjLocale = pjLocale || {};
	pjLocale.langs = <?php echo $tpl['locale_str']; ?>;
	pjLocale.flagPath = "<?php echo PJ_FRAMEWORK_LIBS_PATH; ?>pj/img/flags/";
<?php endif; ?>
</script>