#!/usr/bin/perl

# First of all, let's load HELM configuration
use Env;
my $HELM_LIB_DIR = $ENV{"HELM_LIB_DIR"};
# this should be the only fixed constant
my $DEFAULT_HELM_LIB_DIR = "/projects/helm/on-line/local/lib/helm";
if (defined ($HELM_LIB_DIR)) {
   $HELM_LIB_PATH = $HELM_LIB_DIR."/configuration.pl";
} else {
   $HELM_LIB_PATH = $DEFAULT_HELM_LIB_DIR."/configuration.pl";
}

# next require defines: $helm_dir, $html_link, $dtd_dir, $uris_dbm
require $HELM_LIB_PATH;

use CGI;

$cgi = new CGI($ENV{"REQUEST_URL"});
$mode = $cgi->param('mode');
$cicuri = $cgi->param('cicuri');
$theoryuri = $cgi->param('theoryuri');
$topurl = $cgi->param('topurl');
$processorURL = $cgi->param('processorURL');
$getterURL = $cgi->param('getterURL');
($mode1,$mode2,$mode3,$mode4,$mode5) = split(/,/, $mode);
$natural = "checked" if ($mode4 eq "yes");
$annotations = "checked" if ($mode5 eq "yes");
if ($mode1 eq "raw") {
   $format_raw = "selected";
} else {
   $format_processed = "selected";
}

print <<EOT;
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Control panel</title>
<script language="JavaScript" src="http://phd.cs.unibo.it/helm/javascript/utils.js">
<script language="JavaScript" src="http://phd.cs.unibo.it/helm/javascript/utils.js">
<script language="JavaScript" src="http://phd.cs.unibo.it/helm/javascript/control.js">
</script>
</head>
<body bgcolor="#ffffff" text="#000000">
<form>
<table>
  <tr>
    <td>
      <b>Format</b>:
    </td>
    <td>
      <select name="output" onChange="updateOutput(this,document.forms[0].format)">
        <option value="processed" $format_processed>Processed</option>
        <option value="raw" $format_raw>Raw</option>
      </select>
    </td>
    <td>
      <select name="format" onChange="updateFormat(this)">
EOT
    if ($mode1 eq "raw") {
       $tmp = "output_".$mode2;
       $$tmp="selected";
       print <<EOT;
        <option value="cic" $output_cic>CIC</option>
        <option value="zcic" $output_zcic>CIC GZipped</option>
EOT
    } else {
       $tmp = "output_".$mode3;
       $$tmp="selected";
       print <<EOT;
        <option value="html" $output_html>HTML</option>
        <option value="mml_cont" $output_mml_cont>MathML Content</option>
        <option value="mml_pres" $output_mml_pres>MathML Presentation</option>
EOT
    }
print <<EOT;
      </select>
    </td>
    <td>
     <a target="_top" href="$topurl?mode=$mode&cicuri=$cicuri&theoryuri=$theoryuri&processorURL=$processorURL&getterURL=$getterURL">Reload</a><br>
     (do it also before attempting to take a link to the current page)
     <script>
       top.processorURL = getParam('processorURL');
       top.getterURL = getParam('getterURL');
       top.topurl = getParam('topurl');
       top.mode = getParam('mode');
       top.cicuri = getParam('cicuri');
       top.theoryuri = getParam('theoryuri');
     </script>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <input type="checkbox" $natural onClick="updateNatural(this)">&nbsp;Natural Language</input>
      <input type="checkbox" $annotations onClick="updateAnnotations(this)">&nbsp;Annotations</input>
    </td>
    <td>
     <a target="_top" href="../html/index.html?mode=$mode&cicuri=$cicuri&theoryuri=$theoryuri&processorURL=$processorURL&getterURL=$getterURL">Configuration panel</a>
    </td>
  </tr>
</table>
</form>
</body>
</html>
EOT
