<?php
/***************************************************************************
* copyright            : (C) 2001-2003 Advanced Internet Designs Inc.
* email                : forum@prohost.org
* $Id: admlock.php,v 1.1.1.1.8.1 2004/11/24 14:12: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);

function chmoddir($dirn, $dirp, $filep, $rec=false)
{
	@chmod($dirn, $dirp);
	if (!($d = opendir($dirn))) {
		echo lang('ERROR').': '.lang('Unable to open "%1" directory', $dirn).'<br>';
		return;
	}
	readdir($d); readdir($d);
	while ($f = readdir($d)) {
		$path = $dirn . '/' . $f;
		if (@is_file($path) && !@chmod($path, $filep)) {
			echo lang('ERROR').': '.lang('couldn\'t chmod "%1"', $path).'<br>';
		} else if (@is_dir($path) && $rec === true) {
			chmoddir($path, $dirp, $filep, true);
		}
	}
	closedir($d);
}

	if (isset($_POST['usr_passwd'], $_POST['usr_login']) && q_singleval("SELECT id FROM ".$DBHOST_TBL_PREFIX."users WHERE login='".addslashes($_POST['usr_login'])."' AND passwd='".md5($_POST['usr_passwd'])."' AND (users_opt & 1048576) > 0")) {
		$FUD_OPT_2 |= 8388608;
		if (isset($_POST['btn_unlock'])) {
			$dirperms = 0777;
			$fileperms = 0666;
			@unlink($ERROR_PATH.'FILE_LOCK');
			$FUD_OPT_2 ^= 8388608;
		} else {
			$dirperms = 0700;
			$fileperms = 0600;
		}

		chmoddir(realpath($WWW_ROOT_DISK), $dirperms, $fileperms, true);
		chmoddir(realpath($DATA_DIR), $dirperms, $fileperms, true);

		change_global_settings(array('FUD_OPT_2' => $FUD_OPT_2));
	}

	$status = ($FUD_OPT_2 & 8388608 ? 'LOCKED' : 'UNLOCKED');

	require($WWW_ROOT_DISK . 'adm/admpanel.php');
?>
<div align="center" style="font-size: xx-large; color: #ff0000;">
	<?php echo lang('The forum\'s files appear to be') ?>: <b><?php echo lang($status); ?></b>.<br>
	<font size="-1"><?php echo lang('If this test claims that the forum is unlocked, but you still cannot modify your files click on the "Unlock Files" button.') ?></font><br>
	<?php echo lang('For security reasons remember to lock your forum\'s files after you are done editing them.') ?>
</div>
<form method="post">
<table border="0" cellspacing="0" cellpadding="3">
<tr><td><?php echo lang('Login') ?>:</td><td><input type="text" name="usr_login" value="<?php echo $usr->alias; ?>"></td></tr>
<tr><td><?php echo lang('Password') ?>:</td><td><input type="password" name="usr_passwd"></td></tr>
<tr><td colspan="2" algin="middle">
	<input type="submit" name="btn_lock" value="<?php echo lang('Lock Files') ?>">
	<input type="submit" name="btn_unlock" value="<?php echo lang('Unlock Files') ?>">
</td></tr>
</table>
<?php echo _hs; ?>
</form>
<?php require($WWW_ROOT_DISK . 'adm/admclose.php'); ?>
