New page to visualise referers
[infodrom.org/service.infodrom.org] / src / Infodrom / webstats / referer.wml
1 #include <infodrom.style>
2
3 <page func="Infodrom Oldenburg" title="Statistics">
4
5 <?
6   $tabhead =
7 '<table class="font border" width="100%">
8 <tr bgcolor="#<colh>"><th width="10%">Count</th><th width="90%">Referer</th></tr>';
9   $tabfoot = '</table>';
10   $tabrow = '<tr bgcolor="#%s"><td width="10%%" align="center">%d</td><td width="90%%"><a href="%s" title="%s">%s</a></td></tr>';
11
12   $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
13                or die("Unable to connect to SQL server");
14
15
16   $query = "SELECT id,name FROM ref_site ";
17   if (isset($_GET["site"]))
18     $query .= sprintf("WHERE id = %d ", $_GET["site"]);
19   $query .= "ORDER BY name";
20   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
21
22   for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
23     $site = pg_fetch_array ($sth, $nr);
24     printf ('<h3 class="bar"><a href="<get-var WML_SRC_BASENAME>.php?site=%d">%s</a></h3>', $site["id"], $site["name"]);
25
26     $color = "<cold>";
27     echo $tabhead;
28     $query = sprintf (
29 "SELECT count(*) AS count,ref_origin.url,ref_origin.title
30   FROM ref_origin,ref_url,ref_log
31   WHERE ref_log.url = ref_url.id
32     AND ref_log.origin = ref_origin.id
33     AND ref_url.site = %d
34   GROUP BY ref_origin.url,ref_origin.title
35   ORDER BY count DESC", $site["id"]);
36
37     if (!isset($_GET["site"]))
38       $query .= " LIMIT 10";
39
40     $sth2 = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
41     for ($i=0; $i < pg_NumRows ($sth2); $i++) {
42       $row = pg_fetch_array ($sth2, $i);
43       if (strlen($row["title"])) {
44         $title = substr($row["title"], 0, 80);
45       } else {
46         $title = htmlentities(substr($row["url"], 0, 80));
47       }
48       $color = $color == "<cold>"?"<coln>" : "<cold>";
49       printf ($tabrow, $color, $row["count"], $row["url"], htmlentities($row["url"]), $title);
50     }
51     echo $tabfoot;
52   }
53 ?>
54
55 <div style="padding-top: 1em"></div>
56
57 </page>
58
59 # Local variables:
60 # mode: auto-fill
61 # end: