<?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
 */
 
?>
    
<?php if(!$template->isNewRecord) { ?>
    <div class="pull-right">
        <a href="javascript:;" onclick="window.open('<?php echo $previewUrl;?>', '<?php echo Yii::t('email_templates',  'Preview');?>', 'height=600, width=600'); return false;" class="btn btn-default"><?php echo Yii::t('email_templates',  'Preview');?></a>
        <a data-toggle="modal" href="#template-test-email" class="btn btn-default"><?php echo Yii::t('email_templates',  'Send a test email using this template');?></a>
    </div>
    <div class="clearfix"><!-- --></div>
    <hr />
<?php } ?>
        
<?php $form = $this->beginWidget('CActiveForm'); ?>    
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title"> <span class="glyphicon glyphicon-text-width"></span> <?php echo Yii::t('email_templates',  'Templates');?> </h3>
    </div>
    <div class="panel-body">
        
        <div class="form-group col-lg-6">
            <?php echo $form->labelEx($template, 'name');?>
            <?php echo $form->textField($template, 'name', $template->getHtmlOptions('name')); ?>
            <?php echo $form->error($template, 'name');?>
        </div>
        
        <div class="form-group col-lg-6">
            <?php echo $form->labelEx($template, 'inline_css');?>
            <?php echo $form->dropDownList($template, 'inline_css', $template->getInlineCssArray(), $template->getHtmlOptions('inline_css')); ?>
            <?php echo $form->error($template, 'inline_css');?>
        </div>
        
        <div class="clearfix"><!-- --></div>
        <hr />
        
        <div class="form-group">
            <?php echo $form->labelEx($template, 'content');?>
            <?php echo $form->textArea($template, 'content', $template->getHtmlOptions('content', array('rows' => 15))); ?>
            <?php echo $form->error($template, 'content');?>
        </div>

    </div>
    <div class="panel-footer">
        <div class="pull-right">
            <button type="submit" class="btn btn-default btn-submit" data-loading-text="<?php echo Yii::t('app', 'Please wait, processing...');?>"><?php echo Yii::t('app', 'Save changes');?></button>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
    
</div>
<?php $this->endWidget(); ?>

<?php if(!$template->isNewRecord) { ?>
<div class="modal fade" id="template-test-email" tabindex="-1" role="dialog" aria-labelledby="template-test-email-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('email_templates',  'Send a test email');?></h4>
        </div>
        <div class="modal-body">
             <div class="callout">
                 <strong><?php echo Yii::t('app', 'Notes');?>: </strong><br />
                <?php 
                $text = '
                * if multiple recipients, separate the email addresses by a comma.<br />
                * the email tags will not be parsed while sending test emails.<br />
                * make sure you save the template changes before you send the test.';
                echo Yii::t('email_templates',  StringHelper::normalizeTranslationString($text));
                ?>
             </div>
             <?php echo CHtml::form(array('templates/test', 'template_uid' => $template->template_uid), 'post', array('id' => 'template-test-form'));?>
             <?php echo CHtml::textField('email', null, array('class' => 'form-control'));?>
             <?php CHtml::endForm();?>
        </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" onclick="$('#template-test-form').submit();"><?php echo Yii::t('email_templates',  'Send test');?></button>
        </div>
      </div>
    </div>
</div>
<?php } ?>