<?php

	function offer($service, $user = null) {
		global $db;
		if($user == null) {
			if(login_control()) {
				global $offers;
				if(array_key_exists($service["service_id"], $offers)) {
					return $offers[$service["service_id"]];
				}
			}
			return $service["service_charge"];
		} else {
			$offers = $db->query("SELECT * FROM `special_offers` WHERE user_id = '$user'")->fetchAll(PDO::FETCH_ASSOC);
			$offers_temp = [];
			foreach($offers as $offer) {
				$offers_temp[$offer["service_id"]] = $offer["offer_charge"];
			}
			$offers = $offers_temp;
			if(array_key_exists($service["service_id"], $offers)) {
				return $offers[$service["service_id"]];
			}
			return $service["service_charge"];
		}
	}