function _invoice_api_invoice_get in Invoice 7
Handles GET request for the specified invoice ID
Parameters
integer $invoiceId:
string $format Valid values: html, json or pdf:
1 call to _invoice_api_invoice_get()
- invoice_api_invoice in ./
invoice_api.inc - GET / PUT / POST / DELETE an invoice
File
- ./
invoice_api.inc, line 378
Code
function _invoice_api_invoice_get($invoiceId, $format) {
if (0 === $invoiceId) {
_invoice_api_http_response_code(400);
echo json_encode(array(
'code' => 400,
'message' => 'Invoice ID invalid or missing',
));
exit;
}
else {
$row = db_query("SELECT COUNT(iid) AS count, it.api_username FROM {invoice_invoices} ii\n JOIN {invoice_templates} it ON ii.tid = it.tid\n WHERE iid = :invoiceId\n LIMIT 1", array(
':invoiceId' => $invoiceId,
))
->fetchAssoc();
if ($row['count'] < 1) {
_invoice_api_http_response_code(404);
echo json_encode(array(
'code' => 404,
'message' => 'Not Found',
));
exit;
}
if ($row['api_username'] !== $GLOBALS['user']->name && variable_get('invoice_api_root_username') !== $GLOBALS['user']->name) {
_invoice_api_http_response_code(403);
echo json_encode(array(
'code' => 403,
'message' => 'No access to the template of this invoice',
));
exit;
}
}
_invoice_api_http_response_code(200);
// OK
switch ($format) {
case 'html':
invoice_view_print($invoiceId);
break;
case 'pdf':
invoice_view_pdf($invoiceId);
break;
case 'json':
default:
_invoice_api_view_json($invoiceId);
break;
}
}