<commit_before><?php
if(!isset($_GET['id']) and !isset($_POST['id'])) header('Location: http://www.ifantasyfitness.com');
if(!isset($_COOKIE['iff-id'])) header('Location: http://www.ifantasyfitness.com');
$id = filter_var($_COOKIE['iff-id'], FILTER_SANITIZE_NUMBER_INT);

# Validate the user
include('../../php/db.php');
$check_q = @mysqli_query($db, "SELECT * FROM users WHERE id=$id");
if(mysqli_num_rows($check_q) > 0) {
	$user = mysqli_fetch_array($check_q);
	# confirm with social token
	$valid = false;
	if(isset($_COOKIE['iff-google']) and $_COOKIE['iff-google'] === $user['google']) $valid = true;
	if(isset($_COOKIE['iff-facebook']) and $_COOKIE['iff-facebook'] === $user['facebook']) $valid = true;
	if(!$valid) header('Location: http://www.ifantasyfitness.com');
}

# Grab user's permission value
# 0 - normal user
# 1 - captain
# 2 - coach
# 3 - administrator (this option rarely used)
$perms = $user['permissions'];

# This page requires Level 2 permissions.
# As such, anyone with lower permissions is hereby banished.
if($perms < 2) header('Location: http://www.ifantasyfitness.com/settings/profile');

if(isset($_POST['id'])) {
	# Deletion is confirmed - GO.
	$sid = filter_var($_POST['id'], FILTER_SANITIZE_NUMBER_INT);
	
	# Delete season
	$season_deleter = @mysqli_query($db, "DELETE FROM seasons WHERE name='$sid'");
	
	# Delete teams
	$team_fetcher = @mysqli_query($db, "SELECT * FROM tData WHERE season='$sid'");
	
	$teams = array();
	while($team = mysqli_fetch_array($team_fetcher)) {
		$teams[] = $team['id'];
	}
	$team_deleter = @mysqli_query($db, "DELETE FROM tData WHERE season='$sid'");
	
	# Delete registrations
	$reg_deleter = @mysqli_query($db, "DELETE FROM tMembers WHERE season='$sid'");
	
	# Delete records
	foreach($teams as $tid) {
		$record_deleter = @mysqli_query($db, "DELETE FROM records WHERE team=$tid");
	}
	
	# Done
	setcookie('confirm_message','delete',time()+3,'/','.ifantasyfitness.com');
	header("Location: http://www.ifantasyfitness.com/settings/seasons");
}

# User is valid, and has proper permissions.
$current_set = 'Seasons';
$title = $current_set . ' - Settings';
$connected = true;
include('../../php/head-auth.php');

function settingsType($name, $link, $min_perm) {
	global $current_set;
	global $perms;
	if($perms >= $min_perm) {
		echo '<li';
		if($name == $current_set) echo ' class="active"';
		echo '><a href="/settings/'.$link.'">'.$name.'</a></li>';
	}<commit_msg>Proper deletion. (Actual solution to #3)<commit_after><?php
if(!isset($_GET['id']) and !isset($_POST['id'])) header('Location: http://www.ifantasyfitness.com');
if(!isset($_COOKIE['iff-id'])) header('Location: http://www.ifantasyfitness.com');
$id = filter_var($_COOKIE['iff-id'], FILTER_SANITIZE_NUMBER_INT);

# Validate the user
include('../../php/db.php');
$check_q = @mysqli_query($db, "SELECT * FROM users WHERE id=$id");
if(mysqli_num_rows($check_q) > 0) {
	$user = mysqli_fetch_array($check_q);
	# confirm with social token
	$valid = false;
	if(isset($_COOKIE['iff-google']) and $_COOKIE['iff-google'] === $user['google']) $valid = true;
	if(isset($_COOKIE['iff-facebook']) and $_COOKIE['iff-facebook'] === $user['facebook']) $valid = true;
	if(!$valid) header('Location: http://www.ifantasyfitness.com');
}

# Grab user's permission value
# 0 - normal user
# 1 - captain
# 2 - coach
# 3 - administrator (this option rarely used)
$perms = $user['permissions'];

# This page requires Level 2 permissions.
# As such, anyone with lower permissions is hereby banished.
if($perms < 2) header('Location: http://www.ifantasyfitness.com/settings/profile');

if(isset($_POST['id'])) {
	# Deletion is confirmed - GO.
	$sid = filter_var($_POST['id'], FILTER_SANITIZE_SPECIAL_CHARS);
	
	# Delete teams
	$team_fetcher = @mysqli_query($db, "SELECT * FROM tData WHERE season='$sid'");
	if(mysqli_num_rows($team_fetcher) > 0) {
		$teams = array();
		while($team = mysqli_fetch_array($team_fetcher)) {
			$tid = $team['id'];
			$record_deleter = @mysqli_query($db, "DELETE FROM records WHERE team=$tid");
		}
	}
	
	$team_deleter = @mysqli_query($db, "DELETE FROM tData WHERE season='$sid'");
	
	# Delete registrations
	$reg_deleter = @mysqli_query($db, "DELETE FROM tMembers WHERE season='$sid'");
	
	# Delete season
	$season_deleter = @mysqli_query($db, "DELETE FROM seasons WHERE name='$sid'");
	
	# Done
	setcookie('confirm_message','delete',time()+3,'/','.ifantasyfitness.com');
	header("Location: http://www.ifantasyfitness.com/settings/seasons");
}

# User is valid, and has proper permissions.
$current_set = 'Seasons';
$title = $current_set . ' - Settings';
$connected = true;
include('../../php/head-auth.php');

function settingsType($name, $link, $min_perm) {
	global $current_set;
	global $perms;
	if($perms >= $min_perm) {
		echo '<li';
		if($name == $current_set) echo ' class="active"';
		echo '><a href="/settings/'.$link.'">'.$name.'</a></li>';
	}
{'fraction_non_alphanumeric': 0.19848422777550184, 'fraction_numerical': 0.0036870135190495697, 'mean_word_length': 5.528074866310161, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5187998', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1730, 'n_words': 370}