Working Copy

Small changes still need to be made in php and js but it mostly works.