<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head> <title>Interest summary</title> </head>
<!-- $Id: showinterest.php 14 2004-12-30 02:09:00Z basile $ -->
<!-- Copyright 2004 Basile STARYNKEVITCH -->
<body>
<h1>Interest summary</h1>
<?php
// this showinterest.php file is
//   Copyright © 2004 Basile STARYNKEVITCH
//
// This Software is licensed under the GPL licensed Version 2, 
// please read http://www.gnu.org/copyleft/gpl.html

/* you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software
 * Foundation; either version 2 of the License.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

require 'interest_config.inc';
// the included file defines:
///  for opening the database
///  $int_db_name $int_db_host $int_db_user $int_db_passwd 
///  the name of the rate and access tables $int_tb_rate $int_tb_access
///  $int_webuser the user part of the email address
///  $int_webdomain the domain part of the email address
//// example
// $int_db_name="interest_db";
// $int_db_host="localhost";
// $int_db_user="phpuser";
// $int_db_passwd="secretpassword";
// $int_tb_rate="Tb_Rate";
// $int_tb_access="Tb_Access";
// $int_webuser="webmaster";
// $int_webdomain="exampledomain.org";

function query($query,$descr) {
  if (!($res=mysql_query($query))) {
    echo "<p>Failed mysql query:&nbsp; <tt>"
      . htmlspecialchars($query) . "</tt><br>\n";
    die("mysql query " .$descr . " failed: " . mysql_error());
  };
  return $res;
}
?>

<?php
// fetch data from the HTTP request
$clientip = $_SERVER['REMOTE_ADDR'];
$pagename = $_GET['name'];

// current time
$now=date("Y.M.d-h:i:s");

$link = mysql_connect($int_db_host, $int_db_user, $int_db_passwd)
     or die("Could not connect : " . mysql_error());  
 
mysql_select_db($int_db_name) 
     or die("Could not select database $int_db_name:" . mysql_error());

if ($pagename!="*") 
     $query="SELECT r1,r2,r3,r4,url,pagename FROM $int_tb_rate WHERE pagename='$pagename'";
     else
     $query="SELECT r1,r2,r3,r4,url,pagename FROM $int_tb_rate ORDER BY pagename";

$res=query($query,"rate fetching query");

echo "<table border='1'><caption>Rating feedback given</caption>\n";
echo "<thead bgcolor='pink'><tr><td><b>name</b></td><td align='center'>URL</td><td># rates</td>"
. "<td>rate 1</td><td>rate 2</td><td>rate 3</td><td>rate 4</td><td>mean</td></tr>"
. "<tr><td><small>internal</small></td><td></td><td></td><td><small>best</small></td><td></td><td></td><td><small>worst</small></td><td></td></tr>"
. "</thead>\n";

while ($row = mysql_fetch_array($res)) {
  $r1=$row[0];  $r2=$row[1];  $r3=$row[2];  $r4=$row[3]; $url=$row[4]; $page=$row[5];
  $sum = $r1 + $r2 + $r3 + $r4;
  if ($sum>0)
    $mean= round(($r1 + 2*$r2 + 3*$r3 + 4*$r4)/$sum,2);
  else { $sum=0.01; $mean=0; };
  echo '<tr>';
  printf("<td><em>%s</em></td>",$page);
  printf("<td align='left'> <a href='%s'>%s</a> ", $url, htmlspecialchars($url));
  printf("<td align='right'> %d </td>",$sum);
  printf("<td> %d, <small>%.1f%%</small> </td>", $r1, round(100.0*$r1/$sum,1));
  printf("<td> %d, <small>%.1f%%</small> </td>", $r2, round(100.0*$r2/$sum,1));
  printf("<td> %d, <small>%.1f%%</small> </td>", $r3, round(100.0*$r3/$sum,1));
  printf("<td> %d, <small>%.1f%%</small> </td>", $r4, round(100.0*$r4/$sum,1));
  printf("<td> %.2f </td></tr>\n", $mean);
};
echo "</table>\n";
mysql_free_result($res);
?>
<p>Don't give too much attention to the figures above. They might be inaccurate.<br>
Consecutive feedbacks from the same browsing machine (or proxy?) are ignored if given too often.
</p>

</body>
<!-- eof $Id: showinterest.php 14 2004-12-30 02:09:00Z basile $ -->
</html>
