Documentation is available at Person.inc
- <?php
- ################################################################
- # This file is part of SlidingDoors #
- # Copyright 2001-2002. Eric D. Nielsen, All rights reserverd #
- # SlidingDoors is availible for license under the GPL, see #
- # the COPYING file in the root directory of the install for #
- # the full terms of the GPL. #
- # #
- # File: Person.inc #
- # Author: Eric D. Nielsen #
- # Description: The person class #
- # Attributes: org -- linked to another storeable object #
- # Constructor: person #
- # Methods: validateInputs #
- # populateFromFormVars #
- # Accessors/Mutators: get/setFirstName #
- # get/setLastName #
- # get/setEmail #
- # get/setAffil #
- # Change Log: 6/12/01 -- created -- edn #
- # 7/02/02 -- GPL, PrepStep enabled -- edn #
- # 10/30/04 -- Temporalization -- edn
- ################################################################
- class Person extends StoredObject
- {
- var $org;
- var $address;
- function Person($db=0, $id=0)
- ############################################################
- # Method: Person (constructor) #
- # Arguments: db -- the database to load/save this person #
- # id -- the id of the person, from the db #
- # Returns: the new person object #
- ############################################################
- {
- $this->primeField="id";
- $this->setID($id);
- StoredObject::StoredObject($db);
- GLOBAL $SD_elements;
- if (in_array("Name",$SD_elements))
- $this->addTable("people",
- "peopleid","id",
- array("firstname","lastname"),
- array("firstname","lastname"));
- if (in_array("Affiliation",$SD_elements))
- {
- $this->addTable("people",
- "peopleid","id",
- array("organization"),
- array("organizationID"));
- $this->org = new Organization($this->db);
- }
- if (in_array("Email",$SD_elements))
- $this->addTable( "people_contact",
- "peopleid","id",
- array("emailday"),array("email"));
- if (in_array("Fee Category",$SD_elements))
- $this->addTable( "people_classification",
- "peopleid", "id",
- array("agelevel"),
- array("feeLevel"));
- if (in_array("Birth Year",$SD_elements))
- {
- $this->addTable("people_birthdays",
- "peopleid","id",
- array("year"),array("birthyear"));
- }
- if (in_array("Home Phone", $SD_elements))
- {
- $this->addTable("people_contact",
- "peopleid","id",
- array("phoneeve"),array("phonehome"));
- }
- if (in_array("Address", $SD_elements))
- {
- $this->addTable("people",
- "peopleid","id",
- array("address"),array("addressID"));
- $this->address= new Address($this->db);
- }
- if (in_array("USABDA Number", $SD_elements))
- {
- $this->addTable("people_id_numbers",
- "peopleid","id",
- array("organization","idnumber"),
- array("USABDANO","usabdaID"));
- }
- if (in_array("Package",$SD_elements))
- {
- $this->addTable("people_paying",
- "peopleid","id",
- array("org_pays","orgid"),
- array("orgPays","orgPaying"));
- $this->addTable("packages_purchased",
- "peopleid","id",
- array("packageid"),array("packageid"));
- }
- if ($id)
- $this->retrieve();
- }
- function retrieve()
- {
- global $SD_elements;
- StoredObject::retrieve();
- if (in_array("Affiliation",$SD_elements))
- {
- $this->org = new Organization($this->db);
- $this->org->setID($this->fields["organizationID"]);
- $this->org->retrieve();
- }
- if (in_array("Address",$SD_elements))
- {
- $this->address = new Address($this->db);
- $this->address->setID($this->fields["addressID"]);
- $this->address->retrieve();
- }
- }
- #############################################################
- # Function: validateInputs #
- # Arguements: formVars -- will contain the validated inputs #
- # along with error messages for #
- # invalid inputs #
- # type -- <PRIME | PARTNER | PRIME-UPDATE> #
- # used in determining which fields are #
- # required and where the inputs are #
- # stored #
- # Returns: TRUE iff the inputs are valid, FALSE otherwise #
- # Modifies: formVars #
- #############################################################
- function validateInputs(&$formVars,$type="PRIME")
- {
- GLOBAL $SD_elements;
- GLOBAL $SD_allow_TBAs;
- GLOBAL $SD_prime_is_always_leader;
- GLOBAL $SD_error_text_color;
- switch ($type)
- {
- case "PRIME" : $prime=TRUE; $update=FALSE; $partner=FALSE;
- $prefix=""; $Prefix=""; $label="your "; break;
- case "PARTNER" : $prime=FALSE; $update=FALSE; $partner=TRUE;
- $prefix=""; $Prefix=""; $label= "your partner's ";
- break;
- case "PRIME-UPDATE" : $prime=TRUE; $update=TRUE; $partner=FALSE;
- $prefix="update";
- $label="your "; break;
- default : break;
- }
- $needsName = in_array("Name",$SD_elements);
- $needsEmail = in_array("Email",$SD_elements);
- $needsFee = in_array("Fee Category",$SD_elements);
- $needsPackage = in_array("Package",$SD_elements);
- $needsUsabda = in_array("USABDA Number",$SD_elements);
- $needsAffil = in_array("Affiliation",$SD_elements);
- $needsPhone = in_array("Home Phone",$SD_elements);
- $needsAddress = in_array("Address",$SD_elements);
- $needsBirthYear = in_array("Birth Year",$SD_elements);
- $tbaPost = $Prefix ."TBA";
- $tba = isset($_POST[$tbaPost]) ?
- $_POST[$tbaPost] : "";
- $role = isset($_POST["role"]) ? $_POST["role"] : "";
- $firstNamePost = $prefix."FirstName";
- $firstNameMsg =$firstNamePost."Msg";
- $firstName = isset($_POST[$firstNamePost]) ?
- htmlspecialchars($_POST[$firstNamePost]) : "";
- $lastNamePost = $prefix."LastName";
- $lastNameMsg =$lastNamePost."Msg";
- $lastName = isset($_POST[$lastNamePost])?
- htmlspecialchars($_POST[$lastNamePost]) : "";
- $newAffilPost = $prefix."NewAffil";
- $newAffilMsg =$newAffilPost."Msg";
- $newAffil = isset($_POST[$newAffilPost])?
- htmlspecialchars($_POST[$newAffilPost]) : "";
- $affilShortPost = $prefix."AffilShort";
- $affilShortMsg =$affilShortPost."Msg";
- $affilShort = isset($_POST[$affilShortPost]) ?
- htmlspecialchars($_POST[$affilShortPost]) : "";
- $affilIDPost = $prefix."AffilID";
- $affilIDMsg =$affilIDPost."Msg";
- $affilID = isset($_POST[$affilIDPost]) ?
- $_POST[$affilIDPost]:""; # id's from db
- $emailPost = $prefix."Email";
- $emailMsg =$emailPost."Msg";
- $email = isset($_POST[$emailPost])?
- strtolower(htmlspecialchars($_POST[$emailPost])) : "";
- $feePost = $prefix."Fee";
- $feeMsg =$feePost."Msg";
- $fee = isset($_POST[$feePost])?
- $_POST["$feePost"] :"";
- $packagePost = $prefix."Package";
- $packageMsg =$packagePost."Msg";
- $package = isset($_POST[$packagePost]) ?
- $_POST[$packagePost] : "";
- $birthyearPost = $prefix."Birthyear";
- $birthyearMsg = $birthyearPost."Msg";
- $birthyear = isset($_POST[$birthyearPost])?
- htmlspecialchars($_POST[$birthyearPost]) : "";
- $homephonePost = $prefix."HomePhone";
- $homephoneMsg = $homephonePost."Msg";
- $homephone = isset($_POST[$homephonePost]) ?
- htmlspecialchars($_POST[$homephonePost]) : "";
- $usabdaPost = $prefix."UsabdaNumber";
- $usabdaMsg = $usabdaPost."Msg";
- $usabda = isset($_POST[$usabdaPost]) ?
- htmlspecialchars($_POST[$usabdaPost]) :"";
- $validated= TRUE;
- # handle TBA special cases, over-ridden values are saved during the
- # regular processing of that field
- if ($SD_allow_TBAs)
- {
- if ($tba || $firstName=="TBA")
- {
- $tba=TRUE;
- if ($needsName)
- {
- $firstName="TBA";
- if (!is_num($lastName))
- $lastName = $this->db->getNextTBA();
- }
- else if ($needsEmail)
- $email = "TBA.".$this->db->getNextTBA();
- if ($needsAffil)
- $affilID=-1;
- }
- } else $tba=FALSE;
- # handle first/last names; save value if non empty. Names are required
- # to be filled out, even if TBA, above special case code ensures this
- if ($needsName)
- {
- if ($firstName!="")
- $formVars["$firstNamePost"]=$firstName;
- else
- {
- $formVars[$firstNameMsg]="<font color=\"$SD_error_text_color\">Please enter $label first name.</font><br />\n";
- $validated=FALSE;
- }
- if ($lastName!="")
- $formVars["$lastNamePost"]=$lastName;
- else
- {
- $formVars[$lastNameMsg]="<font color=\"$SD_error_text_color\">Please enter $label last name.</font><br />\n";
- $validated=FALSE;
- }
- }
- # handle email, does not validate or even regexp check, email may
- # be empty if tba and name used
- if ($needsEmail)
- if ($email!="")
- $formVars["$emailPost"]=$email;
- else if (!$tba)
- {
- $formVars[$emailMsg]="<font color=\"$SD_error_text_color\">Please enter $label email.</font><br />\n";
- $validated=FALSE;
- }
- if ($needsAddress)
- {
- $anAddress = new Address($this->db);
- $addressValid = $anAddress->validateInputs($formVars,$prefix,$tba);
- $validated= $validated && $addressValid;
- }
- if ($needsPhone)
- if ($homephone!="")
- $formVars["$homephonePost"]=$homephone;
- else if (!$tba)
- {
- $formVars[$homephoneMsg]="<font color=\"$SD_error_text_color\">Please enter $label home phone.</font><br />\n";
- $validated=FALSE;
- }
- if ($needsUsabda)
- if ($usabda!="")
- $formVars["$usabdaPost"]=$usabda;
- else if (!$tba)
- {
- $formVars[$usabdaMsg]="<font color=\"$SD_error_text_color\">Please enter $label USABDA or enter \"Pending\".</font><br />\n";
- $validated=FALSE;
- }
- # handle packages, should never be empty, but just in case
- if ($needsPackage)
- if ($package!="")
- $formVars["$packagePost"]=$package;
- else if (!$tba)
- {
- $formVars[$packageMsg]="<font color=\"$SD_error_text_color\">Please select $label registration package.</strong><br />\n";
- $validated=FALSE;
- }
- # handles fee category, should never be empty
- if ($needsFee)
- if ($fee!="")
- $formVars["$feePost"]=$fee;
- else
- {
- $formVars[$feeMsg]="<font color=\"$SD_error_text_color\">Please select $label fee category.</strong><br />\n";
- $validated=FALSE;
- }
- # handle the complicated affiliation cases
- if ($needsAffil)
- {
- if ($affilID=="choose")
- $affilID="";
- if ($affilID!="")
- $formVars["$affilIDPost"]=$affilID;
- if ($newAffil!="")
- $formVars["$newAffilPost"]=$newAffil;
- if ($affilShort!="")
- $formVars["$affilShortPost"]=$affilShort;
- $formVars[$affilIDMsg]="";
- $formVars[$newAffilMsg]="";
- # user selected from drop down box and entered text
- if ($affilID!="" && ($newAffil!="" || $affilShort != ""))
- {
- $query = "SELECT * from organizations where name='$newAffil' AND orgid='$affilID';";
- $result = $this->db->query($query);
- if ($result->numrows()!=1)
- {
- $validated=FALSE;
- $formVars[$affilIDMsg]="<font color=\"$SD_error_text_color\">Please do not select an affiliation from the list box and also enter information into the \"New Affiliation\" boxes.</font><br />\n";
- }
- else
- {
- $newAffil=""; $affilShort="";
- }
- }
- # user didn't select nor enter text
- if ($affilID=="" && ($newAffil=="" || $affilShort == ""))
- {
- $validated=FALSE;
- $formVars[$affilIDMsg].="<font color=\"$SD_error_text_color\">Please either select an affiliation from the box, or enter a new one with long and short form in the text boxes below.</font><br />";
- }
- # user didn't select, but only entered 1 of 2 text entries
- if (($newAffil!="" && $affilShort=="") ||
- ($newAffil=="" && $affilShort!=""))
- {
- $validated = FALSE;
- $formVars[$newAffilMsg].="<font color=\"$SD_error_text_color\">Please provide both a long and short form of $label affiliation's name. Here are some examples:<br />Massachusetts Institute of Technology --> MIT<br />Harvard University --> Harvard<br />Fred Astaire Dance Studio, Boston --> FADS Boston<br /></font>";
- }
- if ($affilID=="" && $newAffil!="" && $affilShort!="")
- {
- $query = "SELECT abbreviation from abbreviations where fulltext='$newAffil';";
- $result = $this->db->query($query);
- if ($result->numrows()>0)
- {
- list($temp) = $result->getRowAt(0);
- $validated = FALSE;
- $formVars[$newAffilMsg].="<font color=\"$SD_error_text_color\">An affiliation with the name you entered already exists, please select it from the
- drop down select box, it is listed as '$temp'.</font></br>";
- }
- $query = "SELECT fulltext from abbreviations where abbreviation='$affilShort';";
- $result = $this->db->query($query);
- if ($result->numrows()>0)
- {
- list($tempName) = $result->getRowAt(0);
- $validated = FALSE;
- $formVars[$newAffilMsg].="<font color=\"$SD_error_text_color\">$tempName is already using that abbreviation. You will have to choose another.</font></br>";
- }
- $query = "SELECT orgid FROM organizations WHERE name = '$newAffil' or name LIKE '$newAffil%';";
- $result = $this->db->query($query);
- if ($result->numrows()>0)
- {
- list($tempName) = $result->getRowAt(0);
- $validated = FALSE;
- $formVars[$newAffilMsg].="<font color=\"$SD_error_text_color\">$tempName already exists in the database, please select it from the drop-down menu.</font></br>";
- }
- }
- }
- $formVals["Role"]=$role;
- if ($needsBirthYear)
- {
- $curYear = date('Y');
- if (($birthyear!="") && ($birthyear > $curYear-110) &&
- ($birthyear < $curYear))
- $formVars["$birthyearPost"]=$birthyear;
- else
- {
- $formVars[$birthyearMsg]="<font color=\"$SD_error_text_color\">Please enter a 4 digit birth year</font><br />\n";
- $validated=FALSE;
- }
- }
- return $validated;
- }
- function populateFromFormVars($formVars,$prefix="")
- #############################################################
- # Function: populateFromFormVars #
- # Arguements: formVars -- contains the values to insert #
- # prefix -- an optional string to prefix to #
- # names in FormVars before matching #
- # with fields #
- # stored #
- # Returns: nothing #
- # Modifies: this #
- #############################################################
- {
- GLOBAL $SD_elements;
- if (in_array("Name",$SD_elements))
- {
- $this->setFirstName($formVars[$prefix . "FirstName"]);
- $this->setLastName($formVars[$prefix . "LastName"]);
- $tba = $this->getFirstName()=="TBA";
- }
- if (in_array("Email",$SD_elements))
- $this->setEmail($formVars[$prefix . "Email"]);
- if (in_array("Fee Category",$SD_elements))
- $this->setFeeLevel($formVars[$prefix . "Fee"]);
- if (in_array("Package",$SD_elements))
- $this->setPackage($formVars[$prefix . "Package"]);
- if (in_array("Birth Year",$SD_elements))
- $this->setBirthyear($formVars[$prefix . "Birthyear"]);
- if (in_array("Home Phone",$SD_elements))
- $this->setHomePhone($formVars[$prefix . "HomePhone"]);
- if (in_array("Address",$SD_elements))
- {
- $anAddress = new Address($this->db);
- $addressID = $anAddress->populateFromFormVars($formVars,$prefix,
- $tba);
- $this->setAddressID($addressID);
- }
- if (in_array("USABDA Number",$SD_elements))
- $this->setUsabdaNumber($formVars[$prefix . "UsabdaNumber"]);
- if (in_array("Affiliation",$SD_elements))
- {
- $oldAffilID=$this->getAffilID();
- $oldPayingID=$this->getOrgPaying();
- $affilID= isset($formVars[$prefix."AffilID"])?
- $formVars[$prefix . "AffilID"] : "";
- if (!(($affilID=="") || ($affilID==-1)))
- {
- $this->setAffilID($affilID);
- if ($oldAffilID==$oldPayingID)
- $this->setOrgPaying($affilID);
- }
- else if ($formVars[$prefix."NewAffil"]=="")
- {
- $this->setAffilID(-1);
- $this->setOrgPays("FALSE");
- }
- }
- }
- function getPackage()
- ############################################################
- # Function: getPackage #
- # Arguments: none #
- # Returns: packageID, if no packageID found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->getGeneralData("packageid");
- }
- function setPackage($pid)
- ############################################################
- # Function: setPackage #
- # Arguments: pid #
- # Returns: nothing #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("packageid",$pid);
- }
- function getFirstName()
- ############################################################
- # Function: getFirstName #
- # Arguments: none #
- # Returns: first name, if no first name found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->getGeneralData("firstname");
- }
- function getLastName()
- ############################################################
- # Function: getLastName #
- # Arguments: none #
- # Returns: last name, if no last name found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->getGeneralData("lastname");
- }
- function getAgeLevel()
- {
- $age = date("Y") - $this->getBirthYear();
- $query = "SELECT levelname FROM age_levels WHERE min_age<=$age AND max_age >=$age;";
- $result = $this->db->query($query);
- if ($result->numrows()>0)
- {
- list($ans) = $result->getRowAt(0);
- }
- else
- $ans="";
- return $ans;
- }
- function getEmail()
- ############################################################
- # Function: getEmail #
- # Arguments: none #
- # Returns: email, if no email found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->fields["email"];
- }
- function getAffil()
- ############################################################
- # Function: getAffil #
- # Arguments: none #
- # Returns: affiliation, if no affiliation found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->org->getAbbrev();
- }
- function getAffilID()
- ############################################################
- # Function: getAffil #
- # Arguments: none #
- # Returns: affiliation, if no affiliation found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->getGeneralData("organizationID");
- }
- function getFeeLevel()
- ############################################################
- # Function: getFeeLevel #
- # Arguments: none #
- # Returns: fee level, if no level found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->getGeneralData("feeLevel");
- }
- function getClass()
- ############################################################
- # Function: getClass #
- # Arguments: none #
- # Returns: classification, if no class found returns "" #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->getGeneralData("class");
- }
- function getOrgPays()
- {
- $temp = $this->getGeneralData("orgPays");
- return ($temp=="t"? TRUE : FALSE);
- }
- function getOrgPaying()
- {
- return $this->getGeneralData("orgPaying");
- }
- function setOrgPaying($data)
- {
- return $this->setGeneralData("orgPaying",$data);
- }
- function getBirthyear()
- {
- return $this->getGeneralData("birthyear");
- }
- function getHomePhone()
- {
- return $this->getGeneralData("phonehome");
- }
- function setHomePhone($data)
- {
- return $this->setGeneralData("phonehome",$data);
- }
- function getAddressID()
- {
- return $this->getGeneralData("addressID");
- }
- function setAddressID($data)
- {
- $this->address->setID($data);
- $this->address->retrieve();
- return $this->setGeneralData("addressID",$data);
- }
- function getUsabdaNumber()
- {
- return $this->getGeneralData("usabdaID");
- }
- function setUsabdaNumber($data)
- {
- global $SD_USABDA_ORG_ID;
- $this->setGeneralData("USABDANO",$SD_USABDA_ORG_ID);
- return $this->setGeneralData("usabdaID",$data);
- }
- function setAgeLevel($ageLevel)
- ############################################################
- # Function: setAgeLevel #
- # Arguments: ageLevel -- the ageLevel to set #
- # Returns: 1 if set, 0 otherwise (never) #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("ageLevel",$ageLevel);
- }
- function setFeeLevel($feeLevel)
- ############################################################
- # Function: setFeeLevel #
- # Arguments: feeLevel -- the feeLevel to set #
- # Returns: 1 if set, 0 otherwise (never) #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("feeLevel",$feeLevel);
- }
- function setClass($class)
- ############################################################
- # Function: setClass #
- # Arguments: class -- the class to set #
- # Returns: 1 if set, 0 otherwise (never) #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("class",$class);
- }
- function setFirstName($firstName)
- ############################################################
- # Function: setFirstName #
- # Arguments: firstName -- the firstName to set #
- # Returns: 1 if set, 0 otherwise (never) #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("firstname",$firstName);
- }
- function setLastName($lastName)
- ############################################################
- # Function: setLastName #
- # Arguments: lastName -- the last name to set #
- # Returns: 1 if set, 0 otherwise #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("lastname",$lastName);
- }
- function setEmail($email)
- ############################################################
- # Function: setEmail #
- # Arguments: email -- the email to set #
- # Returns: 1 if set, 0 otherwise #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- return $this->setGeneralData("email", $email);
- }
- function setAffilID($affil)
- ############################################################
- # Function: setAffil #
- # Arguments: affil -- the affil to set #
- # Returns: 1 if set, 0 otherwise #
- # Requires: nothing #
- # Modifies: nothing #
- ############################################################
- {
- if ($this->fields["orgPays"]=="" && $affil!=-1 && $affil!="")
- {
- $query = "SELECT org_pays FROM registration_supplement ";
- $query.= "WHERE orgid=$affil;";
- $result = $this->db->query($query);
- if ($result->numRows())
- {
- list($orgPays) = $result->getRowAt(0);
- $orgPays = ($orgPays=="t");
- $this->setOrgPays($orgPays);
- if ($orgPays)
- $this->setOrgPaying($affil);
- else
- $this->setOrgPaying(0);
- }
- }
- else if ($affil==-1 || $affil=="")
- {
- $this->setOrgPays("FALSE");
- $this->setOrgPaying(0);
- }
- return $this->setGeneralData("organizationID",$affil);
- }
- function setBirthyear($data)
- {
- return $this->setGeneralData("birthyear",$data);
- }
- function setOrgPays($data)
- {
- return $this->setGeneralData("orgPays",($data ? "TRUE" : "FALSE"));
- }
- }
- ?>
Documentation generated on Tue, 25 Apr 2006 13:07:41 -0400 by phpDocumentor 1.3.0RC3