require_once __DIR__.'/inc/football.php'; require_once __DIR__.'/inc/auth.php'; require_once __DIR__.'/inc/predictions.php'; $id=(int)($_GET['id']??0); $d=ic_football_full_load(); $matches=$d['matches']??[]; $standings=$d['standings']??[]; $match=null; foreach($matches as $m){ if((int)($m['id']??0)===$id){ $match=$m; break; } } function esc($s){return htmlspecialchars((string)$s,ENT_QUOTES,'UTF-8');} function find_rank(array $rows,int $teamId): ?array { foreach($rows as $r){ if((int)($r['team_id']??0)===$teamId) return $r; } return null; } $u=ic_current_user(); $predictionMsg=''; $predictionOk=false; if(!$match){ http_response_code(404); } if($match && $_SERVER['REQUEST_METHOD']==='POST' && ($_POST['action']??'')==='prediction'){ if(!$u){ header('Location:/login.php?next='.rawurlencode('/mac.php?id='.$id)); exit; } if(!ic_csrf_ok((string)($_POST['csrf']??''))){ $predictionMsg='Güvenlik doğrulaması başarısız.'; }else{ [$predictionOk,$predictionMsg]=ic_prediction_save( $id, (string)$u['username'], (string)($_POST['pick']??''), $match ); } } $myPrediction=($match && $u)?ic_prediction_get($id,(string)$u['username']):null; $predictionStats=$match?ic_prediction_percentages($id):['1'=>0,'X'=>0,'2'=>0,'total'=>0]; $predictionLocked=$match?ic_prediction_locked($match):true; $csrf=$u?ic_csrf():''; $bsdDetail=[]; if($match){ $bsdPath='/var/lib/iddacafe-football/bsd-details/'.((int)($match['id']??0)).'.json'; if(is_file($bsdPath)){ $tmp=json_decode((string)@file_get_contents($bsdPath),true); if(is_array($tmp)) $bsdDetail=$tmp; } } function bsd_stat_value(array $side,string $key): string { if(!array_key_exists($key,$side) || $side[$key]===null || $side[$key]==='') return '—'; $v=$side[$key]; if($key==='ball_possession') return ((float)$v).'%'; if($key==='xg' && is_array($v)){ $x=$v['actual']??null; return $x===null?'—':number_format((float)$x,2,'.',''); } if(is_float($v)) return number_format($v,2,'.',''); return (string)$v; } function ic_bsd_incidents(array $bsdDetail): array { $x=$bsdDetail['incidents']['incidents']??[]; return is_array($x)?$x:[]; } function ic_bsd_final_score(array $bsdDetail): ?array { foreach(ic_bsd_incidents($bsdDetail) as $x){ if(!is_array($x)) continue; $type=strtolower((string)($x['type']??'')); $text=strtoupper((string)($x['text']??'')); if(($type==='period' && $text==='FT') || $type==='fulltime' || $type==='finished'){ $h=$x['home_score']??null; $a=$x['away_score']??null; if($h!==null && $a!==null) return ['home'=>(int)$h,'away'=>(int)$a]; } } return null; } function ic_bsd_minute(array $x): string { $m=(int)($x['minute']??0); $a=(int)($x['added_time']??0); if($m<=0) return ''; return $a>0 ? ($m.'+'.$a."'") : ($m."'"); } function ic_bsd_event_label(array $x): array { $type=strtolower((string)($x['type']??'')); if($type==='goal') return ['⚽','Gol']; if(in_array($type,['yellowcard','yellow_card','yellow-card'],true)) return ['🟨','Sarı Kart']; if(in_array($type,['redcard','red_card','red-card'],true)) return ['🟥','Kırmızı Kart']; if($type==='substitution') return ['🔄','Oyuncu Değişikliği']; if($type==='period'){ $t=strtoupper((string)($x['text']??'')); if($t==='HT') return ['⏸','Devre']; if($t==='FT') return ['🏁','Maç Sonu']; } if($type==='injurytime') return ['⏱','Uzatma']; if($type==='var') return ['📺','VAR']; return ['•',ucfirst($type ?: 'Olay')]; } function ic_bsd_player_text(array $x): string { $type=strtolower((string)($x['type']??'')); if($type==='substitution'){ $in=(string)($x['player_in']??''); $out=(string)($x['player_out']??''); if($in!=='' || $out!=='') return trim($out.' → '.$in,' →'); } $p=(string)($x['player']??''); if($p!=='') return $p; return (string)($x['text']??''); } function ic_bsd_lineup_side(array $bsdDetail,string $side): array { $x=$bsdDetail['lineups']['lineups'][$side]??[]; return is_array($x)?$x:[]; } function ic_bsd_position_tr(string $p): string { return ['G'=>'Kaleci','D'=>'Defans','M'=>'Orta Saha','F'=>'Forvet'][$p]??$p; } $bsdFinalScore=ic_bsd_final_score($bsdDetail); if($match && $bsdFinalScore){ $match['score']['fullTime']=$bsdFinalScore; $match['status']='FT'; $match['status_long']='Bitti'; } ?>