<?php 
class mail_list extends CI_Controller {
	function mail_list()	 
	{  
    parent::__construct();	
    $this->load->library('session');		
    $this->load->Model('functions', 'fun');  //function in model 
    $this->load->library('pagination');
    $this->load->library('DX_Auth');
    $this->load->helper('form');
	$this->load->helper('url');
	$this->load->library('form_validation');
	$this->dx_auth->check_uri_permissions();

    } 
    
	
		
	function index()
	{   
	    $this->load->model('mail_list_model');  /// model file name
	    	
	   //////pagination styl and config
	    $config['base_url'] = base_url().'index.php/mail_list/index/';
		$config['total_rows'] = $this->mail_list_model->get_num_mail_list();
		$config['per_page'] = 25;
		$config['num_links'] = 3; 
		$config['uri_segment'] = 3;	
		$config['full_tag_open']='<div class="pagination">';
		$config['full_tag_close'] = '</div>';
		$config['next_link'] = 'Next';
		$config['prev_link'] = 'Prev';
		$config['cur_tag_open'] = '<span class="current">';
		$config['cur_tag_close'] = '</span>';		
		$offset = $this->uri->segment(3,0);
		$this->session->set_userdata('offset',$offset);
		$this->pagination->initialize($config); 
		
		$this->load->view('header');
		
		//// load left and send query to creat menu
		$status='all';
		
		$menu=array();
		$menu_q= $this->fun->get_modules();
		$menu['mods']=$menu_q;
		$menu['status']=$status;
		$this->load->view('left',$menu);
		
		////// load content send query to get post 
		$data=array();
		$q=$this->mail_list_model->get_mail_list($config['per_page']);   ///////model class --->model func		
		$data['records']=$q;
		
		$this->load->view('mail_list',$data);
		
		$this->load->view('footer');
	}
	
	
	function add_user()
	{   
	
	           $data=array();
	                $data['username'] = '';
	                $data['pass'] = '';
	                $data['email'] = '';

	
	   $status='all';
	    
	    $this->load->view('header');
	    
	    $menu=array();
		$menu_q= $this->fun->get_modules();
		$menu['mods']=$menu_q;
		$menu['status']=$status;
		$this->load->view('left',$menu);
		$data['status']=$status;
		
		$this->load->view('add_user',$data);
		$this->load->view('footer');

	}
	function save_add_user()
	{	
	
	      $data=array();
	                $data['username'] = $this->input->post('username');
	                $data['pass'] = $this->input->post('password');
	                $data['email'] = $this->input->post('email');
	                $data['roleid'] = '2';
	                
	                    $this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('username', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('password', 'Password ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('email', 'email ', 'trim|required|valid_email|xss_clean');

                    if ($this->form_validation->run() == FALSE)
					{
			
			              $status='all';
						   
						    $this->load->view('header');
						    
						    $menu=array();
							$menu_q= $this->fun->get_modules();
							$menu['mods']=$menu_q;
							$menu['status']=$status;
							$this->load->view('left',$menu);
							$data['status']=$status;
							
							$this->load->view('add_user',$data);
							$this->load->view('footer');
					
					}
					else  // validation ture //
					{ 

	                
					                if($this->dx_auth->is_username_available($data['username']))
					                {
					     
							             if($user = $this->dx_auth->register($data['username'], $data['pass'],$data['email']))
						                 {
						                  $dt['username'] = $user['username'];
						                  $dt['roleid'] = $data['roleid'];
						                  $dt['email'] = $data['email'];
						                  
										  $this->load->model('users_model');   ///model file name
									     $this->users_model->add_new_user($dt);  /////model class --->model func				  
								          redirect('musers');		          
						                 }
						                 else 
						                 {                 	
								          redirect('musers');	
						                 }
						            }
						            else
						            {
					                   echo "<script type=\"text/javascript\"> alert(\" Username already exist \") ;window.location.href= \"".base_url()."index.php/musers/\";</script>";
						             
						            }
			   }
					    
	}




	function edit_mail_list($id)
	{ 	
	     $status='all';
	     $data['status']=$status;
	     $data['qry'] = $this->fun->getone("mail_list", $id); 			
	    
	    $this->load->view('header');
	    
	    $menu=array();
		$menu_q= $this->fun->get_modules();
		$menu['mods']=$menu_q;
		$menu['status']=$status;
		$this->load->view('left',$menu);
						
	    $this->load->view('edit_mail_list', $data);
	    $this->load->view('footer');
	
	}
	
	function save_edite_mail_list($id)
	{
	
	
	                $data['username'] = $this->input->post('username');
	                $data['email'] = $this->input->post('email');
	                
	                $this->form_validation->set_error_delimiters('<font color="#ff0000">', '</font>');
						$this->form_validation->set_rules('username', 'Name ', 'trim|required|xss_clean');
						$this->form_validation->set_rules('email', 'email ', 'trim|required|valid_email|xss_clean');

                  if ($this->form_validation->run() == FALSE)
					{
			               ///go to edit again
			                $status='all';
						     $data['status']=$status;
						     $data['qry'] = $this->fun->getone("mail_list", $id); 			
						    
						    $this->load->view('header');
						    
						    $menu=array();
							$menu_q= $this->fun->get_modules();
							$menu['mods']=$menu_q;
							$menu['status']=$status;
							$this->load->view('left',$menu);
											
						    $this->load->view('edit_mail_list', $data);
						    $this->load->view('footer');
					
					}
					else  // validation ture //
					{ 
								                           
								 $dt=array(
									    'name'=>$this->input->post('username'),
									    'email'=>$this->input->post('email')
									     	    );
								
					          				                  
								  $this->load->model('mail_list_model');   ///model file name
							     $this->mail_list_model->update_mail_list($dt,$id);  /////model class --->model func				  
						          redirect('mail_list');		          
				               
			   	}


	}
	
	function delete_mail_list($id)
	{ 	
	    $q= $this->fun->delete_one("mail_list", $id); 
	    
	    if($q)
	    {
	     echo "<script type=\"text/javascript\"> alert(\" Deleted successfully \") ;window.location.href= \"".base_url()."index.php/mail_list/\";</script>";
	    }
	    else
	    {
	    echo "<script type=\"text/javascript\"> alert(\" Dont Deleted Please Try Again \") ;window.location.href= \"".base_url()."index.php/mail_list/\";</script>";
	    }
	   
	
	}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */