<?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 $form = $this->beginWidget('CActiveForm', array(
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),
));?>
<div class="panel panel-default">
    <div class="panel-heading">
        <div class="pull-left">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-envelope"></span> <?php echo $pageHeading;?>
            </h3>
        </div>
        <div class="pull-right">
            <?php echo CHtml::link(Yii::t('app', 'Cancel'), array('campaigns/index'), array('class' => 'btn btn-default btn-xs', 'title' => Yii::t('app', 'Cancel')));?>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
    <div class="panel-body">
        
        <div class="form-group col-lg-3">
            <?php echo $form->labelEx($campaign, 'from_name');?>
            <?php echo $form->textField($campaign, 'from_name', $campaign->getHtmlOptions('from_name')); ?>
            <?php echo $form->error($campaign, 'from_name');?>
        </div>
        <div class="form-group col-lg-3">
            <?php echo $form->labelEx($campaign, 'from_email');?>
            <?php echo $form->textField($campaign, 'from_email', $campaign->getHtmlOptions('from_email')); ?>
            <?php echo $form->error($campaign, 'from_email');?>
        </div>
        <div class="form-group col-lg-3">
            <?php echo $form->labelEx($campaign, 'reply_to');?>
            <?php echo $form->textField($campaign, 'reply_to', $campaign->getHtmlOptions('reply_to')); ?>
            <?php echo $form->error($campaign, 'reply_to');?>
        </div>
        <div class="form-group col-lg-3">
            <?php echo $form->labelEx($campaign, 'to_name');?> [<a data-toggle="modal" href="#available-tags-modal"><?php echo Yii::t('campaigns', 'Available tags');?></a>]
            <?php echo $form->textField($campaign, 'to_name', $campaign->getHtmlOptions('to_name')); ?>
            <?php echo $form->error($campaign, 'to_name');?>
        </div>
        
        <div class="clearfix"><!-- --></div>
        
        <div class="form-group col-lg-12">
            <?php echo $form->labelEx($campaign, 'subject');?> [<a data-toggle="modal" href="#available-tags-modal"><?php echo Yii::t('campaigns', 'Available tags');?></a>]
            <?php echo $form->textField($campaign, 'subject', $campaign->getHtmlOptions('subject')); ?> 
            <?php echo $form->error($campaign, 'subject');?>
        </div>
              
        <div class="clearfix"><!-- --></div>

        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="pull-left">
                        <h3 class="panel-title">
                            <span class="glyphicon glyphicon-cog"></span> <?php echo Yii::t('campaigns', 'Campaign options');?>
                        </h3>
                    </div>
                    <div class="pull-right"></div>
                    <div class="clearfix"><!-- --></div>
                </div>
                <div class="panel-body">
                    <div class="form-group col-lg-2">
                        <?php echo $form->labelEx($campaign->option, 'url_tracking');?>
                        <?php echo $form->dropDownList($campaign->option, 'url_tracking', $campaign->option->getYesNoOptionsArray(), $campaign->option->getHtmlOptions('url_tracking')); ?>
                        <?php echo $form->error($campaign->option, 'url_tracking');?>
                    </div>
                    <div class="form-group col-lg-2">
                        <?php echo $form->labelEx($campaign->option, 'json_feed');?>
                        <?php echo $form->dropDownList($campaign->option, 'json_feed', $campaign->option->getYesNoOptionsArray(), $campaign->option->getHtmlOptions('json_feed')); ?>
                        <?php echo $form->error($campaign->option, 'json_feed');?>
                    </div>
                    <div class="form-group col-lg-2">
                        <?php echo $form->labelEx($campaign->option, 'xml_feed');?>
                        <?php echo $form->dropDownList($campaign->option, 'xml_feed', $campaign->option->getYesNoOptionsArray(), $campaign->option->getHtmlOptions('xml_feed')); ?>
                        <?php echo $form->error($campaign->option, 'xml_feed');?>
                    </div>
                    <div class="form-group col-lg-2">
                        <?php echo $form->labelEx($campaign->option, 'plain_text_email');?>
                        <?php echo $form->dropDownList($campaign->option, 'plain_text_email', $campaign->option->getYesNoOptionsArray(), $campaign->option->getHtmlOptions('plain_text_email')); ?>
                        <?php echo $form->error($campaign->option, 'plain_text_email');?>
                    </div>
                    <div class="form-group col-lg-4">
                        <?php echo $form->labelEx($campaign->option, 'email_stats');?>
                        <?php echo $form->textField($campaign->option, 'email_stats', $campaign->option->getHtmlOptions('email_stats')); ?>
                        <?php echo $form->error($campaign->option, 'email_stats');?>
                    </div>    
                </div>
            </div>
        </div>
        <div class="clearfix"><!-- --></div> 
        
        <?php if (Yii::app()->options->get('system.campaign.campaign_options.customer_select_delivery_servers', 'no') == 'yes') { ?>
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="pull-left">
                        <h3 class="panel-title">
                            <span class="glyphicon glyphicon-send"></span> <?php echo Yii::t('campaigns', 'Campaign delivery servers');?>
                        </h3>
                    </div>
                    <div class="pull-right"></div>
                    <div class="clearfix"><!-- --></div>
                </div>
                <div class="panel-body panel-delivery-servers-pool">
                    <div class="callout">
                        <?php echo Yii::t('campaigns', 'Select which delivery servers are used for this campaign, if no option is selected, all the available servers will be used.');?>
                    </div>
                    <?php foreach ($deliveryServers as $server) { ?>
                        <div class="form-group col-lg-4">
                            <div class="item">
                                <?php echo CHtml::checkBox($campaignToDeliveryServers->modelName.'[]', in_array($server->server_id, $campaignDeliveryServersArray), array('value' => $server->server_id));?>
                                <?php echo $server->hostname;?>
                            </div>
                        </div>
                    <?php } ?>    
                </div>
            </div>
        </div>
        <div class="clearfix"><!-- --></div> 
        <?php } ?>
        
        <?php if (Yii::app()->options->get('system.campaign.attachments.enabled', 'no') == 'yes') { ?>
        <div class="col-lg-12">
            <div class="panel panel-default panel-campaign-attachments">
                <div class="panel-heading">
                    <div class="pull-left">
                        <h3 class="panel-title">
                            <span class="glyphicon glyphicon-upload"></span> <?php echo Yii::t('campaigns', 'Campaign attachments');?>
                        </h3>
                    </div>
                    <div class="pull-right"></div>
                    <div class="clearfix"><!-- --></div>
                </div>
                <div class="panel-body">
                    <div class="callout">
                        <?php echo Yii::t('campaigns', 'You are allowed to upload up to {maxCount} attachments. Each attachment size must be lower than {maxSize}.', array(
                            '{maxCount}' => $attachment->getAllowedFilesCount(),
                            '{maxSize}'  => ($attachment->getAllowedFileSize() / 1024 / 1024) . ' mb'
                        )); ?>
                        <br />
                        <?php echo Yii::t('campaigns', 'Following file types are allowed for upload: {types}', array(
                            '{types}' => implode(', ', $attachment->getAllowedExtensions()),
                        ));?>
                    </div>
                    <?php
                      $this->widget('CMultiFileUpload', array(
                         'model'        => $attachment,
                         'attribute'    => 'file',
                         'max'          => $attachment->getAllowedFilesCount(),
                      ));
                    ?>
                    <?php if (!empty($campaign->attachments)) { ?>
                    <h5><?php echo Yii::t('campaigns', 'Uploaded files for this campaign:');?></h5>
                    <?php foreach ($campaign->attachments as $file) { ?>
                        <div class="form-group col-lg-4">
                            <div class="item">
                                <a href="<?php echo $this->createUrl('campaigns/remove_attachment', array('campaign_uid' => $campaign->campaign_uid, 'attachment_id' => $file->attachment_id));?>" class="btn btn-xs btn-danger btn-remove-attachment" data-message="<?php echo Yii::t('campaigns', 'Are you sure you want to remove this attachment?');?>">x</a>
                                <?php echo $file->name;?>
                            </div>
                        </div>
                    <?php } ?>  
                    <?php } ?>
                </div>
            </div>
        </div>
        <div class="clearfix"><!-- --></div> 
        <?php } ?>
                   
    </div>
    <div class="panel-footer">
        <div class="wizard">
            <ul class="steps">
                <li class="complete"><a href="<?php echo $this->createUrl('campaigns/update', array('campaign_uid' => $campaign->campaign_uid));?>"><?php echo Yii::t('campaigns', 'Name &amp; recipients');?></a><span class="chevron"></span></li>
                <li class="active"><a href="<?php echo $this->createUrl('campaigns/setup', array('campaign_uid' => $campaign->campaign_uid));?>"><?php echo Yii::t('campaigns', 'Setup');?></a><span class="chevron"></span></li>
                <li><a href="<?php echo $this->createUrl('campaigns/template', array('campaign_uid' => $campaign->campaign_uid));?>"><?php echo Yii::t('campaigns', 'Template');?></a><span class="chevron"></span></li>
                <li><a href="<?php echo $this->createUrl('campaigns/confirm', array('campaign_uid' => $campaign->campaign_uid));?>"><?php echo Yii::t('campaigns', 'Confirmation');?></a><span class="chevron"></span></li>
                <li><a href="javascript:;"><?php echo Yii::t('app', 'Done');?></a><span class="chevron"></span></li>
            </ul>
            <div class="actions">
                <button type="submit" id="is_next" name="is_next" value="1" class="btn btn-default btn-submit btn-go-next" data-loading-text="<?php echo Yii::t('app', 'Please wait, processing...');?>"><?php echo Yii::t('campaigns', 'Save and next');?></button>
            </div>
        </div>
    </div>
</div>    
<?php $this->endWidget();?>

<div class="modal fade" id="available-tags-modal" tabindex="-1" role="dialog" aria-labelledby="available-tags-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('lists', 'Available tags');?></h4>
        </div>
        <div class="modal-body" style="max-height: 300px; overflow-y:scroll;">
            <table class="table table-bordered table-hover table-striped">
                <tr>
                    <td><?php echo Yii::t('lists', 'Tag');?></td>
                    <td><?php echo Yii::t('lists', 'Required');?></td>
                </tr>
                <?php foreach ($campaign->getSubjectToNameAvailableTags() as $tag) { ?>
                <tr>
                    <td><?php echo CHtml::encode($tag['tag']);?></td>
                    <td><?php echo $tag['required'] ? strtoupper(Yii::t('app', Campaign::TEXT_YES)) : strtoupper(Yii::t('app', Campaign::TEXT_NO));?></td>
                </tr>
                <?php } ?>
            </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo Yii::t('app', 'Close');?></button>
        </div>
      </div>
    </div>
</div>