A Unified Scheme for Modular Invariant Partition Functions of WZW Models