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

$msgs_fl="msg1_".$intlang.".php"; require("$msgs_fl");
$msgs_fl="msg2_".$intlang.".php"; require("$msgs_fl");

$prstop_key="2";

if ($HTTP_GET_VARS['md']=="finish"){fin_close();}

if ($HTTP_COOKIE_VARS['chvl']=="2"){setcookie("chvl", "0");}
else { incorr_proc(); exit;}

 
if ($HTTP_COOKIE_VARS['vck']==$prstop_key){print_mssg();}

$var_cook=$HTTP_COOKIE_VARS['vck'];

$cook_login=$HTTP_COOKIE_VARS['cook_login'];
$cook_passw=$HTTP_COOKIE_VARS['cook_passw'];

connect_to_db();

$sql_query="select idnum, visible, exptime from $table_mb where 
login='$cook_login' and passw='$cook_passw' ";
$sql_res=mysql_query("$sql_query");
$row=mysql_fetch_row($sql_res);
$count1=$row[0]; $val_visible=$row[1];

if ($count1==""){  incorr_proc();  exit;}
 
if ($val_visible=="0"){
$sql_query="update $table_mb set visible=1
where login='$cook_login' ";
}
else {
$time_now=time();
if ($row[2] > $time_now){$exptime2=$row[2]+$mbrshp_per*86400;}
else{$exptime2=$time_now+$mbrshp_per*86400;}
$sql_query="update $table_mb set exptime=$exptime2
where login='$cook_login' ";
}

 
mysql_query("$sql_query");

setcookie("vck", $prstop_key);

print_mssg();

exit;

function print_mssg()
{ 
global $html_header, $html_footer, $val_visible, $msg, $msg2;
echo $html_header;
echo "
<center><table width='500'><tr><td>
<font FACE='ARIAL, HELVETICA' COLOR='BLACK'> <font size=-1>
<b><a href='index.php'>".$msg['top'].":</a></b></font>
&nbsp; 
</font> 
<hr size='1'>
<p>
<center>
<font FACE='ARIAL, HELVETICA' COLOR='#000088' >
";

if ($val_visible=="0"){
echo "
<center>
<b>".$msg2['membership_activated_succ']."</b>
</center>
";
}
else {
echo "
<center>
<b>".$msg2['membership_updated_succ']."</b>
</center>
";
}

echo "
 </font>
<p><font FACE='ARIAL, HELVETICA' COLOR='#000088' size=-1>
<a href='mbp.php?md=finish'>
".$msg2['click_to_finish_session']."
</font>
</td></tr></table></center>
$html_footer
";
exit;
}

function incorr_proc()
{

global $html_header, $html_footer, $msg, $msg2;
echo "

$html_header
<p> <center>
<font FACE='ARIAL, HELVETICA' COLOR='#000088' size='-1'>
<b><font color='#aa0000'>".$msg['Incorect_operation_v']."</font> <p>
<a href='mbp.php?md=finish'>
".$msg2['click_to_finish_session']."
</b>
<p>
</center>
$html_footer
";
exit;
}


function fin_close()
{
setcookie("vck", "");
echo "
<html>
<body onload='self.close()'>
</body>
</html>
";
exit;
}
?>