<?php
// $Id: create_config.php,v 1.3 2005/10/28 11:56:02 ohwada Exp $

//================================================================
// create config file for bin/link_check.php
// 2004-10-20 K.OHWADA
//================================================================

include 'admin_header.php';

$dir_config  = $MODULE_ROOT."/cache";
$file_config = $dir_config."/config.php";

xoops_cp_header();

echo "<h3>create config file</h3>\n";
echo "for bin/link_check.php <br />\n";

if ( is_writable($dir_config) ) 
{
	save_config($file_config);
	echo "<h4>created</h4>\n";
}
else
{
	echo "<h3><font color='red'>warnig: directory is not writable</font></h3>\n";
	echo "$dir_config<br><br>\n";
}


echo "<h4><a href='../bin/link_check.php?limit=10'>goto TEST for link check</a></h4>\n";
echo "<hr>\n";
echo "<h4><a href='index.php'>goto admin index</a></h4>\n";

xoops_cp_footer();
exit();


function save_config($file)
{
	global $xoopsConfig;

	$xoops_site_name   = $xoopsConfig['sitename'];
	$xoops_site_email  = $xoopsConfig['adminmail'];
	$xoops_language    = $xoopsConfig['language'];

	$fp = fopen($file, "w");

	fwrite($fp,"<?php \n");

	$date = date("Y/m/d H:i:s");
	fwrite($fp,"// $date \n\n");

	write_constant($fp, 'XOOPS_MAINFILE_INCLUDED', 1);
	write_constant($fp, 'XOOPS_ROOT_PATH');
	write_constant($fp, 'XOOPS_URL');
	write_constant($fp, 'XOOPS_DB_TYPE');
	write_constant($fp, 'XOOPS_DB_PREFIX');
	write_constant($fp, 'XOOPS_DB_HOST');
	write_constant($fp, 'XOOPS_DB_USER');
	write_constant($fp, 'XOOPS_DB_PASS');
	write_constant($fp, 'XOOPS_DB_NAME');
	write_constant($fp, 'XOOPS_DB_PCONNECT');
	write_constant($fp, 'XOOPS_GROUP_ADMIN');
	write_constant($fp, 'XOOPS_GROUP_USERS');
	write_constant($fp, 'XOOPS_GROUP_ANONYMOUS');

	fwrite($fp,"\n");

	write_variable($fp, '$xoops_sitename',  $xoops_site_name );
	write_variable($fp, '$xoops_adminmail', $xoops_site_email );
	write_variable($fp, '$xoops_language',  $xoops_language );

	fwrite($fp,"\n?>");

	fclose($fp);
}

function write_constant($fp, $key, $value='')
{
	if (empty($value))  $value = constant($key);

	$data = "define('$key', '$value');";
	fwrite($fp,"$data \n");
}

function write_variable($fp, $key, $value)
{
	$data = "$key = '$value';";
	fwrite($fp,"$data \n");
}

?>
