rate.php 3.25 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 12 13 14 15
  $('#addrating').click(function() {
    $('#commentform').show('slow'); $('#ratings').hide('slow');
  });
$('#submitrating').click(function() {
<?php
echo "var domain = \"{$_GET['domain']}\";";
?>
$.ajax({
dmorley's avatar
cleanup  
dmorley committed
16 17 18 19 20 21 22 23 24 25
  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);} 
}
});
David Morley's avatar
David Morley committed
26 27
});

dmorley's avatar
cleanup  
dmorley committed
28 29 30 31 32 33 34
$("#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>
35 36
</head>
<body>
David Morley's avatar
David Morley committed
37
<div style="height:500px;width:900px;">
38
<?php
dmorley's avatar
cleanup  
dmorley committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
include('db/config.php');
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) {
  die("Error in connection: " . pg_last_error());
}  
if (is_null($_GET['domain'])) {
  die("domain not specified");
}
$sql = "SELECT * FROM rating_comments WHERE domain = $1";
$result = pg_query_params($dbh, $sql, array($_GET['domain']));
if (!$result) {
  die("Error in SQL query: " . pg_last_error());
}   
$numrows = pg_num_rows($result); 
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>"; 
54
if (!$numrows) {echo "<b>This pod has no rating yet!</b>";}
dmorley's avatar
cleanup  
dmorley committed
55 56 57 58 59 60 61 62
while ($row = pg_fetch_array($result)) {
  if ($row["admin"] == 1) {
  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>";
  } elseif ($row["admin"] == 0) {
  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;'>";
  }
63 64
}
echo <<<EOF
David Morley's avatar
David Morley committed
65 66
</div>
<div id="commentform" style="display:none">
dmorley's avatar
cleanup  
dmorley committed
67
Would you like to add a comment?<br>
David Morley's avatar
David Morley committed
68 69 70
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>
71
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
72
<br><input class="btn primary" id="submitrating" type="submit" value="Submit your Rating">
David Morley's avatar
David Morley committed
73
<div class="alert-message warning" id="error" style="display:none"><span id="errortext">Some Error</span></div>
74 75 76
</div>
EOF;

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