<?php
namespace FAAPI;

$path_to_root = "../..";

include_once ($path_to_root . "/taxes/db/item_tax_types_db.inc");

class ItemTaxTypes {
	// Get Items
	public function get($rest)
	{
		$req = $rest->request();

		$page = $req->get("page");

		if ($page == null) {
			$this->itemtax_all();
		} else {
			// If page = 1 the value will be 0, if page = 2 the value will be 1, ...
			$from = -- $page * RESULTS_PER_PAGE;
			$this->itemtax_all($from);
		}
	}

	private function itemtax_all($from = null) {
		if ($from == null)
			$from = 0;
                
                $length = RESULTS_PER_PAGE;

		$sql = "SELECT * FROM " . TB_PREF . "item_tax_types WHERE !inactive LIMIT " . $from . ", " . RESULTS_PER_PAGE;

		$query = db_query($sql, "error");

		$info = array();

		while ($data = db_fetch_assoc($query, "error")) {
			$info[] = $data;
		}

		$response['items'] = $info;
                $response['incomplete_results'] = FALSE;
                $response['total_count'] = $length;
                api_success_response(json_encode($response));
	}
}