<?php
session_start();
include('header.php');
require_once('../includes/database.php');

// Assuming $webdata and $udata are defined somewhere in your code
$color_obj = json_decode($webdata['color_json']);

// Default color values
$main_color = isset($color_obj->{'main_color'}) ? $color_obj->{'main_color'} : '#3498db';
$supportive_color = isset($color_obj->{'supportive_color'}) ? $color_obj->{'supportive_color'} : '#2ecc71';
$text_color = isset($color_obj->{'text_color'}) ? $color_obj->{'text_color'} : '#ffffff';
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Certificate">
    <title>Certificate</title>

    <link href="../bootstrap/css/sb-admin-2.min.css" rel="stylesheet">
    <style>
        @media print {
            body {
                -webkit-print-color-adjust: exact;
                print-color-adjust: exact;
            }
        }

        #certificate {
            width: 800px;
            height: 500px;
            padding: 20px;
            text-align: center;
            border: 10px solid white;
        }

        .bg-gradient-primary {
            background-image: linear-gradient(180deg, <?php echo $main_color; ?> 10%, <?php echo $supportive_color; ?> 100%);
        }

        .text-white {
            color: <?php echo $text_color; ?>;
        }
    </style>
</head>

<body>
    

    <script>
        window.onload = function () {
            document.addEventListener("contextmenu", function (e) {
                e.preventDefault();
            }, false);

            document.addEventListener("keydown", function (e) {
                if (e.ctrlKey && e.keyCode == 80) { // "Ctrl + P" for printing
                    printCertificate();
                }
            }, false);

            function printCertificate() {
                var printWindow = window.open('', '_blank');
                printWindow.document.write('<html><head><title>Certificate</title></head><body>');
                printWindow.document.write(document.getElementById('certificate').innerHTML);
               
                printWindow.document.close();
                printWindow.print();
            }
        };
    </script>
<script language="JavaScript">
  /**
    * Disable right-click of mouse, F12 key, and save key combinations on page
    * By Nirmal Singh (nsdausa@gmail.com)
    * For full source code, visit http://www.mycyberuniverse.com
    */
  window.onload = function() {
    document.addEventListener("contextmenu", function(e){
      e.preventDefault();
    }, false);
    document.addEventListener("keydown", function(e) {
    //document.onkeydown = function(e) {
       // "I" key
      if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
        disabledEvent(e);
      }
      // "J" key
      if (e.ctrlKey && e.shiftKey && e.keyCode == 74) {
        disabledEvent(e);
      }
      // "S" key + macOS
      if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        disabledEvent(e);
      }
      // "R" key
      if (e.ctrlKey && e.keyCode == 82) {
        disabledEvent(e);
      }
      // "N" key
      if (e.ctrlKey && e.keyCode == 78) {
        disabledEvent(e);
      }
      // "T" key
      if (e.ctrlKey && e.keyCode == 84) {
        disabledEvent(e);
      }
      

      // "O" key
      if (e.ctrlKey && e.keyCode == 79) {
        disabledEvent(e);
      }
      // "P" key
      if (e.ctrlKey && e.keyCode == 80) {
        disabledEvent(e);
      }

      // "A" key
      if (e.ctrlKey && e.keyCode == 65) {
        disabledEvent(e);
      }
      // "F" key
      if (e.ctrlKey && e.keyCode == 70) {
        disabledEvent(e);
      }
      // "G" key
      if (e.ctrlKey && e.keyCode == 71) {
        disabledEvent(e);
      }
      // "H" key
      if (e.ctrlKey && e.keyCode == 72) {
        disabledEvent(e);
      }
      // "J" key
      if (e.ctrlKey && e.keyCode == 74) {
        disabledEvent(e);
      }
      // "U" key
      if (e.ctrlKey && e.keyCode == 85) {
        disabledEvent(e);
      }
      // "F12" key
      if (event.keyCode == 123) {
        disabledEvent(e);
      }
      if (event.keyCode == 116) {
        disabledEvent(e);
      }
    }, false);
    function disabledEvent(e){
      if (e.stopPropagation){
        e.stopPropagation();
      } else if (window.event){
        window.event.cancelBubble = true;
      }
      e.preventDefault();
      return false;
    }
  };
</script>
  <link href="../bootstrap/css/sb-admin-2.min.css" rel="stylesheet">
<?php
$color_obj = json_decode($webdata['color_json']);
?>
<link href="../bootstrap/css/sb-admin-2.min.css" rel="stylesheet">

<style>
  .bg-gradient-primary {
    background-image: linear-gradient(180deg, <?php echo $main_color; ?> 10%, <?php echo $supportive_color; ?> 100%);
  }

  .text-white {
    color: <?php echo $text_color; ?>;
  }

  /* Add more styles as needed */
</style>

<body onload="window.print()" oncontextmenu="return false;">
  <div style="width:800px; height:500px; padding:20px; text-align:center; border: 10px solid white;" class="bg-gradient-primary">
    <div style="width:750px; height:450px; padding:20px; text-align:center; border: 4px solid white">
      <span style="font-size:50px; font-weight:bold" class="text-white">Certificate of Authorization</span>
      <br><hr style="border: 0.4px solid <?php echo $supportive_color; ?>; border-radius: 1px;">
      <span style="font-size:25px" class="text-white"><i>This is to certify that Mr/Ms</i></span><br>
      <span style="font-size:25px" class="text-white"><i> <?php echo ucwords($udata['name']); ?></i></span> <br/><br/>
      <span style="font-size:25px" class="text-white"><i>Has Been Appointed as <?php echo ucwords($udata['usertype']); ?></i></span> <br/><br/>
      <span style="font-size:20px" class="text-white"><b>In <?php echo ucwords($ahkweb['name']); ?></span></b></span><br/>
      <hr style="border: 0.4px solid <?php echo $main_color; ?>; border-radius: 1px;">
      <div class="row">
        <div class="col-sm-6 text-center">
    <img src="https://i0.wp.com/www.kekarjawalekar.com/wp-content/uploads/2018/12/csc-logo.jpg?fit=1581%2C705&ssl=1" class="mx-auto d-block" width="450" height="50">
</div>

        <?php
        $qr_data = "Name: " . $udata['name'] . ",  Appointed as: " . ucwords($udata['usertype']) . ", Shop: " . strtoupper(str_replace('&', ' ', $ahkweb['name'])) . "";
        ?>
        
        <br>
        <span style="font-size:10px" class="text-white">THIS IS COMPUTER GENERATED CERTIFICATE DOES NOT REQUIRE SIGNATURE.</span><br/>
      </div>
      <hr>
      
    </div>
  </div>
</body>
