<?php
// $param_pre = 'zone'; // pre-select the zone for all cases
/*$html_region = $this->bonvoi_retail_generate_chkregion();

//generate destination list if region provided
if(!empty($param_pre)) {
    $html_dest = $this->bonvoi_retail_generate_chkdest($param_pre);
}

//generate plans options if destination provided
if(!empty($param_pde)) {
    $html_plans = $this->bonvoi_retail_generate_chkplan($param_pde);
}

$settings_param_arr = array('bonvoi_topup_new_esim_price');
$options_param_arr = array();
$return_params = $this->bonvoi_retail_generate_parameters($settings_param_arr, $options_param_arr);

$new_esim_price = '';

if(!empty($return_params['bonvoi_topup_new_esim_price'])) {
    $new_esim_price = $return_params['bonvoi_topup_new_esim_price'];
}*/

// echo '<pre>';
// print_r($html_region);
// print_r($html_dest);
//print_r($html_plans);
// echo '</pre>';

// $_SESSION['bonvoi_retail_msg']['status'] = 'success';
// $_SESSION['bonvoi_retail_msg']['msg'] = 'Login Successfully.';
?>

<style>
@media (min-width: 1025px) {
    .wpcompleteautomatc_msgbox_success {
        padding:20px 20px;
        margin-bottom:10px;
    }

    .wpcompleteautomatc_msgbox_error {
        padding:20px 20px;
        margin-bottom:10px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .wpcompleteautomatc_msgbox_success {
        padding:10px 10px;
        margin-bottom:10px;
    }

    .wpcompleteautomatc_msgbox_error {
        padding:10px 10px;
        margin-bottom:10px;
    }
}

@media (max-width: 767px) {
    .wpcompleteautomatc_msgbox_success {
        padding:10px 10px;
        margin-bottom:10px;
    }

    .wpcompleteautomatc_msgbox_error {
        padding:10px 10px;
        margin-bottom:10px;
    }
}

.wpcompleteautomatc_msgbox_success {
    background:#f4fff2;
    border:1px solid #dbe8cf;
}

.wpcompleteautomatc_msgbox_error {
    background:#fff2f2;
    border:1px solid #f4dbdb;
}
</style>

<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$setting_arr = array();

$setting_arr['allstaff_shop_id'] = '';
$setting_arr['allstaff_role_id'] = '';
$setting_arr['allstaff_code'] = '';
$setting_arr['front_passwd'] = '';
$setting_arr['allstaff_name'] = '';
$setting_arr['allstaff_email'] = '';
$setting_arr['allstaff_phone'] = '';
// $setting_arr['allstaff_active'] = '';

$shop_arr = array();
$usr_role_arr = array();

$qry_shops = "SELECT bv_shop_id, bv_shop_name FROM " . $wpdb->prefix . "bonvoi_shops ORDER BY bv_shop_name";
$rs_shops = $wpdb->get_results($qry_shops, ARRAY_A);

if($rs_shops) {
    foreach($rs_shops as $rs_shop) {
        $shop_item = array();
        $shop_item['id'] = $rs_shop['bv_shop_id'];
        $shop_item['text'] = $rs_shop['bv_shop_name'];

        $shop_arr[] = $shop_item;
    }
}

$qry_roles = "SELECT bv_role_id, bv_role_name FROM " . $wpdb->prefix . "bonvoi_roles WHERE bv_role_purpose='user'";
$rs_roles = $wpdb->get_results($qry_roles, ARRAY_A);

if($rs_roles) {
    foreach($rs_roles as $rs_role) {
        $role_item = array();
        $role_item['id'] = $rs_role['bv_role_id'];
        $role_item['text'] = $rs_role['bv_role_name'];

        $usr_role_arr[] = $role_item;
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>

<h4>Retail Staff Registration</h4>

<?php
if(!empty($_SESSION['bonvoi_retail_msg']['status'])) {
    if($_SESSION['bonvoi_retail_msg']['status'] == "success") {
        echo '<div class="wpcompleteautomatc_msgbox_success">';
            echo $_SESSION['bonvoi_retail_msg']['msg'];
        echo '</div>';
    }
    else if ($_SESSION['bonvoi_retail_msg']['status'] == "failed") {
        echo '<div class="wpcompleteautomatc_msgbox_error">';
            echo $_SESSION['bonvoi_retail_msg']['msg'];
        echo '</div>';
    }

    unset($_SESSION['bonvoi_retail_msg']);
}
?>

<div class="topupform">
    <div class="tpfdiv span_staff_id">
        Info:
        <?php
        if(!empty($_SESSION['bonvoi_retail_auth'])) {
            echo $_SESSION['bonvoi_retail_auth']['staff_name'] . ' (' . $_SESSION['bonvoi_retail_auth']['shop_name'] . ')';

            echo '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="'.$page_url . '?process=logout'.'">Logout</a>';
        }

        if($_SESSION['bonvoi_retail_auth']['role'] == 'Retail Supervisor') {
            echo '<br/>';
            
            echo '<a href="'.$page_url .'">eSIM Plans</a>';
            echo '&nbsp;&nbsp;|&nbsp;&nbsp;';
            echo '<a href="'.$page_url . '?process=registration'.'">Registration</a>';
            echo '&nbsp;&nbsp;|&nbsp;&nbsp;';
            echo '<a href="'.$page_url . '?process=reporting'.'">Reporting</a>';
        }
        ?>
    </div>
    <?php
    $form_nonce = wp_create_nonce( 'wpautomationbonvoi_bv_new_retail_staff_nonce' );

    // echo '<form class="general_form_css" method="POST" action="'.admin_url('admin-post.php').'">';
        // echo '<input type="hidden" name="action" value="wpautomationbonvoi_bv_new_retail_staff_nonce" />';
        // echo '<input type="hidden" name="formnonce" class="formnonce" value="'.$form_nonce.'"/>';
    ?>

    <form class="" method="POST" action="<?php echo admin_url('admin-post.php'); ?>">
        <input type="hidden" name="action" value="wpautomationbonvoi_bv_new_retail_staff_nonce" />
        <input type="hidden" name="formnonce" class="formnonce" value="<?php echo $form_nonce; ?>"/>

        <input type="hidden" name="source_interface" value="frontend" />

        <div class="tpfdiv span_employee_code">
            <div class="tpflbl lbl_employee_code">Retail Shop *</div>
            <div class="div_employee_code">
                <?php
                echo '<select class="fullwidth" name="field[allstaff_shop_id]" required>';
                    echo '<option value="">Please Select...</option>';

                    for($i=0; $i<count($shop_arr); $i++) {
                        $selected = '';
                        
                        if(!empty($_SESSION['bonvoi_retail_auth']['shop_id'])) {
                            if($_SESSION['bonvoi_retail_auth']['shop_id'] == $shop_arr[$i]['id']) {
                                $selected = ' selected="selected"';
                            }
                        }
                        
                        echo '<option' . $selected . ' value="' . $shop_arr[$i]['id'] . '">' . $shop_arr[$i]['text'] . '</option>';
                    }
                echo '</select>';
                ?>
            </div>
        </div>

        <div class="tpfdiv span_passwd">
            <div class="tpflbl lbl_passwd">User Role *</div>
            <div class="div_passwd">
                <?php
                echo '<select class="fullwidth" name="field[allstaff_role_id]" required>';
                    echo '<option value="">Please Select...</option>';

                    for($i=0; $i<count($usr_role_arr); $i++) {
                        $selected = '';
                        
                        // if($setting_arr['active_session_min'] == $i) {
                        //     $selected = ' selected="selected"';
                        // }

                        echo '<option' . $selected . ' value="' . $usr_role_arr[$i]['id'] . '">' . $usr_role_arr[$i]['text'] . '</option>';
                    }
                echo '</select>';
                ?>
            </div>
        </div>

        <div class="tpfdiv span_passwd">
            <div class="tpflbl lbl_passwd">Staff Code/Employee Number *</div>
            <div class="div_passwd">
                <?php
                echo '<input class="fullwidth" type="text" name="field[allstaff_code]" value="'.$setting_arr['allstaff_code'].'" required />';
                ?>
            </div>
        </div>

        <div class="tpfdiv span_passwd">
            <div class="tpflbl lbl_passwd">Password *</div>
            <div class="div_passwd">
                <?php
                echo '<input class="fullwidth" type="password" name="field[front_passwd]" value="'.$setting_arr['front_passwd'].'" required />';
                ?>
            </div>
        </div>

        <div class="tpfdiv span_passwd">
            <div class="tpflbl lbl_passwd">Name *</div>
            <div class="div_passwd">
                <?php
                echo '<input class="fullwidth" type="text" name="field[allstaff_name]" value="'.$setting_arr['allstaff_name'].'" required />';
                ?>
            </div>
        </div>

        <div class="tpfdiv span_passwd">
            <div class="tpflbl lbl_passwd">Email</div>
            <div class="div_passwd">
                <?php
                echo '<input class="fullwidth" type="text" name="field[allstaff_email]" value="'.$setting_arr['allstaff_email'].'" />';
                ?>
            </div>
        </div>

        <div class="tpfdiv span_passwd">
            <div class="tpflbl lbl_passwd">Phone</div>
            <div class="div_passwd">
                <?php
                echo '<input class="fullwidth" type="text" name="field[allstaff_phone]" value="'.$setting_arr['allstaff_phone'].'" />';
                ?>
            </div>
        </div>

        <button type="submit" name="smt_btn" class="button alt">Register Now</button>
    </form>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
<script>
    jQuery(document).ready(function() {
        // no action
    });
</script>
<style>
    .through_cls {
        text-decoration: line-through;
    }
    .card_opt_display {
        display:none;
    }
    .topupform .highlinelink {
        color:#7dbae6;
        text-decoration: underline;
    }
    .topupform .loadgif {
        width:12px;
        margin-top:-2px;
        margin-left:5px;
    }
    .topupform .goodnews {
        background: #edfff8;
        border:1px solid #dbf4ea;
        padding:20px 20px;
        margin-bottom:10px;
    }
    .topupform .badnews {
        background: #ffeded;
        border:1px solid #f4dbdb;
        padding:20px 20px;
        margin-bottom:10px;
    }
    .topupform .tpfdiv {
        margin-bottom:20px;
    }
    .topupform .btn_esim {
        margin-bottom:20px;
    }
    .topupform input, .topupform select {
        width:100%;
    }
    .span_vouchermsg {
        display:none;
        color:red;
    }
    /*.span_region, .span_destination, .span_dataplan, .span_chkemail, .btn_paystripe {
        display:none;
    }*/
    .span_chkemail, .btn_paystripe, .span_agreementmsg {
        display:none;
    }
    .load_esim, .load_region, .load_destination, .load_dataplan, .load_paystripe {
        display:none;
    }
    .hidesupportinfoblock {
        display:none;
    }
    .card_text_hide {
        display:none;
    }
    .topupform .infoprice {
        /*margin-top: 30px;
        font-weight: bold;
        font-size: 24px;*/
        font-weight:bold;
        color:#4a86e8;
        font-size: 22px;
    }
    .topupform .woocommerce-Price-amount, .topupform .woocommerce-Price-currencySymbol {
        font-size: 19px !important;
    }
    .topupform .infodesc {
        margin-top:5px;
    }
</style>