<commit_before><?php
session_start();
require_once('../vendor/autoload.php');
require_once('../config.php');
$toy_repo = new \GDS\lib\Repository();
$review_repo = new \GDS\lib\RepositoryReview();
/**
 * get information of a toy based on the url parameter. 
 * also get review of that toy.
 * since this is just a demo, 'protect' the datastore from
 * harmful queries by checking the length of $_GET["id"]
 * 
 */
if (is_string($_GET["id"])) {
    if (strlen($_GET["id"]) < 3) {
        $info_toy = $toy_repo->getToyByToyId($_GET["id"]);
        $reviews_arr = $review_repo->getReviewsOfAToy($_GET["id"]);
    }
}
/**
 * count the number of reviews
 * caluclate the average rating which accompanies each review
 */
$numOfReviews = count($reviews_arr);
$sumOfRating = 0;
foreach ($reviews_arr as $obj_review) {
    $sumOfRating = $sumOfRating + $obj_review->rating;
}
$avgRating = floor($sumOfRating / $numOfReviews);
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Terrific Toys</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="author" content="<NAME>">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="css/navbar.css">
        <link rel="stylesheet" href="css/itemDetail.css">
        <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet"/>

    </head>
    <body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>

        <?php include 'navbar.php'; ?>
        <h2><?php echo $info_toy->name; ?></h2>
        <!-- Information of one toy -->
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <img class="img-responsive" src="<?php echo $info_toy->imgpath; ?>" alt="">
                </div>
                <div class="col-md-4">
                    <h4>Price: $<?php echo $info_toy->price; ?></h4>
                    <h4>Description: </h4>
                    <p><?php echo $info_toy->txtDescript; ?></p>
                </div>

            </div>
            <hr>
            <!-- Average rating gathered from reviews -->
            <div class="row">
                <div class="col-md-8">
                    <h3>Reviews</h3>

                    <div class="lineblock">
                        <?php if ($avgRating == 0) { ?>
                            <img class="img-responsive" src="img/emptyStars.png" alt="Rating is 0">
                        <?php } elseif ($avgRating == 1) { ?>
                            <img class="img-responsive" src="img/oneStar.png" alt="Rating is 1">
                        <?php } elseif ($avgRating == 2) { ?>
                            <img class="img-responsive" src="img/twoStar.png" alt="Rating is 2">
                        <?php } elseif ($avgRating == 3) { ?>
                            <img class="img-responsive" src="img/threeStar.png" alt="Rating is 3">
                        <?php } elseif ($avgRating == 4) { ?>
                            <img class="img-responsive" src="img/fourStar.png" alt="Rating is 4">
                        <?php } elseif ($avgRating == 5) { ?>
                            <img class="img-responsive" src="img/fiveStar.png" alt="Rating is 5">
                        <?php } ?>
                    </div>

                    <div id="numReviews" class="lineblock"  > <?php echo $numOfReviews; ?> reviews </div>
                    <br>
                    <button type="button" data-toggle="modal" data-target="#formModal">Write a review</button>

                </div>
            </div>
            <!-- Pop-up modal to let user input review of the toy -->
            <div id="formModal" class="modal fade" role="dialog">
                <div class="modal-dialog">

                    <!-- Modal content-->
                    <div class="modal-content"><commit_msg>condition check for making review<commit_after><?php
session_start();
require_once('../vendor/autoload.php');
require_once('../config.php');
$toy_repo = new \GDS\lib\Repository();
$review_repo = new \GDS\lib\RepositoryReview();
/**
 * get information of a toy based on the url parameter. 
 * also get review of that toy.
 * since this is just a demo, 'protect' the datastore from
 * harmful queries by checking the length of $_GET["id"]
 * 
 */
if (is_string($_GET["id"])) {
    if (strlen($_GET["id"]) < 3) {
        $info_toy = $toy_repo->getToyByToyId($_GET["id"]);
        $reviews_arr = $review_repo->getReviewsOfAToy($_GET["id"]);
    }
}
/**
 * count the number of reviews
 * caluclate the average rating which accompanies each review
 */
$numOfReviews = count($reviews_arr);
$sumOfRating = 0;
foreach ($reviews_arr as $obj_review) {
    $sumOfRating = $sumOfRating + $obj_review->rating;
}
$avgRating = floor($sumOfRating / $numOfReviews);
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Terrific Toys</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="author" content="<NAME>">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="css/navbar.css">
        <link rel="stylesheet" href="css/itemDetail.css">
        <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet"/>

    </head>
    <body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>

        <?php include 'navbar.php'; ?>
        <h2><?php echo $info_toy->name; ?></h2>
        <!-- Information of one toy -->
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <img class="img-responsive" src="<?php echo $info_toy->imgpath; ?>" alt="">
                </div>
                <div class="col-md-4">
                    <h4>Price: $<?php echo $info_toy->price; ?></h4>
                    <h4>Description: </h4>
                    <p><?php echo $info_toy->txtDescript; ?></p>
                </div>

            </div>
            <hr>
            <!-- Average rating gathered from reviews -->
            <div class="row">
                <div class="col-md-8">
                    <h3>Reviews</h3>

                    <div class="lineblock">
                        <?php if ($avgRating == 0) { ?>
                            <img class="img-responsive" src="img/emptyStars.png" alt="Rating is 0">
                        <?php } elseif ($avgRating == 1) { ?>
                            <img class="img-responsive" src="img/oneStar.png" alt="Rating is 1">
                        <?php } elseif ($avgRating == 2) { ?>
                            <img class="img-responsive" src="img/twoStar.png" alt="Rating is 2">
                        <?php } elseif ($avgRating == 3) { ?>
                            <img class="img-responsive" src="img/threeStar.png" alt="Rating is 3">
                        <?php } elseif ($avgRating == 4) { ?>
                            <img class="img-responsive" src="img/fourStar.png" alt="Rating is 4">
                        <?php } elseif ($avgRating == 5) { ?>
                            <img class="img-responsive" src="img/fiveStar.png" alt="Rating is 5">
                        <?php } ?>
                    </div>

                    <div id="numReviews" class="lineblock"  > <?php echo $numOfReviews; ?> reviews </div>
                    <br>
                    <?php
                    $currUserMadeReview = false;
                    if (isset($_SESSION["userid"])) {
                        foreach ($reviews_arr as $obj_review) {
                            if ($obj_review->userid == $_SESSION["userid"]) {
                                $currUserMadeReview = true;
                            }
                        }
                    }
                    if (isset($_SESSION["userid"])) {
                        if ($currUserMadeReview == false) {
                            ?>
                            <button type="button" data-toggle="modal" data-target="#formModal">Write a review</button>
                            <?php
                        }
                    }
                    ?>


                </div>
            </div>
            <!-- Pop-up modal to let user input review of the toy -->
            <div id="formModal" class="modal fade" role="dialog">
                <div class="modal-dialog">

                    <!-- Modal content-->
                    <div class="modal-content">
{'fraction_non_alphanumeric': 0.16121442975576966, 'fraction_numerical': 0.007618194039883486, 'mean_word_length': 1.7026945201332122, 'pattern_counts': {'":': 0, '<': 159, '<?xml version=': 0, '>': 172, 'https://': 8, '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': '1419997', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2549, 'n_words': 553}