<?php
/***
 * Auth: Vastvikta Nishad
 * Date:   16 Feb 2024
 * Description: To Update Callbacks
 * 
*/
$msg = '';
$id = isset($_GET['id']) ? base64_decode($_GET['id']) : '';
$res = get_callbacks($id);
$callback_alert_time = $res['callback_alert_time'];
$callback_time = $res['callback_time'];
$callback_remark = $res['remark'];
$callback_user = $res['user'];
?>
<div id="success"><?php echo $msg; ?></div>
<form id="mastersrcat" method="post" action="">
    <input name="id" id="id" type="hidden" value="<?php echo $id ?>">
    <span class="breadcrumb_head" style="height:37px;padding:9px 16px">Reschedule Callback Time </span>

    <div class="style2-table">
        <div class="table">
            <table class="tableview tableview-2 main-form">
                <tbody>
                    <?php if ($msg != '') { ?>
                        <tr>
                            <td colspan="2"
                                style="color:#ffffff; width:100%; background:#00CC66; padding:5px; border:1px solid #02944b; text-align:center;">
                                <?php echo $msg ?>
                            </td>
                        </tr>
                    <?php } ?>
                    
                    <!-- Row 1: Callback Time & Callback Alert Time -->
                    <tr>
                        <td class="left" colspan="2">
                            <div class="log-case">
                                <label for="callback_time" style="display: block;">Callback Date::Time<em>*</em></label>
                                <input name="callback_time" id="callback_time" type="text" value="<?php echo $callback_time; ?>" class="input-style1 date_class" style="width:180px;">
                            </div>
                        </td>

                        <td class="left" colspan="2">
                            <?php
                            list($hours, $minutes) = explode(':', $callback_alert_time);
                            ?>
                            <div class="log-case">
                                <label for="callback_alert_hour" style="display: block;">Callback Alert Date::Time<em>*</em></label>
                                <div style="display: flex; align-items: center; gap: 5px;">
                                    <select name="callback_alert_hour" id="callback_alert_hour" 
                                        class="input-style1" style="width: 110px; height:24px; font-size: 14px;">
                                        <?php for ($h = 0; $h < 24; $h++){ ?>
                                            <?php $hour = str_pad($h, 2, '0', STR_PAD_LEFT); ?>
                                            <option value="<?= $hour ?>" <?= ($hour == $hours) ? 'selected' : '' ?>>
                                                <?= $hour ?>
                                            </option>
                                        <?php } ?>
                                    </select>
                                    <span>Hour</span>

                                    <select name="callback_alert_minute" id="callback_alert_minute" 
                                        class="input-style1" style="width: 110px; height:24px; font-size: 14px;">
                                        <?php for ($m = 0; $m < 60; $m++){?>
                                            <?php $minute = str_pad($m, 2, '0', STR_PAD_LEFT); ?>
                                            <option value="<?= $minute ?>" <?= ($minute == $minutes) ? 'selected' : '' ?>>
                                                <?= $minute ?>
                                            </option>
                                        <?php }?>
                                    </select>
                                    <span>Min</span>
                                </div>
                            </div>
                        </td>
                    </tr>

                    <!-- Row 2: Callback Remark & Update Button -->
                    <tr>
                        <td class="left" colspan="2">
                            <div class="log-case">
                            <label for="reassignCallback">Re-Assign<em>*</em></label>
                            <select name="reassignCallback" id="reassignCallback" style="width:180px">
                                <option value="">Select</option>

                                <?php
                                $agents = getActiveAgents($link);
                                foreach ($agents as $agent) {
                                    $selected = ($agent['AtxUserName'] == $callback_user) ? 'selected' : '';
                                    echo "<option value='".$agent['AtxUserName']."' $selected>".$agent['AtxUserName']."</option>";
                                }
                                ?>
                            </select>
                               
                            </div>
                        </td>
                        <td class="left" colspan="2">
                            <div class="log-case">
                                <label for="callback_remark" style="display: block;">Callback Remark<em>*</em></label>
                                <textarea name="callback_remark" id="callback_remark" class="input-style1" style="width:300px;height:60px"><?php echo htmlspecialchars($callback_remark); ?></textarea>
                            </div>
                        </td>
                        </tr>
                        <tr>

                        <td colspan="2">
                            <center>
                                <div class="log-case">
                                    <input name="Update" type="submit" value="Update" class="button-orange1" id="submitclkcallbacks">
                                </div>
                            </center>
                        </td>
                    </tr>

                </tbody>
            </table>
        </div>
    </div>
</form>
