rate.php 3.71 KB
Newer Older
1
<?php
2
($_domain = $_GET['domain'] ?? null) || die('domain not specified');
3
?>
4 5 6 7 8 9 10 11
<html>
<head>
  <style type="text/css">
    #slider {
      margin: 10px;
      width: 250px;
      display: inline-block;
    }
David Morley's avatar
David Morley committed
12

13 14 15 16 17 18 19 20 21 22 23 24
    #rating {
      height: 35px;
      width: 35px;
    }
  </style>
  <script>
    $(document).ready(function () {
      $('#addrating').click(function () {
        $('#commentform').show('slow');
        $('#ratings').hide('slow');
      });
      $('#submitrating').click(function () {
25
        var domain = '<?php echo $_domain; ?>';
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        $.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) {
            $('#submitrating').unbind('click');
            if (msg == 1) {
              $('#commentform').replaceWith('<h3>Your comment was saved, Thank You!</h3>');
            } else {
              $('#errortext').html(msg);
              $('#error').slideDown(633).delay(2500).slideUp(633);
            }
          }
        });
      });

      $('#slider').slider({
        animate: true, max: 10, min: 1, step: 1, value: 10, stop: function (event, ui) {
          var value = $('#slider').slider('option', 'value');
          $('#rating').prop('value', value)
        }
      });
    });
  </script>
50 51
</head>
<body>
David Morley's avatar
David Morley committed
52
<div style="height:500px;width:900px;">
53 54
  <?php
  require_once __DIR__ . '/config.php';
55

56
  $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
57 58
  $dbh || die('Error in connection: ' . pg_last_error());

dmorley's avatar
dmorley committed
59
  $sql    = 'SELECT admin,username,userurl,rating,comment,date,id FROM rating_comments WHERE domain = $1';
60
  $result = pg_query_params($dbh, $sql, [$_domain]);
61 62
  $result || die('Error in SQL query: ' . pg_last_error());

63
  $numrows = pg_num_rows($result);
64
  echo '<input id="addrating" class="btn primary" style="float:right;margin-right:15px;" type="submit" value="Add a Rating"><h3>Podupti.me ratings for ' . $_domain . ' pod</h3><div id="ratings"><hr>';
65 66 67 68
  if (!$numrows) {
    echo '<b>This pod has no rating yet!</b>';
  }
  while ($row = pg_fetch_array($result)) {
69
    if ($row['admin'] === '1') {
70 71
      echo 'Poduptime Approved Comment - User: <b>' . $row['username'] . '</b> Url: <a href="' . $row['userurl'] . '">' . $row['userurl'] . '</a> Rating: <b>' . $row['rating'] . '</b> <br>';
      echo '<i>' . $row['comment'] . '</i><span class="label" title="id: ' . $row['id'] . '" style="float:right;margin-right:115px;">' . $row['date'] . '</span><hr>';
David Morley's avatar
David Morley committed
72
    } else {
73 74 75
      echo 'User Comment - User: <b>' . $row['username'] . '</b> Url: <a href="' . $row['userurl'] . '">' . $row['userurl'] . '</a> Rating: <b>' . $row['rating'] . '</b> <br>';
      echo '<i>' . $row['comment'] . '</i><span class="label" title="id: ' . $row['id'] . '" style="float:right;margin-right:115px;">' . $row['date'] . '</span><hr style="margin-top:0;margin-bottom:15px;">';
    }
dmorley's avatar
dmorley committed
76
  }
77
  ?>
David Morley's avatar
David Morley committed
78 79
</div>
<div id="commentform" style="display:none">
80 81 82 83 84 85 86 87 88 89 90
  Would you like to add a comment?<br>
  <label>Your Name (or Diaspora handle)?<br><input id="username" name="username"></label><br>
  <label>Your Profile URL?<br><input id="userurl" name="userurl"></label><br>
  <label>Comment<br><textarea id="comment" name="comment"></textarea></label><br>
  Rating (1-10 scale, 10 high)<br>
  <div id="slider"></div>
  <input class="disabled" disabled="" id="rating" name="rating" value="10"><br>
  <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>
root's avatar
root committed
91
</div>
92 93 94
<?php
pg_free_result($result);
pg_close($dbh);