<?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Main_Controller extends CI_Controller {  
      //functions  
      
	  
function login()  
      {  
           //http://localhost/tutorial/codeigniter/main/login  
           $data['title'] = 'Login';  
           $this->load->view("login", $data);  
      }  
	  
	  function index()  
      {  
           //http://localhost/tutorial/codeigniter/main/login  
           $data['title'] = 'Login';  
           $this->load->view("login", $data);  
      }  
      function login_validation()  
      {  
           $this->load->library('form_validation');  
           $this->form_validation->set_rules('username', 'Username', 'required');  
           $this->form_validation->set_rules('password', 'Password', 'required');  
           if($this->form_validation->run())  
           {  
                //true  
                $username = $this->input->post('username');  
                $password = md5($this->input->post('password'));  
                //model function  
                $this->load->model('main_model');  
                if($this->main_model->can_login($username, $password))  
                {  
                     $session_data = array(  
                          'username'     =>     $username  
                     );
					 $this->load->library('session');
					 $this->session->set_userdata($session_data);  
					 
                     redirect(base_url() . 'main_controller/enter');  
                }  
                else  
                {  
                     $this->session->set_flashdata('error', 'Invalid Username and Password');  
                     redirect(base_url() . 'main_controller/login');  
                }  
           }  
           else  
           {  
                //false  
                $this->login();  
           }  
      }  
      function enter(){  
           if($this->session->userdata('username') != '')  
           {  
                redirect(base_url() . 'main_controller/subscription');  
                echo '<label><a href="'.base_url

().'main_controller/logout">Logout</a></label>';  
           }  
           else  
           {  
                redirect(base_url() . 'main_controller/login');  
           }  
      }  
      function logout()  
      {  
           $this->session->unset_userdata('username');  
           redirect(base_url() . 'main_controller/login');  
      } 
	  
	 
	  
	  
	  function subscription()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_subcriptions();
			$data['data_intervals']=$this->main_model->get_intervals();
			$data['title'] = 'Subscription';  
            $this->load->view("subscription", $data); 
           //redirect(base_url() . 'main_controller/login');  
      } 


	
	function forgot_pass()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_pages();
			$data['title'] = 'Forgot Password';  
            $this->load->view("forgot_pass", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }  

	function edit_page()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_pages();
			$data['title'] = 'Forgot Password';  
            $this->load->view("forgot_pass", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }	
	  
	  
	  function add_user(){
		   $this->load->library('form_validation');  
           $this->form_validation->set_rules('FirstName', 'FirstName', 'required');  
           $this->form_validation->set_rules('LastName', 'LastName', 'required');  
           $this->form_validation->set_rules('PrimaryPh', 'PrimaryPh', 'required');  
           $this->form_validation->set_rules('Email', 'Email', 'required');  
           $this->form_validation->set_rules('UserName', 'UserName', 'required');  
           $this->form_validation->set_rules('UserPass', 'UserPass', 'required');  
           $this->form_validation->set_rules('ConfirmUserPass', 'ConfirmUserPass', 'required|matches[password]'); 

			if($this->form_validation->run())  
           {
				
					/* $username = $this->input->post('UserName');  
					 $password = md5($this->input->post('UserPass')); 

					 $userFname = $this->input->post('FirstName');					 
					 $userLname = $this->input->post('LastName');					 
					 $userCOR = $this->input->post('COR');					 
					 $userSOR = $this->input->post('SOR');					 
					 $userCity = $this->input->post('City');					 
					 $userPrimaryPh = $this->input->post('PrimaryPh');					 
					 $userPrimaryPhCanText = $this->input->post('canSendTextPrimary');					 
					 $userSeconDaryPh = $this->input->post('SecondaryPh');					 
					 $userSeconDaryPhCanText = $this->input->post('canSendTextSecondary');					 
					 $userEmail = $this->input->post('Email');					 
					 $userDob = $this->input->post('DOB');					 
					 $userRelationStatus = $this->input->post('RelationshipStatus');					 
					 $userCaregiverOrPatient = $this->input->post('isUserCareGiverOrPatient');					 
					 $userHaveCareGiver = $this->input->post('isUserHaveCareGiver');					 
					 $userCareGiverFname = $this->input->post('CareGiverFName');					 
					 $userCareGiverLname = $this->input->post('CareGiverLName');
					
					$patientFname = $this->input->post('PatientFirstName');					 
					$patientLname = $this->input->post('PatientLastName');
					$userTakingPrescripedMedication = $this->input->post('isUserTakePrescriptionMedication');					 
					$userMedicationDesc = $this->input->post('UserMedicationDetails');
					$patientTakingPrescripedMedication = $this->input->post('isPatientTakePresriptionMedication');					 
					$patientMedicationDesc = $this->input->post('PatientMedicationDetails');
					$userEthnicBck = $this->input->post('UserEthnicBck');					 
					$patientEthnicBck = $this->input->post('PatientEthnicBck');
					$userDesc = $this->input->post('UserDescription');					 
					$patientDesc = $this->input->post('PatientDescription');
					$userMemberOfSupportGrp = $this->input->post('supportGrp');	*/		


									
										 
	   
		   }
		   $this->load->model('main_model');
		   if($this->main_model->add_user($this->input->post('FirstName'),$this->input->post('LastName')))  
                {

				}
	  }
	  
	  
	  function add_subscription(){
		   
				
					 $plan_title = $this->input->post('plan_title');  
					 $plan_id = $this->input->post('plan_id'); 
					 $interval_type = $this->input->post('interval_type'); 
					 $interval_nos = $this->input->post('interval_nos'); 
					 $amount = $this->input->post('amount'); 
					 $trail_period_days = $this->input->post('trail_period_days'); 
					 $grp_to_activate = $this->input->post('grp_to_activate'); 

					
	
		   $this->load->model('main_model');
		   if($this->main_model->add_sub($plan_title,$plan_id,$interval_type,$interval_nos,$amount,$trail_period_days,$grp_to_activate))  
                {
					
				}
				
			$this->subscription();  		
	  }
////////////////////////Clients Start///////////////////////////////////////	

function clients()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_pages();
			$this->load->model('main_model');
			$data['title'] = 'Clients';  
			$data['data']=$this->main_model->get_clients();
			$this->load->view("clients", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }    	  
	  
	  function add_clients(){
		   
				
					 $add_fname = $this->input->post('add_fname');  
					 $add_lname = $this->input->post('add_lname'); 
					 $add_email = $this->input->post('add_email'); 
					 $add_pass = md5($this->input->post('add_pass')); 
					 $add_phone = $this->input->post('add_phone');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->add_client($add_fname,$add_lname,$add_email,$add_pass,$add_phone))  
                {
					
				}
				
			$this->clients();  	
	  }
	  
	  
	  function edit_clients(){
		   
				
					 $edit_fname = $this->input->post('edit_fname');  
					 $edit_lname = $this->input->post('edit_lname'); 
					 $edit_email = $this->input->post('edit_email'); 
					 $edit_pass = md5($this->input->post('edit_pass')); 
					 $edit_ph = $this->input->post('edit_ph');
					 $edit_id = $this->input->post('edit_id');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->edit_client($edit_id,$edit_fname,$edit_lname,$edit_email,$edit_pass,$edit_ph))  
                {
					
				}
				
			$this->clients();  	
	  }
	  
	  function delete_clients(){
		   
				
					 $del_id = $this->input->post('del_id');  
	
		   $this->load->model('main_model');
		   if($this->main_model->delete_client($del_id))  
                {
					
				}
				
			$this->clients();  	
	  }
////////////////////////Clients Ends///////////////////////////////////////	
 	  
////////////////////////Contractor Starts///////////////////////////////////////	

function contractors()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_contractors();
			$data['title'] = 'Contractors';  
            $this->load->view("contractors", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }  

 function add_contractors(){
		   
				
					 $add_fname = $this->input->post('add_fname');  
					 $add_lname = $this->input->post('add_lname'); 
					 $add_email = $this->input->post('add_email'); 
					 $add_pass = md5($this->input->post('add_pass')); 
					 $add_Uname = $this->input->post('add_Uname');
					 $add_phone = $this->input->post('add_ph');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->add_contractor($add_fname,$add_lname,$add_email,$add_pass,$add_phone,$add_Uname))  
                {
					
				}
				
			$this->contractors();  	
	  }
	  
	  
	  function edit_contractors(){
		   
				
					 $edit_fname = $this->input->post('edit_fname');  
					 $edit_lname = $this->input->post('edit_lname'); 
					 $edit_email = $this->input->post('edit_email'); 
					 $edit_pass = md5($this->input->post('edit_pass')); 
					 $edit_Uname = $this->input->post('edit_Uname'); 
					 $edit_ph = $this->input->post('edit_ph');
					 $edit_id = $this->input->post('edit_id');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->edit_contractor($edit_id,$edit_fname,$edit_lname,$edit_email,$edit_pass,$edit_ph,$edit_Uname))  
                {
					
				}
				
			$this->contractors();  	
	  }
	  
	  function delete_contractors(){
		   
				
					 $del_id = $this->input->post('del_id');  
	
		   $this->load->model('main_model');
		   if($this->main_model->delete_contractor($del_id))  
                {
					
				}
				
			$this->contractors();  	
	  }
	  
////////////////////////Contractor Ends///////////////////////////////////////	

////////////////////////Clients Start///////////////////////////////////////	

function jobcats()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_jobcats();
			$data['title'] = 'Job Categories';  
            $this->load->view("jobcatagories", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }   	  
	  
	  function add_jobcats(){
		   
				
					 $cat_name = $this->input->post('cat_name');  
					 $cat_qualification = $this->input->post('cat_qualification'); 
					 $cat_add = $this->input->post('cat_add'); 
					 $cat_sal = $this->input->post('cat_sal'); 
					 $cat_cmp = $this->input->post('cat_cmp');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->add_jobcat($cat_name,$cat_qualification,$cat_add,$cat_sal,$cat_cmp))  
                {
					
				}
				
			$this->jobcats();  	
	  }
	  
	  
	  function edit_jobcats(){
		   
				
					 $edit_cat_name = $this->input->post('edit_cat_name');  
					 $edit_cat_qualification = $this->input->post('edit_cat_qualification'); 
					 $edit_cat_add = $this->input->post('edit_cat_add'); 
					 $edit_cat_sal = $this->input->post('edit_cat_sal');
					 $edit_cat_cmp = $this->input->post('edit_cat_cmp');
					 $edit_cat_id = $this->input->post('edit_cat_id');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->edit_jobcat($edit_cat_id,$edit_cat_name,$edit_cat_qualification,$edit_cat_add,$edit_cat_sal,$edit_cat_cmp))  
                {
					
				}
				
			$this->jobcats();  	
	  }
	  
	  function delete_jobcats(){
		   
				
					 $del_id = $this->input->post('del_id');  
	
		   $this->load->model('main_model');
		   if($this->main_model->delete_jobcat($del_id))  
                {
					
				}
				
			$this->jobcats();  	
	  }
////////////////////////Clients Ends///////////////////////////////////////	 


////////////////////////job details Start///////////////////////////////////////	

function jobdetails()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_jobDetails();
			$data['jobtypes']=$this->main_model->get_jobTypes();
			$data['jobdurationtypes']=$this->main_model->get_jobPeriodTypes();
			$data['title'] = 'Job Details';  
            $this->load->view("jobdetails", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }   	  
	  
	  function add_jobs(){
		   
				
					 $job_cat = $this->input->post('job_cat');  
					 $job_title = $this->input->post('job_title'); 
					 $job_type = $this->input->post('job_type'); 
					 $job_hourly = $this->input->post('job_hourly'); 
					 $job_desc = $this->input->post('job_desc');
					 $job_start = date("Y-m-d",strtotime($this->input->post('job_start')));
					 $job_end = date("Y-m-d",strtotime($this->input->post('job_end')));

					
	
		   $this->load->model('main_model');
		   if($this->main_model->add_job($job_cat,$job_title,$job_type,$job_hourly,$job_desc,$job_start,$job_end))  
                {
					
				}
				
			$this->jobdetails();  	
	  }
	  
	  
	  function edit_jobs(){
		   
				
					 $edit_job_cat = $this->input->post('edit_job_cat');  
					 $edit_job_title = $this->input->post('edit_job_title'); 
					 $edit_job_type = $this->input->post('edit_job_type'); 
					 $edit_job_hourly = $this->input->post('edit_job_hourly');
					 $edit_job_desc = $this->input->post('edit_job_desc');
					 $edit_job_start = date("Y-m-d",strtotime($this->input->post('edit_job_start')));
					 $edit_job_end = date("Y-m-d",strtotime($this->input->post('edit_job_end')));
					 $job_id = $this->input->post('job_id');

					
	
		   $this->load->model('main_model');
		   if($this->main_model->edit_job($job_id,$edit_job_cat,$edit_job_title,$edit_job_type,$edit_job_hourly,$edit_job_desc,$edit_job_start,$edit_job_end))  
                {
					
				}
				
			$this->jobdetails();  	
	  }
	  
	  function delete_jobs(){
		   
				
					 $del_id = $this->input->post('del_id');  
	
		   $this->load->model('main_model');
		   if($this->main_model->delete_job($del_id))  
                {
					
				}
				
			$this->jobdetails();  	
	  }
////////////////////////job details Ends///////////////////////////////////////		 

////////////////////////payment starts///////////////////////////////////////	
function payments()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_payments();
			$data['title'] = 'Payments';  
            $this->load->view("payments", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }	 
////////////////////////jpayment Ends///////////////////////////////////////		 

////////////////////////rating-review starts///////////////////////////////////////	
function ratings_review()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_ratings_reviews();
			$data['title'] = 'Ratings & Review';  
            $this->load->view("ratings-review", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }	 
////////////////////////rating-review Ends///////////////////////////////////////		

////////////////////////messages starts///////////////////////////////////////	
function messages()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_messages();
			$data['title'] = 'Messages';  
            $this->load->view("message", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }	 
	  
function delete_mails(){
		   
				
					 $del_id = $this->input->post('del_id');  
	
		   $this->load->model('main_model');
		   if($this->main_model->delete_mail($del_id))  
                {
					
				}
				
			$this->jobdetails();  	
	  }	  
////////////////////////messages Ends///////////////////////////////////////	

////////////////////////reports starts///////////////////////////////////////	
function reports()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_ratings_reviews();
			$data['title'] = 'Reports';  
            $this->load->view("reports", $data); 
           //redirect(base_url() . 'main_controller/login');  
      }	 
////////////////////////reports Ends///////////////////////////////////////	
 
	 
 }  