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

/**
 * MiscController
 * 
 * Handles the actions for ip location services related tasks
 * 
 * @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.3.3
 */
 
class MiscController extends Controller
{
    
    public function init()
    {
        $scripts = array(
            'misc' => AssetsUrl::js('misc.js'),
        );

        foreach ($scripts as $handler => $src) {
            Yii::app()->clientScript->registerScriptFile($src, null, array('id' => 'script-' . $handler));
        }
        
        parent::init();
    }
    
    public function actionIndex()
    {
        $this->redirect(array('misc/application_log'));
    }
    
    public function actionApplication_log()
    {
        $request = Yii::app()->request;
        
        if ($request->isPostRequest && $request->getPost('delete') == 1) {
            if (is_file($file = Yii::app()->runtimePath . '/application.log')) {
                @unlink($file);
                Yii::app()->notify->addSuccess(Yii::t('app', 'The application log file has been successfully deleted!'));
            }
        }
        
        $this->setData(array(
            'pageMetaTitle'     => $this->data->pageMetaTitle . ' | ' . Yii::t('app', 'Application log'), 
            'pageHeading'       => Yii::t('app', 'Application log'),
            'pageBreadcrumbs'   => array(
                Yii::t('app', 'Application log'),
            ),
        ));
        
        $applicationLog = FileSystemHelper::getFileContents(Yii::app()->runtimePath . '/application.log');
        $this->render('application-log', compact('applicationLog'));
    }

}