Integrate the duggasys merge into master

Basic.php was split into several smaller parts (database, course and sessions.php).

This includes some of the untested fixes by @HGustavs and they should probably be reviewed before merging this.