<?php 
class Modelinformationmyown extends Model {
	public function addCustomer($data) {
		$customer_id = $this->customer->getId();
      	$this->db->query("INSERT INTO " . DB_PREFIX . "contest_master SET store_id = '" . (int)$this->config->get('config_store_id') . "',description = '" . $this->db->escape($data['describe']) . "', customer_id = '" . $customer_id . "', special_ocassion = '" . $this->db->escape($data['ocassion']) . "', design_category = '" . $this->db->escape($data['design_category']) . "', masculine_feminine = '" . $this->db->escape($data['masculine_feminine']). "',youthful_mature = '" . $this->db->escape($data['youthful_mature']). "',funky_graceful = '" . $this->db->escape($data['funky_graceful']). "',bold_subtle = '" . $this->db->escape($data['bold_subtle']). "',simple_intricate = '" . $this->db->escape($data['simple_intricate']). "',classic_contemporary = '" . $this->db->escape($data['classic_contemporary']). "',image = '" . $this->db->escape($data['image1']). "', status = 1 ,creation_date = NOW()");	
		
		$contest_master = $this->db->getLastId();
		
		if (isset($data['themeee'])) {
			foreach ($data['themeee'] as $store_id) {
				$this->db->query("INSERT INTO " . DB_PREFIX . "contest_theme SET customer_id = '" . $customer_id . "', theme = '" . (int)$store_id . "',contest_id = '" . (int)$contest_master . "'");
			}
		}

 
		 return $contest_master;
	}
	
	public function getInformations() {
		$query = $this->db->query("select a.title,a.description from information_description a where a.information_id=13");
		
		return $query->rows;
	} 
	
	public function get_image_pics() {
		$query = $this->db->query("select image,contest_sample_designs_id,theme from contest_sample_designs");
		
		return $query->rows;
	} 
	
	public function getoccasionsdes() {
		$query = $this->db->query("select occasionmaster_id, description from occasion_master");
		
		return $query->rows;
	} 
	
	public function get_design_category() {
		$query = $this->db->query("select DISTINCT(design_category),contest_sample_designs_id from contest_sample_designs GROUP BY design_category");
		
		return $query->rows;
	} 
	
	public function getoccasions($data = array()) {
	//	$sql = "SELECT * FROM " . DB_PREFIX . "occassion_master";
		$sql = "SELECT * FROM `occasion_master`";
		
		$sql .= " ORDER BY description";	
			
		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 getcontests () {
		
			$sql = "select ca.currency_code,ca.contest_id,ca.customer_id,ca.name as description,ca.prize_amount,ca.status from contest_master ca  ORDER BY ca.contest_id DESC ";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
	}
	public function getcustomercontests () {
		
			$sql = "select ca.currency_code,ca.contest_id,ca.customer_id,ca.name as description,ca.prize_amount,ca.status from contest_master ca where ca.customer_id = " . $this->customer->islogged() . " ORDER BY ca.contest_id DESC ";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
	}
	public function getactivecontests () {
		
			$sql = "select ca.currency_code,ca.contest_id,ca.customer_id,ca.name as description,ca.prize_amount,ca.status from contest_master ca where ca.status=2 ORDER BY ca.contest_id DESC";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
	public function getmycontests () {
		
			$sql = "select DISTINCT(ca.contest_id),ca.customer_id,ca.name as description,ca.prize_amount,ca.currency_code,ca.status from contest_master ca,sketches_master sm,contest_sketch_assignment cs where ca.contest_id = cs.contest_id AND sm.sketch_id = cs.sketch_id AND ca.status=2 AND sm.designer_id='" . $this->designer->getId() . "' ORDER BY cs.sketch_assignment_id DESC";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
	public function getmycredits () {
		
			$sql = "select * from designer_rewards_distribution dd,rewards r,`order` o,order_product op where r.reward_id=dd.reward_id and o.order_id=r.order_id and o.order_id=op.order_id and r.product_id=op.product_id and dd.customer_designer_id='" . $this->designer->getId() . "' ORDER BY dd.designer_reward_distribution_id DESC";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
	
	public function getprivatemessages ($data = array()) {
	
			$designers = $this->designer->getId();
		
			$sql = "select * from private_messages where from_id='".$designers ."' and is_customer=1  order by creation_date_time desc";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
	
	public function get_customer_privatemessages ($data = array()) {
	
			$customer =  $this->customer->getId();
		
			$sql = "select * from private_messages where from_id= '".$customer."'  order by creation_date_time desc";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
	
	public function getinboxmessages ($data = array()) {
		
			$designers = $this->designer->getId();
		
			$sql = "select * from private_messages where is_customer=0 and to_id= '".$designers ."' order by creation_date_time desc";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
	
	public function get_customer_inboxmessages ($data = array()) {
		
			$customer =  $this->customer->getId();
		
			$sql = "select * from private_messages where to_id='".$customer."'  order by creation_date_time desc";	

			$query = $this->db->query($sql);
		
			return $query->rows;	
		}
		
	public function getcustomername_design($from_id) {
		$query = $this->db->query("select CONCAT(d.firstname,'',d.lastname) as name from customer d , private_messages pm where d.customer_id= '" . (int)$from_id . "'  order by creation_date_time desc");
		
		return $query->row['name']; 
	}
		
	public function getdesignername_customer($from_id) {
		$query = $this->db->query("select CONCAT(d.firstname,'',d.lastname) as name from designer d , private_messages pm where d.designer_id= '" . (int)$from_id . "'  order by creation_date_time desc");
		
		return $query->row['name']; 
	} 
		
	public function getcustomeremail($customer_id) {
		$query = $this->db->query("select email from customer   where customer_id= '" . (int)$customer_id . "'");
		
		return $query->row['email']; 
	} 
		
	public function getcustomername_customer($from_id) {
		$query = $this->db->query("select CONCAT(d.firstname,'',d.lastname) as name from customer d , private_messages pm where d.customer_id= '" . (int)$from_id . "'");
		
		return $query->row['name']; 
	} 
		
	public function getdesignername_design($from_id) {
		$query = $this->db->query("select CONCAT(d.firstname,'',d.lastname) as name from designer d , private_messages pm where d.designer_id= '" . (int)$from_id . "'");
		
		return $query->row['name']; 
	} 
		
	public function get_private_message_details($pm_id) {
		$query = $this->db->query("select body from private_messages where private_messages_id= '" . (int)$pm_id . "'");
		
		return $query->row['body']; 
	} 	
		
	public function getconteststatus($status) {
		$query = $this->db->query("SELECT description FROM " . DB_PREFIX . "`contest_status_master`  WHERE contest_status_master_id = '" . (int)$status . "'");
	
		if (isset($query->row['description']))
		{
		return $query->row['description'];
		}
	}
	
	public function getcontestentry($contest_id) {
		$query = $this->db->query("SELECT COUNT(contest_id) as total FROM " . DB_PREFIX . "`contest_sketch_assignment`  WHERE contest_id = '" . (int)$contest_id . "'");
	
		if (isset($query->row['total']))
		{
		return $query->row['total'];
		}
	}
	public function getcontestfeedback($contest_id) {
		$query = $this->db->query("SELECT COUNT(sc.sketch_comments_id) as total FROM " . DB_PREFIX . "`contest_sketch_assignment` csa," . DB_PREFIX . "`sketch_comments` sc  WHERE csa.sketch_assignment_id = sc.sketch_assignment_id AND csa.contest_id = '" . (int)$contest_id . "' AND sc.is_customer = '1'");
	
		if (isset($query->row['total']))
		{
		return $query->row['total'];
		}
	}
	
	public function getSizeByCountry($country) {
	//$ring_data = $this->cache->get('ring_size');
		
		//if (!$ring_data) {
			$query = $this->db->query("SELECT DISTINCT ring_size FROM " . DB_PREFIX . "ring_size WHERE country = '" . $country . "' AND status = 'Enabled' ORDER BY ring_size");
	
			//$ring_data = $query->rows;
			return $query->rows;
		
			//$this->cache->set('ring_size', $ring_data);
		//}

	//	return $ring_data;
	
	}
	public function getRingsizes() {
		
			$query = $this->db->query("SELECT DISTINCT country,ring_size FROM " . DB_PREFIX . "ring_size WHERE  status = 'Enabled' ORDER BY country,ring_size");
	
			return $query->rows;
		
			
	
	}
	
	public function getCountries() {
		//$count_data = $this->cache->get('countryname');
		
		//if (!$count_data) {
			$query = $this->db->query("SELECT DISTINCT country FROM " . DB_PREFIX . "ring_size WHERE status = 'Enabled' ORDER BY country ASC");
	
		//	$count_data = $query->rows;
			return $query->rows;
		
		//	$this->cache->set('countryname', $count_data);
		//}

		//return $count_data;
	
	}
	
	}
	
	?>