<!-- Template for programming of sequential programs -->
<br>
[% UNLESS user_info.auth %]
<h1>You are not authorised to program Rig [% rig_info.name %]</h1>
[% RETURN %]
[% END %]
<h1>Setup sequential program for Rig [% rig_info.name %]</h1>

<div class=container>
<div class="program_setup content-container fit-content">
<h3>Add command to program</h3>
<table>
<tbody>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<input type="hidden" name="action" value="measure">
<td><input type="submit" name="" value="Log all channels" class="rfcbutton setup0"></td>
</tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<input type="hidden" name="action" value="mleak">
<td><input type="submit" name="" value="Leak measurement" class="rfcbutton setup1"></td>
</tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<td>
<input type=hidden name="action" value="wait">
<input type="submit" name="" value="Wait for" class="rfcbutton setup2">
</td>
<td><input type="text" name="wait" value="30" class="textfield_setup"></td><th> min.</th></tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="text"><input type="submit" name="" title="Comments are simply text that will be appended to the program log"  value="Comment" class="rfcbutton setup3"></td><td colspan="6"><input type="text" name="text" class="textfield"></td></tr>
</form>


[% IF data.relays.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="relay_enabled"><input type="submit" name="" value="Set enabled status for relay" class="rfcbutton setup12"></td>
<td>
<select name="rname" class="textfield" autocomplete=off>
[% IF data.relays.size == 1 %]
<option value="[% data.relays.0 %]" selected=selected>[% data.relays.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select relay</option>
[% FOR i IN data.relays %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
<th align="center"> to </th><td>
<select name="status" class="textfield">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></td></tr>
</form>
[% END %]


[% IF data.gasses.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="set_gas"><input type="submit" name="" value="Set gas flow for" class="rfcbutton setup10"></td><td>
<select name=gas class=textfield autocomplete=off>
[% IF data.gasses.size == 1 %]
<option value="[% data.gasses.0 %]" selected=selected>[% data.gasses.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select gas</option>
[% FOR i IN data.gasses %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th align="center"> to </th><td><input type="text" name="flow" value="0" class="textfield_setup"></td><th> L/hour.</th></tr>
</form>
[% END %]

[% IF data.PIDs.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="set_pid"><input type="submit" name="" value="Set setpoint for feedback" class="rfcbutton setup5"></td><td>
<select name="pid" class="textfield" autocomplete=off>
[% IF data.PIDs.size == 1 %]
<option value="[% data.PIDs.0 %]" selected=selected>[% data.PIDs.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select regulator</option>
[% FOR i IN data.PIDs %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th align="center"> to </th><td><input type="text" name="setpoint" value="0" class="textfield_setup"></td><th></th></tr>
</form>
[% END %]

[% IF data.multiplexers.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form" name=gasmultiplex>
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="gas_multiplex"><input type="submit" name="" value="Set multiplexer" class="rfcbutton setup11"></td><td>
<select name="controler" onchange="set_gasses(this.value)" class="textfield" autocomplete=off>
[% IF data.multiplexers.size == 1 %]
<option value="[% data.multiplexers.0.name %]" selected=selected>[% data.multiplexers.0.label.replace('_',' ') %]</option>
[% ELSE %]
<option value="" selected=selected>Select multiplexer</option>
[% FOR i IN data.multiplexers %]
<option value="[% i.name %]">[% i.label.replace('_',' ') %]</option>
[% END %]
[% END %]
</select>
</td><th align="center"> to </th><td>
<select name="gas" class="textfield">
</select>
</td><th align="center" id="multiplex_pre">with flow </th><td><input type="text" name="flow" value="0" class="textfield_setup" id="multiplex_gas"></td><th id="multiplex_post"> L/hour.</th></tr>
</form>

<script lanuage="javascript">

var mgasses = new Object();
[% FOR i IN data.mgasses.keys -%]
mgasses["[% i %]"] = ["[% data.mgasses.$i.join('","') %]"];
[% END -%]
var mtypes = new Object();
[% FOR i IN data.mtypes.keys -%]
mtypes["[% i %]"] = "[% data.mtypes.$i %]";
[% END -%]



function set_gasses(m)
{
    var s = document.gasmultiplex.gas;
    s.options.length = 0;
    s.options.add(new Option("Select",""));
    for (var x = 0; x < mgasses[m].length; x++)
    {
        s.options.add(new Option(mgasses[m][x]));
    }
    if (mtypes[m] == 'Selector')
    {
	document.getElementById('multiplex_gas').style.display = 'none';
	document.getElementById('multiplex_pre').style.display = 'none';
	document.getElementById('multiplex_post').style.display = 'none';
    }
    else
    {
	document.getElementById('multiplex_gas').style.display = 'inline-block';
	document.getElementById('multiplex_pre').style.display = 'inline-block';
	document.getElementById('multiplex_post').style.display = 'inline-block';
    }
}

function check_flow() {
    var f = document.gasmultiplex.flow.value;
    if (f > 0)
    {
    return true;
    }
    return confirm("Flow for new gas is 0!\nIs this intensional?");
}

[% IF data.multiplexers.size == 1 %]
set_gasses([% data.multiplexers.0.name %]);
[% END %]

</script>

[% END %]


[% IF data.tempcontrols.size > 0%]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="temp"><input type="submit" name="" value="Set temperature for " class="rfcbutton setup8"></td>
<td>
<select name=device class=textfield autocomplete=off>
[% IF data.tempcontrols.size == 1 %]
<option value="[% data.tempcontrols.0 %]" selected=selected>[% data.tempcontrols.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select controler</option>
[% FOR i IN data.tempcontrols %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th>to</th>
<td><input type="text" name="temp" value="[% data.temp %]" class="textfield_setup"></td>
<th> C <div style="float:right;">ramprate</div> </th><td><input type="text" name="ramp" value="[% data.ramp %]" class="textfield_setup"></td>
<th> C/hour
</form>
[% END %]



<!--<tr><td colspan="7"><hr></td></tr>-->
[% IF data.PSUs.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="OCV">
<input type="submit" name="" value="Set OCV for" class="rfcbutton setup3">
</td><td>
<select name=device class=textfield autocomplete=off>
[% IF data.PSUs.size == 1 %]
<option value="[% data.PSUs.0 %]" selected=selected>[% data.PSUs.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select controler</option>
[% FOR i IN data.PSUs %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td>
</tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<td>
<input type="hidden" name="action" value="current">
<input type="submit" name="" value="Set current for" class="rfcbutton setup3">
</td><td>
<select name=device class=textfield autocomplete=off>
[% IF data.PSUs.size == 1 %]
<option value="[% data.PSUs.0 %]" selected=selected>[% data.PSUs.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select controler</option>
[% FOR i IN data.PSUs %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th>to</th><td>
<input type="text" name="current" value="0" class="textfield_setup">
</td><th>A</th>
</tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<td>
<input type="hidden" name="action" value="voltage">
<input type="submit" name="" value="Set voltage for" class="rfcbutton setup3">
</td><td>
<select name=device class=textfield autocomplete=off>
[% IF data.PSUs.size == 1 %]
<option value="[% data.PSUs.0 %]" selected=selected>[% data.PSUs.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select controler</option>
[% FOR i IN data.PSUs %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th>to</th><td>
<input type="text" name="voltage" value="0" class="textfield_setup">
</td><th>V</th>
</tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="ivwait">
<input type="submit" name="" value="Start i-V curve and wait till finish" class="rfcbutton setup4"></td></tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="iv">
<input type="submit" name="" value="Start i-V curve" class="rfcbutton setup5"></td>
<th>and Wait for</th><td><input type="text" name="wait" value="30" class="textfield_setup"></td><th> min.</th></tr>
</form>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="killiv"><input type="submit" name="" value="Kill running i-V curve" class="rfcbutton setup0"></td></tr>
<tr><td colspan="7"><hr></td></tr>
</form>
[% END %]

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<td>
<input type="hidden" name="action" value="flowvar"><input type="submit" name="" value="Flow variation macro" class="rfcbutton setup2" [% UNLESS data.flowlines.size > 0 %]title="Warning: No flow variation macro defined!" disabled=disabled[% END%]>
</td>
</tr>
</form>



<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr>
<td>
<input type="hidden" name="action" value="std_imp"><tr><td rowspan="2"><input type="submit" name="" value="Impedance program macro" class="rfcbutton setup2" [% UNLESS data.implines.size > 0 %]title="Warning: No impedance program macro defined!" disabled=disabled[% END%]>
</td>
<th> IP / hostname </th><td><input type="text" name="ip" value="[% data.server %]" class="textfield_setup"></td>
<th> port </th><td><input type="text" name="port" value="[% data.port %]" class="textfield_setup"></td>
<th> session </th><td><input type="text" name="session" value="[% data.session %]" class="textfield_setup"></td></tr>
<tr><th> User </th><td><input type="text" name="riguser" value="[% data.impuser %]" class="textfield_setup"></td>
<th> compfile </th><td colspan="3"><select name="comp" class="textfield">
<option value="DEFAULT" [% IF data.comp == 'DEFAULT' %]selected=selected[% END %]>DEFAULT</option>
[% FOR i IN data.compfiles %]
<option value="[% i %]" [% IF data.comp == i %]selected=selected[% END %]>[% i %]</option>
[% END %]
</select></td>
</tr>
</form>

<tr><td colspan="7"><hr></td></tr>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<input type="hidden" name="action" value="single_imp">
<tr><td rowspan="2"><input type="submit" name="" value="Single impedance " class="rfcbutton setup6"></td>
<th> IP / hostname </th><td><input type="text" name="ip" value="[% data.server %]" class="textfield_setup"></td>
<th> port </th><td><input type="text" name="port" value="[% data.port %]" class="textfield_setup"></td>
<th> session </th><td><input type="text" name="session" value="[% data.session %]" class="textfield_setup"></td></tr>
<tr><th> User </th><td><input type="text" name="riguser" value="[% data.impuser %]" class="textfield_setup"></td>
<th> compfile </th><td colspan="3">
<select name="comp" class="textfield">
[% FOR i IN data.compfiles %]
<option value="[% i %]" [% IF data.comp == i %]selected=selected[% END %]>[% i %]</option>
[% END %]
</select></td></tr>
</form>

<tr><td colspan="7"><hr></td></tr>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td rowspan="2">
<input type="hidden" name="action" value="current_imp"><input type="submit" name="" value="Impedance under current" class="rfcbutton setup7"></td>
<th> IP / hostname </th><td><input type="text" name="ip" value="[% data.server %]" class="textfield_setup"></td>
<th> port </th><td><input type="text" name="port" value="[% data.port %]" class="textfield_setup"></td></tr>
<tr><th> User </th><td><input type="text" name="riguser" value="[% data.impuser %]" class="textfield_setup"></td>
<th> session </th><td><input type="text" name="session" value="[% data.session %]" class="textfield_setup"></td></tr>
</form>
<tr><td colspan="7"><hr></td></tr>

<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td rowspan="2">
<input type="hidden" name="action" value="socket_call"><input type="submit" name="" value="TCP/IP socket call" class="rfcbutton setup5"></td>
<th> IP / hostname </th><td><input type="text" name="ip" value="[% data.server %]" class="textfield_setup"></td>
<th> port </th><td><input type="text" name="port" value="[% data.port %]" class="textfield_setup"></td></tr>
<tr><th colspan=2> arguments (separate by ,) </th><td colspan="4"><input type="text" name="args" class="textfield"></td></tr>
</form>

<tr><td colspan="7"><hr></td></tr>

[% IF data.tempcontrols.size > 0%]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="adjust"><input type="submit" name="" value="Adjust temperature to" class="rfcbutton setup9" title="Uses XXX to measure temperature and addjust setpoint accrordingly, waits 3 hours!"></td>
<td>
<select name=device class=textfield autocomplete=off>
[% IF data.tempcontrols.size == 1 %]
<option value="[% data.tempcontrols.0 %]" selected=selected>[% data.tempcontrols.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select controler</option>
[% FOR i IN data.tempcontrols %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th>to</th>
<td><input type="text" name="temp" value="[% data.temp %]" class="textfield_setup"></td><th> C with max </th>
<td><input type="text" name="offset" value="[% data.tempoffset %]" class="textfield_setup"></td><th> C in offset</th></tr>
</form>
[% END %]


[% IF data.relays.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="wait_input"><input type="submit" name="" value="Wait for input from relay" class="rfcbutton setup1"></td><td>
<select name="rname" class="textfield" autocomplete=off>
[% IF data.relays.size == 1 %]
<option value="[% data.relays.0 %]" selected=selected>[% data.relays.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select relay</option>
[% FOR i IN data.relays %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</td><th align="center"> Max. time</th><td><input type="text" name="maxtime" class="textfield" value="[% data.maxtime %]"></td><th>minutes</th></tr>
</form>
[% END %]




[% IF global_config.global.allow_exec.lower == 'yes' && data.programs.size > 0 %]
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<tr><td>
<input type="hidden" name="action" value="exec"><input type="submit" name="" value="Execute external program:" class="rfcbutton setup3"></td>
<th>
<select name="program" class="textfield" autocomplete=off>
[% IF data.programs.size == 1 %]
<option value="[% data.programs.0 %]" selected=selected>[% data.programs.0 %]</option>
[% ELSE %]
<option value="" selected=selected>Select program</option>
[% FOR i IN data.programs %]
<option value="[% i %]">[% i %]</option>
[% END %]
[% END %]
</select>
</th><th> Arguments: </th><td colspan="4"><input type="text" name="args" class="textfield"></td></tr>
</form>
[% END %]

</tbody></table>
</div>


<div class="content-container fit-content">
<h3>Current program</h3><button class=rfcbutton type=button onclick="document.getElementById('show_prog').style.display = 'none';document.getElementById('edit_prog').style.display = 'block';this.style.display = 'none';" style="float:right;">Edit</button>
<div id=show_prog class=program_text style="overflow-y:auto;">[% data.program.replace('\n',"<br></n>") %]</div>
<div id=edit_prog class=program_text style="display:none;">
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<button class=rfcbutton name=action value="Save" type=submit style="float:right;">Save</button>
<textarea name=program class=program_text style="height:100%;">[% data.program %]</textarea>
</form>
</div>
<br>
<form method="post" action="/cgi-bin/celltest/setup_program.cgi" enctype="multipart/form-data" class="form">
[% INCLUDE print_hidden.tt %]
<button class=rfcbutton name=action type=submit value="Delete last line">Delete last line</button>
<button class=rfcbutton name=action type=submit value="Clear program"> Clear program</button>
<button class=rfcbutton name=action type=submit value="Load old">Load program</button>
<button class=rfcbutton name=action type=submit value="Run program">Run program</button>
</form>
</div>

</div>


<style>

.program_text {
   min-width:300px;
   height:500px;
}

.container {
   display:flex;
   gap:20px;
   margin:20px;
   align-items:flex-start;
}

.program_setup {
   text-align:left;
   max-width:1000px;
}


.program_setup th {
   text-align:left;
}

.program_setup td {
   text-align:left;
}


.textfield {
   width:100%;
}


.textfield_setup {
   width:100%;
}

</style>


<!-- End program template -->