<?

function sheqmn($d)
{
include("db_settings.php");

//EMTPY TEMPLATES INFO
$handler=mysql_connect($db_server,$db_username,$db_password) or die ("error");
mysql_select_db($db_database);
mysql_query("TRUNCATE TABLE `templates` ",$handler);
mysql_close($handler);

$o=fopen("$d","r");
mysql_connect($db_server,$db_username,$db_password) or die ("error");
mysql_select_db($db_database);



//INSERT NEW TEMPLATE INFO
while(!feof($o)):
{
$f=fgets($o);
if(!feof($o))
{
$x=explode("|",$f);
$x[8]=substr_replace($x[8],"",strlen($x[8])-1);
$br="INSERT INTO templates VALUES (".$x[0].",\"".$x[1]."\",\"".$x[2]."\",\"".$x[3]."\",\"".$x[4]."\",\"".$x[5]."\",\"".$x[6]."\",\"".$x[7]."\",\"".$x[8]."\")";
mysql_query($br);
}
}
endwhile;
mysql_close();
fclose($o);
echo "update ok";
}

$n=$_POST['n'];
$f="<form action=\"upd_base.php\" method=\"post\">
<input type=hidden name=n value=\"send\">
<input type=submit value=\"Ugrade datafeed\"></form>";
if(isset($n))
sheqmn("FEED.txt");
else
echo $f;

?>