<?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");

        if (empty($_GET[$_GET[$column."Col".$num]."Start".$num]))
            $_GET[$_GET[$column."Col".$num]."Start".$num]=0;
        if (empty($_GET[$_GET[$column."Col".$num]."Stop".$num]))
            $_GET[$_GET[$column."Col".$num]."Stop".$num]=0;

        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");

    //init
    if (empty($_GET["plot"]))
        $_GET["plot"]=0;
    if (empty($_GET["primstart"]))
        $_GET["primstart"]=0;
    if (empty($_GET["primstop"]))
        $_GET["primstop"]=0;
    if (empty($_GET["prim"]))
        $_GET["prim"]=0;
    if (empty($_GET["fSequenceFirstCol"]))
        $_GET["fSequenceFirstCol"]=0;
    if (empty($_GET["fSequenceFirstCol2"]))
        $_GET["fSequenceFirstCol2"]=0;
    if (empty($_GET["fRunNumberCol"]))
        $_GET["fRunNumberCol"]=0;
    if (empty($_GET["fRunNumberCol2"]))
        $_GET["fRunNumberCol2"]=0;
    if (empty($_GET["fDataSetNumberCol"]))
        $_GET["fDataSetNumberCol"]=0;
    if (empty($_GET["fDataSetNumberCol2"]))
        $_GET["fDataSetNumberCol2"]=0;
    if (empty($_GET["0Start"]))
        $_GET["0Start"]=0;
    if (empty($_GET["0Stop"]))
        $_GET["0Stop"]=0;
    if (empty($_GET["0Start2"]))
        $_GET["0Start2"]=0;
    if (empty($_GET["0Stop2"]))
        $_GET["0Stop2"]=0;
    if (empty($_GET["Set"]))
        $_GET["Set"]=0;
    if (empty($_GET["Set2"]))
        $_GET["Set2"]=0;

    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("&nbsp;<input type='radio' name='plot' value='prim' onclick='hidepulldown2()' %s> vs primary &nbsp;", $_GET["plot"]=="prim" ? "checked" : "");
    printf("&nbsp;<input type='radio' name='plot' value='val' onclick='showpulldown2()' %s> vs value <br><br>", $_GET["plot"]=="val" ? "checked" : "");

    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' height='400px'>\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");
}
?>
