<?php
class ModelSaleGemstone extends Model {
	public function addCustomerGroup($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "shape SET shape = '" . $this->db->escape($data['shape']) . "',description = '" . $this->db->escape($data['description']) . "', image = '" . $this->db->escape($data['image']) . "', shape1 = '" . $this->db->escape($data['shape1']) . "',shape2 = '" . $this->db->escape($data['shape2']) . "',enable = '" . $this->db->escape($data['enable']) . "'");
	}
	
	public function editCustomerGroup($shape_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "shape SET shape = '" . $this->db->escape($data['shape']) . "', image = '" . $this->db->escape($data['image']) . "', enable = '" . $this->db->escape($data['enable']) . "',description = '" . $this->db->escape($data['description']) . "', shape1 = '" . $this->db->escape($data['shape1']) . "',shape2 = '" . $this->db->escape($data['shape2']) . "' WHERE shape_id = '" . (int)$shape_id . "'");
	}
	
	public function deleteCustomerGroup($shape_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "shape WHERE shape_id = '" . (int)$shape_id . "'");
	//	$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE shape_id = '" . (int)$shape_id . "'");
	}
	
	public function getCustomerGroup($shape_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "shape WHERE shape_id = '" . (int)$shape_id . "'");
		
		return $query->row;
	}
	
	public function getSizebyName($data = array()) {
		$sql = "SELECT size_id,size_code FROM " . DB_PREFIX . "size";
		
		$sql .= " ORDER BY size_code";	
			
		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 getCustomerGroups($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "shape"; 
		
		$sql .= " ORDER BY shape";	
			
		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 getTotalCustomerGroups() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "shape");
		
		return $query->row['total'];
	}
}
?>