<?php
//=====================================
// LINKER Category Engine
//=====================================
// Filename : sqlimport.php
// Path : Manage directory
// last update : 2002/07/13
// Desc : Import DB data
//=====================================
//=====================================
// File include part & DB Layer
//=====================================
include ("./authen.php");
include ("../function/main_func.php");
include ("../$Slang/m_common.php");
//=====================================
// File input parts
//=====================================
if (!$switch) {
print <<<EOF
<html>
<head>
<LINK rel='stylesheet' type='text/css' href='./linker.css'>
<meta http-equiv='Content-Type' content='text/html; charset=$Scharset'>
</head>
<body bgcolor="#E9E9E9">
<form method='post' action='sqlimport.php' method='post' ENCTYPE="multipart/form-data">
<input type="hidden" name="switch" value="submit">
<table border=0 cellpadding=0 cellspacing=1>
<tr>
<td colspan=2>
<table width="100%" border="1"><tr><td bgcolor="#000066" align="center">
<b><font color="white" size="2">$l_data_restore</font></b>
</td></tr></table>
</td> </tr>
<tr><td colspan=2 width=500> </td></tr>
<tr>
<td colspan = '2' bgcolor='E0E0E0' height='60'><font size=2>
$l_sql_txt1<br>
$l_sql_txt2<br>
$l_sql_txt3
</font></td>
</tr>
<tr>
<td align='center' bgcolor='#F6F6F6' height='24'><font size='2'>$l_dump_file</font></td>
<td align='center' bgcolor='#F6F6F6'><font size='2'><input type=file name="upfile"></font></td>
</tr>
<tr>
<td colspan = '2' align='center' bgcolor='E0E0E0' height='24'>
<font size='2'><input type="submit" value="$l_data_restore" class=cinput></font></td>
</tr>
</table>
</form>
EOF;
}
//=====================================
// Data import parts
//=====================================
elseif ($switch =="submit" && $upfile_name) {
if (!$upfile_size) errmsg($l_error_nofile);
set_time_limit(6000);
include ("../function/$Sdb_type.php");
$db = new DB_Sql($Sdb_host,$Sdb_user,$Sdb_pass,$Sselect_db);
// Read Data
$dump = @file($upfile);
@unlink($upfile);
$count = count($dump);
if (trim($dump[0]) <> "# Dump of LINKER_CAT table")
errmsg($l_error_nodump);
$db->query("delete from LINKER_CAT");
$db->query("delete from LINKER_LINK");
$db->query("delete from LINKER_COM");
$db->query("delete from LINKER_WAIT");
$db->query("delete from LINKER_TWORD");
$db->query("delete from LINKER_MAIL");
// Insert Data
for ($i=0 ;$i<$count ;$i++) {
if (!trim($dump[$i])) continue;
if (ereg("^#",$dump[$i])) continue;
$content = str_replace(";\n","\n",$dump[$i]);
$db->query($content);
}
print <<<EOF
<html>
<head>
<LINK rel='stylesheet' type='text/css' href='./linker.css'>
<meta http-equiv='Content-Type' content='text/html; charset=$Scharset'>
</head>
<body bgcolor="#E9E9E9">
<table width="500" border="1"><tr><td bgcolor="#000066" align="center">
<b><font color="white" size="2">$l_dump_result</font></b>
</td></tr></table>
EOF;
}
//=====================================
// File upload error
//=====================================
else {
errmsg($l_error_upload);
}
?>