<?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 campaign-overview-pnl">
    <div class="panel-heading">
        <div class="pull-left">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-envelope"></span> <?php echo Yii::t('campaigns', 'Overview');?>
            </h3>
        </div>
        <div class="pull-right">
            <?php echo CHtml::link(Yii::t('app', 'Create new'), array('campaigns/create'), array('class' => 'btn btn-default btn-xs', 'title' => Yii::t('app', 'New')));?>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
    <div class="panel-body">
        
        <div class="table-responsive">
        <?php
        $this->widget('zii.widgets.CDetailView', array(
            'data'      => $campaign,
            'cssFile'   => false,
            
            'htmlOptions' => array(
                'class' => 'table table-striped table-bordered table-hover table-condensed'
            ),
            
            'attributes' => array(
                'name',
                
                array(
                    'label' => Yii::t('campaigns', 'List name'),
                    'value' => $campaign->list->name . ' ('.$campaign->stats->getListSubscribers(true).' subscribers)',
                ),
                
                array(
                    'label' => Yii::t('campaigns', 'Segment name'),
                    'value' => empty($campaign->segment) ? '-' : $campaign->segment->name . ' ('.$campaign->stats->getSegmentSubscribers(true).' subscribers)',
                ),
                
                'from_name', 'from_email', 'reply_to', 'to_name', 'subject',
                
                array(
                    'label' => $campaign->getAttributeLabel('date_added'),
                    'value' => $campaign->dateAdded,
                ),
                
                array(
                    'label' => $campaign->getAttributeLabel('send_at'),
                    'value' => $campaign->sendAt,
                ),
                
                array(
                    'label' => $campaign->getAttributeLabel('lastOpen'),
                    'value' => $campaign->lastOpen,
                ),
                
                array(
                    'label' => Yii::t('campaigns', 'Web version'),
                    'value' => CHtml::link(Yii::t('app', 'View'), $webVersionUrl, array('target' => '_blank')),
                    'type'  => 'raw',
                ),
                
                array(
                    'label' => Yii::t('campaigns', 'Estimated completition rate'),
                    'value' => Yii::t('campaigns', '{percentage}% sent so far, that is {processed} out of {count}', array(
                        '{percentage}'  => $campaign->stats->getCompletitionRate(true),
                        '{processed}'   => $campaign->stats->getProcessedCount(true),
                        '{count}'       => $campaign->stats->getSubscribersCount(true),
                    )),
                    'visible'   => !empty($campaign->stats->completitionRate),
                ),
                
                array(
                    'label'     => Yii::t('campaigns', 'Estimated completition duration'),
                    'value'     => $campaign->stats->completitionDuration,
                    'visible'   => !empty($campaign->stats->completitionDuration),
                ),
            ),
        ));
        ?>
        </div>
        
        <hr />
        
        <div class="pull-left">
            <h4><?php echo Yii::t('campaigns', 'Tracking stats');?></h4>
        </div>
        <div class="pull-right">
            <a href="<?php echo $this->createUrl('campaign_reports_export/basic', array('campaign_uid' => $campaign->campaign_uid));?>" class="btn btn-primary btn-xs"><?php echo Yii::t('campaign_reports', 'Export basic stats');?></a>
        </div>
        
        <div class="clearfix"><!-- --></div>
        
        <?php 
        $this->renderPartial('stats/delivery');
        $this->renderPartial('stats/opens');
        
        if ($campaign->option->url_tracking == CampaignOption::TEXT_YES) {
            $this->renderPartial('stats/clicks');
        }
        
        $this->renderPartial('stats/bounces');
        $this->renderPartial('stats/unsubscribes');
        ?>

        <div class="clearfix"><!-- --></div>
        
        <?php
        $this->widget('customer.components.web.widgets.campaign-tracking.CampaignTrackingLatestClickedLinksWidget', array(
            'campaign' => $campaign
        ));
        
        $this->widget('customer.components.web.widgets.campaign-tracking.CampaignTrackingLatestOpensWidget', array(
            'campaign' => $campaign
        ));

        $this->widget('customer.components.web.widgets.campaign-tracking.CampaignTrackingTopClickedLinksWidget', array(
            'campaign' => $campaign
        ));
        
        $this->widget('customer.components.web.widgets.campaign-tracking.CampaignTrackingSubstribersWithMostOpensWidget', array(
            'campaign' => $campaign
        ));
        ?>
        
        <div class="clearfix"><!-- --></div>
        
        <?php 
            // hook available since version 1.2
            $hooks->doAction('customer_campaigns_overview_after_tracking_stats', $campaign);
        ?>
        
    </div>
</div>