<?php
/***
Auth: Vastvikta Nishad
Date: 20 Jan 2024
Description: To create and Update the Sub Category
*/

$msg = '';
$id = base64_decode($_GET['id']);
//function defined in web_admin_function.php 
$subcategoryData = getSubCategoryData($link, $id);
?>
<div id="success"></div>
<form name="myform" method="post" id="myform">
    <input name="id" id="id" type="hidden" value="<?php echo $id ?>">
    <span class="breadcrumb_head" style="height:37px;padding:9px 16px"><?php echo  ($id != '') ? "Edit" : "New" ?> Sub Category</span>
    <div class="style2-table">
        <div class="table">
            <table class="tableview tableview-2 main-form" width="100%">
                <tbody>
                    <?php if ($msg != '') { ?>
                        <tr>
                            <td colspan="4" style="color:#ffffff; width:100%; background:#00CC66; padding:5px; border:1px solid #02944b; text-align:center;">
                                <?php echo $msg ?>
                            </td>
                        </tr>
                    <?php } ?>
                    <tr>
                        <td>
                            <label>Category <em>*</em></label>
                        </td>
                        <td class="left boder0-right">
                            <div class="log-case">
                                <?php
                                $selcountry = "Select * from $db.web_category where status=1  order by category";
                                $query1 = mysqli_query($link, $selcountry);
                                ?>
                                <select name="category" id="category" class="select-styl1">
                                    <option value=''>Select Category</option>
                                    <?php while ($c_row = mysqli_fetch_array($query1)) {
                                        $ICategoryID = $c_row['id'];
                                        $VCategoryName = $c_row['category'];

                                        $sel = ($ICategoryID == $subcategoryData['category']) ? ' selected' : '';
                                    ?>
                                        <option value='<?php echo  $ICategoryID ?>' <?php echo $sel ?>>
                                            <?php echo  $VCategoryName ?> - <?php echo $c_row['type'] ?>
                                        </option>
                                    <?php } ?>
                                </select>
                            </div>
                        </td>
                        <td><label>Sub Category<em>*</em></label></td>
                        <td class="left boder0-right">

                            <div class="log-case">
                                <input name="subcategory" id="subcategory" type="text" value="<?php echo  $subcategoryData['subcategory'] ?>" class="input-style1">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><label>Escalation Time In Hours<em>*</em></label></td>
                        <td class="left boder0-right">

                            <div class="log-case">
                                <input name="time_hours" id="time_hours" type="number" value="<?php echo  $subcategoryData['time_hours'] ?>" class="input-style1">
                            </div>
                        </td>
                        <td><label>Level 1 users</label></td>

                        <td>
                            <div class="log-case">
                                <select name="level1_users[]" id="level1_users" class="input-style1" multiple multiselect-search="true" multiselect-select-all="true" multiselect-max-items="3" data-placeholder="Select Level 1 users" required>
                                    <?php
                                    while ($row = mysqli_fetch_array($subcategoryData['result1'])) {

                                        $AtxUserID = $row['AtxUserID'];
                                        $AtxUserName = $row['AtxUserName'];

                                        $val = explode(",", $subcategoryData['level1_users']);

                                        if (in_array($AtxUserID, $val)) {
                                            $sel = ' selected';
                                        } else {
                                            $sel = '';
                                        }

                                    ?>
                                        <option value='<?php echo  $AtxUserID ?>' <?php echo  $sel ?>><?php echo  $AtxUserName ?></option >
                                    <?php } ?>
                                </select>
                            </div>

                        </td>

                    </tr>
                    <tr>
                        <td><label>Second Escalation Time In Hours</label></td>
                        <td class="left boder0-right">

                            <div class="log-case">
                                <input name="second_resolution" id="second_resolution" type="number" value="<?php echo $subcategoryData['second_resolution'] ?>" class="input-style1">
                            </div>
                        </td>
                        <td><label>Level 2 users</label></td>

                        <td>
                            <div class="log-case">
                                <select name="level2_users[]" id="level2_users" class="input-style1" multiple multiselect-search="true" multiselect-select-all="true" multiselect-max-items="3" data-placeholder="Select Level 2 users">
                                    
                                    <?php
                                    while ($row = mysqli_fetch_array($subcategoryData['result2'])) {

                                        $AtxUserID = $row['AtxUserID'];
                                        $AtxUserName = $row['AtxUserName'];

                                        $val = explode(",", $subcategoryData['level2_users']);

                                        if (in_array($AtxUserID, $val)) {
                                            $sel = ' selected';
                                        } else {
                                            $sel = '';
                                        }
                                    ?>
                                        <option value='<?php echo $AtxUserID ?>' <?php echo  $sel ?>><?php echo $AtxUserName ?></option>
                                    <?php } ?>
                                </select>
                            </div>

                        </td>

                    </tr>
                    <tr>
                        <td><label>Third Escalation Time In Hours</label></td>
                        <td class="left boder0-right">

                            <div class="log-case">
                                <input name="third_resolution" id="third_resolution" type="number" value="<?php echo  $subcategoryData['third_resolution'] ?>" class="input-style1">
                            </div>
                        </td>
                        <td><label>Level 3 users</label></td>

                        <td>
                            <div class="log-case">
                                <select name="level3_users[]" id="level3_users" class="input-style1" multiple multiselect-search="true" multiselect-select-all="true" multiselect-max-items="3" data-placeholder="Select Level 3 users">
                                    <?php
                                    while ($row = mysqli_fetch_array($subcategoryData['result3'])) {

                                        $AtxUserID = $row['AtxUserID'];
                                        $AtxUserName = $row['AtxUserName'];

                                        $val = explode(",", $subcategoryData['level3_users']);

                                        if (in_array($AtxUserID, $val)) {
                                            $sel = ' selected';
                                        } else {
                                            $sel = '';
                                        }

                                    ?>
                                        <option value='<?php echo  $AtxUserID ?>' <?php echo  $sel ?>><?php echo  $AtxUserName ?></option>
                                    <?php } ?>
                                </select>
                            </div>

                        </td>

                    </tr>
                    <tr>
                        <td><label>Description</label></td>
                        <td class="left boder0-right">

                            <div class="log-case">
                                <textarea name="V_Description" id="V_Description" cols="" rows="4" class="text-area1"><?php echo  $subcategoryData['VDescription'] ?></textarea>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <center>
                                <?php if ($id != '') { ?>
                                    <input name="Update" type="submit" value="Update" class="button-orange1" id="submitclksub" style="float:inherit">
                                <?php } else { ?>
                                    <input name="addbtn" type="submit" value="Create" class="button-orange1" id="submitclksub" style="float:inherit">
                                <?php } ?>
                            </center>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</form>
