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

class Classsetting extends CI_Controller 
{

 public function __construct()
 {
  parent::__construct();
  $this->load->helper('url');
  $this->load->helper('form');
  $this->load->library('form_validation');
  $this->load->library('userauth');
  $this->load->library('password');
  $this->load->model('Class_model');
}

public function cl_name()
{
  $this->userauth->logged_in();
  $data['all_class']=$this->Class_model->all_class();
  $this->load->view('admin/classsetting-names',$data);
}

public function cl_locations()
{
  $this->userauth->logged_in();
  $data['all_locations']=$this->Class_model->all_locations();
  $this->load->view('admin/classsetting-location',$data);
}

public function cl_instructors()
{
  $this->userauth->logged_in();
  $data['all_instructors']=$this->Class_model->all_instructors();
  $this->load->view('admin/classsetting-instructor',$data);
}

        //CLASS

        //manage class

public function manage_class()
{
  $class_name = array('class_name'=>$this->input->post('class_name'));
  $action = $this->input->post('submit');
  if($action == "Add")
  {
    $data = $this->Class_model->create_class($class_name);
    if($data)
    {
     $this->session->set_flashdata('success_msg','Class Created Successfully');
     redirect('admin/class-name');
   }
   else
   {
     $this->session->set_flashdata('error_msg','Error Occur');
     redirect('admin/class-name');
   }
 }
 elseif($action == "Update")
 {
   $class_id = $this->input->post('class_id');   
   $data = $this->Class_model->update_class($class_name,$class_id);
   if($data)
   {
    $this->session->set_flashdata('success_msg','Class Updated Successfully');
    redirect('admin/class-name');
  }
  else
  {
   $this->session->set_flashdata('error_msg','Error Occur');
   redirect('admin/class-name');
 }   
}
}

        //end manage class

        //return class

public function return_class($class_id)
{
  $this->userauth->logged_in();
  $return_class = $this->Class_model->return_class($class_id);
  $data['class_id']=$return_class->class_id;
  $data['class_name']=$return_class->class_name;
  $data['all_class']=$this->Class_model->all_class();
  $this->load->view('admin/classsetting-names',$data);
}

        //end return class

        //delete class

function delete_class($class_id)
{
  $delete_class = $this->Class_model->delete_class($class_id);
  if($delete_class)
  {
    $this->session->set_flashdata('success_msg','Class Deleted Successfully');
    redirect('admin/class-name');
  } else {
    $this->session->set_flashdata('error_msg','Error Occur');
    redirect('admin/class-name');   
  }
} 

        //end delete class


        //LOCATION

        //manage location

public function manage_location()
{
  $location_name = array('locat_name'=>$this->input->post('locat_name'));
  $action = $this->input->post('submit');
  if($action == "Add")
  {
    $data = $this->Class_model->create_location($location_name);
    if($data)
    {
     $this->session->set_flashdata('success_msg','Location Created Successfully');
     redirect('admin/class-locations');
   }
   else
   {
     $this->session->set_flashdata('error_msg','Error Occur');
     redirect('admin/class-locations');
   }
 }
 elseif($action == "Update")
 {
   $locat_id = $this->input->post('locat_id');   
   $data = $this->Class_model->update_location($location_name,$locat_id);
   if($data)
   {
    $this->session->set_flashdata('success_msg','Location Updated Successfully');
    redirect('admin/class-locations');
  }
  else
  {
   $this->session->set_flashdata('error_msg','Error Occur');
   redirect('admin/class-locations');
 }   
}
}

        //end location class

        //return location

public function return_location($locat_id)
{
  $this->userauth->logged_in();
  $return_location = $this->Class_model->return_location($locat_id);
  $data['locat_id']=$return_location->locat_id;
  $data['locat_name']=$return_location->locat_name;
  $data['all_locations']=$this->Class_model->all_locations();
  $this->load->view('admin/classsetting-location',$data);
}

        //end return location

        //delete location

function delete_location($locat_id)
{
  $delete_location = $this->Class_model->delete_location($locat_id);
  if($delete_location)
  {
    $this->session->set_flashdata('success_msg','Location Deleted Successfully');
    redirect('admin/class-locations');
  } else {
    $this->session->set_flashdata('error_msg','Error Occur');
    redirect('admin/class-locations');   
  }
} 

        //end delete location

        //INSTRUCTORS

        //manage Instructors

public function manage_instructor()
{
  $instructor_name = array('instr_name'=>$this->input->post('instr_name'));
  $action = $this->input->post('submit');
  if($action == "Add")
  {
    $data = $this->Class_model->create_instructors($instructor_name);
    if($data)
    {
     $this->session->set_flashdata('success_msg','Instructor Added Successfully');
     redirect('admin/class-instructors');
   }
   else
   {
     $this->session->set_flashdata('error_msg','Error Occur');
     redirect('admin/class-instructors');
   }
 }
 elseif($action == "Update")
 {
   $instr_id = $this->input->post('instr_id');   
   $data = $this->Class_model->update_instructors($instructor_name,$instr_id);
   if($data)
   {
    $this->session->set_flashdata('success_msg','Instructors Updated Successfully');
    redirect('admin/class-instructors');
  }
  else
  {
   $this->session->set_flashdata('error_msg','Error Occur');
   redirect('admin/class-instructors');
 }   
}
}

        //end manage instructors

        //return instructors

public function return_instructors($instr_id)
{
  $this->userauth->logged_in();
  $return_instructors = $this->Class_model->return_instructors($instr_id);
  $data['instr_id']=$return_instructors->instr_id;
  $data['instr_name']=$return_instructors->instr_name;
  $data['all_instructors']=$this->Class_model->all_instructors();
  $this->load->view('admin/classsetting-instructor',$data);
}

        //end return instructors 

       //delete instructors

function delete_instructors($instr_id)
{
  $delete_instructors = $this->Class_model->delete_instructors($instr_id);
  if($delete_instructors)
  {
    $this->session->set_flashdata('success_msg','Instructor Deleted Successfully');
    redirect('admin/class-instructors');
  } else {
    $this->session->set_flashdata('error_msg','Error Occur');
    redirect('admin/class-instructors');   
  }
} 

        //end delete instructors 

}

?>
