<?php

ini_set('display_errors', 1);

function validateFacultyAccess($conn_rjllearning,$institution_id,$branch_id,$class_id,$subject_id,$userid){
    
        //check faculty or coordinator
        $sql = "Select count(*) as total from users where id  =? and institution_id = ?";
        $validate_faculty = $conn_rjllearning->prepare($sql);
        $validate_faculty->execute(array($userid,$institution_id));
        $result_faculty = $validate_faculty->fetchAll()[0]['total'];
      
        if ($result_faculty == 1) {
       
         $sql = "Select count(*) as total from timetable where institution_id = ? and branch_id = ? and class_id = ? and subject_id = ? and faculty_id = ?";
        $validate_faculty = $conn_rjllearning->prepare($sql);
        $validate_faculty->execute(array($institution_id,$branch_id,$class_id,$subject_id,$userid));
        $result = $validate_faculty->fetchAll()[0]['total'];
        
          if ($result >= 1) {
           
              return true;
              
          } else {
            return false;
        }   
 
            
        } else {
            return false;
        }   
 
}