<?php 
class register extends CI_Controller {
	function register()	 
	{  
   parent::__construct();	
    $this->load->library('session');
    $this->load->Model('functions', 'fun');  //function in model
    $this->load->library('pagination'); 
    	 $this->load->library('form_validation');

    } 



	
	
	public function index($result='')



{

		$data['result']=$result;
		
                $this->load->view('header');
				$this->load->view('register',$data);
				$this->load->view('footer');
	 
	}
	
	
		function send_msg()
	{
	   
	   



	                   	$this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('name', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('mob', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('username', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('pass', 'Password ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('email', 'email ', 'trim|required|valid_email|xss_clean');
						$this->form_validation->set_rules('address', 'Address', 'trim|required|xss_clean');
        if ($this->form_validation->run() == FALSE)
		 {
		      
		 		 $result= "<font color=red><b>All Field Required</b></font>";	 
		         $this->index($result);
		 }
		  else
		 {
		  $chk=$this->fun->check_user($this->input->post('username'));
		  
		  if($chk==TRUE)
		  {
		  $result= "<font color=red><b>This username already exist .. try new username</b></font>";
		   $this->index($result);

		  }
		  else
		  {
		     $pass=md5($this->input->post('pass'));
		     $data=array('name'=>$this->input->post('name'),'phone'=>$this->input->post('mob'),'email'=>$this->input->post('email'),'address'=>$this->input->post('address'),'username'=>$this->input->post('username'),'pass'=>$pass);
             $add=$this->fun->add('members',$data);
             
             if($add)
             {
              $result= "<font color=red><b>Successfully Sent</b></font>";
             }
             else
             {
              $result= "<font color=red><b>Error .. Try Again </b></font>";
             }
              $this->index($result);
           }
 	       // echo "<script type=\"text/javascript\"> alert(\" Successfuly sent \") ;window.location.href= \"".base_url()."index.php/contact/form\";</script>";
		}
	}
	

	



		
}



?>