<?php
class ModelExtensionModuleContactPerson extends Model {
	public function addPerson($data) {
		$sql = "INSERT INTO " . DB_PREFIX . "contact_person(name, position,introduction,qq ,alww,email,tele, gplus,wgdqq ,wgdalww,wgdtele, wgdgplus, image) VALUES ('" . $data['name'] . "', '" . $data['position'] . "', '" . $data['introduction'] . "','" . $data['qq'] . "','" . $data['wgdqq'] . "','" . $data['alww'] . "','" . $data['wgdalww'] . "','" . $data['email'] . "', '" . $data['tele'] . "','" . $data['wgdtele'] . "', '" . $data['gplus'] . "', '" . $data['wgdgplus'] . "', '" . $data['image'] . "')";
		$this->db->query($sql);
	}

	public function editPerson($person_id, $data) {
		$sql = "UPDATE " . DB_PREFIX . "contact_person SET
				name = '" . $data['name'] . "',
				position = '" . $data['position'] . "',
				introduction = '" . $data['introduction'] . "',
				qq = '" . $data['qq'] . "',
				alww = '" . $data['alww'] . "',
				email = '" . $data['email'] . "',
				tele = '" . $data['tele'] . "',
				gplus = '" . $data['gplus'] . "',
				wgdqq = '" . $data['wgdqq'] . "',
				wgdalww = '" . $data['wgdalww'] . "',
				wgdtele = '" . $data['wgdtele'] . "',
				wgdgplus = '" . $data['wgdgplus'] . "',
				image = '" . $data['image'] . "' WHERE contact_person_id = '" . $person_id . "'";
		$this->db->query($sql);
	}
	
	public function deletePerson($person_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "contact_person WHERE contact_person_id = " . (int)$person_id);
	}
	
	public function getPerson($person_id) {
		$query = $this->db->query("SELECT contact_person_id AS id, name, position, introduction, qq, alww, email, tele, gplus,wgdqq, wgdalww ,wgdtele, wgdgplus, image  FROM " . DB_PREFIX . "contact_person WHERE contact_person_id = " . (int)$person_id);
		
		return $query->row;
	}
	
	public function getPersons() {
		$querycheckenabled = $this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "contact_person'");

		if($querycheckenabled->num_rows){
			$query = $this->db->query("SELECT contact_person_id AS id, name, position, introduction, qq, alww, email, tele, gplus, wgdqq, wgdalww, wgdtele, wgdgplus,image FROM " . DB_PREFIX . "contact_person");
		return $query->rows;
		}else 
			return NULL;
	}
	
	public function getTotalPersons() {
		$querycheckenabled = $this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "contact_person'");

		if($querycheckenabled->num_rows){
			$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "contact_person");
		
			return $query->row['total'];
		}else 
			return NULL;
	}	
}
?>