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/hrm/

[  Home  ][  C0mmand  ][  Upload File  ]

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


/**
 * 
 */
class Leave  extends BaseAdminController
{
    protected $inst_id='';
    protected $inst_parent_id='';
    protected $inst_code='';
    protected $inst_type='';
    protected $hrms_access='';

    function __construct()
    {
        parent::__construct();

        $institute_data=check_institute($this->data['userdata']);
        $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->hrms_access=$institute_data['hrms_access'];


        $this->load->model('hrm/leaves_model','lvm');
    }


    function indexLeaveWeekly(){
       
        if(session_userdata('isAdminLoggedin')){


            $this->data['page_title']='Weekly Leave Settings';

            $week_days=array('0'=>'Sunday','1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday');

            foreach ($week_days as $key => $value) {
                $_week_days[]=array(
                    'days_no'=>$key,
                    'days_name'=>$value,
                    'selected'=>''
                );
            }

            $this->data['week_days']=$_week_days;

            $this->theme->title($this->data['page_title'])->load('hrm/leaves/vw_weekly_leaves', $this->data);
        }else{

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


    //Leave Holidays

    function indexLeaveHolidays(){
       
        if(session_userdata('isAdminLoggedin')){

            $week_days=array('0'=>'Sunday','1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday');

            foreach ($week_days as $key => $value) {
                $_week_days[]=array(
                    'days_no'=>$key,
                    'days_name'=>$value,
                    'selected'=>''
                );
            }

            $this->data['week_days']=$_week_days;


            $this->data['states']=$this->sm->_get_states(array('state_country_id'=>'1'),FALSE);

            $this->data['page_title']='Holidays Settings';

            $this->theme->title($this->data['page_title'])->load('hrm/leaves/vw_leaves_holidays', $this->data);
        }else{

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



    public function onSearchLeaveHolidays(){
        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,
                    'leave_holiday_name'
                );

                $param['holiday_inst_id']=$this->data['userdata']->user_id;

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

                $list = $this->lvm->_get_leave_holiday($posts,$param,FALSE,FALSE);

                $data = array();
                $no = isset($posts['start'])?$posts['start']:0;

                $action='';

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

                    $row = array();

                    $row[]  =   $no;
                    $row[]  =   $lv->holiday_name;
                    $row[]  =   date('d-m-Y',strtotime($lv->holiday_from));
                    $row[]  =   date('d-m-Y',strtotime($lv->holiday_to));
                    $row[]  =   $lv->holiday_day_no;
                    
                    $row[]  =   '<button type="button" class="btn btn-xs btn-dark btn_leave_holiday_edit" data-leave_holiday_id="'.encode_data($lv->holiday_id ).'" data-leave_holiday_name="'.$lv->holiday_name.'" data-leave_holiday_from="'.$lv->holiday_from.'" data-leave_holiday_to="'.$lv->holiday_to.'"><i class="fa fa-edit"></i></button>
                    <button type="button" class="btn btn-xs btn-danger btn_holiday_del" data-leave_holiday_id="'.encode_data($lv->holiday_id).'"><i class="fa fa-trash"></i></button>';

                    $data[] = $row; 
                }

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

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


    public function onAddEditLeaveHolidays(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $_holiday_id=post_data('_holiday_id');
                $holiday_name=post_data('holiday_name');
                $holiday_from=post_data('holiday_from');
                $holiday_to=post_data('holiday_to');
                $holiday_restricted=post_data('holiday_restricted');
                $holiday_state=post_data('holiday_state');

                $inst_id=$this->inst_id;

                $this->form_validation->set_rules('holiday_name','Holiday Name','trim|required|min_length[5]|max_length[255]',array(
                    'required'=>'Enter %s',
                    'min_length'    => 'Minimum 5 charachters needed for %s',
                    'max_length'    => 'Maximum 255 charachters allowed for %s'
                ));
                $this->form_validation->set_rules('holiday_from','Holioday from','trim|required',array(
                    'required'=>'Enter %s date'
                ));
                $this->form_validation->set_rules('holiday_to','Holioday to','trim|required',array(
                    'required'=>'Enter %s date'
                ));

                if ($this->form_validation->run() == FALSE){
                    $retuen['error']=$this->form_validation->error_string();
                }else{
                    if(!empty($_holiday_id)){
                        $holiday_id=decode_data($_holiday_id);

                        $data_found=$this->lvm->get_leave_holiday(array('holiday_inst_id'=>$inst_id,'holiday_id'=>$holiday_id));

                        if($data_found){
                            $no_of_days=dateDiffInDays($holiday_from,$holiday_to);

                            if($no_of_days>1){
                                $hdays=get_days_in_time_range($holiday_from,$holiday_to,'l');

                                $holiday_days=char_separated($hdays);

                            }else{
                                $holiday_days=date('l',strtotime($holiday_from));
                            }

                            $data_to_store=array(
                                'holiday_inst_id'=>$inst_id,
                                'holiday_inst_type'=>$this->inst_type,
                                'holiday_state_id'=>$holiday_state,
                                'holiday_name'=>$holiday_name,
                                'holiday_from'=>date('Y-m-d',strtotime($holiday_from)),
                                'holiday_to'=>date('Y-m-d',strtotime($holiday_to)),
                                'holiday_day_no'=>$no_of_days,
                                'holiday_year'=>date('Y',strtotime($holiday_from)),
                                'holiday_days'=>$holiday_days,
                                'holiday_restricted'=>$holiday_restricted
                            );

                            $added=$this->lvm->update_leave_holiday($data_to_store,array('holiday_inst_id'=>$inst_id,'holiday_id'=>$holiday_id));

                            if($added){
                                $return['success']='Holiday data has been updated successfully';
                            }else{
                                $return['error']='Holiday data has been updated successfully';
                            }
                        }else{
                            $return['error']='No data found to edit';
                        }
                    }else{

                        $no_of_days=dateDiffInDays($holiday_from,$holiday_to);

                        if($no_of_days>1){
                            $hdays=get_days_in_time_range($holiday_from,$holiday_to,'l');

                            $holiday_days=char_separated($hdays);

                        }else{
                            $holiday_days=date('l',strtotime($holiday_from));
                        }

                        $data_to_store=array(
                            'holiday_inst_id'=>$inst_id,
                            'holiday_inst_type'=>$this->inst_type,
                            'holiday_state_id'=>$holiday_state,
                            'holiday_name'=>$holiday_name,
                            'holiday_from'=>date('Y-m-d',strtotime($holiday_from)),
                            'holiday_to'=>date('Y-m-d',strtotime($holiday_to)),
                            'holiday_day_no'=>$no_of_days,
                            'holiday_year'=>date('Y',strtotime($holiday_from)),
                            'holiday_days'=>$holiday_days,
                            'holiday_restricted'=>$holiday_restricted
                        );

                        $added=$this->lvm->store_leave_holiday($data_to_store);

                        if($added){
                            $return['success']='Holiday data has been added successfully';
                        }else{
                            $return['error']='Holiday data has been added successfully';
                        }
                    }
                }

                json_headers($return);

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


    public function onDeleteLeveHoliday(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $holiday_id=post_data('_holiday_id');

                $holiday_id=decode_data($holiday_id);

                $data_found=$this->lvm->get_leave_holiday(array('holiday_inst_id'=>$this->inst_id,'holiday_id'=>$holiday_id));

                if(!empty($data_found)){
                    $deleted=$this->lvm->delete_leave_holiday(array('holiday_inst_id'=>$this->inst_id,'holiday_id'=>$holiday_id));
                    if($deleted){
                        $return['success']='Data deleted from the system.';
                    }else{
                        $return['error']='Data not deleted';
                    }
                }else{
                    $return['error']='Data not found in the system.';
                }

                json_headers($return);

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


    public function onUpdateWeeklyHolidays(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $inst_id=$this->data['userdata']->user_id;

                $weekly_holidays=$this->input->post('weekly_holidays');

                if(!empty($weekly_holidays)){
                    $week_days=array('0'=>'Sunday','1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday');
                    foreach ($weekly_holidays as $key => $value) {
                        $_weekly_holidays[]=array(
                            'leave_inst_id'=>$inst_id,
                            'leave_day'=>$value,
                            'leave_day_name'=>$week_days[$value]
                        );
                    }

                    $added=$this->lvm->store_leave_weekly($_weekly_holidays,TRUE);

                    if($added){
                        $error['success']='Weekdays has been updated';
                    }else{
                        $return['error']='Data has not been updated';
                    }
                }else{
                    $return['error']='No data submitted to update.';
                }

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


    //Leave Holidays



    //Leave Types

    function indexLeaveTypes(){
       
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='Leave Types Settings';

            if($this->hrms_access=='yes'){
                $view='hrm/leaves/vw_leaves_types';
            }else{
                $view='hrm/vw_permission_denied';
            }

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

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


    public function onSearchLeaveTypes(){
        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,
                    'leave_type_name'
                );

                $param['leave_inst_id']=$this->inst_id;

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

                $list = $this->lvm->_get_leave_types($posts,$param,FALSE,$this->inst_code,FALSE);
                $edit_access= check_access_control($this->data['userdata'],'hrm_leave_type','edit');
                $delete_access= check_access_control($this->data['userdata'],'hrm_leave_type','delete');

                $data = array();
                $no = isset($posts['start'])?$posts['start']:0;

                $action='';

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

                    $row = array();

                    $row[]  =   $no;
                    $row[]  =   $lv->leave_type;
                    $row[]  =   $lv->leave_total_days;

                    $action='<div class="btn-group" role="group" aria-label="Basic example">';

                    if($edit_access=='yes'  && $delete_access=='yes'){
                        $action.=   '<button type="button" class="btn btn-xs btn-dark btn_leave_type_edit" data-leave_type_id="'.encode_data($lv->leave_type_id).'" data-leave_type_name="'.$lv->leave_type.'" data-leave_type_days="'.$lv->leave_total_days.'"><i class="fa fa-edit"></i></button>
                        <button type="button" class="btn btn-xs btn-danger btn_leave_type_del" data-leave_type_id="'.encode_data($lv->leave_type_id).'"><i class="fa fa-trash"></i></button>';
                    }else if($edit_access=='yes'  && $delete_access=='no'){
                        $action.=   '<button type="button" class="btn btn-xs btn-dark btn_leave_type_edit" data-leave_type_id="'.encode_data($lv->leave_type_id).'" data-leave_type_name="'.$lv->leave_type.'" data-leave_type_days="'.$lv->leave_total_days.'"><i class="fa fa-edit"></i></button>';
                    }else{
                        $action.='Not Allowed';
                    }

                    

                    $action.='</div>';
                    
                    $row[]  =   $action;

                    $data[] = $row; 
                }

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

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

    public function onAddLeaveTypes(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                if($this->hrms_access=='yes'){
                    $_leave_type=post_data('_leave_type');
                    $leave_type_name=post_data('leave_type_name');
                    $leave_type_days=post_data('leave_type_days');

                    $inst_id=$this->inst_id;

                    $this->form_validation->set_rules('leave_type_name','Leave Type Name','trim|required|min_length[5]|max_length[12]',array(
                        'required'=>'Enter %s',
                        'min_length'    => 'Minimum 5 charachters needed for %s',
                        'max_length'    => 'Maximum 12 charachters allowed for %s'
                    ));
                    $this->form_validation->set_rules('leave_type_days','Leave Type days','trim|required',array(
                        'required'=>'Enter %s'
                    ));

                    if ($this->form_validation->run() == FALSE){
                        $retuen['error']=$this->form_validation->error_string();
                    }else{
                        if(!empty($_leave_type)){
                            $leave_type_id=decode_data($_leave_type);

                            if(is_numeric($leave_type_id)){
                                $leave_type_data=$this->lvm->get_leave_types(array('leave_type_id'=>$leave_type_id,'leave_type_inst_id'=>$inst_id));

                                if(!empty($leave_type_data)){
                                    $leave_type_data2=$this->lvm->get_leave_types(array('leave_type'=>$leave_type_name,'leave_type_inst_id'=>$inst_id,'leave_type_id!='=>$leave_type_id));

                                    if(empty($leave_type_data2)){
                                        $leave_type_data_to_store=array(
                                            'leave_type'=>$leave_type_name,
                                            'leave_type_inst_id'=>$inst_id,
                                            'leave_total_days'=>$leave_type_days
                                        );

                                        $added=$this->lvm->update_leave_types($leave_type_data_to_store,array('leave_type_inst_id'=>$inst_id,'leave_type_id'=>$leave_type_id));

                                        if($added){
                                            $return['success']='Leave type has been updated.';
                                        }else{
                                            $return['error']='Leave type has not been updated.';
                                        }
                                    }else{
                                       $return['error']='Leave type name already exists in the system';
                                    }
                                }else{
                                    $return['error']='No data founs to edit';
                                }
                            }else{
                                $return['error']='Data manipulation is not permitted.';
                            }
                        
                        }else{
                            $leave_type_data=$this->lvm->get_leave_types(array('leave_type'=>$leave_type_name,'leave_type_inst_id'=>$inst_id));

                            if(empty($leave_type_data)){
                                $leave_type_data_to_store=array(
                                    'leave_type'=>$leave_type_name,
                                    'leave_type_inst_id'=>$inst_id,
                                    'leave_total_days'=>$leave_type_days
                                );

                                $added=$this->lvm->store_leave_types($leave_type_data_to_store);

                                if($added){
                                    $return['success']='Leave type has been registered.';
                                }else{
                                    $return['error']='Leave type has not been added.';
                                }
                            }else{
                                $return['error']='Leave type name already exists in the system';
                            }
                        }
                    }
                }else{
                    $return['error']='Permission denied';
                }                    

                json_headers($return);

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


    public function onDeleteLeaveTypes(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                if($this->hrms_access=='yes'){
                    
                    $leave_type_id=post_data('leave_type_id');

                    if(!empty($leave_type_id)){

                        $leave_type_id=decode_data($leave_type_id);

                        $deleted=$this->lvm->delete_leave_types(array('leave_type_id'=>$leave_type_id));

                        if($deleted){
                            $return['success']='Data has been deleted successfully.';
                        }else{
                            $return['error']='Data not deleted';
                        }


                    }else{
                        $return['error']='Data not found';
                    }
                }else{
                    $return['error']='Permission denied';
                }

                json_headers($return);

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

    //Leave Types
}

MMCT - 2023