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

class Welcome extends CI_Controller {
    public function __construct(){
        parent::__construct();
        $this->load->helper('text');
        $this->load->helper(array('form','url'));
        date_default_timezone_set('Asia/Kolkata');
        $this->load->model('FeeModel');
        $this->load->model('WelcomeModel');
        $this->load->model('LoginModel');
        $this->load->model('AttendenceModel');
        // $this->load->model('CalenderModel');
        $this->load->model('SchoolModel');
        $this->load->model('NewFeeModel');
        $this->load->model('OpeningBalanceModel');
        $this->load->model('UserModel');
        $this->load->helper('date');
        $this->load->database();    
        $this->load->library('form_validation');
        $this->load->helper(array('form', 'url'));
        $this->load->library('session');
        // $this->load->library('Pdf');
    }
    
    public function test(){
        $this->load->view('newtheme/header');
        // $this->load->view('newtheme/navbar');
        $this->load->view('newtheme/sidebar');
        $this->load->view('erp/new-fee/my-day-collection');
        $this->load->view('newtheme/footer');
    }
    
    public function old_theme(){
        
        $this->load->view('erp/old-theme/header');
        // $this->load->view('newtheme/navbar');
        $this->load->view('erp/old-theme/sidebar');
        $this->load->view('erp/welcome/new-welcome');
        $this->load->view('erp/old-theme/footer');
    }
    public function index(){
        $this->load->view('erp/header');
        $this->load->view('erp/sidebar');
        if($this->session->userdata('admin')==1){
            // $this->load->view('erp/welcome/management-welcome');
            $this->load->view('erp/welcome/new-welcome');
            
            // $this->load->view('erp/welcome/dash-items');
            $this->load->view('erp/new-fee/today-collection');
            // $this->load->view('erp/management/all-fee-admins');
            // $this->load->view('erp/welcome/opening-balance-dashboard');
            $this->load->view('erp/staff-attendance/management-dash');
            // $this->load->view('erp/welcome/opening-balance-data');
        }else if($this->session->userdata('fee') ==1){
            $this->load->view('erp/welcome/new-welcome');
            $this->load->view('erp/new-fee/my-day-collection');
            $this->load->view('erp/new-fee/my-collection');
            // $this->load->view('erp/welcome/opening-balance-dashboard');
        }else if($this->session->userdata('user')==1 && $this->session->userdata('fee') !=1){
            $this->load->view('erp/welcome/teaching-staff-welcome');
        }else{echo "No data";}
        $this->load->view('erp/staff-attendance/dashboard');
        $eid=$this->session->userdata('tid');
        $date=date('Y-m-d');
        $check_day_status=$this->UserModel->check_day_attendance($date,$eid);
        $markout_status=0;
        if($check_day_status){
            foreach($check_day_status as $data1){  
                $markout_status=$data1['is_markout'];    
            }
            if($markout_status==0){
                // $this->load->view('erp/staff-attendance/attendance');         
            }
        }
        $this->load->view('erp/staff-attendance/daily-log');
        $this->load->view('erp/footer');  
    }
    
    
    public function my_collection(){
        $this->load->view('erp/header');
        $this->load->view('erp/sidebar');
        $this->load->view('erp/new-fee/my-day-collection');
        $this->load->view('erp/footer');  
    }
    
    public function change_ac_session(){
        $acedemic_session=$_POST['ac_session_id'];
        $tid=$this->session->userdata('tid');
        $class_teacher=$this->session->userdata('class_teacher');
        if($class_teacher !=''){
            $get_teacher_data=$this->WelcomeModel->class_teacher_info($acedemic_session,$tid);
            if($get_teacher_data){
                foreach($get_teacher_data as $data){
                    $this->session->set_userdata('class_teacher',$data['class']);
                    $this->session->set_userdata('class_teacher_section',$data['section']);
                }
            }
            }else{  
    
            }
            // $section = $this->session->userdata('class_teacher_section');	
            // $table='attendence';
            // $date = date('Y-m-d');
            // $class=$this->session->userdata('class_teacher');
            $acedemic_session_table='academic_session_details';
            $get_ac_year_data=$this->WelcomeModel->get_item_data($acedemic_session,$acedemic_session_table);
            if($get_ac_year_data){
                foreach($get_ac_year_data as $ac_year_data){
                    $this->session->set_userdata('ac_year',$ac_year_data['year_long']);
                }
            }
            $this->session->set_userdata('acedemic_session',$acedemic_session);
        

        }


        public function add_login_credentials(){
            $mm='6388955251';
            echo md5($mm);



            // $all_teachers=$this->LoginModel->all_teachers();
            // if($all_teachers){
            // foreach($all_teachers as $teachers){
            // $data_array=array("user_id"=>$teachers['id'],"Name"=>$teachers['name'],"mob_number"=>$teachers['mobile_number'],"usertype"=>"staff","password"=>md5($teachers['password']),"status"=>$teachers['user_status'],"username"=>$teachers['mobile_number']);
            // $add_login_user=$this->LoginModel->add_login_user($data_array);
            // echo $add_login_user;
            // }    
            // }
            // else{
            // echo "No teacher found";    
            // }
        


            // $all_students=$this->LoginModel->all_students();
            // if($all_students){
            // $count=0;        
            // foreach($all_students as $students){
            // $count =$count + 1;    
            // $data_array=array("user_id"=>$students['id'],"sch_no"=>$students['sch_no'],"Name"=>$students['student_name'],"mob_number"=>$students['contact_no'],"usertype"=>"student","password"=>md5($students['password']),"status"=>$students['status'],"username"=>$students['sch_no']);
            // $add_login_user=$this->LoginModel->add_login_user($data_array);
            // // echo $add_login_user;
            // }  
        
            // echo $count;
            // }
            // else{
            // echo "No teacher found";    
            // }
        
    }

    // public function share_datafor_class(){
        // // $this->load->view('erp/data-share');

        // $class=9;
        // $get_data=$this->SchoolModel->get_class_data($class);
        // if($get_data){
        // foreach($get_data as $data){

        // $Adm_No=$data['sch_no'];
        // $Name=$data['student_name'];
        // $Class=$data['class'];
        // $section=$data['section'];
        // $Gender=$data['gender'];
        // $Fathers_Name=$data['father_name'];
        // $Mothers_Name=$data['mother_name'];
    
        // $data_array=array("Adm_No"=>$Adm_No,"Name"=>$Name,"Gender"=>$Gender,"Class"=>$Class,"section"=>$section,"Fathers_Name"=>$Fathers_Name,"Mothers_Name"=>$Mothers_Name,"unit"=>2);
        // $add_data=$this->SchoolModel->add_class_data($data_array);
        // if($add_data){
        // echo $add_data;    
        // }else{echo "error:No record added";}
        
        // }    
            // }else{echo "no data found";}

    // }
    
    public function attendance(){
        $this->load->view('erp/header');
        $this->load->view('erp/sidebar');
        // $this->load->view('erp/staff-attendance/management-dash');
        $this->load->view('erp/staff-attendance/dashboard');
        $eid=$this->session->userdata('tid');
        $date=date('Y-m-d');
        $check_day_status=$this->UserModel->check_day_attendance($date,$eid);
        $markout_status=0;
        if($check_day_status){
            foreach($check_day_status as $data1){  
                $markout_status=$data1['is_markout'];    
            }
            if($markout_status==0){
                // $this->load->view('erp/staff-attendance/attendance');         
            }
        }
        $this->load->view('erp/staff-attendance/daily-log');
        $this->load->view('erp/footer'); 
    }
    
    public function markin_location($id){
        $this->load->view('erp/header');
        $this->load->view('erp/sidebar');
        $this->load->view('erp/staff-attendance/markin-location-view');
        $this->load->view('erp/footer');
    }

}