ported all JavaScript to PHP constructs