<?php 
if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../../'.$_REQUEST['tenant'].'/config.php');}
if(file_exists('/config.php')){require_once('/config.php');}
require_once('../asset/asset_functions.php');
?>
<div class="col-md-12">
    <form id="wsForm">
        <div class="form-group row">
            <label class="col-12 control-label col-md-2" for="wsDesc">WSE Type</label>
            <div class="col-12 col-md-2 mb-3">
                <div class="form-check">
                    <input type="radio" class="form-check-input" id="wstypeInternal" name="wstype" value="0" checked>
                    <label class="form-check-label" for="wstypeInternal">EnRep</label>
                </div>
            </div>
            <div class="col-12 col-md-2 mb-3">
                <div class="form-check">
                    <input type="radio" class="form-check-input" id="wstypeExisting" name="wstype" value="1">
                    <label class="form-check-label" for="wstypeExisting">Existing</label>
                </div>
            </div>
        </div>

        <div class="form-group row mb-3">
            <label class="col-12 col-md-2 control-label" for="wsDesc">Site</label>
            <div class="col-12 col-md-5"><?= getSites2($_REQUEST['clientnumber'],'')?></div>
        </div>
        <div class="form-group row mb-3">
            <label class="col-12 col-md-2 control-label" for="wsDesc">Location on Site</label>
            <div class="col-12 col-md-6"><input class="form-control form-control-sm" type="text" name="wsDesc" id="wsDesc" value="" /></div>
        </div>
        <div class="row">
            <div class="col-12 text-center">
                <input type="submit" class="btn btn-info" value="Create entry" />
                <input type="hidden" name="mode" value="setWS">
                <input type="hidden" name="clientnumber" value="<?= $_REQUEST['clientnumber']?>">
                <input type="hidden" name="tenant" value="<?= TENANT_URL?>">
            </div>
        </div>
    </form>

</div>

<script>
$("#wsForm input[type='submit']").click(function(event) {
    event.preventDefault();
    var d = $('#wsDesc').val();
    var l = $('#locnumber2').val();
    if ($.trim(d) == "") {
        showResponse('warning', 'YOU MUST SET A DESCRIPTION FOR YOUR WRITTEN SCHEME')
    } else {
        if ($.trim(l) == "") {
            showResponse('warning', 'YOU MUST SELECT A SITE FOR YOUR WRITTEN SCHEME')
        } else {
            $.ajax({
                url: ROOT_URL + '/includes/master/ws_functions.php',
                type: 'POST',
                data: $('#wsForm').serialize(),
                success: function(result) {

                    if ($.trim(result) == "success") {
                        showResponse('success', 'THE WS HAS BEEN CREATED SUCCESSFULLY')
                        relWs()
                        killModal("wsBox")
                    } else {
                        showResponse('danger', 'THERE WAS AN ERROR CREATING THE WS')
                    }
                }
            });
        }
    }
});
</script>