Initial commit (unimportant history in SVN)

Tidy up code style, use new mysqli database methods, etc.