<?php
$cs = Yii::app()->getClientScript();

$cs->registerScript("downloadgmc_format", "function downloadgmc_format(header_id){
    var url = $('#liveSite').val() + 'index.php?r=hiddengmcuploads/DownloadGmcFormat&header_id=' + header_id;
    window.open(url);

        //window.open($('#liveSite').val()+'index.php?r=hiddengmcuploads/DownloadGmcFormat');   
    
}", CClientScript::POS_HEAD);

?><?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'hiddengmc_upload-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
));
?>
<div class="tab-content">
    <div class="tab-pane active">
        <ul class="clearfix form-ul material">
            <?php echo $form->hiddenField($model, 'id'); ?>
            <?php 
            $model->distributer_type_id =$header_id;
            echo $form->hiddenField($model, 'distributer_type_id'); ?>
            <li class="col-sm-4">
                 <?php $model->upload_date = date('d/m/Y');?>
                <?php echo $form->textField($model, 'upload_date', array('data-label' => 'Uploaded Date <span style="color:red">*</span>', 'empty'=>'-Select-')); ?>
            </li>
            <li  class="col-sm-4">
            <button type="button"  class="btn btn-sm btn-theme" onclick="downloadgmc_format(<?php echo $header_id; ?>);"><i class="fa fa-download"></i>CSV FORMAT</button>
            </li>
            <li  class="col-sm-4">
                <?php
                echo CHtml::label('Document', 'Document');
                $allowedExtensions = array("csv");
                $this->widget('ext.EAjaxUpload.EAjaxUpload', array('id' => rand(),
                    'config' => array('action' => Yii::app()->createUrl(Yii::app()->controller->id . '/UploadDocuments', array('folder' => 'upload/hiddengmc')),
                        'multiple' => false, 
                        'allowedExtensions' => $allowedExtensions,
                        'sizeLimit' => 1 * 1024 * 1024, 
                        'onStart' => "js:function(){}", 
                        'class' => 'pull-right', 
                        'onComplete' => "js:function(id, fileName, responseJSON){ 
                           console.log(fileName);
                        $('.icon_images').html('<input type=\"hidden\" value=\"'+responseJSON.filename+'\" name=\"HiddenGmcUploads[file_name]\">');                                                                    "
                        . "}",)));
                ?>        
                <div class="icon_images">
                
                </div>
            </li>
        </ul>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="hiddengmc_upload_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('hiddengmcuploads/SaveGMCUpload');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("GMC Upload Saved Successfully!");
                    $("#hiddengmc_upload_close").click();
                    reloadTable("#tbl_inventory_details");
                } else { 
                    $("#hiddengmc_upload-form .hiddengmc_upload-save-btn").prop("disabled", false);                      
                    $("#hiddengmc_upload-form .hiddengmc_upload-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#hiddengmc_upload-form .hiddengmc_upload-save-btn").prop("disabled", true);                      
            $("#hiddengmc_upload-form .hiddengmc_upload-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

        }'
    ), array('id' => 'mybtn' . rand(), 'class' => 'hiddengmc_upload-save-btn btn btn-theme'));
    ?>
</div>
<?php $this->endWidget(); ?>