<?php
class ModelAffiliateSetting extends Model {
	public function getSetting($group) {
		$data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE AND `group` = '" . $this->db->escape($group) . "'");

		foreach ($query->rows as $result) {
			$data[$result['key']] = $result['value'];
		}

		return $data;
	}
	public function getAffiliateGroups($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "affiliate_group";
		
		$sql .= " ORDER BY name";	
			
		$query = $this->db->query($sql);
		
		return $query->rows;
	}

		
	public function getaffiliateDt($affiliateid){				        
                $rewarddt = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
                $affiliateid=$_SERVER['SERVER_NAME'].'HCETMS';
                $rewarddetail = array("1", "3", "5", "7", "9", "2", "4", "6", "8", "0");
                $healthy  = str_replace($rewarddt, $rewarddetail, $affiliateid);	
		return $healthy;
	}
	
	public function getaffiliateDetail($affiliateid){
		return $this->config->get('config_affiliate_data');
	}
	
	public function editSetting($group, $data) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "setting WHERE `group` = '" . $this->db->escape($group) . "'");

		foreach ($data as $key => $value) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET `group` = '" . $this->db->escape($group) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
		}
	}

	public function deleteSetting($group) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "setting WHERE `group` = '" . $this->db->escape($group) . "'");
	}
}
?>