<?php
$vError = isset($validation_error) && !empty($validation_error) ? $validation_error : array();
$vSaved = isset($saved_data) && !empty($saved_data) ? $saved_data : array();
$vUrl = isset($edit_url) ? $edit_url : 'lbadmin/currency/add';
$vPosted = array();
if(!empty(set_value('currencycode'))){
    $vPosted['currencycode'] = set_value('currencycode');
}
if(!empty(set_value('currencyrate'))){
    $vPosted['currencyrate'] = set_value('currencyrate');
}
$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>
                    <?php echo !empty($vSaved) ? "Edit" : "Add" ?> Currency
                </h2>
            </div>
            <div class="body">
                <?php echo form_open_multipart($vUrl, array("id"=>"currencyAddForm") ); ?>
                <div class="row clearfix">
                    <div class="col-lg-2 col-md-2 col-sm-4 col-xs-12 form-control-label">
                        <label for="currencycode">Currency</label>
                    </div>
                    <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
                        <div class="form-group">
                            <?php if(!empty($vSaved)) : ?>
                                <input type="text" value="<?php echo $this->currency_model->currencyLib(true, getValue('currencycode', $vDefault)) ?>" id="currencycode" class="form-control" placeholder="Enter Currency Code" readonly>
                                <input type="hidden" value="<?php echo getValue('currencycode', $vDefault) ?>" name="currencycode">
                            <?php else: ?>
                                <select name="currencycode" id="currencycode" class="form-control" required>
                                    <option value="">Select Currency</option>
                                    <?php $currencies = $this->currency_model->currencyLib() ?>
                                    <?php foreach ( $currencies AS $key => $value ) : ?>
                                        <option value="<?php echo $key ?>"><?php echo $value ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php endif; ?>

                        </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="currencyrate">Rate in BDT</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('currencyrate', $vDefault) ?>" name="currencyrate" id="currencyrate" class="form-control" placeholder="Currency Rate in BDT" required>
                        </div>
                    </div>
                </div>
                <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</button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var currencyError = <?php echo json_encode($vError) ?>;
</script>
