<?php
$stmt = $GLOBALS['con']->prepare("SELECT `wSol`,`wCat` FROM `lwrittenscheme` WHERE `id`=?")or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('i',getLWSNumber($cd['itemnumber']));$stmt->execute();$ws=$stmt->get_result();$stmt->close();
$lwsd=mysqli_fetch_array($ws);?>
<div class="spacer">&nbsp;</div>
<div class="col-12 col-md-12 ">
    <div class="card">
        <div class="card-header">LOLER Written Scheme Information</div>
        <div class="card-body">
            <div class="col-md-6">
                <div class="row mb-3">
                    <div class="col-md-4"><label class="control-label" for="thorough">Thorough Examination period</label></div>
                    <div class="col-md-5 input-group"><select class="form-control" type="text" name="thorough" id="thorough">
                            <option value="6" <?php if($cd['thorough']=="6"){?> SELECTED<?php }?>>6</option>
                            <option value="12" <?php if($cd['thorough']=="12"){?> SELECTED<?php }?>>12</option>
                            <option value="13" <?php if($cd['thorough']=="13"){?> SELECTED<?php }?>>13</option>
                            <option value="18" <?php if($cd['thorough']=="18"){?> SELECTED<?php }?>>18</option>
                            <option value="24" <?php if($cd['thorough']=="24"){?> SELECTED<?php }?>>24</option>
                            <option value="26" <?php if($cd['thorough']=="26"){?> SELECTED<?php }?>>26</option>
                            <option value="72" <?php if($cd['thorough']=="72"){?> SELECTED<?php }?>>72</option>
                        </select>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-4"><label class="control-label" for="currdate">Intermediate Examination period</label></div>
                    <div class="col-md-5 input-group"><select class="form-control" type="text" name="inter" id="inter">
                            <option value="6" <?php if($cd['intermediate']=="6"){?> SELECTED<?php }?>>6</option>
                            <option value="12" <?php if($cd['intermediate']=="12"){?> SELECTED<?php }?>>12</option>
                            <option value="13" <?php if($cd['intermediate']=="13"){?> SELECTED<?php }?>>13</option>
                            <option value="18" <?php if($cd['intermediate']=="18"){?> SELECTED<?php }?>>18</option>
                            <option value="24" <?php if($cd['intermediate']=="24"){?> SELECTED<?php }?>>24</option>
                            <option value="26" <?php if($cd['intermediate']=="26"){?> SELECTED<?php }?>>26</option>
                            <option value="72" <?php if($cd['intermediate']=="72"){?> SELECTED<?php }?>>72</option>
                        </select>
                    </div>
                </div>
                <div class="row mb-3">
                    <div class="col-md-4"><label class="control-label" for="wSol">Safe operating Limit<br><small style="color:#333333">(Minimum value across the scheme)</small></label></div>
                    <div class="col-md-5"><input type="text" class="form-control" name="wSol" id="wSol" value="<?= $lwsd['wSol']?>" /></div>
                </div>
                <div class="row mb-3">
                    <div class="col-md-4"><label class="control-label" for="wCat">Pressure system category</label></div>
                    <div class="col-md-5"><select class="form-control" type="text" name="wCat" id="wCat">
                            <option value="Minor" <?php if($lwsd['wCat']=="Minor"){?> SELECTED<?php }?>>Minor</option>
                            <option value="Major" <?php if($lwsd['wCat']=="Major"){?> SELECTED<?php }?>>Major</option>
                        </select></div>
                </div>
            </div>

            <div class="col-md-6">
                <?php $ca=0;if($cd['valve']!="" ){$checked="checked";
                    $av=array();
                    $av=unserialize($cd['valve']);
                    if(is_array($av)){foreach($av as $ad){
                        $storedValve.='<div id="valveRow'.$ca.'" class="row mb-3">
<div class="col-md-2"><input type="text" class="form-control" name="valveRange'.$ca.'" id="valveRange'.$ca.'" value="'.$ad['range'].'" /></div><div class="col-md-4"><input type="text" class="form-control" name="valveSerial'.$ca.'" id="valveSerial'.$ca.'" value="'.$ad['serial'].'" /></div><div class="col-md-4"><input type="text" class="form-control" name="valveMake'.$ca.'" id="valveMake'.$ca.'" value="'.$ad['make'].'" /></div><div class="col-md-2"><a class="btn btn-danger" href="javascript:void(0)" onclick="removeRow(\'valveRow'.$ca.'\')"><i class="fad fa-trash"></i></a></div><hr /></div>';
                        $ca++;
                    }}
                }else{$checked="";}?>
                <div class="row mb-3">
                    <div class="col-md-3"><label class="control-label" for="valve">Has safety valve</label></div>
                    <div class="col-md-2"><label><input type="checkbox" class="js-switch" <?= $checked?> name="valve" id="valve" data-switchery="true" style="display: none;"></label></div>

                    <div class="col-md-1 vAmount"><label class="control-label" for="vNo">Amount</label></div>
                    <div class="col-md-3 input-group vAmount"><input type="hidden" class="form-control" name="vStart" id="vStart" value="<?= $ca?>" /><input type="text" class="form-control" name="vNo" id="vNo" />
                        <div class="input-group-append"><button class="btn btn-info" type="button">Add</button></div>
                    </div>

                </div>

                <div class="row mb-3">
                    <div class="col-md-2"><label class="control-label" for="gaugeRange'">Range</label></div>
                    <div class="col-md-4"><label class="control-label" for="gaugeSerial">Serial</label></div>
                    <div class="col-md-4"><label class="control-label" for="gaugeMake">Make</label></div>
                    <div class="col-md-2"></div>
                </div>
                <div id="valveRow" class="row mb-3"><?= $storedValve?></div>

                <hr>


                <?php $cb=0;if($cd['gauge']!="" ){$checked="checked";
                    $ar=array();
                    $ar=unserialize($cd['gauge']);
                    if(is_array($ar)){foreach($ar as $ad){
                        $storedGauge.='<div id="gaugeRow'.$cb.'" class="row mb-3">
<div class="col-md-2"><input type="text" class="form-control" name="gaugeRange'.$cb.'" id="gaugeRange'.$cb.'" value="'.$ad['range'].'" /></div><div class="col-md-4"><input type="text" class="form-control" name="gaugeSerial'.$cb.'" id="gaugeSerial'.$cb.'" value="'.$ad['serial'].'" /></div><div class="col-md-4"><input type="text" class="form-control" name="gaugeMake'.$cb.'" id="gaugeMake'.$cb.'" value="'.$ad['make'].'" /></div><div class="col-md-2"><a class="btn btn-danger" href="javascript:void(0)" onclick="removeRow(\'gaugeRow'.$cb.'\')"><i class="fad fa-trash"></i></a></div><hr /></div>';
                        $cb++;
                    }}
                }else{$checked="";}?>
                <div class="row mb-3">
                    <div class="col-md-3"><label class="control-label" for="gauge">Has pressure gauge</label></div>
                    <div class="col-md-2"><label><input type="checkbox" class="js-switch" <?= $checked?> name="gauge" id="gauge" data-switchery="true" style="display: none;"></label></div>

                    <div class="col-md-1 gAmount"><label class="control-label" for="gNo">Amount</label></div>
                    <div class="col-md-3 input-group gAmount"><input type="hidden" class="form-control" name="gStart" id="gStart" value="<?= $cb?>" /><input type="text" class="form-control" name="gNo" id="gNo" />
                        <div class="input-group-append"><button class="btn btn-info" type="button">Add</button></div>
                    </div>

                </div>

                <div class="row mb-3">
                    <div class="col-md-2"><label class="control-label" for="gaugeRange'">Range</label></div>
                    <div class="col-md-4"><label class="control-label" for="gaugeSerial">Serial</label></div>
                    <div class="col-md-4"><label class="control-label" for="gaugeMake">Make</label></div>
                    <div class="col-md-2"></div>
                </div>
                <div id="gaugeRow" class="row mb-3"><?= $storedGauge?></div>


            </div>



        </div>
    </div>
</div>

<input type="hidden" name="isLWS" value="1" />
<div class="spacer">&nbsp;</div>
<script>
function editLWSC(i) {
    $('#popupBox .modal-body').html('');
    $('#popupBox').modal('show');
    $('#popupBox .modal-body').load('includes/master/lws_edit.php?lws=' + i);
    $('#popupBox .modal-footer').html('<div class="col-md-12"><div id="setButton" class="float-left"></div><div class="text-center float-end"><button class="btn btn-info" onclick="saveLWs()"> Save </button></div></div>');
}
</script>