<?php
require_once ("err.php");
require_once ("pg.php");

class User {

    var $uid, $username, $firstname, $lastname, $fullname, $fail;

    function User ($ident) {
	global $db;
	$db->connect("hardweb","hardweb","hardweb");
	if (is_numeric($ident)) {
	    $res = $db->query (
		"select uid,username,firstname,lastname,fullname from usernames
		 where uid=$ident"
	    );
	} else {
	    $res = $db->query (
		"select uid,username,firstname,lastname,fullname from usernames
		 where username='$ident'"
	    );
	}

	if (gettype($res) != 'resource' || !pg_numrows($res)) {
	    $this->fail = new Err ("NOUSER",$ident);
	    return;
	} else {
	    $dbrec=pg_fetch_object($res,0);
	    $this->uid=$dbrec->uid;
	    $this->username=$dbrec->username;
	    $this->firstname=$dbrec->firtsname;
	    $this->lastname=$dbrec->lastname;
	    $this->fullname=$dbrec->fullname;
	    $db->close;

}
    }
}

$caller = new User ("fiserp");
if ($caller->fail) terminate ($caller->fail);
?>