prepare($sql); $sth->bindValue(':compname', $compname, PDO::PARAM_STR); $sth->bindValue(':comptype', $comptype, PDO::PARAM_INT); $sth->execute(); $id = $pdo->lastInsertId(); $action = ACT_VIEW; break; case 'update': $compname = gpc_get_string($_POST, 'compname'); $comptype = gpc_get_int($_POST, 'comptype'); $street = gpc_get_string($_POST, 'street', 30); $zip = gpc_get_string($_POST, 'zip', 10); $city = gpc_get_string($_POST, 'city', 30); $country = gpc_get_string($_POST, 'country', 30); $contact = gpc_get_string($_POST, 'contact', 30); $phone = gpc_get_string($_POST, 'phone', 30); $email = gpc_get_string($_POST, 'email', 50); $web = gpc_get_string($_POST, 'web', 40); $customerno = gpc_get_string($_POST, 'customerno', 20); $contractno = gpc_get_string($_POST, 'contractno', 20); $remarks = gpc_get_string($_POST, 'remarks', 150); $sql = "UPDATE company " . "SET compname=:compname," . " comptype=:comptype," . " street=:street," . " zip=:zip," . " city=:city," . " country=:country," . " contact=:contact," . " phone=:phone," . " email=:email," . " web=:web," . " customerno=:customerno," . " contractno=:contractno," . " remarks=:remarks " . "WHERE compid=:compid"; $sth = $pdo->prepare($sql); $sth->bindValue(':compid', $id, PDO::PARAM_INT); $sth->bindValue(':compname', $compname, PDO::PARAM_STR); $sth->bindValue(':comptype', $comptype, PDO::PARAM_INT); $sth->bindValue(':street', $street, PDO::PARAM_STR); $sth->bindValue(':zip', $zip, PDO::PARAM_STR); $sth->bindValue(':city', $city, PDO::PARAM_STR); $sth->bindValue(':country', $country, PDO::PARAM_STR); $sth->bindValue(':contact', $contact, PDO::PARAM_STR); $sth->bindValue(':phone', $phone, PDO::PARAM_STR); $sth->bindValue(':email', $email, PDO::PARAM_STR); $sth->bindValue(':web', $web, PDO::PARAM_STR); $sth->bindValue(':customerno', $customerno, PDO::PARAM_STR); $sth->bindValue(':contractno', $contractno, PDO::PARAM_STR); $sth->bindValue(':remarks', $remarks, PDO::PARAM_STR); $sth->execute(); $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 ======================================= echo '
| ', _('Name')," | ", $company->compname, " |
|---|---|
| ', _('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 "', _('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';