<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class Mod_partnership extends CI_Model
	{
		var $table = "tbl_partnership";
		function __construct()
		{
			parent::__construct();
		}	
		
		function getPartnership ()
		{
			$this->db->SELECT("*,`tbl_partnership`.`createddate` as `mydate`");
			$this->db->from($this->table);
			$this->db->join("tbluser","tbluser.userid = tbl_partnership.createdby","left");		
			$this->db->order_by("tbl_partnership.par_id", "DESC"); 
			return $this->db->get();
		}

		function countAll()
		{
			return $this->db->count_all_results('tbl_partnership');
		}

		function add($data)
		{
			$this->db->insert($this->table,$data);	
		}
		
		function add_user($data)
		{
			$this->db->insert('tbl_partnership_user',$data);	
		}
		
		function update_user($data,$id)
		{
			$this->db->where("id",$id);
			$this->db->update('tbl_partnership_user',$data);
		}
		
		function reset_password($id,$password){
			$data = array('password'=>$password,'temp_passwd'=>1);
			$this->db->where("id",$id);
			$this->db->update('tbl_partnership_user',$data);
		}
		
		function delete_user($id)
		{
			$data = array('status'=>0);
			$this->db->where("id",$id);
			$this->db->update('tbl_partnership_user',$data);
			//$this->db->delete('tbl_partnership_user');
		}
		
		function update($data,$id)
		{
			$this->db->where("par_id",$id);
			$this->db->update($this->table,$data);
		}

		function delete($id)
		{
			$this->db->where("par_id",$id);
			$this->db->delete($this->table);
		}
	
		function getById($id)
		{
			$this->db->where("par_id",$id);
			$q = $this->db->get($this->table);
			if($q->num_rows() > 0)
			{
				return $q->row();
			}
			return false;
		}
		
	}