<!--    Authors         :   Carlos C. Corrada-Bravo
                            David J. Ortiz-Rivera

        Organization    :   Centro de Desarrollo y Consultoria Computacional
        Project         :   OPASO Material Registry  
        File            :   inventory
        Description     :   Edit laboratory inventory -->

<!-- Verify Session -->
<?php require_once("header.php");

    /* start user session */
    if(!isset($_SESSION)){
        session_start();
    }

    /* verify lab id */
    if(!isset($_GET["lab_id"])){
        header("Location: /menu");
        die();
    }

    else{
        if(!($_SESSION["authorized"][$_GET["lab_id"]]["access_level"] === "admin") and !($_SESSION["authorized"][$_GET["lab_id"]]["access_level"] === "investigator") and !(array_key_exists($_GET["lab_id"],$_SESSION["authorized"]))){
            header("Location: /menu");
            die();
        }
    }
?>

<!doctype html>
<html lang="en">
    <!-- encoding/imports/styling -->
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title class="title"><?php echo $_SESSION["authorized"][$_GET["lab_id"]]["lab_room"]; ?></title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
        <link rel="stylesheet" href="/style/main.css">
        <link rel="stylesheet" href="/style/laboratory.css">
    </head>

    <!-- content -->
    <body>
        <div class="form-shader close-form">
            <div class="edit-form close-form">
                <div class="edit-form-wrapper">
                    <div class="edit-form-header-wrapper">
                        <h4 class="form-header">Edit Material</h4>
                        <div class="close-icon"><i class="material-icons close-form">close</i></div>
                    </div>
                    <div class="edit-form-body-wrapper">
                        <div class="edit-form-body">
                            <div class="details material">
                                <h5 class="details-header">Material Details</h5>
                                <div class="edit-li-wrapper large-field">
                                    <label for="mat_name">Material</label>
                                    <input class="material-input" type="text" placeholder="Material" name="mat_name">
                                </div>
                                <div class="edit-li-wrapper medium-field">
                                    <label for="cas-number">CAS Num.</label>
                                    <input class="material-input" type="text" placeholder="Cas Num." name="cas">
                                </div>
                                <div class="edit-li-wrapper medium-field">
                                    <label for="man_name">Manufacturer</label>
                                    <input class="material-input" type="text" placeholder="Manufacturer" name="man_name">
                                </div>
                                <div class="edit-li-wrapper large-field">
                                    <label for="sds-link">SDS Link</label>
                                    <input class="material-input" type="text" placeholder="SDS Link" name="sds">
                                </div>
                                <div class="edit-li-wrapper extra-small-field">
                                    <label for="state">State</label>
                                    <input class="material-input" type="text" placeholder="State" name="state">
                                </div>
                            </div>
                            <div class="details hazard">
                                <h5 class="details-header">Hazard Details</h5>
                                <div class="edit-li-wrapper medium-field">
                                    <label for="ghs">GHS</label>
                                    <input class="material-input" type="text" placeholder="GHS" name="ghs">
                                </div>
                            </div>
                            <div class="details container">
                                <h5 class="details-header">Container Details</h5>
                                <div class="edit-li-wrapper extra-small-field">
                                    <label for="type">Type</label>
                                    <input class="material-input" type="text" placeholder="Type" name="type">
                                </div>
                                <div class="edit-li-wrapper small-field">
                                    <label for="capacity">Capacity</label>
                                    <input class="material-input" type="text" name="capacity" placeholder="Capacity" oninput="this.value = this.value.replace(/[^0-9.]/g,'').replace(/(\..*)\./g, '$1');">
                                </div>
                                <div class="edit-li-wrapper small-field quantity">
                                    <label for="quantity">Quantity</label>
                                    <input class="material-input" type="text" name="quantity" placeholder="Quantity" oninput="this.value = this.value.replace(/[^0-9.]/g,'').replace(/(\..*)\./g, '$1');">
                                </div>
                                <div class="edit-li-wrapper small-field uom">
                                    <label for="uom">UOM</label>
                                    <input class="material-input" type="text" placeholder="UOM" name="uom">
                                </div>
                                <div class="edit-li-wrapper medium-field">
                                    <label for="location">Location</label>
                                    <input class="material-input" type="text" placeholder="Location" name="location">
                                </div> 
                            </div>
                        </div>
                        <div class="edit-form-actions">
                            <button class="btn btn-primary action-btn submit" id="edit-submit">Submit</button>
                        </div>
                    </div>
                </div>
            </div> 
        </div>

        <!-- alerts -->
        <div class="alerts">
            <div class="alert">
                <div class="message-icon-wrapper">
                    <i class="message-icon success-icon material-icons">done</i>
                    <i class="message-icon error-icon failed-icon warning-icon material-icons">close</i>
                </div>
                <p class="alert-status"></p>
                <p class="alert-message"></p>
            </div>
        </div>

        <!-- confirm alert -->
        <div class="alert-wrapper hide-confirm">
            <div class="confirm-alert">
                <h5 class="header confirm-header">Confirm</h5>
                <div class="mi-wrapper">
                    <div class="confirm-message"></div>
                    <div class="query-actions">
                        <button class="btn query-btn" id="yes">Yes</button>
                        <button class="btn query-btn hide-confirm">No</button>
                    </div>                                       
                </div>
            </div> 
        </div>

        <div class="content">
           <!-- navbar -->
            <?php require_once("navbar.php")?>

            <div class="main">
                <div class="header-wrapper">
                    <h5 class="header lab-header"><?php echo $_SESSION["authorized"][$_GET["lab_id"]]["lab_room"]; ?></h5>
                    <!-- processing -->
                    <div class="processing">
                        <p class="processing-text">Fetching inventory...</p>
                        <div class="loader"></div>
                    </div>
                </div>

                <div class="main-wrapper">
                    <!-- search form -->
                    <div class="float-right">
                        <div class="search-form-wrapper">
                            <input class="search-form" type="text" placeholder="Search for materials" name="search-form">
                            <button class="clear-btn search-form-submit">
                                <i class="material-icons clear-icon">close</i>
                            </button>
                        </div>
                    </div>

                    <!-- inventory -->
                    <h6 class="header sub-header">Edit Inventory</h6>
                    <div class="table-wrapper inventory">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th class="sort" value="mat_name" >Material
                                        <i class="sort-icon sort-material fas fa-caret-down"></i>
                                    </th>
                                    <th >Manufacturer</th>
                                    <th >CAS Num.</th>
                                    <th >SDS</th>
                                    <th >GHS</th>
                                    <th >State</th>
                                    <th >Type</th>
                                    <th value="capacity">Capacity</th>
                                    <th value="quantity">Quantity</th>
                                    <th value="total">Total</th>
                                    <th value="uom">UOM</th>
                                    <th >Location</th>
                                    <th >Options</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>

                    <h6 class="header table-total"></h6>
                </div>
             </div>

            <!-- footer -->
            <?php require_once("footer.php")?>
        </div>  

        <!-- scripts -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
        <script type="text/javascript" src="/scripts/main.js"></script>
        <script type="text/javascript" src="/scripts/inventory.js"></script>
    </body>
</html>