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

	function delete_message()
	{
			$CI = get_instance();
			$CI->session->set_flashdata('success', 'Successfully Deleted');
	}
	function update_message()
	{
			$CI = get_instance();
			$CI->session->set_flashdata('success', 'Successfully Updated');
	}
	function insert_message()
	{
			$CI = get_instance();
			$CI->session->set_flashdata('success', 'Successfully Inserted');
	}
	function error_message()
	{
			$CI = get_instance();
			$CI->session->set_flashdata('error', 'error........');
	}

	function get_total($id, $type, $city)
	{
	    $CI = get_instance();
	    $CI->load->model('Free_listing_model');
	    $CI->Free_listing_model->get_total($id, $type, $city);
	}
	function is_login()
	{
	    $CI = get_instance();
			if( ! $CI->ion_auth->logged_in()){
				redirect('auth/applogout','refresh');
			}

	}
	function categoryname($id, $type)
	{
	    // Get a reference to the controller object
	    $CI = get_instance();

	    // You may need to load the model if it hasn't been pre-loaded
	    $CI->load->model('Free_listing_model');

	    // Call a function of the model
	    $CI->Free_listing_model->categoryname($id, $type);
	}
	function my_city(){
		if($this->session->userdata('city')!='')
		{
		    $city = str_replace(' ','-',$this->session->userdata('city'));
		}
		else {
		    $city = 'Mumbai';
		}
		return $city;
	}

	// generate ref
	function ref()
	{
		$ref = rand(10,100).time();
		return $ref;
	}
	// return total ads from c_id
	function totalads_cid($c_id)
	{
		$query = $this->db->query('SELECT a_id FROM adds WHERE c_id=$c_id');
		$total = $query->num_rows();
		return $total;
	}

	// encode
	function en($value='')
	{
		$encode = base64_encode($value);
		return $encode;
	}
	// decode
	function dn($value='')
	{
		$decode = base64_decode($value);
		return $decode;
	}
	// remove blank from string -
	function rm_slash($value='')
	{
		$blank = str_replace('/','-', $value);
		return $blank;
	}
	function rm_blank($value='')
	{
		$value = trim($value);
		$percentage = str_replace('%','per', $value);
		$blank = str_replace(' ','-', $percentage);
		return preg_replace('/[^A-Za-z0-9\-]/', '', $blank);
	}
	// remove %20 from string -
	function rm_20($value='')
	{
		$per = str_replace('%20',' ', $value);
		return $per;
	}
	// remove - from string and set blank
	function rm_dash($value='')
	{
		$dash = str_replace('-',' ', $value);
		return $dash;
	}
	function rm_dashslash($value='')
	{
		$dash = str_replace('-','/', $value);
		return $dash;
	}
	//string to array

	// return indian format date
	function date_indian($var = '')
	{
			$var = date('d-M-Y', strtotime($var));
			return $var;
	}

	// Helper For print_r
	function pr($var = '')
	{
		echo "<pre>";
		   print_r($var);
		echo "</pre>";
	    // die();
	}


	//Helper For base_url()
	function bs($value = '')
	{
		// public $url = ""
		echo base_url($value);
	}
	// function fa($name='',$attr='')
	// {
	// 	echo "<i class="'fa fa'.-.".$name."-".$attr""></i>";
	// }

	//Helper for $this->load->view()
	function view($value='', $data=array(), $output = false)
	{
		$CI =& get_instance();
		$CI->load->view($value,$data,$output);
	}

	//Helper For thsi->input->post()
	function post($value='')
	{
		$CI =& get_instance();
	    return $CI->input->post($value);
	}
	
	function getavgrating_sid($id)
	{
		$CI = get_instance();
		$CI->load->model('Common_model');
		$query = $CI->db->query('SELECT AVG(ratings) AS avgratings FROM testimonials WHERE s_id ='.$id);
		$records = $query->result();
		foreach($records as $row);
		return $row->avgratings;
	}

	//helper for var_dump
    function dd($value='')
	{
		echo "<pre>";
		   var_dump($value);
		echo "</pre>";
		die();
	}

	//Helper for last_query()
	function vd()
	{
		$CI =& get_instance();
		return $CI->db->last_query();
	}

	function group_priviliges($value='')
	{
		$CI =& get_instance();

		$gp_id = $CI->session->userdata("group_id");

		$gp_result = $CI->ion_auth_model->user_gp_privilegs($gp_id);

		$gp_data = array();

      	foreach($gp_result as $value)
        {
           //add all data to session
           $gp_data[] = $value->perm_name;

        }

	    return $gp_data;
	}
	function sendsms($msg, $mobile){
		$apiKey = urlencode('ZiDE/vzY/g4-GQ0L5BQmdi2M31iVTPEKKAZlA8nLat');
		$numbers = array($mobile);
		$sender = urlencode('INFOIN');
		$message = rawurlencode($msg);

		$numbers = implode(',', $numbers);
		// Prepare data for POST request
		$data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

		// Send the POST request with cURL
		$ch = curl_init('https://api.textlocal.in/send/');
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$response = curl_exec($ch);
		curl_close($ch);


/*
	  $username = "info@infonid.com";
	  $hash = "ZiDE/vzY/g4-GQ0L5BQmdi2M31iVTPEKKAZlA8nLat";

	  // Config variables. Consult http://api.textlocal.in/docs for more info.
	  $test = "0";

	  // Data for text message. This is the text message data.
	  $sender = "INFOIN"; // This is who the message appears to be from.
	  $numbers = $mobile; // A single number or a comma-seperated list of numbers
	  $message = 'Otp No. is 911111 infonid.com';//$msg;
	  // 612 chars or less
	  // A single number or a comma-seperated list of numbers
	  $message = urlencode($message);
	  $data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
	  $ch = curl_init('http://api.textlocal.in/send/?');
	  curl_setopt($ch, CURLOPT_POST, true);
	  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	  $result = curl_exec($ch); // This is the result from the API
	  curl_close($ch);*/
}

/* End of file custom_helpers.php */
/* Location: ./application/helpers/custom_helpers.php */
