<?php

class Export_json extends View {

	public function render($data) {

		header('Access-Control-Allow-Origin: *');
		header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');	// to do: fix this
		header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');	
		
		if (isset($_GET['exec'])) {			// we're going to change part of the page, not outputting a json table
			$data = hook_execute('output.common', $data);
		}
		
		if (isset($_GET['jsoncallback'])) {
			header('Content-type: application/javascript; charset=utf-8');
			$data = json_encode($data);
			echo $_GET['jsoncallback'] . '(' . $data .');';
		} elseif (isset($_GET['callback'])) {
			$data = json_encode($data);
			header('Content-type: application/javascript; charset=utf-8');
			echo $_GET['callback'] . '(' . $data .');';
		} else {
			header('Content-type: application/json; charset=utf-8');
			echo json_encode($data, JSON_UNESCAPED_SLASHES);
		}
	}
}