<?php
/**
 * Created by PhpStorm.
 * User: Ermin Islamagić - https://ermin.islamagic.com
 * Date: 22.8.2016
 * Time: 09:37
 */

// Check if root path is defined
if (!defined("ROOT_PATH"))
{
    // Show 403 if root path not defined
    header("HTTP/1.1 403 Forbidden");
    exit;
}

/**
 * Class LocaleAppController
 */
class LocaleAppController extends Plugin
{
    /**
     * LocaleAppController constructor.
     */
	public function __construct()
	{
		$this->setLayout('ActionAdmin');
	}

    /**
     * @param $const
     * @return null
     */
	public static function getConst($const)
	{
		$registry = Registry::getInstance();
		$store = $registry->get('Locale');
		return isset($store[$const]) ? $store[$const] : NULL;
	}

    /**
     * @return array
     */
	public function ActionCheckInstall()
	{
		$this->setLayout('ActionEmpty');
	
		$result = array('status' => 'OK', 'code' => 200, 'text' => 'Operation succeeded', 'info' => array());
		$folders = array(UPLOAD_PATH . 'locale');
		foreach ($folders as $dir)
		{
			if (!is_writable($dir))
			{
				$result['status'] = 'ERR';
				$result['code'] = 101;
				$result['text'] = 'Permission requirement';
				$result['info'][] = sprintf('Folder \'<span class="bold">%1$s</span>\' is not writable. You need to set write permissions (chmod 777) to directory located at \'<span class="bold">%1$s</span>\'', $dir);
			}
		}
	
		return $result;
	}
}