chart.php: avoid use of undeclared variable
stats.php: use JSON response when receiving stats
stats.php: store events in an events table

Events are now stored in a dedicated table with a  timestamp
of the event, user identifier, and IP address of the request.