<?php 

    /* Page for editing data of a benchmark format
    */

    require_once('structuredPage.inc.php');

    class PageClass extends EditDBStructuredPage
    {

        function checkEnvironment()
        {
            if (!$_GET['id'])
                return False;

            return True;
        }


        function handleInvalidEnvironment()
        {
            header("Location: formats_LISTING.php"); /* Redirect browser */
            exit();
        }


        function getTitle()
        {
            return 'Format editing';
        }
    

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

            echo("<form action=\"format_CHANGE.php\" method=\"post\">\n");

            echo "<input type=\"hidden\" name=\"formatId\" value=\"$_GET[id]\">";


            # get the basic format info {{{
            $query = "SELECT * from format WHERE id = $_GET[id]";
            $recordSet = $db->Execute($query);
            $row = $recordSet->FetchRow();
            # }}}

            # display the basic info {{{
            echo "<table>\n";
            echo "<tr><td>Name:</td><td>$row[name]</td></tr>\n";
            echo "<tr><td>Description:</td><td><textarea name=\"description\">$row[description]</textarea></td></tr>\n";
            echo "</table>\n";
            # }}}

            echo "Atributy<br>\n";

            $query = "SELECT * FROM formatAttribute WHERE formatId=".$_GET["id"];
            $recordSet = $db->Execute($query);

            $supportedAttributes = array();
            while ($row = $recordSet->FetchRow()) {
                $supportedAttributes[$row["attributeid"]] = 1;
            }

            $query = "SELECT * FROM attribute";
            $recordSet = $db->Execute($query);

            while ($row = $recordSet->FetchRow()) {
                if ($supportedAttributes[$row['id']] == 1)
                    $checked = ' checked';
                else
                    $checked = "";
                
                echo "<input type=\"checkbox\" name=\"attributes[]\" value=\"$row[id]\"$checked>$row[name]<br>\n";
            }

            echo("    <input type=\"submit\" name=\"OK\" value=\"OK\">\n");
            echo("    <input type=\"submit\" name=\"Cancel\" value=\"Cancel\">\n");
            echo("</form>\n");
        }
        
    }

    launchPage();
    
    # vim:enc=iso8859-2:fenc=iso8859-2:
?>
