A generalization of Poncelet's theorem