blob: ffdc9d63e5dca08f02b0450052cbd4ccfa2c924a [file] [log] [blame]
<?php
require_once("/home/data/httpd/eclipse-php-classes/system/dbconnection_foundation.class.php");
class Person {
#*****************************************************************************
#
# person.class.php
#
# Author: Denis Roy
# Date: 2004-08-05
#
# Description: Functions and modules related to User objects
# Stolen on: Nov 25/05 for use with the new website. M. Ward
#
# HISTORY:
#
#*****************************************************************************
var $PersonID = "";
var $FName = "";
var $LName = "";
var $Type = 0;
var $EMail = "";
var $Phone = "";
var $Fax = "";
var $Mobile = "";
var $Address1 = "";
var $Address2 = "";
var $Address3 = "";
var $City = "";
var $Province = "";
var $Country = "";
var $Postal = "";
//define a constant value. the max number of time to try and create a userid
var $MAX_ATTEMPTS = 10;
function getPersonID() {
return $this->PersonID;
}
function getFName() {
return $this->FName;
}
function getLName() {
return $this->LName;
}
function getType() {
return $this->Type;
}
function getEMail() {
return $this->EMail;
}
function getPostal() {
return $this->Postal;
}
function getPhone() {
return $this->Phone;
}
function getFax() {
return $this->Fax;
}
function getMobile() {
return $this->Mobile;
}
function getAddress1() {
return $this->Address1;
}
function getAddress2() {
return $this->Address2;
}
function getAddress3() {
return $this->Address3;
}
function getCity() {
return $this->City;
}
function getProvince() {
return $this->Province;
}
function getCountry() {
return $this->Country;
}
function setPersonID($_PersonID) {
$this->PersonID = $_PersonID;
}
function setFName($_FName) {
$this->FName = $_FName;
}
function setLName($_LName) {
$this->LName = $_LName;
}
//reflects EMployee or INdividual
function setType($_Type) {
$this->Type = $_Type;
}
function setEMail($_EMail) {
$this->EMail = $_EMail;
}
function setPhone($_Phone) {
$this->Phone = $_Phone;
}
function setFax($_Fax) {
$this->Fax = $_Fax;
}
function setMobile($_Mobile) {
$this->Mobile = $_Mobile;
}
function setAddress1($_Address1) {
$this->Address1 = $_Address1;
}
function setAddress2($_Address2) {
$this->Address2 = $_Address2;
}
function setAddress3($_Address3) {
$this->Address3 = $_Address3;
}
function setCity($_City) {
$this->City = $_City;
}
function setProvince($_Province) {
$this->Province = $_Province;
}
function setPostal($_Postal) {
$this->Postal = $_Postal;
}
function setCountry($_Country) {
$this->Country = $_Country;
}
function CreatePersonID (){
//set the max number of lastname chars
$MAX_LAST = 8;
//gen a username
$username = strtolower(substr($this->FName,0,1) . preg_replace('/[ -\']/i','',substr($this->LName,0,$MAX_LAST) ) );
$loops = 2;
//check if the given user name is already in use, or if we have exceed the max # of loops.
while( ( $this->selectPersonIDExists($username) ) && ( loops <= $this->MAX_ATTEMPTS ) && ( (strlen($this->FName)-loops) >= 1 ) ) {
//now if the username exsits then try and gen a new one.
$username = strtolower(substr($this->FName,0,$loops) . preg_replace('/[ -\']/i','',substr($this->LName,0, ($MAX_LAST-$loops) ) ) );
$loops+=1;
}
//ok did we go through the max number of loops(10)
if( $loops >= 10 )
return -1;
else {
//set the username
$this->PersonID = $username;
return 0;
}
}
function insertPerson() {
$App = new App();
$dbc = new DBConnectionRW();
$dbh = $dbc->connect();
# insert
$sql = "INSERT INTO People (
PersonID,
FName,
LName,
Type,
EMail,
Phone,
Fax,
Mobile,
IsUnixAcctCreated
)
VALUES (
" . $App->returnQuotedString($this->getPersonID()) . ",
" . $App->returnQuotedString($this->getFName()) . ",
" . $App->returnQuotedString($this->getLName()) . ",
" . $App->returnQuotedString($this->getType()) . ",
" . $App->returnQuotedString($this->getEMail()) . ",
" . $App->returnQuotedString($this->getPhone()) . ",
" . $App->returnQuotedString($this->getFax()) . ",
" . $App->returnQuotedString($this->getMobile()) . ",\"0\");
";
mysql_query($sql, $dbh)or die (mysql_error()) ;
$sql = "INSERT INTO PeopleAddresses (
PersonID,
AddressID,
Address1,
Address2,
Address3,
City,
ProvStateRegion,
PostalCode,
CCode
)
VALUES (
" . $App->returnQuotedString($this->getPersonID()) . ",1,
" . $App->returnQuotedString($this->getAddress1()) . ",
" . $App->returnQuotedString($this->getAddress2()) . ",
" . $App->returnQuotedString($this->getAddress3()) . ",
" . $App->returnQuotedString($this->getCity()) . ",
" . $App->returnQuotedString($this->getProvince()) . ",
" . $App->returnQuotedString($this->getPostal()) . ",
" . $App->returnQuotedString($this->getCountry()) . ");
";
mysql_query($sql, $dbh)or die (mysql_error()) ;
$sql = "INSERT INTO SYS_ModLog ( LogTable, PK1, PK2, LogAction, PersonID ) VALUES (
\"People\",
" . $App->returnQuotedString($this->getPersonID()) . ",
\"Initial\",
\"INSERT\",
\"WebScript\" );
";
mysql_query($sql, $dbh)or die (mysql_error()) ;
$dbc->disconnect();
}
function selectPersonExists() {
$result = 0;
if( ($this->FName != "") && ($this->LName != "") && ($this->EMail != "") ) {
$App = new App();
$dbc = new DBConnectionRW();
$dbh = $dbc->connect();
$sql = "SELECT COUNT(*) AS RecordCount
FROM People
WHERE FName = " . $App->returnQuotedString($this->getFName()) . " AND LName = " . $App->returnQuotedString($this->getLName()) . "
AND EMail = " . $App->returnQuotedString($this->getEMail()) . ";";
$result = mysql_query($sql, $dbh) or die (mysql_error()) ;
$myrow = mysql_fetch_array($result);
$result = $myrow['RecordCount'];
$dbc->disconnect();
return $result;
}
return -1;
}
function selectPersonIDExists($_PersonID) {
$result = 0;
if($_PersonID != "") {
$App = new App();
$dbc = new DBConnectionRW();
$dbh = $dbc->connect();
$sql = "SELECT COUNT(*) AS RecordCount
FROM People
WHERE PersonID = " . $App->returnQuotedString($_PersonID) .";";
$result = mysql_query($sql, $dbh)or die (mysql_error()) ;
$myrow = mysql_fetch_array($result);
$result = $myrow['RecordCount'];
$dbc->disconnect();
}
return $result;
}
}
?>