Hi Henning, yes please post your codes so that we can all learn from each other here. Thanks a bunch!
By the way, a quick side question. Is there a quick and easy way to export all the course categories (and empty course shells) from one Moodle server to another? We spent a lot of time creating a lot of course categories on our testing server and most of the course shells right now under each course category are still empty. We would like to figure out a way to quickly migrate all the course categories from one server to another one. I'm thinking that we probably need to deal with the mdl_course_category and some other DB tables. Please let me know if anyone know of a quick and easy approach to get this task done. Thanks!