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/BooksAuthor.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


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

        $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/author_model','lmsam');
        $this->load->model('lms/rack_model','rm');
    }
    
    
    function index($author_id=null){
        if($this->data['userdata']->user_type=='student'   || $this->data['userdata']->user_type=='agent'   ){
            redirect($this->data['base_url']);
        }
        
        if(session_userdata('isAdminLoggedin')){
            $edit_access= check_access_control($this->data['userdata'],'lms_books_athors','edit');
            $add_access= check_access_control($this->data['userdata'],'lms_books_athors','add');
            $view_access= check_access_control($this->data['userdata'],'lms_books_athors','view');


            $this->data['page_title']='Books Author';
            $this->data['all_country'] = $this->lmsam->get_all_country();
            $view='lms/vw_books_authors';
            
            if($this->data['userdata']->user_role==1){
                $add_access='yes';
                $edit_access="yes";
                $view_access="yes";
            }

            if($add_access=='yes'){
                $this->data['add_option_view_form']=$add_access;
            }
            else{
                $this->data['add_option_view_form']='no';
            }

            if($view_access=='yes'){
                if(!empty($author_id)){
                    if( $edit_access=='yes'){
                        $this->data['edit_option_view_form']=$edit_access;
                                $author_id=decode_data($author_id);    
                                $this->data['author_data']=$this->lmsam->get_book_author(array('author_id'=>$author_id));
                    }
                    else{
                        $this->data['edit_option_view_form']='no';
                    }
                }
            }
            else{
                $view='lms/vw_lms_permission_denied';
            }
             
            $this->theme->title($this->data['page_title'])->load($view, $this->data);
        }else{
            redirect($this->data['base_url']);
        }
    }


    public function onAddEditBooksAuthor() {
        $return = [];  // Initialize return array
        
        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=='yes'  ||$this->session_upload_access=='no' ){
                    $book_author_name=post_data('book_author_name');
                    $book_author_url=post_data('book_author_url');
                    $book_author_country=post_data('book_author_country');
                    $book_author_bio=post_data('book_author_bio');
                    $bookAuthor=post_data('author_id');
                    $edit_access= check_access_control($this->data['userdata'],'lms_books_athors','edit');
                    $add_access= check_access_control($this->data['userdata'],'lms_books_athors','add');

                    if($this->data['userdata']->user_role==1){
                        $add_access='yes';
                        $edit_access="yes";
                        $view_access="yes";
                    }
         
                    if(!empty($bookAuthor)){
                        
                        $update_author=$this->lmsam->update_book_author_data(array('author_name'=>$book_author_name,'author_url'=>$book_author_url,'author_country'=> $book_author_country,'author_bio'=>$book_author_bio),array('author_id'=>post_data('author_id')));
                                            
                        if($update_author){
                            //  print_obj()
                            $return['success']='Author  updated successfully';
                        }
                        else{
                            $return['error']='Author not   updated';
                        }
                    }                  
            
                    $this->form_validation->set_rules('book_author_name', 'Author name  required', 'trim|required');
                    //$this->form_validation->set_rules("book_author_url", "Author Url", "trim|required|valid_url");
                  
                    if ($this->form_validation->run() == true){  
                        if($add_access=='yes'){                      

                        if(empty($bookAuthor)){
                            
                         
                            $book_author_data=$this->lmsam->get_book_author(array('author_inst_id'=>$this->inst_id,'author_inst_type'=>$this->inst_type,'author_name'=>$book_author_name));

                            if(empty($book_author_data)){
                               
                                $added=$this->lmsam->store_book_author_data(
                                    array(
                                        'author_inst_id'=>$this->inst_id,
                                        'author_inst_type'=>$this->inst_type,
                                        'author_name'=>$book_author_name,
                                        'author_url'=>$book_author_url,
                                        'author_bio'=>$book_author_bio,
                                        'author_country'=>$book_author_country,
                                        'author_status'=>'active',
                                        'author_created_by'=>$this->data['userdata']->user_id
                                        )
                                );

                                if($added){
                                   $return['success']='Author added successfully';  
                                }
                                else{
                                    $return['error']='Author not added';
                                }
                            }else{
                                $return['error']='Author name 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']='you dont   have a permission  to  add this author'; 
                    }
                }
                else{
                    $return['error']='Error occurred';
                } 
               //session 
               }else{
                    $return['error']='Permission denied.';
            }
                    
            }else{
                $return['error']='Action not allowed';
            }  

            return json_headers($return);

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

    public  function   onDeleteBooksAuthor()
    {
           
      if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
      
          if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){
            $delete_access=check_access_control($this->data['userdata'],'lms_books_athors','delete');

            

                   if($delete_access=='yes'){

              $author_id=post_data('author_id');
  
              if(!empty($author_id)){
                  $author_id=decode_data($author_id);
  
                  $author_data=$this->lmsam->delete_book_author_data(array('author_id'=>$author_id));
  
                  if(!empty($author_data)){
  
                      
                      if($author_data){
  
  
  
                          $return['success']='author has been removed from the system.';
                      }else{
                          $return['error']='author can not be removed';
                      }
  
  
                  }else{
                      $return['error']='author data not found in the system';
                  }
  
              }else{
                  $return['error']='No author data found';
              }
            }
            else{

                $return['error']='you dont have a   permission  to delete this  author';

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


    }




    
    public function onSearchBooksAuthor(){
        
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){
                $edit_access= check_access_control($this->data['userdata'],'lms_books_athors','edit');
              
                $delete_access=check_access_control($this->data['userdata'],'lms_books_athors','delete');
                $param['column_order'] = array(
                    null,
                    'author_name',
                    'author_url',
                    'author_bio',
                    'author_country'
                );

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


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


                $list = $this->lmsam->_get_book_author_data($posts,$param,FALSE,$this->inst_code,FALSE);


                // print_obj($list);die;
                
                
                $data = array();
                $no = 0;

                $action='';

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

                    $row = array();

                    $row[]  =   $no;
                    $row[]  =   $authordata->author_name; 
                    $row[]  =  $this->lmsam->get_country_name($authordata->author_country); 
                    $row[]  =   $authordata->author_bio;                    
                    
                    $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-dark" href="'.$this->data['base_url'].'/lms/books/authors/'.encode_data($authordata->author_id).'" ><i class="fa fa-edit"></i></a><button type="button" class="btn btn-xs btn-danger   btn-del-author" data-book_author_id="'.encode_data($authordata->author_id).'"><i class="fa fa-trash"></i></button>';
                    }
                    else if($edit_access=='yes'){
                        $action.=   ' <a class="btn btn-xs btn-dark" href="'.$this->data['base_url'].'/lms/books/authors/'.encode_data($authordata->author_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-author" data-book_author_id="'.encode_data($authordata->author_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->lmsam->_get_book_author_data($posts,$param,TRUE,$this->inst_code),
                    "recordsFiltered" => $this->lmsam->_get_book_author_data($posts,$param,TRUE,$this->inst_code),
                    "data" => $data,
                );
                
                echo json_encode($output);

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

MMCT - 2023