Updated everything with AJAX

Changed all the clumsy php logic to AJAX, moving all the logic to the
/logic directory