<?php
/**
*
* @package - Red Blinking PM MOD
* @version $Id:$
* @file				acp_rbpm.php
* @copyright (c) 2011-2012 all4phone (http://phpbbmods.cba.pl/)
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* @package acp
*/
class acp_rbpm
{
	var $u_action;
	function main($id, $mode)
	{
		global $db, $user, $auth, $template;
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;

		$action = request_var('action', '');
		$submit = (isset($_POST['submit'])) ? true : false;

		if ($mode != 'index')
		{
			return;
		}

		$this->tpl_name = 'acp_rbpm';
		$this->page_title = 'ACP_RBPM_SETTINGS';

		$rbpm_enable = request_var('rbpm_enable', $config['rbpm_enable']);
		$rbpm_insc_enable = request_var('rbpm_insc_enable', $config['rbpm_insc_enable']);
		$rbpm_enable_background = request_var('rbpm_enable_background', $config['rbpm_enable_background']);
		$rbpm_enable_unread = request_var('rbpm_enable_unread', $config['rbpm_enable_unread']);
		$rbpm_enable_unread_blink = request_var('rbpm_enable_unread_blink', $config['rbpm_enable_unread_blink']);
		$rbpm_color = request_var('rbpm_color', $config['rbpm_color']);
		$rbpm_insc_color = request_var('rbpm_insc_color', $config['rbpm_insc_color']);
		$rbpm_unread_color = request_var('rbpm_unread_color', $config['rbpm_unread_color']);
		$rbpm_shadow_colour = request_var('rbpm_shadow_colour', $config['rbpm_shadow_colour']);
		$rbpm_insc_shadow_colour = request_var('rbpm_insc_shadow_colour', $config['rbpm_insc_shadow_colour']);
		$rbpm_italic = request_var('rbpm_italic', $config['rbpm_italic']);
		$rbpm_variant = request_var('rbpm_variant', $config['rbpm_variant']);
		$rbpm_bold = request_var('rbpm_bold', $config['rbpm_bold']);
/**
* font-size
*/
		$rbpm_size_array = explode(',', '11px,10px,12px,13px,14px,15px,16px,17px,18px');
		$rbpm_size_options = '<select id="rbpm_size" name="rbpm_size" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_size_array as $rbpm_size)
		{
			$rbpm_size_options .= '<option class="inputbox2" value="' . $rbpm_size  . '"' . (($config['rbpm_size'] == $rbpm_size) ? ' selected="selected"' : '') . '>' . $rbpm_size . '</option>';
		}
		$rbpm_size_options .= '</select>';
/**
* font-family
*/
		$rbpm_family_array = explode(',', 'Verdana,Arial,Courier,Georgia,Lucida Sans Unicode,Tahoma,Times New Roman');
		$rbpm_family_options = '<select id="rbpm_family" name="rbpm_family" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_family_array as $rbpm_family)
		{
			$rbpm_family_options .= '<option class="inputbox2" value="' . $rbpm_family  . '"' . (($config['rbpm_family'] == $rbpm_family) ? ' selected="selected"' : '') . '>' . $rbpm_family . '</option>';
		}
		$rbpm_family_options .= '</select>';
/**
* transform
*/
		$rbpm_transform = request_var('rbpm_transform', $config['rbpm_transform']);	
/**
* decoration
*/
		$rbpm_decoration = request_var('rbpm_decoration', $config['rbpm_decoration']);
/**
* shadowh
*/
		$rbpm_shadowh_array = explode(',', '0px,-3px,-2px,-1px,1px,2px,3px');
		$rbpm_shadowh_options = '<select id="rbpm_shadowh" name="rbpm_shadowh" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_shadowh_array as $rbpm_shadowh)
		{
			$rbpm_shadowh_options .= '<option class="inputbox2" value="' . $rbpm_shadowh  . '"' . (($config['rbpm_shadowh'] == $rbpm_shadowh) ? ' selected="selected"' : '') . '>' . $rbpm_shadowh . '</option>';
		}
		$rbpm_shadowh_options .= '</select>';
/**
* shadowv
*/
		$rbpm_shadowv_array = explode(',', '0px,-3px,-2px,-1px,1px,2px,3px');
		$rbpm_shadowv_options = '<select id="rbpm_shadowv" name="rbpm_shadowv" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_shadowv_array as $rbpm_shadowv)
		{
			$rbpm_shadowv_options .= '<option class="inputbox2" value="' . $rbpm_shadowv  . '"' . (($config['rbpm_shadowv'] == $rbpm_shadowv) ? ' selected="selected"' : '') . '>' . $rbpm_shadowv . '</option>';
		}
		$rbpm_shadowv_options .= '</select>';
/**
* shadow blur
*/
		$rbpm_shadow_blur_array = explode(',', '0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px');
		$rbpm_shadow_blur_options = '<select id="rbpm_shadow_blur" name="rbpm_shadow_blur" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_shadow_blur_array as $rbpm_shadow_blur)
		{
			$rbpm_shadow_blur_options .= '<option class="inputbox2" value="' . $rbpm_shadow_blur  . '"' . (($config['rbpm_shadow_blur'] == $rbpm_shadow_blur) ? ' selected="selected"' : '') . '>' . $rbpm_shadow_blur . '</option>';
		}
		$rbpm_shadow_blur_options .= '</select>';
/**
* spacing
*/
		$rbpm_spacing_array = explode(',', '-1px,0px,1px,2px,3px');
		$rbpm_spacing_options = '<select id="rbpm_spacing" name="rbpm_spacing" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_spacing_array as $rbpm_spacing)
		{
			$rbpm_spacing_options .= '<option class="inputbox2" value="' . $rbpm_spacing  . '"' . (($config['rbpm_spacing'] == $rbpm_spacing) ? ' selected="selected"' : '') . '>' . $rbpm_spacing . '</option>';
		}
		$rbpm_spacing_options .= '</select>';
/**
* background colour
*/
		$rbpm_background_colour = request_var('rbpm_background_colour', $config['rbpm_background_colour']);
		$rbpm_background_r = request_var('rbpm_background_r', $config['rbpm_background_r']);
		$rbpm_background_g = request_var('rbpm_background_g', $config['rbpm_background_g']);
		$rbpm_background_b = request_var('rbpm_background_b', $config['rbpm_background_b']);
/**
* background transparency
*/
		$rbpm_background_transp_array = explode(',', '1,0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2,0.1');
		$rbpm_background_transp_options = '<select id="rbpm_background_transp" name="rbpm_background_transp" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_background_transp_array as $rbpm_background_transp)
		{
			$rbpm_background_transp_options .= '<option class="inputbox2" value="' . $rbpm_background_transp  . '"' . (($config['rbpm_background_transp'] == $rbpm_background_transp) ? ' selected="selected"' : '') . '>' . $rbpm_background_transp . '</option>';
		}
		$rbpm_background_transp_options .= '</select>';
/**
* border
*/
		$rbpm_border_colour = request_var('rbpm_border_colour', $config['rbpm_border_colour']);
/**
* border width
*/
		$rbpm_border_width_array = explode(',', '0px,1px,2px');
		$rbpm_border_width_options = '<select id="rbpm_border_width" name="rbpm_border_width" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_border_width_array as $rbpm_border_width)
		{
			$rbpm_border_width_options .= '<option class="inputbox2" value="' . $rbpm_border_width  . '"' . (($config['rbpm_border_width'] == $rbpm_border_width) ? ' selected="selected"' : '') . '>' . $rbpm_border_width . '</option>';
		}
		$rbpm_border_width_options .= '</select>';
/**
* border style
*/
		$rbpm_border_style = request_var('rbpm_border_style', $config['rbpm_border_style']);
/**
* border radius
*/
		$rbpm_border_radius_array = explode(',', '0px,1px,2px,3px,4px,5px,6px,7px,8px,9px,10px,11px');
		$rbpm_border_radius_options = '<select id="rbpm_border_radius" name="rbpm_border_radius" class="inputbox" size="1"  onchange="document.adminForm.submit();">';
		foreach ($rbpm_border_radius_array as $rbpm_border_radius)
		{
			$rbpm_border_radius_options .= '<option class="inputbox2" value="' . $rbpm_border_radius  . '"' . (($config['rbpm_border_radius'] == $rbpm_border_radius) ? ' selected="selected"' : '') . '>' . $rbpm_border_radius . '</option>';
		}
		$rbpm_border_radius_options .= '</select>';
		
		
		$form_name = 'acp_rbpm';
		add_form_key($form_name);

		if ($submit)
		{
			if (!check_form_key($form_name))
			{
				trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
			}

			$error = array();

			$message = $user->lang['ACP_RBPM_SETTINGS_CHANGED'];
			$log = 'LOG_RBPM_SETTINGS_CHANGED';

			set_config('rbpm_enable', $rbpm_enable);
			set_config('rbpm_insc_enable', $rbpm_insc_enable);
			set_config('rbpm_enable_background', $rbpm_enable_background);
			set_config('rbpm_enable_unread', $rbpm_enable_unread);
			set_config('rbpm_enable_unread_blink', $rbpm_enable_unread_blink);
			set_config('rbpm_color', $rbpm_color);
			set_config('rbpm_insc_color', $rbpm_insc_color);
			set_config('rbpm_unread_color', $rbpm_unread_color);
			set_config('rbpm_italic', $rbpm_italic);
			set_config('rbpm_variant', $rbpm_variant);
			set_config('rbpm_bold', $rbpm_bold);
			set_config('rbpm_size', request_var('rbpm_size', ''));
			set_config('rbpm_family', request_var('rbpm_family', ''));
			set_config('rbpm_spacing', request_var('rbpm_spacing', ''));
			set_config('rbpm_transform', request_var('rbpm_transform', ''));
			set_config('rbpm_decoration', request_var('rbpm_decoration', ''));
			set_config('rbpm_shadowh', request_var('rbpm_shadowh', ''));
			set_config('rbpm_shadowv', request_var('rbpm_shadowv', ''));
			set_config('rbpm_shadow_blur', request_var('rbpm_shadow_blur', ''));
			set_config('rbpm_shadow_colour', $rbpm_shadow_colour);
			set_config('rbpm_insc_shadow_colour', $rbpm_insc_shadow_colour);
			set_config('rbpm_background_colour', $rbpm_background_colour);
			set_config('rbpm_background_r', $rbpm_background_r);
			set_config('rbpm_background_g', $rbpm_background_g);
			set_config('rbpm_background_b', $rbpm_background_b);
			set_config('rbpm_background_transp', request_var('rbpm_background_transp', ''));
			set_config('rbpm_border_colour', $rbpm_border_colour);
			set_config('rbpm_border_width', request_var('rbpm_border_width', ''));
			set_config('rbpm_border_style', request_var('rbpm_border_style', ''));
			set_config('rbpm_border_radius', request_var('rbpm_border_radius', ''));
			
			add_log('admin', 'LOG_' . $log);
			trigger_error($message . adm_back_link($this->u_action));
		}
		
		$template->assign_vars(array(
			'U_ACTION'						=> $this->u_action,
			'RBPM_ENABLE'					=> $rbpm_enable,
			'RBPM_INSC_ENABLE'				=> $rbpm_insc_enable,
			'RBPM_ENABLE_BACKGROUND'		=> $rbpm_enable_background,
			'RBPM_ENABLE_UNREAD'			=> $rbpm_enable_unread,
			'RBPM_ENABLE_UNREAD_BLINK'		=> $rbpm_enable_unread_blink,
			'RBPM_VERSION'					=> $config['rbpm_version'],
			'RBPM_COLOR'					=> $rbpm_color,
			'RBPM_INSC_COLOR'				=> $rbpm_insc_color,
			'RBPM_UNREAD_COLOR'				=> $rbpm_unread_color,
			'RBPM_ITALIC'					=> $rbpm_italic,
			'RBPM_ITALIC_STYLE'				=> $rbpm_italic == 'italic',
			'RBPM_NORMAL_STYLE'				=> $rbpm_italic == 'normal',
			'RBPM_VARIANT'					=> $rbpm_variant,
			'RBPM_VARIANT_STYLE'			=> $rbpm_variant == 'small-caps',
			'RBPM_NORMAL_VARIANT_STYLE'		=> $rbpm_variant == 'normal',
			'RBPM_BOLD'						=> $rbpm_bold,
			'RBPM_BOLD_STYLE'				=> $rbpm_bold == 'bold',
			'RBPM_NONE_STYLE'				=> $rbpm_bold == 'none',
			'RBPM_SIZE'						=> $rbpm_size_options,
			'RBPM_FAMILY'					=> $rbpm_family_options,
			'RBPM_SPACING'					=> $rbpm_spacing_options,
			'RBPM_TRANSFORM'				=> $config['rbpm_transform'],
			'RBPM_DECORATION'				=> $config['rbpm_decoration'],
			'RBPM_SHADOWH'					=> $rbpm_shadowh_options,
			'RBPM_SHADOWV'					=> $rbpm_shadowv_options,
			'RBPM_SHADOW_BLUR'				=> $rbpm_shadow_blur_options,
			'RBPM_SHADOW_COLOUR'			=> $rbpm_shadow_colour,
			'RBPM_INSC_SHADOW_COLOUR'		=> $rbpm_insc_shadow_colour,
			'RBPM_BACKGROUND_COLOUR'		=> $rbpm_background_colour,
			'RBPM_BACKGROUND_R'				=> $rbpm_background_r,
			'RBPM_BACKGROUND_G'				=> $rbpm_background_g,
			'RBPM_BACKGROUND_B'				=> $rbpm_background_b,
			'RBPM_BACKGROUND_TRANSP'		=> $rbpm_background_transp_options,
			'RBPM_BORDER_COLOUR'			=> $rbpm_border_colour,
			'RBPM_BORDER_WIDTH'				=> $rbpm_border_width_options,
			'RBPM_BORDER_STYLE'				=> $config['rbpm_border_style'],
			'RBPM_BORDER_RADIUS'			=> $rbpm_border_radius_options,
		));
// Get current and latest version
		$errstr = '';
		$errno = 0;

		$mod_version = $user->lang['NO_INFO'];
		$data = array(
			'title'            => $user->lang['NO_INFO'],
			'download'        => $user->lang['NO_INFO'],
			'announcement'    => $user->lang['NO_INFO'],
		);
                
// Load Version File From Host
		$file = get_remote_file('phpbbmods.cba.pl', '/updatecheck/', 'rbpm.xml', $errstr, $errno);

		if ($file)
		{

// let's not stop the page from loading if a mod author messed up their mod check file
// also take care of one of the easiest ways to mess up an xml file: "&"
			$mod = @simplexml_load_string(str_replace('&', '&amp;', $file));
			if (isset($mod->version_check))
			{
				$row = $mod->version_check;
				$mod_version = $row->mod_version->major . '.' . $row->mod_version->minor . '.' . $row->mod_version->revision . $row->mod_version->release;

				$data = array(
					'title'           => $row->title,
					'download'        => $row->download,
					'announcement'    => $row->announcement,
				);
			}

// remove spaces from the version in the mod file stored locally
			$version = str_replace(' ', '', $config['rbpm_version']);
			$version_compare = (version_compare($config['rbpm_version'], $mod_version, '<')) ? false : true;

			$template->assign_block_vars('mods', array(
				'ANNOUNCEMENT'      => $data['announcement'],
				'CURRENT_VERSION'   => $config['rbpm_version'],
				'DOWNLOAD'          => $data['download'],
				'LATEST_VERSION'    => $mod_version,
				'TITLE'             => $data['title'],
				'UP_TO_DATE'        => sprintf((!$version_compare) ? $user->lang['NOT_UP_TO_DATE'] : $user->lang['UP_TO_DATE'], $data['title']),
				'S_UP_TO_DATE'      => $version_compare,
			));
		}
	}
}

?>
