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)); } $numrows = $sth->fetchColumn(); $lastpage = ceil($numrows/$g_rows_pp); $page = gpc_get_int($_REQUEST, 'p', 1); $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 ―'), ); ?>
Filter
', "\n"; echo "\n"; echo ""; echo "" . _('Name') . ""; echo "" . _('Type') . ""; echo "" . _('Remarks') . ""; echo " "; echo "\n"; echo "\n"; foreach ($res as $row) { echo "\n"; echo "". $row['compname'] ."\n"; echo "". $opt_comptype[$row['comptype']] ."\n"; echo "". $row['remarks'] ."\n"; // Action buttons echo ""; echo '', "\n"; echo ''; echo "\n"; echo "\n"; } // Table summary echo "\n"; echo '', sprintf(_('%d records out of total %d'), count($res), $grandtotal), '', "\n"; echo "\n"; echo "\n"; echo $pagination; form_add_button($g_scriptname); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= echo '

', _('Add Company'), "

\n"; ?>
prepare($sql); $sth->execute([$id]); $company = $sth->fetch(PDO::FETCH_OBJ); echo "

", $company->compname, "

\n"; echo '', "\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo '\n"; echo "
', _('Name'),"", $company->compname, "
', _('Short name'),"", $company->shortname, "
', _('Type'),"", $opt_comptype[$company->comptype], "
', _('Street'),"", $company->street, "
', _('Zip, City'),"", $company->zip, ' ', $company->city, "
', _('Country'),"", $company->country, "
', _('Contact'),"", $company->contact, "
', _('Phone'),"", $company->phone, "
', _('Email'),"", $company->email, "
', _('Web'),"", $company->web, "
', _('Customer no.'),"", $company->customerno, "
', _('Contract no.'),"", $company->contractno, "
', _('Remarks'),"", $company->remarks, "
\n"; form_view_buttons($g_scriptname, $id); // show referenced equipment $sql = "SELECT eid, ename FROM equipment WHERE supplier=:id OR manufacturer=:id"; $sth = $pdo->prepare($sql); $sth->execute([':id' => $id]); if ($sth->rowCount() > 0) { 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 reftype='company' AND refid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); if ($sth->rowCount() > 0) { echo "

Invoices:

\n"; echo "\n"; } else { echo '

', _('No invoices'), "

\n"; } elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== echo '

', _('Edit Company'), "

\n"; $sql = "SELECT compname, comptype, street, zip, city, country," . " contact, phone, email, web, customerno, contractno, remarks " . "FROM company " . "WHERE compid=?"; $sth = $pdo->prepare($sql); $sth->execute([$id]); $company = $sth->fetch(PDO::FETCH_OBJ); ?>
prepare($sql); $sth->execute([$id]); $company = $sth->fetch(PDO::FETCH_OBJ); echo '

', _('Delete Company'), "

\n"; 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';