<?php
//bv_shop_id, bv_shop_name, bv_shop_email, bv_shop_phone

$setting_arr = array();

$setting_arr['bv_shop_id'] = '';
$setting_arr['bv_shop_name'] = '';
$setting_arr['bv_shop_email'] = '';
$setting_arr['bv_shop_phone'] = '';

// Get Form data - if not exist, then show error
$qry_info = "SELECT * FROM " . $wpdb->prefix . "bonvoi_shops WHERE bv_shop_id='" . $get_id . "'";
$rs_info = $wpdb->get_row($qry_info, ARRAY_A);
$rs_info_count = $wpdb->num_rows;

if($rs_info > 0) {
    $setting_arr['bv_shop_id'] = $rs_info['bv_shop_id'];
    $setting_arr['bv_shop_name'] = $rs_info['bv_shop_name'];
    $setting_arr['bv_shop_email'] = $rs_info['bv_shop_email'];
    $setting_arr['bv_shop_phone'] = $rs_info['bv_shop_phone'];
}
else {
    $redirectstatus = 'failed';
    $redirectmsg = 'Not Able To Detect Shop ID. Please Try Again. Thanks';
}

if($redirectstatus == "success") {
    echo '<div class="wpcompleteautomatc_msgbox_success">';
        echo $redirectmsg;
    echo '</div>';
}
else if ($redirectstatus == "failed") {
    echo '<div class="wpcompleteautomatc_msgbox_error">';
        echo $redirectmsg;
    echo '</div>';
}

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

// $active_arr = array(
//     '0' => array('id'=>'0', 'text'=>'No'),
//     '1' => array('id'=>'1', 'text'=>'Yes')
// );

// $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;
//     }
// }

// $qry_settings = "SELECT * FROM " . $wpdb->prefix . "bonvoi_settings";
// $rs_settings = $wpdb->get_results($qry_settings, ARRAY_A);

// if($rs_settings) {
//     foreach($rs_settings as $rs_setting) {
//         $setting_arr[$rs_setting['bv_setting_name']] = $rs_setting['bv_setting_val'];
//     }
// }

// echo '<pre>';
// echo $get_id . '<br/>';
// print_r($setting_arr);
// print_r($shop_arr);
// print_r($usr_role_arr);
// echo '</pre>';

// $qry_pagi = "SELECT COUNT(pro_id) AS ttl_pagi FROM " . $wpdb->prefix . "automatc_shopee_products";
// $rs_pagi = $wpdb->get_row($qry_pagi, ARRAY_A);

// $pagi_ttl = (int)$rs_pagi['ttl_pagi'];
// $pagi_limit = 10;
// $pagi_start = ((int)$num - 1) * $pagi_limit;
// $pagi_loop = ceil($pagi_ttl/$pagi_limit);

echo '<div class="wpcompleteautomatc_body">';

    echo '<h1>Update Retail Shop Info</h1><br/>';

    echo '<div class="wpcompleteautomatc_top_panel">';
        // echo '<a href="#" class="wpcompleteautomatc_func_btn delete_btn">Delete Selected Items</a>';
        echo '<a href="'.admin_url('admin.php?page=wpautomationbonvoi_retail_shops').'" class="wpcompleteautomatc_btn">Back to Dashboard</a>';
        //echo '<a href="#" class="wpcompleteautomatc_btn">Sync Shopee Products</a>';
    echo '</div><br/>';

    // wpautomationbonvoi_bv_new_retail_shops_form - wpautomationbonvoi_bv_new_retail_shop_nonce
    // wpautomationbonvoi_bv_update_retail_shops_form - wpautomationbonvoi_bv_update_retail_shop_nonce
    // wpautomationbonvoi_bv_delete_retail_shops_form - wpautomationbonvoi_bv_delete_retail_shop_nonce

    echo '<div class="wpcompleteautomatc_form_panel">';
        $form_nonce = wp_create_nonce( 'wpautomationbonvoi_bv_update_retail_shop_nonce' );

        echo '<form class="general_form_css" method="POST" action="'.admin_url('admin-post.php').'">';
            echo '<input type="hidden" name="action" value="wpautomationbonvoi_bv_update_retail_shop_nonce" />';
            echo '<input type="hidden" name="formnonce" class="formnonce" value="'.$form_nonce.'"/>';
            echo '<input type="hidden" name="field[bv_shop_id]" class="tempt_ids" value="'.$setting_arr['bv_shop_id'].'"/>';

            echo '<div class="form_fields">';
                echo '<div class="form_lbl">Password</div>';
                echo '<div class="form_text">';
                    echo '<input class="fullwidth" type="text" name="field[bv_shop_name]" value="'.$setting_arr['bv_shop_name'].'" />';
                echo '</div>';
            echo '</div>';

            echo '<div class="form_fields">';
                echo '<div class="form_lbl">Name *</div>';
                echo '<div class="form_text">';
                    echo '<input class="fullwidth" type="text" name="field[bv_shop_email]" value="'.$setting_arr['bv_shop_email'].'" required />';
                echo '</div>';
            echo '</div>';

            echo '<div class="form_fields">';
                echo '<div class="form_lbl">Email</div>';
                echo '<div class="form_text">';
                    echo '<input class="fullwidth" type="text" name="field[bv_shop_phone]" value="'.$setting_arr['bv_shop_phone'].'" />';
                echo '</div>';
            echo '</div>';

            //////////////////////////

            echo '<div class="form_fields" style="padding-top:0px;">';
                echo '<input class="wpcompleteautomatc_clean_btn" type="submit" name="smt_btn" value="Update Now" />';
            echo '</div>';
        echo '</form>';
        
    echo '</div>';

echo '</div>';
?>

<script>
    jQuery(document).ready(function($) {
        
    });
</script>

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

    .wpcompleteautomatc_msgbox_error {
        padding:30px 30px;
        margin:20px 20px;
    }

    .wpcompleteautomatc_body {
        margin:20px 20px;
    }
}

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

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

    .wpcompleteautomatc_body {
        margin:20px 10px;
    }
}

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

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

    .wpcompleteautomatc_body {
        margin:20px 10px;
    }
}

.wpcompleteautomatc_form_panel {

}

.general_form_css {
    
}

.form_fields {
    padding-bottom:15px;
}

.form_lbl {
    font-weight: bold;
    padding-bottom:5px;
}

.form_text {
    
}

.form_text input.fullwidth, .form_text textarea.fullwidth, .form_text select.fullwidth {
    width:100% !important;
    max-width:100% !important;
    padding:10px 15px;
}

.form_text input.fullwidth_short, .form_text textarea.fullwidth_short, .form_text select.fullwidth_short {
    /*width:100% !important;
    max-width:100% !important;*/
    padding:10px 15px;
}

.form_text select.fullwidth {
    height: auto !important;
}

.form_text textarea.fullwidth {
    height:200px;
}

.form_text input.fullwidth[type="file"] {
    padding:10px 15px !important;
    border: 1px solid #c3c3c4;
    background-color: rgba(255,255,255,1.0);
    width:auto;
}

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

.wpcompleteautomatc_msgbox_error {
    background:#fff2f2;
    border:1px solid #f4dbdb;
}

.wpcompleteautomatc_body {
    
}

.wpcompleteautomatc_top_panel {
    margin-bottom: 10px;
}

.wpcompleteautomatc_btn {
    padding:10px 20px;
    color:#ffffff !important;
    background:#786890;
    text-decoration: none;
    margin-right:10px;
    margin-bottom:10px;
    border: none;
    cursor: pointer;
}

.wpcompleteautomatc_btn:hover {
    background:#665580;
}

.wpcompleteautomatc_func_btn {
    padding:10px 20px;
    color:#ffffff !important;
    background:#6a937c;
    text-decoration: none;
    margin-right:10px;
    margin-bottom:10px;
}

.wpcompleteautomatc_func_btn:hover {
    background:#3f7d5b;
}

.wpcompleteautomatc_actions {
    margin-right:10px;
    margin-bottom:5px;
    margin-top:5px;
    text-decoration: none;
}

.wpcompleteautomatc_table_panel {
    overflow: auto;
}

.wpcompleteautomatc_table {
    border-collapse: collapse;
}

.wpcompleteautomatc_table tr {
    border-collapse: collapse;
}

.wpcompleteautomatc_table td {
    border-collapse: collapse;
    border:1px solid #c9cdd2;
    padding:10px 20px;
}

.wpcompleteautomatc_table tr.even td {
    background:#f5f7fa;
}

.wpcompleteautomatc_table tr.odd td {
    background:#e8ebf1;
}

.wpcompleteautomatc_table tr.title td {
    background:#afbaca;
    color:#fff;
}

.wpcompleteautomatc_table td.actions {
    
}

.wpcompleteautomatc_table tr.header {

}

.wpcompleteautomatc_table tr.header td {
    border:1px solid #c2ccd9;
    background: #e0e5ec;
    font-weight: bold;
}

.wpcompleteautomatc_pagi {
    margin-top:20px;
    margin-bottom: 10px;
}

.wpcompleteautomatc_pages {
    padding:10px 20px;
    color:#ffffff !important;
    background:#bcbcbc;
    text-decoration: none;
    margin-right:10px;
    margin-bottom:10px;
}

.wpcompleteautomatc_pages:hover {
    background:#a0a0a0;
}

.wpcompleteautomatc_actv {
    background:#786890;
}

.wpcompleteautomatc_actv:hover {
    background:#665580;
}
</style>