<?php
include_once '../session/admin-session.php';
include_once '../classes/class_admin.php';
include_once '../classes/validation.php';
include_once '../classes/common.php';
ob_start();

$log = new common();
$objadm = new class_admin();
$val = new validation();

$BatchList = $objadm->MasterActiveBatchFlagSetting();
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-xl-12 col-xxl-12 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">System Flags</h5>

                </div>
                <div class="card-body">

                    <div class="container mt-4">
                        <div class="section-title"><i>*Click the OPEN/CLOSE button to toggle the action.</i></div>
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>Batch</th>
                                    <th>Registration</th>
                                    <th>Transcript</th>
                                    <th>Feedback</th>
                                    <th>Grade Entry</th>
                                    <th>Marks Table</th>
                                </tr>
                            </thead>
                            <tbody>

                                <!-- Sample row for each batch -->
<?php
while ($row = mysqli_fetch_array($BatchList)) {

    $permit_reg = $row['permit_reg'];
    $permit_trans = $row['permit_trans'];
    $permit_grades = $row['permit_grades'];
    $permit_feedback = $row['permit_feedback'];
    $permit_marks = $row['permit_marks'];

    $flag_pk_id = $row['flag_sr'];
    ?>
                                    <tr>
                                        <td><?php echo $row['batch_name'] . "(" . $row['flag_user'] . ")" ?></td>
                                        <td>
    <?php if ($permit_reg == "Y") { ?>
                                                <input type="button" class="btn btn-success" value="OPEN" onclick="FunUpdateSystemFlags('permit_reg', 'CLOSE', '<?php echo $flag_pk_id; ?>')"/>
                                            <?php } else { ?>
                                                <input type="button" class="btn btn-danger" value="CLOSE" onclick="FunUpdateSystemFlags('permit_reg', 'OPEN', '<?php echo $flag_pk_id; ?>')"/>
                                            <?php } ?>
                                        </td>
                                        <td>
    <?php if ($permit_trans == "Y") { ?>
                                                <input type="button" class="btn btn-success" value="OPEN" onclick="FunUpdateSystemFlags('permit_trans', 'CLOSE', '<?php echo $flag_pk_id; ?>')"/>
                                            <?php } else { ?>
                                                <input type="button" class="btn btn-danger" value="CLOSE" onclick="FunUpdateSystemFlags('permit_trans', 'OPEN', '<?php echo $flag_pk_id; ?>')"/>
                                            <?php } ?>
                                        </td>
                                        <td>
    <?php if ($permit_feedback == "Y") { ?>
                                                <input type="button" class="btn btn-success" value="OPEN" onclick="FunUpdateSystemFlags('permit_feedback', 'CLOSE', '<?php echo $flag_pk_id; ?>')"/>
                                            <?php } else { ?>
                                                <input type="button" class="btn btn-danger" value="CLOSE" onclick="FunUpdateSystemFlags('permit_feedback', 'OPEN', '<?php echo $flag_pk_id; ?>')"/>
                                            <?php } ?>
                                        </td>
                                        <td>
    <?php
    if ($row['flag_user'] == "fac") {
        if ($permit_grades == "Y") {
            ?>
                                                    <input type="button" class="btn btn-success" value="OPEN" onclick="FunUpdateSystemFlags('permit_grades', 'CLOSE', '<?php echo $flag_pk_id; ?>')"/>
                                                <?php } else { ?>
                                                    <input type="button" class="btn btn-danger" value="CLOSE" onclick="FunUpdateSystemFlags('permit_grades', 'OPEN', '<?php echo $flag_pk_id; ?>')"/>
                                                <?php
                                                }
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if ($row['flag_user'] == "fac") {
                                                if ($permit_marks == "Y") {
                                                    ?>
                                                    <input type="button" class="btn btn-success" value="OPEN" onclick="FunUpdateSystemFlags('permit_marks', 'CLOSE', '<?php echo $flag_pk_id; ?>')"/>
                                                <?php } else { ?>
                                                    <input type="button" class="btn btn-danger" value="CLOSE" onclick="FunUpdateSystemFlags('permit_marks', 'OPEN', '<?php echo $flag_pk_id; ?>')"/>
                                                <?php
                                                }
                                            }
                                            ?>
                                        </td>

                                    </tr>
<?php } ?>
                            </tbody>
                        </table>
                    </div>

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

    </div>
</div>
<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'control_system_flags';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>
<script type="text/javascript">

    function FunUpdateSystemFlags(col_name, ActionStr, RefId) {
        if (confirm("Are you sure you want to " + ActionStr + "?")) {
            $.post("admin-action.php",
                    {
                        col_name: col_name,
                        activity: ActionStr,
                        ref_id: RefId,
                        action: "system-flag-update"
                    },
                    function (response) {
                       window.location.href='control-system-flags.php';
                       alert('Flag is updated successfully!');
                    });
        }
    }

</script>