I've had this cat for 13 years so I think I know him pretty well... he's an asshole. How do you fix that?
If he's 13 then he's an equivalent age of around 70 in human years. Cat's are very clean animals but if their litter tray is dirty they'll find somewhere else
If their anal glands are swollen - for a variety of reasons - you'll get what you are getting, so first port of call would be a vet to make sure he's OK
A cat flap is great if he wants to get out but if the weather isnt to his liking, he'll need somewhere to go to the toilet inside. Ideally under a table, for the same reason you don't have a crap in full display of everyone else
Lastly, maybe its just his age - if our cats or dog ever does that then its easily cleaned. That's why we have a vac which also does wet & dry cleaning. It's not the end of the world. So he craps on the carpet - when he's gone & passed over the Rainbow Bridge you miss him and wish he was still there to clean up after.
So enjoy him & love him whilst he's still here