South African president admits government poorly prepared to deal with unrest