<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	$hash = md5(uniqid(rand(), true));
	
	$titles = __('error_titles', true);
	$bodies = __('error_bodies', true);
	?>
	
	
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminItems&amp;action=pjActionCreate" method="post" id="frmCreateItem" class="form pj-form" autocomplete="off">
		<input type="hidden" name="item_create" value="1" />
		<input type="hidden" name="hash" value="<?php echo $hash; ?>" />
		
		<div id="tabs">
			<ul>
				<li><a href="#tabs-1"><?php __('items_details'); ?></a></li>
				<li><a href="#tabs-2"><?php __('items_photos'); ?></a></li>
			</ul>
			
			<div id="tabs-1">
				
				<?php
				pjUtil::printNotice(@$titles['AI06'], @$bodies['AI06']);
				
				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 __('items_title'); ?>:</label>
							<span class="inline_block">
								<input type="text" name="i18n[<?php echo $v['id']; ?>][title]" class="pj-form-field w400<?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"><img src="<?php echo PJ_INSTALL_URL . PJ_FRAMEWORK_LIBS_PATH . 'pj/img/flags/' . $v['file']; ?>" alt="" /></span>
								<?php endif; ?>
							</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 __('items_desc'); ?>:</label>
							<span class="inline_block">
								<textarea name="i18n[<?php echo $v['id']; ?>][description]" class="pj-form-field w500 h150"></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 __('items_category'); ?></label>
						<span class="inline_block">
							<?php							
							if(!empty($tpl['category_arr']))
							{ 
								?>
								<select name="category_id" id="category_id" class="pj-form-field">
									<option value="">-- <?php __('lblChoose'); ?>--</option>
									<?php
									foreach ($tpl['category_arr'] as $v)
									{
										?><option value="<?php echo $v['id']; ?>"><?php echo stripslashes($v['title']); ?></option><?php
									}
									?>
								</select>
								<?php
							}else{
								$message = __('lblNoCategoriesMessage', true);
								$message = str_replace("{STAG}", '<a href="'.PJ_INSTALL_URL.'index.php?controller=pjAdminCategories&action=pjActionCreate">', $message);
								$message = str_replace("{ETAG}", '</a>', $message);
								?><span class="block t5"><?php echo $message;?></span><?php
							} 
							?>
						</span>
					</p>
					<p>
						<label class="title"><?php __('items_cnt'); ?></label>
						<span class="inline_block">
							<input type="text" name="cnt" class="pj-form-field w80 spinner" value="0" />
						</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=pjAdminItems&action=pjActionIndex';" />
					</p>
				</div>
			</div>
			<div id="tabs-2">
				<?php pjUtil::printNotice(@$titles['AI07'], @$bodies['AI07']); ?>
				<div id="gallery"></div>
			</div>
		</div>
	</form>
	
	<script type="text/javascript">
	var myGallery = myGallery || {};
	myGallery.foreign_id = "";
	myGallery.hash = "<?php echo $hash; ?>";
	<?php if ((int) $tpl['option_arr']['o_multi_lang'] === 1) : ?>
	var pjLocale = pjLocale || {};
	pjLocale.langs = <?php echo $tpl['locale_str']; ?>;
	pjLocale.flagPath = "<?php echo PJ_FRAMEWORK_LIBS_PATH; ?>pj/img/flags/";
	(function ($) {
		$(function() {
			$(".multilang").multilang({
				langs: pjLocale.langs,
				flagPath: pjLocale.flagPath,
				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);
	<?php endif; ?>
	</script>
	<?php
}
?>