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 ======================================= // 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'; $sql = "SELECT compid, compname, comptype, remarks " . "FROM company"; if ($where) $sql .= ' WHERE ' . $where; $sql .= $order; $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(); 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, " |
Referenced in equipment:
\n"; echo "\n"; } else { echo '', _('Not referenced in any equipment'), "
\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';