<?php
///////////////////////////////////////////////////////////////////
//	Copyright: Mintegra.com
//	Product: Ebay Auction Lister 2.0
//	Distributors: www.mintegra.com
//	Support: http://www.mintgera.com/support
///////////////////////////////////////////////////////////////////
class ModelEbayAuction extends Model {
	public function addAuction($data) {
		//$this->db->query("INSERT INTO `" . DB_PREFIX . "auction` SET title = '" . $this->db->escape($data['auction_title']) . "', subtitle = '" . $this->db->escape($data['auction_subtitle']) . "', image= '" . $this->db->escape($data['auction_image']) . "', description= '" . $this->db->escape($data['auction_description']) . "', quantity ='" . (int)$this->db->escape($data['auction_quantity']) . "', duration='" . $this->db->escape($data['auction_duration']) . "', buyitnowprice= '"  . (float)$this->db->escape($data['auction_buyitnowprice']) . "', auctiontype = '" . $this->db->escape($data['auction_type']) . "', startprice='" . (float)$this->db->escape($data['auction_startprice']) . "', immediatepayment='" . (int)$this->db->escape($data['auction_immediatepayment']) . "', category= '" . (int)$this->db->escape($data['auction_category']) . "', galleryplus= '" . (int)$this->db->escape($data['auction_galleryplus']) . "', boldtitle = '" . (int)$this->db->escape($data['auction_boldtitle']) . "', includesubtitle = '" . (int)$this->db->escape($data['auction_includesubtitle']) . "', shippingtype = '" . $this->db->escape($data['auction_shipping']) . "', service1='" . $this->db->escape($data['auction_service1']) . "', cost1 ='" . (float)$this->db->escape($data['auction_service1cost']) . "', additionalcost1 ='" . (float)$this->db->escape($data['auction_service1addcost']) . "', service2='" . $this->db->escape($data['auction_service2']) . "', cost2 ='" . (float)$this->db->escape($data['auction_service2cost']) . "', additionalcost2 ='" . (float)$this->db->escape($data['auction_service2addcost']) . "', service3='" . $this->db->escape($data['auction_service3']) . "', cost3 ='" . (float)$this->db->escape($data['auction_service3cost']) . "', additionalcost3 ='" . (float)$this->db->escape($data['auction_service3addcost']) . "', packagetype='" . $this->db->escape($data['auction_packagetype']) . "', irregular='" . (int)$this->db->escape($data['auction_irregular']) . "', length='"  . (float)$this->db->escape($data['length']) . "', height='"  . (float)$this->db->escape($data['height']) . "', width='"  . (float)$this->db->escape($data['width']) . "', weight='"  . (float)$this->db->escape($data['weight']) . "', freeshipping='"  . (int)$this->db->escape($data['auction_freeshipping']) . "', localpickup='"  . (int)$this->db->escape($data['auction_localpickup']) . "', handlingtime='"  . $this->db->escape($data['auction_handlingtime']) . "'");
		$this->db->query("INSERT INTO `" . DB_PREFIX . "auction` SET title = '" . $this->db->escape($data['auction_title']) .  "'");
			
		$auction_id = $this->db->getLastId();
		
		if (isset($data['product_id'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET product_id = '" . (int)$this->db->escape($data['product_id']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		if (isset($data['auction_title'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET title = '" . $this->db->escape($data['auction_title']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_title'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET subtitle = '" . $this->db->escape($data['auction_subtitle']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_image'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET image = '" . $this->db->escape($data['auction_image']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}		
		 
		if (isset($data['auction_description'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET description = '" . $this->db->escape($data['auction_description']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_quantity'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET quantity = '" . (int)$this->db->escape($data['auction_quantity']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_duration'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET duration = '" . $this->db->escape($data['auction_duration']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_buyitnowprice'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET buyitnowprice = '" . (float)$this->db->escape($data['auction_buyitnowprice']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
 
		if (isset($data['auction_type'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET auctiontype = '" . $this->db->escape($data['auction_type']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_startprice'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET startprice = '" . (float)$this->db->escape($data['auction_startprice']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	

		if (isset($data['auction_immediatepayment'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET immediatepayment = '" . $this->db->escape($data['auction_immediatepayment']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_category'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET category = '" . (int)$this->db->escape($data['auction_category']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	

		if (isset($data['auction_galleryplus'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET galleryplus = '" . $this->db->escape($data['auction_galleryplus']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}			

		if (isset($data['auction_boldtitle'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET boldtitle = '" . $this->db->escape($data['auction_boldtitle']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_includesubtitle'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET includesubtitle  = '" . $this->db->escape($data['auction_includesubtitle']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	

		if (isset($data['auction_shipping'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET shippingtype  = '" . $this->db->escape($data['auction_shipping']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}			

		if (isset($data['auction_service1'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET service1  = '" . $this->db->escape($data['auction_service1']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_service1cost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET cost1 = '" . (float)$this->db->escape($data['auction_service1cost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_service1addcost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET additionalcost1 = '" . (float)$this->db->escape($data['auction_service1addcost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}		

		if (isset($data['auction_service2'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET service2  = '" . $this->db->escape($data['auction_service2']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_service1cost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET cost2 = '" . (float)$this->db->escape($data['auction_service2cost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_service2addcost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET additionalcost2 = '" . (float)$this->db->escape($data['auction_service2addcost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_service3'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET service3  = '" . $this->db->escape($data['auction_service3']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_service1cost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET cost3 = '" . (float)$this->db->escape($data['auction_service3cost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_service2addcost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET additionalcost3 = '" . (float)$this->db->escape($data['auction_service3addcost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_packagetype'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET packagetype = '" . $this->db->escape($data['auction_packagetype']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_irregular'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET irregular = '" . $this->db->escape($data['auction_irregular']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['length'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET length = '" . (float)$this->db->escape($data['length']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['height'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET height = '" . (float)$this->db->escape($data['height']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['width'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET width = '" . (float)$this->db->escape($data['width']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['weight'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET weight = '" . (float)$this->db->escape($data['weight']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_freeshipping'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET freeshipping = '" . $this->db->escape($data['auction_freeshipping']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_localpickup'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET localpickup = '" . $this->db->escape($data['auction_localpickup']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}		

		if (isset($data['auction_handlingtime'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET handlingtime = '" . $this->db->escape($data['auction_handlingtime']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_condition'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET itemcondition = '" . $this->db->escape($data['auction_condition']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_returns'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET returns = '" . $this->db->escape($data['auction_returns']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
	}
	
	public function editAuction($data,$auction_id) {
		
		//$this->db->query("UPDATE `" . DB_PREFIX . "auction` SET title = '" . $this->db->escape($data['auction_title']) . "', subtitle = '" . $this->db->escape($data['auction_subtitle']) . "', image= '" . $this->db->escape($data['auction_image']) . "', description= '" . $this->db->escape($data['auction_description']) . "', quantity ='" . (int)$this->db->escape($data['auction_quantity']) . "', duration='" . $this->db->escape($data['auction_duration']) . "', buyitnowprice= '"  . (float)$this->db->escape($data['auction_buyitnowprice']) . "', auctiontype = '" . $this->db->escape($data['auction_type']) . "', startprice='" . (float)$this->db->escape($data['auction_startprice']) . "', immediatepayment='" . (int)$this->db->escape($data['auction_immediatepayment']) . "', category= '" . (int)$this->db->escape($data['auction_category']) . "', galleryplus= '" . (int)$this->db->escape($data['auction_galleryplus']) . "', boldtitle = '" . (int)$this->db->escape($data['auction_boldtitle']) . "', includesubtitle = '" . (int)$this->db->escape($data['auction_includesubtitle']) . "', shippingtype = '" . $this->db->escape($data['auction_shipping']) . "', service1='" . $this->db->escape($data['auction_service1']) . "', cost1 ='" . (float)$this->db->escape($data['auction_service1cost']) . "', additionalcost1 ='" . (float)$this->db->escape($data['auction_service1addcost']) . "', service2='" . $this->db->escape($data['auction_service2']) . "', cost2 ='" . (float)$this->db->escape($data['auction_service2cost']) . "', additionalcost2 ='" . (float)$this->db->escape($data['auction_service2addcost']) . "', service3='" . $this->db->escape($data['auction_service3']) . "', cost3 ='" . (float)$this->db->escape($data['auction_service3cost']) . "', additionalcost3 ='" . (float)$this->db->escape($data['auction_service3addcost']) . "', packagetype='" . $this->db->escape($data['auction_packagetype']) . "', irregular='" . (int)$this->db->escape($data['auction_irregular']) . "', length='"  . (float)$this->db->escape($data['length']) . "', height='"  . (float)$this->db->escape($data['height']) . "', width='"  . (float)$this->db->escape($data['width']) . "', weight='"  . (float)$this->db->escape($data['weight']) . "', freeshipping='"  . (int)$this->db->escape($data['auction_freeshipping']) . "', localpickup='"  . (int)$this->db->escape($data['auction_localpickup']) . "', handlingtime='"  . $this->db->escape($data['auction_handlingtime']) . "' WHERE auction_id = " . $auction_id);
		if (isset($data['auction_title'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET title = '" . $this->db->escape($data['auction_title']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_title'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET subtitle = '" . $this->db->escape($data['auction_subtitle']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_image'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET image = '" . $this->db->escape($data['auction_image']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}		
		 
		if (isset($data['auction_description'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET description = '" . $this->db->escape($data['auction_description']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_quantity'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET quantity = '" . (int)$this->db->escape($data['auction_quantity']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_duration'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET duration = '" . $this->db->escape($data['auction_duration']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_buyitnowprice'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET buyitnowprice = '" . (float)$this->db->escape($data['auction_buyitnowprice']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
 
		if (isset($data['auction_type'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET auctiontype = '" . $this->db->escape($data['auction_type']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_startprice'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET startprice = '" . (float)$this->db->escape($data['auction_startprice']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	

		if (isset($data['auction_immediatepayment'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET immediatepayment = '" . $this->db->escape($data['auction_immediatepayment']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_category'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET category = '" . (int)$this->db->escape($data['auction_category']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	

		if (isset($data['auction_galleryplus'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET galleryplus = '" . $this->db->escape($data['auction_galleryplus']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}			

		if (isset($data['auction_boldtitle'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET boldtitle = '" . $this->db->escape($data['auction_boldtitle']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_includesubtitle'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET includesubtitle  = '" . $this->db->escape($data['auction_includesubtitle']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	

		if (isset($data['auction_shipping'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET shippingtype  = '" . $this->db->escape($data['auction_shipping']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}			

		if (isset($data['auction_service1'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET service1  = '" . $this->db->escape($data['auction_service1']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_service1cost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET cost1 = '" . (float)$this->db->escape($data['auction_service1cost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_service1addcost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET additionalcost1 = '" . (float)$this->db->escape($data['auction_service1addcost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}		

		if (isset($data['auction_service2'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET service2  = '" . $this->db->escape($data['auction_service2']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_service1cost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET cost2 = '" . (float)$this->db->escape($data['auction_service2cost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_service2addcost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET additionalcost2 = '" . (float)$this->db->escape($data['auction_service2addcost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_service3'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET service3  = '" . $this->db->escape($data['auction_service3']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
		
		if (isset($data['auction_service1cost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET cost3 = '" . (float)$this->db->escape($data['auction_service3cost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}

		if (isset($data['auction_service2addcost'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET additionalcost3 = '" . (float)$this->db->escape($data['auction_service3addcost']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_packagetype'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET packagetype = '" . $this->db->escape($data['auction_packagetype']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_irregular'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET irregular = '" . $this->db->escape($data['auction_irregular']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['length'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET length = '" . (float)$this->db->escape($data['length']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['height'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET height = '" . (float)$this->db->escape($data['height']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['width'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET width = '" . (float)$this->db->escape($data['width']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['weight'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET weight = '" . (float)$this->db->escape($data['weight']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_freeshipping'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET freeshipping = '" . $this->db->escape($data['auction_freeshipping']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_localpickup'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET localpickup = '" . $this->db->escape($data['auction_localpickup']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}		

		if (isset($data['auction_handlingtime'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET handlingtime = '" . (int)$this->db->escape($data['auction_handlingtime']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_condition'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET itemcondition = '" . $this->db->escape($data['auction_condition']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}
		
		if (isset($data['auction_returns'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "auction SET returns = '" . $this->db->escape($data['auction_returns']) . "' WHERE auction_id = '" . (int)$auction_id . "'");
		}	
	
	}

	public function deleteAuction($auction_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "auction WHERE auction_id = '" . (int)$auction_id . "'");
		$this->cache->delete('auction');
	}
	public function getAuctions($data = array()){

		$sql ="SELECT auction_id,title,auctiontype,categoryname category FROM " . DB_PREFIX . "auction" . " LEFT OUTER JOIN ". DB_PREFIX. "ebay_category ON " . DB_PREFIX . "auction.category = " . DB_PREFIX . "ebay_category.categoryid";
		
		$sort_data = array(
			'title',
			'auctiontype',
			'category'
		);	
			
		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort'];	
		} else {
			$sql .= " ORDER BY title";	
		}
			
		if (isset($data['order']) && ($data['order'] == 'DESC')) {
			$sql .= " DESC";
		} else {
			$sql .= " ASC";
		}
		
		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}			
			
			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}	
			
			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}
			
		$query = $this->db->query($sql);
	
		return $query->rows;
	}	
	
	public function getTotalAuctions() {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "auction`");
		
		return $query->row['total'];
	}
	
	public function getAuction($auction_id) {
		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "auction` WHERE auction_id = '" . (int)$auction_id . "'");
	
		return $query->row;
	}
	
	public function addSpecifics($data,$auction_id) {
	
		$this->db->query("DELETE FROM " . DB_PREFIX . "ebay_specifics WHERE auction_id = '" . (int)$auction_id . "'");
		$total_specifics = (int) $this->db->escape($data['total_specifics']);
		for($i=0; $i < $total_specifics ;$i++){
			$spec_name = "specific_name_" . $i;
			$spec_value = "specific_value_" . $i;
			$this->log->write(addslashes($data[$spec_value]) );
			$this->db->query("INSERT INTO `" . DB_PREFIX . "ebay_specifics` SET auction_id = " . (int) $auction_id .  ",seq_id =" . $i . ",spec_name ='" .$this->db->escape($data[$spec_name]) . "',spec_value = '" . $this->db->escape($data[$spec_value]) . "'");
		}
	
	}
	
	public function getSpecifics($auction_id){
		$sql ="SELECT *  FROM " . DB_PREFIX . "ebay_specifics" . " WHERE auction_id = '" . (int)$auction_id . "' ORDER BY seq_id ASC";
		
		$query = $this->db->query($sql);
	
		return $query->rows;
	}	


}
?>