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

/**
 * staff Class
 *
 * @package     edusol
 * @subpackage  class
 * @author      Atif Razzaq
 * @link        http://atifrazzaq.arteck.xyz
 */
class Classes extends CI_Controller {

    private $userInfo = array();

    public function __construct()
    {
        parent::__construct();
        $this->load->model("user_model");
        $this->load->model("class_model");
        $this->user_model->check_login("admin");
        $this->userInfo = $this->user_model->userInfo("first_name,last_name");
    }


   public function index()
    {
        $this->user_model->check_permissions("classes/index");
        $data['edit_delete']=$this->user_model->checkEditDelete('classes/index');

        
        $data['is_super'] = $this->user_model->is_super();
        $data['menu'] = $this->load_model->menu();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT * FROM `class` Order By `class_id` DESC ");
          }else{
            $query = $this->db->query("SELECT * FROM `class` Order By `class_id` DESC ");
          }
        //echo "<pre>";print_r($query->result_array());exit;
        $data['base_url'] = base_url();
        $data['userInfo'] = $this->userInfo;
        $data['classes'] = $query->result_array();
                // calling view pages
        $this->load->view('header',$data);
        $this->load->view('sidebar',$data);
        $this->load->view('clases/class_view',$data);
    }
    
    public function fetch_class(){
        
        $data['is_super'] = $this->user_model->is_super();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT class.* FROM `class` inner join `branch` on branch.id=class.branch Order By `class_id` DESC ");
          }else{
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b'  Order By `class_id` DESC ");
          }
        // echo "<pre>";print_r($query->result_array());exit;
          $record = $query->result_array();
        if(!empty($record))
         {
            $i=0; 
            foreach ($record as $key => $value)
            { $i++;
                echo "
                 <tr>
                          <td>$i</td>
                          <td>$value[class_name]</td>
                          <td>$value[description]</td>
                          <td>$value[tution_fee]</td>
                          <td>$value[admin_fee]</td>
                          <td>$value[prefix]</td>";
                   if($this->user_model->is_super()){
                       
                            $b = $value['branch'];
                            $query = $this->db->select('name')->where('id',$b)->where('is_delete',0)->get('branch')->result_array()[0];
                    echo "<td>$query[name]</td>";
                           } 
                        $class=$value['class_id'];
                           $branch=$this->user_model->getbranch();
                          $query=$this->db->query("Select count(*) as total from `class` 
                          inner join `section` on class.class_id=section.class_id where section.class_id='$class'
                          AND section.branch='$branch' AND section.is_delete='0'  ")->result_array()[0]; 
                          
                          $base_url=base_url();
                             $bas= base64_encode(json_encode($value['class_id'].SALT));
                              echo "<td>
                
                             <span class='scroll'><a href='' onclick='edit($value[class_id],event)'>
                            <i class='fa fa-edit'></i></a></span> |<a href='$base_url/classes/view_section/$bas' class='badge bg-green'>
                            View Sections<span class='badge bg-green'>$query[total]</span></a> |"; 
                            $status=$value['is_delete'];
                            // var_dump($status);
                           if($status=='0'){
                    echo "           
                   <a href='' onclick='deactive($value[class_id],event)' style='color:green;'><i class='fa fa-lg fa-check-circle' aria-hidden='true'></i>Activated&nbsp;<span class='label label-info'>Click to Deactivate</span></a>";
                        } 
                     
                         if($status=='1')
                                { 
echo "<a href='' onclick='active($value[class_id],event)' style='color:red;'><i class='fa fa-lg fa-times-circle' aria-hidden='true'></i>Deactivated&nbsp;<span class='label label-info'>Click to Activate</span></a>";  
                                }
 echo "</td>";
                echo"</tr>";
                        } 
               
            }        
         
    }

            // class insertion view
     public function create()
    {
         $this->user_model->check_permissions("classes/index");
$data['edit_delete']=$this->user_model->checkEditDelete('classes/index');

        
        $data['is_super'] = $this->user_model->is_super();
        $data['menu'] = $this->load_model->menu();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b'  Order By `class_id` DESC ");
          }else{
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b'  Order By `class_id` DESC ");
          }
        //echo "<pre>";print_r($query->result_array());exit;
        $data['base_url'] = base_url();
        $data['userInfo'] = $this->userInfo;
        $data['classes'] = $query->result_array();
        
            //calling view pages
        $this->load->view('header',$data);
        $this->load->view('sidebar',$data);
        $this->load->view('clases/class_view',$data);
    }
    public function check_class($class,$branch)
    {
    $this->db->select();
	$this->db->from('class');
	$this->db->where('class_name',$class);
	$this->db->where('branch',$branch);
	$query = $this->db->get();
	//var_dump($query->num_rows());die;
   
	if($query->num_rows() > 0)
			{
				 //var_dump('hello');die;
				 //redirect("classes/create?error=Sorry! Class Already Added.","refresh");
				 //return true;
				 $data =  1;
			}
		else{
		    //echo 'hello';
		    //return false;
		    $data =  0;
		    }
		echo json_encode($data);
    }
    public function check_editclass($id,$class,$branch)
    {
    $this->db->select();
	$this->db->from('class');
	$this->db->where('class_id!=',$id);
	$this->db->where('class_name',$class);
	$this->db->where('branch',$branch);
	$query = $this->db->get();
	//var_dump($query->num_rows());die;
   
	if($query->num_rows() > 0)
			{
				 //var_dump('hello');die;
				 //redirect("classes/create?error=Sorry! Class Already Added.","refresh");
				 //return true;
				 $data =  1;
			}
		else{
		    //echo 'hello';
		    //return false;
		    $data =  0;
		    }
		echo json_encode($data);
    }
     public function check_orderr($orderr,$branch)
    {
    $this->db->select();
	$this->db->from('class');
	$this->db->where('orderr',$orderr);
	$this->db->where('branch',$branch);
	$query = $this->db->get();
	//var_dump($query->num_rows());die;
   
	if($query->num_rows() > 0)
			{
				
				 $data =  1;
			}
		else{
		  
		    $data =  0;
		    }
		echo json_encode($data);
    }
    public function check_editorderr($id,$orderr,$branch)
    {
    $this->db->select();
	$this->db->from('class');
	$this->db->where('class_id!=',$id);
	$this->db->where('$orderr',$orderr);
	$this->db->where('branch',$branch);
	$query = $this->db->get();
	//var_dump($query->num_rows());die;
   
	if($query->num_rows() > 0)
			{
			
				 $data =  1;
			}
		else{
		   
		    $data =  0;
		    }
		echo json_encode($data);
    }
    public function save($name,$des,$tufe,$adm,$branch,$orderr,$prefex)
    {
       $myname=rawurldecode($name);
         $mydes=rawurldecode($des);
         $mytufe=rawurldecode($tufe);
         $myadm=rawurldecode($adm);
         $mybranch=rawurldecode($branch);
          $myorderr=rawurldecode($orderr);
          $myprefix=rawurldecode($prefex);
         
	$this->db->select();
	$this->db->from('class');
	$this->db->where('class_name',$myname);
	$this->db->where('branch', $mybranch);
	$query = $this->db->get();
	if($query->num_rows() > 0)
			{
				// var_dump('hello');die;
				 redirect("classes/create?error=Sorry! Class Already Added.","refresh");   			
			}
	 
	        $fields_class = array(
                            'branch' => $mybranch,
                            'class_name' => $myname,
                            'description' => $mydes ,
                            'tution_fee'=>$mytufe ,
                            'admin_fee'=>$myadm,
                            'orderr'=>$myorderr,
                            'prefix'=>$myprefix
                );
              
              $this->db->insert('class',$fields_class);
           
           //Extract  data
           
           $data['is_super'] = $this->user_model->is_super();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT * FROM `class` inner join `branch` on branch.id=class.branch Order By `class_id` DESC ");
          }else{
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b'  Order By `class_id` DESC ");
          }
          $record = $query->result_array();
        if(!empty($record))
         {
            $i=0; 
            foreach ($record as $key => $value)
            { $i++;
           
                echo "
                 <tr>
                          <td>$i</td>
                          <td>$value[class_name]</td>
                          <td>$value[description]</td>
                          <td>$value[tution_fee]</td>
                          <td>$value[admin_fee]</td>
                           <td>$value[prefix]</td>";
                  if($this->user_model->is_super()){
                            $branch = $value['branch'];
                            $query = $this->db->select('name')->where('id',$branch)->where('is_delete',0)->get('branch')->result_array()[0];
                    echo "<td>$query[name]</td>";
                          } 
                 $class=$value['class_id'];
                           $branch=$this->user_model->getbranch();
                          $query=$this->db->query("Select count(*) as total from `class` 
                          inner join `section` on class.class_id=section.class_id where section.class_id='$class'
                          AND section.branch='$branch' AND section.is_delete='0'")->result_array()[0]; 
                            $base_url=base_url();
                             $bas= base64_encode(json_encode($class.SALT));
                             echo "<td>

                            <a href='' onclick='edit($value[class_id],event)'>
                            <i class='fa fa-edit'></i></a> |<a href='$base_url/classes/view_section/$bas' class='badge bg-green'>
                            View Sections<span class='badge bg-green'>$query[total]</span></a> |"; 
                            $status=$value['is_delete'];
                           if($status=='0'){
                    echo "           
                   <a href='' onclick='deactive($value[class_id],event)' style='color:green;'><i class='fa fa-lg fa-check-circle' aria-hidden='true'></i>Activated&nbsp;<span class='label label-info'>Click to Deactivate</span></a>";
                        } 
                     
                         if($status=='1')
                         
                                { 
echo "<a href='' onclick='active($value[class_id],event)' style='color:red;'><i class='fa fa-lg fa-times-circle' aria-hidden='true'></i>Deactivated&nbsp;<span class='label label-info'>Click to Activate</span></a>";  
                                }
                       
                            
 echo "</td>";

                      echo"</tr>";
                        } 
               
            } 
       
    }

public function get_record($id){
    $b=$this->user_model->getbranch();
      $query=$this->db->select('*')
                     ->from('class')
                     ->where('class_id',$id)
                     ->get()->row_array();
                echo json_encode($query);
   }
   
    public function edit()
    {       
            if($this->uri->segment(3))
            {  $branch=$this->user_model->getbranch();
                     if($this->user_model->is_super())
                        $data['branch'] = $this->db->select("name,id")->from("branch")->get()->result_array();
                     else
                        $data['branch'] = $this->db->select("name,id")->from("branch")->where("id",$branch)->get()->result_array();
            
             $data['menu'] = $this->load_model->menu();
             $id = explode(SALT,json_decode(base64_decode($this->uri->segment(3))))[0];
             $data['values']= $this->db->where('class_id',$id)->get('class')->result_array()[0];
             $data['userInfo'] = $this->userInfo;
             $data['base_url'] = base_url();
             
             $this->load->view('header',$data);
             $this->load->view('sidebar',$data);
             $this->load->view('clases/class_edit',$data);
            }
            else
            {
                redirect("classes/index","refresh");
            }
             

      
    }
    
      public function up_cls($id,$name,$des,$tufe,$adm,$orderr,$prefix)
{
         $myname=rawurldecode($name);
         $mydes=rawurldecode($des);
         $mytufe=rawurldecode($tufe);
         $myadm=rawurldecode($adm);
         $myorderr=rawurldecode($orderr);
         $myprefix=rawurldecode($prefix);
  $data=array(
       'class_name' => $myname,
        'description' => $mydes ,
         'tution_fee'=>$mytufe ,
          'admin_fee'=>$myadm,
          'orderr'=>$myorderr,
          'prefix'=>$myprefix
  );
 
  $query=$this->db->where('class_id',$id)
                  ->update('class',$data);
 $data['is_super'] = $this->user_model->is_super();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT class.* FROM `class` inner join `branch` on branch.id=class.branch Order By `class_id` DESC");
          }else{
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b' Order By `class_id` DESC ");
          }
          $record = $query->result_array();
        if(!empty($record))
         {
            $i=0; 
            foreach ($record as $key => $value)
            { $i++;
                echo "
                 <tr>
                          <td>$i</td>
                          <td>$value[class_name]</td>
                          <td>$value[description]</td>
                          <td>$value[tution_fee]</td>
                          <td>$value[admin_fee]</td>
                          <td>$value[prefix]</td>";
                  if($this->user_model->is_super()){
                            $branch = $value['branch'];
                            $query = $this->db->select('name')->where('id',$branch)->where('is_delete',0)->get('branch')->result_array()[0];
                    echo "<td>$query[name]</td>";
                          } 
                 $class=$value['class_id'];
                           $branch=$this->user_model->getbranch();
                          $query=$this->db->query("Select count(*) as total from `class` 
                          inner join `section` on class.class_id=section.class_id where section.class_id='$class'
                          AND section.branch='$branch' AND section.is_delete='0'")->result_array()[0]; 
                          
                         $base_url=base_url();
                             $bas= base64_encode(json_encode($value['class_id'].SALT));
                             echo "<td>

                            <a href='' onclick='edit($value[class_id],event)'>
                            <i class='fa fa-edit'></i></a> |<a href='$base_url/classes/view_section/$bas' class='badge bg-green'>
                            View Sections<span class='badge bg-green'>$query[total]</span></a> |"; 
                            $status=$value['is_delete'];
                           if($status=='0'){
                    echo "           
                   <a href='' onclick='deactive($value[class_id],event)' style='color:green;'><i class='fa fa-lg fa-check-circle' aria-hidden='true'></i>Activated&nbsp;<span class='label label-info'>Click to Deactivate</span></a>";
                        } 
                     
                         if($status=='1')
                         
                                { 
echo "<a href='' onclick='active($value[class_id],event)' style='color:red;'><i class='fa fa-lg fa-times-circle' aria-hidden='true'></i>Deactivated&nbsp;<span class='label label-info'>Click to Activate</span></a>";  
                                }
                       
                            
 echo "</td>";

                      echo"</tr>";
                        } 
               
            } 
       
    }                 

 public function cl_active($id="")
   {
            $update_data=array(
                           'is_delete'=>0
                       );
                       $this->db->where('class_id',$id);
                      $this->db->update('class',$update_data);
                      
    $data['is_super'] = $this->user_model->is_super();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT class.* FROM `class` inner join `branch` on branch.id=class.branch Order By `class_id` DESC");
          }else{
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b'  Order By `class_id` DESC");
          }
          $record = $query->result_array();
        if(!empty($record))
         {
            $i=0; 
            foreach ($record as $key => $value)
            { $i++;
                echo "
                 <tr>
                          <td>$i</td>
                          <td>$value[class_name]</td>
                          <td>$value[description]</td>
                          <td>$value[tution_fee]</td>
                          <td>$value[admin_fee]</td>
                          <td>$value[prefix]</td>";
                   if($this->user_model->is_super()){
                            $branch = $value['branch'];
                            $query = $this->db->select('name')->where('id',$branch)->where('is_delete',0)->get('branch')->result_array()[0];
                    echo "<td>$query[name]</td>";
                           } 
                 $class=$value['class_id'];
                           $branch=$this->user_model->getbranch();
                          $query=$this->db->query("Select count(*) as total from `class` 
                          inner join `section` on class.class_id=section.class_id where section.class_id='$class'
                          AND section.branch='$branch' AND section.is_delete='0'")->result_array()[0]; 
                          $base_url=base_url();
                             $bas= base64_encode(json_encode($value[class_id].SALT));
                             echo "<td>

                            <a href='' onclick='edit($value[class_id],event)'>
                            <i class='fa fa-edit'></i></a> |<a href='$base_url/classes/view_section/$bas' class='badge bg-green'>
                            View Sections<span class='badge bg-green'>$query[total]</span></a> |"; 
                            $status=$value['is_delete'];
                           if($status=='0'){
                    echo "           
                   <a href='' onclick='deactive($value[class_id],event)' style='color:green;'><i class='fa fa-lg fa-check-circle' aria-hidden='true'></i>Activated&nbsp;<span class='label label-info'>Click to Deactivate</span></a>";
                        } 
                     
                         if($status=='1')
                         
                                { 
echo "<a href='' onclick='active($value[class_id],event)' style='color:red;'><i class='fa fa-lg fa-times-circle' aria-hidden='true'></i>Deactivated&nbsp;<span class='label label-info'>Click to Activate</span></a>";  
                                }
                       
                            
 echo "</td>";
                      echo"</tr>";
                        } 
               
            } 
       
    }                                       
     
      public function cl_deactive($id="")
   {
            $update_data=array(
                           'is_delete'=>1
                       );
                       $this->db->where('class_id',$id);
                      $this->db->update('class',$update_data);
                      $this->db->where('class_id',$id);
              $this->db->update('section',array('is_delete'=>1));
                      
    $data['is_super'] = $this->user_model->is_super();
        $b=$this->user_model->getbranch();
        
        $total = $this->db->query("SELECT count(*) as total FROM `class` where branch=$b")->result_array()[0]['total'];
         if($this->user_model->is_super())
         {
            $query = $this->db->query("SELECT class.* FROM `class` inner join `branch` on branch.id=class.branch Order By `class_id` DESC");
          }else{
            $query = $this->db->query("SELECT * FROM `class` WHERE class.branch = '$b' Order By `class_id` DESC");
          }
          $record = $query->result_array();
        if(!empty($record))
         {
            $i=0; 
            foreach ($record as $key => $value)
            { $i++;
                echo "
                 <tr>
                          <td>$i</td>
                          <td>$value[class_name]</td>
                          <td>$value[description]</td>
                          <td>$value[tution_fee]</td>
                          <td>$value[admin_fee]</td>
                          <td>$value[prefix]</td>";
                   if($this->user_model->is_super()){
                            $branch = $value['branch'];
                            $query = $this->db->select('name')->where('id',$branch)->where('is_delete',0)->get('branch')->result_array()[0];
                    echo "<td>$query[name]</td>";
                           } 
                 $class=$value['class_id'];
                           $branch=$this->user_model->getbranch();
                          $query=$this->db->query("Select count(*) as total from `class` 
                          inner join `section` on class.class_id=section.class_id where section.class_id='$class'
                          AND section.branch='$branch' AND section.is_delete='0'")->result_array()[0]; 
                      $base_url=base_url();
                             $bas= base64_encode(json_encode($value['class_id'].SALT));
                             echo "<td>

                            <a href='' onclick='edit($value[class_id],event)'>
                            <i class='fa fa-edit'></i></a> |<a href='$base_url/classes/view_section/$bas' class='badge bg-green'>
                            View Sections<span class='badge bg-green'>$query[total]</span></a> |"; 
                            $status=$value['is_delete'];
                           if($status=='0'){
                    echo "           
                   <a href='' onclick='deactive($value[class_id],event)' style='color:green;'><i class='fa fa-lg fa-check-circle' aria-hidden='true'></i>Activated&nbsp;<span class='label label-info'>Click to Deactivate</span></a>";
                        } 
                     
                         if($status=='1')
                         
                                { 
echo "<a href='' onclick='active($value[class_id],event)' style='color:red;'><i class='fa fa-lg fa-times-circle' aria-hidden='true'></i>Deactivated&nbsp;<span class='label label-info'>Click to Activate</span></a>";  
                                }
                       
                            
 echo "</td>";
                      echo"</tr>";
                        } 
               
            } 
       
    }  
    
    public function update()
    {
        $cname=$this->input->post('class_name');
    	$this->db->select();
    	$this->db->from('class');
    	$this->db->where('class_name',$cname);
    	$query = $this->db->get();
    	if($query->num_rows() > 0)
			{
				// var_dump('hello');die;
				 redirect("classes/create?error=Sorry! Class Already Added.","refresh"); 
				 
			}
        
        else
        {
            $data = $this->input->post();
            //var_dump($data);die();
            $db_update = $this->class_model->update($data);
            redirect("classes/index","refresh");
    
        }

    }
   /* public function update()
    {
        if($this->input->post())
        {
            $data = $this->input->post();
            //var_dump($data);die();
            $db_update = $this->class_model->update($data);
            redirect("classes/index","refresh");
    
        }
        else
        {
            redirect("classes/index","refresh");

        }
        

   }*/
   public function delete()
   {
            
        if($this->uri->segment(3))
        {
            $id=$this->uri->segment(3);
            $this->class_model->delete($id);
            redirect('classes/index','refresh');    
        }
        else
        {
            redirect('classes/index','refresh');    

        }
       
   }
public function view_section()
{
       //$this->user_model->check_permissions("classes/index");
           if($this->uri->segment(3)){

$id = explode(SALT,json_decode(base64_decode($this->uri->segment(3))))[0];
                 $data['section']=$this->db->query("SELECT * From `section` inner join `class` on class.class_id=section.class_id where section.class_id='$id' AND `section`.`is_delete`='0'")->result_array();
                 
                 $data['menu'] = $this->load_model->menu();
                 $data['base_url'] = base_url();
                  $data['userInfo'] = $this->userInfo;
            //calling view pages
        $this->load->view('header',$data);
        $this->load->view('sidebar',$data);
        $this->load->view('clases/view_sections',$data);
}
}
public function students()
{
           if($this->uri->segment(3)){
                $id=$this->uri->segment(3);
                $branch=$this->user_model->getbranch();
                 $data['student']=$this->db->query("SELECT student.*,class.*,section.*,student.id as stid FROM student JOIN promotion ON promotion.student_id=student.id JOIN class ON promotion.class_id=class.class_id JOIN section ON promotion.section_id=section.section_id WHERE student.branch = '$branch' AND student.status='0' AND promotion.is_active='1' AND promotion.section_id='$id'")->result_array();
                 
                 $data['menu'] = $this->load_model->menu();
                 $data['is_super'] = $this->user_model->is_super();
                 $data['base_url'] = base_url();
                  $data['userInfo'] = $this->userInfo;
            //calling view pages
        $this->load->view('header',$data);
        $this->load->view('sidebar',$data);
        $this->load->view('clases/student_view',$data);

}
}

public function deactive()
   {
         if($this->uri->segment(3))
         {
          $id = explode(SALT,json_decode(base64_decode($this->uri->segment(3))))[0];
              $fetch=$this->db->select('*');
                     $this->db->from('class');
                     $this->db->where('class_id',$id);
                     $this->db->order_by('class_id', 'DESC');
                     $this->db->get();
                      $result=$fetch->result_array();
                      
                      foreach($result as $key) {
                      $class_id=$key['class_id']; 
                      $branch=$key['branch']; 
                      $class_name=$key['class_name']; 
                      $class_number=$key['class_number']; 
                      $description=$key['description'];  
                      $tution_fee=$key['tution_fee']; 
                      $admin_fee=$key['admin_fee']; 
                      $is_delete=$key['is_delete']; 
                        }
            
            $update_data=array(
                           'class_id'=>$class_id,
                           'branch'=>$branch,
                           'class_name'=>$class_name,
                           'class_number'=>$class_number,
                           'description'=>$description,
                           'admin_fee'=>$admin_fee,
                           'admin_fee'=>$admin_fee,
                           'is_delete'=>1
            
                       );
                       $this->db->where('class_id',$id);
              $this->db->update('class',$update_data);
              $this->db->where('class_id',$id);
              $this->db->update('section',array('is_delete'=>1));
            
             redirect('Classes/index','refresh');
         }
         else
         {
             redirect('Classes/index','refresh');

         }
   
   }
   
   public function active()
   {
         if($this->uri->segment(3))
         {
             $id = explode(SALT,json_decode(base64_decode($this->uri->segment(3))))[0];
              $fetch=$this->db->select('*');
                      $this->db->from('class');
                      $this->db->where('class_id',$id);
                      $this->db->order_by('class_id', 'DESC');
                       $this->db->get();
                      $result=$fetch->result_array();
                      
                      foreach($result as $key) {
                      $class_id=$key['class_id']; 
                      $branch=$key['branch']; 
                      $class_name=$key['class_name']; 
                      $class_number=$key['class_number']; 
                      $description=$key['description'];  
                      $tution_fee=$key['tution_fee']; 
                      $admin_fee=$key['admin_fee']; 
                      $is_delete=$key['is_delete']; 
                        }
            
            $update_data=array(
                           'class_id'=>$class_id,
                           'branch'=>$branch,
                           'class_name'=>$class_name,
                           'class_number'=>$class_number,
                           'description'=>$description,
                           'admin_fee'=>$admin_fee,
                           'admin_fee'=>$admin_fee,
                           'is_delete'=>0
            
                       );
                       $this->db->where('class_id',$id);
              $this->db->update('class',$update_data);
            
             redirect('Classes/index','refresh');
         }
         else
         {
             redirect('Classes/index','refresh');

         }
   
   }
}
