Add(_('Delete prohibited, invalid security token!')); $action = ACT_VIEW; break; } unset($_SESSION['token']); $sth = $pdo->prepare("DELETE FROM company WHERE compid=?"); $sth->execute([$id]); $g_message->Add(sprintf(_('Deleted company no. %d'), $id)); $action = ACT_DEFAULT; break; default: $g_error->Add(sprintf(_('Unknown function!'), $submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== require 'header.php'; // ========== PAGE CONTENT ==================================================== if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= page_caption_search($pagetitle); // load filter from db $flt = db_get_filter($user->id, 208); $w = array(); $p = array(); if ($flt->type > 0) { $w[] = 'comptype=:comptype'; $p[':comptype'] = $flt->type; } if (strlen($flt->txt) > 1) { $w[] = '(compname LIKE :txt OR remarks LIKE :txt)'; $p[':txt'] = '%'.$flt->txt.'%'; } $where = join(' AND ', $w); $order = ' ORDER BY comptype, compname'; // grand total of records for current vessel $grandtotal = $pdo->query("SELECT COUNT(*) FROM company")->fetchColumn(); // get total record count for pagination and limit $sql = "SELECT COUNT(*) FROM company"; if ($where) { $sql .= " WHERE $where"; } $sth = $pdo->prepare($sql); try { $sth->execute($p); } catch(PDOException $e) { $g_error->Add($e->getMessage()); $g_error->Add($sql); $g_error->Add(print_r($p, true)); $g_error->PrintOut(); } $numrows = $sth->fetchColumn(); $page = gpc_get_int($_REQUEST, 'p', 1); $rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp); $lastpage = ceil($numrows/$rows_pp); $sql = "SELECT compid, compname, comptype, remarks " . "FROM company"; if ($where) $sql .= ' WHERE ' . $where; $sql .= $order; // if pagination: $sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp; $sth = $pdo->prepare($sql); try { $sth->execute($p); } catch(PDOException $e) { $g_error->Add($e->getMessage()); $g_error->Add($sql); $g_error->Add(print_r($p, true)); } $res = $sth->fetchAll(); // Filter $opt_special = array( -2 => _('― all ―'), ); ?>
', "\n"; echo "\n"; echo "Referenced in equipment:
\n"; echo "\n"; } else { echo '', _('Not referenced in any equipment'), "
\n"; } // show referenced invoices $sql = "SELECT docid, refid, filename, title " . "FROM docref AS r JOIN document AS d USING (docid) " . "WHERE r.reftype='company' AND r.refid=? AND d.doctype='invoice'"; $sth = $pdo->prepare($sql); $sth->execute([$id]); if ($sth->rowCount() > 0) { echo "
", _('Invoices'), ":
\n"; echo "', _('No invoices'), "
\n"; } elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== echo '
', sprintf(_('Record no. %d'), $id), "
\n"; echo 'Name: ', $company->compname, "
"; echo 'Remarks: ', $company->remarks, "
"; // Still used as a supplier or manufacturer for equipment? $sql = "SELECT COUNT(*) FROM equipment WHERE supplier=:id OR manufacturer=:id"; $sth = $pdo->prepare($sql); $sth->bindValue(':id', $id, PDO::PARAM_INT); $sth->execute(); $usecount = $sth->fetchColumn(); if ($usecount > 0) { echo '', _('Company can not be deleted as there are equipment-references!'), "
\n"; echo '', _('Back'), "\n"; } else { echo '
', _('Deleting a company is final. There is no way back. Only delete if you are absolute sure.'), "
\n"; $_SESSION['token'] = bin2hex(random_bytes(8)); form_delete_buttons($g_scriptname, $id, $_SESSION['token']); } else: // ========== ERROR UNKNOWN VARIANT =========================================== echo '', _('Unknown function call: Please report to system development!'), "
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= include 'footer.php';