<?php 
    $vError = isset($validation_error) && !empty($validation_error) ? $validation_error : array();
    $vSaved = isset($saved_data) && !empty($saved_data) ? $saved_data : array();
    $vPosted = array();
    $bkashErrorCode = isset($bkashErrorCode) && !empty($bkashErrorCode) ? $bkashErrorCode : array();
    if(!empty(set_value('bkashusername'))){
        $vPosted['bkashusername'] = set_value('bkashusername');
    }
    if(!empty(set_value('bkashpassword'))){
        $vPosted['bkashpassword'] = set_value('bkashpassword');
    }
    if(!empty(set_value('bkrskey'))){
        $vPosted['bkrskey'] = set_value('bkrskey');
    }
    if(!empty(set_value('bkashmerchant'))){
        $vPosted['bkashmerchant'] = set_value('bkashmerchant');
    }
    if(!empty(set_value('bkashqrcode'))){
        $vPosted['bkashqrcode'] = '';
    }
    if(!empty(set_value('bkashcharge'))){
        $vPosted['bkashcharge'] = set_value('bkashcharge');
    }
    foreach($bkashErrorCode AS $bk => $bv) {
        if(!empty(set_value('bkasherror'.$bk))){
            $vPosted['bkasherror'.$bk] = set_value('bkasherror'.$bk);
        }
    }
    $vDefault = array_merge($vSaved, $vPosted);
?>
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                  bKash Settings
                </h2>
            </div>
            <div class="body">
                <?php echo form_open_multipart('lbadmin/bkash', array("id"=>"bkashSettingsForm") ); ?>
                    <?php if(isset($upload_error) && count($upload_error)>0) : ?>
                    <?php foreach($upload_error as $upError) : ?>
                    <div class="alert alert-danger alert-dismissible" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                        <?php echo $upError ?>
                    </div>  
                    <?php endforeach; ?>
                    <?php endif;?>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkashusername">API Username</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <input type="text" value="<?php echo getValue('bkashusername', $vDefault) ?>" name="bkashusername" id="bkashusername" class="form-control" placeholder="Your bKash API Username" required>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkashpassword">API Password</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                 <input type="text" value="<?php echo getValue('bkashpassword', $vDefault) ?>" name="bkashpassword" id="bkashpassword" class="form-control" placeholder="Your bKash API password" required>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkrskey">Gateway Key</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" value="<?php echo getValue('bkrskey', $vDefault) ?>" name="bkrskey" id="bkrskey" class="form-control" placeholder="Enter Resell.Biz 32 bit secure key" required>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkashmerchant">Merchant Number</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" value="<?php echo getValue('bkashmerchant', $vDefault) ?>" name="bkashmerchant" id="bkashmerchant" class="form-control" placeholder="Enter your bKash Merchant mobile number" required>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkashqrcode">App Qr Code</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <input type="text" id="bkashqrcode" value="<?php echo getValue('bkashqrcode', $vDefault) ?>" class="form-control file-path" placeholder="Select Your bKash Qr Code file" readonly>  
                                <div>
                                <img src="<?php echo base_url('images/'.(!empty($vDefault['bkashqrcode'])?$vDefault['bkashqrcode']:'defaultsquare.png') ) ?>" width="150" height="150" id="bkashqrcodepreview" class="img-thumbnail m-t-5" alt="<?php echo !empty($vDefault['bkashqrcode'])?$vDefault['bkashqrcode']:'defaultsquare.png' ?>"<?php echo !empty($vDefault['bkashqrcode'])?' acl-actual="'.$vDefault['bkashqrcode'].'"':'' ?> acl-default="defaultsquare.png">
                                </div>
                                <div class="m-t-5 acl-file-input">
                                    <div class="file-field btn btn-default btn-sm">
                                        <span><?php echo !empty($vDefault['bkashqrcode'])?'Change':'Choose file' ?></span>
                                        <input class="aclimageupload_input" name="bkashqrcode" for="bkashqrcode" type="file" accept="image/jpeg,image/png">
                                    </div>
                                    <?php if(!empty($vDefault['bkashqrcode'])) : ?>
                                    <button type="button" acl-target="bkashqrcode" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Loading.." class="btn btn-danger btn-sm removeConfigImage">Remove</button>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkashcharge">Bkash Charge (Percentage)</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <div class="input-group spinner m-b-0" data-trigger="spinner">
                                    <input type="text" value="<?php echo getValue('bkashcharge', $vDefault) ?>" name="bkashcharge" id="bkashcharge" class="form-control" value="1" data-rule="currency">
                                    <span class="input-group-addon">
                                        <a href="javascript:;" class="spin-up" data-spin="up"><i class="glyphicon glyphicon-chevron-up"></i></a>
                                        <a href="javascript:;" class="spin-down" data-spin="down"><i class="glyphicon glyphicon-chevron-down"></i></a>
                                    </span>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="row clearfix">
                        <div class="col-md-12 m-b-15"><div class="acl-form-header">ERROR CODES</div></div>   
                    </div>
                    <?php foreach($bkashErrorCode as $bCode => $bVal) : ?>
                    <div class="row clearfix">
                        <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                            <label for="bkasherror<?php echo $bCode ?>">Error (<?php echo $bVal['c'] ?>)</label>
                        </div>
                        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" value="<?php echo getValue('bkasherror'.$bCode, $vDefault) ?>" name="bkasherror<?php echo $bCode ?>" id="bkasherror<?php echo $bCode ?>" class="form-control" placeholder="<?php echo $bVal['t'] ?>">
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                    <div class="row clearfix">
                        <div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-4 col-xs-offset-0">
                            <button type="submit" class="btn btn-success m-l-15 waves-effect">Save Changes</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
var bkashSettingsError = <?php echo json_encode($vError) ?>;
var success = <?php echo isset($savesuccess)?($savesuccess?'true':'false'):'false' ?>;
</script>