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

class User_model extends CI_Model
{

	public function save_post_record()
	{

		$fname= (string)$this->input->post('fname');
		$mname= (string)$this->input->post('mname');
		$lname= (string)$this->input->post('lname');
		$username= (string)$this->input->post('username');
		$password= (string)$this->input->post('password');
		$password= md5($password);

		$data = array(
			'fname'=>$fname,
			'mname'=>$mname,
			'lname'=>$lname,
			'username'=>$username,
			'password'=>$password,
			'role'=> USER_ROLE_VISITOR
		);

		$response = $this->db->insert('users',$data);

		if( $response)
		{
			return $this->db->insert_id();
		}
		else 
		{
			return FALSE;
		}
	}

	public function get_profile_information($id)
	{
		$this->db->where('user', $id);
		$query = $this->db->get('users');
		$row = $query->row();

		if($row)
		{
			$row->personal_information = $this->get_personal_information($id);
			$row->payment_information = $this->get_payment_information($id);
		}

		return $row;
	}

	public function get_personal_information($id)
	{
		$this->db->where('user', $id);
		$query = $this->db->get('personal_information');
		$row = $query->row();

		return $row;
	}
	public function get_payment_information($id)
	{
		$this->db->where('user', $id);
		$query = $this->db->get('payment');
		$row = $query->row();

		return $row;
	}

	
}