<?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
 */

/**
 * This hook gives a chance to prepend content or to replace the default view content with a custom content.
 * Please note that from inside the action callback you can access all the controller view
 * variables via {@CAttributeCollection $collection->controller->data}
 * In case the content is replaced, make sure to set {@CAttributeCollection $collection->renderContent} to false 
 * in order to stop rendering the default content.
 * @since 1.3.3.1
 */
$hooks->doAction('before_view_file_content', $viewCollection = new CAttributeCollection(array(
    'controller'    => $this,
    'renderContent' => true,
)));

// and render if allowed
if ($viewCollection->renderContent) { ?>
    <div class="box box-primary campaign-overview-pnl">
        <div class="box-header">
            <div class="pull-left">
                <h3 class="box-title">
                    <span class="glyphicon glyphicon-envelope"></span> <?php echo $pageHeading;?>
                </h3>
            </div>
            <div class="pull-right">
                <?php echo CHtml::link(Yii::t('app', 'Create new'), array('campaigns/create'), array('class' => 'btn btn-primary btn-xs', 'title' => Yii::t('app', 'New')));?>
            </div>
            <div class="clearfix"><!-- --></div>
        </div>
        <div class="box-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', 'Type'),
                        'value' => ucfirst(Yii::t('campaigns', $campaign->type)),
                    ),
                    array(
                        'label' => Yii::t('campaigns', 'List/Segment'),
                        'value' => $campaign->getListSegmentName(),
                    ),
                    '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,
                        'visible'   => $campaign->isRegular,
                    ),
                    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', 'Forwards'),
                        'value' => CHtml::link($campaign->countForwards(), array('campaign_reports/forward_friend', 'campaign_uid' => $campaign->campaign_uid)),
                        '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'   => $campaign->isRegular && !empty($campaign->stats->completitionRate),
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Estimated completition duration'),
                        'value'     => $campaign->stats->completitionDuration,
                        'visible'   => $campaign->isRegular && !empty($campaign->stats->completitionDuration),
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Autoresponder event'),
                        'value'     => Yii::t('campaigns', $campaign->option->autoresponder_event),
                        'visible'   => $campaign->isAutoresponder,
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Autoresponder time unit'),
                        'value'     => ucfirst(Yii::t('app', $campaign->option->autoresponder_time_unit)),
                        'visible'   => $campaign->isAutoresponder,
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Autoresponder time value'),
                        'value'     => $campaign->option->autoresponder_time_value,
                        'visible'   => $campaign->isAutoresponder,
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Campaign to send for'),
                        'value'     => !empty($campaign->option->autoresponder_open_campaign_id) ? $campaign->option->autoresponderOpenCampaign->name : null,
                        'visible'   => $campaign->isAutoresponder && !empty($campaign->option->autoresponder_open_campaign_id),
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Current opens count for target campaign'),
                        'value'     => !empty($campaign->option->autoresponder_open_campaign_id) ? (int)$campaign->option->autoresponderOpenCampaign->getUniqueOpensCount(true) : null,
                        'visible'   => $campaign->isAutoresponder && !empty($campaign->option->autoresponder_open_campaign_id),
                    ),
                    array(
                        'label'     => Yii::t('campaigns', 'Include imported subscribers'),
                        'value'     => ucfirst(Yii::t('app', $campaign->option->autoresponder_include_imported)),
                        'visible'   => $campaign->isAutoresponder,
                    ),
                ),
            ));
            ?>
            </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');

            $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', new CAttributeCollection(array(
                    'controller'    => $this,
                )));
            ?>
            <div class="clearfix"><!-- --></div>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
<?php 
}
/**
 * This hook gives a chance to append content after the view file default content.
 * Please note that from inside the action callback you can access all the controller view
 * variables via {@CAttributeCollection $collection->controller->data}
 * @since 1.3.3.1
 */
$hooks->doAction('after_view_file_content', new CAttributeCollection(array(
    'controller'        => $this,
    'renderedContent'   => $viewCollection->renderContent,
)));