<?php
/**
*
* @package phpBB Statistics
* @version $Id: acp_stats.php 58 2009-08-29 22:49:56Z marc1706 $
* @copyright (c) 2009 Marc Alexander(marc1706) www.m-a-styles.de
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @based on: acp_stats.php included in the Board3 Portal package (www.board3.de)
*/
class acp_stats
{
var $u_action;
var $new_config = array();
function main($id, $mode)
{
global $db, $user, $template;
global $config, $stats_config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
include($phpbb_root_path . 'statistics/includes/functions.' . $phpEx);
$stats_config = obtain_stats_config();
$user->add_lang('mods/lang_stats_acp');
$action = request_var('action', '');
$submit = (isset($_POST['submit'])) ? true : false;
$this->new_config = $stats_config;
/**
* Validation types are:
* string, int, bool,
* script_path (absolute path in url - beginning with / and no trailing slash),
* rpath (relative), rwpath (realtive, writeable), path (relative path, but able to escape the root), wpath (writeable)
*/
switch ($mode)
{
case 'general':
$display_vars = array(
'title' => 'ACP_STATS_GENERAL_INFO',
'vars' => array(
'legend1' => 'ACP_STATS_GENERAL_SETTINGS',
'stats_enable' => array('lang' => 'ACP_STATS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'basic_basic_enable' => array('lang' => 'ACP_BASIC_BASIC_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'basic_advanced_enable' => array('lang' => 'ACP_BASIC_ADVANCED_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'basic_miscellaneous_enable' => array('lang' => 'ACP_BASIC_MISCELLANEOUS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'activity_forums_enable' => array('lang' => 'ACP_ACTIVITY_FORUMS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'activity_topics_enable' => array('lang' => 'ACP_ACTIVITY_TOPICS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'activity_users_enable' => array('lang' => 'ACP_ACTIVITY_USERS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'contributions_attachments_enable' => array('lang' => 'ACP_CONTRIBUTIONS_ATTACHMENTS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'contributions_polls_enable' => array('lang' => 'ACP_CONTRIBUTIONS_POLLS_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'periodic_daily_enable' => array('lang' => 'ACP_PERIODIC_DAILY_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'periodic_monthly_enable' => array('lang' => 'ACP_PERIODIC_MONTHLY_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'periodic_hourly_enable' => array('lang' => 'ACP_PERIODIC_HOURLY_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'settings_board_enable' => array('lang' => 'ACP_SETTINGS_BOARD_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'settings_profile_enable' => array('lang' => 'ACP_SETTINGS_PROFILE_ENABLE' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
)
);
break;
case 'basic_advanced':
$display_vars = array(
'title' => 'ACP_BASIC_ADVANCED_INFO',
'vars' => array(
'legend1' => 'ACP_BASIC_ADVANCED_SETTINGS',
'basic_advanced_security' => array('lang' => 'ACP_BASIC_ADVANCED_SECURITY' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'basic_advanced_pretend_version' => array('lang' => 'ACP_BASIC_ADVANCED_PRETEND' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
)
);
break;
case 'basic_miscellaneous':
$display_vars = array(
'title' => 'ACP_BASIC_MISCELLANEOUS_INFO',
'vars' => array(
'legend1' => 'ACP_BASIC_MISCELLANEOUS_SETTINGS',
'basic_miscellaneous_hide_warnings' => array('lang' => 'ACP_BASIC_MISCELLANEOUS_WARNINGS' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
'resync_stats_bbcodes' => array('lang' => 'ACP_BASIC_MISCELLANEOUS_BBCODES' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
)
);
break;
case 'activity_users':
$display_vars = array(
'title' => 'ACP_ACTIVITY_USERS_INFO',
'vars' => array(
'legend1' => 'ACP_ACTIVITY_USERS_SETTINGS',
'activity_users_hide_anonymous' => array('lang' => 'ACP_ACTIVITY_USERS_HIDE_ANONYMOUS' , 'validate' => 'bool' , 'type' => 'radio:yes_no' , 'explain' => true),
)
);
break;
default:
trigger_error('NO_MODE', E_USER_ERROR);
break;
}
if (isset($display_vars['lang']))
{
$user->add_lang($display_vars['lang']);
}
$cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
$error = array();
// We validate the complete config if whished
validate_config_vars($display_vars['vars'], $cfg_array, $error);
// Do not write values if there is an error
if (sizeof($error))
{
$submit = false;
}
// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
foreach ($display_vars['vars'] as $config_name => $null)
{
if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') || ($mode == 'links' && strpos($config_name, 'portal_link_') ) !== false)
{
continue;
}
$this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
if ($submit)
{
set_stats_config($config_name, $config_value);
}
}
if ($submit)
{
add_log('admin', 'LOG_STATS_CONFIG_' . strtoupper($mode));
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
}
$this->tpl_name = 'acp_board';
$this->page_title = $display_vars['title'];
$title_explain = $user->lang[$display_vars['title'] . '_EXPLAIN'];
$title_explain .= ( $display_vars['title'] == 'ACP_STATS_GENERAL_INFO' ) ? '<br /><br />' . sprintf($user->lang['ACP_STATS_VERSION'], $stats_config['stats_version']) : '';
$template->assign_vars(array(
'L_TITLE' => $user->lang[$display_vars['title']],
'L_TITLE_EXPLAIN' => $title_explain,
'S_ERROR' => (sizeof($error)) ? true : false,
'ERROR_MSG' => implode('<br />', $error),
'U_ACTION' => $this->u_action)
);
// Output relevant page
foreach ($display_vars['vars'] as $config_key => $vars)
{
if (!is_array($vars) && strpos($config_key, 'legend') === false)
{
continue;
}
if (strpos($config_key, 'legend') !== false)
{
$template->assign_block_vars('options', array(
'S_LEGEND' => true,
'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
);
continue;
}
$type = explode(':', $vars['type']);
$l_explain = '';
if ($vars['explain'] && isset($vars['lang_explain']))
{
$l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
}
else if ($vars['explain'])
{
$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
}
$template->assign_block_vars('options', array(
'KEY' => $config_key,
'TITLE' => (isset($user->lang[$vars['lang']])) ? $user->lang[$vars['lang']] : $vars['lang'],
'S_EXPLAIN' => $vars['explain'],
'TITLE_EXPLAIN' => $l_explain,
'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars),
)
);
unset($display_vars['vars'][$config_key]);
}
}
}
?>