<?php

/**
 * @author Jilani jidni
 *
 */

class Contact_Profile_model extends CI_Model {

	public function __construct()
	{
		parent::__construct();
	}

	function getContactProfile($admin_user_id)
	{
		$this->db->select('*');
		$this->db->from('tbl_admin_user');
		$this->db->where('admin_user_id',$admin_user_id);
		$resultSet = $this->db->get();
		return $resultSet->row_array();
	}

	function updateContactProfile($contact_data)
	{
		$this->db->where('admin_user_id',$contact_data['admin_user_id']);
		$this->db->update('tbl_admin_user',$contact_data);
	}

	function getSuperAdminContactDetails()
	{
		$contact_profile = $this->getContactProfile(1);

		$footerText = $contact_profile['first_name'].' '.$contact_profile['last_name'].'<br/>';
		$footerText .= $contact_profile['company_name'].'<br/>';
		$footerText .= $contact_profile['contact_phone'].'<br/>';
		$footerText .= $contact_profile['address'].'<br/>';
		$footerText .= $contact_profile['city'].'<br/>';

        $footerText .= getStateFullName($contact_profile['state']).'<br/>';
		$footerText .= getCountryFullName($contact_profile['country']).'<br/>';
		$footerText .= $contact_profile['website'];

		$contact_details['full_name'] = $contact_profile['first_name'].' '.$contact_profile['last_name'];
		$contact_details['email_address'] = $contact_profile['email_address'];
		$contact_details['footer_text'] = $footerText;

		return $contact_details;
	}

	function checkExists($data)
	{
		$this->db->select('*');
		$this->db->from('tbl_admin_user');
		$this->db->where('user_name',$data['user_name']);
		$this->db->where('admin_user_id',$data['admin_user_id']);

		$res = $this->db->get();
		$result = $res->row();
		$admin_password = $result->user_pwd;

		if($admin_password == md5($data['current_password']))
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}

	function changePassword($data)
	{
		$this->db->set('user_pwd',md5($data['new_password']));
		$this->db->where('user_name',$data['user_name']);
		$this->db->where('admin_user_id',$data['admin_user_id']);
		$this->db->update('tbl_admin_user');
	}
}

?>
