<commit_before><?php
  class Users extends CI_Model {

        public function __construct()
        {
                $this->load->database();
                $this->load->library('session');

                 // added by <NAME>
                $this->load->helper('form');
                $this->load->library('encrypt');

                parent::__construct();      
        }


        public function saveEmail($hash){
                $username = $this->session->userdata['id_number'];
                $email = $_POST['email'];
                return $this->db->query("INSERT INTO email (id_number, email_address, hash) VALUES('$username','$email', '$hash')");     
        }


        public function queryUserByEmail($email){
              // $email = $_POST['reset_email'];
              $result= $this->db->query("SELECT id_number from email where email_address = '$email'")->row();

             return $result;
        }



        public function insertPersonalData(){
                // print_r($_POST);exit;
               $result = $this->db->query("SELECT id_number FROM personal_details WHERE id_number ='14-2649-276'")->result_array();
               // print_r($result);
                if (empty($result)) {
                     return $this->db->insert('personal_details', $_POST);   
                }else{

                }                
        }

        public function resetUserPassword($username){
          $password = $_POST['<PASSWORD>'];
          $this->db->query("UPDATE users SET password = <PASSWORD>' WHERE id_number = '$username'");
        }


        public function insertFamilyData(){

                $result = $this->db->query("SELECT id_number FROM family_details WHERE id_number ='14-2649-276'")->result_array();
               // print_r($result);
                if (empty($result)) {
                     return $this->db->insert('family_details', $_POST);   
                }else{

                }
        } 

        public function insertEmergencyData(){
                $result = $this->db->query("SELECT id_number FROM emergency_details WHERE id_number ='14-2649-276'")->result_array();
               // print_r($result);
                if (empty($result)) {
                     return $this->db->insert('emergency_details', $_POST);   
                }else{

                }
        }

        public function updateAnnouncemment($username){
            $announcement_id = $_POST['announcement_id'];
            $this->db->query("UPDATE announcements SET status = 1, date_posted = date_posted WHERE id = $announcement_id AND username = '$username'");
        }

        public function getNumberUnreadAnnouncements($username){
            $query = $this->db->query("SELECT count(status) as numberUnread FROM announcements WHERE username = '$username' AND status = 0")->row();

            return $query;
        }

        public function updateAnnouncemmentToUnreadAll(){
            $username = $_POST['username'];
            $this->db->query("UPDATE announcements SET status = 1, date_posted = date_posted WHERE username = '$username'");
        }
        public function updateAnnouncemmentToUnread($username){
            $announcement_id = $_POST['announcement_id'];
            $this->db->query("UPDATE announcements SET status = 0, date_posted = date_posted WHERE id = $announcement_id AND username = '$username'");
        }

        public function getAnnouncements($username){
            $query = $this->db->query("SELECT a.id, admin_id,content,username,status,date_posted,announcement_id,name,id_number FROM announcements as a INNER JOIN admin ON a.admin_id = admin.id_number WHERE a.username = '$username' ORDER BY a.id DESC");
            return $query->result_array();
        }
        public function getAnnouncementsForStudents(){
            $announcement_id = $_POST['announcement_id'];
            $query = $this->db->query("SELECT * FROM announcements WHERE id = '$announcement_id'")->row();
            
            echo json_encode($query);
        }

        public function user_login(){
                $username = $_POST['username']; //need to be dynamic
                $password = $_POST['password']; //need to be dynamic
                $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username' AND password = '$password'");
                //print_r($result->result_array());
                $affectedRows = $this->db->affected_rows();
                
               if($affectedRows>0){
                    return true;
                        
                }else{
                    return false;
                }
        }

         public function user_login_administrator(){
                $username = $_POST['username']; //need to be dynamic
                $password = $_POST['password']; //need to be dynamic
                $result = $this->db->query("SELECT * FROM admin WHERE id_number = '$username' AND password = '$password'");
                //print_r($result->result_array());
                $affectedRows = $this->db->affected_rows();
                
               if($affectedRows>0){
                    return true;
                        
                }else{
                    return false;
                }
        }

        public function insertAnnouncement($id){
            $usernames = $this->db->query("SELECT id_number FROM users WHERE admin_id = '$id'")->result_array();
            $i = $this->db->query("SELECT MAX(announcement_id) as max_id FROM announcements")->row();
            $announcement = $this->input->post('announcement');
            $insert_announce = mysqli_real_escape_string($this->get_mysqli(),$announcement);
            if(empty($i->max_id)){
              $i=1;
              foreach ($usernames as $username)    {
                $stud_username = $username['id_number'];

                $this->db->query("INSERT INTO announcements(admin_id,content, username,announcement_id) VALUES ('$id','$insert_announce', '$stud_username','$i')");
            
            }
            }else{
              
            $i = $i+$i->max_id;
            foreach ($usernames as $username)    {
                $stud_username = $username['id_number'];

                $this->db->query("INSERT INTO announcements(admin_id,content, username,announcement_id) VALUES ('$id','$insert_announce', '$stud_username','$i')");
            
              }
            }
            
        }

      public  function get_mysqli() { 
                $db = (array)get_instance()->db;
                return mysqli_connect('localhost', $db['username'], $db['password'], $db['database']);
            }

        public function readUserAdmin($data){
            $username = $data['username'];
            $password = $data['password'];
      
            $result = $this->db->query("SELECT * FROM admin WHERE id_number = '$username' AND password = '$password'");
            return $result->result_array();

         
         }

         public function user_login_supervisor(){
                $username = $_POST['username']; //need to be dynamic
                $password = $_POST['password']; //need to be dynamic
                $result = $this->db->query("SELECT * FROM supervisor WHERE id_number = '$username' AND password = '$password'");
                //print_r($result->result_array());
                $affectedRows = $this->db->affected_rows();
                
               if($affectedRows>0){
                    return true;
                        
                }else{
                    return false;
                }
        }

      public function readUserId($data){
        $username = $data['username'];
        $password = $data['password'];
  
        $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username' AND password = '$password'");
        return $result->result_array();

         
         }

         public function readUserSupervisor($data){
             $username = $data['username'];
             $password = $data['password'];
  
            $result = $this->db->query("SELECT * FROM supervisor WHERE id_number = '$username' AND password = '$password'");
             return $result->result_array();
         }




        public function supervisorGetTrainee($company_name,$username){

          $company_name2 = $company_name[0]['company_name'];
            $query = $this->db->query("SELECT users.id_number, users.first_name, users.last_name FROM users INNER JOIN company_information ON users.id_number = company_information.id_number WHERE company_information.company_name = '$company_name2' AND supervisor_id = '' AND transitioned = '0'");
           return $query->result_array();
       }


       
        public function getCompanyNames(){
            $query = $this->db->query("SELECT DISTINCT company_name FROM company_information ORDER BY company_name ASC");

           return $query->result_array();
         }

         public function getCompanyWatchlist(){
            $query = $this->db->query("SELECT DISTINCT company_name FROM company_information WHERE watchlisted = 0");
           return $query->result_array();
         }
         public function getCompanySupervisor($id_number){
             $query = $this->db->query("SELECT company_name FROM supervisor WHERE id_number= '$id_number'");
             return $query->result_array();
         }

         public function getAccountType($data){
           $username = $data;
            $result = $this->db->query("SELECT account_type FROM users WHERE id_number = '$username'");
            return $result->result_array();
         }

        //  public function dashboardDataAdmin($data){   
        //        $username = $data;
             
        //         $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username'");
        //         return $result->result_array();


        // }

         public function getStudentList(){
          $admin_id = $this->session->userdata('id_number');
          $query = $this->db->query("SELECT * FROM users INNER JOIN ojt_records ON users.id_number = ojt_records.id_number WHERE users.status!='DELETED' AND users.admin_id = '$admin_id'");

            return $query->result_array();
         }

        public function insertLogs(){

            $id_number = $_POST['id_number'];
            $date =  $_POST['log_date'];
            $time_in = $_POST['time_in'];
            $time_out = $_POST['time_out'];
            $division = $_POST['division'];
            $department = $_POST['department'];
            $designation = $_POST['designation'];
            $log_content = $_POST['log_activity'];
            $hours_rendered = $_POST['hours_rendered'];
            $supervisor_id = empty($_POST['supervisor_id']) ? '' : $_POST['supervisor_id'];
            $ojt_program = $this->getOjtProgramForStud($id_number);
            $ojtP = $ojt_program->ojt_program;
            $data = Array(
            'id_number' => $id_number,
            'date' => $date,
            'time_in' => $time_in,
            'time_out' => $time_out,
            'division' => $division,
            'department' => $department,
            'designation' => $designation,
            'log_content' => $log_content,
            'hours_rendered' => $hours_rendered,
            'supervisor_id' => $supervisor_id,
            'ojt_program' => $ojtP
            );
            $existDate = $this->db->query("SELECT * FROM logs WHERE date = '$date' AND id_number = '$id_number' AND ojt_program = '$ojtP'")->result();

            if(!empty($existDate)){
              echo 'dateexist';
            }else{
               $this->db->insert('logs',$data);
            }
          


        }

        public function getLogs($data,$limit, $start, $ojt_program){
            $username = $data;
              $this->db->limit($limit, $start);
              $this->db->select('*');
              $this->db->where('id_number', $username);
              $this->db->where('ojt_program', $ojt_program);
              $this->db->from('logs');
              $this->db->order_by('id', 'DESC');
              $result = $this->db->get();
              // print_r($result->result_array());
            // $result = $this->db->query("SELECT * FROM logs WHERE id_number = '$username' ORDER BY id DESC");
            return $result->result_array();
        }

        public function getLogsForStuds($id_number, $ojt_program){
         
              $this->db->select('*');
              $this->db->where('id_number', $id_number);
              $this->db->where('ojt_program', $ojt_program);
              $this->db->from('logs');
              $this->db->order_by('id', 'DESC');
              $result = $this->db->get();
              return $result->result_array();
        }

        public function deleteLog(){
            $id = $_POST['log_id'];
            $this->db->where('id', $id);
            $this->db->delete('logs');

            $this->db->where('log_id', $id);
            $this->db->delete('comments');
        }

         public function dashboardData($id_number){   
             $username = $id_number;         
             $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username'");
             return $result->result_array();


        }

        public function dashboardDataRecords($id_number, $ojt_program){   
            $username = $id_number;
            if($ojt_program == 'ojt_one'){
              $result = $this->db->query("SELECT ojtone_required as required, ojtone_rendered as rendered, total_evaluations as total, ojtone_current_evaluations as current_eval, logs_one as total_logs, logs_one_verified as verified_logs FROM ojt_records WHERE id_number = '$username'");
            }else{
              $result = $this->db->query("SELECT ojttwo_required as required, ojttwo_rendered as rendered, total_evaluations as total, ojttwo_current_evaluations as current_eval, logs_two as total_logs, logs_two_verified as verified_logs  FROM ojt_records WHERE id_number = '$username'");
            }
            
                  
           return $result->result_array();
         }   

         public function getOjtRecordsForSupervisor($username){
            $result = $this->db->query("SELECT ojt_records.id_number, ojt_records.ojtone_required,ojt_records.ojtone_rendered,ojt_records.ojttwo_rendered, ojt_records.ojttwo_required, users.first_name, users.last_name, users.ojt_program FROM ojt_records INNER JOIN users ON users.id_number = ojt_records.id_number WHERE supervisor_id = '$username'");         

            // echo '<pre>';print_r($result->result_array()); echo'</pre>';
            return $result->result_array();
         }

         public function filterStud(){
          $admin_id = $this->session->userdata('id_number');
          $html = '';
          $course = empty($_POST['course']) ? '' : $_POST['course'];
          $sy = empty($_POST['sy']) ? '' : $_POST['sy'];
          $eval = empty($_POST['eval']) ? '' : $_POST['eval'];
          $stat = empty($_POST['stat']) ? '' : $_POST['stat'];
          
          if($sy == 'all'){
            $sy = '';
          }
          if($eval == 'all'){
            $eval = '';
          }
          if($eval == 'None'){
            $eval = '0';
          }
          if($course == 'all'){
            $course = '';
          }
          if($stat == 'all'){
            $stat = '';
          }

          ///echo $eval;exit;
          if(empty($sy)){
              $query = $this->db->query("SELECT * FROM users INNER JOIN ojt_records ON users.id_number = ojt_records.id_number WHERE status!='DELETED' AND users.admin_id = '$admin_id' AND users.course LIKE '%$course%' AND ojtone_current_evaluations LIKE '%$eval%' || ojttwo_current_evaluations LIKE '%$eval%' AND ojtone_status LIKE '%$stat%' ORDER BY users.id_number");
          }else{
              $query = $this->db->query("SELECT * FROM users INNER JOIN ojt_records ON users.id_number = ojt_records.id_number WHERE status!='DELETED' AND users.admin_id = '$admin_id' AND users.course LIKE '%$course%' AND school_year = '$sy' AND ojtone_current_evaluations LIKE '%$eval%' AND ojtone_status LIKE '%$stat%' ORDER BY users.id_number ASC");
          }
          return $query->result_array();
        }

         public function editLog(){
            $id = $_POST['log_id'];
            $date = $_POST['date'];
            $time_in = $_POST['time_in'];
            $time_out = $_POST['time_out'];
            $division = $_POST['division'];
            $department = $_POST['department'];
            $designation = $_POST['designation'];
            $log_activity = $_POST['log_activity'];
            $hours_rendered = $_POST['hours_rendered'];

            return $this->db->query("UPDATE logs SET date = '$date', time_in = '$time_in', time_out = '$time_out', division = '$division', department = '$division', designation = '$designation', log_content = '$log_activity', hours_rendered = '$hours_rendered'  WHERE id = $id");

         }
        public function getNumberLogs($data, $ojt_program){
            $id = $data;

            $result = $this->db->query("SELECT COUNT(logs.id) as logscount FROM logs WHERE id_number = '$id' AND ojt_program = '$ojt_program' ");
            return $result->result_array();
        }


        public function getMidtermEvaluations($username, $ojt_program){

          $query =  $this->db->query("SELECT * FROM midterm_evaluation WHERE username = '$username' AND ojt_program = '$ojt_program'");

          return $query->row();
        }
        public function getFinalEvaluations($username, $ojt_program){

          $query =  $this->db->query("SELECT * FROM final_evaluation WHERE username = '$username' AND ojt_program = '$ojt_program'");

          return $query->row();
        }
        public function getSumRendered($data, $ojt_program){
            $id = $data;

            $query = $this->db->query("SELECT SUM(hours_rendered) AS rendered FROM logs WHERE (id_number ='$id' AND verified = 1) AND ojt_program = '$ojt_program'");
            return $query->result_array();
        }

        public function updateLogCount($logscount,$id, $ojt_program){
          if($ojt_program == 'ojt_one'){
             $this->db->query("UPDATE ojt_records SET logs_one = $logscount WHERE id_number ='$id'");
          }else{
            $this->db->query("UPDATE ojt_records SET logs_two = $logscount WHERE id_number ='$id'");
          }
        }
        public function updateLogsVerifiedCount($logscount, $id, $ojt_program){

             if($ojt_program == 'ojt_two'){
              
                 $this->db->query("UPDATE ojt_records SET logs_two_verified = $logscount WHERE id_number = '$id'");
             }else{
              
                $this->db->query("UPDATE ojt_records SET logs_one_verified = $logscount WHERE id_number = '$id'");
             }
            
        }

        public function updateRenderedHours($hours, $id, $ojt_program){

            if($ojt_program == 'ojt_one'){

             $this->db->query("UPDATE ojt_records SET ojtone_rendered = $hours WHERE id_number = '$id'");
            }else{
              $this->db->query("UPDATE ojt_records SET ojttwo_rendered = $hours WHERE id_number = '$id'");
            }
        }

        public function getNumberLogsVerified($data, $ojt_program){
             $id = $data;
            $result = $this->db->query("SELECT COUNT(verified) as logscount FROM logs WHERE id_number = '$id' AND ojt_program = '$ojt_program' AND verified = 1");
            return $result->result_array();
        }

        public function insertNewRecordOjt($data){
            return $this->db->insert('ojt_records', $data);
        }

        public function getOjtLogs($id, $ojt_program){
          $logs = array(array(
            'id'=>'',
            'id_number'=>'',
            'date'=>'',
            'time_in'=>'',
            'time_out'=>'',
            'first_name'=>'',
            'last_name'=>'',
            'user_image'=>'',
            'department'=>'',
            'designation'=>'',
            'division'=>'',
            'hours_rendered'=>'',
            'verified'=>'',
            'log_content'=>''
          ));
          $i =0;
     
                  foreach ($ojt_program as $key => $program) {
                    $p = $program['ojt_program'];
                    // echo $p;
                    $d = $program['username'];
         

                    $query = $this->db->query("SELECT logs.id, logs.ojt_program, logs.id_number, logs.date, logs.time_in, logs.time_out, logs.division, logs.department, logs.designation, logs.log_content, logs.hours_rendered, logs.verified, users.first_name, users.last_name, users.user_image FROM logs INNER JOIN users ON logs.id_number = users.id_number WHERE logs.ojt_program = '$p' AND logs.id_number = '$d'")->result();
                      
                  
                        
                        foreach ($query as $key => $value) {
                            $logs[$i]['id'] = $value->id;
                            // $logs[$i]['p'] = $value->ojt_program;
                            $logs[$i]['id_number'] = $value->id_number;
                            $logs[$i]['date'] = $value->date;
                            $logs[$i]['time_in'] = $value->time_in;
                            $logs[$i]['time_out'] = $value->time_out;
                            $logs[$i]['first_name'] = $value->first_name;
                            $logs[$i]['last_name'] = $value->last_name;
                            $logs[$i]['user_image'] = $value->user_image;
                            $logs[$i]['department'] = $value->department;
                            $logs[$i]['designation'] = $value->designation;
                            $logs[$i]['division'] = $value->division;
                            $logs[$i]['hours_rendered'] = $value->hours_rendered;
                            $logs[$i]['verified'] = $value->verified;
                            $logs[$i]['log_content'] = $value->log_content;
                            $i++;
                        }

                    }

                     if($logs[0]['log_content'] == ''){
                      foreach ($logs as $key => $value) {
                          $key = array_search($value, $logs);

                          unset($logs[$key]);
                      }
                      return $logs;
                  }else{
                    return $logs;
                  }
            
           // echo '<pre>'; print_r($logs); echo '</pre>';
          
           
            return $logs;
        }

          public function filterLogsForSupervisor($id){
      // print_r($_POST);exit;
          $current_ojt_program = $this->getOjtProgramForStudSup($id);
          // echo '<pre>'; print_r($current_ojt_program); echo '</pre>';
        $status = $_POST['status'];
          $logs = array(array(
            'id'=>'',
            'id_number'=>'',
            'date'=>'',
            'time_in'=>'',
            'time_out'=>'',
            'first_name'=>'',
            'last_name'=>'',
            'user_image'=>'',
            'department'=>'',
            'designation'=>'',
            'division'=>'',
            'hours_rendered'=>'',
            'verified'=>'',
            'log_content'=>''
          ));
          $i =0;


        $stud = empty($_POST['stud_id']) ? '' : $_POST['stud_id'];

          if($status == 'all'){
             foreach ($current_ojt_program as $key => $program) {
              $p = $program['ojt_program'];
              $d = $program['username'];
             $query = $this->db->query("SELECT logs.id, logs.id_number, logs.date, logs.time_in, logs.time_out, logs.division, logs.department, logs.designation, logs.log_content, logs.hours_rendered, logs.verified, users.first_name, users.last_name, users.user_image FROM logs INNER JOIN users ON users.id_number = logs.id_number  WHERE logs.supervisor_id = '$id' AND logs.ojt_program = '$p' AND logs.id_number = '$d' AND users.id_number LIKE '%$stud%' ORDER BY id DESC")->result();
                if(!empty($query)){
                      foreach ($query as $key => $value) {
                            $logs[$i]['id'] = $value->id;
                            // echo value;
                            // $logs[$i]['p'] = $value->ojt_program;
                            $logs[$i]['id_number'] = $value->id_number;
                            $logs[$i]['date'] = $value->date;
                            $logs[$i]['time_in'] = $value->time_in;
                            $logs[$i]['time_out'] = $value->time_out;
                            $logs[$i]['first_name'] = $value->first_name;
                            $logs[$i]['last_name'] = $value->last_name;
                            $logs[$i]['user_image'] = $value->user_image;
                            $logs[$i]['department'] = $value->department;
                            $logs[$i]['designation'] = $value->designation;
                            $logs[$i]['division'] = $value->division;
                            $logs[$i]['hours_rendered'] = $value->hours_rendered;
                            $logs[$i]['verified'] = $value->verified;
                            $logs[$i]['log_content'] = $value->log_content;
                            $i++;
                    }
                }
               


            }
          }else{
            // echo "hey";exit;
            foreach ($current_ojt_program as $key => $program) {
              $p = $program['ojt_program'];
              $d = $program['username'];
              // echo $p;
              $query = $this->db->query("SELECT logs.id, logs.id_number, logs.ojt_program, logs.date, logs.time_in, logs.time_out, logs.division, logs.department, logs.designation, logs.log_content, logs.hours_rendered, logs.verified, users.first_name, users.last_name, users.user_image FROM logs INNER JOIN users ON users.id_number = logs.id_number  WHERE logs.supervisor_id = '$id' AND verified = $status AND users.id_number LIKE '%$stud%' AND logs.ojt_program = '$p' AND logs.id_number = '$d' ORDER BY id DESC")->result();
                // print_r($query);
                if(!empty($query)){
                    foreach ($query as $key => $value) {
                            $logs[$i]['id'] = $value->id;
                            // echo value;
                            $logs[$i]['p'] = $value->ojt_program;
                            $logs[$i]['id_number'] = $value->id_number;
                            $logs[$i]['date'] = $value->date;
                            $logs[$i]['time_in'] = $value->time_in;
                            $logs[$i]['time_out'] = $value->time_out;
                            $logs[$i]['first_name'] = $value->first_name;
                            $logs[$i]['last_name'] = $value->last_name;
                            $logs[$i]['user_image'] = $value->user_image;
                            $logs[$i]['department'] = $value->department;
                            $logs[$i]['designation'] = $value->designation;
                            $logs[$i]['division'] = $value->division;
                            $logs[$i]['hours_rendered'] = $value->hours_rendered;
                            $logs[$i]['verified'] = $value->verified;
                            $logs[$i]['log_content'] = $value->log_content;
                            $i++;
                  }
                }
                

            }
            
          }
            
          if($logs[0]['log_content'] == ''){
              foreach ($logs as $key => $value) {
                  $key = array_search($value, $logs);

                  unset($logs[$key]);
              }
              return $logs;
          }else{
            return $logs;
          }

          
      }

         public function getNotVerified($username, $ojt_program){
           $count = array();
            $i=0;
            $total = 0;
          foreach ($ojt_program as $key => $program) {
            $p = $program['ojt_program'];
            $d = $program['username'];
           
            $query = $this->db->query("SELECT count(verified) as not_verified from logs WHERE supervisor_id = '$username' AND ojt_program = '$p' AND id_number = '$d' AND verified = 0")->result();

              foreach ($query as $key => $value) {
                  $count[$i] = $value->not_verified;
                  $i++;
              }
          }

          foreach ($count as $value) {
            $total += $value;
          }
          

         return $total; 
            
         
         
      }

        public function updateLog(){
            $log_id = $_POST['log_id'];
             $this->db->query("UPDATE logs SET verified = 1 WHERE id = $log_id");
        }

        public function unverifyLog(){
            $log_id = $_POST['log_id'];
             $this->db->query("UPDATE logs SET verified = 0 WHERE id = $log_id");
        }
            
        public function getComments(){
            $query = $this->db->query("SELECT * FROM comments");

            return $query->result_array();
        }
        public function updateOJTStatus($id, $ojt_program){

           if($ojt_program == 'ojt_one'){
            $this->db->query("UPDATE ojt_records SET ojtone_status = 'COMPLETED' WHERE ojtone_rendered >= ojtone_required AND ojtone_current_evaluations >= 2 AND id_number = '$id'");
          }else{
              $this->db->query("UPDATE ojt_records SET ojttwo_status = 'COMPLETED' WHERE ojttwo_rendered >= ojttwo_rendered AND ojttwo_current_evaluations >= 2 AND id_number = '$id'");
          }
           
        }
        public function updatePassword($id,$account_type){

            if($account_type == 'admin'){
                 $old_pass = $this->db->query("SELECT password FROM admin WHERE id_number = '$id'")->row();
             
              $new_pass = $_POST['<PASSWORD>pass'];
              $confirm = $_POST['confirm_newpass'];
              $old = $_POST['old_password'];
              if($old!=$old_pass->password){
                echo "old_not_match_admin";exit;
                 //echo '<script>alert("Old passwords did not match");  window.location.href = "changepassword"</script>';
              }else{
                 $this->db->query("UPDATE admin SET password = '$<PASSWORD>' WHERE id_number = '$id'");
                 //echo '<script>alert("Password successfully changed"); window.location.href = "admindashboard";</script> ';

              }
            }else if($account_type == 'student'){
                 $old_pass = $this->db->query("SELECT password FROM users WHERE id_number = '$id'")->row();
           
            $new_pass = $_POST['newpass'];
            $confirm = $_POST['confirm_newpass'];
            $old = $_POST['old_password'];
            if($old!=$old_pass->password){
               //echo '<script>alert("Old passwords did not match");  window.location.href = "changepassword"</script>';
              echo "old_not_match_student";exit;
            }else{
               $this->db->query("UPDATE users SET password = '$<PASSWORD>' WHERE id_number = '$id'");
               //echo '<script>alert("Password successfully changed"); window.location.href = "dashboard";</script> ';
            }
          
            }else if($account_type == 'supervisor'){
                 $old_pass = $this->db->query("SELECT password FROM supervisor WHERE id_number = '$id'")->row();
           
            $new_pass = $_POST['newpass'];
            $confirm = $_POST['confirm_newpass'];
            $old = $_POST['old_password'];
            if($old!=$old_pass->password){
               echo "old_not_match_supervisor";exit;
            }else{
               $this->db->query("UPDATE supervisor SET password = '$<PASSWORD>' WHERE id_number = '$id'");
              // echo '<script>alert("Password successfully changed"); window.location.href = "dashboard";</script> ';

            }
            }

           
        }

        public function insertComment(){
            $log_id = $_POST['log_id'];
            $comment = $_POST['comment'];
            $supervisor_id = $_POST['supervisor_id'];
            return $this->db->query("INSERT INTO comments (log_id, content, supervisor_id) VALUES($log_id, '$comment', '$supervisor_id')");
        }

         public function updateTraineeSupID(){
            $supervisor_id = $_POST['supervisor_id'];
            $student_id = $_POST['studentID'];
           $query = $this->db->query("SELECT * FROM ojt_records WHERE supervisor_id = '' AND id_number = '$student_id' ")->row();
           if(!empty($query)){
              $this->db->query("UPDATE company_information SET supervisor_id = '$supervisor_id' WHERE id_number='$student_id'");
               $this->db->query("UPDATE logs SET supervisor_id = '$supervisor_id' WHERE id_number='$student_id'");
               $this->db->query("UPDATE ojt_records SET supervisor_id = '$supervisor_id' WHERE id_number='$student_id'");
           }else{
              echo 'error';
           }
          
         
         }
         public function getSupervisorIdForStudent($username, $ojt_program){

            $query = $this->db->query("SELECT supervisor_id FROM company_information WHERE id_number = '$username' AND ojt_program = '$ojt_program'");

            return $query->row();
         }

         public function addAdmin(){
            //print_r($_POST);exit;
            $adminName = $_POST['adName'];
            $adminID = $_POST['adID'];
            $adminPass = $_POST['adPass'];
            $adminCollege = $_POST['adCollege'];
            $adminEmail = $_POST['adEmail'];
            
            //check duplicate name
            $result = $this->db->query("SELECT * FROM admin WHERE name = '".$adminName."' ");
            if($this->db->affected_rows() > 0){
                echo "name_exist"; exit;
            }

            //check duplicate id
            $result = $this->db->query("SELECT * FROM admin WHERE id_number = '".$adminID."' ");
            if($this->db->affected_rows() > 0){
                echo "id_exist"; exit;
            }

            //check duplicate email
            $result = $this->db->query("SELECT * FROM admin WHERE email = '".$adminEmail."' ");
            if($this->db->affected_rows() > 0){
               echo "email_exist"; exit;
            }
            $result = $this->db->query("SELECT * FROM personal_details WHERE email_address = '".$adminEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            $result = $this->db->query("SELECT * FROM supervisor WHERE email = '".$adminEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            else{
                return $this->db->query("INSERT INTO admin (name, id_number, password, college, email) VALUES('$adminName', '$adminID', '$adminPass', '$adminCollege', '$adminEmail')");
             }
         }
         public function addWatch(){
            $companyToWatch = $_POST['companyName'];

            // CHANGE OPERATOR TO LIKE  --------------
            $result = $this->db->query("SELECT * FROM watchlist WHERE company_name = '".$companyToWatch."'");
            if($this->db->affected_rows() > 0){
                echo "fail";
            }
            else{  
               $this->db->query("UPDATE company_information SET watchlisted = 1 WHERE company_name = '$companyToWatch'");
               return $this->db->query("INSERT INTO watchlist (company_name) VALUES('$companyToWatch')");
            }
         }

         public function addSupervisor(){
            $supervisorName = $_POST['supName'];
            $supervisorComp = $_POST['supCompany'];
            $supervisorDesig = $_POST['supDesig'];
            $supervisorID = $_POST['supID'];
            $supervisorPass = $_POST['supPass'];
            $supervisorEmail = $_POST['supEmail'];
            
            //check duplicate name
            $result = $this->db->query("SELECT * FROM supervisor WHERE name = '".$supervisorName."'");
            if($this->db->affected_rows() > 0){
                echo "name_exist";exit;
            }
            
            //check duplicate id
            $result = $this->db->query("SELECT * FROM supervisor WHERE id_number = '".$supervisorID."'");
            if($this->db->affected_rows() > 0){
                echo "id_exist";exit;
            }
            
            //check duplicate email
            $result = $this->db->query("SELECT * FROM personal_details WHERE email_address = '".$supervisorEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            $result = $this->db->query("SELECT * FROM admin WHERE email = '".$supervisorEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            $result = $this->db->query("SELECT * FROM supervisor WHERE email = '".$supervisorEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            else{
                return $this->db->query("INSERT INTO supervisor (name,company_name,designation,id_number,password,email) VALUES('$supervisorName','$supervisorComp','$supervisorDesig','$supervisorID','$supervisorPass','$supervisorEmail')");
            }
           
         }

         public function getWatchlists(){
            $query = $this->db->query("SELECT * FROM watchlist");
            return $query->result_array();
         }

         public function getProfile($id){
            return $this->db->query("SELECT * FROM personal_details WHERE id_number = '$id'")->result_array();
         }

         public function displayImageToHeader($id){
            return $this->db->query("SELECT * FROM users WHERE id_number = '$id'")->result_array();
         }

         public function getStudentInfo($id_number){

            return $this->db->query("SELECT * FROM users WHERE id_number ='$id_number'")->result_array();

         }
         public function profileImage(){
            if(isset($_POST['saveBrowse'])){
                $id = $this->session->userdata['id_number'];
                $file = $_FILES['files'];

                $path = $_FILES['files']['name'];
                $ext = pathinfo($path, PATHINFO_EXTENSION);
                $fileTmpName = $file['tmp_name'];
                $fileError = $file['error'];
                $randString = $this->generateRandomString();
                if($fileError === 0){
                    $newFileName = $id.".".$ext;
                    $fileDestination = FCPATH."assets\uploads\\";
                    $full_path = 'assets/uploads/'.$newFileName . '?dummy='.$randString;
                    // $img_tag = '<img src='.$full_path.' class="img-circle">';
                    /*$img_tag_toHeader = '<img src='.$full_path.' class="pull-right circular-square user-image" style="width: 40px; height: 40px; margin-top: -5px;">';
*/
                    if (move_uploaded_file($_FILES['files']['tmp_name'], $fileDestination. $newFileName)) {
                           echo "<script>window.location.href='profile'</script>";
                    $this->db->query("UPDATE users SET user_image = '$full_path' WHERE id_number = '$id'");   
                    $this->db->query("UPDATE personal_details SET image_id = '$full_path' WHERE id_number = '$id'");
                    }
                }else{
                    echo "There was an error uploading the file";
                }

            }
         }

         public function generateRandomString($length = 10) {
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $randomString = '';
            for ($i = 0; $i < $length; $i++) {
                $randomString .= $characters[rand(0, $charactersLength - 1)];
            }
            return $randomString;
        }

         public function supervisorImage($id){
            return $this->db->query("SELECT * FROM supervisor WHERE id_number = '$id'")->result_array();
         }

         public function sup_image(){
            if(isset($_POST['supSave'])){
                $id = $this->session->userdata['id_number'];
                $file = $_FILES['supFiles'];
                $path = $_FILES['supFiles']['name'];
                $randString = $this->generateRandomString();
                $ext = pathinfo($path, PATHINFO_EXTENSION);
                $fileTmpName = $file['tmp_name'];
                $fileError = $file['error'];

                if($fileError === 0){
                    $newFileName = $id.".".$ext;
                    $fileDestination = FCPATH."assets\uploads\\";
                    $full_path ='assets/uploads/'.$newFileName. '?dummy='.$randString;
                    /*$img_tag = '<img src='.$full_path.' class="img-circle" id="image-modal">';
                    $img_tag_toHeader = '<img src='.$full_path.' class="pull-right circular-square user-image" style="width: 40px; height: 40px; margin-top: -5px;">';*/

                    if (move_uploaded_file($_FILES['supFiles']['tmp_name'], $fileDestination. $newFileName)) {
                           echo '<script>window.location.href="supervisordashboard"</script>';
                    $this->db->query("UPDATE supervisor SET imageDisplayToChange = '$full_path' WHERE id_number = '$id'");   
                    return $this->db->query("UPDATE supervisor SET image_id = '$full_path' WHERE id_number = '$id'");
                    }
                }else{
                    echo "There was an error uploading the file";
                }

            }
         }

         public function addReport(){
                if(isset($_POST['btn-report'])){
                    $report=$_POST['comment'];
                    return $this->db->query("INSERT INTO reports (report) VALUES('".$report."')");
                }
         }
         public function getLastLog(){
            $username = $_POST['username'];
            $ojtProgram = $this->getOjtProgramForStud($username);
            $ojtP = $ojtProgram->ojt_program;
            $latestId = $this->db->query("SELECT MAX(id) AS latest_id FROM logs WHERE id_number = '$username' AND ojt_program = '$ojtP'")->row();
            $maxId = $latestId->latest_id;
            $lastlog = $this->db->query("SELECT * FROM logs WHERE id = $maxId")->row();

             echo json_encode($lastlog);
         }  

         public function loadSpecificLog(){
            $id = $_POST['log_id'];

          
            $log = $this->db->query("SELECT * FROM logs WHERE id = $id")->row();

             echo json_encode($log);
         }
        



         //import csv
         public function importCSV(){
            $admin_id = $this->session->userdata('id_number');
            $filename=$_FILES["importCSV"]["tmp_name"];      
            $duplicate_names="";
 
             if($_FILES["importCSV"]["size"] > 0)
             {
                $file = fopen($filename, "r");
                fgets($file);
                while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
                 {
                    // $username = strtolower($getData[1].".".$getData[3]);
                    $username = strtolower(str_replace(' ', '',$getData[1]).".".str_replace(' ', '',$getData[0]));
                    $sy=str_replace(' ','',$getData[5]);
                    
                    $result = $this->db->query("SELECT id_number FROM users WHERE id_number = '".$username."'")->result_array();
                    if(in_array($username, array_column($result, 'id_number'))){
                      $key = array_search($username, array_column($result, 'id_number'));
                      $existStuds[] = $result[$key];
                     
                    } else{
                      if($getData[7]!=""){
                         $total_hours = $getData[6]+$getData[7];
                      }else{
                        $total_hours = $getData[6];
                      }
                      
                      $this->db->query("INSERT INTO users (id_number,admin_id,first_name,middle_initial,last_name,course,year,school_year,password) 
                        values ('$username','$admin_id','".$getData[1]."','".$getData[2]."','".$getData[0]."','".$getData[3]."','".$getData[4]."','$sy','123456')");
                      $this->db->query("INSERT INTO ojt_records(id_number,total_hours,ojtone_required,ojttwo_required) VALUES('$username',$total_hours,'".$getData[6]."','".$getData[7]."')");
                    }
                    
                 }<commit_msg>insert different ojt<commit_after><?php
  class Users extends CI_Model {

        public function __construct()
        {
                $this->load->database();
                $this->load->library('session');

                 // added by <NAME> sku
                $this->load->helper('form');
                $this->load->library('encrypt');

                parent::__construct();      
        }


        public function saveEmail($hash){
                $username = $this->session->userdata['id_number'];
                $email = $_POST['email'];
                return $this->db->query("INSERT INTO email (id_number, email_address, hash) VALUES('$username','$email', '$hash')");     
        }


        public function queryUserByEmail($email){
              // $email = $_POST['reset_email'];
              $result= $this->db->query("SELECT id_number from email where email_address = '$email'")->row();

             return $result;
        }



        public function insertPersonalData(){
                // print_r($_POST);exit;
               $result = $this->db->query("SELECT id_number FROM personal_details WHERE id_number ='14-2649-276'")->result_array();
               // print_r($result);
                if (empty($result)) {
                     return $this->db->insert('personal_details', $_POST);   
                }else{

                }                
        }

        public function resetUserPassword($username){
          $password = $_POST['<PASSWORD>'];
          $this->db->query("UPDATE users SET password = <PASSWORD>' WHERE id_number = '$username'");
        }


        public function insertFamilyData(){

                $result = $this->db->query("SELECT id_number FROM family_details WHERE id_number ='14-2649-276'")->result_array();
               // print_r($result);
                if (empty($result)) {
                     return $this->db->insert('family_details', $_POST);   
                }else{

                }
        } 

        public function insertEmergencyData(){
                $result = $this->db->query("SELECT id_number FROM emergency_details WHERE id_number ='14-2649-276'")->result_array();
               // print_r($result);
                if (empty($result)) {
                     return $this->db->insert('emergency_details', $_POST);   
                }else{

                }
        }

        public function updateAnnouncemment($username){
            $announcement_id = $_POST['announcement_id'];
            $this->db->query("UPDATE announcements SET status = 1, date_posted = date_posted WHERE id = $announcement_id AND username = '$username'");
        }

        public function getNumberUnreadAnnouncements($username){
            $query = $this->db->query("SELECT count(status) as numberUnread FROM announcements WHERE username = '$username' AND status = 0")->row();

            return $query;
        }

        public function updateAnnouncemmentToUnreadAll(){
            $username = $_POST['username'];
            $this->db->query("UPDATE announcements SET status = 1, date_posted = date_posted WHERE username = '$username'");
        }
        public function updateAnnouncemmentToUnread($username){
            $announcement_id = $_POST['announcement_id'];
            $this->db->query("UPDATE announcements SET status = 0, date_posted = date_posted WHERE id = $announcement_id AND username = '$username'");
        }

        public function getAnnouncements($username){
            $query = $this->db->query("SELECT a.id, admin_id,content,username,status,date_posted,announcement_id,name,id_number FROM announcements as a INNER JOIN admin ON a.admin_id = admin.id_number WHERE a.username = '$username' ORDER BY a.id DESC");
            return $query->result_array();
        }
        public function getAnnouncementsForStudents(){
            $announcement_id = $_POST['announcement_id'];
            $query = $this->db->query("SELECT * FROM announcements WHERE id = '$announcement_id'")->row();
            
            echo json_encode($query);
        }

        public function user_login(){
                $username = $_POST['username']; //need to be dynamic
                $password = $_POST['password']; //need to be dynamic
                $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username' AND password = '$password'");
                //print_r($result->result_array());
                $affectedRows = $this->db->affected_rows();
                
               if($affectedRows>0){
                    return true;
                        
                }else{
                    return false;
                }
        }

         public function user_login_administrator(){
                $username = $_POST['username']; //need to be dynamic
                $password = $_POST['password']; //need to be dynamic
                $result = $this->db->query("SELECT * FROM admin WHERE id_number = '$username' AND password = '$password'");
                //print_r($result->result_array());
                $affectedRows = $this->db->affected_rows();
                
               if($affectedRows>0){
                    return true;
                        
                }else{
                    return false;
                }
        }

        public function insertAnnouncement($id){
            $usernames = $this->db->query("SELECT id_number FROM users WHERE admin_id = '$id'")->result_array();
            $i = $this->db->query("SELECT MAX(announcement_id) as max_id FROM announcements")->row();
            $announcement = $this->input->post('announcement');
            $insert_announce = mysqli_real_escape_string($this->get_mysqli(),$announcement);
            if(empty($i->max_id)){
              $i=1;
              foreach ($usernames as $username)    {
                $stud_username = $username['id_number'];

                $this->db->query("INSERT INTO announcements(admin_id,content, username,announcement_id) VALUES ('$id','$insert_announce', '$stud_username','$i')");
            
            }
            }else{
              
            $i = $i+$i->max_id;
            foreach ($usernames as $username)    {
                $stud_username = $username['id_number'];

                $this->db->query("INSERT INTO announcements(admin_id,content, username,announcement_id) VALUES ('$id','$insert_announce', '$stud_username','$i')");
            
              }
            }
            
        }

      public  function get_mysqli() { 
                $db = (array)get_instance()->db;
                return mysqli_connect('localhost', $db['username'], $db['password'], $db['database']);
            }

        public function readUserAdmin($data){
            $username = $data['username'];
            $password = $data['password'];
      
            $result = $this->db->query("SELECT * FROM admin WHERE id_number = '$username' AND password = '$password'");
            return $result->result_array();

         
         }

         public function user_login_supervisor(){
                $username = $_POST['username']; //need to be dynamic
                $password = $_POST['password']; //need to be dynamic
                $result = $this->db->query("SELECT * FROM supervisor WHERE id_number = '$username' AND password = '$password'");
                //print_r($result->result_array());
                $affectedRows = $this->db->affected_rows();
                
               if($affectedRows>0){
                    return true;
                        
                }else{
                    return false;
                }
        }

      public function readUserId($data){
        $username = $data['username'];
        $password = $data['password'];
  
        $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username' AND password = '$password'");
        return $result->result_array();

         
         }

         public function readUserSupervisor($data){
             $username = $data['username'];
             $password = $data['password'];
  
            $result = $this->db->query("SELECT * FROM supervisor WHERE id_number = '$username' AND password = '$password'");
             return $result->result_array();
         }




        public function supervisorGetTrainee($company_name,$username){

          $company_name2 = $company_name[0]['company_name'];
            $query = $this->db->query("SELECT users.id_number, users.first_name, users.last_name FROM users INNER JOIN company_information ON users.id_number = company_information.id_number WHERE company_information.company_name = '$company_name2' AND supervisor_id = '' AND transitioned = '0'");
           return $query->result_array();
       }


       
        public function getCompanyNames(){
            $query = $this->db->query("SELECT DISTINCT company_name FROM company_information ORDER BY company_name ASC");

           return $query->result_array();
         }

         public function getCompanyWatchlist(){
            $query = $this->db->query("SELECT DISTINCT company_name FROM company_information WHERE watchlisted = 0");
           return $query->result_array();
         }
         public function getCompanySupervisor($id_number){
             $query = $this->db->query("SELECT company_name FROM supervisor WHERE id_number= '$id_number'");
             return $query->result_array();
         }

         public function getAccountType($data){
           $username = $data;
            $result = $this->db->query("SELECT account_type FROM users WHERE id_number = '$username'");
            return $result->result_array();
         }

        //  public function dashboardDataAdmin($data){   
        //        $username = $data;
             
        //         $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username'");
        //         return $result->result_array();


        // }

         public function getStudentList(){
          $admin_id = $this->session->userdata('id_number');
          $query = $this->db->query("SELECT * FROM users INNER JOIN ojt_records ON users.id_number = ojt_records.id_number WHERE users.status!='DELETED' AND users.admin_id = '$admin_id'");

            return $query->result_array();
         }

        public function insertLogs(){

            $id_number = $_POST['id_number'];
            $date =  $_POST['log_date'];
            $time_in = $_POST['time_in'];
            $time_out = $_POST['time_out'];
            $division = $_POST['division'];
            $department = $_POST['department'];
            $designation = $_POST['designation'];
            $log_content = $_POST['log_activity'];
            $hours_rendered = $_POST['hours_rendered'];
            $supervisor_id = empty($_POST['supervisor_id']) ? '' : $_POST['supervisor_id'];
            $ojt_program = $this->getOjtProgramForStud($id_number);
            $ojtP = $ojt_program->ojt_program;
            $data = Array(
            'id_number' => $id_number,
            'date' => $date,
            'time_in' => $time_in,
            'time_out' => $time_out,
            'division' => $division,
            'department' => $department,
            'designation' => $designation,
            'log_content' => $log_content,
            'hours_rendered' => $hours_rendered,
            'supervisor_id' => $supervisor_id,
            'ojt_program' => $ojtP
            );
            $existDate = $this->db->query("SELECT * FROM logs WHERE date = '$date' AND id_number = '$id_number' AND ojt_program = '$ojtP'")->result();

            if(!empty($existDate)){
              echo 'dateexist';
            }else{
               $this->db->insert('logs',$data);
            }
          


        }

        public function getLogs($data,$limit, $start, $ojt_program){
            $username = $data;
              $this->db->limit($limit, $start);
              $this->db->select('*');
              $this->db->where('id_number', $username);
              $this->db->where('ojt_program', $ojt_program);
              $this->db->from('logs');
              $this->db->order_by('id', 'DESC');
              $result = $this->db->get();
              // print_r($result->result_array());
            // $result = $this->db->query("SELECT * FROM logs WHERE id_number = '$username' ORDER BY id DESC");
            return $result->result_array();
        }

        public function getLogsForStuds($id_number, $ojt_program){
         
              $this->db->select('*');
              $this->db->where('id_number', $id_number);
              $this->db->where('ojt_program', $ojt_program);
              $this->db->from('logs');
              $this->db->order_by('id', 'DESC');
              $result = $this->db->get();
              return $result->result_array();
        }

        public function deleteLog(){
            $id = $_POST['log_id'];
            $this->db->where('id', $id);
            $this->db->delete('logs');

            $this->db->where('log_id', $id);
            $this->db->delete('comments');
        }

         public function dashboardData($id_number){   
             $username = $id_number;         
             $result = $this->db->query("SELECT * FROM users WHERE id_number = '$username'");
             return $result->result_array();


        }

        public function dashboardDataRecords($id_number, $ojt_program){   
            $username = $id_number;
            if($ojt_program == 'ojt_one'){
              $result = $this->db->query("SELECT ojtone_required as required, ojtone_rendered as rendered, total_evaluations as total, ojtone_current_evaluations as current_eval, logs_one as total_logs, logs_one_verified as verified_logs FROM ojt_records WHERE id_number = '$username'");
            }else{
              $result = $this->db->query("SELECT ojttwo_required as required, ojttwo_rendered as rendered, total_evaluations as total, ojttwo_current_evaluations as current_eval, logs_two as total_logs, logs_two_verified as verified_logs  FROM ojt_records WHERE id_number = '$username'");
            }
            
                  
           return $result->result_array();
         }   

         public function getOjtRecordsForSupervisor($username){
            $result = $this->db->query("SELECT ojt_records.id_number, ojt_records.ojtone_required,ojt_records.ojtone_rendered,ojt_records.ojttwo_rendered, ojt_records.ojttwo_required, users.first_name, users.last_name, users.ojt_program FROM ojt_records INNER JOIN users ON users.id_number = ojt_records.id_number WHERE supervisor_id = '$username'");         

            // echo '<pre>';print_r($result->result_array()); echo'</pre>';
            return $result->result_array();
         }

         public function filterStud(){
          $admin_id = $this->session->userdata('id_number');
          $html = '';
          $course = empty($_POST['course']) ? '' : $_POST['course'];
          $sy = empty($_POST['sy']) ? '' : $_POST['sy'];
          $eval = empty($_POST['eval']) ? '' : $_POST['eval'];
          $stat = empty($_POST['stat']) ? '' : $_POST['stat'];
          
          if($sy == 'all'){
            $sy = '';
          }
          if($eval == 'all'){
            $eval = '';
          }
          if($eval == 'None'){
            $eval = '0';
          }
          if($course == 'all'){
            $course = '';
          }
          if($stat == 'all'){
            $stat = '';
          }

          ///echo $eval;exit;
          if(empty($sy)){
              $query = $this->db->query("SELECT * FROM users INNER JOIN ojt_records ON users.id_number = ojt_records.id_number WHERE status!='DELETED' AND users.admin_id = '$admin_id' AND users.course LIKE '%$course%' AND ojtone_current_evaluations LIKE '%$eval%' || ojttwo_current_evaluations LIKE '%$eval%' AND ojtone_status LIKE '%$stat%' ORDER BY users.id_number");
          }else{
              $query = $this->db->query("SELECT * FROM users INNER JOIN ojt_records ON users.id_number = ojt_records.id_number WHERE status!='DELETED' AND users.admin_id = '$admin_id' AND users.course LIKE '%$course%' AND school_year = '$sy' AND ojtone_current_evaluations LIKE '%$eval%' AND ojtone_status LIKE '%$stat%' ORDER BY users.id_number ASC");
          }
          return $query->result_array();
        }

         public function editLog(){
            $id = $_POST['log_id'];
            $date = $_POST['date'];
            $time_in = $_POST['time_in'];
            $time_out = $_POST['time_out'];
            $division = $_POST['division'];
            $department = $_POST['department'];
            $designation = $_POST['designation'];
            $log_activity = $_POST['log_activity'];
            $hours_rendered = $_POST['hours_rendered'];

            return $this->db->query("UPDATE logs SET date = '$date', time_in = '$time_in', time_out = '$time_out', division = '$division', department = '$division', designation = '$designation', log_content = '$log_activity', hours_rendered = '$hours_rendered'  WHERE id = $id");

         }
        public function getNumberLogs($data, $ojt_program){
            $id = $data;

            $result = $this->db->query("SELECT COUNT(logs.id) as logscount FROM logs WHERE id_number = '$id' AND ojt_program = '$ojt_program' ");
            return $result->result_array();
        }


        public function getMidtermEvaluations($username, $ojt_program){

          $query =  $this->db->query("SELECT * FROM midterm_evaluation WHERE username = '$username' AND ojt_program = '$ojt_program'");

          return $query->row();
        }
        public function getFinalEvaluations($username, $ojt_program){

          $query =  $this->db->query("SELECT * FROM final_evaluation WHERE username = '$username' AND ojt_program = '$ojt_program'");

          return $query->row();
        }
        public function getSumRendered($data, $ojt_program){
            $id = $data;

            $query = $this->db->query("SELECT SUM(hours_rendered) AS rendered FROM logs WHERE (id_number ='$id' AND verified = 1) AND ojt_program = '$ojt_program'");
            return $query->result_array();
        }

        public function updateLogCount($logscount,$id, $ojt_program){
          if($ojt_program == 'ojt_one'){
             $this->db->query("UPDATE ojt_records SET logs_one = $logscount WHERE id_number ='$id'");
          }else{
            $this->db->query("UPDATE ojt_records SET logs_two = $logscount WHERE id_number ='$id'");
          }
        }
        public function updateLogsVerifiedCount($logscount, $id, $ojt_program){

             if($ojt_program == 'ojt_two'){
              
                 $this->db->query("UPDATE ojt_records SET logs_two_verified = $logscount WHERE id_number = '$id'");
             }else{
              
                $this->db->query("UPDATE ojt_records SET logs_one_verified = $logscount WHERE id_number = '$id'");
             }
            
        }

        public function updateRenderedHours($hours, $id, $ojt_program){

            if($ojt_program == 'ojt_one'){

             $this->db->query("UPDATE ojt_records SET ojtone_rendered = $hours WHERE id_number = '$id'");
            }else{
              $this->db->query("UPDATE ojt_records SET ojttwo_rendered = $hours WHERE id_number = '$id'");
            }
        }

        public function getNumberLogsVerified($data, $ojt_program){
             $id = $data;
            $result = $this->db->query("SELECT COUNT(verified) as logscount FROM logs WHERE id_number = '$id' AND ojt_program = '$ojt_program' AND verified = 1");
            return $result->result_array();
        }

        public function insertNewRecordOjt($data){
            return $this->db->insert('ojt_records', $data);
        }

        public function getOjtLogs($id, $ojt_program){
          $logs = array(array(
            'id'=>'',
            'id_number'=>'',
            'date'=>'',
            'time_in'=>'',
            'time_out'=>'',
            'first_name'=>'',
            'last_name'=>'',
            'user_image'=>'',
            'department'=>'',
            'designation'=>'',
            'division'=>'',
            'hours_rendered'=>'',
            'verified'=>'',
            'log_content'=>''
          ));
          $i =0;
     
                  foreach ($ojt_program as $key => $program) {
                    $p = $program['ojt_program'];
                    // echo $p;
                    $d = $program['username'];
         

                    $query = $this->db->query("SELECT logs.id, logs.ojt_program, logs.id_number, logs.date, logs.time_in, logs.time_out, logs.division, logs.department, logs.designation, logs.log_content, logs.hours_rendered, logs.verified, users.first_name, users.last_name, users.user_image FROM logs INNER JOIN users ON logs.id_number = users.id_number WHERE logs.ojt_program = '$p' AND logs.id_number = '$d'")->result();
                      
                  
                        
                        foreach ($query as $key => $value) {
                            $logs[$i]['id'] = $value->id;
                            // $logs[$i]['p'] = $value->ojt_program;
                            $logs[$i]['id_number'] = $value->id_number;
                            $logs[$i]['date'] = $value->date;
                            $logs[$i]['time_in'] = $value->time_in;
                            $logs[$i]['time_out'] = $value->time_out;
                            $logs[$i]['first_name'] = $value->first_name;
                            $logs[$i]['last_name'] = $value->last_name;
                            $logs[$i]['user_image'] = $value->user_image;
                            $logs[$i]['department'] = $value->department;
                            $logs[$i]['designation'] = $value->designation;
                            $logs[$i]['division'] = $value->division;
                            $logs[$i]['hours_rendered'] = $value->hours_rendered;
                            $logs[$i]['verified'] = $value->verified;
                            $logs[$i]['log_content'] = $value->log_content;
                            $i++;
                        }

                    }

                     if($logs[0]['log_content'] == ''){
                      foreach ($logs as $key => $value) {
                          $key = array_search($value, $logs);

                          unset($logs[$key]);
                      }
                      return $logs;
                  }else{
                    return $logs;
                  }
            
           // echo '<pre>'; print_r($logs); echo '</pre>';
          
           
            return $logs;
        }

          public function filterLogsForSupervisor($id){
      // print_r($_POST);exit;
          $current_ojt_program = $this->getOjtProgramForStudSup($id);
          // echo '<pre>'; print_r($current_ojt_program); echo '</pre>';
        $status = $_POST['status'];
          $logs = array(array(
            'id'=>'',
            'id_number'=>'',
            'date'=>'',
            'time_in'=>'',
            'time_out'=>'',
            'first_name'=>'',
            'last_name'=>'',
            'user_image'=>'',
            'department'=>'',
            'designation'=>'',
            'division'=>'',
            'hours_rendered'=>'',
            'verified'=>'',
            'log_content'=>''
          ));
          $i =0;


        $stud = empty($_POST['stud_id']) ? '' : $_POST['stud_id'];

          if($status == 'all'){
             foreach ($current_ojt_program as $key => $program) {
              $p = $program['ojt_program'];
              $d = $program['username'];
             $query = $this->db->query("SELECT logs.id, logs.id_number, logs.date, logs.time_in, logs.time_out, logs.division, logs.department, logs.designation, logs.log_content, logs.hours_rendered, logs.verified, users.first_name, users.last_name, users.user_image FROM logs INNER JOIN users ON users.id_number = logs.id_number  WHERE logs.supervisor_id = '$id' AND logs.ojt_program = '$p' AND logs.id_number = '$d' AND users.id_number LIKE '%$stud%' ORDER BY id DESC")->result();
                if(!empty($query)){
                      foreach ($query as $key => $value) {
                            $logs[$i]['id'] = $value->id;
                            // echo value;
                            // $logs[$i]['p'] = $value->ojt_program;
                            $logs[$i]['id_number'] = $value->id_number;
                            $logs[$i]['date'] = $value->date;
                            $logs[$i]['time_in'] = $value->time_in;
                            $logs[$i]['time_out'] = $value->time_out;
                            $logs[$i]['first_name'] = $value->first_name;
                            $logs[$i]['last_name'] = $value->last_name;
                            $logs[$i]['user_image'] = $value->user_image;
                            $logs[$i]['department'] = $value->department;
                            $logs[$i]['designation'] = $value->designation;
                            $logs[$i]['division'] = $value->division;
                            $logs[$i]['hours_rendered'] = $value->hours_rendered;
                            $logs[$i]['verified'] = $value->verified;
                            $logs[$i]['log_content'] = $value->log_content;
                            $i++;
                    }
                }
               


            }
          }else{
            // echo "hey";exit;
            foreach ($current_ojt_program as $key => $program) {
              $p = $program['ojt_program'];
              $d = $program['username'];
              // echo $p;
              $query = $this->db->query("SELECT logs.id, logs.id_number, logs.ojt_program, logs.date, logs.time_in, logs.time_out, logs.division, logs.department, logs.designation, logs.log_content, logs.hours_rendered, logs.verified, users.first_name, users.last_name, users.user_image FROM logs INNER JOIN users ON users.id_number = logs.id_number  WHERE logs.supervisor_id = '$id' AND verified = $status AND users.id_number LIKE '%$stud%' AND logs.ojt_program = '$p' AND logs.id_number = '$d' ORDER BY id DESC")->result();
                // print_r($query);
                if(!empty($query)){
                    foreach ($query as $key => $value) {
                            $logs[$i]['id'] = $value->id;
                            // echo value;
                            $logs[$i]['p'] = $value->ojt_program;
                            $logs[$i]['id_number'] = $value->id_number;
                            $logs[$i]['date'] = $value->date;
                            $logs[$i]['time_in'] = $value->time_in;
                            $logs[$i]['time_out'] = $value->time_out;
                            $logs[$i]['first_name'] = $value->first_name;
                            $logs[$i]['last_name'] = $value->last_name;
                            $logs[$i]['user_image'] = $value->user_image;
                            $logs[$i]['department'] = $value->department;
                            $logs[$i]['designation'] = $value->designation;
                            $logs[$i]['division'] = $value->division;
                            $logs[$i]['hours_rendered'] = $value->hours_rendered;
                            $logs[$i]['verified'] = $value->verified;
                            $logs[$i]['log_content'] = $value->log_content;
                            $i++;
                  }
                }
                

            }
            
          }
            
          if($logs[0]['log_content'] == ''){
              foreach ($logs as $key => $value) {
                  $key = array_search($value, $logs);

                  unset($logs[$key]);
              }
              return $logs;
          }else{
            return $logs;
          }

          
      }

         public function getNotVerified($username, $ojt_program){
           $count = array();
            $i=0;
            $total = 0;
          foreach ($ojt_program as $key => $program) {
            $p = $program['ojt_program'];
            $d = $program['username'];
           
            $query = $this->db->query("SELECT count(verified) as not_verified from logs WHERE supervisor_id = '$username' AND ojt_program = '$p' AND id_number = '$d' AND verified = 0")->result();

              foreach ($query as $key => $value) {
                  $count[$i] = $value->not_verified;
                  $i++;
              }
          }

          foreach ($count as $value) {
            $total += $value;
          }
          

         return $total; 
            
         
         
      }

        public function updateLog(){
            $log_id = $_POST['log_id'];
             $this->db->query("UPDATE logs SET verified = 1 WHERE id = $log_id");
        }

        public function unverifyLog(){
            $log_id = $_POST['log_id'];
             $this->db->query("UPDATE logs SET verified = 0 WHERE id = $log_id");
        }
            
        public function getComments(){
            $query = $this->db->query("SELECT * FROM comments");

            return $query->result_array();
        }
        public function updateOJTStatus($id, $ojt_program){

           if($ojt_program == 'ojt_one'){
            $this->db->query("UPDATE ojt_records SET ojtone_status = 'COMPLETED' WHERE ojtone_rendered >= ojtone_required AND ojtone_current_evaluations >= 2 AND id_number = '$id'");
          }else{
              $this->db->query("UPDATE ojt_records SET ojttwo_status = 'COMPLETED' WHERE ojttwo_rendered >= ojttwo_rendered AND ojttwo_current_evaluations >= 2 AND id_number = '$id'");
          }
           
        }
        public function updatePassword($id,$account_type){

            if($account_type == 'admin'){
                 $old_pass = $this->db->query("SELECT password FROM admin WHERE id_number = '$id'")->row();
             
              $new_pass = $_POST['newpass'];
              $confirm = $_POST['confirm_newpass'];
              $old = $_POST['old_password'];
              if($old!=$old_pass->password){
                echo "old_not_match_admin";exit;
                 //echo '<script>alert("Old passwords did not match");  window.location.href = "changepassword"</script>';
              }else{
                 $this->db->query("UPDATE admin SET password = '$<PASSWORD>' WHERE id_number = '$id'");
                 //echo '<script>alert("Password successfully changed"); window.location.href = "admindashboard";</script> ';

              }
            }else if($account_type == 'student'){
                 $old_pass = $this->db->query("SELECT password FROM users WHERE id_number = '$id'")->row();
           
            $new_pass = $_POST['newpass'];
            $confirm = $_POST['confirm_newpass'];
            $old = $_POST['old_password'];
            if($old!=$old_pass->password){
               //echo '<script>alert("Old passwords did not match");  window.location.href = "changepassword"</script>';
              echo "old_not_match_student";exit;
            }else{
               $this->db->query("UPDATE users SET password = '$<PASSWORD>' WHERE id_number = '$id'");
               //echo '<script>alert("Password successfully changed"); window.location.href = "dashboard";</script> ';
            }
          
            }else if($account_type == 'supervisor'){
                 $old_pass = $this->db->query("SELECT password FROM supervisor WHERE id_number = '$id'")->row();
           
            $new_pass = $_POST['newpass'];
            $confirm = $_POST['confirm_newpass'];
            $old = $_POST['old_password'];
            if($old!=$old_pass->password){
               echo "old_not_match_supervisor";exit;
            }else{
               $this->db->query("UPDATE supervisor SET password = '$<PASSWORD>' WHERE id_number = '$id'");
              // echo '<script>alert("Password successfully changed"); window.location.href = "dashboard";</script> ';

            }
            }

           
        }

        public function insertComment(){
            $log_id = $_POST['log_id'];
            $comment = $_POST['comment'];
            $supervisor_id = $_POST['supervisor_id'];
            return $this->db->query("INSERT INTO comments (log_id, content, supervisor_id) VALUES($log_id, '$comment', '$supervisor_id')");
        }

         public function updateTraineeSupID(){
            $supervisor_id = $_POST['supervisor_id'];
            $student_id = $_POST['studentID'];
           $query = $this->db->query("SELECT * FROM ojt_records WHERE supervisor_id = '' AND id_number = '$student_id' ")->row();
           if(!empty($query)){
              $this->db->query("UPDATE company_information SET supervisor_id = '$supervisor_id' WHERE id_number='$student_id'");
               $this->db->query("UPDATE logs SET supervisor_id = '$supervisor_id' WHERE id_number='$student_id'");
               $this->db->query("UPDATE ojt_records SET supervisor_id = '$supervisor_id' WHERE id_number='$student_id'");
           }else{
              echo 'error';
           }
          
         
         }
         public function getSupervisorIdForStudent($username, $ojt_program){

            $query = $this->db->query("SELECT supervisor_id FROM company_information WHERE id_number = '$username' AND ojt_program = '$ojt_program'");

            return $query->row();
         }

         public function addAdmin(){
            //print_r($_POST);exit;
            $adminName = $_POST['adName'];
            $adminID = $_POST['adID'];
            $adminPass = $_POST['adPass'];
            $adminCollege = $_POST['adCollege'];
            $adminEmail = $_POST['adEmail'];
            
            //check duplicate name
            $result = $this->db->query("SELECT * FROM admin WHERE name = '".$adminName."' ");
            if($this->db->affected_rows() > 0){
                echo "name_exist"; exit;
            }

            //check duplicate id
            $result = $this->db->query("SELECT * FROM admin WHERE id_number = '".$adminID."' ");
            if($this->db->affected_rows() > 0){
                echo "id_exist"; exit;
            }

            //check duplicate email
            $result = $this->db->query("SELECT * FROM admin WHERE email = '".$adminEmail."' ");
            if($this->db->affected_rows() > 0){
               echo "email_exist"; exit;
            }
            $result = $this->db->query("SELECT * FROM personal_details WHERE email_address = '".$adminEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            $result = $this->db->query("SELECT * FROM supervisor WHERE email = '".$adminEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            else{
                return $this->db->query("INSERT INTO admin (name, id_number, password, college, email) VALUES('$adminName', '$adminID', '$adminPass', '$adminCollege', '$adminEmail')");
             }
         }
         public function addWatch(){
            $companyToWatch = $_POST['companyName'];

            // CHANGE OPERATOR TO LIKE  --------------
            $result = $this->db->query("SELECT * FROM watchlist WHERE company_name = '".$companyToWatch."'");
            if($this->db->affected_rows() > 0){
                echo "fail";
            }
            else{  
               $this->db->query("UPDATE company_information SET watchlisted = 1 WHERE company_name = '$companyToWatch'");
               return $this->db->query("INSERT INTO watchlist (company_name) VALUES('$companyToWatch')");
            }
         }

         public function addSupervisor(){
            $supervisorName = $_POST['supName'];
            $supervisorComp = $_POST['supCompany'];
            $supervisorDesig = $_POST['supDesig'];
            $supervisorID = $_POST['supID'];
            $supervisorPass = $_POST['supPass'];
            $supervisorEmail = $_POST['supEmail'];
            
            //check duplicate name
            $result = $this->db->query("SELECT * FROM supervisor WHERE name = '".$supervisorName."'");
            if($this->db->affected_rows() > 0){
                echo "name_exist";exit;
            }
            
            //check duplicate id
            $result = $this->db->query("SELECT * FROM supervisor WHERE id_number = '".$supervisorID."'");
            if($this->db->affected_rows() > 0){
                echo "id_exist";exit;
            }
            
            //check duplicate email
            $result = $this->db->query("SELECT * FROM personal_details WHERE email_address = '".$supervisorEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            $result = $this->db->query("SELECT * FROM admin WHERE email = '".$supervisorEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            $result = $this->db->query("SELECT * FROM supervisor WHERE email = '".$supervisorEmail."'");
            if($this->db->affected_rows() > 0){
                echo "email_exist";exit;
            }
            else{
                return $this->db->query("INSERT INTO supervisor (name,company_name,designation,id_number,password,email) VALUES('$supervisorName','$supervisorComp','$supervisorDesig','$supervisorID','$supervisorPass','$supervisorEmail')");
            }
           
         }

         public function getWatchlists(){
            $query = $this->db->query("SELECT * FROM watchlist");
            return $query->result_array();
         }

         public function getProfile($id){
            return $this->db->query("SELECT * FROM personal_details WHERE id_number = '$id'")->result_array();
         }

         public function displayImageToHeader($id){
            return $this->db->query("SELECT * FROM users WHERE id_number = '$id'")->result_array();
         }

         public function getStudentInfo($id_number){

            return $this->db->query("SELECT * FROM users WHERE id_number ='$id_number'")->result_array();

         }
         public function profileImage(){
            if(isset($_POST['saveBrowse'])){
                $id = $this->session->userdata['id_number'];
                $file = $_FILES['files'];

                $path = $_FILES['files']['name'];
                $ext = pathinfo($path, PATHINFO_EXTENSION);
                $fileTmpName = $file['tmp_name'];
                $fileError = $file['error'];
                $randString = $this->generateRandomString();
                if($fileError === 0){
                    $newFileName = $id.".".$ext;
                    $fileDestination = FCPATH."assets\uploads\\";
                    $full_path = 'assets/uploads/'.$newFileName . '?dummy='.$randString;
                    // $img_tag = '<img src='.$full_path.' class="img-circle">';
                    /*$img_tag_toHeader = '<img src='.$full_path.' class="pull-right circular-square user-image" style="width: 40px; height: 40px; margin-top: -5px;">';
*/
                    if (move_uploaded_file($_FILES['files']['tmp_name'], $fileDestination. $newFileName)) {
                           echo "<script>window.location.href='profile'</script>";
                    $this->db->query("UPDATE users SET user_image = '$full_path' WHERE id_number = '$id'");   
                    $this->db->query("UPDATE personal_details SET image_id = '$full_path' WHERE id_number = '$id'");
                    }
                }else{
                    echo "There was an error uploading the file";
                }

            }
         }

         public function generateRandomString($length = 10) {
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $randomString = '';
            for ($i = 0; $i < $length; $i++) {
                $randomString .= $characters[rand(0, $charactersLength - 1)];
            }
            return $randomString;
        }

         public function supervisorImage($id){
            return $this->db->query("SELECT * FROM supervisor WHERE id_number = '$id'")->result_array();
         }

         public function sup_image(){
            if(isset($_POST['supSave'])){
                $id = $this->session->userdata['id_number'];
                $file = $_FILES['supFiles'];
                $path = $_FILES['supFiles']['name'];
                $randString = $this->generateRandomString();
                $ext = pathinfo($path, PATHINFO_EXTENSION);
                $fileTmpName = $file['tmp_name'];
                $fileError = $file['error'];

                if($fileError === 0){
                    $newFileName = $id.".".$ext;
                    $fileDestination = FCPATH."assets\uploads\\";
                    $full_path ='assets/uploads/'.$newFileName. '?dummy='.$randString;
                    /*$img_tag = '<img src='.$full_path.' class="img-circle" id="image-modal">';
                    $img_tag_toHeader = '<img src='.$full_path.' class="pull-right circular-square user-image" style="width: 40px; height: 40px; margin-top: -5px;">';*/

                    if (move_uploaded_file($_FILES['supFiles']['tmp_name'], $fileDestination. $newFileName)) {
                           echo '<script>window.location.href="supervisordashboard"</script>';
                    $this->db->query("UPDATE supervisor SET imageDisplayToChange = '$full_path' WHERE id_number = '$id'");   
                    return $this->db->query("UPDATE supervisor SET image_id = '$full_path' WHERE id_number = '$id'");
                    }
                }else{
                    echo "There was an error uploading the file";
                }

            }
         }

         public function addReport(){
                if(isset($_POST['btn-report'])){
                    $report=$_POST['comment'];
                    return $this->db->query("INSERT INTO reports (report) VALUES('".$report."')");
                }
         }
         public function getLastLog(){
            $username = $_POST['username'];
            $ojtProgram = $this->getOjtProgramForStud($username);
            $ojtP = $ojtProgram->ojt_program;
            $latestId = $this->db->query("SELECT MAX(id) AS latest_id FROM logs WHERE id_number = '$username' AND ojt_program = '$ojtP'")->row();
            $maxId = $latestId->latest_id;
            $lastlog = $this->db->query("SELECT * FROM logs WHERE id = $maxId")->row();

             echo json_encode($lastlog);
         }  

         public function loadSpecificLog(){
            $id = $_POST['log_id'];

          
            $log = $this->db->query("SELECT * FROM logs WHERE id = $id")->row();

             echo json_encode($log);
         }
        



         //import csv
         public function importCSV(){
            $admin_id = $this->session->userdata('id_number');
            $filename=$_FILES["importCSV"]["tmp_name"];      
            $duplicate_names="";

 
             if($_FILES["importCSV"]["size"] > 0)
             {
                $file = fopen($filename, "r");
                fgets($file);
                while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
                 {
                  
                    // $username = strtolower($getData[1].".".$getData[3]);
                    $username = strtolower(str_replace(' ', '',$getData[1]).".".str_replace(' ', '',$getData[0]));
                    $sy=str_replace(' ','',$getData[5]);
                    
                    $result = $this->db->query("SELECT id_number FROM users WHERE id_number = '".$username."'")->result_array();
                    if(in_array($username, array_column($result, 'id_number'))){
                      $key = array_search($username, array_column($result, 'id_number'));
                      $existStuds[] = $result[$key];
                     
                    } else{
                      if($getData[7]!=""){
                         $total_hours = $getData[6]+$getData[7];
                      }else{
                        $total_hours = $getData[6];
                      }
                      $program = $getData[8];

                      if($program == 1){
                          $this->db->query("INSERT INTO users (id_number,admin_id,first_name,middle_initial,last_name,course,year,school_year,password,ojt_program) 
                        values ('$username','$admin_id','".$getData[1]."','".$getData[2]."','".$getData[0]."','".$getData[3]."','".$getData[4]."','$sy','123456', 'ojt_one')");
                         $this->db->query("INSERT INTO ojt_records(id_number,total_hours,ojtone_required,ojttwo_required) VALUES('$username',$total_hours,'".$getData[6]."','".$getData[7]."')");
                      }else{
                          $this->db->query("INSERT INTO users (id_number,admin_id,first_name,middle_initial,last_name,course,year,school_year,password,ojt_program) 
                        values ('$username','$admin_id','".$getData[1]."','".$getData[2]."','".$getData[0]."','".$getData[3]."','".$getData[4]."','$sy','123456', 'ojt_two')");
                         $this->db->query("INSERT INTO ojt_records(id_number,total_hours,ojtone_required,ojttwo_required) VALUES('$username',$total_hours,'".$getData[6]."','".$getData[7]."')");
                      }
                      
                    }
                    
                 }
{'fraction_non_alphanumeric': 0.15289914386213305, 'fraction_numerical': 0.0028427316771010773, 'mean_word_length': 1.809241190727736, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 1028, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1525990', 'n_tokens_mistral': 25515, 'n_tokens_neox': 24168, 'n_words': 4764}