php solution to a pratical schedule problem