<?
require("mb_conf.php");
require("config.php");
require("mb_fn1.php");


if ($md=="logout") {  logout();}

connect_to_db(); 

if ($md=="print_menu") 
{
if($admpassw1 != $adm_passw){
$inc_passw="incorrect password !"; 
printpasswordform($inc_passw);
exit;
}
setcookie("admcookpassw", $admpassw1);
print_menu();
exit;
}

if($admcookpassw != $adm_passw){
if ($admcookpassw != ""){
$inc_passw= "Incorrect password or cookies does not work"; 
}
printpasswordform($inc_passw);
exit;
}

if ($md=="") print_menu();
if ($md=="create_db") create_db();
if ($md=="create_tb") create_tb();
if ($md=="sql_tb") print_sql_tb();
 

function logout()
{
setcookie("admcookpassw", "0");

printpasswordform($inc_passw);
exit;
} 

 

function print_menu()
{
global $html_header, $html_footer, $db_name, $table_mb, 
$moderating, $categories;
echo $html_header;
echo "<center>
<table width='650' bgcolor='#dddddd' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font FACE='ARIAL, HELVETICA' >
<center><b> Admin Interface </b></center> 
</font>
</td></tr></table>
<p>
";
echo " 
<p>
<table width='650' bgcolor='#dddddd' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font FACE='ARIAL, HELVETICA' size=-1>
<b>Create database table for membership database</b>
</font></td></tr><tr><td>
<TABLE   bgcolor='#ffffff' border='0' cellspacing=0 cellpadding=0 WIDTH='100%' >
<tr><td> 
<font FACE='ARIAL, HELVETICA' size=-1>
 
<br><a href='mbcrtb.php?md=create_tb'>Create table '$table_mb'</a>
<p> 
<a href='mbcrtb.php?md=sql_tb'>SQL for creating table '$table_mb'</a>
 </font>
</td></tr></table>
</td></tr></table>
<p><b><a href='mbadmin.php?md=logout'>Log Out from admin. interface</a></b>
</center>";
echo $html_footer;
exit;
}

 

function print_sql_tb()
{
global $html_header, $html_footer;
echo $html_header;
echo sql_create_tb();
echo $html_footer;
exit;
}

function create_db()
{
global $host_name, $db_user,$db_password, $html_header, 
$html_footer, $db_name, $table_mb;

mysql_connect("$host_name","$db_user","$db_password");
mysql_create_db("$db_name");
echo $html_header;
echo "Database '$db_name' was created";
echo $html_footer;
exit; 
}

function create_tb()
{
global $host_name, $db_user,$db_password,
 $html_header, $html_footer, $db_name, $table_mb; 


$sql_query1=sql_create_tb();
mysql_connect("$host_name","$db_user","$db_password");
$slq_drop1="DROP TABLE $table_mb";
mysql("$db_name","$slq_drop1");

$sql_rs1=mysql("$db_name","$sql_query1");
 
if ($sql_rs1)
{
$message="
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' font size='+1'>
<b>Table '$table_mb' was created</b>  
<p></b></font>";
}

else {
$message="
<font FACE='ARIAL, HELVETICA' COLOR='BLACK' font size='+1'>
<b>Table $table_mb does not created correctly</b>  
<p>
</font>
";
}

admin_message1($message);
exit; 
}

function sql_create_tb()
{
global $mb_fields, $table_mb;
$table_name=$table_mb;
$db_t_fields['idnum']="integer not NULL primary key";
$db_t_fields['time']="integer";
$db_t_fields['exptime']="integer";
$db_t_fields['visible']="integer";
 

foreach ($mb_fields as $key => $value)
{
$db_t_fields[$key]=$mb_fields[$key][6];
}

$create_string="";
foreach ($db_t_fields as $db_key => $value)
{
$create_string=$create_string.$db_key." ".$db_t_fields[$db_key].", ";
}
$create_string=corr_sqlstring($create_string);
$sql="create table $table_name ( $create_string ) ";
return $sql;
}

 function admin_message1($message)
{
global $cat_fields, $photos_count, $html_header, $html_footer, $id,
$ct, $categories, $ad_second_width, $left_width_sp, $exp_period;
echo $html_header;
echo "
<center><table width='600'><tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'> <font size=-1>
<b><a href='mbadm.php'>Top:</a></b></font>
&nbsp; 
<hr size='1'><p>
$message
<p><hr size='1'>
</tr></td></table>
</center>
";
echo $html_footer;
exit;
}

function  printpasswordform($inc_passw)
{
global $html_header, $html_footer;

echo $html_header; 
echo "
<center>
<table width='600' bgcolor='#dddddd' border=0 cellspacing=0 cellpadding=1>
<tr><td> 
<font FACE='ARIAL, HELVETICA' >
<center><b> Admin Interface </b></center> 
</font>
</td></tr></table>
<p>
<font FACE='ARIAL, HELVETICA' COLOR='#990000'  >
<b> $inc_passw </b>
</font>
<p>
<form action='mbcrtb.php?md=print_menu' method='post'>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-1'>
<b>
Input admin password : </b></font>
<input type='text' name='admpassw1'>
<input type='submit' value='Submit'>
</form>
<font FACE='ARIAL, HELVETICA' COLOR='#000099' size='-2'>
<br><b>(Cookies must be set up)
 </b></font>
 
<p>
<hr size=1 width='600'>
</center>
";
echo $html_footer;
exit;
}
 
?>