<?php
#----------------------------------------------------------#
# チーム
#----------------------------------------------------------#
function teamR(){
global$disp,$Q,$SET;
#--------------------------------------#
# データチェック
#--------------------------------------#
$db=sql_open();
check_id($_COOKIE[id],$_COOKIE[pass]);
$PL=read_data('player',$_COOKIE[id]);
$TM=read_data('team',$_COOKIE[id]);
$title=title('game');
#カードフォーカス
global$CF;$html_cf=ch_focus($_COOKIE[id]);
#--------------------------------------#
# ベンチ/ベンチ外読み込み
#--------------------------------------#
$sql=mysql_query("SELECT * FROM player_card WHERE player_id='$_COOKIE[id]'");
while ($CD=mysql_fetch_assoc($sql)){
	$CD=ch_growth($CD);
	if($CD[38]){
		$D[pl_reg]--;
		if(!$CD[39]){
			if($CD[1]=='P'){
				$CD_RP=read_data('card_res_p',$CD[id]);
				$html_pcsb.="<tr style=\"text-align:center;\"><td><img src=\"$SET[dir_icon]/$CD[6]\" height=\"$SET[icon_h_m]\" title=\"$CD[0]\"></td><td onclick=\"javascript:card_focus('".$CF[$CD[id]]."');\">$CD[0]</td><td>$CD[2]</td><td>".ch_tone($CD[4])."</td><td>".ch_fati($CD[5])."</td><td>".ERA($CD_RP[11],$CD_RP[9])."</td><td>".WHIP($CD_RP[11],($CD_RP[3]+$CD_RP[15]+$CD_RP[16]))."</td>";
				$html_pcsb.="<td>".ch_ptime($CD_RP[11])."</td><td>".AVE($CD_RP[2],$CD_RP[3])."</td></tr>\n";
				#チーム分析用
				$TM_STPN[0]++;
				$TM_STPN[1]+=$CD[21];
				$TM_STPN[2]+=$CD[22];
				$TM_STPN[3]+=$CD[23];
				$TM_STPN[4]+=$CD[24]+$CD[25]+$CD[26]+$CD[27]+$CD[28];
				$TM_STPN[5]+=brk_num($CD);
			}elseif($CD[1]=='B'){
				$CD_RB=read_data('card_res_b',$CD[id]);
				$CD_BAP=explode('!',$CD[40]);
				$ch_OBP=AVE(($CD_RB[2]+$CD_RB[15]+$CD_RB[16]+$CD_RB[17]+$CD_RB[14]),($CD_RB[3]+$CD_RB[15]+$CD_RB[16]+$CD_RB[17]));
				$ch_SLG=AVE($CD_RB[2],$CD_RB[8]);
				$ch_OPS=AVE2(($ch_OBP+$ch_SLG));
				$html_btsb.="<tr style=\"text-align:center;\"><td><img src=\"$SET[dir_icon]/$CD[6]\" height=\"$SET[icon_h_m]\" title=\"$CD[0]\"></td><td onclick=\"javascript:card_focus('".$CF[$CD[id]]."');\">$CD[0]</td><td>$CD[2]</td><td>$CD[3]</td><td>".ch_tone($CD[4])."</td><td>".ch_fati($CD[5])."</td><td>".AVE($CD_RB[2],$CD_RB[3])."</td><td>$ch_OPS</td>";
				$html_btsb.="<td>";
				if($CD_BAP[1]||$CD_BAP[2]||$CD_BAP[3]){
					if($CD_BAP[1]){$html_btsb.="打";}
					if($CD_BAP[2]){$html_btsb.="走";}
					if($CD_BAP[3]){$html_btsb.="守";}
				}else{
					$html_btsb.="-";
				}
				$html_btsb.="</td></tr>\n";
			}
		}
	}
}
#--------------------------------------#
# ローテーション読み込み
#--------------------------------------#
$TM_ROT=explode('!',$PL[25]);
if(data_check('player_card','id',$TM_ROT[0])){
	$i=0;
	foreach($TM_ROT as $CD_ID){
		$CD=read_data('player_card',$CD_ID);
		$CD=ch_growth($CD);
		$CD_RP=read_data('card_res_p',$CD_ID);
		#ローテ色付け
		if(($i+1)==$PL[15]){
			$html_rot.="<tr style=\"text-align:center;background-color:pink;\">";
		}else{
			$html_rot.="<tr style=\"text-align:center;\">";
		}
		#表示
		$html_rot.="<td>".($i+1)."</td><td><img src=\"$SET[dir_icon]/$CD[6]\" height=\"$SET[icon_h_m]\" title=\"$CD[0]\"></td><td onclick=\"javascript:card_focus('".$CF[$CD[id]]."');\">$CD[0]</td><td>$CD[2]</td><td>".ch_tone($CD[4])."</td><td>".ch_fati($CD[5])."</td><td>".ERA($CD_RP[11],$CD_RP[9])."</td><td>".WHIP($CD_RP[11],($CD_RP[3]+$CD_RP[15]+$CD_RP[16]))."</td>";
		$html_rot.="<td>".ch_ptime($CD_RP[11])."</td><td>".AVE($CD_RP[2],$CD_RP[3])."</td></tr>\n";
		#チーム分析用
		$TM_STPS[0]++;
		$TM_STPS[1]+=$CD[21];
		$TM_STPS[2]+=$CD[22];
		$TM_STPS[3]+=$CD[23];
		$TM_STPS[4]+=$CD[24]+$CD[25]+$CD[26]+$CD[27]+$CD[28];
		$TM_STPS[5]+=brk_num($CD);
		$i++;
	}
}
#--------------------------------------#
# オーダー読み込み
#--------------------------------------#
$TM_BT=explode('!',$PL[24]);
$TM_DF=explode('!',$PL[23]);
#打順
for($i=0;$i<=8;$i++){
	if($TM_BT[$i]){
		$CD_BN=$i+1;
		$CD_DF=$TM_BT[$i];
		$CD_ID=$TM_DF[$i];
		$html_bt.="<tr style=\"text-align:center;\"><td>$CD_BN</td><td>".$SET[game_def][$CD_DF]."</td>";
		#選手表示
		if($CD_DF==1){#投手
			$html_bt.="<td colspan=15 style=\"background-color:pink;\">投手</td>";
		}elseif(data_check('player_card','id',$CD_ID)){
			$CD=read_data('player_card',$CD_ID);
			$CD=ch_growth($CD);
			$CD_RB=read_data('card_res_b',$CD[id]);
			$ch_OBP=AVE(($CD_RB[2]+$CD_RB[15]+$CD_RB[16]+$CD_RB[17]+$CD_RB[14]),($CD_RB[3]+$CD_RB[15]+$CD_RB[16]+$CD_RB[17]));
			$ch_SLG=AVE($CD_RB[2],$CD_RB[8]);
			$ch_OPS=AVE2(($ch_OBP+$ch_SLG));
			$html_bt.="<td><img src=\"$SET[dir_icon]/$CD[6]\" height=\"$SET[icon_h_m]\" title=\"$CD[0]\"></td><td onclick=\"javascript:card_focus('".$CF[$CD[id]]."');\">$CD[0]</td><td>$CD[2]</td><td>$CD[3]</td><td>".ch_tone($CD[4])."</td><td>".ch_fati($CD[5])."</td><td>".AVE($CD_RB[2],$CD_RB[3])."</td><td>$ch_OPS</td>";
			#チーム分析用
			$TM_STB[0]++;
			$TM_STB[1]+=$CD[11];
			$TM_STB[2]+=$CD[12];
			$TM_STB[3]+=$CD[13];
			$TM_STB[4]+=$CD[14];
			$TM_STB[5]+=$CD[15];
			$TM_STB[6]+=$CD[16];
			$TM_STB[7]+=$CD[17];
		}else{
			$html_bt.="<td colspan=15>-</td>";
		}
		$html.="</tr>\n";
	}else{#
		$html_bt.="<tr><td colspan=17>データが未設定です。</td></tr>\n";
	}
}
	#--------------------------------------#
	# 分析
	#--------------------------------------#
	$D[barlen]=100;
	#$TM_STB
	if($TM_STB[0]>0){
		for($i=1;$i<=7;$i++){
			$TM_STBA[$i]=floor($TM_STB[$i]/$TM_STB[0]*100)/100;
			$TM_STBL[$i]=$TM_STBA[$i]/110*$D[barlen];
			$TM_STBL2[$i]=$D[barlen]-$TM_STBL[$i];
		}
		$TM_STBA[ALL]=floor(($TM_STBA[1]+$TM_STBA[2]+$TM_STBA[3]+$TM_STBA[4]+$TM_STBA[5]+$TM_STBA[6]+$TM_STBA[7])/7*100)/100;
		$TM_STBL[ALL]=$TM_STBA[ALL]/110*$D[barlen];
		$TM_STBL2[ALL]=$D[barlen]-$TM_STBL[ALL];
		#各能力表示
		$html_analysis1.="<table class=tbcen><tr><th colspan=3>野手分析</th></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[1]'><td>ミート</td><td>".ch_st($TM_STBA[1],0)."&nbsp;$TM_STBA[1]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[1]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[1]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[2]'><td>パワー</td><td>".ch_st($TM_STBA[2],0)."&nbsp;$TM_STBA[2]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[2]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[2]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[3]'><td>走力</td><td>".ch_st($TM_STBA[3],0)."&nbsp;$TM_STBA[3]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[3]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[3]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[4]'><td>肩力</td><td>".ch_st($TM_STBA[4],0)."&nbsp;$TM_STBA[4]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[4]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[4]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[5]'><td>守備力</td><td>".ch_st($TM_STBA[5],0)."&nbsp;$TM_STBA[5]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[5]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[5]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[6]'><td>反応</td><td>".ch_st($TM_STBA[6],0)."&nbsp;$TM_STBA[6]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[6]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[6]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[7]'><td>E回避</td><td>".ch_st($TM_STBA[7],0)."&nbsp;$TM_STBA[7]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[7]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[7]></td></tr>\n";
		$html_analysis1.="<tr title='$TM_STBA[ALL]'><td>総合</td><td>".ch_st($TM_STBA[ALL],0)."&nbsp;$TM_STBA[ALL]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STBL[ALL]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STBL2[ALL]></td></tr>\n";
		$html_analysis1.="</table>";
	}else{
		$html_analysis1.="野手が選択されていません<br>";
	}
	#$TM_STPS,$TM_STPN
	if($TM_STPS[0]>0){
		for($i=1;$i<=5;$i++){
			$TM_STPSA[$i]=floor($TM_STPS[$i]/$TM_STPS[0]*100)/100;
			$TM_STPSL[$i]=$TM_STPSA[$i]/110*$D[barlen];
			$TM_STPSL2[$i]=$D[barlen]-$TM_STPSL[$i];
		}
		$html_analysis2.="<table class=tbcen><tr><th colspan=3>先発投手分析</th></tr>\n";
		#各能力表示
		$html_analysis2.="<tr title='$TM_STPSA[1]'><td>球速</td><td>".ch_st($TM_STPSA[1],0)."&nbsp;$TM_STPSA[1]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPSL[1]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPSL2[1]></td></tr>\n";
		$html_analysis2.="<tr title='$TM_STPSA[2]'><td>制球</td><td>".ch_st($TM_STPSA[2],0)."&nbsp;$TM_STPSA[2]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPSL[2]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPSL2[2]></td></tr>\n";
		$html_analysis2.="<tr title='$TM_STPSA[3]'><td>体力</td><td>".ch_st($TM_STPSA[3],0)."&nbsp;$TM_STPSA[3]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPSL[3]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPSL2[3]></td></tr>\n";
		$html_analysis2.="<tr title='$TM_STPSA[4]'><td>変化量</td><td>".ch_st($TM_STPSA[4],0)."&nbsp;$TM_STPSA[4]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPSL[4]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPSL2[4]></td></tr>\n";
		$html_analysis2.="<tr title='$TM_STPSA[5]'><td>球種数</td><td colspan=2>$TM_STPSA[5]</td></tr>\n";
		$html_analysis2.="</table>";
	}else{
		$html_analysis2.="先発投手が選択されていません<br>";
	}
	if($TM_STPN[0]>0){
		for($i=1;$i<=5;$i++){
			$TM_STPNA[$i]=floor($TM_STPN[$i]/$TM_STPN[0]*100)/100;
			$TM_STPNL[$i]=$TM_STPNA[$i]/110*$D[barlen];
			$TM_STPNL2[$i]=$D[barlen]-$TM_STPNL[$i];
		}
		$html_analysis3.="<table class=tbcen><tr><th colspan=3>継投投手分析</th></tr>\n";
		#各能力表示
		$html_analysis3.="<tr title='$TM_STPNA[1]'><td>球速</td><td>".ch_st($TM_STPNA[1],0)."&nbsp;$TM_STPNA[1]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPNL[1]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPNL2[1]></td></tr>\n";
		$html_analysis3.="<tr title='$TM_STPNA[2]'><td>制球</td><td>".ch_st($TM_STPNA[2],0)."&nbsp;$TM_STPNA[2]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPNL[2]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPNL2[2]></td></tr>\n";
		$html_analysis3.="<tr title='$TM_STPNA[3]'><td>体力</td><td>".ch_st($TM_STPNA[3],0)."&nbsp;$TM_STPNA[3]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPNL[3]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPNL2[3]></td></tr>\n";
		$html_analysis3.="<tr title='$TM_STPNA[4]'><td>変化量</td><td>".ch_st($TM_STPNA[4],0)."&nbsp;$TM_STPNA[4]</td><td><img src='$SET[dir_img]/blue.gif' height=7 width=$TM_STPNL[4]><img src='$SET[dir_img]/red.gif' height=7 width=$TM_STPNL2[4]></td></tr>\n";
		$html_analysis3.="<tr title='$TM_STPNA[5]'><td>球種数</td><td colspan=2>$TM_STPNA[5]</td></tr>\n";
		$html_analysis3.="</table>";
	}else{
		$html_analysis3.="継投投手が選択されていません<br>";
	}
#--------------------------------------#
sql_close($db);
#--------------------------------------#

$disp.=head();
$disp.=$html_cf;
$disp.=html_bar();
$disp.=$title;
$disp.=<<<EOF
<tr style="vertical-align:top;text-align:center;"><td>
<b>スターティングオーダー</b><input type=button value="オーダー設定" onclick="location.href='$SET[path_index]?r=team_order';">
<table class=tbcen>
<tr><th colspan=2>&nbsp;</th><th colspan=2>名前</th><th>投</th><th>打</th><th>調</th><th>疲</th><th>Ave</th><th>OPS</th></tr>
$html_bt
</table><br>
<b>野手控え</b>
<table class=tbcen>
<tr><th colspan=2>名前</th><th>投</th><th>打</th><th>調</th><th>疲</th><th>Ave</th><th>OPS</th><th>起用法</th></tr>
$html_btsb
</table><br>
$html_analysis1
</td><td>
<b>先発ローテーション</b><input type=button value="登板設定" onclick="location.href='$SET[path_index]?r=team_pitch';">
<table class=tbcen>
<tr><th>&nbsp;</th><th colspan=2>名前</th><th>投</th><th>調</th><th>疲</th><th>ERA</th><th>WHIP</th><th>投球回</th><th>被打率</th></tr>
$html_rot
</table><br>
<b>中継ぎ・抑え</b>
<table class=tbcen>
<tr><th colspan=2>名前</th><th>投</th><th>調</th><th>疲</th><th>ERA</th><th>WHIP</th><th>投球回</th><th>被打率</th></tr>
$html_pcsb
</table><br>
$html_analysis2
$html_analysis3
</td></tr>
EOF;
$disp.=foot();
}
#----------------------------------------------------------#
function brk_num($CD){
	$brk_num=0;
	if($CD[24]>0){$brk_num++;}
	if($CD[25]>0){$brk_num++;}
	if($CD[26]>0){$brk_num++;}
	if($CD[27]>0){$brk_num++;}
	if($CD[28]>0){$brk_num++;}
	return $brk_num;
}
#----------------------------------------------------------#
?>