translate editStage code to php