Coupling of magnetic ordering and vibrational properties: a density functional theory study of magnetic and structural phase transitions