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

class MY_Controller extends CI_Controller{

		//initialize all required variables
		function __construct(){	
			parent::__construct();

			$this->load->helper('cookie');
			$this->load->library('session');			
			$this->load->helper('date');
			$this->load->helper('url');
			$this->load->helper('common_func');
			$this->load->library('Breadcrumb');
			$this->load->library('pagination');
			$this->load->database();
			$this->load->library('curl');
			$this->load->library('email');
			$this->load->library('upload'); 
       		$this->load->library('image_lib'); //load library
			$this->load->helper('file');
			$this->load->library('cart');
			$this->data['base_url'] 		= $this->config->item('base_url');
			$this->data['base_path']        = $this->config->item('base_path');			
			$this->data['base_assets'] 		= $this->config->item('base_assets');
			$this->data['url_name']         = $this->uri->segment(1, 0);
			$this->data['userid']        = $this->session->userdata('userid');
			
			if($this->data['userid']!=''){
				$this->load->model('home_model', '', TRUE);
				$this->data['user_ahentication'] = $this->home_model->user_details($this->data['userid']);
			}
			$this->data['menuname'] =  $this->uri->segment(1);
			$this->data['submenuname'] =  $this->uri->segment(2);
			$this->smarty->assign('data', $this->data);
		}
		function unique_multidim_array($array, $key) { 
	        $temp_array = array(); 
	        $i = 0; 
	        $key_array = array(); 
	        
	        foreach($array as $val) { 
	            if (!in_array($val[$key], $key_array)) { 
	                $key_array[$i] = $val[$key]; 
	                $temp_array[$i] = $val; 
	            } 
	            $i++; 
	        } 
	        return $temp_array; 
	    }
		// USE FOR UPLOAD IMAGES
		function do_upload_img($folder,$image,$size){	
			if(!is_dir('assets/images/'.$folder.'/')){
				@mkdir('assets/images/'.$folder.'/', 0777);
			}
			if(!is_dir('assets/images/'.$folder.'/thumbnails')){
				@mkdir('assets/images/'.$folder.'/thumbnails', 0777);
			} 
			$config = array(
				//'allowed_types' => 'gif|GIF|JPG|jpg|JPEG|jpeg|PNG|png|TIFF|tiff|PSD|psd',
				'allowed_types' => '*',
				'upload_path' => 'assets/images/'.$folder.'/',
				'file_name' => str_replace(' ','',$_FILES[$image]['name']),
				'max_size'=>5380334
			);
			$file_name=str_replace(' ','',$_FILES[$image]['name']);
			$this->upload->initialize($config);
			$this->upload->do_upload($image); //do upload
			$image_data = $this->upload->data(); //get icon data
			if($size){
				$config1 = array(	  
				'source_image' => $_FILES[$image]['tmp_name'], //get original image
				'new_image' => 'assets/images/'.$folder.'/thumbnails/'.$size['width'].'X'.$size['height'].'_'.$file_name, 
				'maintain_ratio' => true,
				'width' =>  $size['width'],
				'height' => $size['height']
				//'master_dim' => 'width'
				);               
				$this->image_lib->initialize($config1);
				$resize_img = $this->image_lib->resize(); //do whatever specified in config
				unset($config1);
			}
			$image_name=$image_data['file_name'];
			return $image_name;                
		}
		function get_random_string($length)
		{
			$charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
		    $str = '';
		    $count = strlen($charset);
			
			for($i=1;$i<$length;$i++) {
		        $str .= $charset[mt_rand(0, $count-1)];
		    }
		    return $str;
		}
    	
    	function createOTP($length = 6, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')  
		{  
			 $chars_length = (strlen($chars) - 1);  
			 $string = $chars{rand(0, $chars_length)};  
			 for ($i = 1; $i < $length; $i = strlen($string))  
			 {  
			    $r = $chars{rand(0, $chars_length)};  
			    if ($r != $string{$i - 1}) $string .= $r;
			 }  
			 return $string;
		}
}
?>