<?php //REPORT OF PRESSURE SYSTEM OR PART  
if (!function_exists('enrep_itemdetails_pressure_from_record')) {
    $itemdetailsJsonHelper = __DIR__ . '/../../enrepcore/functions/itemdetails_json.php';
    if (file_exists($itemdetailsJsonHelper)) {
        require_once $itemdetailsJsonHelper;
    }
}
if (function_exists('enrep_itemdetails_pressure_from_record') && isset($cd) && is_array($cd)) {
    $cd = array_replace($cd, enrep_itemdetails_pressure_from_record($cd));
}

$legacyReportRows=explode("|",$rd['protectiveDevices'] ?? '');
$rd['protectiveDevices']=$legacyReportRows[0] ?? '';
$rd['protectiveDevicesNarrative']=$legacyReportRows[1] ?? '';
$cd['system_type']        = ($cd['system_type'] ?? '')        ?: ($dData['system_type'] ?? '');
$cd['changeScheme']       = ($rd['changeScheme'] ?? ($cd['changeScheme'] ?? '')) ?: "No";
$cd['lease_or_hire']      = ($cd['lease_or_hire'] ?? '')      ?: "No";
$cd['lastReportSeen']     = ($rd['lastReportSeen'] ?? ($cd['lastReportSeen'] ?? ($cd['lastReport'] ?? ''))) ?: "Yes";
$rd['history']            = ($rd['history'] ?? '')            ?: ($dData['history'] ?? '');
$rd['examType']           = ($rd['examType'] ?? '')           ?: ($dData['examType'] ?? '');
$rd['resultOfExam']       = ($rd['resultOfExam'] ?? '')       ?: ($dData['resultOfExam'] ?? '');
$rd['partsCovered']       = ($rd['partsCovered'] ?? '')       ?: "None";
$rd['partsInaccessible']  = ($rd['partsInaccessible'] ?? '')  ?: ($dData['partsInaccessible'] ?? '');
$rd['conditionInternal']  = ($rd['conditionInternal'] ?? '')  ?: ($dData['conditionInternal'] ?? '');
$rd['conditionExternal']  = ($rd['conditionExternal'] ?? '')  ?: ($dData['conditionExternal'] ?? '');
$rd['conditionFittings']  = ($rd['conditionFittings'] ?? '')  ?: ($dData['conditionFittings'] ?? '');
$rd['obs']                = ($rd['obs'] ?? '')                ?: ($dData['obs'] ?? '');
$rd['repair_details']     = ($rd['repair_details'] ?? '')     ?: "None";

if(empty($rd['repair_details'])){$rd['repair_details']="None";}

if(!empty($_REQUEST['protectiveDevices'])){
	$repdev=explode("|",$_REQUEST['protectiveDevices']);
	$rd['protectiveDevices']=$repdev[0] ?? '';
	$rd['protectiveDevicesNarrative']=$repdev[1] ?? '';
	}
	if(empty($rd['protectiveDevices'])){$rd['protectiveDevices']="Yes";}

if(empty($rd['9b1'])){$rd['9b1']="No";}
if(empty($rd['9b2'])){$rd['9b2']="No";}
if(empty($rd['9b3'])){$rd['9b3']="No";}



$stmt = $GLOBALS['con']->prepare("SELECT `id`,`wsnumber` FROM `wsitems` WHERE `itemnumber`=?")or die($error=mysqli_error($GLOBALS['con']));
$stmt->bind_param('i',$d[2]);$stmt->execute();$res=$stmt->get_result();$stmt->close();
$c=mysqli_num_rows($res);$ds=mysqli_fetch_array($res);

$wsi = [
    'scheme_number_alt' => $cd['scheme_number_alt'] ?? '',
    'select_for_scheme' => $cd['select_for_scheme'] ?? '',
];

if($c==0 && $wsi['select_for_scheme']==0){
    $prClientnumber = (int)($d[0] ?? ($cd['clientnumber'] ?? 0));
    $prItemnumber = (int)$d[2];

    $stmt = $GLOBALS['con']->prepare("SELECT `id`,`no`,`title` FROM `writtenscheme` WHERE `clientnumber`=? ORDER BY abs(no) ASC") or die(mysqli_error($GLOBALS['con']));
    $stmt->bind_param('i', $prClientnumber);
    $stmt->execute();
    $wsList = $stmt->get_result();
    $stmt->close();
?>


<div class="row justify-content-center mb-4">
    <div class="col-12 col-lg-8">
        <div class="card">
            <div class="card-header" style="background-color:#f80!important; color:#333">Written Scheme Required</div>
            <div class="card-body">
                <p class="mb-3">This pressure report cannot continue until the item is attached to a Written Scheme. Select an existing scheme; once the item is attached, the form will refresh and continue.</p>

                <div class="row g-2 align-items-end">
                    <div class="col-12 col-md-7">
                        <label class="form-label" for="pressureReportWsSelect">Existing Written Scheme</label>
                        <select id="pressureReportWsSelect" class="form-control">
                            <option value="">Select Written Scheme</option>
                            <?php while ($wsRow = mysqli_fetch_array($wsList)) { ?>
                                <option value="<?= (int)$wsRow['id'] ?>"><?= htmlspecialchars($wsRow['no'] . ': ' . $wsRow['title'], ENT_QUOTES, 'UTF-8') ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <div class="col-12 col-md-5 d-flex gap-2">
                        <button type="button" class="btn btn-success" onclick="attachPressureReportWs()">
                            <i class="fad fa-link"></i> Attach
                        </button>
                       
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function pressureReportRefresh() {
    window.location.reload();
}

function attachPressureReportWs(wsnumber) {
    const select = document.getElementById('pressureReportWsSelect');
    const selectedWs = wsnumber || (select ? select.value : '');

    if (!selectedWs) {
        showResponse('warning', 'Please select a Written Scheme first');
        return;
    }

    fetch(ROOT_URL + '/includes/master/ws_functions.php', {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: new URLSearchParams({
            mode: 'addWSI',
            wsnumber: String(selectedWs),
            clientnumber: '<?= $prClientnumber ?>',
            itemnumber: '<?= $prItemnumber ?>',
            tenant: TENANT_URL
        })
    })
    .then(response => response.text())
    .then(ret => {
        const dta = ret.split('|');
        if (dta[0] !== 'success') {
            showResponse('danger', ret);
            return;
        }

        showResponse('success', 'The item has been attached to the Written Scheme');
        window.setTimeout(pressureReportRefresh, 600);
    });
}

function createPressureReportWs() {
    const dest = encodeURI(
        ROOT_URL
        + '/includes/client/client_ws.php'
        + '?clientnumber=<?= $prClientnumber ?>'
        + '&tenant=' + TENANT_URL
    );

    loadModalContent(dest, 'wsBox', 'modal-xl', 1060, 'true', 'New Written Scheme');
}

window.pssrAddWsOption = function(insertId) {
    const idNum = parseInt(insertId, 10);
    if (!idNum) return;
    attachPressureReportWs(idNum);
};
</script>
<?php
exit();
}
else{
$wsRef=isWS($d[2]);
$wsRef=str_replace('\\','',$wsRef);
$wsRef=str_replace('<div class="float-end">','',$wsRef);
$wsRef=str_replace('</div>','',$wsRef);
$wsRef=str_replace('btn-info tip','btn btn-info',$wsRef);
?>
<div class="row">

    <div class="col-12 col-md-6 mb-4">

        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Written Scheme Number</div>
            <div class="col-11 col-md-5"><?= $wsRef?> </div>
            <div class="col-1"><input type="radio" class="flat" name="snc" id="int" value="int"></div>
        </div>

        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Existing Scheme Number</div>
            <div class="col-11 col-md-5"><input type="text" class="form-control" id="scheme_number_alt" name="pressure[scheme_number_alt]" value="<?= $cd['scheme_number_alt']?>"></div>
            <div class="col-1"></div>
        </div>


        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Identification of System</div>
            <div class="col-12 col-md-6"><input type="text" class="form-control" name="" value="<?= ucwords($cd['system_type'])?>"></div>
        </div>


        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Is the system subject to a lease Agreement<br><small>i.e Written agreement under section 2</small></div>
            <div class="col-12 col-md-2"><select class="form-control" name="pressure[lease_or_hire]">
                    <option value="Yes" <?php if(strcasecmp((string)$cd['lease_or_hire'], "Yes") === 0){?>selected<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$cd['lease_or_hire'], "No") === 0){?>selected<?php }?>>No</option>
                </select></div>
        </div>

    </div>

    <div class="col-12 col-md-6 mb-4">

        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">State whether last report seen</div>
            <div class="col-12 col-md-4"><select class="form-control" name="lastReportSeen">
                    <option value="Yes" <?php if(strcasecmp((string)$cd['lastReportSeen'], "Yes") === 0){?>SELECTED<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$cd['lastReportSeen'], "No") === 0){?>SELECTED<?php }?>>No</option>
                </select></div>
        </div>

        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Is any change advised in the scheme of examination</div>
            <div class="col-12 col-md-4"><select class="form-control" name="changeScheme">
                    <option value="Yes" <?php if(strcasecmp((string)$cd['changeScheme'], "Yes") === 0){?>selected<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$cd['changeScheme'], "No") === 0){?>selected<?php }?>>No</option>
                </select></div>
        </div>

        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Safe Operating limits</div>
            <div class="col-12 col-md-5"><input type="text" class="form-control" name="swl" value="<?= $cd['swl']?>"></div>
        </div>

        <div class="row mb-3">
            <div class="col-12 col-md-6 lead">Are protective devices operating in order to maintain the system parts within the safe operating limits?</div>
            <div class="col-12 col-md-4"><select class="form-control" name="protectiveDevices">
                    <option value="N/A" <?php if($rd['protectiveDevices']=="N/A"){?>selected<?php }?>>N/A</option>
                    <option value="Yes" <?php if(strcasecmp((string)$rd['protectiveDevices'], "Yes") === 0 || $rd['protectiveDevices']==""){?>selected<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$rd['protectiveDevices'], "No") === 0){?>selected<?php }?>>No</option>
                </select></div>
            <div class="col-12"><input class="form-control" name="protectiveDevicesNarrative" placeholder="Result details (not required)" value="<?= $rd['protectiveDevicesNarrative']?>"></div>
        </div>

    </div>

</div>

<div class="row">

    <div class="col-12 col-md-6">

        <div class="row mb-3">
            <div class="col-12 control-label lead">Result of Examination</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="resultOfExam" name="resultOfExam"><?= $rd['resultOfExam']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('resultOfExam')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','resultOfExam','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('resultOfExam','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','resultOfExam','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('resultOfExam')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Relevant History including tests and dates</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="history" name="history"><?= $rd['history']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('history')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','history','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('history','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','history','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('history')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Type of examination and test(s) undertaken</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="examType" name="examType"><?= $rd['examType']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('examType')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','examType','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('examType','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','examType','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('examType')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Parts covered but requiring periodic examination and date of last examination</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="partsCovered" name="partsCovered"><?= $rd['partsCovered']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('partsCovered')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','partsCovered','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('partsCovered','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','partsCovered','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('partsCovered')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

    </div>

    <div class="col-12 col-md-6">

        <div class="row mb-3">
            <div class="col-12 control-label lead">Parts inaccessible</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="partsInaccessible" name="partsInaccessible"><?= $rd['partsInaccessible']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('partsInaccessible')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','partsInaccessible','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('partsInaccessible','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','partsInaccessible','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('partsInaccessible')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Condition of internal parts</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="conditionInternal" name="conditionInternal"><?= $rd['conditionInternal']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('conditionInternal')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','conditionInternal','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('conditionInternal','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','conditionInternal','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('conditionInternal')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Condition of external parts</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="conditionExternal" name="conditionExternal"><?= $rd['conditionExternal']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('conditionExternal')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','conditionExternal','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('conditionExternal','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','conditionExternal','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('conditionExternal')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Condition of fittings</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="conditionFittings" name="conditionFittings"><?= $rd['conditionFittings']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('conditionFittings')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','conditionFittings','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('conditionFittings','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','conditionFittings','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('conditionFittings')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-12 control-label lead">Repairs or modifications</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="repair_details" name="repair_details"><?= $rd['repair_details']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('repair_details')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','repair_details','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('repair_details','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','repair_details','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('repair_details')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>

    </div>

</div>

<div class="row mb-4">

    <div class="col-12 mt-5">
        <p><strong>Are changes to the safe working limit required?</strong></p>
    </div>

    <div class="col-12 col-md-4">
        <div class="row mb-3">
            <div class="col-12 col-md-6">Before the examination of the period specified</div>
            <div class="col-12 col-md-4"><select class="form-control" name="9b1">
                    <option value="Yes" <?php if(strcasecmp((string)$rd['9b1'], "Yes") === 0){?>selected<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$rd['9b1'], "No") === 0){?>selected<?php }?>>No</option>
                </select></div>
        </div>
    </div>

    <div class="col-12 col-md-4">
        <div class="row mb-3">
            <div class="col-12 col-md-6 control-label">After the expiration of such period if the required repairs have not been completed</div>
            <div class="col-12 col-md-4"><select class="form-control" name="9b2">
                    <option value="Yes" <?php if(strcasecmp((string)$rd['9b2'], "Yes") === 0){?>selected<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$rd['9b2'], "No") === 0){?>selected<?php }?>>No</option>
                </select></div>
        </div>
    </div>

    <div class="col-12 col-md-4">
        <div class="row mb-3">
            <div class="col-12 col-md-6">After the completion of the required repairs</div>
            <div class="col-12 col-md-4"><select class="form-control" name="9b3">
                    <option value="Yes" <?php if(strcasecmp((string)$rd['9b3'], "Yes") === 0){?>selected<?php }?>>Yes</option>
                    <option value="No" <?php if(strcasecmp((string)$rd['9b3'], "No") === 0){?>selected<?php }?>>No</option>
                </select></div>
        </div>
    </div>
</div>

<div class="row mb-4">
    <div class="col-12">
        <div class="row mb-3">
            <div class="col-12 control-label lead">Other Observations</div>
            <div class="col-12 d-flex"><textarea rows="4" class="form-control" id="obs" name="obs"><?= $rd['obs']?></textarea>
                <div class="d-flex flex-column">
                    <button type="button" class="btn btn-secondary mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Clear Field" onClick="clearbox('obs')">
                        <i class="fad fa-eraser"></i>
                    </button>
                    <?php if($_SESSION['usertype']=="admins"){ ?>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','obs','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <button type="button" class="btn btn-success mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Save field as new entry" onClick="savebox('obs','phrases')">
                        <i class="fad fa-save"></i>
                    </button>
                    <?php } else { ?>
                    <button type="button" class="btn btn-success mb-1" onClick="javascript:void(0)"></button>
                    <button type="button" class="btn btn-info mb-1" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="View List" onClick="autofill('F<?= $d[2]?>','obs','phrases')">
                        <i class="fad fa-edit"></i>
                    </button>
                    <?php } ?>
                    <button type="button" class="btn btn-danger" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reset FIeld" onClick="resetBox('obs')">
                        <i class="fad fa-refresh"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>

</div>

<?php }?>
