<?php

require_once(SF_ROOT_DIR . '/includes/common/class.convert.php');
require_once(SF_ROOT_DIR . "/apps/amms_store/lib/StoreActions.php");

class ProofActions extends StoreActions {

	// Provides the raw PDF proof of a given order product.
	// Essentially a proxy.
	public function executeIndex() {
		$id = $this->getRequestParameter("order_product_id");
		$url = Us2OrderProofPeer::GetLastProof($id);
		$contents = file_get_contents($url);

		header("Content-Type: application/pdf");
		return $this->renderText($contents);
	}

	// Provides a light wrapper around the PDF.js viewer
	// that polls proof state and provides more helpful
	// error handling.
	public function executeView() {
		$this->setLayout(false);
		return sfView::SUCCESS;
	}

	// Provides the PDF.js view. The viewer will be looking
	// for the GET param "file".
	// ex: /proof/viewer?file=/proof?order_product_id=123456
	public function executeViewer() {
		$this->setLayout(false);
		return sfView::SUCCESS;
	}

	public function executeStatus() {
		uProduce::GetJobStatus($JobId);
		return $this->serveJSON(array(
			"status" => 1
		));
	}

}
