<?

require_once ('../common.inc.php');
require_once ('../user.inc.php');

user_auth_required('committee', 'admin');

$q = $pdo->prepare('SELECT * FROM judges WHERE passwordexpiry IS NULL');
$q->execute();
while ($i = $q->fetch(PDO::FETCH_OBJ)) {
	echo "Autocompleting Judge {$i->email}<br />";
	$id = $i->id;

	$p = password_hash(generatePassword(), PASSWORD_BCRYPT);
	$stmt = $pdo->prepare("UPDATE judges SET password=?,complete=?");
	$stmt->execute([$p, 'yes']);
	show_pdo_errors_if_any($pdo);
	$stmt = $pdo->prepare("DELETE FROM judges_years WHERE judges_id=?");
	$stmt->execute([$id]);
	show_pdo_errors_if_any($pdo);
	$stmt = $pdo->prepare("INSERT INTO judges_years (`judges_id`,`year`) VALUES (?, ?)");
	$stmt->execute([$id, $config['FAIRYEAR']]);
	show_pdo_errors_if_any($pdo);
}

?>
