Indonesia's parliament has approved a new criminal code that will make sex outside of marriage punishable by up to a year in prison.