76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
require 'database.php';
|
|
|
|
$tabellSQL = "
|
|
CREATE OR REPLACE TABLE Postnummer (
|
|
postnummer INT(4) NOT NULL PRIMARY KEY,
|
|
poststed VARCHAR(30) NOT NULL
|
|
);
|
|
|
|
CREATE OR REPLACE TABLE Medlem (
|
|
medlemId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
fornavn VARCHAR(40) NOT NULL,
|
|
etternavn VARCHAR(40) NOT NULL,
|
|
adresse VARCHAR(40) NOT NULL,
|
|
postnummer INT(4) NOT NULL,
|
|
epost VARCHAR(100) NOT NULL UNIQUE,
|
|
dob DATE NOT NULL,
|
|
kjoenn ENUM('M', 'F', 'O') NOT NULL,
|
|
kontigentStatus ENUM('BETALT', 'IKKE_BETALT') NOT NULL DEFAULT 'IKKE_BETALT',
|
|
medlemStart DATE NOT NULL,
|
|
FOREIGN KEY (postnummer) REFERENCES Postnummer(postnummer)
|
|
);
|
|
";
|
|
|
|
function getPdoConn(): PDO {
|
|
$conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_BASE . "", DB_USER, DB_PASS);
|
|
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
return $conn;
|
|
}
|
|
|
|
class Medlem {
|
|
public string $rolle = "Standard";
|
|
public int $dbid;
|
|
public string $fornavn = '';
|
|
public string $etternavn = '';
|
|
public string $adresse1 = '';
|
|
public string $adresse2 = '';
|
|
public int $postnummer;
|
|
public string $poststed = '';
|
|
public string $epost = '';
|
|
public DateTime $dob;
|
|
public string $kjoenn = '';
|
|
public string $interesser = '';
|
|
public string $kursaktiviteter = '';
|
|
public DateTime $medlem_siden;
|
|
public string $kontigentstatus = '';
|
|
|
|
public function set($felt, $verdi){
|
|
$this->${$felt} = $verdi;
|
|
}
|
|
|
|
public function get($felt){
|
|
return $this->${$felt};
|
|
}
|
|
|
|
}
|
|
|
|
// Caching av poststed
|
|
$poststed = array();
|
|
function hentPoststed($postnummer): string {
|
|
global $poststed;
|
|
|
|
if(!$poststed[ $postnummer ]){
|
|
$db = getPdoConn();
|
|
$stmt = $db->prepare("SELECT postnummer, poststed FROM Postnummer WHERE postnummer = ?");
|
|
$stmt->execute([$postnummer]);
|
|
|
|
foreach ($stmt as $row){
|
|
$poststed[$row['postnummer']] = $row['poststed'];
|
|
}
|
|
}
|
|
|
|
return $poststed[$postnummer] ?? "Ukjent";
|
|
} |