cvs: pearweb /public_html admin.php package-stats.php
| From: | Richard Heyes | Date: | Mon, 03 Jun 2002 17:37:05 +0000 |
| Subject: | cvs: pearweb /public_html admin.php package-stats.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4392@lists.php.net to get a copy of this message | ||
richard Mon Jun 3 13:37:05 2002 EDT
Modified files:
/pearweb/public_html package-stats.php admin.php
Log:
* Added global/category stats
Index: pearweb/public_html/package-stats.php diff -u pearweb/public_html/package-stats.php:1.9 pearweb/public_html/package-stats.php:1.10 --- pearweb/public_html/package-stats.php:1.9 Sun Jun 2 15:46:42 2002 +++ pearweb/public_html/package-stats.php Mon Jun 3 13:37:05 2002 @@ -14,8 +14,9 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Martin Jansen <mj@php.net> | + | Richard Heyes <richard@php.net> | +----------------------------------------------------------------------+ - $Id: package-stats.php,v 1.9 2002/06/02 19:46:42 richard Exp $ + $Id: package-stats.php,v 1.10 2002/06/03 17:37:05 richard Exp $ */ require_once "HTML/Form.php"; @@ -138,159 +139,244 @@ if (isset($_GET['pid']) && $_GET['pid'] != "") { - if (User::isAdmin($_COOKIE['PEAR_USER']) || - maintainer::get($_GET['pid']) == $_COOKIE['PEAR_USER']) - { - $info = package::info($_GET['pid']); + $info = package::info($_GET['pid']); + + echo "<h2>Statistics for package \"" . $info['name'] . "\"</h2>\n"; + + $bb = new Borderbox("General statistics"); + echo "Number of releases: <b>" . count($info['releases']) . "</b><br />\n"; + echo "Total downloads: <b>" . statistics::package($_GET['pid']) . "</b><br />\n"; + $bb->end(); + + if (count($info['releases']) > 0) { + echo "<br />\n"; + $bb = new Borderbox("Release statistics"); + + $release_statistics = statistics::release($_GET['pid'], (isset($_GET['rid']) ? $_GET['rid'] : "")); + + $i= 0; + foreach ($release_statistics as $key => $value) { + $bb2 = new Borderbox("Release: " . $value['version'], 400); + echo "Number of downloads: <b>" . $value['total'] . "</b><br />\n"; + + if ($value['total'] > 1) { + echo "First download: <b>" . $value['first_download'] . "</b><br />\n"; + echo "Last download: <b>" . $value['last_download'] . "</b><br />\n"; + } + + $bb2->end(); + echo "<br />\n"; + } - echo "<h2>Statistics for package \"" . $info['name'] . "\"</h2>\n"; - - $bb = new Borderbox("General statistics"); - echo "Number of releases: <b>" . count($info['releases']) . "</b><br />\n"; - echo "Total downloads: <b>" . statistics::package($_GET['pid']) . "</b><br />\n"; $bb->end(); + + /** + * Print the graph + */ + printf('<br /><img src="package-stats-graph.php?pid=%s&releases=%s_339900" name="stats_graph" width="543" height="200" alt="">', $_GET['pid'], (int)$_GET['rid']); + + /** + * Print the graph control stuff + */ + $releases = $dbh->getAll('SELECT id, version FROM releases WHERE package = ' . $_GET['pid'], DB_FETCHMODE_ASSOC); + ?> +<br /><br /> +<script language="JavaScript" type="text/javascript"> +<!-- + function clearGraphList() + { + graphForm = document.forms['graph_control']; + for (i=0; i<graphForm.graph_list.options.length; i++) { + graphForm.graph_list.options[i] = null; + } + } - if (count($info['releases']) > 0) { - echo "<br />\n"; - $bb = new Borderbox("Release statistics"); + function addGraphItem() + { + graphForm = document.forms['graph_control']; + selectedRelease = graphForm.releases.options[graphForm.releases.selectedIndex]; + selectedColour = graphForm.colours.options[graphForm.colours.selectedIndex]; + + if (selectedRelease.value != "" && selectedColour.value != "") { + newText = 'Release ' + selectedRelease.text + ' in ' + selectedColour.text; + newValue = selectedRelease.value + '_' + selectedColour.value; + graphForm.graph_list.options[graphForm.graph_list.options.length] = new Option(newText, newValue); + + } else { + alert('Please select a release and a colour!'); + } + } + + function removeGraphItem() + { + graphForm = document.forms['graph_control']; + graphList = graphForm.graph_list; - $release_statistics = statistics::release($_GET['pid'], (isset($_GET['rid']) ? $_GET['rid'] : "")); + if (graphList.selectedIndex != null) { + graphList.options[graphList.selectedIndex] = null; + } + } + + function updateGraph() + { + graphForm = document.forms['graph_control']; + releases_qs = ''; - $i= 0; - foreach ($release_statistics as $key => $value) { - $bb2 = new Borderbox("Release: " . $value['version'], 400); - echo "Number of downloads: <b>" . $value['total'] . "</b><br />\n"; - - if ($value['total'] > 1) { - echo "First download: <b>" . $value['first_download'] . "</b><br />\n"; - echo "Last download: <b>" . $value['last_download'] . "</b><br />\n"; + if (graphForm.graph_list.options.length) { + for (i=0; i<graphForm.graph_list.options.length; i++) { + if (i == 0) { + releases_qs += graphForm.graph_list.options[i].value; + } else { + releases_qs += ',' + graphForm.graph_list.options[i].value; } - - $bb2->end(); - echo "<br />\n"; } - - $bb->end(); + graphForm.update.value = 'Updating...'; + document.images['stats_graph'].src = 'package-stats-graph.php?pid=<?=$_GET['pid']?>&releases=' + releases_qs; + graphForm.update.value = 'Update graph'; - /** - * Print the graph - */ - printf('<br /><img src="package-stats-graph.php?pid=%s&releases=%s_339900" name="stats_graph" width="543" height="200" alt="">', $_GET['pid'], (int)$_GET['rid']); - - /** - * Print the graph control stuff - */ - $releases = $dbh->getAll('SELECT id, version FROM releases WHERE package = ' . $_GET['pid'], DB_FETCHMODE_ASSOC); - ?> -<br /><br /> -<script language="JavaScript" type="text/javascript"> -<!-- - function clearGraphList() - { - graphForm = document.forms['graph_control']; - for (i=0; i<graphForm.graph_list.options.length; i++) { - graphForm.graph_list.options[i] = null; - } - } - - function addGraphItem() - { - graphForm = document.forms['graph_control']; - selectedRelease = graphForm.releases.options[graphForm.releases.selectedIndex]; - selectedColour = graphForm.colours.options[graphForm.colours.selectedIndex]; - - if (selectedRelease.value != "" && selectedColour.value != "") { - newText = 'Release ' + selectedRelease.text + ' in ' + selectedColour.text; - newValue = selectedRelease.value + '_' + selectedColour.value; - graphForm.graph_list.options[graphForm.graph_list.options.length] = new Option(newText, newValue); - - } else { - alert('Please select a release and a colour!'); - } - } - - function removeGraphItem() - { - graphForm = document.forms['graph_control']; - graphList = graphForm.graph_list; - - if (graphList.selectedIndex != null) { - graphList.options[graphList.selectedIndex] = null; - } - } - - function updateGraph() - { - graphForm = document.forms['graph_control']; - releases_qs = ''; - - if (graphForm.graph_list.options.length) { - for (i=0; i<graphForm.graph_list.options.length; i++) { - if (i == 0) { - releases_qs += graphForm.graph_list.options[i].value; - } else { - releases_qs += ',' + graphForm.graph_list.options[i].value; - } - } - graphForm.update.value = 'Updating...'; - document.images['stats_graph'].src = 'package-stats-graph.php?pid=<?=$_GET['pid']?>&releases=' + releases_qs; - graphForm.update.value = 'Update graph'; - - } else { - alert('Please select one or more releases to show!'); - } - } + } else { + alert('Please select one or more releases to show!'); + } + } //--> </script> <form name="graph_control"> <!-- No action as it should never be submitted --> <table border="0"> + <tr> + <td colspan="2"> + Show graph of:<br /> + <select style="width: 543px" name="graph_list" size="5"> + </select> + </td> + </tr> + <tr> + <td valign="top"> + Release: + <select align="absmiddle" name="releases"> + <option value="">Select...</option> + <option value="0">All</option> + <?foreach($releases as $r):?> + <option value="<?=$r['id']?>"><?=$r['version']?></option> + <?endforeach?> + </select> + Colour: + <select align="absmiddle" name="colours"> + <option>Select...</option> + <option value="339900">Green</option> + <option value="dd0000">Red</option> + <option value="003399">Blue</option> + <option value="000000">Black</option> + <option value="999900">Yellow</option> + </select> + </td> + <td align="right"> + <input type="submit" style="width: 100px" name="add" value="Add" onclick="addGraphItem(); return false;"> + <input type="submit" style="width: 100px" name="remove" value="Remove" onclick="removeGraphItem(); return false" /> + </td> + </tr> + <tr> + <td align="center" colspan="2"> + <input type="submit" name="update" value="Update graph" onclick="updateGraph(); return false" /> + </td> + </tr> +</table> +</form> +<br /> + <?php + } + +/** +* Category based statistics +*/ +} elseif (!empty($_GET['cid'])) { + + $category_name = $dbh->getOne(sprintf("SELECT name FROM categories WHERE id = %d", $_GET['cid'])); + $total_packages = $dbh->getOne(sprintf("SELECT COUNT(DISTINCT pid) FROM package_stats WHERE cid = %d", $_GET['cid'])); + $total_maintainers = $dbh->getOne(sprintf("SELECT COUNT(DISTINCT m.handle) FROM maintains m, packages p WHERE m.package = p.id AND p.category = %d", $_GET['cid'])); + $total_releases = $dbh->getOne(sprintf("SELECT COUNT(*) FROM package_stats WHERE cid = %d", $_GET['cid'])); + $total_categories = $dbh->getOne(sprintf("SELECT COUNT(*) FROM categories WHERE parent = %d", $_GET['cid'])); + + // Query to get package list from package_stats_table + $query = sprintf("SELECT dl_number, package, release, pid, rid, cid FROM package_stats WHERE cid = %s ORDER BY dl_number DESC", $_GET['cid']); + +/** +* Global stats +*/ +} else { + + $total_packages = $dbh->getOne("SELECT COUNT(DISTINCT pid) FROM package_stats"); + $total_maintainers = $dbh->getOne("SELECT COUNT(DISTINCT handle) FROM maintains"); + $total_releases = $dbh->getOne("SELECT COUNT(*) FROM package_stats"); + $total_categories = $dbh->getOne("SELECT COUNT(*) FROM categories"); + $query = "SELECT dl_number, package, release, pid, rid, cid FROM package_stats ORDER BY dl_number DESC"; + +} + +/** +* Display this for Global and Category stats pages only +*/ +if (!$_GET['pid']) { + echo '<br />'; + $bb = new BorderBox(!empty($_GET['cid']) ? 'Category statistics for: <i>' . $category_name . '</i>' : 'Global statistics'); + ?> +<table border="0" width="100%"> <tr> - <td colspan="2"> - Show graph of:<br /> - <select style="width: 543px" name="graph_list" size="5"> - </select> - </td> - </tr> - <tr> - <td valign="top"> - Release: - <select align="absmiddle" name="releases"> - <option value="">Select...</option> - <option value="0">All</option> - <?foreach($releases as $r):?> - <option value="<?=$r['id']?>"><?=$r['version']?></option> - <?endforeach?> - </select> - Colour: - <select align="absmiddle" name="colours"> - <option>Select...</option> - <option value="339900">Green</option> - <option value="dd0000">Red</option> - <option value="003399">Blue</option> - <option value="000000">Black</option> - <option value="999900">Yellow</option> - </select> - </td> - <td align="right"> - <input type="submit" style="width: 100px" name="add" value="Add" onclick="addGraphItem(); return false;"> - <input type="submit" style="width: 100px" name="remove" value="Remove" onclick="removeGraphItem(); return false" /> - </td> + <td width="25%">Total Packages:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_packages?></td> + <td width="25%">Total Releases:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_releases?></td> </tr> <tr> - <td align="center" colspan="2"> - <input type="submit" name="update" value="Update graph" onclick="updateGraph(); return false" /> - </td> + <td width="25%">Total Maintainers:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_maintainers?></td> + <td width="25%">Total Categories:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_categories?></td> </tr> </table> -</form> -<br /> - <?php - } + <?php + $bb->end(); + + echo '<br />'; - } else { - PEAR::raiseError("Not enough priviliges to view statistics for" - . " this package."); - } + $bb = new BorderBox("Package statistics"); + + $sth = $dbh->query($query); //$query defined above + + if (DB::isError($sth)) { + PEAR::raiseError("unable to generate stats"); + } + + echo "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"2\">\n"; + echo "<tr align=\"left\" bgcolor=\"#cccccc\">\n"; + echo "<th>Package name</th>\n"; + echo "<th>Release</th>\n"; + echo "<th><u># of downloads</u></th>\n"; + echo "<th> </th>\n"; + echo "</tr>\n"; + + $lastPackage = ""; + + while ($row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) { + if ($row['package'] == $lastPackage) { + $row['package'] = ""; + } else { + $lastPackage = $row['package']; + $row['package'] = "<a href=\"package-info.php?pacid=" . + $row['pid'] . "\">" . + $row['package'] . "</a>\n"; + } + + echo "<tr bgcolor=\"#eeeeee\">\n"; + echo "<td>\n" . $row['package'] . "</td>\n"; + echo "<td>" . $row['release'] . "</td>\n"; + echo "<td>" . $row['dl_number'] . "</td>\n"; + echo "<td>[". make_link("/package-stats.php?cid=" . $row['cid'] . "&pid=" . $row['pid'] . "&rid=" . $row['rid'], "Details") . "]</td>\n"; + echo "</tr>\n"; + } + + echo "</table>\n"; + + $bb->end(); } response_footer(); Index: pearweb/public_html/admin.php diff -u pearweb/public_html/admin.php:1.16 pearweb/public_html/admin.php:1.17 --- pearweb/public_html/admin.php:1.16 Thu May 30 05:09:48 2002 +++ pearweb/public_html/admin.php Mon Jun 3 13:37:05 2002 @@ -233,54 +233,5 @@ echo "<br /><br />\n"; -/* -$bb = new BorderBox("Download statistics"); - -$query = "SELECT COUNT(d.id) AS dl_number, p.id AS pid, p.name AS package, r.id AS rid, r.version AS release, p.category AS cid - FROM downloads d, packages p, releases r - - WHERE d.package = p.id AND d.release = r.id - GROUP BY d.package, d.release ORDER BY dl_number DESC"; - -$sth = $dbh->query($query); - -if (DB::isError($sth)) { - PEAR::raiseError("unable to generate stats"); -} - -echo "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"2\">\n"; -echo "<tr align=\"left\" bgcolor=\"#cccccc\">\n"; -echo "<th>Package name</th>\n"; -echo "<th>Release</th>\n"; -echo "<th><u># of downloads</u></th>\n"; -echo "<th> </th>\n"; -echo "</tr>\n"; - -$lastPackage = ""; - -while ($row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) { - if ($row['package'] == $lastPackage) { - $row['package'] = ""; - } else { - $lastPackage = $row['package']; - $row['package'] = "<a href=\"package-info.php?pacid=" . - $row['pid'] . "\">" . - $row['package'] . "</a>\n"; - } - - echo "<tr bgcolor=\"#eeeeee\">\n"; - echo "<td>\n" . $row['package'] . "</td>\n"; - echo "<td>" . $row['release'] . "</td>\n"; - echo "<td>" . $row['dl_number'] . "</td>\n"; - echo "<td>[". make_link("/package-stats.php?cid=" . $row['cid'] . "&pid=" . $row['pid'] . "&rid=" . $row['rid'], "Details") . "]</td>\n"; - echo "</tr>\n"; -} - -echo "</table>\n"; - -$bb->end(); - -*/ - response_footer(); ?>
Index: pearweb/public_html/package-stats.php diff -u pearweb/public_html/package-stats.php:1.9 pearweb/public_html/package-stats.php:1.10 --- pearweb/public_html/package-stats.php:1.9 Sun Jun 2 15:46:42 2002 +++ pearweb/public_html/package-stats.php Mon Jun 3 13:37:05 2002 @@ -14,8 +14,9 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Martin Jansen <mj@php.net> | + | Richard Heyes <richard@php.net> | +----------------------------------------------------------------------+ - $Id: package-stats.php,v 1.9 2002/06/02 19:46:42 richard Exp $ + $Id: package-stats.php,v 1.10 2002/06/03 17:37:05 richard Exp $ */ require_once "HTML/Form.php"; @@ -138,159 +139,244 @@ if (isset($_GET['pid']) && $_GET['pid'] != "") { - if (User::isAdmin($_COOKIE['PEAR_USER']) || - maintainer::get($_GET['pid']) == $_COOKIE['PEAR_USER']) - { - $info = package::info($_GET['pid']); + $info = package::info($_GET['pid']); + + echo "<h2>Statistics for package \"" . $info['name'] . "\"</h2>\n"; + + $bb = new Borderbox("General statistics"); + echo "Number of releases: <b>" . count($info['releases']) . "</b><br />\n"; + echo "Total downloads: <b>" . statistics::package($_GET['pid']) . "</b><br />\n"; + $bb->end(); + + if (count($info['releases']) > 0) { + echo "<br />\n"; + $bb = new Borderbox("Release statistics"); + + $release_statistics = statistics::release($_GET['pid'], (isset($_GET['rid']) ? $_GET['rid'] : "")); + + $i= 0; + foreach ($release_statistics as $key => $value) { + $bb2 = new Borderbox("Release: " . $value['version'], 400); + echo "Number of downloads: <b>" . $value['total'] . "</b><br />\n"; + + if ($value['total'] > 1) { + echo "First download: <b>" . $value['first_download'] . "</b><br />\n"; + echo "Last download: <b>" . $value['last_download'] . "</b><br />\n"; + } + + $bb2->end(); + echo "<br />\n"; + } - echo "<h2>Statistics for package \"" . $info['name'] . "\"</h2>\n"; - - $bb = new Borderbox("General statistics"); - echo "Number of releases: <b>" . count($info['releases']) . "</b><br />\n"; - echo "Total downloads: <b>" . statistics::package($_GET['pid']) . "</b><br />\n"; $bb->end(); + + /** + * Print the graph + */ + printf('<br /><img src="package-stats-graph.php?pid=%s&releases=%s_339900" name="stats_graph" width="543" height="200" alt="">', $_GET['pid'], (int)$_GET['rid']); + + /** + * Print the graph control stuff + */ + $releases = $dbh->getAll('SELECT id, version FROM releases WHERE package = ' . $_GET['pid'], DB_FETCHMODE_ASSOC); + ?> +<br /><br /> +<script language="JavaScript" type="text/javascript"> +<!-- + function clearGraphList() + { + graphForm = document.forms['graph_control']; + for (i=0; i<graphForm.graph_list.options.length; i++) { + graphForm.graph_list.options[i] = null; + } + } - if (count($info['releases']) > 0) { - echo "<br />\n"; - $bb = new Borderbox("Release statistics"); + function addGraphItem() + { + graphForm = document.forms['graph_control']; + selectedRelease = graphForm.releases.options[graphForm.releases.selectedIndex]; + selectedColour = graphForm.colours.options[graphForm.colours.selectedIndex]; + + if (selectedRelease.value != "" && selectedColour.value != "") { + newText = 'Release ' + selectedRelease.text + ' in ' + selectedColour.text; + newValue = selectedRelease.value + '_' + selectedColour.value; + graphForm.graph_list.options[graphForm.graph_list.options.length] = new Option(newText, newValue); + + } else { + alert('Please select a release and a colour!'); + } + } + + function removeGraphItem() + { + graphForm = document.forms['graph_control']; + graphList = graphForm.graph_list; - $release_statistics = statistics::release($_GET['pid'], (isset($_GET['rid']) ? $_GET['rid'] : "")); + if (graphList.selectedIndex != null) { + graphList.options[graphList.selectedIndex] = null; + } + } + + function updateGraph() + { + graphForm = document.forms['graph_control']; + releases_qs = ''; - $i= 0; - foreach ($release_statistics as $key => $value) { - $bb2 = new Borderbox("Release: " . $value['version'], 400); - echo "Number of downloads: <b>" . $value['total'] . "</b><br />\n"; - - if ($value['total'] > 1) { - echo "First download: <b>" . $value['first_download'] . "</b><br />\n"; - echo "Last download: <b>" . $value['last_download'] . "</b><br />\n"; + if (graphForm.graph_list.options.length) { + for (i=0; i<graphForm.graph_list.options.length; i++) { + if (i == 0) { + releases_qs += graphForm.graph_list.options[i].value; + } else { + releases_qs += ',' + graphForm.graph_list.options[i].value; } - - $bb2->end(); - echo "<br />\n"; } - - $bb->end(); + graphForm.update.value = 'Updating...'; + document.images['stats_graph'].src = 'package-stats-graph.php?pid=<?=$_GET['pid']?>&releases=' + releases_qs; + graphForm.update.value = 'Update graph'; - /** - * Print the graph - */ - printf('<br /><img src="package-stats-graph.php?pid=%s&releases=%s_339900" name="stats_graph" width="543" height="200" alt="">', $_GET['pid'], (int)$_GET['rid']); - - /** - * Print the graph control stuff - */ - $releases = $dbh->getAll('SELECT id, version FROM releases WHERE package = ' . $_GET['pid'], DB_FETCHMODE_ASSOC); - ?> -<br /><br /> -<script language="JavaScript" type="text/javascript"> -<!-- - function clearGraphList() - { - graphForm = document.forms['graph_control']; - for (i=0; i<graphForm.graph_list.options.length; i++) { - graphForm.graph_list.options[i] = null; - } - } - - function addGraphItem() - { - graphForm = document.forms['graph_control']; - selectedRelease = graphForm.releases.options[graphForm.releases.selectedIndex]; - selectedColour = graphForm.colours.options[graphForm.colours.selectedIndex]; - - if (selectedRelease.value != "" && selectedColour.value != "") { - newText = 'Release ' + selectedRelease.text + ' in ' + selectedColour.text; - newValue = selectedRelease.value + '_' + selectedColour.value; - graphForm.graph_list.options[graphForm.graph_list.options.length] = new Option(newText, newValue); - - } else { - alert('Please select a release and a colour!'); - } - } - - function removeGraphItem() - { - graphForm = document.forms['graph_control']; - graphList = graphForm.graph_list; - - if (graphList.selectedIndex != null) { - graphList.options[graphList.selectedIndex] = null; - } - } - - function updateGraph() - { - graphForm = document.forms['graph_control']; - releases_qs = ''; - - if (graphForm.graph_list.options.length) { - for (i=0; i<graphForm.graph_list.options.length; i++) { - if (i == 0) { - releases_qs += graphForm.graph_list.options[i].value; - } else { - releases_qs += ',' + graphForm.graph_list.options[i].value; - } - } - graphForm.update.value = 'Updating...'; - document.images['stats_graph'].src = 'package-stats-graph.php?pid=<?=$_GET['pid']?>&releases=' + releases_qs; - graphForm.update.value = 'Update graph'; - - } else { - alert('Please select one or more releases to show!'); - } - } + } else { + alert('Please select one or more releases to show!'); + } + } //--> </script> <form name="graph_control"> <!-- No action as it should never be submitted --> <table border="0"> + <tr> + <td colspan="2"> + Show graph of:<br /> + <select style="width: 543px" name="graph_list" size="5"> + </select> + </td> + </tr> + <tr> + <td valign="top"> + Release: + <select align="absmiddle" name="releases"> + <option value="">Select...</option> + <option value="0">All</option> + <?foreach($releases as $r):?> + <option value="<?=$r['id']?>"><?=$r['version']?></option> + <?endforeach?> + </select> + Colour: + <select align="absmiddle" name="colours"> + <option>Select...</option> + <option value="339900">Green</option> + <option value="dd0000">Red</option> + <option value="003399">Blue</option> + <option value="000000">Black</option> + <option value="999900">Yellow</option> + </select> + </td> + <td align="right"> + <input type="submit" style="width: 100px" name="add" value="Add" onclick="addGraphItem(); return false;"> + <input type="submit" style="width: 100px" name="remove" value="Remove" onclick="removeGraphItem(); return false" /> + </td> + </tr> + <tr> + <td align="center" colspan="2"> + <input type="submit" name="update" value="Update graph" onclick="updateGraph(); return false" /> + </td> + </tr> +</table> +</form> +<br /> + <?php + } + +/** +* Category based statistics +*/ +} elseif (!empty($_GET['cid'])) { + + $category_name = $dbh->getOne(sprintf("SELECT name FROM categories WHERE id = %d", $_GET['cid'])); + $total_packages = $dbh->getOne(sprintf("SELECT COUNT(DISTINCT pid) FROM package_stats WHERE cid = %d", $_GET['cid'])); + $total_maintainers = $dbh->getOne(sprintf("SELECT COUNT(DISTINCT m.handle) FROM maintains m, packages p WHERE m.package = p.id AND p.category = %d", $_GET['cid'])); + $total_releases = $dbh->getOne(sprintf("SELECT COUNT(*) FROM package_stats WHERE cid = %d", $_GET['cid'])); + $total_categories = $dbh->getOne(sprintf("SELECT COUNT(*) FROM categories WHERE parent = %d", $_GET['cid'])); + + // Query to get package list from package_stats_table + $query = sprintf("SELECT dl_number, package, release, pid, rid, cid FROM package_stats WHERE cid = %s ORDER BY dl_number DESC", $_GET['cid']); + +/** +* Global stats +*/ +} else { + + $total_packages = $dbh->getOne("SELECT COUNT(DISTINCT pid) FROM package_stats"); + $total_maintainers = $dbh->getOne("SELECT COUNT(DISTINCT handle) FROM maintains"); + $total_releases = $dbh->getOne("SELECT COUNT(*) FROM package_stats"); + $total_categories = $dbh->getOne("SELECT COUNT(*) FROM categories"); + $query = "SELECT dl_number, package, release, pid, rid, cid FROM package_stats ORDER BY dl_number DESC"; + +} + +/** +* Display this for Global and Category stats pages only +*/ +if (!$_GET['pid']) { + echo '<br />'; + $bb = new BorderBox(!empty($_GET['cid']) ? 'Category statistics for: <i>' . $category_name . '</i>' : 'Global statistics'); + ?> +<table border="0" width="100%"> <tr> - <td colspan="2"> - Show graph of:<br /> - <select style="width: 543px" name="graph_list" size="5"> - </select> - </td> - </tr> - <tr> - <td valign="top"> - Release: - <select align="absmiddle" name="releases"> - <option value="">Select...</option> - <option value="0">All</option> - <?foreach($releases as $r):?> - <option value="<?=$r['id']?>"><?=$r['version']?></option> - <?endforeach?> - </select> - Colour: - <select align="absmiddle" name="colours"> - <option>Select...</option> - <option value="339900">Green</option> - <option value="dd0000">Red</option> - <option value="003399">Blue</option> - <option value="000000">Black</option> - <option value="999900">Yellow</option> - </select> - </td> - <td align="right"> - <input type="submit" style="width: 100px" name="add" value="Add" onclick="addGraphItem(); return false;"> - <input type="submit" style="width: 100px" name="remove" value="Remove" onclick="removeGraphItem(); return false" /> - </td> + <td width="25%">Total Packages:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_packages?></td> + <td width="25%">Total Releases:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_releases?></td> </tr> <tr> - <td align="center" colspan="2"> - <input type="submit" name="update" value="Update graph" onclick="updateGraph(); return false" /> - </td> + <td width="25%">Total Maintainers:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_maintainers?></td> + <td width="25%">Total Categories:</td> + <td width="25%" align="center" bgcolor="#cccccc"><?=$total_categories?></td> </tr> </table> -</form> -<br /> - <?php - } + <?php + $bb->end(); + + echo '<br />'; - } else { - PEAR::raiseError("Not enough priviliges to view statistics for" - . " this package."); - } + $bb = new BorderBox("Package statistics"); + + $sth = $dbh->query($query); //$query defined above + + if (DB::isError($sth)) { + PEAR::raiseError("unable to generate stats"); + } + + echo "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"2\">\n"; + echo "<tr align=\"left\" bgcolor=\"#cccccc\">\n"; + echo "<th>Package name</th>\n"; + echo "<th>Release</th>\n"; + echo "<th><u># of downloads</u></th>\n"; + echo "<th> </th>\n"; + echo "</tr>\n"; + + $lastPackage = ""; + + while ($row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) { + if ($row['package'] == $lastPackage) { + $row['package'] = ""; + } else { + $lastPackage = $row['package']; + $row['package'] = "<a href=\"package-info.php?pacid=" . + $row['pid'] . "\">" . + $row['package'] . "</a>\n"; + } + + echo "<tr bgcolor=\"#eeeeee\">\n"; + echo "<td>\n" . $row['package'] . "</td>\n"; + echo "<td>" . $row['release'] . "</td>\n"; + echo "<td>" . $row['dl_number'] . "</td>\n"; + echo "<td>[". make_link("/package-stats.php?cid=" . $row['cid'] . "&pid=" . $row['pid'] . "&rid=" . $row['rid'], "Details") . "]</td>\n"; + echo "</tr>\n"; + } + + echo "</table>\n"; + + $bb->end(); } response_footer(); Index: pearweb/public_html/admin.php diff -u pearweb/public_html/admin.php:1.16 pearweb/public_html/admin.php:1.17 --- pearweb/public_html/admin.php:1.16 Thu May 30 05:09:48 2002 +++ pearweb/public_html/admin.php Mon Jun 3 13:37:05 2002 @@ -233,54 +233,5 @@ echo "<br /><br />\n"; -/* -$bb = new BorderBox("Download statistics"); - -$query = "SELECT COUNT(d.id) AS dl_number, p.id AS pid, p.name AS package, r.id AS rid, r.version AS release, p.category AS cid - FROM downloads d, packages p, releases r - - WHERE d.package = p.id AND d.release = r.id - GROUP BY d.package, d.release ORDER BY dl_number DESC"; - -$sth = $dbh->query($query); - -if (DB::isError($sth)) { - PEAR::raiseError("unable to generate stats"); -} - -echo "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"2\">\n"; -echo "<tr align=\"left\" bgcolor=\"#cccccc\">\n"; -echo "<th>Package name</th>\n"; -echo "<th>Release</th>\n"; -echo "<th><u># of downloads</u></th>\n"; -echo "<th> </th>\n"; -echo "</tr>\n"; - -$lastPackage = ""; - -while ($row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) { - if ($row['package'] == $lastPackage) { - $row['package'] = ""; - } else { - $lastPackage = $row['package']; - $row['package'] = "<a href=\"package-info.php?pacid=" . - $row['pid'] . "\">" . - $row['package'] . "</a>\n"; - } - - echo "<tr bgcolor=\"#eeeeee\">\n"; - echo "<td>\n" . $row['package'] . "</td>\n"; - echo "<td>" . $row['release'] . "</td>\n"; - echo "<td>" . $row['dl_number'] . "</td>\n"; - echo "<td>[". make_link("/package-stats.php?cid=" . $row['cid'] . "&pid=" . $row['pid'] . "&rid=" . $row['rid'], "Details") . "]</td>\n"; - echo "</tr>\n"; -} - -echo "</table>\n"; - -$bb->end(); - -*/ - response_footer(); ?>