#!/usr/bin/perl

#///////////////////////////////////////////////////////////////////////////////
#                         Affiliate Members Manager Ver9.50

#                    ----- 2007(C) WEB INVENTOR(Solve) -----
#                                 solve@wb-i.net
#                                 http://wb-i.net/
#
#///////////////////////////////////////////////////////////////////////////////
#================================ [注意事項] ===================================
# このスクリプトはシェアウエアです。このスクリプトを使用したいかなる損害に対して
# も作者は一切の責任を負いません。
#====================================使用法=====================================
# 次のようにして呼び出してください。
#	１．会員管理
#			http://・・/aff_adm.cgi
#
#	２．管理者用
#			http://・・/shop.cgi?mode=adm1
#==================================================================
require './aff_set.pl';

$t_width ='630';
$color_r ='#accad2';
$bg_color2 ='#ffffff';

unless($display_limit){$display_limit =100;}	#検索結果から表示する件数

#===============================================================================
# ▼設定▼
#===============================================================================
# jcode.plへのパス
require '../jcode.pl';

# cgi-lib.plへのパス
require '../cgi-lib.pl';

# MIMEコード変換ライブラリ
require '../mimew.pl';

# スポット的メルマガ送信用ＣＳＶファイル
$spot_file ="$aff_lock/spot.csv";

# メルマガ送信用TXTファイル
$mag_file ="$aff_lock/subj.txt";

# メルマガ送信用NOファイル(送信済み最終ファイル番号)
$next_no_file ="$aff_lock/end_no.txt";

# メールマガジン中止用ファイル名
$magazine_stop ="$aff_lock/magazine_stop.log";

# <body>のカスタマイズ
$body = "<body marginheight='0' leftmargin='0' marginwidth='0' topmargin='0' bgcolor=$bg_color2 background =$bk_ground>";

$header = <<"EOF";
<DIV align="center">
<TABLE width="$t_width" border=0 cellpadding=0 cellspacing=0>
<TBODY>
<TR>
<TD align="center"><br><IMG src="$aff_image/title4.gif" border="0"><BR>
</TD>
</TR>
</TBODY>
</TABLE>
EOF

#フッター
#著作権表示は削除できません。
if($right_free<49999 || $right_free>69999 || $right_free =~ /[^0-9]/){
$foot = <<EOF;
<table width="$t_width" bgcolor="">
<tr><td>
<center><a href="http://wb-i.net/"><FONT class='link_color'>Affiliate Members Manager Ver9.50</font></a></center></td></tr>
</table>
</div>
EOF
}else{
$foot = <<EOF;
<table width="$t_width" bgcolor="">
<tr><td>
<center><FONT class='link_color'>$replace_name</font></center></td></tr>
</table>
</div>
EOF
}

# ===============================================================================
# ▲設定終了▲
# ===============================================================================
# 機種のテーブル
@kisyu_table =('PC','ezweb','i-mode','j-sky','other');		#デフォルトは$kisyu_table[0]。

&ReadParse;

while (($key,$val) = each %in) {
	&jcode'convert(*val, "sjis");
	$val =~ s/<>//g;
	
	$in2{$key} = $val;
	
$val =~ s/\r\n/<br>/g;
$val =~ s/\r/<br>/g;
$val =~ s/\n/<br>/g;
	$form2{$key} = $val;

$val =~ s/\"/&quot;/g;
$val =~ s/\0/ /g;
if ($val =~ /<br>$/) {
	while ($val =~ /<br>$/) { $val =~ s/<br>$//g; }
}

	$form{$key} = $val;

$val =~ s/&lt;/</g;
$val =~ s/&gt;/>/g;
$val =~ s/<br>/\n/g;
$val =~ s/\.\n/\. \n/g;

	$in{$key} = $val;
}

$ff_no =$in{'FF'};


#===== 戻り先========================================================
$pasword_encode =$in{'pas_word'};
$pasword_encode =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;    #ここでエンコード

$modoru ="$script_aff_adm?mode=m_manager&pass=$in{'pass'}&E_NO=$in{'E_NO'}&M_ID=$in{'M_ID'}&pas_word=$pasword_encode";

$top_modoru ="../shop.cgi?mode=adm_menu&pass=$in{'pass'}";
$top_mail ="$script_aff_adm?mode=mail&pass=$in{'pass'}";
$header .= <<"EOF";
<table width=$t_width align=center cellpadding=0 border=0>
<tr><td><br>
<div align="right"><a href="$top_modoru"><FONT class='link_color'>▲管理メニュー</font></a>\　\　<a href="$script_aff_adm?pass=$in{'pass'}"><FONT class='link_color'>▲ｱﾌｨﾘｴｲﾄ会員管理</font></a></div><hr width=$t_width noshade size=1>
</td></tr></table>
EOF

#====================================================================
	if ( $in{'mode'} eq 'refresh' ) { &send_magazine; exit;}
	if ( $in{'mode'} eq 'renew1' ) { &renew1; exit;}
	if ( $in{'mode'} eq 'renew2' ) { &renew2; exit;}
	if ( $in{'mode'} eq 'renew3' ) { &renew3; exit;}
	if ( $in{'mode'} eq 'adm1' ) { &adm1; exit;}
	if ( $in{'mode'} eq 'mail' ) { &mail_magazine; exit;}
	if ( $in{'mode'} eq 'test_magazine' ) { &test_magazine; exit;}
	if ( $in{'mode'} eq 'send_magazine' ) { &send_magazine; exit;}
#	if ( $in{'mode'} eq 'mail_k' ) { &mail_magazine_k; exit;}
	if ( $in{'mode'} eq 'stop' ) { &send_stop; exit;}
	else { &m_manager; exit;}
#=======================================================================
sub adm1 {

if($aff_password eq "1234"){
	$dis_closure = "<br>[パスワード = 1234]<br>";
}
&html_header();

print <<"EOF";
<br><br>
<table bgcolor=$color_r width=350 align=center cellpadding=10 border=1 bordercolor=$color_adm_d>
<tr><td><center>
<form method=post action=$script_aff_adm>
<input type=hidden name=mode value=m_manager>
<input type=hidden name=class value="all">
<input type=hidden name=FF value=0>
<input type=hidden name="keyword" value="">
<input type="hidden" name="superkey" value="1"><br>
管理者用パスワードを入力してください。<br><br>
<input type=password name=pass>
<input type=submit value=認証>$dis_closure</form>
</td></tr></table>
<br><b></center>
<hr width=$t_width noshade size=1>
$foot
</body></html>
EOF

}

#================比較サブルーチン=========================================================
sub compare{
	$object =$_[0];
	$object =~ tr/A-Z/a-z/;		#小文字に変換

	$pair_or =$_[1];
	@pair_or  =split(/or/,$pair_or);
	$falg_or =0;

	foreach (@pair_or){
		$_ =~ tr/A-Z/a-z/;		#小文字に変換

		if (index($object,$_) >= 0) {
			$falg_or =1;
			last;
		}
	}
    return($falg_or);
}
#==============================================
sub puls_access{
	($a1,$a2) = split(/\,/,$_[0]);
	$puls_data =$a1 + $a2;
	return($puls_data);
}
#==================================member Manager=================================
sub m_manager{
if ( $in{'pass'} ne $aff_password ) { print "Location: $script_aff_adm?mode=adm1\n\n"; exit; }

$data_su=0;		#初期化
$whole_click=0;
$whole_order=0;
$whole_order_get=0;
$whole_get=0;
$whole_get_past1=0;
$whole_get_past2=0;

$x =100;
while($x < 200){
	$number1 =substr("$x",1,1);
	$number2 =substr("$x",2,1);
	$list_file =$aff_list.'/'.$number1.$number2.'.cgi';

#==会員IDダイレクトアクセス==
	if($in{'M_ID'} ne ''){
		$x =200;
		$in{'ID_NAME'} =$in{'M_ID'};
		&get_file_name();
	}
#============================
	if (-e $list_file) {
		if (!open(IN,"$list_file")) { &error("ファイルオープンエラー",'指定された書込みファイルが開けません。');}
		@LIST= <IN>;
		close(IN);

foreach $num (0 .. $#LIST) {
	$data = $data2 = $LIST[$num];

		($personal_data,$click,$access_data) = split(/\<\>/,$data);
		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);
		($click{"$kisyu_table[0]"},$click{"$kisyu_table[1]"},$click{"$kisyu_table[2]"},$click{"$kisyu_table[3]"},$click{"$kisyu_table[4]"}) = split(/\,/,$click);
	if($entry_no eq '' || $entry_no eq "\n"){next;}

	# 検索処理
	if ($in{'E_NO'} ne "") {
		if ($entry_no eq $in{'E_NO'}) {
		 	push(@NEW,$data2);
    		push(@KENSAKU,$data2);
		 	$data_su++;
		 	last; 
		 } else { next; }
	}

	if ($in{'M_ID'} ne '') {
		if ($identity eq $in{'M_ID'}) {
		 	push(@NEW,$data2);
    		push(@KENSAKU,$data2);
		 	$data_su++;
		 	last; 
		 } else { next; }
	}
	if($in{'pas_word'} ne "") {
    
		# 入力内容を整理
		$word = $in{'pas_word'};
		$word =~ s/　/ /g;
		$word =~ s/\t/ /g;
		@pairs = split(/ /,$word);

	
	$flag_k = 0;
	foreach $pair (@pairs){
		if (compare($password,$pair)) {
		 next;
		}elsif (compare($name,$pair)) {
		 next;
		}elsif (compare($url,$pair)) {
		 next;
		}elsif (compare($mail,$pair)) {
		 next;
		}elsif (compare($date,$pair)) {
		 next;
		}elsif (compare($aux1,$pair)) {
		 next;
		}elsif (compare($aux2,$pair)) {
		 next;
		}elsif (compare($aux3,$pair)) {
		 next;
		}elsif (compare($aux4,$pair)) {
		 next;
		}
		$flag_k = 1;
		last;
	}
		if ($flag_k == 1) { next; }

    }

	push(@BASE500, $data2);
	$data_su++;

#==アフィリエイト集計==
	&whole_total_pre();

#==送信リストの作成==
if($spot_entry_no){
	$spot_entry_no .=",".$entry_no;
}else{
	$spot_entry_no =$entry_no;
}

}

#==データのソート（クリック数順）==
	@BASE500 = sort { (split(/\<\>/,$b))[1] <=> (split(/\<\>/,$a))[1] } @BASE500;
	if($m_zyunzyo == 1 ){
		@BASE500 = reverse @BASE500;
	}

#///////////////////////////////////////////////////////
#==表示数の上限以降を削除==
	if($data_su > $display_limit){
		splice(@BASE500,$display_limit);
	}
}
	$x ++;
}

if($data_su > $display_limit){
	$display_limit_mess ="（検索結果からｸﾘｯｸ数の多い順位に$display_limit件まで表\示）";
}

#========================================================================
$hit = 0;
$next_num = '';
$over_no = 0;
$data_ff =0;

foreach $num (0 .. $#BASE500) {
	$data = $data2 = $BASE500[$num];

	# ページ作成処理
	if ($hit == $aff_page) { $next_num = $data_ff; $over_no ++; $hit++; next; }
	elsif($hit < $aff_page && $data_ff >= $ff_no){
		 push(@NEW,$data2); $hit++; 
	}elsif($hit > $aff_page && $data_ff >= $ff_no){
		$over_no ++;
	}
	
	$data_ff ++;

	if($over_no > $aff_page){
		$over_no = $aff_page;
	}

}

#====================================送信リスト出力===========================
if($in{'spot'}){
open (OUT,">$spot_file") || &error('ファイルオープンエラーspot0','指定された書込みファイルが開けません。');
print OUT "$spot_entry_no";
close (OUT);
}
#=============================================================================
&html_header();

print <<"EOF";
<FORM>
<TABLE>
  <TBODY>
    <TR>
      <TD>登録番号 <INPUT  STYLE='ime-mode:disabled;' size="15" type="text" name="E_NO">
      </TD>
      <TD>\　\　会員ＩＤ
      <INPUT  STYLE='ime-mode:disabled;' size="15" type="text" name="M_ID">
      </TD>
      <TD>\　\　ｷｰﾜｰﾄﾞ
      <INPUT size="15" type="text" name="pas_word" value="$in{'pas_word'}">
      </TD>
    </TR><TR><TD colspan=3 align =right>
    <input type=hidden name=mode value=m_manager>
    <input type=hidden name=pass value="$in{'pass'}">
    <input type=hidden name=FF value=0>
<INPUT type='checkbox' name='spot' value='on'><font color='#000099'>送信リスト作成</font>
\　\　\　 <INPUT type="submit" value="会員検索">\　\　<INPUT type="reset" value="クリア">
  </td></tr></TBODY>
</TABLE>
</FORM>

<table width="$t_width" bgcolor="$color_r"><tr><td bgcolor="$color_r" colspan ='2' align="center"><b>アフィリエイト会員一\覧\表\ $display_limit_mess</b></td></tr>
</table><br>

<TABLE>
  <TBODY>
    <TR>
      <TD><b>検索数[ $data_su ]\　\　\　検索条件＝\　登録番号[ $in{'E_NO'} ]\　\　会員ＩＤ[ $in{'M_ID'} ]\　\　ｷｰﾜｰﾄﾞ[ $in{'pas_word'} ]</b></TD>
    </TR>
  </TBODY>
</TABLE>

EOF


print <<"EOF";
<TABLE width="$t_width" bgcolor="#0e5d7d">
  <TBODY>
    <TR>
      <TD>
      <TABLE cellpadding="1" cellspacing="1" bgcolor="">
        <TBODY>
          <TR>
            <TD align="center" width="110" bgcolor="#0e5d7d"><B><FONT color="#ffffff">登録NO</FONT></B></TD>
            <TD align="center" width="100" bgcolor="#0e5d7d"><B><FONT color="#ffffff">ID/ﾊﾟｽ</FONT></B></TD>
            <TD align="center" width="100" bgcolor="#0e5d7d"><B><FONT color="#ffffff">名前/日付</FONT></B></TD>
            <TD colspan="3" align="center" width="280" bgcolor="#0e5d7d"><FONT color="#ffffff"><B>メール/URL</B></FONT></TD>
            <TD align="center" width="80" bgcolor="#0e5d7d"><B><FONT color="#ffffff">購読拒否</FONT></B></TD>
          </TR>
EOF


foreach(@NEW){
		($personal_data,$click,$access_data) = split(/\<\>/,$_);
		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);
		$i =0;
		@click = split(/\,/,$click);
		foreach(@kisyu_table){
			$click{"$_"} =$click[$i];
			unless($click{"$_"}){$click{"$_"} =0;}
			$i ++;
		}
#=================報酬額の計算============================================
$access_data =~ s/\r\n//g;
$access_data =~ s/\r//g;
$access_data =~ s/\n//g;

@access = split(/\:/,$access_data);

$reward_total =0;
$reward_total_past2 =0;
$reward_total_past3 =0;
$access_detail ='';
foreach(@kisyu_table){
	$access_su{"$_"} =0;
	$access_get_su{"$_"} =0;
}
foreach $access_one(@access) {
	($date_access,$order_access,$total_access,$reward_access,$access_type,$access_kisyu) = split(/\,/,$access_one);
	unless($access_kisyu){$access_kisyu =$kisyu_table[0];}			#機種のデフォルト
	($type_data,$reward_type)= split(/\//,$access_type);
	
	$kakutei ='---';
	if($reward_access eq '1'){
		if($reward_type){
			$kakutei =$type_data;
		}else{
			$kakutei =int($total_access*$type_data);
		}
		$reward_total +=$kakutei;
		$access_get_su{"$access_kisyu"} ++;
	}
	if($reward_access eq '2'){
		if($reward_type){
			$past2 =$type_data;
		}else{
			$past2 =int($total_access*$type_data);
		}
		$reward_total_past2 +=$past2;
		next;
	}
	if($reward_access eq '3'){
		if($reward_type){
			$past3 =$type_data;
		}else{
			$past3 =int($total_access*$type_data);
		}
		$reward_total_past3 +=$past3;
		next;
	}
	$access_su{"$access_kisyu"} ++;
}

$reward_total =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$reward_total_past2 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$reward_total_past3 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
#====================================
print <<"EOF";
          <TR>
            <TD width="110" bgcolor="#ffffff" rowspan="2" valign=top><b><FONT color='#0e5d7d'>NO.$entry_no</b><a><BR>
           </TD>
            <TD width="100" bgcolor="#ffffff" rowspan="2" valign=top><A href="$script_aff_adm?entry_no=$entry_no&ID_NAME=$identity&PASS_W=$password&mode=renew1&pass=$in{'pass'}"><b><FONT class='link_color'>$identity</font></b></a><br>$password</TD>
            <TD width="100" bgcolor="#ffffff" rowspan="2" valign=top>$name<br>$date</TD>
            <TD colspan="3" width="280" bgcolor="#ffffff">ﾒｰﾙ： <A href="mailto:$name<$mail>?Subject=$mail_title&body=$name様"><FONT class='link_color'>$mail</font></A></TD>
            <TD align="center" bgcolor="#ffffff" width="80">$mag</TD>
          </TR>
          <TR>
            <TD colspan="4" width="360" bgcolor="#ffffff">URL： $url</TD>
          </TR>
          
          <TR>
            <TD width="110" align="center" bgcolor="$color_r">$click{"$kisyu_table[0]"}/$click{"$kisyu_table[1]"}/$click{"$kisyu_table[2]"}/$click{"$kisyu_table[3]"}/$click{"$kisyu_table[4]"}</TD>
            <TD width="100" align="center" bgcolor="$color_r">$access_su{"$kisyu_table[0]"}/$access_su{"$kisyu_table[1]"}/$access_su{"$kisyu_table[2]"}/$access_su{"$kisyu_table[3]"}/$access_su{"$kisyu_table[4]"}</TD>
            <TD width="100" align="center" bgcolor="$color_r">$access_get_su{"$kisyu_table[0]"}/$access_get_su{"$kisyu_table[1]"}/$access_get_su{"$kisyu_table[2]"}/$access_get_su{"$kisyu_table[3]"}/$access_get_su{"$kisyu_table[4]"}</TD>
            <TD width="120" align="right" bgcolor="$color_r">$reward_total円</TD>
            <TD width="120" align="right" bgcolor="$color_r">$reward_total_past2円</TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r">$reward_total_past3円</TD>
          </TR>
          <TR><TD colspan="6" height='2'></TD></TR>
EOF
}

#==============
&whole_total();
#==============
print <<"EOF";
          <TR>
            <TD width="110" align="center" bgcolor="#0e5d7d"><B><FONT color="#ffffff">ｸﾘｯｸ数</FONT></B></TD></TD>
            <TD width="100" align="center" bgcolor="#0e5d7d"><B><FONT color="#ffffff">注文数</FONT></B></TD>
            <TD width="100" align="center" bgcolor="#0e5d7d"><B><FONT color="#ffffff">報酬確定数</FONT></B></TD>
            <TD width="120" align="center" bgcolor="#0e5d7d"><B><FONT color="#ffffff">確定報酬額</FONT></B></TD>
            <TD width="120" align="center" bgcolor="#0e5d7d"><B><FONT color="#ffffff">前回報酬額</FONT></B></TD>
            <TD colspan="2" width="120" align="center" bgcolor="#0e5d7d"><B><FONT color="#ffffff">前々報酬額</FONT></B></TD>
          </TR>
          <TR>
            <TD width="110" align="right" bgcolor="$color_r">
            <table width="110" cellpadding="0" cellspacing="0"><tr><td width="30" align="center"><b>$kisyu_table[0]</b></td><td align="right" width="80"><b>$whole_click{"$kisyu_table[0]"}</b></td></tr></table>
            </TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order{"$kisyu_table[0]"}</b></TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order_get{"$kisyu_table[0]"}</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get{"$kisyu_table[0]"}円</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get_past2{"$kisyu_table[0]"}円</b></TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r"><b>$whole_get_past3{"$kisyu_table[0]"}円</b></TD>
          </TR>
          <TR>
            <TD width="110" align="right" bgcolor="$color_r">
            <table width="110" cellpadding="0" cellspacing="0"><tr><td width="40" align="center"><b>$kisyu_table[1]</b></td><td align="right" width="70"><b>$whole_click{"$kisyu_table[1]"}</b></td></tr></table>
            </TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order{"$kisyu_table[1]"}</b></TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order_get{"$kisyu_table[1]"}</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get{"$kisyu_table[1]"}円</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get_past2{"$kisyu_table[1]"}円</b></TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r"><b>$whole_get_past3{"$kisyu_table[1]"}円</b></TD>
          </TR>

          <TR>
            <TD width="110" align="right" bgcolor="$color_r">
            <table width="110" cellpadding="0" cellspacing="0"><tr><td width="55" align="center"><b>$kisyu_table[2]</b></td><td align="right" width="55"><b>$whole_click{"$kisyu_table[2]"}</b></td></tr></table>
            </TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order{"$kisyu_table[2]"}</b></TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order_get{"$kisyu_table[2]"}</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get{"$kisyu_table[2]"}円</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get_past2{"$kisyu_table[2]"}円</b></TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r"><b>$whole_get_past3{"$kisyu_table[2]"}円</b></TD>
          </TR>
          <TR>
            <TD width="110" align="right" bgcolor="$color_r">
            <table width="110" cellpadding="0" cellspacing="0"><tr><td width="40" align="center"><b>$kisyu_table[3]</b></td><td align="right" width="70"><b>$whole_click{"$kisyu_table[3]"}</b></td></tr></table>
            </TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order{"$kisyu_table[3]"}</b></TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order_get{"$kisyu_table[3]"}</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get{"$kisyu_table[3]"}円</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get_past2{"$kisyu_table[3]"}円</b></TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r"><b>$whole_get_past3{"$kisyu_table[3]"}円</b></TD>
          </TR>
          <TR>
            <TD width="110" align="right" bgcolor="$color_r">
            <table width="110" cellpadding="0" cellspacing="0"><tr><td width="40" align="center"><b>$kisyu_table[4]</b></td><td align="right" width="70"><b>$whole_click{"$kisyu_table[4]"}</b></td></tr></table>
            </TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order{"$kisyu_table[4]"}</b></TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order_get{"$kisyu_table[4]"}</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get{"$kisyu_table[4]"}円</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get_past2{"$kisyu_table[4]"}円</b></TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r"><b>$whole_get_past3{"$kisyu_table[4]"}円</b></TD>
          </TR>
          <TR>
            <TD width="110" align="right" bgcolor="$color_r">
            <table width="110" cellpadding="0" cellspacing="0"><tr><td width="40" align="center"><b>合計</b></td><td align="right" width="70"><b>$whole_click</b></td></tr></table>
            </TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order</b></TD>
            <TD width="100" align="right" bgcolor="$color_r"><b>$whole_order_get</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get円</b></TD>
            <TD width="120" align="right" bgcolor="$color_r"><b>$whole_get_past2円</b></TD>
            <TD colspan="2" width="120" align="right" bgcolor="$color_r"><b>$whole_get_past3円</b></TD>
          </TR>

        </TBODY>
      </TABLE>
      </TD>
    </TR>
  </TBODY>
</TABLE>
<TABLE width="$t_width">
  <TBODY>
    <TR><TD align=left>
    ★会員ＩＤをクリック⇒会員の情報変更。クリック数が多い順に表\示されます。
    </TD></TR>
  </TBODY>

EOF
#===========================================

        $nextlink = "";
		if ($next_num ne '') {
			$nextlink = "<a href=\"$modoru&FF=$next_num\"><font color='#0000ff'>次の$over_no件<font></a>";
		}
		
		$backlink = "";
		$back_num = $ff_no -$aff_page;
		if($back_num >=0) {
			$backlink = "<a href=\"$modoru&FF=$back_num\"><font color='#0000ff'>前の$aff_page件</font></a>\　\　\　";
		}
	   	print "<center><table><tr><td>$backlink$nextlink</td></tr></table></center>\n";

	print "<p>$foot</body></html>\n" ;

}

#=======================================================
sub whole_total_pre{

		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);
		$i =0;
		@click = split(/\,/,$click);
		foreach(@kisyu_table){
			$click{"$_"} =$click[$i];
			unless($click{"$_"}){$click{"$_"} =0;}
			$i ++;
		}
#=================報酬額の計算============================================
$access_data =~ s/\r\n//g;
$access_data =~ s/\r//g;
$access_data =~ s/\n//g;

@access = split(/\:/,$access_data);

foreach(@kisyu_table){
$access_get_su{"$_"} =0;
$reward_total{"$_"} =0;
$reward_total_past2{"$_"} =0;
$reward_total_past3{"$_"} =0;
$access_detail{"$_"} ='';
$access_su{"$_"} =0;
}

foreach $access_one(@access) {
	($date_access,$order_access,$total_access,$reward_access,$access_type,$access_kisyu) = split(/\,/,$access_one);
	unless($access_kisyu){$access_kisyu =$kisyu_table[0];}			#機種のデフォルト
	($type_data,$reward_type)= split(/\//,$access_type);
	
	$kakutei ='---';
	if($reward_access eq '1'){
		if($reward_type){
			$kakutei =$type_data;
		}else{
			$kakutei =int($total_access*$type_data);
		}
		$reward_total{"$access_kisyu"} +=$kakutei;
		$access_get_su{"$access_kisyu"} ++;
	}
	if($reward_access eq '2'){
		if($reward_type){
			$past2 =$type_data;
		}else{
			$past2 =int($total_access*$type_data);
		}
		$reward_total_past2{"$access_kisyu"} +=$past2;
		next;
	}
	if($reward_access eq '3'){
		if($reward_type){
			$past3 =$type_data;
		}else{
			$past3 =int($total_access*$type_data);
		}
			$reward_total_past3{"$access_kisyu"} +=$past3;
		next;
	}
	$access_su{"$access_kisyu"} ++;
}

foreach(@kisyu_table){

$whole_click{"$_"} +=$click{"$_"};
$whole_order{"$_"} +=$access_su{"$_"};
$whole_order_get{"$_"} +=$access_get_su{"$_"};
$whole_get{"$_"} +=$reward_total{"$_"};
$whole_get_past2{"$_"} +=$reward_total_past2{"$_"};
$whole_get_past3{"$_"} +=$reward_total_past3{"$_"};
}

}
#=========================アクセス全総計================
sub whole_total{

foreach(@kisyu_table){
$whole_click += $whole_click{"$_"};
$whole_order += $whole_order{"$_"};
$whole_order_get += $whole_order_get{"$_"};
$whole_get += $whole_get{"$_"};
$whole_get_past2 += $whole_get_past2{"$_"};
$whole_get_past3 += $whole_get_past3{"$_"};
}

foreach(@kisyu_table){
$whole_get{"$_"} =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$whole_get_past2{"$_"} =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$whole_get_past3{"$_"} =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
}

$whole_get =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$whole_get_past2 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$whole_get_past3 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理

}
#=======================================================
sub read_list{

&get_file_name();

if (-e $list_file) {

	if (!open(IN,"$list_file")) { &error("ファイルオープンエラー",'指定された書込みファイルが開けません。');}
	@BASE = <IN>;
	close(IN);

	$exist_flag = 0;
	foreach(@BASE) {
		($personal_data,$click,$access_data) = split(/\<\>/,$_);
		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);
		$i =0;
		@click = split(/\,/,$click);
		foreach(@kisyu_table){
			$click{"$_"} =$click[$i];
			unless($click{"$_"}){$click{"$_"} =0;}
			$i ++;
		}
		
    	if($in{'ID_NAME'} eq $identity){
			$exist_flag =1;
			if($in{'PASS_W'} eq $password){$exist_flag =2;}
			last;
    	}
	}
}else{ $read_error = 1; $exist_flag = 0;}

}
#===============================================================

sub search {
	
	$x =100;
	while($x < 200){
		$number1 =substr("$x",1,1);
		$number2 =substr("$x",2,1);
		$list_file =$aff_list.'/'.$number1.$number2.'.cgi';
		
		&read_all();
		if($exist_flag ne 0){ last;}
		
		$x ++;
	}
}

sub read_all{

if (-e $list_file) {

	if (!open(IN,"$list_file")) { &error("ファイルオープンエラー",'指定された書込みファイルが開けません。');}
	@BASE = <IN>;
	close(IN);

	$exist_flag = 0;
	foreach(@BASE) {
		($personal_data,$click,$access_data) = split(/\<\>/,$_);
		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);
		$i =0;
		@click = split(/\,/,$click);
		foreach(@kisyu_table){
			$click{"$_"} =$click[$i];
			unless($click{"$_"}){$click{"$_"} =0;}
			$i ++;
		}

    	if($in{'ID_NAME'} eq $identity){$exist_flag =1;last;}
		if($in{'MAIL'} eq $mail){$exist_flag =2;last;}
			
	}
}else{ $read_error = 1; $exist_flag = 0;}


}
#===============================================================
sub get_file_name{

$letter =substr($in{'ID_NAME'},0,1);
&letter_number();
$number1 =$number;

$letter =substr($in{'ID_NAME'},1,1);
&letter_number();
$number2 =$number;

$list_file =$aff_list.'/'.$number1.$number2.'.cgi';
$aff_lock_file =$aff_lock.'/'.$number1.$number2.'.lock';

}
sub letter_number{

	if($letter =~ /[ab]+/){
		$number =0;
	}elsif($letter =~ /[cd]+/){
		$number =1;
	}elsif($letter =~ /[e-g]+/){
	    $number =2;
	}elsif($letter =~ /[h-l]+/){
	    $number =3;
	}elsif($letter =~ /[m-o]+/){
	    $number =4;
	}elsif($letter =~ /[p-r]+/){
	    $number =5;
	}elsif($letter =~ /[s]+/){
	    $number =6;
	}elsif($letter =~ /[t-z]+/){
	    $number =7;
	}elsif($letter =~ /[A-L]+/){
	    $number =8;
	}elsif($letter =~ /[M-Z]+/){
	    $number =9;
	}elsif($letter =~ /[0-9]+/){
		$number =$letter;
	}else{
	    $number =9;
	}
}
#========================================================================================
sub mail_magazine{
if ( $in{'pass'} ne $aff_password ) { print "Location: $script_aff_adm?mode=adm1\n\n"; exit; }

#=======================送信開始ファイル番号
if($in{'kei'}){$next_no_file =$next_no_k_file;}
if($in{'kei'}){$mag_file =$mag_k_file;}

if(-e $mag_file){
open (IN,"$mag_file") || &error('ファイルオープンエラーMAG','指定された書込みファイルが開けません。');
@MAG = <IN>;
close (IN);
}

($in{'magazine_subject'},$in{'magazine_head'},$in{'magazine_mess'},$in{'magazine_foot'}) =@MAG;
if($in{'magazine_subject'}){
	$in{'magazine_subject'} =~ s/\n//g;
	$in{'magazine_head'} =~ s/\n//g;
	$in{'magazine_mess'} =~ s/\n//g;
	$in{'magazine_foot'} =~ s/\n//g;
	$in{'magazine_subject'} =~ s/<br>/\n/g;
	$in{'magazine_head'} =~ s/<br>/\n/g;
	$in{'magazine_mess'} =~ s/<br>/\n/g;
	$in{'magazine_foot'} =~ s/<br>/\n/g;
	
	$aff_mag_title =$in{'magazine_subject'};
	$aff_mag_header =$in{'magazine_head'};
	$aff_mag_footer =$in{'magazine_foot'};
	
}
&html_header();

print <<"EOF";
<br>
<form method=post action=$script_aff_adm>
<table bgcolor=$color_r width=$t_width align=center cellpadding=5 border=1 bordercolor=$color_d>
<TR>
<TD align="center" colspan =2 bgcolor="$color_r" height="22"><B>メールマガジンの作成(PC用)</B></TD></TR>
<TR>
	<TD align="center" width="150"bgcolor="$color_r" height="22"><B>送信者名</B></TD>
	<TD bgcolor="#ffffff" height="22">$aff_mag_name</TD>
	</TR>
<tr><TD align="center" width="150"bgcolor="$color_r" height="20"><B>送信者のメール</B></TD>
	 <TD bgcolor="#ffffff" height="20">$aff_mag_mail</TD>
	</TR>

<TR>
	<TD align="center" width="130"bgcolor="$color_r" height="22"><B>送信テーマ</B></TD>
	<TD bgcolor="#ffffff" height="22"><FONT color=#333399><INPUT size=45 name=magazine_subject value="$aff_mag_title"></FONT></TD>
	</TR>
<tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジンヘッダー</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2 align=center><TEXTAREA name=magazine_head rows=5 cols=60>$aff_mag_header</TEXTAREA></TD>
	</TR>
<tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジン内容</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2 align=center><TEXTAREA name=magazine_mess rows=30 cols=60>$in{'magazine_mess'}</TEXTAREA></TD>
	</TR><tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジンフッター</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2 align=center><TEXTAREA name=magazine_foot rows=5 cols=60>$aff_mag_footer</TEXTAREA></TD>
	</TR>
<tr><td bgcolor="$color_r" colspan=2><center>
<input type="hidden" name="mode" value="test_magazine">
<br>
<input type="hidden" name="pass" value="$in{'pass'}">
<input type="hidden" name="kei" value="">
<input type=submit value=テスト送信>\　\　<input type=reset value=リセット><BR><br>
</center></td></tr></table>
</form>
<hr width=$t_width noshade size=1>
$foot
</body></html>
EOF


}

#===============================テスト送信===============================
sub test_magazine{
if($in{'kei'}){
	$t_width ='450';
	$next_no_file =$next_no_k_file;
	$mag_file =$mag_k_file;
}

#=============メールの内容の情報・・・書き込みと取得=======================
@MAG =("$form2{'magazine_subject'}\n","$form2{'magazine_head'}\n","$form2{'magazine_mess'}\n","$form2{'magazine_foot'}\n");
#========書き込み===========================
open (OUT,">$mag_file") || &error('ファイルオープンエラーMAG','指定された書込みファイルが開けません。');
print OUT @MAG;
close (OUT);
#========取得===============================
open (IN,"$mag_file") || &error('ファイルオープンエラーMAG','指定された書込みファイルが開けません。');
@MAG = <IN>;
close (IN);
	

($in{'magazine_subject'},$in{'magazine_head'},$in{'magazine_mess'},$in{'magazine_foot'}) =@MAG;
$in{'magazine_subject'} =~ s/\n//g;
$in{'magazine_head'} =~ s/\n//g;
$in{'magazine_mess'} =~ s/\n//g;
$in{'magazine_foot'} =~ s/\n//g;
$in{'magazine_subject'} =~ s/<br>/\n/g;
$in{'magazine_head'} =~ s/<br>/\n/g;
$in{'magazine_mess'} =~ s/<br>/\n/g;
$in{'magazine_foot'} =~ s/<br>/\n/g;
#=============================================================================

$mailto =$aff_mag_mail;

$fromname =$aff_mag_name;
$frommail =$aff_mag_mail;
$subject =$in{'magazine_subject'};
$from_n_m ="$fromname<$frommail>";
$from_mime = &mimeencode($from_n_m);
$subject_mime = &mimeencode($subject);


$mailbody = <<"END_OF_DATA";
$in{'magazine_head'}

会員名 [会員ID] 様

$in{'magazine_mess'}

$in{'magazine_foot'}
END_OF_DATA
&jcode'convert(*mailbody, "jis");

&magazine_send();

#=======================送信開始ファイル番号
if(-e $next_no_file){
	open (IN,"$next_no_file") || &error('ファイルオープンエラーNEXT_NO.0','指定された書込みファイルが開けません。');
	$next_no = <IN>;
	close (IN);
}else{
	$next_no =0;
}

#==============================================================

&html_header();
print <<"EOF";
	<center>
	<br><table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>テスト送信完了</center></b></td>
	</tr></table><br>
</CENTER>

<table bgcolor=$color_r width=$t_width align=center cellpadding=5 border=1 bordercolor=$color_d>
<TR>
<TD align="center" colspan =2 bgcolor="$color_r" height="22"><B>メールマガジンの作成</B></TD></TR>
<TR>
	<TD align="center" width="150"bgcolor="$color_r" height="22"><B>送信者名</B></TD>
	<TD bgcolor="#ffffff" height="22" width="550">$aff_mag_name</TD>
	</TR>
<tr><TD align="center" width="150"bgcolor="$color_r" height="22"><B>送信者のメール</B></TD>
	 <TD bgcolor="#ffffff" height="20" width="550">$aff_mag_mail</TD>
	</TR>

<TR>
	<TD align="center" width="150" bgcolor="$color_r" height="22"><B>送信テーマ</B></TD>
	<TD bgcolor="#ffffff" height="22" width="550">$in{'magazine_subject'}</TD>
	</TR>
<tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジンヘッダー</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2>$form{'magazine_head'}</TD>
	</TR>
<tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジン内容</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2>$form{'magazine_mess'}</TD>
	</TR><tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジンフッター</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2>$form{'magazine_foot'}</TD>
	</TR>
<tr><td bgcolor="$color_r" colspan=2><center>
<BR><b>メールマガジンをテスト送信しました。</b><br><b>テストメールを確認してからメール一括送信をクリックしてください。</b>
<form method=post action=$script_aff_adm>
<table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
<tr><td bgcolor="$color_r"><center><br>
<input type="hidden" name="magazine_subject" value="$in{'magazine_subject'}">
<input type="hidden" name="magazine_head" value="$in{'magazine_head'}">
<input type="hidden" name="magazine_mess" value="$form{'magazine_mess'}">
<input type="hidden" name="magazine_foot" value="$in{'magazine_foot'}">
<input type="hidden" name="mode" value="send_magazine">
<input type="hidden" name="pass" value="$in{'pass'}">
<input type="hidden" name="kei" value="$in{'kei'}">

<INPUT type='radio' name='spot' value=''><font color='#000099'>全会員</font>
\　\　
<INPUT type='radio' name='spot' value='on' checked><font color='#000099'>スポット送信</font>\　\　
<font color='#000099'>送信開始ファイル番号＝</font><input type='text' STYLE='ime-mode:disabled;' name="start_ff" size=5 value="$next_no" align='right'>
<br><br>

\　\　\　 <input type=submit value=メール一括送信><br><br>
</center></td></tr></table>
</form>
</center></td></tr>
<tr><td colspan=2>
<form method=post action=$script_aff_adm>
<table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
<tr><td bgcolor="$color_r"><center>
※一括送信ボタンを押した後に、送信を中断したいときに使用します。<br><br>
<input type="hidden" name="mode" value="stop">
<input type="hidden" name="pass" value="$in{'pass'}">
<input type=submit value="送信中断"><br><br>
</center></td></tr></table>
</form>

</td></tr>
</table>
<br><hr noshade size=1 width=$t_width><p>$foot</body></html>

EOF

}

#===============================マガジン送信================================
sub send_magazine {
if($in{'kei'}){
	$t_width ='450';
	$next_no_file =$next_no_k_file;
	$mag_file =$mag_k_file;
}
#=============メールの内容の情報取得=======================
open (IN,"$mag_file") || &error('ファイルオープンエラーMAG','指定された書込みファイルが開けません。');
@MAG = <IN>;
close (IN);

($in{'magazine_subject'},$in{'magazine_head'},$in{'magazine_mess'},$in{'magazine_foot'}) =@MAG;
$in{'magazine_subject'} =~ s/\n//g;
$in{'magazine_head'} =~ s/\n//g;
$in{'magazine_mess'} =~ s/\n//g;
$in{'magazine_foot'} =~ s/\n//g;
$in{'magazine_subject'} =~ s/<br>/\n/g;
$in{'magazine_head'} =~ s/<br>/\n/g;
$in{'magazine_mess'} =~ s/<br>/\n/g;
$in{'magazine_foot'} =~ s/<br>/\n/g;

#=========================スポット的メルマガ送信============================
if($in{'spot'}){
open (IN,"$spot_file") || &error('ファイルオープンエラーSopt1','指定された書込みファイルが開けません。');
$spot_data = <IN>;
close (IN);

$spot_data =~ s/\n//g;
@spot_data2 =split(/\,/,$spot_data);

}
#===========================================================================

if($in{'all'}){
	$magazine_all =$in{'all'};
}else{
	$magazine_all =0;
}
if($in{'non'}){
	$magazine_non =$in{'non'};
}else{
	$magazine_non =0;
}

$fromname =$aff_mag_name;
$frommail =$aff_mag_mail;
$subject =$in{'magazine_subject'};
$from_n_m ="$fromname<$frommail>";
$from_mime = &mimeencode($from_n_m);
$subject_mime = &mimeencode($subject);

if($in{'start_ff'}){
	$x =$in{'start_ff'};
	$next_ff =$in{'start_ff'};
}else{
	$x =0;
	$next_ff =0;
}
$x =$x + 100;

$send_kazu =0;
while($x < 200){

if($spot_data eq '' && $in{'spot'} ne ''){$x=200;last;}

	$number1 =substr("$x",1,1);
	$number2 =substr("$x",2,1);
	$list_file =$aff_list.'/'.$number1.$number2.'.cgi';
		
if (-e $list_file) {

	if (!open(IN,"$list_file")) { &error("ファイルオープンエラー",'指定された書込みファイルが開けません。');}
	@BASE = <IN>;
	close(IN);

	foreach(@BASE) {
		($personal_data,$click,$access_data) = split(/\<\>/,$_);
		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);
		$i =0;
		@click = split(/\,/,$click);
		foreach(@kisyu_table){
			$click{"$_"} =$click[$i];
			unless($click{"$_"}){$click{"$_"} =0;}
			$i ++;
		}

$entry_no =~ s/\n//g;
if($entry_no eq ''){next;}

#=========================スポット的メルマガ送信=======================
if($in{'spot'}){
$zero =@spot_data2;
if($zero ==0){$x=200;last;}
$spot_i =0;
$spot_flag =1;
foreach(@spot_data2){
	if($entry_no eq $_){$spot_flag =0;last;}
	$spot_i ++;	
}
if($spot_flag){next;}
splice(@spot_data2, $spot_i, 1);	#送信済みのＮＯを削除
}
#======================================================================

$mag =~ s/\n//g;
if($mag ne 1 && $mag ne '１'){
$mailbody = <<END_OF_DATA;
$in{'magazine_head'}

$name [$identity] 様

$in{'magazine_mess'}

$in{'magazine_foot'}
END_OF_DATA

	&jcode'convert(*mailbody, "jis");

	$mailto =$mail;

	&magazine_send();
	$magazine_all ++;
#==================中断チェック=============
	if (-e $magazine_stop) {
		unlink($magazine_stop);
		&error("メールマガジンの送信を中断しました。送信件数＝$magazine_all件。","ファイル番号 $next_ff の会員に送信中。");
	}
#============================================
$send_kazu ++;
}else{ $magazine_non ++;}

}

}
$x ++;
$next_ff ++;;
if($send_kazu > $aff_mag_no){ last;}		#送信数チェック

}

#=================スポットファイル保存====================
foreach(@spot_data2){
	if($spot_save){
		$spot_save .=",".$_;
	}else{
		$spot_save =$_;
	}
}
if($in{'spot'}){
	open (OUT,">$spot_file") || &error('ファイルオープンエラーspot1','指定された書込みファイルが開けません。');
	print OUT "$spot_save";
	close (OUT);
}
#=========================================================

if($x >= 200){

if(-e $next_no_file){unlink($next_no_file);}

&html_header();
print <<"EOF";
	<center>
	<br><table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>メール一括送信完了</center></b></td>
	</tr></table><br>
</CENTER>

EOF
	print "<br><center><b>会員 $magazine_all名へメールマガジンを送信しました。</b></center>\n";
	print "<br><center><b>（会員 $magazine_non名がメールマガジンの購読を解除しています。）</b></center>\n";

	print "<br><hr noshade size=1 width=$t_width><p>$foot</body></html>\n";
	
exit;
#==================終了====================
}else{

#======
open (OUT,">$next_no_file") || &error('ファイルオープンエラーNEXT_NO1','指定された書込みファイルが開けません。');
print OUT "$next_ff";
close (OUT);

#=============================再描画========================
	print "Content-type: text/html\n\n";
	print "<html><head><title>$main_title</title>\n";
	print "<meta http-equiv=\"REFRESH\" content=\"$aff_mag_time;URL=$script_aff_adm?mode=refresh&start_ff=$next_ff&all=$magazine_all&non=$magazine_non&spot=$in{'spot'}&pass=$in{'pass'}&kei=$in{'kei'}\">\n";
	print "<META content=\"text/html; charset=Shift_JIS\" http-equiv=Content-Type>\n";
	print "<META content=text/css http-equiv=Content-Style-Type>\n";

	print "$style";
	
	print "</head>$body$header\n";

print <<"EOF";
	<center>
	<br><table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>メール一括送信中・・・</center></b></td>
	</tr></table><br>
</CENTER>

EOF
	print "<br><center><b>会員 $magazine_all名へメールマガジンを送信しました。</b></center>\n";
	print "<br><br><center><b>現在、ファイル番号 $next_ff の会員に送信中。</b></center><br>\n";
print <<"EOF";
<table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
<tr><td bgcolor="$color_r"><br><center>
※一括送信ボタンを押した後に、送信を中断したいときに使用します。<br><br>
<form method=post action=$script_aff_adm>
<input type="hidden" name="mode" value="stop">
<input type="hidden" name="pass" value="$in{'pass'}">
<input type=submit value="送信中断"><br>
</form>
</center></td></tr></table>
EOF
	print "<br><hr noshade size=1 width=$t_width><p>$foot</body></html>\n";
}

}
#========================================================================================
sub mail_magazine_k{
$t_width ='450';
#=======================送信開始ファイル番号
$next_no_file =$next_no_k_file;
$mag_file =$mag_k_file;

if(-e $mag_file){
open (IN,"$mag_file") || &error('ファイルオープンエラーMAG','指定された書込みファイルが開けません。');
@MAG = <IN>;
close (IN);
}
($in{'magazine_subject'},$in{'magazine_head'},$in{'magazine_mess'},$in{'magazine_foot'}) =@MAG;
if($in{'magazine_subject'}){
	$in{'magazine_subject'} =~ s/\n//g;
	$in{'magazine_head'} =~ s/\n//g;
	$in{'magazine_mess'} =~ s/\n//g;
	$in{'magazine_foot'} =~ s/\n//g;
	$in{'magazine_subject'} =~ s/<br>/\n/g;
	$in{'magazine_head'} =~ s/<br>/\n/g;
	$in{'magazine_mess'} =~ s/<br>/\n/g;
	$in{'magazine_foot'} =~ s/<br>/\n/g;
	
	$aff_mag_title =$in{'magazine_subject'};
	$aff_mag_header_k =$in{'magazine_head'};
	$aff_mag_footer_k =$in{'magazine_foot'};
	
}
&html_header();

print <<"EOF";
<br>
<form method=post action=$script_aff_adm>
<table bgcolor=$color_r width=$t_width align=center cellpadding=5 border=1 bordercolor=$color_d>
<TR>
<TD align="center" colspan =2 bgcolor="$color_r" height="22"><B>メールマガジンの作成(携帯用)</B></TD></TR>
<TR>
	<TD align="center" width="150"bgcolor="$color_r" height="22"><B>送信者名</B></TD>
	<TD bgcolor="#ffffff" height="22">$aff_mag_name</TD>
	</TR>
<tr><TD align="center" width="150"bgcolor="$color_r" height="20"><B>送信者のメール</B></TD>
	 <TD bgcolor="#ffffff" height="20">$aff_mag_mail</TD>
	</TR>

<TR>
	<TD align="center" width="130"bgcolor="$color_r" height="22"><B>送信テーマ</B></TD>
	<TD bgcolor="#ffffff" height="22"><FONT color=#333399><INPUT size=45 name=magazine_subject value="$aff_mag_title"></TD>
	</TR>
<tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジンヘッダー</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2 align=center><TEXTAREA name=magazine_head rows=5 cols=60>$aff_mag_header_k</TEXTAREA></TD>
	</TR>
<tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジン内容</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2 align=center><TEXTAREA name=magazine_mess rows=30 cols=60>$in{'magazine_mess'}</TEXTAREA></TD>
	</TR><tr><TD align="center" bgcolor="$color_r" height="20" COLSPAN=2><B>マガジンフッター</B></TD></TR><TR>
	 <TD bgcolor="#ffffff" height="20" COLSPAN=2 align=center><TEXTAREA name=magazine_foot rows=5 cols=60>$aff_mag_footer_k</TEXTAREA></TD>
	</TR>
<tr><td bgcolor="$color_r" colspan=2><center>
<input type="hidden" name="mode" value="test_magazine">
<br>
<input type="hidden" name="pass" value="$in{'pass'}">
<input type="hidden" name="kei" value="1">
<input type=submit value=テスト送信>\　\　<input type=reset value=リセット><BR><br>
</center></td></tr></table>
</form>
<hr width=$t_width noshade size=1>
$foot
</body></html>
EOF

}

#===========================メールを送信する========================
#///////////////////////////////////////////////////////////////////
sub magazine_send{
if ($testkey == 0) { return; }

if($sendmail =~ /sendmail/i){		#sendmail使用

$mailhead = "To: $mailto\n";
$mailhead .= "From: $from_mime\n";
$mailhead .= "Subject: $subject_mime\n";
$mailhead .= "MIME-Version: 1.0\n";
$mailhead .= "Content-Type: text/plain;charset=\"ISO-2022-JP\"\n";
$mailhead .= "Content-Transfer-Encoding: 7bit\n";
$mailhead .= "\n";

if (-x $sendmail) {
	unless (open(OUT, "| $sendmail -t -f $frommail")) {
	    &mail_err();
	}
	unless (print OUT $mailhead) {
	    &mail_err();
	}
	unless (print OUT $mailbody) {
	    &mail_err();
	}
	close(OUT);
} else {
	&mail_err();
	&error("$sendmailがありません。(22)");
}

}else{			#SMTP使用：Windowsサーバ

	$mail_server =$sendmail;
	&send_mail($mail_server, $frommail, $mailto, $subject, $mailbody);	

}

}

#///////////////////////////////////////////////////////////////////
sub mail_error {
	&error("メールの送信に失敗しました。ブラウザの [戻る] ボタンで戻ってください。");
}

#==================================================================
sub renew1{

&read_list();
if($exist_flag == 0){&error("会員ＩＤが間違っています。"); exit;}
if($exist_flag == 1){&error("パスワードが間違っています。"); exit;}

$access_data =~ s/\r\n//g;
$access_data =~ s/\r//g;
$access_data =~ s/\n//g;
@access = split(/\:/,$access_data);

#==========================================
$access_get_su =0;
$reward_total =0;
$reward_total_past2 =0;
$reward_total_past3 =0;
$access_su =0;
foreach $access_one(@access) {
	($date_access,$order_access,$total_access,$reward_access,$access_type) = split(/\,/,$access_one);
	
	($type_data,$reward_type)= split(/\//,$access_type);
	
	if($reward_access eq '1'){
		if($reward_type){
			$kakutei =$type_data;
		}else{
			$kakutei =int($total_access*$type_data);
		}
		$reward_total +=$kakutei;
		$access_get_su ++;
	}
	if($reward_access eq '2'){
		if($reward_type){
			$past2 =$type_data;
		}else{
			$past2 =int($total_access*$type_data);
		}
		$reward_total_past2 +=$past2;
		next;
	}
	if($reward_access eq '3'){
		if($reward_type){
			$past3 =$type_data;
		}else{
			$past3 =int($total_access*$type_data);
		}
		$reward_total_past3 +=$past3;
		next;
	}
	$access_su ++;
}
$reward_total =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$reward_total_past2 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$reward_total_past3 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
#===========================================
$access_data =~ s/\:/\:\n/g;

&html_header();

	print <<"EOF";
<BR><form name ="F1" method="post" action="$script_aff_adm" enctype="multipart/form-data" onSubmit="return kakunin()">
	<table bgcolor=$color_adm_d border=0 cellspacing=0 cellpadding=0 align=center width=$t_width><tr><td>
	<table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>会員情報変更</center></b></td>
	</tr></table></td></tr></table>
	<table border="0" cellpadding="10" align="center" cellspacing="1" width=$t_width>
	<tr><td valign=top>
	<table bgcolor=$color_adm_d border=0 cellspacing=0 cellpadding=0 align=center width=$t_width><tr><td>
	<table border=0 cellspacing=1 cellpadding=2 width="$t_width" align=center>
EOF

	print <<"EOF";
	<tr> 
	<td nowrap bgcolor="$color_r"><b>登録番号</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$entry_no
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>登録日付</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$date
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>会員ＩＤ</b></td>
	<td bgcolor=#FFFFFF> 
	$identity
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>パスワード</b></td>
	<td bgcolor=#FFFFFF> 
	<input  STYLE='ime-mode:disabled;' maxLength=10 type="password" SIZE=35 name="PASS_W" value="$password"><br>
	<font color="#ff0000">※英数半角で４文字以上１０文字以内。</font>
	</td>
	</tr>
EOF

	print <<"EOF";
<tr><td height='4'></td></tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>お名前</b></td>
	<td bgcolor=#FFFFFF> 
	<input type="text" SIZE=35 name="NAME" value="$name"><br>
	<font color="#ff0000">※実在のお名前。</font>
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>ﾒｰﾙｱﾄﾞﾚｽ</b></td>
	<td bgcolor=#FFFFFF> 
	<input  STYLE='ime-mode:disabled;' type="text" SIZE=35 name="MAIL"  value="$mail"><br>
	<font color="#ff0000">※連絡用メールアドレス。</font>
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>ホームページURL</b></td>
	<td bgcolor=#FFFFFF> 
	<input  STYLE='ime-mode:disabled;' type="text" SIZE=45 name="URL" value="$url"><br>
	</td></tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>ﾒｰﾙﾏｶﾞｼﾞﾝ購読拒否</b></td>
	<td bgcolor=#FFFFFF> 
	<input  STYLE='ime-mode:disabled;' type="text" SIZE=15 name="MAG" value="$mag"><br>
	<font color="#ff0000">※1のときは購読拒否。</font>
	</td></tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>その他１</b></td>
	<td bgcolor=#FFFFFF> 
	<input type="text" SIZE=45 name="AUX1" value="$aux1"><br>
	</td></tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>その他２</b></td>
	<td bgcolor=#FFFFFF> 
	<input type="text" SIZE=45 name="AUX2" value="$aux2"><br>
	</td></tr>
	
<tr><td height='4'></td></tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>クリック総数</b></td>
	<td bgcolor=#FFFFFF width="550">$kisyu_table[0]⇒$click{"$kisyu_table[0]"}回  $kisyu_table[1]⇒$click{"$kisyu_table[1]"}回  $kisyu_table[2]⇒$click{"$kisyu_table[2]"}回  $kisyu_table[3]⇒$click{"$kisyu_table[3]"}回  $kisyu_table[4]⇒$click{"$kisyu_table[4]"}回
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>注文数</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$access_su件(アフィリエイト経由での注文数。報酬請求済みの分は除く。)
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>報酬確定数</b></td>
	<td bgcolor=#FFFFFF> 
	$access_get_su件(前回の報酬請求以降の報酬確定数)
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>確定報酬額</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$reward_total円
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>前回の報酬額</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$reward_total_past2円
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>前々回の報酬額</b></td>
	<td bgcolor=#FFFFFF> 
	$reward_total_past3円
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>アクセスデータ</b></td>
	<td bgcolor=#FFFFFF> 
	<TEXTAREA rows="20" cols="48" name='new_data'>$access_data</TEXTAREA><br>
	<font color="#ff0000">※ｱｸｾｽ時間,注文番号,購入総額,報酬確定,報酬率/報酬の形態:</font><br>
	<font color="#ff0000">※報酬確定=0(見込み)、1(確定)、2(請求済)、3(前回請求済)、c(ｷｬﾝｾﾙ)。3及びcは請求時に自動的に削除されます。</font><br>
	<font color="#ff0000">※報酬の形態=0又はブランク(％)、1(定額)。</font><br>
	</td></tr>
	
	<tr><td colspan=2 bgcolor=#FFFFFF></td></tr>
	<tr><td colspan=2 bgcolor=#FFFFFF>
	<input type="hidden" name="ENTRY_NO" value="$entry_no">
	<input type="hidden" name="ID_NAME" value="$identity">
	<input type="hidden" name="click" value="$click">
	<input type="hidden" name="DATE" value="$date">
	<input type="hidden" name="mode" value="renew2">
	<input type="hidden" name="pass" value="$in{'pass'}">
	<input type="submit" value="情報変更[確認]">\　
	<input type="reset" value="クリア">
	</td></tr>
	<TR><TD  colspan=2 bgcolor=#FFFFFF>★お名前をブランクにすると会員データを削除することができます。
	</TD></TR>
</table>
	</td></tr></table>
	</td></tr></table>
	</form>
EOF

#=======================入力チェック===================================
	print <<"EOF";
<SCRIPT LANGUAGE="JavaScript">
<!--
function kakunin(){
  x=document.F1.ID_NAME.value;
  y =x.length;
  if (document.F1.ID_NAME.value == "" || y < 4) {
    alert("会員ＩＤが正しくありません。");
    document.F1.ID_NAME.focus();
    return(false);
  }
  x=document.F1.PASS_W.value;
  z =x.length;
  if (document.F1.PASS_W.value == "" || z < 4) {
    alert("パスワードが正しくありません。");
    document.F1.PASS_W.focus();
    return(false);
  }
  if (document.F1.NAME.value == "") {
		if (!(confirm("会員情報を削除しますか？"))) {
		   return(false);
		}
  }
  if (document.F1.MAIL.value == "") {
    alert("メールアドレスが入力されていません。");
    document.F1.MAIL.focus();
    return(false);
  }

}
// -->
</SCRIPT>
EOF


print "<p>$foot</body></html>\n" ;

}

sub renew2{
if ($in{'MAIL'} ne "" && $in{'MAIL'} !~ /[\w\.\-]+\@[\w\.\-]+\.[a-zA-Z]{2,5}$/) {
	&error("ブラウザの [戻る] ボタンで戻って、メールアドレスを確認してください。");
}
if ($in{'PASS'} ne "" && $in{'PASS'} =~ /[^a-zA-Z0-9]/) {
	&error("ブラウザの [戻る] ボタンで戻って、パスワードを確認してください。");
}

if($in{"NAME"}){
	$sousinn_botton ='情報変更[送信]';
	$midashi ='会員情報変更確認';
}else{
	$sousinn_botton ='情報削除[送信]';
	$midashi ='会員情報削除確認';
}

#==========================================
$i =0;
@click = split(/\,/,$in{'click'});
foreach(@kisyu_table){
	$click{"$_"} =$click[$i];
	unless($click{"$_"}){$click{"$_"} =0;}
	$i ++;
}

$access_data =$in{'new_data'};
$access_data =~ s/\r\n//g;
$access_data =~ s/\r//g;
$access_data =~ s/\n//g;
@access = split(/\:/,$access_data);

$access_get_su =0;
$reward_total =0;
$reward_total_past2 =0;
$reward_total_past3 =0;
$access_su =0;
foreach $access_one(@access) {
	($date_access,$order_access,$total_access,$reward_access,$access_type) = split(/\,/,$access_one);
	
	($type_data,$reward_type)= split(/\//,$access_type);
	
	if($reward_access eq '1'){
		if($reward_type){
			$kakutei =$type_data;
		}else{
			$kakutei =int($total_access*$type_data);
		}
		$reward_total +=$kakutei;
		$access_get_su ++;
	}
	if($reward_access eq '2'){
		if($reward_type){
			$past2 =$type_data;
		}else{
			$past2 =int($total_access*$type_data);
		}
		$reward_total_past2 +=$past2;
		next;
	}
	if($reward_access eq '3'){
		if($reward_type){
			$past3 =$type_data;
		}else{
			$past3 =int($total_access*$type_data);
		}
		$reward_total_past3 +=$past3;
		next;
	}
	$access_su ++;
}
$reward_total =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$reward_total_past2 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
$reward_total_past3 =~ s/(.*\d)(\d\d\d)/$1,$2/g; #桁カンマを入れる処理
#===========================================

&html_header();
print <<"EOF";
<CENTER>
<br><table border=0 cellspacing=0 cellpadding=5 align=center width="$t_width">
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>$midashi</center></b></td>
	</tr></table><br>
</CENTER>
EOF

print <<"EOF";
<CENTER>
<form name ="F1" method="post" action="$script_aff_adm" enctype="multipart/form-data">
<TABLE bgcolor="$color_d" border=0 width="$t_width" cellpadding="0" cellspacing=0><tr><td>
<TABLE bgcolor="$color_d" border=0 cellpadding="2" cellspacing=1 width="$t_width">
<TBODY>
<TR>
	<TD width="150"bgcolor="$color_r" height="22"><B>登録番号</B></TD>
	<TD bgcolor="#ffffff" width="$ajust" height="22" width="550">$in{"ENTRY_NO"}</TD>
	</TR>
<TR>
	<TD width="150"bgcolor="$color_r" height="22"><B>会員日付</B></TD>
	<TD bgcolor="#ffffff" width="$ajust" height="22" width="550">$in{"DATE"}</TD>
	</TR>
<TR>
	<TD width="150"bgcolor="$color_r" height="22"><B>会員ＩＤ</B></TD>
	<TD bgcolor="#ffffff" width="$ajust" height="22" width="550">$in{"ID_NAME"}</TD>
	</TR>
<TR>
	<TD width="150"bgcolor="$color_r" height="20"><B>パスワード</B></TD>
	 <TD bgcolor="#ffffff" height="20" width="550">$in{"PASS_W"}</TD>
	</TR>
EOF

	print <<"EOF";
<TR>
	<TD width="150"bgcolor="$color_r"><B>お名前</B></TD>
	<TD bgcolor="#ffffff" width="550">$in{"NAME"}</FONT></TD>
</TR>

<TR>
	<TD width="150"bgcolor="$color_r"><B>メール</B></TD>
	<TD bgcolor="#ffffff" width="550">$in{"MAIL"}</FONT></TD>
</TR>
<TR>
	<TD width="150"bgcolor="$color_r"><B>URL</B></TD>
	<TD bgcolor="#ffffff" width="550">$in{"URL"}</TD>
	</TR>
<TR>
	<TD width="150"bgcolor="$color_r"><B>購読拒否</B></TD>
	<TD bgcolor="#ffffff" width="550">$in{"MAG"}</TD>
	</TR>
<TR>
	<TD width="150"bgcolor="$color_r"><B>その他１</B></TD>
	<TD bgcolor="#ffffff" width="550">$in{"AUX1"}</TD>
	</TR>
<TR>
	<TD width="150"bgcolor="$color_r"><B>その他２</B></TD>
	<TD bgcolor="#ffffff" width="550">$in{"AUX2"}</TD>
	</TR>
<tr><td height='4'></td></tr>
	<tr>
	<td nowrap bgcolor="$color_r"><b>クリック総数</b></td>
	<td bgcolor=#FFFFFF width="550">$kisyu_table[0]⇒$click{"$kisyu_table[0]"}回  $kisyu_table[1]⇒$click{"$kisyu_table[1]"}回  $kisyu_table[2]⇒$click{"$kisyu_table[2]"}回  $kisyu_table[3]⇒$click{"$kisyu_table[3]"}回  $kisyu_table[4]⇒$click{"$kisyu_table[4]"}回
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>注文数</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$access_su件(アフィリエイト経由での注文数。報酬請求済みの分は除く。)
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>報酬確定数</b></td>
	<td bgcolor=#FFFFFF> 
	$access_get_su件(前回の報酬請求以降の報酬確定数)
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>確定報酬額</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$reward_total円
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>前回の報酬額</b></td>
	<td bgcolor=#FFFFFF width="550"> 
	$reward_total_past2円
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>前々回の報酬額</b></td>
	<td bgcolor=#FFFFFF> 
	$reward_total_past3円
	</td>
	</tr>
	<tr> 
	<td nowrap bgcolor="$color_r"><b>アクセスデータ</b></td>
	<td bgcolor=#FFFFFF> 
	<TEXTAREA rows="10" cols="45" name='new_data_2' disabled>$in{"new_data"}</TEXTAREA><br>
	</td></tr>
	<tr><td colspan=2 bgcolor=#FFFFFF></td></tr>
	<tr><td colspan=2 bgcolor=#FFFFFF>
<input type="hidden" name="new_data" value="$in{'new_data'}">
<input type="hidden" name="ENTRY_NO" value="$in{'ENTRY_NO'}">
<input type="hidden" name="click" value="$in{'click'}">
<input type="hidden" name="ID_NAME" value="$in{'ID_NAME'}">
<input type="hidden" name="PASS_W" value="$in{'PASS_W'}">
<input type="hidden" name="NAME" value="$in{'NAME'}">
<input type="hidden" name="MAIL" value="$in{'MAIL'}">
<input type="hidden" name="AUX1" value="$in{'AUX1'}">
<input type="hidden" name="AUX2" value="$in{'AUX2'}">
<input type="hidden" name="URL" value="$in{'URL'}">
<input type="hidden" name="MAG" value="$in{'MAG'}">
<input type="hidden" name="DATE" value="$in{'DATE'}">
<input type="hidden" name="mode" value="renew3">
<input type="hidden" name="pass" value="$in{'pass'}">
<INPUT type="submit" value="$sousinn_botton"><BR>
</TD></TR></TBODY>
</TABLE>
</TD></TR></table>
</FORM>

EOF

	print "<p>$foot</body></html>\n" ;	

}

sub renew3{

&get_file_name();

#=====ロック処理=======================
if ($lockkey ne 0) { &lock_aff(); }

&read_list();
if($exist_flag == 0){&error("会員ＩＤが間違っています。"); exit;}

	$exist_flag = 0;
	foreach $member_data(@BASE) {
	
		($personal_data,$click,$access_data) = split(/\<\>/,$member_data);
		($entry_no,$identity,$password,$name,$mail,$url,$mag,$date,$aux1,$aux2,$aux3,$aux4) = split(/\,/,$personal_data);

		if($entry_no eq '' || $entry_no eq "\n"){next;}

    	if($in{'ID_NAME'} eq $identity){
    		unless($in{'NAME'}){next;}		#削除
    		
			$in{'new_data'} =~ s/\n//g;
			
			$member_data = "$entry_no,$in{'ID_NAME'},$in{'PASS_W'},$in{'NAME'},$in{'MAIL'},$in{'URL'},$in{'MAG'},$date,$in{'AUX1'},$in{'AUX2'},$aux3,$aux4<>$in{'click'}<>$in{'new_data'}\n"
    	}
    	
    	push (@NEW,$member_data); 

	}

open (OUT,">$list_file") || &error("ファイルオープンエラー",'指定された書込みファイルが開けません。');
print OUT (@NEW);
close (OUT);

#=====ファイルロック解除===============

if ($lockflag) { &unlock_aff; }
if($in{'NAME'}){
	$henkou_sakuzyo ='会員情報変更';
}else{
	$henkou_sakuzyo ='会員削除変更';
}

&html_header();
	
print <<"EOF";
	<center>
	<br><table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>$henkou_sakuzyo完了</center></b></td>
	</tr></table><br>
</CENTER>

EOF
	print "<br><center><b>$in{'NAME'} [$in{'ID_NAME'}] 様の$henkou_sakuzyoが完了しました。</b></center>\n";

	print "<br><hr noshade size=1 width=$t_width><p>$foot</body></html>\n" ;	

}

#======メールを送信する===========
#
#///////////////////////////////////////////////////////////////////
sub mail_send{
if ($testkey == 0) { return; }

if($sendmail =~ /sendmail/i){		#sendmail使用

$from_n_m ="$fromname<$frommail>";
$from_mime = &mimeencode($from_n_m);
$subject_mime = &mimeencode($subject);
&jcode'convert(*mailbody, "jis");

$mailhead = "To: $mailto\n";
$mailhead .= "From: $from_mime\n";
$mailhead .= "Subject: $subject_mime\n";
$mailhead .= "MIME-Version: 1.0\n";
$mailhead .= "Content-Type: text/plain;charset=\"ISO-2022-JP\"\n";
$mailhead .= "Content-Transfer-Encoding: 7bit\n";
$mailhead .= "\n";

if (-x $sendmail) {
	unless (open(OUT, "| $sendmail -t -f $frommail")) {
	    &mail_err();
	}
	unless (print OUT $mailhead) {
	    &mail_err();
	}
	unless (print OUT $mailbody) {
	    &mail_err();
	}
	close(OUT);
} else {
	&mail_err();
	&error("$sendmailがありません。(22)");
}

}else{			#SMTP使用：Windowsサーバ

	$mail_server =$sendmail;
	&send_mail($mail_server, $frommail, $mailto, $subject, $mailbody);	

}

}
#=====SMTPサブルーチン=======
sub send_mail {
	(my $SMTPserver,my $from,my $to,local $subj,local $body) = @_;	# 引数の受信
	my $SMTP;

	&jcode'convert(*subj,'jis');			# 文字化けするので、変換
	&jcode'convert(*body,'jis');			# 同上。

	# オブジェクトの作成
	$SMTP = Net::SMTP -> new( $SMTPserver,		# SMTPサーバー名を指定
				Hello => $SMTPserver,	# SMTPドメイン名を指定
				Timeout => 60);		# 接続待ち許容時間（秒）
	#ヘッダ部の組み立て
	$SMTP -> mail($from);				# 送信元メールアドレスを指定
	$SMTP -> to($to);				# 宛先メールアドレスを指定
#	$SMTP -> cc($cc);				# CC(カーボンコピー)先メールアドレスを指定
#	$SMTP -> bcc($from);				# ブラインドCC先メールアドレスを指定（送信元にもBccでメールを送る）Bcc不要時、コメント行にする。

	#データ部の組み立て
	$SMTP -> data();
	$SMTP -> datasend("From:$from\n");		# 送信元(データ部）
	$SMTP -> datasend("To:$to\n");			# 宛先(データ部）
	$SMTP -> datasend("Subject:$subj\n");		# 件名
	$SMTP -> datasend("\n");
	$SMTP -> datasend("$body\n");			# 本文
	$SMTP -> dataend();				# データ終端、メール送信
	$SMTP -> quit;					# SMTP接続の終了
}
#///////////////////////////////////////////////////////////////////
sub mail_err {
	&error("メールの送信に失敗しました。ブラウザの [戻る] ボタンで戻ってください。");
}

#=========================================================================================

# Cookieに値を書き込むためのSet-Cookie:ヘッダを生成する
#
sub setCookie{
    local($tmp, $val);
    $val = $_[1];
    $val =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;
    $tmp = "Set-Cookie: ";
    $tmp .= "$_[0]=$val; ";
    $tmp .= "expires=Thu, 1-Jan-2050 00:00:00 GMT;\n";
    return($tmp);
}
sub setCookie_0{
    local($tmp, $val);
    $val = $_[1];
    $val =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;
    $tmp = "Set-Cookie: ";
    $tmp .= "$_[0]=$val; ";
    $tmp .= ";\n";
    return($tmp);
}
#
# Cookieの値を読み出す
#
sub getCookie {
    local($xx, $name, $value);
    for $xx (split(/; */, $ENV{'HTTP_COOKIE'})) {
        ($name, $value) = split(/=/, $xx);
        $value =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg;
        $COOKIE{$name} = $value;
    }
}

sub html_header{
	print "Content-type: text/html\n\n";
	print "<html><head><title>$main_title</title>\n";
	print "<META content=\"text/html; charset=Shift_JIS\" http-equiv=Content-Type>\n";
	print "<META content=text/css http-equiv=Content-Style-Type>\n";

	print "$style";
	
	print "</head>$body$header\n";
}
#=================ロック処理===================================
sub lock_aff {
	local($retry)=5;
	# symlink関数式ロック
	if ($lockkey == 1) {
		while (!symlink(".", $aff_lock_file)) {
			if (--$retry <= 0) { &error("Members List is lock."); }
			sleep(1);
		}
	# mkdir関数式ロック
	} elsif ($lockkey == 2) {
		while (!mkdir($aff_lock_file, 0755)) {
			if (--$retry <= 0) { &error("Members List is lock."); }
			sleep(1);
		}
	}
	$lockflag=1;
}
#=====================ロック解除======================
sub unlock_aff {
	if ($lockkey == 1) { unlink($aff_lock_file); }
	elsif ($lockkey == 2) { rmdir($aff_lock_file); }
	$lockflag=0;
}

#=================メルマガ送信中断=============================
sub send_stop{
	if(symlink(".", $magazine_stop)){
	sleep(3);
	unlink($magazine_stop);
	}
	
&html_header();
print <<"EOF";
	<center>
	<br><table border=0 cellspacing=0 cellpadding=5 width="$t_width" align=center>
	<tr> 
	<td bgcolor="$color_r" align=center><b><center>メール一括送信中断</center></b></td>
	</tr></table><br>
</CENTER>

EOF
	print "<br><center><b>メールマガジンの送信を中断いたしました。</b></center>\n";

	print "<br><hr noshade size=1 width=$t_width><p>$foot</body></html>\n";

}

#===============================================================
sub error {
# ファイルロック解除
if (-e $aff_lock_file) { &unlock_aff(); }

&html_header();

	print "<br><center><b>$_[0]</b></center>\n";
	print "<center><b>$_[1]</b></center>\n";

	print "<br><hr noshade size=1 width=$t_width><p>$foot</body></html>\n";
	exit;
}

