#!/usr/bin/perl

# this script only displays the web form and transmits user input to the
# other script, that remotely runs isotop

use CGI qw/:standard *table start_td/;

# the name of the cgi script to be called to connect to Luis' machine
$script_name="isotop_client.pl";

# labels of the pop-down menus and check buttons
%input_labels=('user'=>'User input',
               'example'=>'Example polynomial',
               'random'=>'Random polynomial');
%approach_labels=('1'=>'saturation','2'=>'constraint saturation');
%compute_2d_boxes_labels=('rs'=>'RS','isotop'=>'Isotop');
%visualize_labels=('true'=>'yes','false'=>'no');

# before displaying the cgi form, we read the cgi parameters with which
# this script was called, to see whether we have to display advanced
# options
my $advanced;
if(param() and param("advanced") eq "1"){
        $advanced=1;
}else{
        $advanced=0;
}

print
        header,
        start_html('Isotop'),
        h1('Online Isotop server'),
        # start the cgi form
        start_form(-action=>$script_name),
        start_table(),
        start_td(),
        "<font size=\"+2\">",
        radio_group(-name=>'input_type',
                    -values=>['user','example','random'],
                    -default=>'user',
                    -linebreak=>'true',
                    -labels=>\%input_labels),
        "</font>",
        p,
        end_td(),
        start_td(),
        "<font title=\"polynomial in x and y, in maple format\">",
        textfield(-name=>'curve',-size=>80),
        "</font>",
        p,
        popup_menu(-name=>'example',
                   -values=>['F[1]','F[14]',
                             'OL[1][7]','OL[3][20]','OL[7][6]','OL[9][9]']),
        p,
        "degree ",textfield('degree','5',6,6),
        ", coefficient bitsize ",textfield('bitsize','32',6,6),
        end_td(),
        end_table(),
        #p,
        #"Approach ",popup_menu(
        #               -name=>'approach_nb',-values=>['1','2'],
        #               -default=>'1',-labels=>\%approach_labels),
        p;
if($advanced eq 1){
        print
                "Compute 2D boxes with ",
                popup_menu(
                        -name=>'compute_2d_boxes',-values=>['rs','isotop'],
                        -default=>'rs',-labels=>\%compute_2d_boxes_labels),
                p,
                "RS precision ",
                textfield('rs_precision','5',4,4),
                " RS precision for vertical isolation ",
                textfield('rs_vertical_precision','10',4,4),
                p;
}
print
        checkbox(
                -name=>"visualize",
                -checked=>1,
                -label=>"Plot the curve"),
        p;
if($advanced eq 1){
        print
                "Number of subdivisions for visualization ",
                textfield('visualize_split','10',4,4),
                p;
}
print
        checkbox(
                -name=>"custom_box",
                -checked=>0,
                -label=>"Visualize in a custom box"),
        ", x<sub>min</sub>=",textfield('xmin','-1',6,6),
        ", x<sub>max</sub>=",textfield('xmax','1',6,6),
        ", y<sub>min</sub>=",textfield('ymin','-1',6,6),
        ", y<sub>max</sub>=",textfield('ymax','1',6,6),
        p,
        hidden(-name=>"remote",-default=>remote_host()),
        submit,
        # end the cgi form
        end_form,
        hr,
        "Example polynomials are taken from:",
        start_table(),
        "<tr>",
        start_td(),
        "<font>[F]</font>",
        end_td(),
        start_td(),
        "<font>Laureano Gonz&aacute;lez Vega and Ioana Necula. ",
        "Efficient topology determination of implicitly defined ",
        "algebraic plane curves. <i>Computer Aided Geometric Design</i>, ",
        "2002.",
        "</font>",
        end_td(),
        "</tr>",
        "<tr>",
        start_td(),
        "<font>[OL]</font>",
        end_td(),
        start_td(),
        "<font>Oliver Labs. A list of challenges for real algebraic ",
        "plane curve visualization software. <i>Nonlinear ",
        "Computational Geometry</i>, 2009.</font>",
        end_td(),
        "</tr>",
        end_table(),
        end_html;
