<?php
require_once ("/data/hwextra/common/common.php");
require_once ("/data/hwextra/common/obj/err.php");
require_once ("/data/hwextra/common/obj/pg.php");
require_once ("/data/hwextra/common/obj/persts.php");


// 'generation 1' persistent group
//  no membership yet
//  no update / delete yet

class Group {
    var $gid,
	$groupname,
	$psts,		// persistence status
	$fail;		// failure status


    function fetch () {
	global $db;
	if ($gid) {
	    $res=$db->query (
		"select gid,groupname from groupnames
		 where gid=$this->gid"
	    );
	} else {
	    $res=$db->query (
		"select gid,groupname from groupnames
		 where groupname='$this->groupname'"
	    );
	}

	if (gettype ($res) != 'resource') return $res;
	if (pg_numrows($res)==0) {
	    $this->psts &= ~DB_EX;
	    $this->psts |=  DB_NOEX;
	} else {
	    $this->psts |=  DB_EX;
	    $this->psts &= ~DB_NOEX;

	    $dbobj=pg_fetch_object ($res,0);
	    $this->gid=$dbobj->gid;
	    $this->groupname=$dbobj->groupname;
	}
    }

    function Group ($ident, $psts) {

	$this->psts = $psts;
	if (is_numeric($ident)) {
	    $this->gid=$ident;
	} else {
	    $this->groupname=$ident;
	}

	if (!($psts & DB_NOEX) 
	and !($psts & DB_DIRTY) 
	and !$this->fail) {
	    $this->fail=$this->fetch();
	}
    }
}
?>
