<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hs {
   
    public function __construct()
    {
		$this->CI =& get_instance();
		 
	}
	
	//*********this function return websetting data from database**********//
	public function getwebsettings($key_value){
		
		$query_setting = $this->CI->Data_access_model->select_data('value_text','hs_setting',array('key_text'=>$key_value));
		if(!empty($query_setting)){ 
			$web_settingdata = $query_setting->row_array();
			return $web_settingdata['value_text'];
		}else{
			return $web_settingdata['value_text'] = '';
		}
	}
	
	//*********this function return uniq_id and value_text setting data from database**********//
	public function getsetting_uniq_id($key_text){
		
		$uniq_id_setting = $this->CI->Data_access_model->select_data('uniq_id,value_text','hs_setting',array('key_text'=>$key_text));
	    if(!empty($uniq_id_setting)){ 
			return $web_settingdata = $uniq_id_setting->row_array();
		}else{	 
			return $web_settingdata = '';
		} 
	}
	
	//**************this function return user details by user id*********//
	public function get_userdetails($column,$userid){
		
		$user_details = $this->CI->Data_access_model->select_data($column,'hs_user',array('user_id'=>$userid));
	    if(!empty($user_details)){ 
			$user_data = $user_details->row_array();
			return $user_data[$column];
		}else{	 
			return $user_data[$column] = '';
		} 
	}
	 
	 
	//**********this function return count ************// 
	public function count_table_column($countcolumn,$table,$where_data){
		
		$count_result = $this->CI->Data_access_model->select_data('count('.$countcolumn.') as total_count',$table,$where_data);
		if(!empty($count_result)){ 
		    $count_column =$count_result->row(); 
			return $count_column->total_count;
		}else{	 
			return $count_column = 0;
		} 
	} 
	//************this function send mail ****************//
	public function send_mail($to_send_mail='',$subject='',$message=''){
		if(!empty($to_send_mail)){
			 		 
			$from_name = $this->CI->hs->getwebsettings('sender_name');
			$from_email = $this->CI->hs->getwebsettings('sender_mailid'); 
			$subject =	$subject;
			$to_email =  $to_send_mail;
			if(!empty($to_email))
			{
				$res = 'themeassets/images/mail.png';
				$smtp_status = $this->CI->hs->getwebsettings('smtp_status');
				if($smtp_status ==1){
					$config['protocol'] = 'smtp';
					$config['smtp_host'] =$this->CI->hs->getwebsettings('smtp_host');
					$config['smtp_port'] =$this->CI->hs->getwebsettings('smtp_port'); 
					$config['smtp_user'] =$this->CI->hs->getwebsettings('smtp_username');
					$config['smtp_pass'] =$this->CI->hs->getwebsettings('smtp_password');
				}
				 
				$config['charset'] = 'iso-8859-1'; 
				$config['mailtype'] = 'html';
				$config['wordwrap'] = TRUE;
				$this->CI->load->library('email');
				$this->CI->email->initialize($config);
				$this->CI->email->to($to_email);
				$this->CI->email->from($from_email,$from_name);	
				$this->CI->email->subject($subject);
				$this->CI->email->message($message);
				//Send mail 
                if($this->CI->email->send()){ 
					return 1;
				}else{
					return 0;
				}			 				
			}
		}	
	} 
	 
}
	
?>