<?PHP
/*
Name: set_base.php
Author: Julio Tuozzo - hide@address.com
Function: Configure the access variables of phd.inc
Ver: 2.00
*/
session_start();
require('phd.inc');
if (!isset($_SESSION['BASE']))
{include('setup_head.inc');
echo "<p class='danger'>INVALID CALL</p>";
exit();
}
$path_phd="";
$a_include = explode( PATH_SEPARATOR, ini_get('include_path') );
$a_long=count($a_include);
for ($I=0; $I<$a_long; $I++)
{$f_path=str_replace("\\","/",$a_include[$I]);
if (substr($f_path,-1)!='/')
{$f_path.='/';
}
if (is_readable($f_path."phd.inc"))
{ if (strlen($path_phd)>0)
{include('setup_head.inc');
echo "<p class='danger'><b>ERROR - THERE ARE AT LEAST TWO FILES <i>phd.inc</i></p>
<p class='ok'>One is place in <i>$path_phd</i> and other in <i>$f_path</i>.<br />
Make sure that are only one accesible in the variable <i>include_path</i> of the file
phd.inc that are inicialy in <i>/phd_2_00/include/.</i></p>";
exit();
}
else
{$path_phd=$f_path;
}
}
}
if (!is_writable($path_phd."phd.inc"))
{include('setup_head.inc');
echo "<p class='danger'><b>ERROR - IMPOSSIBLE TO WRITE THE FILE {$path_phd}phd.inc </b></p>
<p class='ok'>Verify if the file exists and the access permission and try again.<br />
The phd.inc file is placed in <b>/phd_2_00/include/.</b>
</p>";
exit();
}
$a_phd = implode('', file($path_phd."phd.inc"));
if (!isset($_POST[b_base]))
{require('set_base.inc');
exit();
}
if(!@mysql_connect($_POST[host],$_POST[usuario],$_POST[contrasena]) or !mysql_select_db($_POST[base]))
{$mensaje="<p class='danger'>ERROR - Did not connect with the data base. Enter the values again.</p>";
require('set_base.inc');
exit();
}
$a_phd=str_replace("\$Host = '$Host'","\$Host = '$_POST[host]'",$a_phd);
$a_phd=str_replace("\$Usuario = '$Usuario'","\$Usuario = '$_POST[usuario]'",$a_phd);
$a_phd=str_replace("\$Contrasena = '$Contrasena'","\$Contrasena = '$_POST[contrasena]'",$a_phd);
$a_phd=str_replace("\$Base = '$Base'","\$Base = '$_POST[base]'",$a_phd);
$fp = fopen ($path_phd."phd.inc", "w+");
fwrite($fp,$a_phd);
fclose($fp);
session_destroy();
header("Location: index.php");
?>