<?php defined('MW_PATH') || exit('No direct script access allowed');

/**
 * This file is part of the MailWizz EMA application.
 * 
 * @package MailWizz EMA
 * @author Serban George Cristian <cristian.serban@mailwizz.com> 
 * @link http://www.mailwizz.com/
 * @copyright 2013-2014 MailWizz EMA (http://www.mailwizz.com)
 * @license http://www.mailwizz.com/license/
 * @since 1.0
 */
 
?>

<div class="panel panel-default">
    <div class="panel-heading">
        <div class="pull-left">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-list-alt"></span> <?php echo Yii::t('list_import', 'Import options');?>
            </h3>
        </div>
        <div class="pull-right">
            <?php echo CHtml::link(Yii::t('app', 'Cancel'), array('lists/overview', 'list_uid' => $list->list_uid), array('class' => 'btn btn-default btn-xs', 'title' => Yii::t('app', 'Cancel')));?>
            <?php echo CHtml::link(Yii::t('app', 'Refresh'), array('list_import/index', 'list_uid' => $list->list_uid), array('class' => 'btn btn-default btn-xs', 'title' => Yii::t('app', 'Refresh')));?>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
    <div class="panel-body">
        
        <div class="panel panel-default panel-template-box">
            <div class="panel-heading"><h3 class="panel-title"><?php echo Yii::t('list_import', 'Import from CSV');?></h3></div>
            <div class="panel-body">
                <?php echo Yii::t('list_import', 'Easily select a CSV file and start importing existing subscribers into your list.');?>
            </div>
            <div class="panel-footer">
                <div class="pull-left">
                    <a href="#csv-upload-modal" data-toggle="modal" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-import"></span> <?php echo Yii::t('list_import', 'Select file to import');?></a>
                </div>
                <div class="clearfix"><!-- --></div>
            </div>
        </div>

    </div>
    <div class="panel-footer"></div>
</div>

<div class="modal fade" id="csv-upload-modal" tabindex="-1" role="dialog" aria-labelledby="csv-upload-modal-label" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title"><?php echo Yii::t('list_import', 'Import from CSV file');?></h4>
        </div>
        <div class="modal-body">
             <div class="callout">
                <?php 
                $text = 'Please note, we only accept valid CSV files that contain a header, that is the column names for the data to be imported.<br />
                 We also have a limit on the file size you are allowed to upload, that is {uploadLimit}.<br />
                 The import process might fail with some of the files, mainly because these are not correctly formatted or they contain invalid data.<br />
                 You should first do a test import(in a test list) and see if that goes as planned then do it for your actual list.<br />
                 <strong>Important</strong>: The CSV file column names will be used to create the list TAGS, if a tag does not exist, it will be created.<br />
                 You can also click <a href="{exampleArchiveHref}" target="_blank">here</a> to see a csv file example.';
                echo Yii::t('list_import', StringHelper::normalizeTranslationString($text), array(
                    '{uploadLimit}'         => $maxUploadSize . 'MB',
                    '{exampleArchiveHref}'  => Yii::app()->apps->getAppUrl('customer', 'assets/files/example-csv-import.csv', false, true),
                ));
                ?>
             </div>
            <?php 
            $form = $this->beginWidget('CActiveForm', array(
                'action'        => array('list_import/csv', 'list_uid' => $list->list_uid),
                'htmlOptions'   => array(
                    'id'        => 'upload-csv-form', 
                    'enctype'   => 'multipart/form-data'
                ),
            ));
            ?>
            <div class="form-group">
                <?php echo $form->labelEx($importCsv, 'file');?>
                <?php echo $form->fileField($importCsv, 'file', $importCsv->getHtmlOptions('file')); ?>
                <?php echo $form->error($importCsv, 'file');?>
            </div>
            <?php $this->endWidget(); ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo Yii::t('app', 'Close');?></button>
          <button type="button" class="btn btn-primary btn-submit" data-loading-text="<?php echo Yii::t('app', 'Please wait, processing...');?>" onclick="$('#upload-csv-form').submit();">Upload file</button>
        </div>
      </div>
    </div>
</div>