public function Save($updateLastUpdated = false) { // A valid stake ID is required. if (!Stake::Load($this->StakeID)) { fail("Cannot save account information for leader with email: {$this->Email} -- a valid stake ID is required ({$this->StakeID} is not valid)."); } // Make sure the email address is unique $this->Email = trim($this->Email); $q = "SELECT 1 FROM Credentials WHERE Email='{$this->Email}' AND ID!='{$this->CredentialsID}' LIMIT 1"; if (mysql_num_rows(DB::Run($q)) > 0) { fail("Could not save account info for {$this->Email}. That email address is already in use by another stake leader or member."); } // For EmailJobs, make sure name and email has no delimiting characters. // (Just trim them out; validation should have already occurred.) $this->Email = str_replace("=", "", $this->Email); $this->Email = str_replace(",", "", $this->Email); $this->FirstName = str_replace("=", "", $this->FirstName); $this->FirstName = str_replace(",", "", $this->FirstName); $this->LastName = str_replace("=", "", $this->LastName); $this->LastName = str_replace(",", "", $this->LastName); if ($updateLastUpdated) { $this->LastUpdated = now(); } // Prepare to save this object. It goes in two parts: Credentials and Member data. // The BuildCredentialsSaveQuery function will remove the fields which are not // in the StakeLeaders table, after using them in building the query. $objectVars = get_object_vars($this); $q = DB::BuildCredentialsSaveQuery($this, $objectVars); $r = DB::Run($q); if (!$this->CredentialsID) { $this->CredentialsID = mysql_insert_id(); } $q = DB::BuildSaveQuery($this, $objectVars); $r = DB::Run($q); if (!$this->ID) { $this->ID = mysql_insert_id(); return $this->Save(); } return $r ? true : false; }
public function Save($updateLastUpdated = false) { // A valid ward ID is required. if (!Ward::Load($this->WardID)) { fail("Cannot save account information for {$this->Email} -- a valid ward ID is required ({$this->WardID} is not valid)."); } // Make sure the email address and the email ACCOUNT is unique (foo+a@bar.com is not unique to foo+b@bar.com) $this->Email = trim($this->Email); $q = "SELECT 1 FROM Credentials WHERE Email='{$this->Email}' AND ID!='{$this->CredentialsID}' LIMIT 1"; if (mysql_num_rows(DB::Run($q)) > 0) { fail("Could not save account info for {$this->Email}. That email address is already in use by another member."); } // Standardize the phone number $this->PhoneNumber = preg_replace("/[^0-9A-Za-z]+/", "", $this->PhoneNumber); $this->PhoneNumber = strtoupper($this->PhoneNumber); // Turn it into number-only (e.g. 123-6454 instead of 123-PINK) -- some phones don't have letters with the digits $this->PhoneNumber = phoneAlphaToNumeric($this->PhoneNumber); // For EmailJobs, make sure name and email has no delimiting characters. // (Just trim them out; validation should have already occurred.) $this->Email = str_replace("=", "", $this->Email); $this->Email = str_replace(",", "", $this->Email); $this->FirstName = str_replace("=", "", $this->FirstName); $this->FirstName = str_replace(",", "", $this->FirstName); $this->LastName = str_replace("=", "", $this->LastName); $this->LastName = str_replace(",", "", $this->LastName); if ($updateLastUpdated) { $this->LastUpdated = now(); } // Prepare to save this object. It goes in two parts: Credentials and Member data. // The BuildCredentialsSaveQuery function will remove the fields which are not // in the Members table, after using them in building the query. $objectVars = get_object_vars($this); $q = DB::BuildCredentialsSaveQuery($this, $objectVars); $r = DB::Run($q); if (!$this->CredentialsID) { $this->CredentialsID = mysql_insert_id(); } $q = DB::BuildSaveQuery($this, $objectVars); $r = DB::Run($q); if (!$this->ID) { $this->ID = mysql_insert_id(); return $this->Save(); } return $r ? true : false; }