|
<?
header( "Content-Type: text/html; Charset=utf-8" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
mb_language( "ja" );
mb_internal_encoding("UTF-8");
$Site = FALSE;
$file = file( "gmap.txt" );
for( $i = 0; $i < count( $file ); $i++ ) {
# 改行削除
$target = rtrim( $file[$i] );
# 空行は無視
if ( $target == "" ) {
continue;
}
# コメント文字
if ( substr( $target, 0, 1 ) == ";" ) {
continue;
}
$len = strlen( $target );
$ref = substr( $_SERVER['HTTP_REFERER'], 0, $len );
if ( $target == $ref ) {
$Site = TRUE;
break;
}
}
# **********************************************************
# 0:OK, 1:サイトエラー, 2:10秒エラー
# **********************************************************
if ( $Site ) {
$mode = $_GET['mode'];
$gid = $_GET['gid'];
$keyword = mb_convert_encoding($_GET['keyword'],"EUC-JP","UTF-8");
$title = mb_convert_encoding($_GET['title'],"EUC-JP","UTF-8");
$url = $_GET['url'];
}
else {
print "1";
exit();
}
if ( $mode == '1' ) {
print InsertData();
}
if ( $mode == '2' ) {
print "0";
}
if ( $mode == '7' ) {
$nCount = 0;
ListData();
}
# **********************************************************
# 同一 IP からは 10秒間更新作業はできない
# **********************************************************
function CheckSpan( &$Connect ) {
$Query = "select now()-DATE_ADD(LASTDATE,INTERVAL 10 SECOND)";
$Query .= " from `google_map`";
$Query .= " where IP = '{$_SERVER['REMOTE_ADDR']}'";
$Query .= " order by LASTDATE desc";
$Result = mysql_query( $Query,$Connect );
$Column = mysql_fetch_array( $Result );
if ( $Column ) {
if ( 0 + $Column[0] < 0 ) {
return FALSE;
}
else {
return TRUE;
}
}
else {
return TRUE;
}
}
# **********************************************************
# 登録
# **********************************************************
function InsertData() {
global $mode,$gid,$keyword,$title,$url;
if ( trim( $_GET['keyword'] ) == "" ) {
return 4;
}
if ( trim( $_GET['title'] ) == "" ) {
return 5;
}
if ( substr($_GET['url'],0,strlen("http://maps.google.co.jp/"))
!= "http://maps.google.co.jp/" ) {
return 3;
}
$Connect = mysql_connect(
"mysql11.db.sakura.ne.jp",
"lightbox",
"mysql4trustno1" );
mysql_select_db( "lightbox", $Connect );
if ( !CheckSpan( $Connect ) ) {
mysql_close( $Connect );
return 2;
}
if ( $gid == '' ) {
$Query = 'insert into `google_map`';
$Query .= ' (KEYWORD,TITLE,URL,IP,LASTDATE)';
$Query .= " values('$keyword','$title','$url',";
$Query .= " '{$_SERVER['REMOTE_ADDR']}',NOW())";
mysql_query( $Query, $Connect );
}
else {
$Query = "update `google_map`";
$Query .= " set KEYWORD = '$keyword',";
$Query .= " TITLE = '$title',URL = '$url'";
$Query .= " where GID = '$gid'";
mysql_query( $Query, $Connect );
}
mysql_close( $Connect );
return 0;
}
# **********************************************************
# 一覧表示
# **********************************************************
function ListData() {
global $mode,$gid,$keyword,$title,$url;
global $nCount;
$Connect = mysql_connect(
"mysql11.db.sakura.ne.jp",
"lightbox",
"mysql4trustno1" );
mysql_select_db( "lightbox", $Connect );
$Query = 'select * from `google_map`';
$Query .= " where keyword = '$keyword' order by title";
$Result = mysql_query( $Query,$Connect );
$Column = mysql_fetch_array( $Result );
print "<br><TABLE>\n";
print "<TH>タイトル</TH>\n";
print "<TH>フィールドへデータを転送</TH>\n";
while( $Column ) {
$nCount++;
print "<TR>\n";
print "<TD><A href='" . $Column[5] . "' target='_blank'>" ;
print mb_convert_encoding($Column[4],"UTF-8","EUC-JP");
print "</A>\n";
print "</TD>";
print "<TD><SPAN ";
print " style='cursor:pointer'";
print " onMouseover='ChangeAtt(this,\"#0000FF\",\"underline\")'";
print " onMouseout='ChangeAtt(this,\"#000000\",\"none\")'";
print " onClick='SetData({$Column[0]},\"";
print mb_convert_encoding($Column[4],"UTF-8","EUC-JP");
print '","' . $Column[5] . "\")'>";
print "編集";
print "</SPAN>\n";
print "</TD>";
print "</TR>\n";
$Column = mysql_fetch_array( $Result );
}
if ( $nCount == 0 ) {
print "<TR>\n";
print "<TD>該当データは存在しませんでした</TD>\n";
print "</TR>\n";
}
print "</TABLE>\n";
mysql_close( $Connect );
}
?>
| |