['historic']); db_save_filter($flt, 208); $action = ACT_DEFAULT; break; case 'insert': $p[':compname'] = gpc_get_string($_POST, 'compname'); $p[':comptype'] = gpc_get_int($_POST, 'comptype'); $id = db_exec_insert('company', $p); db_set_revision('table', TBL_COMPANIES); $action = ACT_VIEW; break; case 'update': $p[':compid'] = $id; $p[':compname'] = gpc_get_string($_POST, 'compname'); $p[':shortname'] = gpc_get_string($_POST, 'shortname', 20); $p[':comptype'] = gpc_get_int($_POST, 'comptype'); $p[':comptype2'] = gpc_get_int($_POST, 'comptype2'); if ($p[':comptype2'] <= 0) $p[':comptype2'] = NULL; $p[':street'] = gpc_get_string($_POST, 'street', 40); $p[':zip'] = gpc_get_string($_POST, 'zip', 10); $p[':city'] = gpc_get_string($_POST, 'city', 30); $p[':country'] = gpc_get_string($_POST, 'country', 30); $p[':contact'] = gpc_get_string($_POST, 'contact', 30); $p[':phone'] = gpc_get_string($_POST, 'phone', 30); $p[':email'] = gpc_get_string($_POST, 'email', 50); $p[':web'] = gpc_get_string($_POST, 'web', 40); $p[':customerno'] = gpc_get_string($_POST, 'customerno', 20); $p[':contractno'] = gpc_get_string($_POST, 'contractno', 20); $p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); $allowed = db_load_enum('company', 'flags'); $p[':flags'] = gpc_get_set($_POST, 'flags', $allowed, true, NULL); db_exec_update('company', $p, 'compid'); $action = ACT_VIEW; break; case 'delete': // Security token needed! if (gpc_get_string($_POST, 'token', 16) != $_SESSION['token']) { $g_error->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, ['type','txt','flags']); $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.'%'; } // condition for multiple flags is OR $parts = ["flags=''", 'flags IS NULL']; foreach ($flt->flags as $f) { $parts[] = "FIND_IN_SET('$f', flags)"; } if (!empty($parts)) { if (count($parts) > 1) { $w[] = '(' . join(' OR ', $parts) . ')'; } else { $w[] = $parts[0]; } } $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', $user->rows_pp); $lastpage = ceil($numrows/$rows_pp); $sql = "SELECT compid, compname, comptype, remarks, flags " . "FROM company"; if ($where) $sql .= ' WHERE ' . $where; $sql .= $order; // if pagination: $sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $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 ?>
', "\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: ', h($company->compname), "
"; echo 'Remarks: ', h($company->remarks, br:true), "
"; // 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';