<?php 

function adm_filter_fee($fee, $options) {
	if(!isset($options[0]['term_of_admission'])) {
		return $fee;
	}
	if($options[0]['term_of_admission'] !== $options[1]) {
		return $fee; // meaning it is not the term of admission so no admission fee
	}
	$gender = sfm_convert_gender($options[0]['gender']);
	$key = $gender."-".$options[1]."-".$options[0]['class']."-".$options[2]['description'];
	if(isset($session->{$key}) && (time() < $session{$key."-Expiry"})) {
		if(!$session->{$key}) {
			return $fee;
		}
		return $session->{$key};
	}
	$fee_meta = db_post_unique(['type' => 'registration_fee', 'adm_term' => $options[1], 'gender' => $gender, 'adm_class' => $options[0]['class'], 'cat' => $options[2]['description']]);
	$session->{$key} = $fee_meta ? $fee_meta['amount'] : false;
	$session{$key."-Expiry"} = time() + 120;
	if(!$session->{$key}) {
		return $fee;
	}
	return $session->{$key};
}