Damn, it's harder than I thought. I am sure that there is an optimal way, perhaps with loops and/or arrays, but that's beyond my scope of knowledge!
Here is a semi-working example, the problem is that when you come back to the main menu, the locking/unlocking resets. That's because the booleans doesn't keep their state after you leave the menu layout. You have to find a way to store each level's condition within a global variable (or an array, dictionary, whatever stores data). I am too confused to think about it right now. Try to improve upon this, if it helps you, and meanwhile perhaps someone else will think something more appropriate!