getMessage()); } mysqli_query_check('COMMIT'); mysqli_query_check('SET AUTOCOMMIT = 1'); // Special case for invoices - check for duplicate invoice numbers if ($table == '{prefix}invoice' && isset($values['invoice_no']) && !isOffer($primaryKey) ) { $query = 'SELECT ID FROM {prefix}invoice where deleted=0 AND id!=? AND invoice_no=?'; $params = [ $primaryKey, $values['invoice_no'] ]; if (getSetting('invoice_numbering_per_base')) { $query .= ' AND base_id=?'; $params[] = $values['base_id']; } if (getSetting('invoice_numbering_per_year')) { $query .= ' AND invoice_date >= ' . date('Y') . '0101'; } $res = mysqli_param_query($query, $params); if (mysqli_fetch_assoc($res)) $warnings = $GLOBALS['locInvoiceNumberAlreadyInUse']; } // Special case for invoices - check, according to settings, that the invoice has // an invoice number and a reference number if ($table == '{prefix}invoice' && $onPrint && !isOffer($primaryKey) && (getSetting('invoice_add_number') || getSetting('invoice_add_reference_number')) ) { mysqli_query_check( 'LOCK TABLES {prefix}invoice WRITE, {prefix}settings READ' . ', {prefix}company READ' ); $res = mysqli_param_query( 'SELECT invoice_no, ref_number, base_id, company_id, invoice_date,' . "interval_type FROM $table WHERE id=?", [$primaryKey] ); $data = mysqli_fetch_assoc($res); $needInvNo = getSetting('invoice_add_number'); $needRefNo = getSetting('invoice_add_reference_number'); if (($needInvNo && empty($data['invoice_no'])) || ($needRefNo && empty($data['ref_number'])) ) { $defaults = getInvoiceDefaults( $primaryKey, $data['base_id'], $data['company_id'], dateConvDBDate2Date($data['invoice_date']), $data['interval_type'], $data['invoice_no'] ); $sql = "UPDATE {prefix}invoice SET"; $updateStrings = []; $params = []; if ($needInvNo && empty($data['invoice_no'])) { $updateStrings[] = 'invoice_no=?'; $params[] = $defaults['invoice_no']; } if ($needRefNo && empty($data['ref_number'])) { $updateStrings[] = 'ref_number=?'; $params[] = $defaults['ref_no']; } $sql .= ' ' . implode(', ', $updateStrings) . ' WHERE id=?'; $params[] = $primaryKey; mysqli_param_query($sql, $params); } mysqli_query_check('UNLOCK TABLES'); } return true; } // Fetch a record. Values in $values, may modify $formElements. // Returns TRUE on success, 'deleted' for deleted records and 'notfound' if record is not found. function fetchRecord($table, $primaryKey, &$formElements, &$values) { $result = TRUE; $strQuery = "SELECT * FROM $table WHERE id=?"; $intRes = mysqli_param_query($strQuery, [ $primaryKey ]); $row = mysqli_fetch_assoc($intRes); if (!$row) return 'notfound'; if ($row['deleted']) $result = 'deleted'; foreach ($formElements as $elem) { $type = $elem['type']; $name = $elem['name']; if (!$type || $type == 'LABEL' || $type == 'FILLER' || $type == 'DROPDOWNMENU' ) { continue; } switch ($type) { case 'IFORM' : case 'RESULT' : $values[$name] = $primaryKey; break; case 'BUTTON' : case 'JSBUTTON' : case 'IMAGE' : if (strstr($elem['listquery'], '=_ID_')) { $values[$name] = $primaryKey; } else { $tmpListQuery = $elem['listquery']; $strReplName = substr($tmpListQuery, strpos($tmpListQuery, '_')); $strReplName = strtolower( substr($strReplName, 1, strrpos($strReplName, '_') - 1)); $values[$name] = isset($values[$strReplName]) ? $values[$strReplName] : ''; $elem['listquery'] = str_replace(strtoupper($strReplName), 'ID', $elem['listquery']); } break; case 'INTDATE' : $values[$name] = dateConvDBDate2Date($row[$name]); break; case 'INT' : if (isset($elem['decimals'])) { $values[$name] = miscRound2Decim($row[$name], $elem['decimals']); } else { $values[$name] = $row[$name]; } break; default : $values[$name] = $row[$name]; } } return $result; } function getFormElements($form) { $strForm = $form; require 'form_switch.php'; return $astrFormElements; } function getFormParentKey($form) { $strForm = $form; require 'form_switch.php'; return $strParentKey; } function getFormJSONType($form) { $strForm = $form; require 'form_switch.php'; return $strJSONType; } function getFormClearRowValuesAfterAdd($form) { $strForm = $form; require 'form_switch.php'; return $clearRowValuesAfterAdd; } function getFormOnAfterRowAdded($form) { $strForm = $form; require 'form_switch.php'; return $onAfterRowAdded; }