<?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);
		$blank = str_replace(' ','-', $value);
		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);
	}

	//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;
	}

}

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