<?php
require '../connections/conn.php';
$app = $_GET['app_id'];
$p = "SELECT * FROM `appointment`, `patient` WHERE `appointment`.`p_id` = `patient`.`p_id` AND app_id = $app";
$r = $conn->query($p);

while ($row = mysqli_fetch_array($r)) {
    $name = $row['p_name'];
    $date = $row['date'];
    $treat = $row['test'];
    $age = $row['p_age'];
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Appointment Print</title>
    <style>
        .button-30 {
            align-items: center;
            appearance: none;
            background-color: #FCFCFD;
            border-radius: 4px;
            border-width: 0;
            box-shadow: rgba(45, 35, 66, 0.4) 0 2px 4px,
                        rgba(45, 35, 66, 0.3) 0 7px 13px -3px,
                        #D6D6E7 0 -3px 0 inset;
            box-sizing: border-box;
            color: #36395A;
            cursor: pointer;
            display: inline-flex;
            font-family: "JetBrains Mono", monospace;
            height: 48px;
            justify-content: center;
            line-height: 1;
            list-style: none;
            padding: 0 16px;
            text-decoration: none;
            transition: box-shadow .15s, transform .15s;
            font-size: 18px;
        }

        .button-30:hover {
            box-shadow: rgba(45, 35, 66, 0.4) 0 4px 8px,
                        rgba(45, 35, 66, 0.3) 0 7px 13px -3px,
                        #D6D6E7 0 -3px 0 inset;
            transform: translateY(-2px);
        }

        .button-30:active {
            box-shadow: #D6D6E7 0 3px 7px inset;
            transform: translateY(2px);
        }

        @media print {
            .button-30 {
                display: none;
            }
        }
    </style>

    <script>
        function printdiv(printpage) {
            var headstr = "<html><head><title>Print</title></head><body>";
            var footstr = "</body></html>";
            var newstr = document.getElementById(printpage).innerHTML;
            var oldstr = document.body.innerHTML;

            document.body.innerHTML = headstr + newstr + footstr;
            window.print();
            document.body.innerHTML = oldstr;
            location.reload();
            return false;
        }
    </script>
</head>
<body>
    <br><br>
    <center>
        <div id="div_print" style="width: 100%;">
            <table style="margin-top: 190px;">
                <tr>
						<td width="50px">Name:</td>
						<td width="200px"><?php echo $name;?></td>
						<td width="40px">Age:</td>
						<td width="100px"><?php 
						$dateOfBirth = $age;
						$today = date("Y-m-d");
						$diff = date_diff(date_create($dateOfBirth), date_create($today));
						echo $diff->format('%y')." Years";
						?></td>
						<td width="50px">Date:</td>
						<td width="100px">
						<?php 
						$unixTime = strtotime($date);

						
						$newDate = date("d-m-Y", $unixTime);
						echo $newDate;
						?>
						</td>
					</tr>
            </table>
            <hr><br>
            <textarea cols="50" rows="20" style="font-size:18px; text-align:left; border:none; overflow:auto;" readonly><?php echo $treat; ?></textarea><br>
        </div>

        <input name="b_print" type="button" class="button-30" onClick="printdiv('div_print');" value="Print">
        <a class="button-30" href="home.php">Done</a>
    </center>
</body>
</html>
