<commit_before><?php
include "include/header.php";

// Only allow Employees and Admins to view a pet.
if($_SESSION['authenticated'] < 2) {
    header("Location: " . $http . $_SERVER['HTTP_HOST'] . "/login.php?redirect=" . $redirect);
    die();
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Pet</title>
</head>
<body>

<?php
    
include "include/menu.php";
    
if(!empty($_GET['id'])) {
    $id = $_GET['id'];
    $stmt = $database->prepare("SELECT Vaccines, Picture FROM Pets WHERE ID = :ID");
    $stmt->bindValue(':ID', $id);
    $stmt->execute();
    $pet = $stmt->fetch();
    if(!empty($pet)) {
        if(!empty($_POST['Name']) && !empty($_POST['Breed']) && !empty($_GET['id'])) {

            (!empty($_POST['TwoPeople'])) ? $two = 1 : $two = 0;

            (!empty($_POST['DogOfMonth'])) ? $dom = strtotime($_POST['DogOfMonth']) : $dom = false;

            // Create SQL query based on fields recieved
            $stmt = $database->prepare('Update Pets Set Name=:Name, Breed=:Breed, Age=:Age, Weight=:Weight, Notes=:Notes, Info=:Info, DogOfMonth=:DogOfMonth, Time=:Time, PreferredGroomer=:PreferredGroomer, TwoPeople=:TwoPeople WHERE ID=:ID');
            $stmt->bindValue(':Name', $_POST['Name']);
            $stmt->bindValue(':Breed', $_POST['Breed']);
            (!empty($_POST['Age'])) ? $stmt->bindValue(':Age', $_POST['Age']) : $stmt->bindValue(':Age', NULL);
            (!empty($_POST['Weight'])) ? $stmt->bindValue(':Weight', $_POST['Weight']) : $stmt->bindValue(':Weight', NULL);
            (!empty($_POST['Notes'])) ? $stmt->bindValue(':Notes', $_POST['Notes']) : $stmt->bindValue(':Notes', NULL);
            (!empty($_POST['Info'])) ? $stmt->bindValue(':Info', $_POST['Info']) : $stmt->bindValue(':Info', NULL);
            ($dom != false) ? $stmt->bindValue(':DogOfMonth', $dom) : $stmt->bindValue(':DogOfMonth', NULL);
            (is_array($_POST['Time'])) ? $stmt->bindValue(':Time', json_encode($_POST['Time'])) : $stmt->bindValue(':Time', NULL);
            $stmt->bindValue(':PreferredGroomer', $_POST['PreferredGroomer']);
            $stmt->bindValue(':TwoPeople', $two);
            $stmt->bindValue(':ID', $_GET['id']);
            $stmt->execute();
            $id = $_GET['id'];

            if(!empty($_FILES['Vaccines']['name']) || !empty($_FILES['Picture']['name'])) {
                $stmt = $database->prepare('UPDATE Pets SET Vaccines=:Vaccines, Picture=:Picture WHERE ID = :ID');

                if(!empty($_FILES['Vaccines']['name'])) {
                    if(!file_exists('petdocs/' . $id)) { mkdir('petdocs/' . $id, 0777, 1); }
                    $uploaddir = 'petdocs/' . $id . '/';
                    $vaccines = $uploaddir . basename($_FILES['Vaccines']['name']);
                    if(move_uploaded_file($_FILES['Vaccines']['tmp_name'], $vaccines)) {
                        echo "Vaccines File Uploaded!<br />";
                        $stmt->bindValue(':Vaccines', $vaccines);
                    }
                    else {
                        echo "Upload failed!";
                        $stmt->bindValue(':Vaccines', $pet['Vaccines']);
                    }
                }
                else {
                    $stmt->bindValue(':Vaccines', $pet['Vaccines']);
                }

                if(!empty($_FILES['Picture']['name'])) {
                    if(!file_exists('petdocs/' . $id)) { mkdir('petdocs/' . $id, 0777, 1); }
                    $uploaddir = 'petdocs/' . $id . '/';
                    $picture = $uploaddir . basename($_FILES['Picture']['name']);
                    if(move_uploaded_file($_FILES['Picture']['tmp_name'], $picture)) {
                        echo "Picture Uploaded!<br />";
                        $stmt->bindValue(':Picture', $picture);
                    }
                    else {
                        echo "Upload failed!";
                        $stmt->bindValue(':Picture', $pet['Picture']);
                    }
                }
                else {
                    $stmt->bindValue(':Picture', $pet['Picture']);
                }

                $stmt->bindValue(':ID', $id);
                $stmt->execute();
            }
        }
        $stmt = $database->prepare("SELECT * FROM Pets WHERE ID = :ID");
        $stmt->bindValue(':ID', $id);
        $stmt->execute();
        $pet = $stmt->fetch();
        $pet['Time'] = json_decode($pet['Time'], true);
        $stmt = $database->prepare("SELECT * FROM Scheduling WHERE PetID = :ID");
        $stmt->bindValue(':ID', $id);
        $stmt->execute();
        $events = $stmt->fetchAll();
        $stmt = $database->query("SELECT Timezone FROM Globals");
        $temp = $stmt->fetch();
        $timezone = $temp['Timezone'];
        $stmt = $database->prepare("SELECT FirstName, LastName FROM Owners WHERE ID = :ID");
        $stmt->bindValue(':ID', $pet['OwnedBy']);
        $stmt->execute();
        $owner = $stmt->fetch();
        $stmt = $database->prepare("SELECT Name FROM Users WHERE ID = :ID");
        $stmt->bindValue(':ID', $pet['PreferredGroomer']);
        $stmt->execute();
        $groomername = $stmt->fetch();
        
        if(!empty($_GET['delete'])) {
            $stmt = $database->prepare("DELETE FROM Scheduling WHERE ID = :ID");
            $stmt->bindValue(':ID', $_GET['delete']);
            $stmt->execute();
        }
        
        if(empty($_GET['e'])) { ?>
            <a href="viewpet.php?id=<?php echo $pet['ID']; ?>&e=1">Edit Pet</a>
            <?php echo (!empty($pet['Picture'])) ? '<img src="' . $pet['Picture'] . '" />' : ''; ?>
            <table>
                <tr><td>ID</td><td><?php echo $pet['ID']; ?></td></tr>
                <tr><td>Name</td><td><?php echo $pet['Name']; ?></td></tr>
                <tr><td>Breed</td><td><?php echo $pet['Breed']; ?></td></tr>
                <tr><td>Age</td><td><?php echo $pet['Age']; ?></td></tr>
                <tr><td>Weight</td><td><?php echo $pet['Weight'] ?></td></tr>
                <tr><td>Vaccines</td><td><?php echo ((!empty($pet['Vaccines'])) ? '<a href="' . $pet['Vaccines'] . '">View</a>' : ''); ?></td></tr>
                <tr><td>Notes</td><td><?php echo $pet['Notes']; ?></td></tr>
                <tr><td>Info</td><td><?php echo $pet['Info']; ?></td></tr>
                <tr><td>Dog of the Month Date</td><td><?php echo date('m/d/Y', $pet['DogOfMonth']); ?></td></tr>
                <tr>
                    <td>Time (In Minutes):</td>
                    <td>
                        <strong>Bath Only:</strong><br />
                        Bath Time: <?php echo $pet['Time']['Bath']['BathTime']; ?><br />
                        Groom Time: <?php echo $pet['Time']['Bath']['GroomTime']; ?><br />
                        <strong>Bath &amp; Groom:</strong><br />
                        Bath Time: <?php echo $pet['Time']['Groom']['BathTime']; ?><br />
                        Groom Time: <?php echo $pet['Time']['Groom']['GroomTime']; ?><br />
                    </td><commit_msg>Show breed name isntead of ID on viewpet<commit_after><?php
include "include/header.php";

// Only allow Employees and Admins to view a pet.
if($_SESSION['authenticated'] < 2) {
    header("Location: " . $http . $_SERVER['HTTP_HOST'] . "/login.php?redirect=" . $redirect);
    die();
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Pet</title>
</head>
<body>

<?php
    
include "include/menu.php";
    
if(!empty($_GET['id'])) {
    $id = $_GET['id'];
    $stmt = $database->prepare("SELECT Vaccines, Picture FROM Pets WHERE ID = :ID");
    $stmt->bindValue(':ID', $id);
    $stmt->execute();
    $pet = $stmt->fetch();
    if(!empty($pet)) {
        if(!empty($_POST['Name']) && !empty($_POST['Breed']) && !empty($_GET['id'])) {

            (!empty($_POST['TwoPeople'])) ? $two = 1 : $two = 0;

            (!empty($_POST['DogOfMonth'])) ? $dom = strtotime($_POST['DogOfMonth']) : $dom = false;

            // Create SQL query based on fields recieved
            $stmt = $database->prepare('Update Pets Set Name=:Name, Breed=:Breed, Age=:Age, Weight=:Weight, Notes=:Notes, Info=:Info, DogOfMonth=:DogOfMonth, Time=:Time, PreferredGroomer=:PreferredGroomer, TwoPeople=:TwoPeople WHERE ID=:ID');
            $stmt->bindValue(':Name', $_POST['Name']);
            $stmt->bindValue(':Breed', $_POST['Breed']);
            (!empty($_POST['Age'])) ? $stmt->bindValue(':Age', $_POST['Age']) : $stmt->bindValue(':Age', NULL);
            (!empty($_POST['Weight'])) ? $stmt->bindValue(':Weight', $_POST['Weight']) : $stmt->bindValue(':Weight', NULL);
            (!empty($_POST['Notes'])) ? $stmt->bindValue(':Notes', $_POST['Notes']) : $stmt->bindValue(':Notes', NULL);
            (!empty($_POST['Info'])) ? $stmt->bindValue(':Info', $_POST['Info']) : $stmt->bindValue(':Info', NULL);
            ($dom != false) ? $stmt->bindValue(':DogOfMonth', $dom) : $stmt->bindValue(':DogOfMonth', NULL);
            (is_array($_POST['Time'])) ? $stmt->bindValue(':Time', json_encode($_POST['Time'])) : $stmt->bindValue(':Time', NULL);
            $stmt->bindValue(':PreferredGroomer', $_POST['PreferredGroomer']);
            $stmt->bindValue(':TwoPeople', $two);
            $stmt->bindValue(':ID', $_GET['id']);
            $stmt->execute();
            $id = $_GET['id'];

            if(!empty($_FILES['Vaccines']['name']) || !empty($_FILES['Picture']['name'])) {
                $stmt = $database->prepare('UPDATE Pets SET Vaccines=:Vaccines, Picture=:Picture WHERE ID = :ID');

                if(!empty($_FILES['Vaccines']['name'])) {
                    if(!file_exists('petdocs/' . $id)) { mkdir('petdocs/' . $id, 0777, 1); }
                    $uploaddir = 'petdocs/' . $id . '/';
                    $vaccines = $uploaddir . basename($_FILES['Vaccines']['name']);
                    if(move_uploaded_file($_FILES['Vaccines']['tmp_name'], $vaccines)) {
                        echo "Vaccines File Uploaded!<br />";
                        $stmt->bindValue(':Vaccines', $vaccines);
                    }
                    else {
                        echo "Upload failed!";
                        $stmt->bindValue(':Vaccines', $pet['Vaccines']);
                    }
                }
                else {
                    $stmt->bindValue(':Vaccines', $pet['Vaccines']);
                }

                if(!empty($_FILES['Picture']['name'])) {
                    if(!file_exists('petdocs/' . $id)) { mkdir('petdocs/' . $id, 0777, 1); }
                    $uploaddir = 'petdocs/' . $id . '/';
                    $picture = $uploaddir . basename($_FILES['Picture']['name']);
                    if(move_uploaded_file($_FILES['Picture']['tmp_name'], $picture)) {
                        echo "Picture Uploaded!<br />";
                        $stmt->bindValue(':Picture', $picture);
                    }
                    else {
                        echo "Upload failed!";
                        $stmt->bindValue(':Picture', $pet['Picture']);
                    }
                }
                else {
                    $stmt->bindValue(':Picture', $pet['Picture']);
                }

                $stmt->bindValue(':ID', $id);
                $stmt->execute();
            }
        }
        $stmt = $database->prepare("SELECT * FROM Pets WHERE ID = :ID");
        $stmt->bindValue(':ID', $id);
        $stmt->execute();
        $pet = $stmt->fetch();
        $stmt = $database->prepare("SELECT Name FROM Breeds WHERE ID = :ID");
        $stmt->bindValue(':ID', $pet['Breed']);
        $stmt->execute();
        $breed = $stmt->fetch();
        $pet['Time'] = json_decode($pet['Time'], true);
        $stmt = $database->prepare("SELECT * FROM Scheduling WHERE PetID = :ID");
        $stmt->bindValue(':ID', $id);
        $stmt->execute();
        $events = $stmt->fetchAll();
        $stmt = $database->query("SELECT Timezone FROM Globals");
        $temp = $stmt->fetch();
        $timezone = $temp['Timezone'];
        $stmt = $database->prepare("SELECT FirstName, LastName FROM Owners WHERE ID = :ID");
        $stmt->bindValue(':ID', $pet['OwnedBy']);
        $stmt->execute();
        $owner = $stmt->fetch();
        $stmt = $database->prepare("SELECT Name FROM Users WHERE ID = :ID");
        $stmt->bindValue(':ID', $pet['PreferredGroomer']);
        $stmt->execute();
        $groomername = $stmt->fetch();
        
        if(!empty($_GET['delete'])) {
            $stmt = $database->prepare("DELETE FROM Scheduling WHERE ID = :ID");
            $stmt->bindValue(':ID', $_GET['delete']);
            $stmt->execute();
        }
        
        if(empty($_GET['e'])) { ?>
            <a href="viewpet.php?id=<?php echo $pet['ID']; ?>&e=1">Edit Pet</a>
            <?php echo (!empty($pet['Picture'])) ? '<img src="' . $pet['Picture'] . '" />' : ''; ?>
            <table>
                <tr><td>ID</td><td><?php echo $pet['ID']; ?></td></tr>
                <tr><td>Name</td><td><?php echo $pet['Name']; ?></td></tr>
                <tr><td>Breed</td><td><?php echo $breed['Name']; ?></td></tr>
                <tr><td>Age</td><td><?php echo $pet['Age']; ?></td></tr>
                <tr><td>Weight</td><td><?php echo $pet['Weight'] ?></td></tr>
                <tr><td>Vaccines</td><td><?php echo ((!empty($pet['Vaccines'])) ? '<a href="' . $pet['Vaccines'] . '">View</a>' : ''); ?></td></tr>
                <tr><td>Notes</td><td><?php echo $pet['Notes']; ?></td></tr>
                <tr><td>Info</td><td><?php echo $pet['Info']; ?></td></tr>
                <tr><td>Dog of the Month Date</td><td><?php echo date('m/d/Y', $pet['DogOfMonth']); ?></td></tr>
                <tr>
                    <td>Time (In Minutes):</td>
                    <td>
                        <strong>Bath Only:</strong><br />
                        Bath Time: <?php echo $pet['Time']['Bath']['BathTime']; ?><br />
                        Groom Time: <?php echo $pet['Time']['Bath']['GroomTime']; ?><br />
                        <strong>Bath &amp; Groom:</strong><br />
                        Bath Time: <?php echo $pet['Time']['Groom']['BathTime']; ?><br />
                        Groom Time: <?php echo $pet['Time']['Groom']['GroomTime']; ?><br />
                    </td>
{'fraction_non_alphanumeric': 0.22727591281799706, 'fraction_numerical': 0.002102459878057327, 'mean_word_length': 2.1116441343218493, 'pattern_counts': {'":': 0, '<': 209, '<?xml version=': 0, '>': 317, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2425319', 'n_tokens_mistral': 4477, 'n_tokens_neox': 4239, 'n_words': 765}