<?php
if (isset($tpl['status']))
{
	$status = __('status', true);
	switch ($tpl['status'])
	{
		case 2:
			pjUtil::printNotice(NULL, $status[2]);
			break;
	}
} else {
	pjUtil::printNotice(__('infoUpdateOfferTitle', true), __('infoUpdateOfferDesc', true));
	?>
	
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOffers&amp;action=pjActionUpdate" method="post" id="frmUpdateOffer" class="pj-form form">
		<input type="hidden" name="offer_update" value="1" />
		<input type="hidden" name="id" value="<?php echo $tpl['arr']['id'];?>" />

		<div class="clear_both">
			<p>
				<label class="title"><?php __('lblCreated'); ?></label>
				<span class="inline_block">
					<label class="content"><?php echo date($tpl['option_arr']['o_date_format'], strtotime($tpl['arr']['created'])) . ', ' . date($tpl['option_arr']['o_time_format'], strtotime($tpl['arr']['created']));?></label>
				</span>
			</p>
			<?php
			$message = __('lblOffersFromIpAddress', true);
			if($tpl['arr']['cnt_offers'] == 1)
			{
				$message = __('lblOfferFromIpAddress', true);
			} 
			$message = str_replace("{OFFERS}", $tpl['arr']['cnt_offers'], $message);
			$message = str_replace("{STAG}", '<a href="'.$_SERVER['PHP_SELF'].'?controller=pjAdminOffers&amp;action=pjActionIndex&amp;ip='.$tpl['arr']['ip'].'">', $message);
			$message = str_replace("{ETAG}", '</a>', $message);
			?>
			<p>
				<label class="title"><?php __('lblIp'); ?></label>
				<span class="inline_block">
					<label class="content"><?php echo $tpl['arr']['ip'];?> (<?php echo $message;?>)</label>
				</span>
			</p>
			<p>
				<label class="title"><?php __('lblProductName'); ?></label>
				<span class="inline_block">
					<select name="product_id" class="pj-form-field float_left r5 w300 required" data-msg-required="<?php __('lblFieldRequired');?>">
						<option value="">-- <?php __('lblChoose'); ?> --</option>
						<?php
						foreach($tpl['product_arr'] as $k => $v)
						{
							?><option value="<?php echo $v['id'];?>"<?php echo $v['id'] == $tpl['arr']['product_id'] ? ' selected="selected"' : null;?>><?php echo $v['name'];?></option><?php
						} 
						?>
					</select>
					<a id="pjSPEditProduct" href="#" data-href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminProducts&amp;action=pjActionUpdate&amp;id=<?php echo $tpl['arr']['product_id'];?>" class="pj-edit t4"></a>
				</span>
			</p>
			<div id="pjSpPriceBox">
				<?php
				$opt = $tpl['arr']['price_option'];
				$message = '';
				switch ($tpl['product']['suggest_type']) {
					case 'offer':
						?>
						<p>
							<label class="title"><?php __('lblPrice'); ?></label>
							<span class="inline_block">
								<span class="block b10">
									<input type="radio" id="price_suggest_1" name="price" value="<?php echo $tpl['product']['price_suggest_1'];?>"<?php echo $tpl['arr']['price'] == $tpl['product']['price_suggest_1'] ? ' checked="checked"' : null; ?> class="required block float_left r3"/><label for="price_suggest_1"><?php echo pjUtil::formatCurrencySign($tpl['product']['price_suggest_1'], $tpl['option_arr']['o_currency']);?></label>
								</span>
								<span class="block b10">
									<input type="radio" id="price_suggest_2" name="price" value="<?php echo $tpl['product']['price_suggest_2'];?>"<?php echo $tpl['arr']['price'] == $tpl['product']['price_suggest_2'] ? ' checked="checked"' : null; ?> class="required block float_left r3"/><label for="price_suggest_2"><?php echo pjUtil::formatCurrencySign($tpl['product']['price_suggest_2'], $tpl['option_arr']['o_currency']);?></label>
								</span>
								<span class="block">
									<input type="radio" id="price_suggest_3" name="price" value="<?php echo $tpl['product']['price_suggest_3'];?>"<?php echo $tpl['arr']['price'] == $tpl['product']['price_suggest_3'] ? ' checked="checked"' : null; ?> class="required block float_left r3"/><label for="price_suggest_3"><?php echo pjUtil::formatCurrencySign($tpl['product']['price_suggest_3'], $tpl['option_arr']['o_currency']);?></label>
								</span>
							</span>
						</p>
						<?php
						$action = $tpl['product']['price_suggest_'.$opt.'_action'];
						$action = $action == 'thank' ? 'message' : $action;
						$message = $tpl['product']['price_suggest_'.$opt.'_' . $action];
					break;
					case 'suggest':
						?>
						<p>
							<label class="title"><?php __('lblPrice'); ?></label>
							<span class="inline_block">
								<span class="pj-form-field-custom pj-form-field-custom-before float_left r10">
									<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" value="<?php echo $tpl['arr']['price'];?>" class="pj-form-field required number w60" data-msg-required="<?php __('lblFieldRequired');?>" data-msg-number="<?php __('lblValidPrice');?>"/>
								</span>
							</span>
						</p>
						<?php
						$action = $tpl['product']['price_range_'.$opt.'_action'];
						$action = $action == 'thank' ? 'message' : $action;
						$message = $tpl['product']['price_range_'.$opt.'_' . $action];
						break;
				}
				?>
				<div id="pjSpMessageBox">
					<input type="hidden" name="price_option" value="<?php echo $opt;?>" />
					<?php 
					if($action == 'email')
					{
						?>
						<p>
							<label class="title"><?php __('email'); ?></label>
							<span class="pj-form-field-custom pj-form-field-custom-before">
								<span class="pj-form-field-before"><abbr class="pj-form-field-icon-email"></abbr></span>
								<input type="text" name="email" id="email" value="<?php echo $tpl['arr']['email'];?>" class="pj-form-field required email w200"/>
							</span>
						</p>
						<?php
					}else if($message != ''){
						?>
						<p>
							<label class="title">&nbsp;</label>
							<span class="inline_block">
								<label class="content"><?php echo $message;?></label>
							</span>
						</p>
						<?php
					}
					?>
				</div>
			</div>
			<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=pjAdminOffers&action=pjActionIndex';" />
			</p>
		</div>
	</form>
	
	<script type="text/javascript">
	var myLabel = myLabel || {};
	</script>
	<?php
}
?>