<?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);
		$bodies = __('error_bodies', true);
		$bodies_text = str_replace("{SIZE}", ini_get('post_max_size'), @$bodies[$_GET['err']]);
		pjUtil::printNotice(@$titles[$_GET['err']], $bodies_text);
	}
	?>
	<div class="ui-tabs ui-widget ui-widget-content ui-corner-all b10">
		<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
			<li class="ui-state-default ui-corner-top ui-tabs-active ui-state-active"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionUpdate&amp;id=<?php echo $tpl['arr']['id']?>"><?php __('details'); ?></a></li>
			<li class="ui-state-default ui-corner-top"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionFeature&amp;id=<?php echo $tpl['arr']['id']?>"><?php __('features'); ?></a></li>
		</ul>
	</div>
	<?php
	pjUtil::printNotice(__('infoUpdateProductTitle', true, false), __('infoUpdateProductDesc', true, false));
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionUpdate" method="post" id="frmUpdateProduct" class="pj-form form" enctype="multipart/form-data">
		<input type="hidden" name="product_update" value="1" />
		<input type="hidden" name="csrf_token" value="<?php echo pjAppController::getCsrfToken(); ?>" />
		<input type="hidden" id="index_arr" name="index_arr" value="" />
		<input type="hidden" id="remove_arr" name="remove_arr" value="" />
		<input type="hidden" name="id" value="<?php echo $tpl['arr']['id']?>" />
		<?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 __('product_name'); ?>:</label>
					<span class="inline_block">
						<input type="text" name="i18n[<?php echo $v['id']; ?>][product_name]" 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']]['product_name']); ?>"/>
						<?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 __('image'); ?></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="pc-image" src="<?php echo $thumb_url; ?>" />
						<a href="javascript:void(0);" class="pj-delete-image" data-href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionDeleteImage&id=<?php echo $tpl['arr']['id'];?>"><?php __('delete');?></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 __('description'); ?>:</label>
					<span class="inline_block">
						<textarea id="i18n_description_<?php echo $v['id'];?>" name="i18n[<?php echo $v['id']; ?>][product_description]" class="pj-form-field h120 w450" lang="<?php echo $v['id']; ?>" ><?php echo pjSanitize::html(@$tpl['arr']['i18n'][$v['id']]['product_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
			} 
			?>
			<div id="pc_model_list" class="pc-model-list">
				<?php
				if(count($tpl['model_arr']) > 0)
				{
					foreach($tpl['model_arr'] as $k => $model)
					{
						?>
						<div class="pc-model-row" data-index="<?php echo $model['id'];?>">
							<?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 echo __('product_model', true, false); ?> <span class="pc-title-<?php echo $model['id'];?>">#<?php echo $k + 1;?></span></label>
									<span class="inline_block">
										<input type="text" name="i18n[<?php echo $v['id']; ?>][model_name][<?php echo $model['id'];?>]" class="pj-form-field float_left r3 w300<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>" value="<?php echo pjSanitize::html(@$model['i18n'][$v['id']]['model_name']); ?>"/>
										<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
										<span class="pj-multilang-input float_left r10"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
										<?php endif;?>
									</span>
								</p>
								<?php
							}
							if($k != 0)
							{
								?>
								<div class="model-icons">
									<input type="button" value="<?php __('btnRemove'); ?>" class="pj-button pj-remove-model pj-confirm" />
								</div>
								<?php
							} 
							?>
							<p>
								<label class="title">&nbsp;</label>
								<span class="inline_block">
									<input type="file" name="model_image_<?php echo $model['id'];?>" class="pj-form-field w300"/>
								</span>
							</p>
							<?php
							if(!empty($model['thumb_path']))
							{
								$thumb_url = PJ_INSTALL_URL . $model['thumb_path'];
								?>
								<p>
									<label class="title">&nbsp;</label>
									<span class="inline_block">
										<img class="pc-image" src="<?php echo $thumb_url; ?>" />
										<a href="#" class="pj-delete-model-image" data-href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionDeleteModelImage&id=<?php echo $model['id'];?>"><?php __('delete');?></a>
									</span>
								</p>
								<?php
							} 
							?>
							<?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">&nbsp;</label>
									<span class="inline_block">
										<textarea name="i18n[<?php echo $v['id']; ?>][description][<?php echo $model['id'];?>]" class="pj-form-field w450 h80"><?php echo pjSanitize::html(@$model['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 float_left r10"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
										<?php endif;?>
									</span>
								</p>
								<?php
							}
							?>
						</div>
						<?php
					}
				}else{
					$index = 'bs_' . rand(1, 999999);
					?>
					<div class="pc-model-row" data-index="<?php echo $index;?>">
						<?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 __('product_model'); ?></label>
								<span class="inline_block">
									<span class="block float_left t5 r10 pc-title-<?php echo $index;?>">#1</span>
									<input type="text" name="i18n[<?php echo $v['id']; ?>][model_name][<?php echo $index;?>]" class="pj-form-field float_left r3 w300<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>"/>
									<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
									<span class="pj-multilang-input float_left r10"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
									<?php endif;?>
								</span>
							</p>
							<?php
						}
						?>
					</div>
					<?php
				} 
				?>
			</div>
			<p>
				<label class="title">&nbsp;</label>
				<input type="button" value="<?php __('btnAddModel'); ?>" class="pj-button pj-add-model" />
			</p>
			<p>
				<label class="title"><?php __('categories'); ?></label>
				<span class="inline_block" id="boxCategory">
					<select name="category_id[]" id="category_id" class="pj-form-field required" multiple="multiple" size="5">
						<?php
						foreach ($tpl['category_arr'] as $v)
						{
							?><option value="<?php echo $v['id']; ?>"<?php echo in_array($v['id'], $tpl['category_id_arr']) ? ' selected="selected"' : null;?>><?php echo pjSanitize::html($v['name']); ?></option><?php
						}
						?>
					</select>
				</span>
			</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=pjAdminProducts&action=pjActionIndex';" />
			</p>
		</div>
	</form>
	
	<div id="pc_model_clone" style="display:none;">
		<div class="pc-model-row" data-index="{INDEX}">
			<?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 echo __('product_model', true, false); ?> <span class="pc-title-{INDEX}">#{ORDER}</span></label>
					<span class="inline_block">
						<input type="text" name="i18n[<?php echo $v['id']; ?>][model_name][{INDEX}]" class="pj-form-field float_left r3 w300<?php echo (int) $v['is_default'] === 0 ? NULL : ' required'; ?>"/>
						<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
						<span class="pj-multilang-input float_left r10"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
						<?php endif;?>
					</span>
				</p>
				<?php
			}
			?>
			<div class="model-icons">
				<input type="button" value="<?php __('btnRemove'); ?>" class="pj-button pj-remove-model" />
			</div>
			<p>
				<label class="title">&nbsp;</label>
				<span class="inline_block">
					<input type="file" name="model_image_{INDEX}" class="pj-form-field w300"/>
				</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">&nbsp;</label>
					<span class="inline_block">
						<textarea name="i18n[<?php echo $v['id']; ?>][description][{INDEX}]" class="pj-form-field w450 h80"></textarea>
						<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1 && count($tpl['lp_arr']) > 1) : ?>
						<span class="pj-multilang-input float_left r10"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
						<?php endif;?>
					</span>
				</p>
				<?php
			}
			?>
		</div>
	</div>
	
	<div id="dialogDeleteModel" style="display: none" title="<?php __('lblDeleteModel');?>"><?php __('lblDeleteModelConfirmation');?></div>
	<div id="dialogDeleteImage" style="display: none" title="<?php __('delete_image');?>"><?php __('delete_image_confirmation');?></div>
	<div id="dialogDeleteModelImage" style="display: none" title="<?php __('delete_image');?>"><?php __('delete_image_confirmation');?></div>
	
	<script type="text/javascript">
	var locale_array = new Array(); 
	var myLabel = myLabel || {};
	myLabel.field_required = "<?php __('pc_field_required'); ?>";
	myLabel.select_categories = "<?php __('lblSelectCategories'); ?>";
	<?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) {
					// Callback, e.g. ajax requests or whatever
				}
			});
		});
	})(jQuery_1_8_2);
	</script>
	<?php
}
?>