Update first'); } if (!($contract['contract_status'] === 'Draft' || contractHoursLive($contract))) { apiFormRefuse('Hours are added to a draft or active contract, or a cancelled one until its last day - renew it first'); } $in = []; foreach (['hours', 'bought', 'expires', 'price', 'note', 'invoice', 'category'] as $key) { if (array_key_exists($key, $_POST)) { $in[$key] = is_scalar($_POST[$key]) ? (string) $_POST[$key] : ''; } } [$f, $error] = contractHoursFromInput($in); if ($error === '' && $f['invoice'] && intval($config_module_enable_accounting) !== 1) { $error = 'Invoicing needs accounting turned on, in Admin > Settings > Modules.'; } if ($error !== '') { apiFormRefuse($error); } [$block_id, $invoice_id, $number] = contractHoursAdd($contract, $f, $session_user_id, 'The API (' . html_entity_decode($api_key_name, ENT_QUOTES, 'UTF-8') . ')'); $insert_id = intval($block_id) ?: false; if ($invoice_id) { $return_arr['invoice_id'] = intval($invoice_id); $return_arr['invoice_reference'] = $number; } $hours = escapeSql(contractHoursWords($f['hours'])); logAudit("Contract", "Edit", "Added $hours to contract $contract_label" . ($invoice_id ? ", on invoice " . escapeSql($number) : '') . " via API ($api_key_name)", $client_id, $contract_id); logAudit("API", "Success", "Added $hours to contract $contract_label via API ($api_key_name)", $client_id); } // Output require_once '../create_output.php';