<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	
	pjUtil::printNotice(__('infoUpdateExtraTitle', true, false), __('infoUpdateExtraDesc', true, false)); 
	
	?>
	
	<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) :?>
	<div class="multilang"></div>
	<?php endif; ?>
	
	<div class="clear_both">
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminExtras&amp;action=pjActionUpdate" method="post" id="frmUpdateExtra" class="form pj-form" enctype="multipart/form-data">
			<input type="hidden" name="extra_update" value="1" />
			<input type="hidden" name="id" value="<?php echo $tpl['arr']['id']; ?>" />
			<input type="hidden" id="apply_max_count" name="apply_max_count" value="" />
			
			<p>
				<label class="title"><?php __('lblAvailableFor'); ?></label>
				<span class="inline_block">
					<?php
					if(!empty($tpl['calendar_arr']))
					{ 
						?>
						<select name="calendar_id[]" id="calendar_id" multiple="multiple" size="5" class="pj-form-field required w300">
							<?php
							foreach ($tpl['calendar_arr'] as $v)
							{
								?><option value="<?php echo $v['id']; ?>"<?php echo in_array($v['id'], $tpl['calendar_id_arr']) ? ' selected="selected"' : NULL;?>><?php echo stripslashes($v['name']); ?></option><?php
							}
							?>
						</select>
						<?php
					} 
					?>
				</span>
			</p>
			<?php
			foreach ($tpl['lp_arr'] as $v)
			{
				?>
				<p class="pj-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : NULL; ?>">
					<label class="title"><?php __('lblExtraName'); ?></label>
					<span class="inline_block">
						<input type="text" id="i18n_name_<?php echo $v['id'];?>" name="i18n[<?php echo $v['id']; ?>][name]" class="pj-form-field w300<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>" value="<?php echo htmlspecialchars(stripslashes(@$tpl['arr']['i18n'][$v['id']]['name'])); ?>" lang="<?php echo $v['id']; ?>"/>
						<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
						<span class="pj-multilang-input"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
						<?php endif; ?>
					</span>
				</p>
				<?php
			}
			?>
			<p>
				<label class="title"><?php __('lblPrice'); ?></label>
				<span class="inline_block">
					<span class="block float_left r10">
						<span class="pj-form-field-custom pj-form-field-custom-before">
							<span class="pj-form-field-before"><abbr class="pj-form-field-icon-text"><?php echo pjUtil::formatCurrencySign(NULL, $tpl['option_arr']['o_currency'], ""); ?></abbr></span>
							<input type="text" id="price" name="price" class="pj-form-field w80 required<?php echo isset($tpl['option_arr']['o_currency_format']) ? ' pjNumber' : ' number';?>" value="<?php echo pjUtil::converToCurrencyFormat($tpl['arr']['price'], $tpl['option_arr']);?>" data-currency_format="<?php echo isset($tpl['option_arr']['o_currency_format']) ? $tpl['option_arr']['o_currency_format'] : 0;?>" data-msg-number="<?php __('lblValidNumberMessage');?>" data-msg-pjNumber="<?php __('lblValidNumberMessage');?>"/>
						</span>
					</span>
					<?php
					$price_types = $tpl['option_arr']['o_price_based_on'] == 'days' ? __('day_price_types', true) : __('price_types', true);
					$price_types = pjUtil::sortArrayByArray($price_types, array('person','night','person_night', 'count','count_night', 'one_time'));
					?>
					<select name="price_type" id="price_type" class="pj-form-field block float_left r10">
						<?php
						foreach ($price_types as $k => $v)
						{
							?><option value="<?php echo $k; ?>"<?php echo $k == $tpl['arr']['price_type'] ? ' selected="selected"' : null;?>><?php echo $v; ?></option><?php
						}
						?>
					</select>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblRequired'); ?></label>
				<span class="inline_block t5">
					<input type="checkbox" id="required" name="required"<?php echo 'T' == $tpl['arr']['required'] ? ' checked="checked"' : null;?>/>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblMultiQuantity'); ?></label>
				<span class="inline_block t5">
					<input type="checkbox" id="multi" name="multi"<?php echo 'T' == $tpl['arr']['multi'] ? ' checked="checked"' : null;?> class="block float_left r10"/>
					<span id="pjRpbMaxCount" class="block float_left" ><span class="block float_left r5"><?php __('lblMaximumCount');?></span><span class="block float_left r5" style="margin-top: -7px;"><input type="text" id="max_count" name="max_count" value="<?php echo $tpl['arr']['max_count'];?>" readonly="readonly" class="pj-form-field number field-int w80"/></span></span>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblStatus'); ?></label>
				<span class="inline_block">
					<select name="status" id="status" class="pj-form-field required" data-msg-required="<?php __('pj_field_required');?>">
						<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>
				</span>
			</p>
			<p>
				<label class="title">&nbsp;</label>
				<span class="inline_block">
					<input type="submit" value="<?php __('btnSave'); ?>" class="pj-button" />
					<input type="button" value="<?php __('btnCancel'); ?>" class="pj-button" onclick="window.location.href='<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjAdminExtras&action=pjActionIndex';" />
				</span>
			</p>
		</form>
	</div>
	
	<script type="text/javascript">
	var pjLocale = pjLocale || {};
	var myLabel = myLabel || {};
	myLabel.choose = "-- <?php __('lblChoose'); ?> --";
	var locale_array = new Array(); 
	pjLocale.langs = <?php echo $tpl['locale_str']; ?>;
	pjLocale.flagPath = "<?php echo PJ_FRAMEWORK_LIBS_PATH; ?>pj/img/flags/";
	myLabel.field_required = "<?php __('pj_field_required'); ?>";
	<?php
	foreach ($tpl['lp_arr'] as $v)
	{
		?>locale_array.push(<?php echo $v['id'];?>);<?php
	} 
	?>
	myLabel.locale_array = locale_array;
	(function ($) {
		$(function() {
			$(".multilang").multilang({
				langs: pjLocale.langs,
				flagPath: pjLocale.flagPath,
				select: function (event, ui) {
				}
			});
		});
	})(jQuery_1_8_2);
	</script>
	<?php
}
?>