|
<?
if ( $_POST['pcname'] != '' ) {
session_start();
setcookie("pcname", $_POST['pcname'], time()+3600*24*30);
setcookie("service", $_POST['service'], time()+3600*24*30);
setcookie("user", $_POST['user'], time()+3600*24*30);
setcookie("pass", $_POST['pass'], time()+3600*24*30);
setcookie("table", $_POST['table'], time()+3600*24*30);
$_POST['path'] = trim(str_replace("\\\\","\\", $_POST['path']));
setcookie("path", $_POST['path'], time()+3600*24*30);
if ( trim( $_POST['service'] ) != "" ) {
$_POST['service'] = '/' . $_POST['service'];
}
$str = <<<VBS
' **********************************************************
' オブジェクト作成
' **********************************************************
Set Cn = CreateObject( "ADODB.Connection" )
Set Rs = CreateObject( "ADODB.Recordset" )
Set Fs = CreateObject( "Scripting.FileSystemObject" )
strDriver = "{Microsoft ODBC for Oracle}"
strServer = "{$_POST['pcname']}{$_POST['service']}"
strUser = "{$_POST['user']}"
strPass = "{$_POST['pass']}"
strTable = "{$_POST['table']}"
ConnectionString = _
"Provider=MSDASQL" & _
";Driver=" & strDriver & _
";Server=" & strServer & _
";UID=" & strUser & _
";PWD=" & strPass & _
";"
' **********************************************************
' 接続
' **********************************************************
on error resume next
Cn.Open ConnectionString
if Err.Number <> 0 then
Wscript.Echo Err.Description
Wscript.Quit
end if
on error goto 0
' **********************************************************
' 列情報取得
' **********************************************************
Query = "select * from USER_TAB_COLUMNS"
Query = Query & " where TABLE_NAME = '" & strTable & "'"
Query = Query & " order by COLUMN_ID"
on error resume next
Rs.Open Query, Cn
if Err.Number <> 0 then
Cn.Close
Wscript.Echo Err.Description
Wscript.Quit
end if
on error goto 0
Query = "select "
CsvTitle = ""
Do While not Rs.EOF
if CsvTitle <> "" then
Query = Query & "||','||"
CsvTitle = CsvTitle & ","
end if
Query = Query & Rs.Fields("COLUMN_NAME").Value
CsvTitle = CsvTitle & Rs.Fields("COLUMN_NAME").Value
Rs.MoveNext
Loop
Query = Query & " from " & strTable
Rs.Close
' **********************************************************
' データ取得用クエリー
' **********************************************************
on error resume next
Rs.Open Query, Cn
if Err.Number <> 0 then
Cn.Close
Wscript.Echo Err.Description
Wscript.Quit
end if
on error goto 0
' **********************************************************
' 出力ファイルオープン
' **********************************************************
Set Csv = Fs.CreateTextFile( "{$_POST['path']}", True )
' **********************************************************
' タイトル出力
' **********************************************************
Csv.WriteLine CsvTitle
' **********************************************************
' データ出力
' **********************************************************
Do While not Rs.EOF
Csv.WriteLine Rs.Fields(0).Value
Rs.MoveNext
Loop
' **********************************************************
' ファイルクローズ
' **********************************************************
Csv.Close
' **********************************************************
' レコードセットクローズ
' **********************************************************
Rs.Close
' **********************************************************
' 接続解除
' **********************************************************
Cn.Close
' **********************************************************
' オブジェクト解放
' **********************************************************
Set Fs = Nothing
Set Rs = Nothing
Set Cn = Nothing
Wscript.Echo "処理が終了しました"
VBS;
$flname = "oraclecsv" . session_id() . ".vbs";
file_put_contents($flname,$str);
header( "Location: $flname" );
}
else {
header( "Content-Type: text/html" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
if ( $_COOKIE['service'] == "" ) {
$_COOKIE['service'] = "ORCL";
}
if ( $_COOKIE['path'] != "" ) {
$_COOKIE['path'] = trim(str_replace("\\\\","\\", $_COOKIE['path']));
}
?>
<HTML>
<HEAD>
<META http-equiv="Content-type" content="text/html; charset=shift_jis" />
<STYLE type="text/css">
* {
font-size: 12px;
}
.column {
font-weight:bold;
border-style:solid;
border-width:1px;
border-color:#000000;
padding: 4px;
}
.head {
background-color:#C0C0C0;
}
</STYLE>
<SCRIPT language="javascript" type="text/javascript">
function SetSavePath( obj ) {
if ( document.getElementsByName("table")[0].value == "" ) {
alert("テーブル名を入力して下さい")
return;
}
var path = obj.value;
var idx = path.lastIndexOf("\\");
path = path.substring( 0, idx )
document.getElementsByName("path")[0].value =
path + "\\" +
document.getElementsByName("table")[0].value + ".csv";
}
</SCRIPT>
</HEAD>
<BODY>
<FORM
method="POST"
>
<TABLE
style='
border-collapse:collapse;
border-style:solid;
border-width:1px;
border-color:#000000;
'
>
<TR>
<TD class="column head">PC名</TD>
<TD class="column">
<INPUT
type="text"
name="pcname"
value="<?= $_COOKIE['pcname'] ?>"
style='width:200px;'
> サービス名
<INPUT
type="text"
name="service"
value="<?= $_COOKIE['service'] ?>"
style='width:50px;'
>
</TD>
</TR>
<TR>
<TD class="column head">ユーザー</TD>
<TD class="column">
<INPUT
type="text"
name="user"
value="<?= $_COOKIE['user'] ?>"
style='width:200px;'
>
</TD>
</TR>
<TR>
<TD class="column head">パスワード</TD>
<TD class="column">
<INPUT
type="password"
name="pass"
value="<?= $_COOKIE['pass'] ?>"
style='width:200px;'
>
</TD>
</TR>
<TR>
<TD class="column head">テーブル名</TD>
<TD class="column">
<INPUT
type="text"
name="table"
value="<?= $_COOKIE['table'] ?>"
style='width:400px;'
>
</TD>
</TR>
<TR>
<TD class="column head">保存パス<br>仮参照</TD>
<TD class="column">
<INPUT
type="file"
name="pathdummy"
style='width:500px;'
onChange='SetSavePath(this);'
><br>対象ディレクトリにあるファイルを参照して下さい
</TD>
</TR>
<TR>
<TD class="column head">保存パス</TD>
<TD class="column">
<INPUT
type="text"
name="path"
value="<?= $_COOKIE['path'] ?>"
style='width:500px;'
>
</TD>
</TR>
<TR>
<TD class="column" colspan="2">
<INPUT
type="submit"
name="send"
value="送信"
>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<?
$DirHandle = @opendir("./");
if ( $DirHandle ) {
$Target = readdir( $DirHandle );
while( $Target !== false ) {
if ( $Target != "." ) {
$ext = strrchr( $Target, "." );
$ext = strtolower($ext);
if ( $ext == ".vbs" ) {
$astamp = stat($Target);
$laststamp = $astamp[9];
if ( $laststamp < time() - 300 ) {
@unlink($Target);
}
}
}
$Target = readdir( $DirHandle );
}
closedir( $DirHandle );
}
}
?>
| |