rate.php 3.12 KB
Newer Older
1
<?php
2

3 4 5 6 7 8
/**
 * Popup modal for pod rating.
 */

declare(strict_types=1);

9 10
use RedBeanPHP\R;

11
($_domain = $_GET['domain'] ?? null) || die('domain not specified');
12

13
require_once __DIR__ . '/boot.php';
14

15
?>
16 17
<html>
<head>
18
    <script>
19
        $(document).ready(function () {
David Morley's avatar
David Morley committed
20
            $("#rating").ionRangeSlider();
21
            $('#addrating').click(function () {
David Morley's avatar
David Morley committed
22
                $('.ratings').hide('fast');
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
                $('#commentform').show('slow');
            });
            $('#submitrating').click(function () {
                var domain = '<?php echo $_domain; ?>';
                $.ajax({
                    type: 'POST',
                    url: 'db/saverating.php',
                    data: 'username=' + $('#username').val() + '&userurl=' + $('#userurl').val() + '&comment=' + $('#comment').val() + '&rating=' + $('#rating').val() + '&domain=' + domain,
                    success: function (msg) {
                        if (msg == 1) {
                            $('#commentform').replaceWith('<h3>Your comment was saved, Thank You!</h3>');
                            $('#submitrating').unbind('click');
                        } else {
                            $('#errortext').html(msg);
                            $('#error').slideDown(633).delay(2500).slideUp(633);
                        }
                    }
                });
            });
42 43
        });
    </script>
44 45
</head>
<body>
David Morley's avatar
David Morley committed
46 47 48 49
<div id="commentform" class="container" style="display:none">
    Would you like to add a comment?<br>
    <label>Your Name:<br><input id="username" name="username"></label><br>
    <label>Comment:<br><textarea id="comment" name="comment"></textarea></label><br>
David Morley's avatar
David Morley committed
50 51
    <label>Rating (1-10 scale, 10 high):<br><input type="text" name="rating" id="rating" data-slider-id="ratingSlider" data-min="1" data-max="10" data-step="1"></label><br>

David Morley's avatar
David Morley committed
52 53 54 55 56
    <input class="btn primary" id="submitrating" type="submit" value="Submit your Rating">
    <div class="alert-message warning" id="error" style="display:none">
        <span id="errortext">Some Error</span>
    </div>
</div>
David Morley's avatar
David Morley committed
57
<div>
58
    <?php
59

60 61 62 63 64
    try {
        $ratings = R::findAll('ratingcomments', 'domain LIKE ? ORDER BY date_created DESC LIMIT 8', [$_domain]);
    } catch (\RedBeanPHP\RedException $e) {
        die('Error in SQL query: ' . $e->getMessage());
    }
65

David Morley's avatar
David Morley committed
66
    echo '<div class="container ratings"><div class="row"><div class="col col-10"><b>Ratings for ' . $_domain . '</b></div></div>';
67 68 69 70
    if (empty($ratings)) {
        echo '<b>This pod has no rating yet!</b>';
    } else {
        foreach ($ratings as $rating) {
David Morley's avatar
David Morley committed
71 72
            echo '<div class="m-1 rounded"><div class="row  bg-secondary"><div class="col-10">Comment from: <b>' . $rating['username'] . '</b></div> <div class="col text-right">Rating: ' . $rating['rating'] . '</div></div>';
            echo '<div class="row"><div class="col-10"><i>' . $rating['comment'] . '</i></div><div class="col text-muted text-right" title="id: ' . $rating['id'] . '">' . date('Y-m-d', strtotime($rating['date_created'])) . '</div></div></div>';
73
        }
74
    }
75
    ?>
76
    <input id="addrating" class="btn primary" type="submit" value="Add a Rating">
77 78 79
</div>
</body>
</html>