Lessons - backend work

- Moved admin lessons sql code into the lessons library to keep the
code together.
- Added a new function, findAndCleanLessons(). This looks for lessons
that have passed [(lesson start time + lesson duration) < now] and
updates their status to done.
This is controlled by a new setting in the site configuration page,
giving the admins control of this process. This means that every time
an operation connected to lessons is performed, the system has an
opportunity to update records as needed.