<?php
{
    function PrintDiv($column, $list, $num)
    {
        if (($_GET["prim"]==$column && empty($num)) || ($_GET["prim"]==$column && $_GET["plot"]=="val" && $num==2))
            printf("<div id='%s%s' style='display:inline'>\n", $column, $num);
        else
            printf("<div id='%s%s' style='display:none'>\n", $column, $num);

        if (!empty($num))
            $vs="vs";

        printf("<select name='%sCol%s' size='1' class='Width'>\n", $column, $num);
        foreach($list as $column2)
            if ($_GET[$column."Col".$num]==$column2)
                printf("<option value='%s' selected>%s %s</option>\n", $column2, $vs, $column2);
            else
                printf("<option value='%s'>%s %s</option>\n", $column2, $vs, $column2);

        printf("</select>\n");
        printf(" from&nbsp;<input name='%sStart%s' type='text' size='6' maxlength='6' value='%s'>", $_GET[$column."Col".$num], $num, $_GET[$_GET[$column."Col".$num]."Start".$num]);
        printf(" to&nbsp;<input name='%sStop%s' type='text' size='6' maxlength='6' value='%s'><br>\n", $_GET[$column."Col".$num], $num, $_GET[$_GET[$column."Col".$num]."Stop".$num]);
        printf("</div>\n");
    }

    ini_set("display_errors", "On");
    ini_set("mysql.trace_mode", "On");

    echo (file_get_contents("index-header.html"));

    include("plotinclude.php");

    printf("<center>\n<table cellpadding='0'>\n");
    printf("<tr><td align='left'>\n");
    printf("<form style='margin-bottom:0;' action='plotdb.php' METHOD='GET'>\n");

    printf("<select name='plot' size='1' class='Width'>\n");
    if ($_GET["plot"]=="prim")
        printf("<option value='prim' onclick='hidepulldown2()' selected>vs primary</option>\n");
    else
        printf("<option value='prim' onclick='hidepulldown2()'>vs primary</option>\n");
    if ($_GET["plot"]=="val")
        printf("<option value='val' onclick='showpulldown2()' selected>vs value</option>\n");
    else
        printf("<option value='val' onclick='showpulldown2()'>vs value</option>\n");
    printf("</select><br>\n");

    printf("<select name='prim' size='1' class='Width'>\n");
    foreach($prims as $primary => $column)
        if ($_GET["prim"]==$column)
            printf("<option onclick=\"showpulldown('%s')\" value='%s' selected>%s</option>\n", $column, $column, $primary);
        else
            printf("<option onclick=\"showpulldown('%s')\" value='%s'>%s</option>\n", $column, $column, $primary);
    printf("</select>\n");
    printf(" from&nbsp;<input name='primstart' type='text' size='6' maxlength='6' value='%s'>", $_GET["primstart"]);
    printf(" to&nbsp;<input name='primstop' type='text' size='6' maxlength='6' value='%s'><br>\n", $_GET["primstop"]);

    foreach($prims as $primary => $column)
    {
        $list=GetList($host, $user, $pw, $db, $column, $tables);
        PrintDiv($column, $list, "");
        PrintDiv($column, $list, "2");
    }

    printf("<br>Set1: <input name='Set' type='text' size='20' maxlength='100' value='%s'>\n", $_GET["Set"]);
    printf("<br>Set2: <input name='Set2' type='text' size='20' maxlength='100' value='%s'>\n", $_GET["Set2"]);
    printf("<br><br><input class='Width' type='submit' value='Query Plot'><br>\n");
    printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"plotdb.php\"'><br>\n");

    printf("</form>");
    printf("</td>\n");

    printf("<td align='right' width='640px'>\n");
    if (!empty($_GET))
    {
        $img="plot.php?par=hallo";
        foreach($_GET as $var => $val)
            $img.="&amp;".$var ."=".$val;
//        printf("link: %s<br>", $img);
        printf("<img src='%s' alt='plot'>", $img);
    }
    printf("</td></tr>\n");
    printf("<tr><td colspan='2'>\n");
    printf("some remarks:\n<ul>");
    printf("<li>For Runs plotting the whole range (i.e. without giving a range or when giving a too large range) ");
    printf("doesn't work with ChartDirector.</li>\n");
    printf("<li>In Set1 and Set2 Sets can be given (e.g. on sequences in Set1 and off sequences in Set2) - they ");
    printf("are displayed in colour (Set: blue, Set2: red). Please give the numbers with space as separator (e.g. 40004 40022).</<li>\n");
    printf("<li>0 is not accepted in the ranges fields, please write .0 or 00</li>");
    printf("<li>Be aware, that plotting timestamps, e.g. fRunStart, doesn't work. </li>");
    printf("</ul></td></tr>\n");
    /*
    printf("<tr><td>\n");
    $query=GetQuery($tables, $joins);
    printf("Q: %s</td></tr>", $query);
    */
    printf("</table>\n");
    printf("</center>\n");

    echo (file_get_contents("index-footer.html"));

    ini_set("display_errors", "Off");
    ini_set("mysql.trace_mode", "Off");
}
?>
