rate.php 3.32 KB
Newer Older
1
<html><head>
dmorley's avatar
cleanup  
dmorley committed
2 3
<style type="text/css">
#slider { margin: 10px;width:250px;display:inline-block; }
David Morley's avatar
David Morley committed
4
#rating { height: 35px;width:35px; }
dmorley's avatar
cleanup  
dmorley committed
5 6 7
</style>
<script>
$(document).ready(function() {
David Morley's avatar
David Morley committed
8 9 10 11
  $('#addrating').click(function() {
    $('#commentform').show('slow'); $('#ratings').hide('slow');
  });
$('#submitrating').click(function() {
noplanman's avatar
noplanman committed
12
var domain = '<?php echo $_GET['domain']; ?>';
David Morley's avatar
David Morley committed
13
$.ajax({
noplanman's avatar
noplanman committed
14 15 16
  type: 'POST',
  url: 'db/saverating.php',
  data: 'username='+$('#username').val()+'&userurl='+$('#userurl').val()+'&comment='+$('#comment').val()+'&rating='+$('#rating').val()+'&domain='+domain,
dmorley's avatar
cleanup  
dmorley committed
17 18 19
  success: function(msg){
  $('#submitrating').unbind('click');
  if (msg == 1) {
noplanman's avatar
noplanman committed
20
    $('#commentform').replaceWith('<h3>Your comment was saved, Thank You!</h3>');
dmorley's avatar
cleanup  
dmorley committed
21 22 23
  } else {$('#errortext').html(msg);$('#error').slideDown(633).delay(2500).slideUp(633);} 
}
});
David Morley's avatar
David Morley committed
24 25
});

noplanman's avatar
noplanman committed
26 27 28
$('#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 )
dmorley's avatar
cleanup  
dmorley committed
29 30 31 32
} 
});
});
</script>
33 34
</head>
<body>
David Morley's avatar
David Morley committed
35
<div style="height:500px;width:900px;">
36
<?php
37 38
require_once __DIR__ . '/config.php';

dmorley's avatar
cleanup  
dmorley committed
39 40
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
41
  die('Error in connection: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
42 43
}  
if (is_null($_GET['domain'])) {
44
  die('domain not specified');
dmorley's avatar
cleanup  
dmorley committed
45 46 47 48
}
$sql = "SELECT * FROM rating_comments WHERE domain = $1";
$result = pg_query_params($dbh, $sql, array($_GET['domain']));
if (!$result) {
49
  die('Error in SQL query: ' . pg_last_error());
dmorley's avatar
cleanup  
dmorley committed
50 51
}   
$numrows = pg_num_rows($result); 
noplanman's avatar
noplanman committed
52
echo '<input id="addrating" class="btn primary" style="float:right;margin-right:15px;" type="submit" value="Add a Rating"><h3>Podupti.me ratings for ' . $_GET['domain'] . ' pod</h3><div id="ratings"><hr>';
53
if (!$numrows) {echo '<b>This pod has no rating yet!</b>';}
dmorley's avatar
cleanup  
dmorley committed
54
while ($row = pg_fetch_array($result)) {
55
  if ($row['admin'] == 1) {
noplanman's avatar
noplanman committed
56 57
  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>';
58
  } elseif ($row['admin'] == 0) {
noplanman's avatar
noplanman committed
59 60
  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
cleanup  
dmorley committed
61
  }
62 63
}
echo <<<EOF
David Morley's avatar
David Morley committed
64 65
</div>
<div id="commentform" style="display:none">
dmorley's avatar
cleanup  
dmorley committed
66
Would you like to add a comment?<br>
David Morley's avatar
David Morley committed
67 68 69
Your Name (or Diaspora handle)?<br><input id="username" name="username"><br>
Your Profile URL?<br><input id="userurl" name="userurl"><br>
Comment<br><textarea id="comment" name="comment"></textarea><br>
70
Rating (1-10 scale, 10 high)<br><div id="slider"></div><input class="disabled" disabled="" id="rating" name="rating" value="10">
David Morley's avatar
David Morley committed
71
<br><input class="btn primary" id="submitrating" type="submit" value="Submit your Rating">
David Morley's avatar
David Morley committed
72
<div class="alert-message warning" id="error" style="display:none"><span id="errortext">Some Error</span></div>
73 74 75
</div>
EOF;

dmorley's avatar
cleanup  
dmorley committed
76 77
pg_free_result($result);       
pg_close($dbh);
78
?>
root's avatar
root committed
79
</div>