<?php
/**
 * Mobile Joomla! Pro
 * http://www.mobilejoomla.com
 *
 * @version		1.2.13.pro
 * @license		GNU/GPL v2 - http://www.gnu.org/licenses/gpl-2.0.html
 * @copyright	(C) 2008-2015 Kuneri Ltd.
 * @date		February 2015
 */
defined('_JEXEC') or die('Restricted access');

jimport('joomla.plugin.plugin');

class plgMobileMJPro_Subscription extends JPlugin
{
	function __construct(&$subject, $config)
	{
		parent::__construct($subject, $config);
	}

	function onMJDisplayConfig(&$config_blobs, &$MobileJoomla_Settings, $lists)
	{
		$doc = JFactory::getDocument();
		$doc->addScript(JURI::root(true).'/media/mjpro/subscription.js');
		$doc->addStyleSheet(JURI::root(true).'/media/mjpro/subscription.css');

		$app = JFactory::getApplication();
		$expirenotice = '<div id="mjpronotify"></div>';
		if(version_compare(JVERSION, '3.0', '>='))
		{
			echo $expirenotice;
		}
		else
		{
			$app->enqueueMessage($expirenotice, 'mj');
			if(version_compare(JVERSION, '1.7', '<'))
			{
				$document = JFactory::getDocument();
				$document->addStyleDeclaration('#mjpronotify{margin:-8px -10px 8px}');
			}
		}

		$information =& $config_blobs['COM_MJ__GENERAL_SETTINGS'][1]['COM_MJ__INFORMATION'];

		// latest version
		$information[1] = array(
				'label_blob' => JHTML::_('mjconfig.label', 'COM_MJ__LATEST_VERSION'),
				'input_blob' => '<p><span class="fltrt"><span class="mjactive"><a class="modal" id="mjlatestverurl" href="index.php?tmpl=component&option=com_mobilejoomla&task=update" rel="{handler: \'iframe\', size: {x: 480, y: 320}}">'.JText::_('COM_MJ__UPDATE').'</a> <a target="_blank" class="mjrenewurl" href="http://www.mobilejoomla.com/orders.html">'.JText::_('COM_MJ__RENEW').'</a></span></span><span id="mjlatestver"></span></p>'
			);

		switch($this->params->get('contype', ''))
		{
		case 'fsock':
			$onlineStatus = function_exists('fsockopen');
			break;
		case 'curl':
			$onlineStatus = function_exists('curl_init');
			break;
		case 'stream':
			$onlineStatus = ini_get('allow_url_fopen');
			break;
		default:
			$onlineStatus = false;
		}

		$offlineBlob = $information[2]['input_blob'];
		if($onlineStatus)
			$information[2]['input_blob'] = '<p><a target="_blank" class="fltrt mjrenewurl" href="http://www.mobilejoomla.com/orders.html">'.JText::_('COM_MJ__RENEW').'</a>Remote database [Online] <span class="mjexpired">(expired)</span></p>';
		else
			$information[2]['input_blob'] .= '<p>Remote database [Offline]</p>';

		$blob = array(
				array(
					'label_blob' => JHTML::_('mjconfig.label', 'COM_MJ__DEVICE_DATABASE_ONLINE'),
					'input_blob' => '<p><a target="_blank" class="fltrt mjrenewurl" href="http://www.mobilejoomla.com/orders.html">'.JText::_('COM_MJ__RENEW').'</a>'.($onlineStatus?'Online':'Disabled').' <span class="mjexpired">(expired)</span></p>'
				),
				array(
					'label_blob' => JHTML::_('mjconfig.label', 'COM_MJ__DEVICE_DATABASE_OFFLINE'),
					'input_blob' => $offlineBlob
				)
			);
		array_unshift_assoc($config_blobs['COM_MJ__ADVANCED_SETTINGS'][0], $blob, 'COM_MJ__DEVICE_DATABASE');

		$subscription_blob = array(
			'label_blob' => JHTML::_('mjconfig.label', 'COM_MJ__SUBSCRIPTION'),
			'input_blob' => '<p><a target="_blank" class="fltrt mjrenewurl" href="http://www.mobilejoomla.com/orders.html">'.JText::_('COM_MJ__RENEW').'</a><span class="mjexpired">Expired</span><span class="mjactive">Pro (<span id="mjsubscription"></span> days left)</span></p>'
		);
		array_unshift_assoc($information, $subscription_blob);
	}
}
