<?php 
    # $Id: benchmarkSet_SHOW.php,v 1.9 2007/01/08 14:49:30 jarda Exp $

    /* Page that displays data of a benchmark set
    */
    
    require_once('structuredPage.inc.php');

    class PageClass extends ViewStructuredPage
    {

        function getTitle()
        {
            return 'Benchmark set information';
        }


        function printContents() {
            $db = connect();

            $query = "SELECT * FROM benchmarkSet WHERE id=$_GET[id]";
            $result = $db->Execute($query);

            if (!$result->RecordCount())
                die('Unknown benchmark set ID');

            $row = $result->FetchRow();

            # the info {{{
            echo "<table>\n";
            echo "<tr><td>Benchmark set:</td><td>$row[name]</td></tr>\n";
            echo "<tr><td>Description:</td><td>$row[description]</td></tr>\n";
            $instanceCount = $this->getInstanceCount($_GET['id']);
            echo "<tr><td>Number of benchmark instances:</td><td>$instanceCount</td></tr>\n";
            echo "</table><br>\n";
            # }}}

            echo "<form action=\"benchmarkInstances_SEARCH.php\" type=\"get\">\n";
            echo "<input type=\"hidden\" name=\"benchmarkSetId\" value=\"$_GET[id]\">";
            echo "Search for matching instances: <input type=\"submit\" name=\"search\" value=\"Search\">\n";
            echo "</form>\n";

            echo '<br>';

            # Formats used in the set {{{
            echo "Formats used in the benchmark set:";

            $query = "SELECT name, id FROM format WHERE id IN " .
                     "(SELECT formatId FROM benchmarkInstance " .
                     "WHERE benchmarkSetId = $_GET[id]" .
                     "GROUP BY formatId)";

            $result = $db->Execute($query);

            echo "<table>\n";

            while ($row = $result->FetchRow()) {
                $this->addFormatTableRow($row);
            }

            echo "</table><br>\n";
            # }}}
        }


        /* Returns number of benchmark instances contained in the specified benchmark set
        */
        function getInstanceCount($benchmarkSetId)
        {
            $db = connect();
            
            $query = "SELECT COUNT(*) FROM benchmarkInstance WHERE benchmarkSetId = $benchmarkSetId";

            $recordSet = $db->Execute($query);
            $row = $recordSet->FetchRow();

            return $row['count'];
        }
        
        /* Adds a row of table of contained format to the page
        */
        function addFormatTableRow($row)
        {
            echo "<tr><td><a href=\"format_SHOW.php?id=$row[id]\">$row[name]</a></td></tr>\n";
        }

    }

    launchPage();

    # vim:enc=iso8859-2:fenc=iso8859-2:
?>
