<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'supplier-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data'
    ),
));
?>

<div class="tab-content">
<div class="tab-pane active">

<ul class="clearfix form-ul material">

<?php echo $form->hiddenField($model,'id'); ?>

<li class="col-sm-12">
<label>Supplier Name</label>
<?php echo $form->textField($model,'supplier_name',array(
    'class'=>'form-control',
    'placeholder'=>'Enter Supplier Name'
)); ?>
</li>

<li class="col-sm-12">
<label>Phone</label>
<?php echo $form->textField($model,'phone_no',array(
    'class'=>'form-control',
    'placeholder'=>'Enter Phone Number'
)); ?>
</li>

<li class="col-sm-12">
<label>Email</label>
<?php echo $form->textField($model,'email',array(
    'class'=>'form-control',
    'placeholder'=>'Enter Email'
)); ?>
</li>

<li class="col-sm-12">
<label>Address</label>
<?php echo $form->textArea($model,'Address',array(
    'class'=>'form-control',
    'placeholder'=>'Enter Address'
)); ?>
</li>

<li class="col-sm-12">
<label>Location</label>

<?php
echo $form->dropDownList(
    $model,
    'location_id',
    CHtml::listData(
        Locations::model()->findAll(array(
            'condition'=>'isActive="Y"',
            'order'=>'location_name ASC'
        )),
        'id',
        'location_name'
    ),
    array(
        'class'=>'form-control',
        'prompt'=>'Select Location'
    )
);
?>

</li>

<li class="col-sm-12">
<label>Country</label>

<?php
echo $form->dropDownList(
    $model,
    'country_id',
    CHtml::listData(
        Country::model()->findAll(array(
            'condition'=>'isActive="Y"',
            'order'=>'country_name ASC'
        )),
        'id',
        'country_name'
    ),
    array(
        'class'=>'form-control',
        'prompt'=>'Select Country',
        'id'=>'country_id'
    )
);
?>

</li>

<li class="col-sm-12">
<label>State</label>

<?php
echo $form->dropDownList(
    $model,
    'state_id',
    array(),
    array(
        'class'=>'form-control',
        'prompt'=>'Select State',
        'id'=>'state_id'
    )
);
?>

</li>

<li class="col-sm-12">
<label>Upload Image</label>

<input type="file" name="img_upload" class="form-control">

<?php if(!empty($model->img_upload)){ ?>

<br>

<img src="<?php echo Yii::app()->baseUrl.'/uploads/suppliers/'.$model->img_upload; ?>" width="80">

<?php } ?>

</li>

</ul>

</div>
</div>

<div class="modal-footer">

<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>

<button type="button" class="btn btn-primary" id="btn-save-supplier">
Save
</button>

</div>

<?php $this->endWidget(); ?>



<script>

$(document).ready(function(){

$("#country_id").change(function(){

    var country_id = $(this).val();

    if(country_id == ""){
        $("#state_id").html('<option value="">Select State</option>');
        return;
    }

    $.ajax({
        url: '<?php echo Yii::app()->createUrl("suppliers/getStates"); ?>',
        type: 'POST',
        data: {country_id: country_id},

        success: function(data){
            $("#state_id").html(data);
        },

        error: function(){
            $("#state_id").html('<option>Error loading states</option>');
        }

    });

});

});

</script>