<?php
require("connection.php");
// registration code
// session_start();

if(isset($_POST['submit'])){
  
  $email = mysqli_real_escape_string($con, $_POST['useremail']);
  $password = mysqli_real_escape_string($con, $_POST['userpassword']);

  $query = "SELECT * FROM admintable WHERE useremail = '$email' AND userpassword = '$password'";

  $output = mysqli_query($con, $query);

  if(mysqli_fetch_array($output) > 0){
      session_start();
      $_SESSION['useremail'] = $email;
   header("location: front_staff.php");
   exit();
  }else{
   echo "<script>alert('Oooop! Wrong Email or Password')</script>";
  }
}

// core staff section
if(isset($_POST['corestaff'])){
    $fname = mysqli_real_escape_string($con, $_POST['fname']);
    $lname = mysqli_real_escape_string($con, $_POST['lname']);
    $middlename = mysqli_real_escape_string($con, $_POST['middlename']);
    $email = mysqli_real_escape_string($con, $_POST['email']);
    $phone = mysqli_real_escape_string($con, $_POST['phone']);
    $rank = mysqli_real_escape_string($con, $_POST['rank']);
    $department = mysqli_real_escape_string($con, $_POST['department']);
    $qualification1 = mysqli_real_escape_string($con, $_POST['qualification1']);
    $qualification2 = mysqli_real_escape_string($con, $_POST['qualification2']);
    $qualification3 = mysqli_real_escape_string($con, $_POST['qualification3']);
    $qualification4 = mysqli_real_escape_string($con, $_POST['qualification4']);
    $course_assigned = mysqli_real_escape_string($con, $_POST['course_assigned']);

    //path where our images will be stored
    $images1 = $con->real_escape_string('upload/' .basename($_FILES['images1']['name']));

    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images1']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images1']['tmp_name'], $images1)){
            $_SESSION['images1'] = $images1;

         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
    
    //path where our images will be stored
    $images2 = $con->real_escape_string('upload/' .basename($_FILES['images2']['name']));

    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images2']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images2']['tmp_name'], $images2)){
            $_SESSION['images2'] = $images2;

         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
 //path where our images will be stored
 $images3 = $con->real_escape_string('upload/' .basename($_FILES['images3']['name']));

 //make sure the file type is images
 if(preg_match("!image!", $_FILES['images3']['type'])){
      //copy images to upload folder
      if(copy($_FILES['images3']['tmp_name'], $images3)){
         $_SESSION['images3'] = $images3;

      }else{
         $_SESSION['message'] = 'file upload failed';
      }
 }
  //path where our images will be stored
  $images4 = $con->real_escape_string('upload/' .basename($_FILES['images4']['name']));

  //make sure the file type is images
  if(preg_match("!image!", $_FILES['images4']['type'])){
       //copy images to upload folder
       if(copy($_FILES['images4']['tmp_name'], $images4)){
          $_SESSION['images4'] = $images4;

       }else{
          $_SESSION['message'] = 'file upload failed';
       }
  }



    $query = "INSERT INTO corestaff(fname, lname, middlename, email, phone, rank,department, qualification1, qualification2, qualification3, qualification4, course_assigned, images1,images2, images3, images4)
     VALUE('$fname','$lname','$middlename','$email','$phone','$rank','$department','$qualification1','$qualification2','$qualification3','$qualification4','$course_assigned', '$images1','$images2','$images3','$images4')";

     if(mysqli_query($con, $query)){
        echo "<script>alert('Staff Record Inserted Successfully')</script>";
     }else{
        echo "<script>alert('Staff Record Not Inserted Successfully')</script>";   
     }
}



// service staff section
if(isset($_POST['servicestaff'])){

   $fname = mysqli_real_escape_string($con, $_POST['fname']);
   $lname = mysqli_real_escape_string($con, $_POST['lname']);
   $middlename = mysqli_real_escape_string($con, $_POST['middlename']);
   $email = mysqli_real_escape_string($con, $_POST['email']);
   $phone = mysqli_real_escape_string($con, $_POST['phone']);
   $rank = mysqli_real_escape_string($con, $_POST['rank']);
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $qualification1 = mysqli_real_escape_string($con, $_POST['qualification1']);
   $qualification2 = mysqli_real_escape_string($con, $_POST['qualification2']);
   $qualification3 = mysqli_real_escape_string($con, $_POST['qualification3']);
   $qualification4 = mysqli_real_escape_string($con, $_POST['qualification4']);
   $course_assigned = mysqli_real_escape_string($con, $_POST['course_assigned']);

    //path where our images will be stored
    $images1 = $con->real_escape_string('upload/' .basename($_FILES['images1']['name']));

    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images1']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images1']['tmp_name'], $images1)){
            $_SESSION['images1'] = $images1;

         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
    
    //path where our images will be stored
    $images2 = $con->real_escape_string('upload/' .basename($_FILES['images2']['name']));

    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images2']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images2']['tmp_name'], $images2)){
            $_SESSION['images2'] = $images2;

         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
 //path where our images will be stored
 $images3 = $con->real_escape_string('upload/' .basename($_FILES['images3']['name']));

 //make sure the file type is images
 if(preg_match("!image!", $_FILES['images3']['type'])){
      //copy images to upload folder
      if(copy($_FILES['images3']['tmp_name'], $images3)){
         $_SESSION['images3'] = $images3;

      }else{
         $_SESSION['message'] = 'file upload failed';
      }
 }
  //path where our images will be stored
  $images4 = $con->real_escape_string('upload/' .basename($_FILES['images4']['name']));

  //make sure the file type is images
  if(preg_match("!image!", $_FILES['images4']['type'])){
       //copy images to upload folder
       if(copy($_FILES['images4']['tmp_name'], $images4)){
          $_SESSION['images4'] = $images4;

       }else{
          $_SESSION['message'] = 'file upload failed';
       }
  }


  $query = "INSERT INTO servicestaff(fname, lname, middlename, email, phone, rank,department, qualification1, qualification2, qualification3, qualification4, course_assigned, images1,images2, images3, images4)
  VALUE('$fname','$lname','$middlename','$email','$phone','$rank','$department','$qualification1','$qualification2','$qualification3','$qualification4','$course_assigned', '$images1','$images2','$images3','$images4')";

  if(mysqli_query($con, $query)){
     echo "<script>alert('Staff Record Inserted Successfully')</script>";
  }else{
     echo "<script>alert('Staff Record Not Inserted Successfully')</script>";   
  }
}


// administrative staff section
if(isset($_POST['administrativestaff'])){
   
   $fname = mysqli_real_escape_string($con, $_POST['fname']);
   $lname = mysqli_real_escape_string($con, $_POST['lname']);
   $middlename = mysqli_real_escape_string($con, $_POST['middlename']);
   $email = mysqli_real_escape_string($con, $_POST['email']);
   $phone = mysqli_real_escape_string($con, $_POST['phone']);
   $rank = mysqli_real_escape_string($con, $_POST['rank']);
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $qualification1 = mysqli_real_escape_string($con, $_POST['qualification1']);
   $qualification2 = mysqli_real_escape_string($con, $_POST['qualification2']);
   $qualification3 = mysqli_real_escape_string($con, $_POST['qualification3']);
   $qualification4 = mysqli_real_escape_string($con, $_POST['qualification4']);
   $course_assigned = mysqli_real_escape_string($con, $_POST['course_assigned']);

       //path where our images will be stored
       $images1 = $con->real_escape_string('upload/' .basename($_FILES['images1']['name']));

       //make sure the file type is images
       if(preg_match("!image!", $_FILES['images1']['type'])){
            //copy images to upload folder
            if(copy($_FILES['images1']['tmp_name'], $images1)){
               $_SESSION['images1'] = $images1;
   
            }else{
               $_SESSION['message'] = 'file upload failed';
            }
       }
       
       //path where our images will be stored
       $images2 = $con->real_escape_string('upload/' .basename($_FILES['images2']['name']));
   
       //make sure the file type is images
       if(preg_match("!image!", $_FILES['images2']['type'])){
            //copy images to upload folder
            if(copy($_FILES['images2']['tmp_name'], $images2)){
               $_SESSION['images2'] = $images2;
   
            }else{
               $_SESSION['message'] = 'file upload failed';
            }
       }
    //path where our images will be stored
    $images3 = $con->real_escape_string('upload/' .basename($_FILES['images3']['name']));
   
    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images3']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images3']['tmp_name'], $images3)){
            $_SESSION['images3'] = $images3;
   
         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
     //path where our images will be stored
     $images4 = $con->real_escape_string('upload/' .basename($_FILES['images4']['name']));
   
     //make sure the file type is images
     if(preg_match("!image!", $_FILES['images4']['type'])){
          //copy images to upload folder
          if(copy($_FILES['images4']['tmp_name'], $images4)){
             $_SESSION['images4'] = $images4;
   
          }else{
             $_SESSION['message'] = 'file upload failed';
          }
     }
   
   
     $query = "INSERT INTO administrativestaff(fname, lname, middlename, email, phone, rank,department , qualification1, qualification2, qualification3, qualification4, course_assigned, images1,images2, images3, images4)
     VALUE('$fname','$lname','$middlename','$email','$phone','$rank','$department','$qualification1','$qualification2','$qualification3','$qualification4','$course_assigned', '$images1','$images2','$images3','$images4')";
   
     if(mysqli_query($con, $query)){
        echo "<script>alert('Staff Record Inserted Successfully')</script>";
     }else{
        echo "<script>alert('Staff Record Not Inserted Successfully')</script>";   
     }
}


// Technical staff section
if(isset($_POST['technicalstaff'])){
   $fname = mysqli_real_escape_string($con, $_POST['fname']);
   $lname = mysqli_real_escape_string($con, $_POST['lname']);
   $middlename = mysqli_real_escape_string($con, $_POST['middlename']);
   $email = mysqli_real_escape_string($con, $_POST['email']);
   $phone = mysqli_real_escape_string($con, $_POST['phone']);
   $rank = mysqli_real_escape_string($con, $_POST['rank']);
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $qualification1 = mysqli_real_escape_string($con, $_POST['qualification1']);
   $qualification2 = mysqli_real_escape_string($con, $_POST['qualification2']);
   $qualification3 = mysqli_real_escape_string($con, $_POST['qualification3']);
   $qualification4 = mysqli_real_escape_string($con, $_POST['qualification4']);
   $lab_assigned = mysqli_real_escape_string($con, $_POST['lab_assigned']);

    //path where our images will be stored
    $images1 = $con->real_escape_string('upload/' .basename($_FILES['images1']['name']));

    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images1']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images1']['tmp_name'], $images1)){
            $_SESSION['images1'] = $images1;

         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
    
    //path where our images will be stored
    $images2 = $con->real_escape_string('upload/' .basename($_FILES['images2']['name']));

    //make sure the file type is images
    if(preg_match("!image!", $_FILES['images2']['type'])){
         //copy images to upload folder
         if(copy($_FILES['images2']['tmp_name'], $images2)){
            $_SESSION['images2'] = $images2;

         }else{
            $_SESSION['message'] = 'file upload failed';
         }
    }
 //path where our images will be stored
 $images3 = $con->real_escape_string('upload/' .basename($_FILES['images3']['name']));

 //make sure the file type is images
 if(preg_match("!image!", $_FILES['images3']['type'])){
      //copy images to upload folder
      if(copy($_FILES['images3']['tmp_name'], $images3)){
         $_SESSION['images3'] = $images3;

      }else{
         $_SESSION['message'] = 'file upload failed';
      }
 }
  //path where our images will be stored
  $images4 = $con->real_escape_string('upload/' .basename($_FILES['images4']['name']));

  //make sure the file type is images
  if(preg_match("!image!", $_FILES['images4']['type'])){
       //copy images to upload folder
       if(copy($_FILES['images4']['tmp_name'], $images4)){
          $_SESSION['images4'] = $images4;

       }else{
          $_SESSION['message'] = 'file upload failed';
       }
  }

  $query = "INSERT INTO technicalstaff(fname, lname, middlename, email, phone, rank, department, qualification1, qualification2, qualification3, qualification4, lab_assigned, images1,images2, images3, images4)
  VALUE('$fname','$lname','$middlename','$email','$phone','$rank','$department','$qualification1','$qualification2','$qualification3','$qualification4','$lab_assigned', '$images1','$images2','$images3','$images4')";

  if(mysqli_query($con, $query)){
     echo "<script>alert('Staff Record Inserted Successfully')</script>";
  }else{
     echo "<script>alert('Staff Record Not Inserted Successfully')</script>";   
  }

}
  // Biz equipment section
  if(isset($_POST['equip'])){
      $department = mysqli_real_escape_string($con, $_POST['department']);
      $title1 = mysqli_real_escape_string($con, $_POST['title1']);


       // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO equipment(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
  }
//equipment view code
  if (isset($_GET['equip_id'])) {
   $id = $_GET['equip_id'];

   // fetch file to download from database
   $sql = "SELECT * FROM equipment WHERE equip_id=$id";
   $result = mysqli_query($con, $sql);

   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];

   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);

       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE equipment SET downloads=$newCount WHERE equip_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }

}


   // Biz Project work section
   if(isset($_POST['projectwork'])){
      $department = mysqli_real_escape_string($con, $_POST['department']);
      $title1 = mysqli_real_escape_string($con, $_POST['title1']);


     // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO projectwork(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
      }
  }

  //project work view code
if (isset($_GET['projectwork_id'])) {
   $id = $_GET['projectwork_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM projectwork WHERE projectwork_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE projectwork SET downloads=$newCount WHERE projectwork_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


  // Biz practicals section
  if(isset($_POST['practicals'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);


   // name of the uploaded file
   $images1 = $_FILES['images1']['name'];

   // destination of the file on the server
   $destination = 'upload/' . $images1;

   // get the file extension
   $extension = pathinfo($images1, PATHINFO_EXTENSION);

   // the physical file on a temporary uploads directory on the server
   $file = $_FILES['images1']['tmp_name'];
   $size = $_FILES['images1']['size'];

   if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
    echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
} elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
  echo "<script>alert('File too large!')</script>";
 } else {
     // move the uploaded (temporary) file to the specified destination
     if (move_uploaded_file($file, $destination)) {

        $query = "INSERT INTO practicals(department, title1, images1) VALUE('$department','$title1', '$images1')";
         if (mysqli_query($con, $query)) {
           echo "<script>alert('Record Inserted Successfully')</script>";
         }
     } else {
        echo "<script>alert('Record Not Inserted Successfully')</script>";  
     }
}
  }

  //practicals work view code
if (isset($_GET['practicals_id'])) {
   $id = $_GET['practicals_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM practicals WHERE practicals_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE practicals SET downloads=$newCount WHERE practicals_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

// Biz Success Rate section
if(isset($_POST['successrate'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);

       // name of the uploaded file
       $images1 = $_FILES['images1']['name'];

       // destination of the file on the server
       $destination = 'upload/' . $images1;
   
       // get the file extension
       $extension = pathinfo($images1, PATHINFO_EXTENSION);
   
       // the physical file on a temporary uploads directory on the server
       $file = $_FILES['images1']['tmp_name'];
       $size = $_FILES['images1']['size'];
   
       if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
        echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
    } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
      echo "<script>alert('File too large!')</script>";
     } else {
         // move the uploaded (temporary) file to the specified destination
         if (move_uploaded_file($file, $destination)) {
   
            $query = "INSERT INTO successrate(department, title1, images1) VALUE('$department','$title1', '$images1')";
             if (mysqli_query($con, $query)) {
               echo "<script>alert('Record Inserted Successfully')</script>";
             }
         } else {
            echo "<script>alert('Record Not Inserted Successfully')</script>";  
         }
     }
}

  //successrate work view code
  if (isset($_GET['successrate_id'])) {
   $id = $_GET['successrate_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM successrate WHERE successrate_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE successrate SET downloads=$newCount WHERE successrate_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

// Biz Time Table section
if(isset($_POST['titmetable'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
  

       // name of the uploaded file
       $images1 = $_FILES['images1']['name'];

       // destination of the file on the server
       $destination = 'upload/' . $images1;
   
       // get the file extension
       $extension = pathinfo($images1, PATHINFO_EXTENSION);
   
       // the physical file on a temporary uploads directory on the server
       $file = $_FILES['images1']['tmp_name'];
       $size = $_FILES['images1']['size'];
   
       if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
        echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
    } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
      echo "<script>alert('File too large!')</script>";
     } else {
         // move the uploaded (temporary) file to the specified destination
         if (move_uploaded_file($file, $destination)) {
   
            $query = "INSERT INTO timetable(department, title1, images1) VALUE('$department','$title1', '$images1')";
             if (mysqli_query($con, $query)) {
               echo "<script>alert('Record Inserted Successfully')</script>";
             }
         } else {
            echo "<script>alert('Record Not Inserted Successfully')</script>";  
         }
     }
}

  //timetable work view code
  if (isset($_GET['timetable_id'])) {
   $id = $_GET['timetable_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM timetable WHERE timetable_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE timetable SET downloads=$newCount WHERE timetable_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

// Biz curriculum section
if(isset($_POST['Curriculum'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);


   // name of the uploaded file
   $images1 = $_FILES['images1']['name'];

   // destination of the file on the server
   $destination = 'upload/' . $images1;

   // get the file extension
   $extension = pathinfo($images1, PATHINFO_EXTENSION);

   // the physical file on a temporary uploads directory on the server
   $file = $_FILES['images1']['tmp_name'];
   $size = $_FILES['images1']['size'];

   if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
    echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
} elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
  echo "<script>alert('File too large!')</script>";
 } else {
     // move the uploaded (temporary) file to the specified destination
     if (move_uploaded_file($file, $destination)) {

        $query = "INSERT INTO Curriculum(department, title1, images1) VALUE('$department','$title1', '$images1')";
         if (mysqli_query($con, $query)) {
           echo "<script>alert('Record Inserted Successfully')</script>";
         }
     } else {
        echo "<script>alert('Record Not Inserted Successfully')</script>";  
     }
 }
}

  //Curriculum work view code
  if (isset($_GET['Curriculum_id'])) {
   $id = $_GET['Curriculum_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM Curriculum WHERE Curriculum_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE Curriculum SET downloads=$newCount WHERE Curriculum_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz marking Scheme section
if(isset($_POST['MarkingScheme'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);

   // name of the uploaded file
   $images1 = $_FILES['images1']['name'];

   // destination of the file on the server
   $destination = 'upload/' . $images1;

   // get the file extension
   $extension = pathinfo($images1, PATHINFO_EXTENSION);

   // the physical file on a temporary uploads directory on the server
   $file = $_FILES['images1']['tmp_name'];
   $size = $_FILES['images1']['size'];

   if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
    echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
} elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
  echo "<script>alert('File too large!')</script>";
 } else {
     // move the uploaded (temporary) file to the specified destination
     if (move_uploaded_file($file, $destination)) {

        $query = "INSERT INTO MarkingScheme(department, title1, images1) VALUE('$department','$title1', '$images1')";
         if (mysqli_query($con, $query)) {
           echo "<script>alert('Record Inserted Successfully')</script>";
         }
     } else {
        echo "<script>alert('Record Not Inserted Successfully')</script>";  
     }
 }
}

//MarkingScheme work view code
if (isset($_GET['MarkingScheme_id'])) {
   $id = $_GET['MarkingScheme_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM markingscheme WHERE MarkingScheme_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE markingscheme SET downloads=$newCount WHERE MarkingScheme_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz Student list section 
if(isset($_POST['studentlist'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO studentlist(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//studentlist work view code
if (isset($_GET['studentlist_id'])) {
   $id = $_GET['studentlist_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM studentlist WHERE studentlist_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE studentlist SET downloads=$newCount WHERE studentlist_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

// Biz architechturaldesign section 
if(isset($_POST['architechturaldesign'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO architechturaldesign(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//architechtural design work view code
if (isset($_GET['architechturaldesign_id'])) {
   $id = $_GET['architechturaldesign_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM architechturaldesign WHERE architechturaldesign_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE architechturaldesign SET downloads=$newCount WHERE architechturaldesign_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz handbook section 
if(isset($_POST['Handbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO handbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//architechtural design work view code
if (isset($_GET['handbook_id'])) {
   $id = $_GET['handbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM handbook WHERE handbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE handbook SET downloads=$newCount WHERE handbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

 // Biz computer sciences  section 
if(isset($_POST['computerscience'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO computerscience (department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Computer science work view code
if (isset($_GET['computerscience_id'])) {
   $id = $_GET['computerscience_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM computerscience WHERE computerscience_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE computerscience SET downloads=$newCount WHERE computerscience_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


 // Biz Science lab technology section 
 if(isset($_POST['science'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO science (department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Science lab technology work view code
if (isset($_GET['science_id'])) {
   $id = $_GET['science_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM science WHERE science_id =$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE science SET downloads=$newCount WHERE science_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

 // Biz Electrical Electronics Engineering section 
 if(isset($_POST['electrical'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO electrical (department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Electrical Electronics Engineerings work view code
if (isset($_GET['electrical_id'])) {
   $id = $_GET['electrical_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM electrical WHERE electrical_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE electrical SET downloads=$newCount WHERE electrical_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

  // Biz Computer Engineering section 
  if(isset($_POST['computerengineering'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO computerengineering(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Computer Engineering view code
if (isset($_GET['engineering_id'])) {
   $id = $_GET['engineering_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM computerengineering WHERE engineering_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE computerengineering SET downloads=$newCount WHERE  	engineering_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }



 // Biz Marine Engineering Technolog Book section 
  if(isset($_POST['Marineengineering'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO Marineengineering(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Marine Engineering Technolog view code
if (isset($_GET['marine_id'])) {
   $id = $_GET['marine_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM Marineengineering WHERE marine_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE Marineengineering SET downloads=$newCount WHERE marine_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz Business Administration section 
  if(isset($_POST['BusinessAdministration'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO BusinessAdministration(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Business Administrationview code
if (isset($_GET['business_id'])) {
   $id = $_GET['business_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM BusinessAdministration WHERE business_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE BusinessAdministration SET downloads=$newCount WHERE business_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }



// Biz Maritime Transport And Business Studies Books section 
  if(isset($_POST['Maritimetransportandbusinessstudies'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO Maritimetransportandbusinessstudies(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Maritime Transport And Business Studies Books  view code
if (isset($_GET['maritimetran_id'])) {
   $id = $_GET['maritimetran_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM Maritimetransportandbusinessstudies WHERE maritimetran_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE Maritimetransportandbusinessstudies SET downloads=$newCount WHERE maritimetran_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz efficientdeckhandbook section 
  if(isset($_POST['efficientdeckhandbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO efficientdeckhandbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//efficientdeckhandbook view code
if (isset($_GET['efficientdeckhandbook_id'])) {
   $id = $_GET['efficientdeckhandbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM efficientdeckhandbook WHERE efficientdeckhandbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE efficientdeckhandbook SET downloads=$newCount WHERE efficientdeckhandbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

// Biz medicalfirstaidbook section 
  if(isset($_POST['medicalfirstaidbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO medicalfirstaidbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//medicalfirstaidbook view code
if (isset($_GET['medicalfirstaidbook_id'])) {
   $id = $_GET['medicalfirstaidbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM medicalfirstaidbook WHERE medicalfirstaidbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE medicalfirstaidbook SET downloads=$newCount WHERE medicalfirstaidbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }
 
 
 // Biz motormanbook section 
  if(isset($_POST['motormanbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO motormanbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//motormanbook view code
if (isset($_GET['motormanbook_id'])) {
   $id = $_GET['motormanbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM motormanbook WHERE motormanbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE motormanbook SET downloads=$newCount WHERE motormanbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz auditsafetymanagementbook section 
  if(isset($_POST['auditsafetymanagementbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO auditsafetymanagementbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//auditsafetymanagementbook view code
if (isset($_GET['auditsafetymanagementbook_id'])) {
   $id = $_GET['auditsafetymanagementbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM auditsafetymanagementbook WHERE auditsafetymanagementbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE auditsafetymanagementbook SET downloads=$newCount WHERE auditsafetymanagementbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }
 
 
 // Biz confinedspaceentrybook section 
  if(isset($_POST['confinedspaceentrybook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO confinedspaceentrybook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//confinedspaceentrybook view code
if (isset($_GET['confinedspaceentrybook_id'])) {
   $id = $_GET['confinedspaceentrybook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM confinedspaceentrybook WHERE confinedspaceentrybook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE confinedspaceentrybook SET downloads=$newCount WHERE confinedspaceentrybook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }
 
 
 
 // Biz engineroomresourcemanagementbook section 
  if(isset($_POST['engineroomresourcemanagementbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO engineroomresourcemanagementbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//engineroomresourcemanagementbook view code
if (isset($_GET['engineroomresourcemanagementbook_id'])) {
   $id = $_GET['engineroomresourcemanagementbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM engineroomresourcemanagementbook WHERE engineroomresourcemanagementbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE engineroomresourcemanagementbook SET downloads=$newCount WHERE engineroomresourcemanagementbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }
 
 
 // Biz liftingmanagementbook section 
  if(isset($_POST['liftingmanagementbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO liftingmanagementbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//liftingmanagementbook view code
if (isset($_GET['liftingmanagementbook_id'])) {
   $id = $_GET['liftingmanagementbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM liftingmanagementbook WHERE liftingmanagementbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE liftingmanagementbook SET downloads=$newCount WHERE liftingmanagementbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }
 
 
 
 // Biz marineengineerassistantbook section 
  if(isset($_POST['marineengineerassistantbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO marineengineerassistantbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//marineengineerassistantbook view code
if (isset($_GET['marineengineerassistantbook_id'])) {
   $id = $_GET['marineengineerassistantbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM marineengineerassistantbook WHERE marineengineerassistantbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE marineengineerassistantbook SET downloads=$newCount WHERE marineengineerassistantbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }
 
 
 // Biz Permittoworksystemtrainingbook section 
  if(isset($_POST['Permittoworksystemtrainingbook'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO Permittoworksystemtrainingbook(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//Permittoworksystemtrainingbook view code
if (isset($_GET['Permittoworksystemtrainingbook_id'])) {
   $id = $_GET['Permittoworksystemtrainingbook_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM Permittoworksystemtrainingbook WHERE Permittoworksystemtrainingbook_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE Permittoworksystemtrainingbook SET downloads=$newCount WHERE Permittoworksystemtrainingbook_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }

 // Biz general study book section 
 if(isset($_POST['generalstudybooks'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO generalstudybooks(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//general study book work view code
if (isset($_GET['generalstudybooks_id'])) {
   $id = $_GET['generalstudybooks_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM generalstudybooks WHERE generalstudybooks_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE generalstudybooks SET downloads=$newCount WHERE generalstudybooks_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }


// Biz student project work section 
if(isset($_POST['studentprojectwork'])){
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $title1 = mysqli_real_escape_string($con, $_POST['title1']);
   

   // name of the uploaded file
    $images1 = $_FILES['images1']['name'];

    // destination of the file on the server
    $destination = 'upload/' . $images1;

    // get the file extension
    $extension = pathinfo($images1, PATHINFO_EXTENSION);

    // the physical file on a temporary uploads directory on the server
    $file = $_FILES['images1']['tmp_name'];
    $size = $_FILES['images1']['size'];

    if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
      echo "<script>alert('You file extension must be .zip, .pdf or .docx')</script>";
  } elseif ($_FILES['images1']['size'] > 15000000) { // file shouldn't be larger than 1Megabyte
    echo "<script>alert('File too large!')</script>";
  } else {
      // move the uploaded (temporary) file to the specified destination
      if (move_uploaded_file($file, $destination)) {

         $query = "INSERT INTO studentprojectwork(department, title1, images1) VALUE('$department','$title1', '$images1')";
          if (mysqli_query($con, $query)) {
            echo "<script>alert('Record Inserted Successfully')</script>";
          }
      } else {
         echo "<script>alert('Record Not Inserted Successfully')</script>";  
      }
  }
}

//student project work view code
if (isset($_GET['studentprojectwork_id'])) {
   $id = $_GET['studentprojectwork_id'];
 
   // fetch file to download from database
   $sql = "SELECT * FROM studentprojectwork WHERE studentprojectwork_id=$id";
   $result = mysqli_query($con, $sql);
 
   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];
 
   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);
 
       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE studentprojectwork SET downloads=$newCount WHERE studentprojectwork_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }
 
 }