<?php
class ControllerProductAuction extends Controller {
	public function index() {
		$this->language->load('product/auction');
		$this->load->model('catalog/auction');
		if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
			$auction_status_ids = $this->config->get('config_auction_status_id');
		} else {
			$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
		}
		if (!is_null($this->config->get('config_auction_quick_bidding'))) {
			$quick_bidding = (int)$this->config->get('config_auction_quick_bidding');
		} else {
			$quick_bidding = 1;
		}
		$this->load->model('localisation/auction_status');
		$auction_statuses = $this->model_localisation_auction_status->getAuctionStatuses();
		$this->data['text_auction_statuses'] = array();
		$this->data['auction_status_ids'] = array();
		$this->data['auction_statuses'] = array();
		foreach ($auction_status_ids as $key => $value) {
			foreach ($auction_statuses as $auction_status) {
				if ($auction_status['auction_status_id'] == $value) {
					$this->data['text_auction_statuses'][$key] = $auction_status['name'];
					$this->data['auction_status_ids'][$key] = $value;
					$this->data['auction_statuses'][(string)$value] = $auction_status['name'];
				}
			}
		}
		if (isset($this->request->get['completed'])) {
			$completed = 1;
		} else {
			$completed = 0;
		}
		if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} elseif ($completed) {
			$sort = 'a.date_closed';
		} else {
			$sort = 'a.real_ending_time';
		}
		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} elseif ($completed) {
			$order = 'DESC';
		} else {
			$order = 'ASC';
		}
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else { 
			$page = 1;
		}
		if (isset($this->request->get['limit'])) {
			$limit = $this->request->get['limit'];
		} else {
			$limit = $this->config->get('config_catalog_limit');
		}
		$this->data['breadcrumbs'] = array();
		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);
		$data = array(
			'completed'          => $completed,
			'auction_status_ids' => $auction_status_ids,
			'sort'               => $sort,
			'order'              => $order,
			'start'              => ($page - 1) * $limit,
			'limit'              => $limit
		);
		$auction_total = $this->model_catalog_auction->getTotalAuctions($data);
		$results = $this->model_catalog_auction->getAuctions($data);
		if ($results) {
			if ($completed) {
				$this->data['heading_title'] = $this->language->get('text_completed');
				$this->data['text_toggle'] = $this->language->get('button_view') . ' ' . $this->language->get('text_live_auction');
				$this->data['link_current'] = $this->url->link('product/auction', 'completed=1');
				$this->data['link_toggle'] = $this->url->link('product/auction');
			} else {
				$this->data['heading_title'] = $this->language->get('text_live_auction');
				//$this->data['heading_title'] = 'Encheres';
				$this->data['text_toggle'] = $this->language->get('button_view') . ' ' . $this->language->get('text_completed');
				$this->data['link_current'] = $this->url->link('product/auction');
				$this->data['link_toggle'] = $this->url->link('product/auction', 'completed=1');
			}
			$this->data['breadcrumbs'][] = array(
				'text'      => $this->data['heading_title'],
				'href'      => $this->data['link_current'],
				'separator' => $this->language->get('text_separator')
			);
			$this->document->setTitle($this->data['heading_title']);
			$this->data['text_display'] = $this->language->get('text_display');
			$this->data['text_grid'] = $this->language->get('text_grid');
			$this->data['text_sort'] = $this->language->get('text_sort');
			$this->data['text_limit'] = $this->language->get('text_limit');
			$this->data['text_rating'] = $this->language->get('text_rating');			
			$this->data['text_review'] = $this->language->get('text_review');			
			$this->data['text_reviews'] = $this->language->get('text_reviews');			
			$this->data['text_closing'] = $this->language->get('text_closing');
			$this->data['text_closed'] = $this->language->get('text_closed');
			$this->data['text_ended'] = $this->language->get('text_ended');
			$this->data['button_quick_bid'] = $this->customer->isLogged() ? $this->language->get('button_quick_bid') : $this->language->get('button_login');
			$this->data['symbol_left'] = $this->currency->getSymbolLeft();
			$this->data['symbol_right'] = $this->currency->getSymbolRight();
			$this->data['decimal_place'] = $this->currency->getDecimalPlace();
			$this->data['decimal_point'] = $this->language->get('decimal_point');
			$this->data['thousand_point'] = $this->language->get('thousand_point');
			if (!$this->customer->isLogged()) {
				$this->session->data['redirect'] = $this->url->link('product/auction', '', 'SSL');
			}
			$this->data['logged'] = (int)$this->customer->isLogged();
			$this->data['login_url'] = $this->url->link('account/login');
			$this->data['quick_bidding'] = $quick_bidding;
			$this->data['completed'] = $completed;
			$this->data['auctions'] = array();
			$this->data['auction_ids'] = array();
			$meta_description = array();
			$meta_keyword = array();
			$this->load->model('tool/image');
			foreach ($results as $result) {
				if ($result['product_image']) {
					$product_image = $this->model_tool_image->resize($result['product_image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
				} else {
					$product_image = $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
				}
				//if (strlen(stripslashes($result['product_name'])) > 30) {
				//	$product_name = substr(stripslashes($result['product_name']), 0, 30) . ' ...';
				//} else {
					$product_name = stripslashes($result['product_name']);
				//}
				if ($this->config->get('config_review_status')) {
					$product_rating = (float)$result['product_rating'];
				} else {
					$product_rating = false;
				}
				if ($result['meta_description']) {
					$meta_description[] = trim(stripslashes($result['meta_description']));
				}
				if ($result['meta_keyword']) {
					$meta_keyword[] = trim(stripslashes($result['meta_keyword']));
				}
				if (!$result['total_no_of_bid']) {
					$current_bid_amount = (float)$result['starting_price'];
					$next_bid_amount = (float)$result['starting_price'];
				} elseif ((float)$result['buyout_price'] > 0 && !$result['buyout_made'] && (float)(string)((float)$result['highest_bid_amount'] + (float)$result['min_increment']) > (float)$result['buyout_price']) {
					$current_bid_amount = (float)$result['highest_bid_amount'];
					$next_bid_amount = (float)$result['buyout_price'];
				} else {
					$current_bid_amount = (float)$result['highest_bid_amount'];
					$next_bid_amount = (float)(string)((float)$result['highest_bid_amount'] + (float)$result['min_increment']);
				}
				if ($result['auction_status_id'] == $auction_status_ids['won'] || $result['auction_status_id'] == $auction_status_ids['expired'] || $result['auction_status_id'] == $auction_status_ids['sold'] || $result['auction_status_id'] == $auction_status_ids['voided']) {
					$auction_closed = '<font style="color: #FF0000;">' . $this->language->get('text_closed') . '</font>';
				} elseif ($result['auction_status_id'] == $auction_status_ids['starting'] || $result['auction_status_id'] == $auction_status_ids['relisting']) {
					$auction_closed = '<font style="color: #FF0000;">' . $this->language->get('text_status_error') . '</font>';
				} else {
					$auction_closed = '';
				}
				if ($result['auction_status_id'] == $auction_status_ids['won']) {
					$auction_ended = '<font style="color: #999999; font-size: 10px;">' . $this->language->get('text_won') . '</font>';
				} elseif ($result['auction_status_id'] == $auction_status_ids['expired']) {
					$auction_ended = '<font style="color: #999999; font-size: 10px;">' . $this->language->get('text_expired') . '</font>';
				} elseif ($result['auction_status_id'] == $auction_status_ids['sold']) {
					$auction_ended = '<font style="color: #999999; font-size: 10px;">' . $this->language->get('text_sold') . '</font>';
				} elseif ($result['auction_status_id'] == $auction_status_ids['voided']) {
					$auction_ended = '<font style="color: #999999; font-size: 10px;">' . $this->language->get('text_voided') . '</font>';
				} else {
					$auction_ended = '';
				}
				$this->data['auctions'][] = array(
					'product_id'              => (int)$result['product_id'],
					'product_image'           => $product_image,
					'product_name'            => $product_name,
					'product_rating'          => $product_rating,
					'product_reviews'         => (int)$result['product_reviews'],
					'auction_href'            => $this->url->link('product/product', 'product_id=' . $result['product_id'] . '&auction_id=' . $result['auction_id']),
					'auction_id'              => (int)$result['auction_id'],
					'auction_name'            => stripslashes($result['auction_name']),
					'auction_closed'          => $auction_closed,
					'auction_ended'           => $auction_ended,
					'reserved_quantity'       => (int)$result['reserved_quantity'],
					'buyout_price'            => $this->currency->format((float)$result['buyout_price'], '', '', false, 'up'),
					'min_increment'           => $this->currency->format((float)$result['min_increment'], '', '', false, 'up'),
					'highest_bid_id'          => (int)$result['highest_bid_id'],
					'highest_bidder_masked'   => (int)$result['highest_bidder_id'] ? substr(preg_replace("/[^a-z0-9]/", '', strtolower(stripslashes($result['customer_email']))), 0, 3) . 'xxxxxxx' : '---',
					'current_bid_amount'      => $this->currency->format((float)$current_bid_amount, '', '', false, 'up'),
					'current_bid_amount_text' => $this->currency->format((float)$current_bid_amount, '', '', true, 'up'),
					'next_bid_amount'         => $this->currency->format((float)$next_bid_amount, '', '', false, 'up'),
					'next_bid_amount_text'    => $this->currency->format((float)$next_bid_amount, '', '', true, 'up'),
					'real_ending_time'        => (int)$result['real_ending_time'],
					'auction_status_id'       => (int)$result['auction_status_id']
				);
				$this->data['auction_ids'][] = (int)$result['auction_id'];
			}
			$this->document->setDescription(implode(', ', $meta_description));
			$this->document->setKeywords(implode(', ', $meta_keyword));
			$url = '';
			if (isset($this->request->get['completed'])) {
				$url .= '&completed=' . $this->request->get['completed'];
			}
			if (isset($this->request->get['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}
			$this->data['sorts'] = array();
			if ($completed) {
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_default'),
					'value' => 'a.date_closed-DESC',
					'href'  => $this->url->link('product/auction', 'sort=a.date_closed&order=DESC' . $url)
				);
			} else {
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_default'),
					'value' => 'a.real_ending_time-ASC',
					'href'  => $this->url->link('product/auction', 'sort=a.real_ending_time&order=ASC' . $url)
				);
			}
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_hottest'),
				'value' => 'a.total_no_of_bid-DESC',
				'href'  => $this->url->link('product/auction', 'sort=a.total_no_of_bid&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_best_seller'),
				'value' => 'product_orders-DESC',
				'href'  => $this->url->link('product/auction', 'sort=product_orders&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_latest'),
				'value' => 'pa.starting_time-DESC',
				'href'  => $this->url->link('product/auction', 'sort=pa.starting_time&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_featured'),
				'value' => 'product_featured-DESC',
				'href'  => $this->url->link('product/auction', 'sort=product_featured&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_name_asc'),
				'value' => 'product_name-ASC',
				'href'  => $this->url->link('product/auction', 'sort=product_name&order=ASC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_name_desc'),
				'value' => 'product_name-DESC',
				'href'  => $this->url->link('product/auction', 'sort=product_name&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_price_asc'),
				'value' => 'current_bid_amount-ASC',
				'href'  => $this->url->link('product/auction', 'sort=current_bid_amount&order=ASC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_price_desc'),
				'value' => 'current_bid_amount-DESC',
				'href'  => $this->url->link('product/auction', 'sort=current_bid_amount&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_buyout_asc'),
				'value' => 'pa.buyout_price-ASC',
				'href'  => $this->url->link('product/auction', 'sort=pa.buyout_price&order=ASC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_buyout_desc'),
				'value' => 'pa.buyout_price-DESC',
				'href'  => $this->url->link('product/auction', 'sort=pa.buyout_price&order=DESC' . $url)
			);
			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_most_viewed'),
				'value' => 'product_viewed-DESC',
				'href'  => $this->url->link('product/auction', 'sort=product_viewed&order=DESC' . $url)
			);
			if ($this->config->get('config_review_status')) {
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_high_rating'),
					'value' => 'product_rating-DESC',
					'href'  => $this->url->link('product/auction', 'sort=product_rating&order=DESC' . $url)
				); 
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_most_reviews'),
					'value' => 'product_reviews-DESC',
					'href'  => $this->url->link('product/auction', 'sort=product_reviews&order=DESC' . $url)
				); 
			}
			$url = '';
			if (isset($this->request->get['completed'])) {
				$url .= '&completed=' . $this->request->get['completed'];
			}
			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}
			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}
			$this->data['limits'] = array();
			$default_limit  = (int)$this->config->get('config_catalog_limit');
			for ($limit_fold = 1; $limit_fold <= 5; $limit_fold++) {
				$display_limit = $default_limit * $limit_fold;
				$this->data['limits'][] = array(
					'text'  => $display_limit,
					'value' => $display_limit,
					'href'  => $this->url->link('product/auction', $url . '&limit=' . $display_limit)
				);
			}
			$url = '';
			if (isset($this->request->get['completed'])) {
				$url .= '&completed=' . $this->request->get['completed'];
			}
			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}	
			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}
			if (isset($this->request->get['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}
			$pagination = new Pagination();
			$pagination->total = $auction_total;
			$pagination->page = $page;
			$pagination->limit = $limit;
			$pagination->text = $this->language->get('text_pagination');
			$pagination->url = $this->url->link('product/auction', $url . '&page={page}');
			$this->data['pagination'] = $pagination->render();
			$this->data['sort'] = $sort;
			$this->data['order'] = $order;
			$this->data['limit'] = $limit;
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/auction_list.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/product/auction_list.tpl';
			} else {
				$this->template = 'default/template/product/auction_list.tpl';
			}
			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);
			$this->response->setOutput($this->render());
		} else {
			$url = '';
			if (isset($this->request->get['completed'])) {
				$url .= '&completed=' . $this->request->get['completed'];
			}
			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}	
			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}
			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}
			if (isset($this->request->get['limit'])) {
				$url .= '&limit=' . $this->request->get['limit'];
			}
			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_error'),
				'href'      => $this->url->link('product/auction', $url),
				'separator' => $this->language->get('text_separator')
			);
			$this->document->setTitle($this->language->get('text_error'));
			$this->data['heading_title'] = $this->language->get('text_error');
			$this->data['text_error'] = $this->language->get('text_error');
			$this->data['button_continue'] = $this->language->get('button_continue');
			$this->data['continue'] = $this->url->link('common/home');
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);
			$this->response->setOutput($this->render());
		}
	}

	public function info() {
		$this->language->load('product/auction');
		$this->load->model('catalog/auction');
		if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
			$auction_status_ids = $this->config->get('config_auction_status_id');
		} else {
			$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
		}
		$this->load->model('localisation/auction_status');
		$auction_statuses = $this->model_localisation_auction_status->getAuctionStatuses();
		$this->data['text_auction_statuses'] = array();
		$this->data['auction_status_ids'] = array();
		$this->data['auction_statuses'] = array();
		foreach ($auction_status_ids as $key => $value) {
			foreach ($auction_statuses as $auction_status) {
				if ($auction_status['auction_status_id'] == $value) {
					$this->data['text_auction_statuses'][$key] = $auction_status['name'];
					$this->data['auction_status_ids'][$key] = $value;
					$this->data['auction_statuses'][(string)$value] = $auction_status['name'];
				}
			}
		}
		if (!is_null($this->config->get('config_auction_normal_sales'))) {
			$this->data['normal_sales'] = (int)$this->config->get('config_auction_normal_sales');
		} else {
			$this->data['normal_sales'] = 0;
		}
		if (isset($this->request->get['product_id'])) {
			$product_id = $this->request->get['product_id'];
		} else {
			$product_id = 0;
		}
		if (isset($this->request->get['auction_id'])) {
			$auction_id = (int)$this->request->get['auction_id'];
			$auction_valid = (int)$this->model_catalog_auction->getAuctionValidity($product_id, $auction_id, $auction_status_ids);
		} else {
			$auction_id = 0;
			$auction_valid = 0;
		}
		$total_auctions = (int)$this->model_catalog_auction->getTotalLiveAuctionsByProductId($product_id, $auction_status_ids);
		$this->data['product_id'] = $product_id;
		$this->data['auction_id'] = $auction_id;
		$this->data['total_auctions'] = $total_auctions;
		$this->data['auction'] = array();
		$this->data['auction_active'] = false;
		$this->data['auction_ids'] = array();
		if ($auction_valid || $total_auctions) {
			// auction tabs
			$this->data['tab_bid_history'] = $this->language->get('tab_bid_history');
			$this->data['tab_auctions'] = $this->language->get('tab_auctions');
			// auction entries
			$this->data['entry_maxbid'] = $this->language->get('entry_maxbid');
			$this->data['entry_persistbid'] = $this->language->get('entry_persistbid');
			// auction texts
			$this->data['text_ok'] = $this->language->get('text_ok');
			$this->data['text_for'] = $this->language->get('text_for');
			$this->data['text_yes'] = $this->language->get('text_yes');
			$this->data['text_no'] = $this->language->get('text_no');
			$this->data['text_active'] = $this->language->get('text_active');
			$this->data['text_inactive'] = $this->language->get('text_inactive');
			$this->data['text_closing'] = $this->language->get('text_closing');
			$this->data['text_closed'] = $this->language->get('text_closed');
			$this->data['text_started_on'] = $this->language->get('text_started_on');
			$this->data['text_ended_on'] = $this->language->get('text_ended_on');
			$this->data['text_current_bid'] = $this->language->get('text_current_bid');
			$this->data['text_close_price'] = $this->language->get('text_close_price');
			$this->data['text_time_extended'] = $this->language->get('text_time_extended');
			$this->data['text_time_buyout'] = $this->language->get('text_time_buyout');
			$this->data['text_ending_soon'] = $this->language->get('text_ending_soon');
			$this->data['text_going_going'] = $this->language->get('text_going_going');
			$this->data['text_gone'] = $this->language->get('text_gone');
			$this->data['text_current_high'] = $this->language->get('text_current_high');
			$this->data['text_by'] = $this->language->get('text_by');
			$this->data['text_seconds_short'] = $this->language->get('text_seconds_short');
			$this->data['text_or'] = $this->language->get('text_or');
			$this->data['text_bundled_qty'] = $this->language->get('text_bundled_qty');
			$this->data['text_autobid'] = $this->language->get('text_autobid');
			$this->data['text_autobid_help'] = $this->language->get('text_autobid_help');
			$this->data['text_autobidsaved'] = $this->language->get('text_autobidsaved');
			$this->data['text_autobidstart'] = $this->language->get('text_autobidstart');
			$this->data['text_autobidstop'] = $this->language->get('text_autobidstop');
			$this->data['text_bid_boughtout'] = $this->language->get('text_bid_boughtout');
			$this->data['text_bid_extended'] = $this->language->get('text_bid_extended');
			$this->data['text_bid_success'] = $this->language->get('text_bid_success');
			$this->data['text_bid_updated'] = $this->language->get('text_bid_updated');
			$this->data['text_bid_updated2'] = $this->language->get('text_bid_updated2');
			$this->data['text_maxbid'] = $this->language->get('text_maxbid');
			$this->data['text_persistbid'] = $this->language->get('text_persistbid');
			$this->data['text_in_progress'] = $this->language->get('text_in_progress');
			$this->data['text_auction'] = $this->language->get('text_auction');
			$this->data['text_auctions'] = $this->language->get('text_auctions');
			$this->data['text_auction_price'] = $this->language->get('text_auction_price');
			$this->data['text_buyout_price'] = $this->language->get('text_buyout_price');
			// auction buttons
			$this->data['button_start_bidding'] = $this->language->get('button_start_bidding');
			$this->data['button_place_bid'] = $this->customer->isLogged() ? $this->language->get('button_place_bid') : $this->language->get('button_login_to_bid');
			$this->data['button_buy_now'] = $this->language->get('button_buy_now');
			$this->data['button_save_auto_bid'] = $this->language->get('button_save_auto_bid');
			$this->data['button_wishlist'] = $this->language->get('button_wishlist');
			$this->data['button_compare'] = $this->language->get('button_compare');			
			// auction error messages
			$this->data['modal_confirm'] = $this->language->get('modal_confirm');
			$this->data['modal_warning'] = $this->language->get('modal_warning');
			$this->data['modal_bid_buyout'] = $this->language->get('modal_bid_buyout');
			$this->data['modal_cfm_buyout'] = $this->language->get('modal_cfm_buyout');
			$this->data['modal_bid_fail'] = $this->language->get('modal_bid_fail');
			$this->data['modal_not_enough'] = $this->language->get('modal_not_enough');
			$this->data['modal_data_corrupt'] = $this->language->get('modal_data_corrupt');
			$this->data['modal_alr_highest'] = $this->language->get('modal_alr_highest');
			$this->data['modal_just_ended'] = $this->language->get('modal_just_ended');
			$this->data['modal_not_active'] = $this->language->get('modal_not_active');
			$this->data['modal_not_found'] = $this->language->get('modal_not_found');
			$this->data['modal_no_params'] = $this->language->get('modal_no_params');
			$this->data['modal_not_login'] = $this->language->get('modal_not_login');
			$this->data['modal_conn_lost'] = $this->language->get('modal_conn_lost');
			$this->data['modal_auto_not_set'] = $this->language->get('modal_auto_not_set');
			$this->data['modal_save_too_low'] = $this->language->get('modal_save_too_low');
			$this->data['modal_save_buyout'] = $this->language->get('modal_save_buyout');
			$this->data['modal_save_fail'] = $this->language->get('modal_save_fail');
			$this->data['modal_invalid_data'] = $this->language->get('modal_invalid_data');
			$this->data['modal_no_params2'] = $this->language->get('modal_no_params2');
			$this->data['modal_not_login2'] = $this->language->get('modal_not_login2');
			$this->data['modal_conn_lost2'] = $this->language->get('modal_conn_lost2');
			// auction related symbols
			$this->data['symbol_left'] = $this->currency->getSymbolLeft();
			$this->data['symbol_right'] = $this->currency->getSymbolRight();
			$this->data['decimal_place'] = $this->currency->getDecimalPlace();
			$this->data['decimal_point'] = $this->language->get('decimal_point');
			$this->data['thousand_point'] = $this->language->get('thousand_point');
			if (!$this->customer->isLogged()) {
				$this->session->data['redirect'] = $this->url->link('product/product', 'product_id=' . $product_id);
			}
			// valid auction information
			if ($auction_valid) {
				$auction = $this->model_catalog_auction->getAuctionDetails($auction_id);
				if ($auction) {
					// auction related values
					if (!$this->customer->isLogged()) {
						$this->session->data['redirect'] = $this->url->link('product/product', 'product_id=' . $product_id . '&auction_id=' . $auction_id);
					}
					$this->data['logged'] = (int)$this->customer->isLogged();
					$this->data['login_url'] = $this->url->link('account/login');
					$this->data['bid_disabled'] = 'disabled';
					$this->data['customer_id'] = (int)$this->customer->getId();
					$this->data['bid_setting'] = array();
					$this->data['max_bid_amount'] = 0;
					// add new auction bread crumb after product
					$this->data['breadcrumb'] = array(
						'text'      => stripslashes($auction['auction_name']),
						'href'      => $this->url->link('product/product', 'product_id=' . $product_id . '&auction_id=' . $auction_id),
						'separator' => $this->language->get('text_separator')
					);
					// check if auction is still in-progress
					if ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended']) {
						$this->data['auction_active'] = true;
						$this->data['bid_disabled'] = '';
					}
					// pre-define current bid amount and next bid amount for display
					if (!$auction['total_no_of_bid']) {
						$current_bid_amount = (float)$auction['starting_price'];
						$next_bid_amount = (float)$auction['starting_price'];
					} elseif ((float)$auction['buyout_price'] > 0 && !$auction['buyout_made'] && (float)(string)((float)$auction['highest_bid_amount'] + (float)$auction['min_increment']) > (float)$auction['buyout_price']) {
						$current_bid_amount = (float)$auction['highest_bid_amount'];
						$next_bid_amount = (float)$auction['buyout_price'];
					} else {
						$current_bid_amount = (float)$auction['highest_bid_amount'];
						$next_bid_amount = (float)(string)((float)$auction['highest_bid_amount'] + (float)$auction['min_increment']);
					}
					// mask highest bidder email address
					if ($auction['highest_bidder_id']) {
						$highest_bidder_masked = substr(preg_replace("/[^a-z0-9]/", '', strtolower(stripslashes($auction['customer_email']))), 0, 3) . 'xxxxxxx';
					} else {
						$highest_bidder_masked = '---';
					}
					// current bid text display
					if ($auction['total_no_of_bid'] && ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended'])) {
						$this->data['auction_current_bid_text'] = $this->language->get('text_current_bid');
					} elseif ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended']) {
						$this->data['auction_current_bid_text'] = $this->language->get('text_start_price');
					} elseif ($auction['auction_status_id'] == $auction_status_ids['won'] || $auction['auction_status_id'] == $auction_status_ids['expired'] || $auction['auction_status_id'] == $auction_status_ids['sold'] || $auction['auction_status_id'] == $auction_status_ids['voided']) {
						$this->data['auction_current_bid_text'] = $this->language->get('text_close_price');
					} else {
						$this->data['auction_current_bid_text'] = '';
					}
					// bidder text display
					if ($this->customer->isLogged() && $auction['highest_bidder_id'] == $this->customer->getId() && ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended'])) {
						$this->data['auction_bidder_text'] = '(' . $this->language->get('text_current_high') . ')';
					} elseif (!$auction['total_no_of_bid'] && ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended'])) {
						$this->data['auction_bidder_text'] = '(' . $this->language->get('text_no_bid_yet') . ')';
					} elseif ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended']) {
						$this->data['auction_bidder_text'] = '(' . $this->language->get('text_by') . ' ' . $highest_bidder_masked . ')';
					} elseif ($auction['auction_status_id'] == $auction_status_ids['expired'] || $auction['auction_status_id'] == $auction_status_ids['voided']) {
						$this->data['auction_bidder_text'] = '(' . $this->language->get('text_no_winner') . ')';
					} elseif ($auction['auction_status_id'] == $auction_status_ids['won'] || $auction['auction_status_id'] == $auction_status_ids['sold']) {
						$this->data['auction_bidder_text'] = '(' . $this->language->get('text_congrats_to') . ' ' . $highest_bidder_masked . ')';
					} else {
						$this->data['auction_bidder_text'] = '';
					}
					// countdown timer display
					if ($auction['auction_status_id'] == $auction_status_ids['won'] || $auction['auction_status_id'] == $auction_status_ids['expired'] || $auction['auction_status_id'] == $auction_status_ids['sold'] || $auction['auction_status_id'] == $auction_status_ids['voided']) {
						$this->data['auction_countdown_text'] = '<font style="color: #FF0000;">' . $this->language->get('text_closed') . '</font>';
					} elseif ($auction['auction_status_id'] == $auction_status_ids['starting'] || $auction['auction_status_id'] == $auction_status_ids['relisting']) {
						$this->data['auction_countdown_text'] = '<font style="color: #FF0000;">' . $this->language->get('text_status_error') . '</font>';
					} else {
						$this->data['auction_countdown_text'] = '';
					}
					// time left display
					if ($auction['auction_status_id'] == $auction_status_ids['inprogress']) {
						$this->data['auction_timeleft_text'] = $this->language->get('text_time_left');
					} elseif ($auction['auction_status_id'] == $auction_status_ids['extended']) {
						$this->data['auction_timeleft_text'] = $this->language->get('text_time_extended');
					} elseif ($auction['auction_status_id'] == $auction_status_ids['expired']) {
						$this->data['auction_timeleft_text'] = $this->language->get('text_time_expired');
					} elseif ($auction['auction_status_id'] == $auction_status_ids['voided']) {
						$this->data['auction_timeleft_text'] = $this->language->get('text_time_voided');
					} elseif ($auction['buyout_made']) {
						$this->data['auction_timeleft_text'] = $this->language->get('text_time_buyout');
					} elseif ($auction['auction_status_id'] == $auction_status_ids['won'] || $auction['auction_status_id'] == $auction_status_ids['sold']) {
						$this->data['auction_timeleft_text'] = $this->language->get('text_time_won');
					} else {
						$this->data['auction_timeleft_text'] = '';
					}
					// load up auction details
					$this->data['auction'] = array(
						'auction_name'            => stripslashes($auction['auction_name']),
						'reserved_quantity'       => (int)$auction['reserved_quantity'],
						'starting_time_text'      => date($this->language->get('date_format_short') . ' ' . $this->language->get('time_format'), (int)$auction['starting_time']),
						'buyout_price'            => $this->currency->format((float)$auction['buyout_price'], '', '', false, 'up'),
						'min_increment'           => $this->currency->format((float)$auction['min_increment'], '', '', false, 'up'),
						'allow_auto_bid'          => (int)$auction['allow_auto_bid'],
						'allow_auto_extend'       => (int)$auction['allow_auto_extend'],
						'highest_bid_id'          => (int)$auction['highest_bid_id'],
						'current_bid_amount'      => $this->currency->format($current_bid_amount, '', '', false, 'up'),
						'current_bid_amount_text' => $this->currency->format($current_bid_amount, '', '', true, 'up'),
						'next_bid_amount'         => $this->currency->format($next_bid_amount, '', '', false, 'up'),
						'next_bid_amount_text'    => $this->currency->format($next_bid_amount, '', '', true, 'up'),
						'buyout_price_text'       => $this->currency->format((float)$auction['buyout_price'], '', '', true, 'up'),
						'total_no_of_bid'         => (int)$auction['total_no_of_bid'],
						'real_ending_time'        => (int)$auction['real_ending_time'],
						'real_ending_time_text'   => (int)$auction['buyout_made'] ? date($this->language->get('date_format_short') . ' ' . $this->language->get('time_format'), strtotime($auction['date_closed'])) : date($this->language->get('date_format_short') . ' ' . $this->language->get('time_format'), (int)$auction['real_ending_time'])
					);
					// load up customer auto-bid setting
					if ($this->customer->isLogged()) {
						if ((float)$auction['buyout_price'] > 0) {
							$max_bid_amount = (float)$auction['buyout_price'];
						} elseif ((float)$auction['reserve_price'] > 0) {
							$max_bid_amount = (float)$auction['reserve_price'];
						} else {
							$max_bid_amount = (float)(string)($next_bid_amount * 10);
						}
						$auction_bid_setting = $this->model_catalog_auction->getAuctionBidSettingByCustomerId($auction_id, $this->customer->getId());
						if ($auction_bid_setting) {
							if ((float)$auction_bid_setting['max_bid_amount'] > 0) {
								$max_bid_amount = (float)$auction_bid_setting['max_bid_amount'];
							}
							$this->data['bid_setting'] = array(
								'auction_bid_setting_id' => (int)$auction_bid_setting['auction_bid_setting_id'],
								'set_auto_bid'           => (int)$auction_bid_setting['set_auto_bid'],
								'persistent_bidding'     => (int)$auction_bid_setting['persistent_bidding']
							);
						}
						$this->data['max_bid_amount'] = $this->currency->format($max_bid_amount, '', '', false, 'up');
					}
				}
			}
			if ($total_auctions) {
				// load up auction price range
				$price_range = $this->model_catalog_auction->getAuctionsPriceRange($product_id, $auction_status_ids);
				if ($price_range) {
					if ((float)$price_range['high_bid'] > (float)$price_range['min_price']) {
						$this->data['min_price_text'] = $this->language->get('text_from') . ' ' . $this->currency->format((float)$price_range['high_bid'], '', '', true, 'up');
					} else {
						$this->data['min_price_text'] = $this->language->get('text_from') . ' ' . $this->currency->format((float)$price_range['min_price'], '', '', true, 'up');
					}
					if ((float)$price_range['max_buy'] > (float)$price_range['max_price']) {
						$this->data['max_price_text'] = $this->language->get('text_to') . ' ' . $this->currency->format((float)$price_range['max_buy'], '', '', true, 'up');
					} elseif ((float)$price_range['high_bid'] > (float)$price_range['max_price']) {
						$this->data['max_price_text'] = $this->language->get('text_to') . ' ' . $this->currency->format((float)$price_range['high_bid'], '', '', true, 'up');
					} elseif ((float)$price_range['max_price'] > (float)$price_range['min_price']) {
						$this->data['max_price_text'] = $this->language->get('text_to') . ' ' . $this->currency->format((float)$price_range['max_price'], '', '', true, 'up');
					} else {
						$this->data['max_price_text'] = '';
					}
					if ((float)$price_range['min_buy'] > 0) {
						$this->data['min_buy_text'] = $this->language->get('text_from') . ' ' . $this->currency->format((float)$price_range['min_buy'], '', '', true, 'up');
					} else {
						$this->data['min_buy_text'] = '';
					}
					if ((float)$price_range['max_buy'] > (float)$price_range['min_buy']) {
						$this->data['max_buy_text'] = $this->language->get('text_to') . ' ' . $this->currency->format((float)$price_range['max_buy'], '', '', true, 'up');
					} else {
						$this->data['max_buy_text'] = '';
					}
				} else {
					$this->data['min_price_text'] = '';
					$this->data['max_price_text'] = '';
					$this->data['min_buy_text'] = '';
					$this->data['max_buy_text'] = '';
				}
				// load up all auction ids including this auction
				$results = $this->model_catalog_auction->getLiveAuctionIdsByProductId($product_id, $auction_status_ids);
				foreach ($results as $result) {
					$this->data['auction_ids'][] = (int)$result['auction_id'];
				}
			}
		}
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/auction_info.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/product/auction_info.tpl';
		} else {
			$this->template = 'default/template/product/auction_info.tpl';
		}
		$this->response->setOutput($this->render());
	}

	public function history() {
		$this->language->load('product/auction');
		$this->load->model('catalog/auction');
		$this->data['column_bid_amount'] = $this->language->get('column_bid_amount');
		$this->data['column_bid_type'] = $this->language->get('column_bid_type');
		$this->data['column_bidder'] = $this->language->get('column_bidder');
		$this->data['column_bid_time'] = $this->language->get('column_bid_time');
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}
		if ($this->config->get('config_auction_bid_status_id') && is_array($this->config->get('config_auction_bid_status_id'))) {
			$auction_bid_status_ids = $this->config->get('config_auction_bid_status_id');
		} else {
			$auction_bid_status_ids = array('winning' => 1, 'outbid' => 2, 'buyout' => 3, 'voided' => 4);
		}
		$this->data['auction_bids'] = array();
		$results = $this->model_catalog_auction->getAuctionBids($this->request->get['auction_id'], ($page - 1) * 20, 20);
		foreach ($results as $result) {
			if ($result['auction_bid_status_id'] == $auction_bid_status_ids['voided']) {
				$bid_type = $this->language->get('text_bid_voided');
			} elseif ($result['auction_bid_status_id'] == $auction_bid_status_ids['buyout']) {
				$bid_type = $this->language->get('text_bid_buyout');
			} elseif ($result['auction_bid_status_id'] == $auction_bid_status_ids['winning']) {
				$bid_type = $this->language->get('text_bid_winning');
			} elseif ($result['is_auto_bid']) {
				$bid_type = $this->language->get('text_bid_auto');
			} else {
				$bid_type = $this->language->get('text_bid_manual');
			}
			$this->data['auction_bids'][] = array(
				'bid_amount_text' => $this->currency->format((float)$result['bid_amount'], '', '', true, 'up'),
				'bid_type'        => $bid_type,
				'bidder_masked'   => substr(preg_replace("/[^a-z0-9]/", '', strtolower(stripslashes($result['email']))), 0, 3) . 'xxxxxxx',
				'bid_time_text'   => date($this->language->get('date_format_short') . ' ' . $this->language->get('time_format'), (int)$result['bid_time'])
			);
		}
		$auction_bid_total = (int)$this->model_catalog_auction->getTotalAuctionBids($this->request->get['auction_id']);
		$pagination = new Pagination();
		$pagination->total = $auction_bid_total;
		$pagination->page = $page;
		$pagination->limit = 20;
		$pagination->text = $this->language->get('text_pagination');
		$pagination->url = $this->url->link('product/auction/history', 'auction_id=' . $this->request->get['auction_id'] . '&page={page}');
		$this->data['pagination'] = $pagination->render();
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/auction_history.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/product/auction_history.tpl';
		} else {
			$this->template = 'default/template/product/auction_history.tpl';
		}
		$this->response->setOutput($this->render());
	}

	public function live() {
		$this->language->load('product/auction');
		$this->load->model('catalog/auction');
		$this->data['button_quick_bid'] = $this->customer->isLogged() ? $this->language->get('button_quick_bid') : $this->language->get('button_login');
		$this->data['text_ended'] = $this->language->get('text_ended');
		if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
			$auction_status_ids = $this->config->get('config_auction_status_id');
		} else {
			$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
		}
		if (!is_null($this->config->get('config_auction_quick_bidding'))) {
			$quick_bidding = (int)$this->config->get('config_auction_quick_bidding');
		} else {
			$quick_bidding = 1;
		}
		$this->data['logged'] = (int)$this->customer->isLogged();
		$this->data['login_url'] = $this->url->link('account/login');
		$this->data['quick_bidding'] = $quick_bidding;
		$this->load->model('tool/image');
		$this->data['auctions_live'] = array();
		$results = $this->model_catalog_auction->getLiveAuctionsByProductId($this->request->get['product_id'], $auction_status_ids);
		foreach ($results as $result) {
			if ($result['product_image']) {
				$product_image = $this->model_tool_image->resize($result['product_image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
			} else {
				$product_image = $this->model_tool_image->resize('no_image.jpg', $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
			}
			//if (strlen(stripslashes($result['product_name'])) > 30) {
			//	$product_name = substr(stripslashes($result['product_name']), 0, 30) . ' ...';
			//} else {
				$product_name = stripslashes($result['product_name']);
			//}
			if (!$result['total_no_of_bid']) {
				$current_bid_amount = (float)$result['starting_price'];
				$next_bid_amount = (float)$result['starting_price'];
			} elseif ((float)$result['buyout_price'] > 0 && !$result['buyout_made'] && (float)(string)((float)$result['highest_bid_amount'] + (float)$result['min_increment']) > (float)$result['buyout_price']) {
				$current_bid_amount = (float)$result['highest_bid_amount'];
				$next_bid_amount = (float)$result['buyout_price'];
			} else {
				$current_bid_amount = (float)$result['highest_bid_amount'];
				$next_bid_amount = (float)(string)((float)$result['highest_bid_amount'] + (float)$result['min_increment']);
			}
			$this->data['auctions_live'][] = array(
				'product_image'           => $product_image,
				'product_name'            => $product_name,
				'auction_href'            => $this->url->link('product/product', 'product_id=' . $this->request->get['product_id'] . '&auction_id=' . $result['auction_id']),
				'auction_id'              => (int)$result['auction_id'],
				'auction_name'            => stripslashes($result['auction_name']),
				'reserved_quantity'       => (int)$result['reserved_quantity'],
				'buyout_price'            => $this->currency->format((float)$result['buyout_price'], '', '', false, 'up'),
				'min_increment'           => $this->currency->format((float)$result['min_increment'], '', '', false, 'up'),
				'highest_bid_id'          => (int)$result['highest_bid_id'],
				'highest_bidder_masked'   => (int)$result['highest_bidder_id'] ? substr(preg_replace("/[^a-z0-9]/", '', strtolower(stripslashes($result['customer_email']))), 0, 3) . 'xxxxxxx' : '---',
				'current_bid_amount'      => $this->currency->format((float)$current_bid_amount, '', '', false, 'up'),
				'current_bid_amount_text' => $this->currency->format((float)$current_bid_amount, '', '', true, 'up'),
				'next_bid_amount'         => $this->currency->format((float)$next_bid_amount, '', '', false, 'up'),
				'next_bid_amount_text'    => $this->currency->format((float)$next_bid_amount, '', '', true, 'up'),
				'real_ending_time'        => (int)$result['real_ending_time']
			);
		}
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/auction_live.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/product/auction_live.tpl';
		} else {
			$this->template = 'default/template/product/auction_live.tpl';
		}
		$this->response->setOutput($this->render());
	}

	public function auctionsaveautobidsetting() {
		$result = 0;
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
				$auction_status_ids = $this->config->get('config_auction_status_id');
			} else {
				$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
			}
			$customer_id = (int)$this->customer->getId();
			if ($customer_id) {
				if (isset($this->request->get['auction_id']) && isset($this->request->get['set_auto_bid']) && isset($this->request->get['max_bid_amount']) && isset($this->request->get['persistent_bidding'])) {
					$auction_id = (int)$this->request->get['auction_id'];
					$set_auto_bid = (int)$this->request->get['set_auto_bid'];
					if ($this->currency->getCode() != $this->config->get('config_currency')) {
						$max_bid_amount = (float)(string)$this->currency->convert((float)$this->request->get['max_bid_amount'], $this->currency->getCode(), $this->config->get('config_currency'));
					} else {
						$max_bid_amount = (float)$this->request->get['max_bid_amount'];
					}
					$persistent_bid = (int)$this->request->get['persistent_bidding'];
					$this->load->model('catalog/auction');
					$auction = $this->model_catalog_auction->getAuctionDetails($auction_id);
					if ($auction && $max_bid_amount > 0 && ($auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended']) && (int)$auction['real_ending_time'] >= time() && !$auction['buyout_made'] && !$auction['order_auction_id'] && (strtotime($auction['date_closed']) === false || strtotime($auction['date_closed']) <= 0) && $auction['allow_auto_bid']) {
						$bid_set_record = $this->model_catalog_auction->getAuctionBidSettingByCustomerId($auction_id, $customer_id);
						if ($bid_set_record) {
							$bid_setting_id = $bid_set_record['auction_bid_setting_id'];
						} else {
							$bid_setting_id = 0;
						}
						$this_set_id = (int)$this->model_catalog_auction->setAuctionBidSetting($bid_setting_id, $auction_id, $customer_id, $set_auto_bid, $max_bid_amount, $persistent_bid);
						if ($this_set_id) {
							$result = $this_set_id;	// save successful
						} else {
							$result = 0;		// save attempt failed
						}
					} else {
						$result = -1;		// setting not valid
					}
				} else {
					$result = -7;		// parameters not set
				}
			} else {
				$result = -8;		// not logged in
			}
		} else {
			$result = -9;		// server connection lost
		}
		$this->response->setOutput($result);
	}

	public function auctionplacebid($backdoor = false, $auth = '', $auction_id = 0, $bid_amount = 0, $is_auto_bid = 0, $customer_id_encrypted = '') {
		$result = 0;
		if ($backdoor && $auth && $auction_id && $bid_amount && $is_auto_bid && $customer_id_encrypted) {
			$this->request->get['auth'] = (string)$auth;
			$this->request->get['auction_id'] = (int)$auction_id;
			$this->request->get['bid_amount'] = (float)$bid_amount;
			$customer_id = (int)$this->encryption->decrypt((string)$customer_id_encrypted);
		} else {
			$customer_id = (int)$this->customer->getId();
		}
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
				$auction_status_ids = $this->config->get('config_auction_status_id');
			} else {
				$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
			}
			if ($this->config->get('config_auction_bid_status_id') && is_array($this->config->get('config_auction_bid_status_id'))) {
				$auction_bid_status_ids = $this->config->get('config_auction_bid_status_id');
			} else {
				$auction_bid_status_ids = array('winning' => 1, 'outbid' => 2, 'buyout' => 3, 'voided' => 4);
			}
			if ($customer_id) {
				if (isset($this->request->get['auction_id']) && isset($this->request->get['bid_amount'])) {
					$auction_id = (int)$this->request->get['auction_id'];
					if ($this->currency->getCode() != $this->config->get('config_currency')) {
						$bid_amount = (float)(string)$this->currency->convert((float)$this->request->get['bid_amount'], $this->currency->getCode(), $this->config->get('config_currency'));
					} else {
						$bid_amount = (float)$this->request->get['bid_amount'];
					}
					$bid_time = time();
					$this->load->model('catalog/auction');
					$auction = $this->model_catalog_auction->getAuctionDetails($auction_id);
					if ($auction) {
						// original settings
						$product_id = (int)$auction['product_id'];
						$reserved_quantity = (int)$auction['reserved_quantity'];
						$starting_price = (float)$auction['starting_price'];
						$reserve_price = (float)$auction['reserve_price'];
						$buyout_price = (float)$auction['buyout_price'];
						$min_increment = (float)$auction['min_increment'];
						$allow_auto_bid = (int)$auction['allow_auto_bid'];
						$fast_fwd_auto_bids = (int)$auction['fast_fwd_auto_bids'];
						$allow_auto_extend = (int)$auction['allow_auto_extend'];
						$extension_duration = (int)$auction['extension_duration'];
						$extension_window = (int)$auction['extension_window'];
						// dynamic details
						$highest_bidder_id = (int)$auction['highest_bidder_id'];
						$highest_bid_amount = (float)$auction['highest_bid_amount'];
						$total_no_of_bid = (int)$auction['total_no_of_bid'];
						$total_auto_bid = (int)$auction['total_auto_bid'];
						$reserve_met = (int)$auction['reserve_met'];
						$buyout_made = (int)$auction['buyout_made'];
						$real_ending_time = (int)$auction['real_ending_time'];
						$extension_count = (int)$auction['extension_count'];
						$auction_status_id = (int)$auction['auction_status_id'];
						$order_auction_id = (int)$auction['order_auction_id'];
						$date_closed = strtotime($auction['date_closed']);
						// adjusted settings
						if (!$total_no_of_bid) {
							$next_bid_amount = $starting_price;
						} elseif ($buyout_price > 0 && !$buyout_made && (float)(string)($highest_bid_amount + $min_increment) > $buyout_price) {
							$next_bid_amount = $buyout_price;
						} else {
							$next_bid_amount = (float)(string)($highest_bid_amount + $min_increment);
						}
						$auction_timeleft = (int)($real_ending_time - $bid_time);
						// pre-defining last few seconds to make a final bid
						$last_few_seconds = 3;
						if ($auction_status_id == $auction_status_ids['inprogress'] || $auction_status_id == $auction_status_ids['extended']) {
							// allow auto-bid final calls via back door even if auction already passed the current time (due to lag or cronjob under-run)
							if ($real_ending_time >= $bid_time || $is_auto_bid) {
								// allow self-overlapping in last few seconds on self-outbid if reserve not met yet or self-outbid by buying out
								if ($highest_bidder_id != $customer_id || ($reserve_price > 0 && !$reserve_met && $auction_timeleft < $last_few_seconds) || ($buyout_price > 0 && !$buyout_made && $bid_amount >= $buyout_price)) {
									if (!$order_auction_id && ($date_closed === false || $date_closed <= 0)) {
										if ($bid_amount >= $next_bid_amount) {
											if ($buyout_price > 0 && !$buyout_made && $bid_amount >= $buyout_price) {
												$auction_bid_status_id = $auction_bid_status_ids['buyout'];
												$bid_amount = $buyout_price;
												$new_buyout_made = 1;
											} else {
												$auction_bid_status_id = $auction_bid_status_ids['winning'];
												$new_buyout_made = $buyout_made;
											}
											if ($allow_auto_bid && $is_auto_bid) {
												$ip_address = '127.0.0.1';
											} elseif (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) {
												$ip_address = $this->request->server['HTTP_X_FORWARDED_FOR'];
											} elseif(!empty($this->request->server['HTTP_CLIENT_IP'])) {
												$ip_address = $this->request->server['HTTP_CLIENT_IP'];
											} else {
												$ip_address = $this->request->server['REMOTE_ADDR'];
											}
											$this_bid_id = (int)$this->model_catalog_auction->setAuctionNewBid($auction_id, $customer_id, $bid_amount, $bid_time, $is_auto_bid, $auction_bid_status_id, $ip_address);
											if ($this_bid_id) {
												$new_total_no_of_bid = (int)($total_no_of_bid + 1);
												if ($allow_auto_bid && $is_auto_bid) {
													$new_total_auto_bid = (int)($total_auto_bid + 1);
												} else {
													$new_total_auto_bid = $total_auto_bid;
												}
												if ($reserve_price > 0 && !$reserve_met && $bid_amount >= $reserve_price) {
													$new_reserve_met = 1;
												} else {
													$new_reserve_met = $reserve_met;
												}
												$min_extension_count = (int)floor((float)(string)((float)(string)($bid_amount - $next_bid_amount) / $min_increment));
												if ($allow_auto_extend && $allow_auto_bid && $fast_fwd_auto_bids && $total_auto_bid && $is_auto_bid && $min_extension_count && $auction_bid_status_id == $auction_bid_status_ids['winning']) {
													$new_real_ending_time = (int)($real_ending_time + ($extension_duration * $min_extension_count));
													$new_extension_count = (int)($extension_count + $min_extension_count);
												} elseif ($allow_auto_extend && $auction_timeleft < $extension_window && $auction_bid_status_id == $auction_bid_status_ids['winning']) {
													$new_real_ending_time = (int)($bid_time + $extension_duration);
													$new_extension_count = (int)($extension_count + 1);
												} else {
													$new_real_ending_time = $real_ending_time;
													$new_extension_count = $extension_count;
												}
												if ($auction_bid_status_id == $auction_bid_status_ids['buyout']) {
													$new_auction_status_id = (int)$auction_status_ids['won'];
													$new_date_closed = $bid_time;
													$this->addAuctionToCart($product_id, $reserved_quantity, $auction_id, $customer_id);
												} elseif ($new_extension_count) {
													$new_auction_status_id = (int)$auction_status_ids['extended'];
													$new_date_closed = $date_closed;
												} else {
													$new_auction_status_id = (int)$auction_status_ids['inprogress'];
													$new_date_closed = $date_closed;
												}
												$auction_updates = array(
													'highest_bid_id'     => $this_bid_id,
													'highest_bidder_id'  => $customer_id,
													'highest_bid_amount' => $bid_amount,
													'highest_bid_time'   => $bid_time,
													'total_no_of_bid'    => $new_total_no_of_bid,
													'total_auto_bid'     => $new_total_auto_bid,
													'reserve_met'        => $new_reserve_met,
													'buyout_made'        => $new_buyout_made,
													'real_ending_time'   => $new_real_ending_time,
													'extension_count'    => $new_extension_count,
													'auction_status_id'  => $new_auction_status_id,
													'date_closed'        => $new_date_closed
												);
												$this->model_catalog_auction->setAuctionUpdate($auction_id, $auction_updates);						// no tracking required
												$this->model_catalog_auction->setAuctionOutBid($auction_id, $bid_amount, $auction_bid_status_ids);	// no tracking required
												$result = $this_bid_id;	// bid successful id
											} else {
												$result = 0;		// bid attempt failed
											}
										} else {
											$result = -1;		// bid not enough
										}
									} else {
										$result = -2;		// auction data corrupted
									}
								} else {
									$result = -3;		// already highest bidder
								}
							} else {
								$result = -4;		// auction just ended
							}
						} else {
							$result = -5;		// auction not active
						}
					} else {
						$result = -6;		// auction not found
					}
				} else {
					$result = -7;		// parameters not set
				}
			} else {
				$result = -8;		// not logged in
			}
		} else {
			$result = -9;		// server connection lost
		}
		if ($backdoor) {
			return $result;
		} else {
			$this->response->setOutput($result);
		}
	}

	public function auctionglobalpoll() {
		$json = array();
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if (isset($this->request->get['auction_ids']) && isset($this->request->get['last_polled'])) {
				$auction_ids = explode(',', (string)$this->request->get['auction_ids']);
				foreach ($auction_ids as $auction_id) {
					$new_auction_ids[] = '\'' . $auction_id . '\'';		// addslashes to each id
				}
				$auction_ids = implode(',', $new_auction_ids);
				$last_polled = (int)$this->request->get['last_polled'];
				if ($last_polled < (int)(time() - 60)) {
					$last_polled = (int)(time() - 60);	// max 1min gap if javascript failed to set polling time properly
				}
				if (!empty($this->request->get['admin'])) {
					$currency_code = $this->config->get('config_currency');
					$rounding_code = '';
				} else {
					$currency_code = '';
					$rounding_code = 'up';
				}
				$this->load->model('catalog/auction');
				$auctions = $this->model_catalog_auction->getGlobalAuctionPoll($auction_ids, $last_polled);
				foreach ($auctions as $auction) {
					$json[] = array(
						'auction_id'            => (int)$auction['auction_id'],
						'highest_bid_id'        => (int)$auction['highest_bid_id'],
						'highest_bidder_id'     => (int)$auction['highest_bidder_id'],
						'highest_bidder_masked' => (int)$auction['highest_bidder_id'] ? substr(preg_replace("/[^a-z0-9]/", '', strtolower(stripslashes($auction['customer_email']))), 0, 3) . 'xxxxxxx' : '---',
						'highest_bidder_ip'     => stripslashes($auction['ip_address']),
						'highest_bid_amount'    => $this->currency->format((float)$auction['highest_bid_amount'], $currency_code, '', false, $rounding_code),
						'highest_bid_time'      => (int)$auction['highest_bid_time'],
						'total_no_of_bid'       => (int)$auction['total_no_of_bid'],
						'total_auto_bid'        => (int)$auction['total_auto_bid'],
						'reserve_met'           => (int)$auction['reserve_met'],
						'buyout_made'           => (int)$auction['buyout_made'],
						'real_ending_time'      => (int)$auction['real_ending_time'],
						'extension_count'       => (int)$auction['extension_count'],
						'auction_status_id'     => (int)$auction['auction_status_id']
					);
				}
			}
		}
		$this->response->setOutput(json_encode($json));
	}

	public function auctionglobalsendnotification() {
		$updates = 0;
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
				$auction_status_ids = $this->config->get('config_auction_status_id');
			} else {
				$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
			}
			if ($this->config->get('config_auction_payment_period')) {
				$payment_period = (int)$this->config->get('config_auction_payment_period');
			} else {
				$payment_period = 21;
			}
			if ($this->config->get('config_auction_notifications') && is_array($this->config->get('config_auction_notifications'))) {
				$auction_notifications = $this->config->get('config_auction_notifications');
			} else {
				$auction_notifications = array('1stbid', 'outbid', 'overrun', 'ending', 'extended', 'won', 'lost', 'expired', 'voided', 'payment');
			}
			$this->load->model('catalog/auction');
			// send out email notifications for 1st bid
			if (in_array('1stbid', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBidders1stBid();
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, '1stbid');
					$updates++;
				}
			}
			// send out email notifications for 1st out bid
			if (in_array('outbid', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersOutBid();
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'outbid');
					$updates++;
				}
			}
			// send out email notifications for auto-bids overrun
			if (in_array('overrun', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersOverrun();
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'overrun');
					$updates++;
				}
			}
			// send out email notifications for ending auctions in 5min
			if (in_array('ending', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersEnding();
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'ending');
					$updates++;
				}
			}
			// send out email notifications for extended auctions
			if (in_array('extended', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersExtended();
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'extended');
					$updates++;
				}
			}
			// send out email notifications for auction winners
			if (in_array('won', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersWon($auction_status_ids);
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'won');
					$updates++;
				}
			}
			// send out email notifications for auction losers
			if (in_array('lost', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersLost($auction_status_ids);
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'lost');
					$updates++;
				}
			}
			// send out email notifications for expired auctions
			if (in_array('expired', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersExpired($auction_status_ids);
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'expired');
					$updates++;
				}
			}
			// send out email notifications for voided auctions
			if (in_array('voided', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersVoided($auction_status_ids);
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'voided');
					$updates++;
				}
			}
			// send out email notifications for daily payment reminders on won-auctions
			if (in_array('payment', $auction_notifications)) {
				$notifications = $this->model_catalog_auction->getAuctionNotifyBiddersPayment($auction_status_ids, $payment_period);
				foreach ($notifications as $notification) {
					$auction_id = (int)$notification['auction_id'];
					$customer_id = (int)$notification['customer_id'];
					$notification_id = is_null($notification['auction_notification_id']) ? 0 : (int)$notification['auction_notification_id'];
					$this->model_catalog_auction->setGlobalAuctionNotifyBidders($auction_id, $customer_id, $notification_id, 'payment');
					$updates++;
				}
			}
		}
		$this->response->setOutput($updates);
	}

	public function auctionglobalvalidatewon() {
		$updates = 0;
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
				$auction_status_ids = $this->config->get('config_auction_status_id');
			} else {
				$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
			}
			if ($this->config->get('config_auction_bid_status_id') && is_array($this->config->get('config_auction_bid_status_id'))) {
				$auction_bid_status_ids = $this->config->get('config_auction_bid_status_id');
			} else {
				$auction_bid_status_ids = array('winning' => 1, 'outbid' => 2, 'buyout' => 3, 'voided' => 4);
			}
			if ($this->config->get('config_auction_payment_period')) {
				$payment_period = (int)$this->config->get('config_auction_payment_period');
			} else {
				$payment_period = 21;
			}
			if (!is_null($this->config->get('config_auction_auto_bidding'))) {
				$auto_bidding = (int)$this->config->get('config_auction_auto_bidding');
			} else {
				$auto_bidding = 1;
			}
			if (!is_null($this->config->get('config_auction_fast_auto_bids'))) {
				$fast_auto_bids = (int)$this->config->get('config_auction_fast_auto_bids');
			} else {
				$fast_auto_bids = 1;
			}
			if (!is_null($this->config->get('config_auction_auto_extension'))) {
				$auto_extension = (int)$this->config->get('config_auction_auto_extension');
			} else {
				$auto_extension = 1;
			}
			if ($this->config->get('config_auction_ext_duration')) {
				$ext_duration = (int)$this->config->get('config_auction_ext_duration');
			} else {
				$ext_duration = 15;
			}
			if ($this->config->get('config_auction_ext_window')) {
				$ext_window = (int)$this->config->get('config_auction_ext_window');
			} else {
				$ext_window = 60;
			}
			if (!is_null($this->config->get('config_auction_auto_relisting'))) {
				$auto_relisting = (int)$this->config->get('config_auction_auto_relisting');
			} else {
				$auto_relisting = 1;
			}
			if ($this->config->get('config_auction_relist_window')) {
				$relist_window = (int)$this->config->get('config_auction_relist_window');
			} else {
				$relist_window = 1;
			}
			if ($this->config->get('config_auction_relist_max')) {
				$relist_max = (int)$this->config->get('config_auction_relist_max');
			} else {
				$relist_max = 3;
			}
			$this->load->model('catalog/auction');
			$auctions = $this->model_catalog_auction->getWonAuctionIds($auction_status_ids);
			foreach ($auctions as $auction) {
				$auction_ended = $this->model_catalog_auction->getAuctionDetails($auction['auction_id']);
				if ($auction_ended) {
					$update_required = 0;
					$validate_updates = array();
					// original settings
					$product_id = (int)$auction_ended['product_id'];
					$product_auction_id = (int)$auction_ended['product_auction_id'];
					$auction_id = (int)$auction_ended['auction_id'];
					$reserved_quantity = (int)$auction_ended['reserved_quantity'];
					$starting_time = (int)$auction_ended['starting_time'];
					$ending_time = (int)$auction_ended['ending_time'];
					$starting_price = (float)$auction_ended['starting_price'];
					$reserve_price = (float)$auction_ended['reserve_price'];
					$buyout_price = (float)$auction_ended['buyout_price'];
					$min_increment = (float)$auction_ended['min_increment'];
					$allow_auto_bid = (int)$auction_ended['allow_auto_bid'];
					// dynamic details
					$highest_bid_id = (int)$auction_ended['highest_bid_id'];
					$highest_bidder_id = (int)$auction_ended['highest_bidder_id'];
					$highest_bid_amount = (float)$auction_ended['highest_bid_amount'];
					$highest_bid_time = (int)$auction_ended['highest_bid_time'];
					$total_no_of_bid = (int)$auction_ended['total_no_of_bid'];
					$reserve_met = (int)$auction_ended['reserve_met'];
					$buyout_made = (int)$auction_ended['buyout_made'];
					$real_ending_time = (int)$auction_ended['real_ending_time'];
					$relisting_count = (int)$auction_ended['relisting_count'];
					$auction_status_id = (int)$auction_ended['auction_status_id'];
					$order_auction_id = (int)$auction_ended['order_auction_id'];
					$date_closed = strtotime($auction_ended['date_closed']);
					$payment_due_limit = (int)($date_closed + ($payment_period * 24 * 60 * 60));
					if ($payment_due_limit < time() && $highest_bid_id && $highest_bidder_id && $highest_bid_amount > 0 && $highest_bid_time && $total_no_of_bid && (!$reserve_price || ($reserve_price > 0 && $reserve_met) || ($buyout_price > 0 && $buyout_made)) && !$order_auction_id && $date_closed && $date_closed > 0 && $auction_status_id != $auction_status_ids['voided']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['voided'];
						$validate_updates['auction_status_id'] = $auction_status_id;		// voided
						if ($auto_relisting && $relisting_count < $relist_max) {
							$auction_original_properties = array(
								'product_id'         => $product_id,
								'product_auction_id' => $product_auction_id,
								'reserved_quantity'  => $reserved_quantity,
								'starting_time'      => (int)(time() + ($relist_window * 60 * 60)),
								'ending_time'        => (int)(time() + ($relist_window * 60 * 60) + ($ending_time - $starting_time)),
								'starting_price'     => $starting_price,
								'reserve_price'      => $reserve_price,
								'buyout_price'       => $buyout_price,
								'min_increment'      => $min_increment,
								'allow_auto_bid'     => (int)($allow_auto_bid * $auto_bidding),
								'fast_fwd_auto_bids' => (int)($allow_auto_bid * $auto_bidding * $fast_auto_bids),
								'allow_auto_extend'  => $auto_extension,
								'extension_duration' => $ext_duration,
								'extension_window'   => $ext_window,
								'relisting_count'    => (int)($relisting_count + 1),
								'auction_status_id'  => (int)$auction_status_ids['relisting']
							);
							$this->model_catalog_auction->setAuctionInsert($auction_original_properties);				// trigger auto-relist
						} else {
							$this->model_catalog_auction->setAuctionReturnQuantity($product_id, $reserved_quantity);	// trigger return quantity to product stock
						}
						$this->model_catalog_auction->setAuctionVoidedBid($auction_id, $auction_bid_status_ids);		// trigger void winning-bid
						$this->removeAuctionFromCart($product_id, $auction_id, $highest_bidder_id);
					}
					if (($payment_due_limit < time() || $payment_due_limit >= time()) && $highest_bid_id && $highest_bidder_id && $highest_bid_amount > 0 && $highest_bid_time && $total_no_of_bid && (!$reserve_price || ($reserve_price > 0 && $reserve_met) || ($buyout_price > 0 && $buyout_made)) && $order_auction_id && $date_closed && $date_closed > 0 && $auction_status_id != $auction_status_ids['sold']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['sold'];
						$validate_updates['auction_status_id'] = $auction_status_id;		// sold, include late payment if undetected by system earlier (very low chance for this to happen if this cron runs every minute)
						$this->removeAuctionFromCart($product_id, $auction_id, $highest_bidder_id);
					}
					if ($payment_due_limit >= time() && $highest_bid_id && $highest_bidder_id && $highest_bid_amount > 0 && $highest_bid_time && $total_no_of_bid && (!$reserve_price || ($reserve_price > 0 && $reserve_met) || ($buyout_price > 0 && $buyout_made)) && !$order_auction_id && $date_closed && $date_closed > 0 && $auction_status_id != $auction_status_ids['sold'] && $auction_status_id != $auction_status_ids['voided']) {
						$this->addAuctionToCart($product_id, $reserved_quantity, $auction_id, $highest_bidder_id);		// persistent inclusion of won-auctions in customer cart
					}
					if ($update_required) {
						$this->model_catalog_auction->setAuctionUpdate($auction_id, $validate_updates);
						$updates++;
					}
				}
			}
		}
		$this->response->setOutput($updates);
	}

	public function auctionglobalvalidateintegrity() {
		$updates = 0;
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
				$auction_status_ids = $this->config->get('config_auction_status_id');
			} else {
				$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
			}
			if ($this->config->get('config_auction_bid_status_id') && is_array($this->config->get('config_auction_bid_status_id'))) {
				$auction_bid_status_ids = $this->config->get('config_auction_bid_status_id');
			} else {
				$auction_bid_status_ids = array('winning' => 1, 'outbid' => 2, 'buyout' => 3, 'voided' => 4);
			}
			$this->load->model('catalog/auction');
			$auctions = $this->model_catalog_auction->getActiveAuctionIds($auction_status_ids);
			foreach ($auctions as $auction) {
				$auction_live = $this->model_catalog_auction->getAuctionDetails($auction['auction_id']);
				if ($auction_live) {
					$update_required = 0;
					$validate_updates = array();
					// original settings
					$auction_id = (int)$auction_live['auction_id'];
					$ending_time = (int)$auction_live['ending_time'];
					$reserve_price = (float)$auction_live['reserve_price'];
					$buyout_price = (float)$auction_live['buyout_price'];
					$allow_auto_bid = (int)$auction_live['allow_auto_bid'];
					$allow_auto_extend = (int)$auction_live['allow_auto_extend'];
					$extension_duration = (int)$auction_live['extension_duration'];
					// dynamic details
					$highest_bid_id = (int)$auction_live['highest_bid_id'];
					$highest_bidder_id = (int)$auction_live['highest_bidder_id'];
					$highest_bid_amount = (float)$auction_live['highest_bid_amount'];
					$highest_bid_time = (int)$auction_live['highest_bid_time'];
					$total_no_of_bid = (int)$auction_live['total_no_of_bid'];
					$total_auto_bid = (int)$auction_live['total_auto_bid'];
					$reserve_met = (int)$auction_live['reserve_met'];
					$buyout_made = (int)$auction_live['buyout_made'];
					$real_ending_time = (int)$auction_live['real_ending_time'];
					$extension_count = (int)$auction_live['extension_count'];
					// discrepancy checks
					$total_bids = (int)$this->model_catalog_auction->getTotalAuctionBids($auction_id);
					if ($total_bids) {
						// check total number of bids
						$bids_total_count = (int)$total_bids;
						if ($bids_total_count != $total_no_of_bid) {
							$update_required++;
							$validate_updates['total_no_of_bid'] = $bids_total_count;
						}
					}
					// discrepancy checks
					$auto_bids = (int)$this->model_catalog_auction->getTotalAuctionAutoBids($auction_id);
					if ($allow_auto_bid && $auto_bids) {
						// check number of auto bids
						$bids_auto_count = (int)$auto_bids;
						if ($bids_auto_count != $total_auto_bid) {
							$update_required++;
							$validate_updates['total_auto_bid'] = $bids_auto_count;
						}
					}
					// discrepancy checks
					$top_bid = $this->model_catalog_auction->getTopAuctionBidDetails($auction_id);
					if ($top_bid) {
						// check highest bid id
						$top_bid_bid_id = (int)$top_bid['auction_bid_id'];
						if ($top_bid_bid_id != $highest_bid_id) {
							$update_required++;
							$validate_updates['highest_bid_id'] = $top_bid_bid_id;
						}
						// check highest bidder
						$top_bid_bidder_id = (int)$top_bid['customer_id'];
						if ($top_bid_bidder_id != $highest_bidder_id) {
							$update_required++;
							$validate_updates['highest_bidder_id'] = $top_bid_bidder_id;
						}
						// check highest bid amount
						$top_bid_amount = (float)$top_bid['bid_amount'];
						if ($top_bid_amount != $highest_bid_amount) {
							$update_required++;
							$validate_updates['highest_bid_amount'] = $top_bid_amount;
						}
						// check highest bid time
						$top_bid_time = (int)$top_bid['bid_time'];
						if ($top_bid_time != $highest_bid_time) {
							$update_required++;
							$validate_updates['highest_bid_time'] = $top_bid_time;
						}
						// check reserve price met
						if ($reserve_price > 0 && !$reserve_met && $top_bid_amount >= $reserve_price) {
							$update_required++;
							$validate_updates['reserve_met'] = 1;
						}
						// check buyout made (1-way validation only)
						$top_bid_status_id = (int)$top_bid['auction_bid_status_id'];
						if ($buyout_price > 0 && !$buyout_made && $top_bid_amount >= $buyout_price && $top_bid_status_id == $auction_bid_status_ids['buyout']) {
							$update_required++;
							$validate_updates['highest_bid_amount'] = $buyout_price;
							$validate_updates['buyout_made'] = 1;
						}
						// check real ending time
						$top_bid_time_extended = (int)($top_bid_time + $extension_duration);
						if ($allow_auto_extend && $top_bid_time_extended > $real_ending_time) {
							$update_required++;
							$validate_updates['real_ending_time'] = $top_bid_time_extended;
						}
						// check extension count
						$total_extended_time = (int)($real_ending_time - $ending_time);
						$min_extension_count = (int)floor((float)(string)($total_extended_time / $extension_duration));
						if ($allow_auto_extend && $min_extension_count > $extension_count) {
							$update_required++;
							$validate_updates['extension_count'] = $min_extension_count;
						}
					}
					if ($update_required) {
						$this->model_catalog_auction->setAuctionUpdate($auction_id, $validate_updates);
						$updates++;
					}
				}
			}
		}
		$this->response->setOutput($updates);
	}

	public function auctionglobalvalidateactive() {
		$updates = 0;
		if (isset($this->request->get['auth']) && $this->checkAuthTimeTokenSHA1($this->request->get['auth']) === true) {
			if ($this->config->get('config_auction_status_id') && is_array($this->config->get('config_auction_status_id'))) {
				$auction_status_ids = $this->config->get('config_auction_status_id');
			} else {
				$auction_status_ids = array('starting' => 1, 'relisting' => 2, 'inprogress' => 3, 'extended' => 4, 'won' => 5, 'expired' => 6, 'sold' => 7, 'voided' => 8);
			}
			if ($this->config->get('config_auction_bid_status_id') && is_array($this->config->get('config_auction_bid_status_id'))) {
				$auction_bid_status_ids = $this->config->get('config_auction_bid_status_id');
			} else {
				$auction_bid_status_ids = array('winning' => 1, 'outbid' => 2, 'buyout' => 3, 'voided' => 4);
			}
			if (!is_null($this->config->get('config_auction_auto_bidding'))) {
				$auto_bidding = (int)$this->config->get('config_auction_auto_bidding');
			} else {
				$auto_bidding = 1;
			}
			if (!is_null($this->config->get('config_auction_fast_auto_bids'))) {
				$fast_auto_bids = (int)$this->config->get('config_auction_fast_auto_bids');
			} else {
				$fast_auto_bids = 1;
			}
			if (!is_null($this->config->get('config_auction_auto_extension'))) {
				$auto_extension = (int)$this->config->get('config_auction_auto_extension');
			} else {
				$auto_extension = 1;
			}
			if ($this->config->get('config_auction_ext_duration')) {
				$ext_duration = (int)$this->config->get('config_auction_ext_duration');
			} else {
				$ext_duration = 15;
			}
			if ($this->config->get('config_auction_ext_window')) {
				$ext_window = (int)$this->config->get('config_auction_ext_window');
			} else {
				$ext_window = 60;
			}
			if (!is_null($this->config->get('config_auction_auto_relisting'))) {
				$auto_relisting = (int)$this->config->get('config_auction_auto_relisting');
			} else {
				$auto_relisting = 1;
			}
			if ($this->config->get('config_auction_relist_window')) {
				$relist_window = (int)$this->config->get('config_auction_relist_window');
			} else {
				$relist_window = 1;
			}
			if ($this->config->get('config_auction_relist_max')) {
				$relist_max = (int)$this->config->get('config_auction_relist_max');
			} else {
				$relist_max = 3;
			}
			$this->load->model('catalog/auction');
			if (isset($this->request->get['auction_id'])) {
				$auction_id = (int)$this->request->get['auction_id'];
				$auctions = $this->model_catalog_auction->getActiveAuctionId($auction_id, $auction_status_ids);
			} elseif (isset($this->request->get['product_id'])) {
				$product_id = (int)$this->request->get['product_id'];
				$auctions = $this->model_catalog_auction->getActiveAuctionIdsByProductId($product_id, $auction_status_ids);
			} else {
				$auctions = $this->model_catalog_auction->getActiveAuctionIds($auction_status_ids);
			}
			foreach ($auctions as $auction) {
				$auction_live = $this->model_catalog_auction->getAuctionDetails($auction['auction_id']);
				if ($auction_live) {
					$update_required = 0;
					$validate_updates = array();
					// original settings
					$product_id = (int)$auction_live['product_id'];
					$auction_id = (int)$auction_live['auction_id'];
					$product_auction_id = (int)$auction_live['product_auction_id'];
					$reserved_quantity = (int)$auction_live['reserved_quantity'];
					$starting_time = (int)$auction_live['starting_time'];
					$ending_time = (int)$auction_live['ending_time'];
					$starting_price = (float)$auction_live['starting_price'];
					$reserve_price = (float)$auction_live['reserve_price'];
					$buyout_price = (float)$auction_live['buyout_price'];
					$min_increment = (float)$auction_live['min_increment'];
					$allow_auto_bid = (int)$auction_live['allow_auto_bid'];
					$fast_fwd_auto_bids = (int)$auction_live['fast_fwd_auto_bids'];
					$allow_auto_extend = (int)$auction_live['allow_auto_extend'];
					// dynamic details
					$highest_bid_id = (int)$auction_live['highest_bid_id'];
					$highest_bidder_id = (int)$auction_live['highest_bidder_id'];
					$highest_bid_amount = (float)$auction_live['highest_bid_amount'];
					$highest_bid_time = (int)$auction_live['highest_bid_time'];
					$total_no_of_bid = (int)$auction_live['total_no_of_bid'];
					$reserve_met = (int)$auction_live['reserve_met'];
					$buyout_made = (int)$auction_live['buyout_made'];
					$real_ending_time = (int)$auction_live['real_ending_time'];
					$extension_count = (int)$auction_live['extension_count'];
					$relisting_count = (int)$auction_live['relisting_count'];
					$auction_status_id = (int)$auction_live['auction_status_id'];
					$order_auction_id = (int)$auction_live['order_auction_id'];
					$date_closed = strtotime($auction_live['date_closed']);
					$skip_status_update = 0;
					// auto-bid runner
					if (!$total_no_of_bid) {
						$next_bid_amount = $starting_price;
					} elseif ($buyout_price > 0 && !$buyout_made && (float)(string)($highest_bid_amount + $min_increment) > $buyout_price) {
						$next_bid_amount = $buyout_price;
					} else {
						$next_bid_amount = (float)(string)($highest_bid_amount + $min_increment);
					}
					if ($allow_auto_bid) {
						$auto_bid_settings = $this->model_catalog_auction->getAuctionAutoBidSettings($auction_id, $next_bid_amount);
						// allow final calls from auto-bids even if auction already passed the current time (due to lag or cronjob under-run)
						if ($auto_bid_settings && !$buyout_made && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && ($auction_status_id == $auction_status_ids['inprogress'] || $auction_status_id == $auction_status_ids['extended'])) {
							// sort auto-bidding into random order
							shuffle($auto_bid_settings);
							$auto_bids = $auto_bid_settings;
							$auction_timeleft = (int)($real_ending_time - time());
							$current_bidder_id = $highest_bidder_id;
							// pre-defining last few seconds to make a final bid
							$last_few_seconds = 3;
							// staggered bidding time over last 10 seconds for non-persistent auto-bidders
							$last_ten_seconds = (int)rand($last_few_seconds, 10);
							if ($fast_fwd_auto_bids && count($auto_bid_settings) > 1) {
								$persistent_bidders = 0;
								$top_persistent_bid1 = 0;
								$top_persistent_bid2 = 0;
								$top_persistent_bidder_id = 0;
								foreach ($auto_bid_settings as $auto_bid_setting) {
									if ($auto_bid_setting['persistent_bidding'] || $auction_timeleft <= $last_ten_seconds) {
										if ((float)$auto_bid_setting['max_bid_amount'] > $top_persistent_bid1) {
											if (!$top_persistent_bid2) {
												$top_persistent_bid2 = $next_bid_amount;
											} else {
												$top_persistent_bid2 = $top_persistent_bid1;
											}
											$top_persistent_bid1 = (float)$auto_bid_setting['max_bid_amount'];
											$top_persistent_bidder_id = (int)$auto_bid_setting['customer_id'];
										} elseif ((float)$auto_bid_setting['max_bid_amount'] > $top_persistent_bid2) {
											$top_persistent_bid2 = (float)$auto_bid_setting['max_bid_amount'];
										}
										$persistent_bidders++;
									}
								}
								if ($persistent_bidders > 1 && $top_persistent_bid2 > $next_bid_amount) {
									// predicting fast forward auto bidding outcome
									$final_persistent_bid = (float)(string)($top_persistent_bid2 + $min_increment);
									if ($final_persistent_bid > $top_persistent_bid1) {
										$final_persistent_bid = $top_persistent_bid1;
									}
									if ($final_persistent_bid >= (float)(string)($next_bid_amount + (float)(string)($min_increment * $persistent_bidders))) {
										$auto_bids[] = array(
											'customer_id'        => $top_persistent_bidder_id,
											'max_bid_amount'     => $final_persistent_bid,
											'persistent_bidding' => 2
										);
									}
								}
							}
							foreach ($auto_bids as $auto_bid) {
								$auto_bidder_id = (int)$auto_bid['customer_id'];
								$auto_bid_amount = (float)$auto_bid['max_bid_amount'];
								$persistent_bidding = (int)$auto_bid['persistent_bidding'];
								// last 10 seconds can be considered as persistent bidding, last few seconds can self-outbid if reserve not met yet or self-outbid by buying out
								if (($persistent_bidding || $auction_timeleft <= $last_ten_seconds) && $auto_bid_amount >= $next_bid_amount && ($auto_bidder_id != $current_bidder_id || ($reserve_price > 0 && !$reserve_met && $auction_timeleft < $last_few_seconds) || ($buyout_price > 0 && !$buyout_made && $next_bid_amount >= $buyout_price))) {
									if ($reserve_price > 0 && !$reserve_met && $auto_bid_amount >= $reserve_price && $auction_timeleft < $last_few_seconds) {
										$next_bid_amount = $reserve_price;			// match the reserve price for a last second push
									} elseif ($reserve_price > 0 && !$reserve_met && $auto_bid_amount < $reserve_price && $auction_timeleft < $last_few_seconds) {
										$next_bid_amount = $auto_bid_amount;		// dump the maximum amount for a last second push, although it won't win
									} elseif ($fast_fwd_auto_bids && $persistent_bidding == 2) {
										$next_bid_amount = $auto_bid_amount;		// skip to fast forward auto bid end result
									}
									$result = (int)$this->auctionplacebid(true, (string)sha1(time()), (int)$auction_id, (float)$next_bid_amount, 1, (string)$this->encryption->encrypt((string)$auto_bidder_id));
									if ($result > 0) {
										$highest_bid_id = $result;
										$highest_bidder_id = $auto_bidder_id;
										$highest_bid_amount = $next_bid_amount;
										$highest_bid_time = time();
										$total_no_of_bid++;
										if ($real_ending_time < time()) {
											$skip_status_update = 1;
										}
										if ($reserve_price > 0 && $next_bid_amount >= $reserve_price) {
											$reserve_met = 1;
										}
										if ($buyout_price > 0 && $next_bid_amount >= $buyout_price) {
											$buyout_made = 1;
											break;
										} else {
											$next_bid_amount = (float)(string)($next_bid_amount + $min_increment);
											$current_bidder_id = $auto_bidder_id;
										}
									}
								}
							}
						}
					}
					// skip auto-status changer if there are changes made by auto-bid runner, allowing cronjob to check for updated auction details at next cycle
					if ($skip_status_update) {
						continue;
					}
					// auto-status changer
					if ($real_ending_time < time() && (!$highest_bid_id || !$highest_bidder_id || !$highest_bid_amount || !$highest_bid_time || !$total_no_of_bid || ($reserve_price > 0 && !$reserve_met)) && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && $auction_status_id != $auction_status_ids['expired']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['expired'];
						$date_closed = time();
						$validate_updates['auction_status_id'] = $auction_status_id;		// expired
						$validate_updates['date_closed'] = $date_closed;
						if ($auto_relisting && $relisting_count < $relist_max) {
							$auction_original_properties = array(
								'product_id'         => $product_id,
								'product_auction_id' => $product_auction_id,
								'reserved_quantity'  => $reserved_quantity,
								'starting_time'      => (int)(time() + ($relist_window * 60 * 60)),
								'ending_time'        => (int)(time() + ($relist_window * 60 * 60) + ($ending_time - $starting_time)),
								'starting_price'     => $starting_price,
								'reserve_price'      => $reserve_price,
								'buyout_price'       => $buyout_price,
								'min_increment'      => $min_increment,
								'allow_auto_bid'     => (int)($allow_auto_bid * $auto_bidding),
								'fast_fwd_auto_bids' => (int)($allow_auto_bid * $auto_bidding * $fast_auto_bids),
								'allow_auto_extend'  => $auto_extension,
								'extension_duration' => $ext_duration,
								'extension_window'   => $ext_window,
								'relisting_count'    => (int)($relisting_count + 1),
								'auction_status_id'  => (int)$auction_status_ids['relisting']
							);
							$this->model_catalog_auction->setAuctionInsert($auction_original_properties);				// trigger auto-relist
						} else {
							$this->model_catalog_auction->setAuctionReturnQuantity($product_id, $reserved_quantity);	// trigger return quantity to product stock
						}
						$this->model_catalog_auction->setAuctionVoidedBid($auction_id, $auction_bid_status_ids);		// trigger void winning-bid
					}
					if ($real_ending_time < time() && $highest_bid_id && $highest_bidder_id && $highest_bid_amount > 0 && $highest_bid_time && $total_no_of_bid && (!$reserve_price || ($reserve_price > 0 && $reserve_met) || ($buyout_price > 0 && $buyout_made)) && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && $auction_status_id != $auction_status_ids['won']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['won'];
						$date_closed = time();
						$validate_updates['auction_status_id'] = $auction_status_id;		// won
						$validate_updates['date_closed'] = $date_closed;
						$this->addAuctionToCart($product_id, $reserved_quantity, $auction_id, $highest_bidder_id);
					}
					if ($real_ending_time >= time() && $ending_time < time() && $highest_bid_id && $highest_bidder_id && $highest_bid_amount > 0 && $highest_bid_time && $total_no_of_bid && $allow_auto_extend && $extension_count && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && $auction_status_id != $auction_status_ids['extended']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['extended'];
						$validate_updates['auction_status_id'] = $auction_status_id;		// extended
					}
					if ($real_ending_time >= time() && $starting_time <= time() && !$extension_count && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && $auction_status_id != $auction_status_ids['inprogress']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['inprogress'];
						$validate_updates['auction_status_id'] = $auction_status_id;		// in-progress
					}
					if ($real_ending_time > time() && $starting_time > time() && $relisting_count && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && $auction_status_id != $auction_status_ids['relisting']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['relisting'];
						$validate_updates['auction_status_id'] = $auction_status_id;		// relisting
					}
					if ($real_ending_time > time() && $starting_time > time() && !$relisting_count && !$order_auction_id && ($date_closed === false || $date_closed <= 0) && $auction_status_id != $auction_status_ids['starting']) {
						$update_required++;
						$auction_status_id = (int)$auction_status_ids['starting'];
						$validate_updates['auction_status_id'] = $auction_status_id;		// starting
					}
					if ($update_required) {
						$this->model_catalog_auction->setAuctionUpdate($auction_id, $validate_updates);
						$updates++;
					}
				}
			}
		}
		$this->response->setOutput($updates);
	}

	protected function checkAuthTimeTokenSHA1($auth) {
		$success = false;
		$latency_min = -10;
		$latency_max = 10;
		for ($a = 0; $a <= $latency_max; $a++) {
			if ($auth == sha1(time() + $a)) {
				$success = true;
				break;
			}
		}
		for ($a = -1; $a >= $latency_min; $a--) {
			if ($auth == sha1(time() + $a)) {
				$success = true;
				break;
			}
		}
		return $success;
	}

	protected function addAuctionToCart($product_id, $r_quantity, $auction_id, $customer_id) {
		if ($product_id && $r_quantity && $auction_id && $customer_id) {
			$this->load->model('catalog/auction');
			$order_auction_id = (int)$this->model_catalog_auction->getAuctionOrderId($auction_id);
			if (!$order_auction_id) {
				$session_customer_id = (int)$this->customer->getId();
				if ($session_customer_id && $session_customer_id == $customer_id) {
					$this->cart->add($product_id, $r_quantity, $auction_id);
				} else {
					$customer_record = $this->model_catalog_auction->getCustomerCartDetails($customer_id);
					if ($customer_record) {
						$cart = $customer_record['cart'];
						$cart_arr = array();
						if (is_string($cart)) {
							$cart_arr = unserialize($cart);
						}
						if (is_array($cart_arr)) {
							foreach ($cart_arr as $key => $quantity) {
								$key_arr = explode(':', $key);
								if (!empty($key_arr[1]) && is_int(unserialize(base64_decode($key_arr[1]))) && !is_array(unserialize(base64_decode($key_arr[1])))) {
									$cart_product_id = (int)$key_arr[0];
									$cart_auction_id = (int)unserialize(base64_decode($key_arr[1]));
									if ($cart_product_id == $product_id && $cart_auction_id == $auction_id) {
										return;
									}
								}
							}
						}
						$product_auction_key = $product_id . ':' . base64_encode(serialize($auction_id));
						$cart_arr[$product_auction_key] = (int)$r_quantity;
						$this->model_catalog_auction->setCustomerCartDetails($customer_id, $cart_arr);
					}
				}
			}
		}
	}

	protected function removeAuctionFromCart($product_id, $auction_id, $customer_id) {
		if ($product_id && $auction_id && $customer_id) {
			$this->load->model('catalog/auction');
			$order_auction_id = (int)$this->model_catalog_auction->getAuctionOrderId($auction_id);
			if (!$order_auction_id) {
				$session_customer_id = (int)$this->customer->getId();
				if ($session_customer_id && $session_customer_id == $customer_id) {
					$product_auction_key = $product_id . ':' . base64_encode(serialize($auction_id));
					$this->cart->remove($product_auction_key);
				} else {
					$customer_record = $this->model_catalog_auction->getCustomerCartDetails($customer_id);
					if ($customer_record) {
						$cart = $customer_record['cart'];
						$cart_arr = array();
						if (is_string($cart)) {
							$cart_arr = unserialize($cart);
						}
						if (is_array($cart_arr)) {
							foreach ($cart_arr as $key => $quantity) {
								$key_arr = explode(':', $key);
								if (!empty($key_arr[1]) && is_int(unserialize(base64_decode($key_arr[1]))) && !is_array(unserialize(base64_decode($key_arr[1])))) {
									$cart_product_id = (int)$key_arr[0];
									$cart_auction_id = (int)unserialize(base64_decode($key_arr[1]));
									if ($cart_product_id == $product_id && $cart_auction_id == $auction_id) {
										unset($cart_arr[$key]);
									}
								}
							}
						}
						$this->model_catalog_auction->setCustomerCartDetails($customer_id, $cart_arr);
					}
				}
			}
		}
	}
}
?>