Dynamics of foam in porous media