<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	if (isset($_GET['err']))
	{
		$titles = __('error_titles', true, false);
		$bodies = __('error_bodies', true, false);
		
		pjUtil::printNotice(@$titles[$_GET['err']], @$bodies[$_GET['err']]);
	}
	
	pjUtil::printNotice(__('infoUpdateFleetTitle', true, false), __('infoUpdateFleetDesc', true, false));
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminFleets&amp;action=pjActionUpdate" method="post" id="frmUpdateFleet" class="pj-form form" enctype="multipart/form-data">
		<input type="hidden" name="fleet_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']?>" />
		<input type="hidden" id="index_arr" name="index_arr" value="" />
		<input type="hidden" id="remove_arr" name="remove_arr" value="" />
		<?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">
			<?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 __('lblFleet'); ?></label>
					<span class="inline_block">
						<input type="text" name="i18n[<?php echo $v['id']; ?>][fleet]" class="pj-form-field w300<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>" lang="<?php echo $v['id']; ?>" value="<?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']]['fleet']); ?>" />
						<?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 __('lblImage', false, true); ?></label>
				<span class="inline_block">
					<input type="file" name="image" id="image" class="pj-form-field w300"/>
				</span>
			</p>
			<?php
			if(!empty($tpl['arr']['source_path']))
			{
				$thumb_url = PJ_INSTALL_URL . $tpl['arr']['thumb_path'];
				?>
				<p id="image_container">
					<label class="title">&nbsp;</label>
					<span class="inline_block">
						<img class="tr-image" src="<?php echo $thumb_url; ?>" />
						<a href="javascript:void(0);" class="pj-delete-image" data-href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminFleets&amp;action=pjActionDeleteImage&id=<?php echo $tpl['arr']['id'];?>"><?php __('lblDelete');?></a>
					</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 __('lblDescription'); ?>:</label>
					<span class="inline_block">
						<textarea name="i18n[<?php echo $v['id']; ?>][description]" class="pj-form-field w500 h150" lang="<?php echo $v['id']; ?>" ><?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']]['description']); ?></textarea>
						<?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 __('lblPassengers'); ?></label>
				<span class="inline-block">
					<input type="text" name="passengers" id="passengers" class="pj-form-field field-int w80" value="<?php echo pjSanitize::clean($tpl['arr']['passengers'])?>"/>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblLuggage'); ?></label>
				<span class="inline-block">
					<input type="text" name="luggage" id="luggage" class="pj-form-field field-int w80" value="<?php echo pjSanitize::clean($tpl['arr']['luggage'])?>"/>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblExtras'); ?></label>
				<span class="inline_block">
					<?php
					if(!empty($tpl['extra_arr']))
					{ 
						?>
						<select name="extra_id[]" id="extra_id" multiple="multiple" size="5" class="pj-form-field required w300">
							<?php
							foreach ($tpl['extra_arr'] as $v)
							{
							    ?><option value="<?php echo $v['id']; ?>"<?php echo in_array($v['id'], $tpl['extra_id_arr']) ? ' selected="selected"' : NULL;?>><?php echo pjSanitize::html($v['name']); ?></option><?php
							}
							?>
						</select>
						<?php
					}
					?>
				</span>
			</p>
			<div id="tr_dropoff_container" class="p tr-dropoff-container">
				<label class="title"><?php __('lblServices'); ?></label>
				<table id="tr_dropoff_table" class="tr-dropoff-table">
					<tr>
						<td>
							<label class="tr-column-name"><?php __('lblName');?></label>
							<?php 
							foreach ($tpl['lp_arr'] as $v)
							{ 
								?>
								<p class="pj-column-multilang-wrap" data-index="<?php echo $v['id']; ?>" style="display: <?php echo (int) $v['is_default'] === 0 ? 'none' : 'inline-block'; ?>">
									<?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;?>
								</p>
								<?php
							} 
							?>
						</td>
						<td><?php __('lblPrice'); ?></td>
						<td><?php __('lblIncludedExtras'); ?></td>
						<td>&nbsp;</td>
					</tr>
					<?php
					if(count($tpl['service_arr']) > 0)
					{
						foreach($tpl['service_arr'] as $k => $service)
						{
							?>
							<tr class="tr-location-row" data-index="<?php echo $service['id'];?>">
								<td>
									<?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' : 'inline-block'; ?>">
											<span class="inline_block">
												<input type="text" name="i18n[<?php echo $v['id']; ?>][name][<?php echo $service['id']; ?>]"  class="pj-form-field w150" lang="<?php echo $v['id']; ?>" value="<?php echo pjSanitize::html(@$service['i18n'][$v['id']]['name']); ?>"/>
											</span>
										</p>
										<?php
									} 
									?>
								</td>
								<td>
									<p>
										<span class="inline_block">
											<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="service_price_<?php echo $service['id'];?>" name="service_price[<?php echo $service['id'];?>]" value="<?php echo $service['price']; ?>" class="pj-form-field number w60 required"/>
											</span>
										</span>
									</p>
									
								</td>
								<td>
									<p class="pj-included-extras">
										<span class="inline_block">
											<select name="service_extra_id_<?php echo $service['id'];?>[]" id="service_extra_id_<?php echo $service['id'];?>" multiple="multiple" size="5" class="pj-form-field w200 pj-multieselect">
											<?php
											foreach ($tpl['extra_arr'] as $v)
											{
											    ?><option value="<?php echo $v['id']; ?>"<?php echo in_array($v['id'], $service['extra_id_arr']) ? ' selected="selected"' : NULL; ?>><?php echo pjSanitize::html($v['name']); ?></option><?php
											}
											?>
										</select>
										</span>
									</p>
								</td>
								<?php
								if($k > 0)
								{ 
									?>
									<td>
										<p class="pj-remove-service-outer">
											<span class="inline_block">
												<a href="#" class="pj-remove-service"></a>
											</span>
										</p>
									</td>
									<?php
								}
								?>
							</tr>
							<?php
						}
					} else {
						$index = 'tr_' . rand(1, 999999);
						?>
						<tr class="tr-location-row" data-index="<?php echo $index;?>">
							<td>
								<?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' : 'inline-block'; ?>">
										<span class="inline_block">
											<input type="text" name="i18n[<?php echo $v['id']; ?>][name][<?php echo $index;?>]"  class="pj-form-field w150<?php echo (int) $v['is_default'] === 0 ? '' : ' required'; ?>" lang="<?php echo $v['id']; ?>" />
										</span>
									</p>
									<?php
								} 
								?>
							</td>
							<td>
								<p>
									<span class="inline_block">
										<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="service_price_<?php echo $index;?>" name="service_price[<?php echo $index;?>]" class="pj-form-field number w60 required"/>
										</span>
									</span>
								</p>
								
							</td>
							<td>
								<p class="pj-included-extras">
									<span class="inline_block">
										<select name="service_extra_id_<?php echo $index;?>[]" id="service_extra_id_<?php echo $index;?>" multiple="multiple" size="5" class="pj-form-field w200 pj-multieselect">
										<?php
										foreach ($tpl['extra_arr'] as $v)
										{
											?><option value="<?php echo $v['id']; ?>"><?php echo stripslashes($v['name']); ?></option><?php
										}
										?>
									</select>
									</span>
								</p>
							</td>
						</tr>
						<?php
					} 
					?>
				</table>
			</div>
			<p>
				<label class="title">&nbsp;</label>
				<input type="button" value="<?php __('btnAdd'); ?>" class="pj-button pj-add-service" />
			</p>
			<p>
				<label class="title">&nbsp;</label>
				<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=pjAdminFleets&action=pjActionIndex';" />
			</p>
		</div>
	</form>
	
	<div id="dialogDeleteImage" style="display: none" title="<?php __('lblDeleteImage');?>"><?php __('lblDeleteConfirmation');?></div>
	
	<table id="tr_dropoff_table_clone" style="display: none;">
		<tr class="tr-location-row" data-index="{INDEX}">
			<td>
				<?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' : 'inline-block'; ?>">
						<span class="inline_block">
							<input type="text" name="i18n[<?php echo $v['id']; ?>][name][{INDEX}]"  class="pj-form-field w150<?php echo (int) $v['is_default'] === 0 ? '' : ' required'; ?>" lang="<?php echo $v['id']; ?>" />
						</span>
					</p>
					<?php
				} 
				?>
			</td>
			<td>
				<p>
					<span class="inline_block">
						<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="service_price_{INDEX}" name="service_price[{INDEX}]" class="pj-form-field number w60 required"/>
						</span>
					</span>
				</p>
				
			</td>
			<td>
				<p class="pj-included-extras">
					<span class="inline_block">
						<select name="service_extra_id_{INDEX}[]" id="service_extra_id_{INDEX}" multiple="multiple" size="5" class="pj-form-field w200 {MULTISELECT}">
						<?php
						foreach ($tpl['extra_arr'] as $v)
						{
						    ?><option value="<?php echo $v['id']; ?>"><?php echo pjSanitize::html($v['name']); ?></option><?php
						}
						?>
					</select>
					</span>
				</p>
			</td>
			<td>
				<p class="pj-remove-service-outer">
					<span class="inline_block">
						<a href="#" class="pj-remove-service"></a>
					</span>
				</p>
			</td>
		</tr>
	</table>
	
	<script type="text/javascript">
	var locale_array = new Array(); 
	var myLabel = myLabel || {};
	myLabel.field_required = "<?php __('tr_field_required'); ?>";
	<?php
	foreach ($tpl['lp_arr'] as $v)
	{
		?>locale_array.push(<?php echo $v['id'];?>);<?php
	} 
	?>
	myLabel.locale_array = locale_array;
	myLabel.localeId = "<?php echo $controller->getLocaleId(); ?>";
	(function ($) {
		$(function() {
			$(".multilang").multilang({
				langs: <?php echo $tpl['locale_str']; ?>,
				flagPath: "<?php echo PJ_FRAMEWORK_LIBS_PATH; ?>pj/img/flags/",
				tooltip: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sit amet faucibus enim.",
				select: function (event, ui) {
					$('.pj-column-multilang-wrap').css('display','none');
					$(".pj-column-multilang-wrap[data-index='" + ui.index + "']").css('display','block');
				}
			});
		});
	})(jQuery_1_8_2);
	</script>
	<?php
}
?>