You are here

function _invoice_user_has_admin_access_to_invoice in Invoice 7

Same name and namespace in other branches
  1. 6 invoice_helpers.inc \_invoice_user_has_admin_access_to_invoice()

Returns if the user has access to administer the given invoice

Parameters

integer $invoice_id:

Return value

boolean

4 calls to _invoice_user_has_admin_access_to_invoice()
invoice_delete_item in ./invoice_ajax.inc
Delete an invoice item
invoice_edit_item in ./invoice_ajax.inc
Edit an invoice item
invoice_invoices in ./invoice.module
Overview of all invoices
invoice_save_item in ./invoice_ajax.inc
Add an invoice item

File

./invoice_helpers.inc, line 286
Invoice module

Code

function _invoice_user_has_admin_access_to_invoice($invoice_id) {
  $has_access = FALSE;
  if (empty($invoice_id)) {
    $has_access = TRUE;
  }
  else {
    if (user_access('administer invoices')) {
      $has_access = TRUE;
    }
    elseif (user_access('administer own invoices')) {
      $count = db_query("SELECT COUNT(*) FROM {invoice_invoices} WHERE iid = :iid AND uid = :uid", array(
        ':iid' => $invoice_id,
        ':uid' => $GLOBALS['user']->uid,
      ))
        ->fetchField();
      if ($count > 0) {
        $has_access = TRUE;
      }
    }
  }
  return $has_access;
}