<?php
/***************************************************************************
* copyright            : (C) 2001-2003 Advanced Internet Designs Inc.
* email                : forum@prohost.org
* $Id: admglobal.php,v 1.1.1.1.8.1 2004/11/24 14:35:19 kazuyan Exp $
*
* This program is free software; you can redistribute it and/or modify it 
* under the terms of the GNU General Public License as published by the 
* Free Software Foundation; either version 2 of the License, or 
* (at your option) any later version.
***************************************************************************/

	require('./GLOBALS.php'); fud_phpgw();
	fud_use('adm.inc', true);
	fud_use('glob.inc', true);
	fud_use('widgets.inc', true);
	fud_use('draw_select_opt.inc');
	fud_use('users_reg.inc');
	fud_use('tz.inc');

function get_max_upload_size()
{
	$us = strtolower(ini_get('upload_max_filesize'));
	$size = (int) $us;
	if (strpos($us, 'm') !== false) {
		$size *= 1024 * 1024;
	} else if (strpos($us, 'k') !== false) {
		$size *= 1024;
	}
	return $size;
}

	$max_attach_size = get_max_upload_size();
	if (isset($_POST['CF_PRIVATE_ATTACH_SIZE'])) {
		if ($_POST['CF_PRIVATE_ATTACH_SIZE'] > $max_attach_size) {
			$_POST['CF_PRIVATE_ATTACH_SIZE'] = $max_attach_size;
		}
	} else if ($GLOBALS['PRIVATE_ATTACH_SIZE'] > $max_attach_size) {
		$GLOBALS['PRIVATE_ATTACH_SIZE'] = $max_attach_size;
	}

	$help_ar = read_help();

	if (isset($_POST['form_posted'])) {
		for ($i = 1; $i < 10; $i++) {
			if (isset($GLOBALS['FUD_OPT_'.$i])) {
				$GLOBALS['NEW_FUD_OPT_'.$i] = 0;
			} else {
				break;
			}
		}

		/* make a list of the fields we need to change */
		foreach ($_POST as $k => $v) {
			if (!strncmp($k, 'CF_', 3)) {
				$k = substr($k, 3);
				if (!isset($GLOBALS[$k]) || $GLOBALS[$k] != $v) {
					$ch_list[$k] = is_numeric($v) ? (int) $v : $v;
				}
			} else if (!strncmp($k, 'FUD_OPT_', 8)) {
				$GLOBALS['NEW_' . substr($k, 0, 9)] |= (int) $v;
			}
		}

		for ($i = 1; $i < 10; $i++) {
			if (!isset($GLOBALS['FUD_OPT_'.$i])) {
				break;
			}

			if ($GLOBALS['FUD_OPT_'.$i] != $GLOBALS['NEW_FUD_OPT_'.$i]) {
				$ch_list['FUD_OPT_'.$i] = $GLOBALS['NEW_FUD_OPT_'.$i];
			}
		}

		if (isset($ch_list)) {
			change_global_settings($ch_list);

			/* some fields require us to make special changes */
			if (isset($ch_list['SHOW_N_MODS'])) {
				$GLOBALS['SHOW_N_MODS'] = $ch_list['SHOW_N_MODS'];
				fud_use('users_reg.inc');
				rebuildmodlist();
			}

			/* Topic tree view disabled */
			if (($FUD_OPT_2 ^ $NEW_FUD_OPT_2) & 512 && !($NEW_FUD_OPT_2 & 512)) {
				q('UPDATE '.$DBHOST_TBL_PREFIX.'users SET users_opt=users_opt|128 WHERE (users_opt & 128)=0');
			}

			$q_data = array();
			if (isset($ch_list['POSTS_PER_PAGE'])) {
				$q_data[] = 'posts_ppg='.(int)$ch_list['POSTS_PER_PAGE'];
			}
			if (isset($ch_list['ANON_NICK'])) {
				$q_data[] = "login='".addslashes($ch_list['ANON_NICK'])."', alias='".addslashes(htmlspecialchars($ch_list['ANON_NICK']))."'";
			}
			if (isset($ch_list['SERVER_TZ'])) {
				$q_data[] = "time_zone='".addslashes($ch_list['SERVER_TZ'])."'";
			}
			if (($FUD_OPT_2 ^ $NEW_FUD_OPT_2) & (4|8)) {
				/* only allow threaded topic view if it is selected & it's enabled */
				$opt  = $NEW_FUD_OPT_2 & 4 && $NEW_FUD_OPT_2 & 512 ? 128 : 0;
				$opt |= $NEW_FUD_OPT_2 & 8 ? 256 : 0;
				$q_data[] = 'users_opt=(users_opt & ~ 384) | '.$opt;
			}
			if ($q_data) {
				q('UPDATE '.$DBHOST_TBL_PREFIX.'users SET '.implode(',', $q_data).' WHERE id=1');
			}

			/* put the settings 'live' so they can be seen on the form */
			foreach ($ch_list as $k => $v) {
				$GLOBALS[$k] = $v;
			}
		}
	}
	require($WWW_ROOT_DISK . 'adm/admpanel.php');
?>
<h2><?php echo lang('Global Configuration') ?></h2>
<table border="0" cellspacing="1" cellpadding="3">
<form method="post" action="admglobal.php">
<?php
	echo _hs;
	print_bit_field(lang('Forum Enabled'), 'FORUM_ENABLED');
	print_reg_field(lang('Reason for Disabling'), 'DISABLED_REASON');
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('Global (do not change these unless you know what you are doing)') ?></b></td></tr>
<?php
	print_reg_field(lang('WWW Root'), 'WWW_ROOT');
	print_reg_field(lang('WWW Root (disk path)'), 'WWW_ROOT_DISK');
	print_reg_field(lang('Data Root'), 'DATA_DIR');
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('Private Messaging') ?></b> </td></tr>
<?php
	print_bit_field(lang('Allow Private Messaging'), 'PM_ENABLED');
	print_reg_field(lang('File Attachments in Private Messages'), 'PRIVATE_ATTACHMENTS', 1);
	print_reg_field(lang('Maximum Attachment Size (bytes)'), 'PRIVATE_ATTACH_SIZE', 1);
	print_bit_field(lang('Allow Smilies'), 'PRIVATE_MSG_SMILEY');
	print_bit_field(lang('Allow Images (fudcode only)'), 'PRIVATE_IMAGES');
	print_bit_field(lang('Tag Style'), 'PRIVATE_TAGS');
	print_reg_field(lang('Maximum Private Messages Folder Size'), 'MAX_PMSG_FLDR_SIZE', 1);
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('Custom Avatar Settings') ?></b> </td></tr>
<?php
	print_bit_field(lang('Avatar Approval'), 'CUSTOM_AVATAR_APPOVAL');
	print_bit_field(lang('Allow Flash (swf) avatars'), 'CUSTOM_AVATAR_ALLOW_SWF');
	print_bit_field(lang('Custom Avatars'), 'CUSTOM_AVATARS');
	print_reg_field(lang('Custom Avatar Max Size (bytes)'), 'CUSTOM_AVATAR_MAX_SIZE', 1);
	print_reg_field(lang('Custom Avatar Max Dimentions'), 'CUSTOM_AVATAR_MAX_DIM');
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('Signature Settings') ?></b> </td></tr>
<?php
	print_bit_field(lang('Allow Signatures'), 'ALLOW_SIGS');
	print_bit_field(lang('Tag Style'), 'FORUM_CODE_SIG');
	print_bit_field(lang('Allow Smilies'), 'FORUM_SML_SIG');
	print_bit_field(lang('Allow Images (fudcode only)'), 'FORUM_IMG_SIG');
	print_reg_field(lang('Maximum number of images'), 'FORUM_IMG_CNT_SIG', 1);
	print_reg_field(lang('Maximum signature length'), 'FORUM_SIG_ML', 1);
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('Spell Checker') ?></b> </td></tr>
<?php
	if (function_exists('pspell_new_config')) {
		$pspell_support = '<font color="red">'.lang('is enabled.').'</font>';
	} else {
		$pspell_support = '<font color="red">'.lang('is disabled.').'<br>'.lang('Please ask your administrator to enable pspell support.').'</font>';
		$GLOBALS['CF_SPELL_CHECK_ENABLED'] = 0;
	}
	print_bit_field(lang('Enable Spell Checker'), 'SPELL_CHECK_ENABLED');
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('Email Settings') ?></b> </td></tr>
<?php
	print_bit_field(lang('Allow Email'), 'ALLOW_EMAIL');
	print_bit_field(lang('Use SMTP To Send Email'), 'USE_SMTP');
	print_reg_field(lang('SMTP Server'), 'FUD_SMTP_SERVER');
	print_reg_field(lang('SMTP Server Timeout'), 'FUD_SMTP_TIMEOUT', 1);
	print_reg_field(lang('SMTP Server Login'), 'FUD_SMTP_LOGIN');
	print_reg_field(lang('SMTP Server Password'), 'FUD_SMTP_PASS');
	print_bit_field(lang('Email Confirmation'), 'EMAIL_CONFIRMATION');
	print_reg_field(lang('Administrator Email'), 'ADMIN_EMAIL');
	print_reg_field(lang('Notify From'), 'NOTIFY_FROM');
	print_bit_field(lang('Notify W/Body'), 'NOTIFY_WITH_BODY');
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>

<tr bgcolor="#bff8ff"><td colspan="2"><br><b><?php echo lang('General Settings') ?></b> </td></tr>
<?php
	print_reg_field(lang('Anonymous Username'), 'ANON_NICK');
	print_reg_field(lang('Anonymous Password'), 'ANON_PASS');
	print_bit_field(lang('Public Host Resolving'), 'PUBLIC_RESOLVE_HOST');

	print_bit_field(lang('Logged In Users List Enabled'), 'LOGEDIN_LIST');
	print_reg_field(lang('Logged In Users List Timeout (minutes)'), 'LOGEDIN_TIMEOUT', 1);
	print_reg_field(lang('Maximum number of logged in users to show'), 'MAX_LOGGEDIN_USERS', 1);
	print_bit_field(lang('Allow Action List'), 'ACTION_LIST_ENABLED');
	print_bit_field(lang('Online/Offline Status Indicator'), 'ONLINE_OFFLINE_STATUS');

	print_reg_field(lang('Max Smilies Shown'), 'MAX_SMILIES_SHOWN', 1);

	print_reg_field(lang('Maximum Shown Login Length'), 'MAX_LOGIN_SHOW', 1);
	print_reg_field(lang('Maximum Shown Location Length'), 'MAX_LOCATION_SHOW', 1);

	print_reg_field(lang('Posts Per Page'), 'POSTS_PER_PAGE', 1);
	print_reg_field(lang('Topics Per Page'), 'THREADS_PER_PAGE', 1);
	print_reg_field(lang('Message icons per row'), 'POST_ICONS_PER_ROW', 1);

	print_bit_field(lang('Allow Tree View of Thread Listing'), 'TREE_THREADS_ENABLE');
	print_bit_field(lang('Default Topic View'), 'DEFAULT_THREAD_VIEW');
	print_reg_field(lang('Maximum Depth of Thread Listing (tree view)'), 'TREE_THREADS_MAX_DEPTH', 1);
	print_reg_field(lang('Maximum Shown Subject Length (tree view)'), 'TREE_THREADS_MAX_SUBJ_LEN', 1);
	print_reg_field(lang('Polls Per Page'), 'POLLS_PER_PAGE', 1);

	print_reg_field(lang('Word Wrap'), 'WORD_WRAP', 1);
	print_reg_field(lang('Flood Trigger (seconds)'), 'FLOOD_CHECK_TIME', 1);
	print_reg_field(lang('Moved Topic Pointer Expiry'), 'MOVED_THR_PTR_EXPIRY', 1);
?>
<tr bgcolor="#bff8ff"><td colspan="2"><?php echo lang('Server Time Zone') ?>: <font size="-1"> <?php echo $help_ar['SERVER_TZ'][0]; ?></font><br /><select name="CF_SERVER_TZ" style="font-size: xx-small;"><?php echo tmpl_draw_select_opt($tz_values, $tz_names, $SERVER_TZ, '', ''); ?></select></td></tr>
<?php
	print_bit_field(lang('Forum Search Engine'), 'FORUM_SEARCH');
	print_reg_field(lang('Search results cache'), 'SEARCH_CACHE_EXPIRY', 1);
	print_bit_field(lang('Member Search'), 'MEMBER_SEARCH_ENABLED');
	print_reg_field(lang('Members Per Page'), 'MEMBERS_PER_PAGE', 1);
	print_reg_field(lang('Maximum logged-in users'), 'MAX_LOGGEDIN_USERS', 1);
	print_reg_field(lang('Quick Pager Link Count'), 'THREAD_MSG_PAGER', 1);
	print_reg_field(lang('General Pager Link Count'), 'GENERAL_PAGER_COUNT', 1);
	print_bit_field(lang('Show Edited By'), 'SHOW_EDITED_BY');
	print_bit_field(lang('Show Edited By Moderator'), 'EDITED_BY_MOD');
	print_reg_field(lang('Edit Time Limit (minutes)'), 'EDIT_TIME_LIMIT', 1);
	print_bit_field(lang('Display IP Publicly'), 'DISPLAY_IP');
	print_reg_field(lang('Max Image Count'), 'MAX_IMAGE_COUNT', 1);
	print_reg_field(lang('Number Of Moderators To Show'), 'SHOW_N_MODS', 1);
	print_bit_field(lang('Public Stats'), 'PUBLIC_STATS');
	print_bit_field(lang('Forum Info'), 'FORUM_INFO');
	print_reg_field(lang('Forum Info Cache Age'), 'STATS_CACHE_AGE', 1);
	print_bit_field(lang('Enable Affero').'<br><a href="http://www.affero.net/bbsteps.html" target="_blank">'.lang('Click here for details').'</a>', 'ENABLE_AFFERO');
	print_bit_field(lang('Topic Rating'), 'ENABLE_THREAD_RATING');
	print_bit_field(lang('Profile Image'), 'ALLOW_PROFILE_IMAGE');
	print_bit_field(lang('Moderator Notification'), 'MODERATED_POST_NOTIFY');
	print_reg_field(lang('Max History'), 'MNAV_MAX_DATE', 1);
	print_reg_field(lang('Max Message Preview Length'), 'MNAV_MAX_LEN', 1);
	print_bit_field(lang('Show PDF Generation Link'), 'SHOW_PDF_LINK');
	print_bit_field(lang('Show Syndication Link'), 'SHOW_XML_LINK');
	print_bit_field(lang('Attachment Referrer Check'), 'DWLND_REF_CHK');
	print_bit_field(lang('Show Reply Reference'), 'SHOW_REPL_LNK');

	if (function_exists('ob_gzhandler')) {
		print_bit_field(lang('Use PHP compression'), 'PHP_COMPRESSION_ENABLE');
		print_reg_field(lang('PHP compression level'), 'PHP_COMPRESSION_LEVEL', 1);
	}
?>
<tr bgcolor="#bff8ff"><td colspan="2" align="left"><input type="submit" name="btn_submit" value="<?php echo lang('Set') ?>"></td></tr>
</table>
<input type="hidden" name="form_posted" value="1">
</form>
<?php require($WWW_ROOT_DISK . 'adm/admclose.php'); ?>
