<?/*
Copyright (C) 2003 Media Net Link, Inc. Danville, CA 94526 USA

This file is part of AthenaRMS.

AthenaRMS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

AthenaRMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/?>
<?php

require_once 'lib/base_object.php';

class User {

  function User extends Base_Object ($obj='') {
    global $dbi;
    $this->db = &$dbi;

    $this->Use_Person_Object ($obj);
  }

  function Set_Person_Object ($obj) {
    $this->person_obj = $obj;
  }

  function Init_Person_Object () {
    require_once 'person.php';

    $this->person_obj = new Person_Record ();
  }

  function Use_Person_Object ($obj='') {
    #if ($this->person_obj) { return; }

    if ($obj) {
      $this->Set_Person_Object ($obj);
    } else {
      $this->Init_Person_Object ();
    }
  }

  function Is_Super_Admin ($user='') {
    if (!$user) { $user = $this->Person_Logged_In (); }

    $pid = $this->To_Person_ID ($user);

    if (!$pid) { return 0; }

    $a = $this->person_obj->Get_Types ($pid);

    if (in_array ('Super Admin', $a)) {
      return 1;
    }

    return 0;
  }

  function To_Person_ID ($uid_or_pid) {
    if (!$uid_or_pid) { return; }

    if ($this->person_obj->Is_Person_ID ($uid_or_pid)) {
      return $uid_or_pid;
    } else {
      return $this->person_obj->from_username ($uid_or_pid);
    }
  }
}
?>
