Example #1
0
 public function Save()
 {
     $q = DB::BuildSaveQuery($this, get_object_vars($this), false);
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #2
0
 public function Save()
 {
     if (!$this->WardID) {
         return false;
     }
     // Must belong to a ward
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
 public function Save()
 {
     // Can we have multiple answer options of the exact
     // same value for the same question?
     // Right now... NO.
     // Make safe the answer value before our preliminary query (including stripping HTML tags)
     $safeAns = DB::Safe($this->AnswerValue);
     $q = "SELECT 1 FROM SurveyAnswerOptions WHERE QuestionID='{$this->QuestionID}' AND AnswerValue='{$safeAns}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         fail("Hmmm, this answer option ({$this->AnswerValue}) already exists for this question. Are you sure you didn't mean something else?");
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #4
0
 public function Save()
 {
     if (!$this->QuestionID || !$this->ObjectID || !$this->ObjectType) {
         return false;
     }
     // Make sure the permission is unique
     $q = "SELECT 1 FROM Permissions WHERE QuestionID='{$this->QuestionID}' AND ObjectID='{$this->ObjectID}' AND ObjectType='{$this->ObjectType}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         // We don't need to kill the script...? Just return false.
         //die("It appears that ".strtolower($this->ObjectType)." already has permissions for that information. Permission not saved; aborting.");
         return false;
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #5
0
 public function Save()
 {
     // Should we be able to save multiple answers to the
     // same question for the same member? No.
     // Make safe the user's input, then let's prevent duplication.
     if (is_array($this->AnswerValue)) {
         $this->AnswerArrayToString();
     }
     $safeAns = DB::Safe($this->AnswerValue);
     // Strips HTML tags, just be aware of that.
     $q = "SELECT 1 FROM SurveyAnswers WHERE AnswerValue='{$safeAns}' AND QuestionID='{$this->QuestionID}' AND MemberID='{$this->MemberID}' AND ID!='{$this->ID}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         fail("Oops. Could not save this answer; this user has already answered that question, but instead of changing the existing answer we tried adding a new one. Huh.");
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #6
0
 public function Save()
 {
     // The ward ID and question content is required!
     if (!$this->WardID || !trim($this->Question)) {
         fail("ERROR > Cannot save this question without a ward ID and question text.");
     }
     if (!Ward::Load($this->WardID)) {
         fail("ERROR > Cannot save question \"" . $this->Question . "\" because the ward ID (" . $this->WardID . ") is found to be invalid.");
     }
     // Make sure the question is unique
     $safeQ = DB::Safe($this->Question);
     $q = "SELECT 1 FROM SurveyQuestions WHERE Question='{$safeQ}' AND WardID='{$this->WardID}' AND ID!='{$this->ID}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         fail("Oops. Could not save question; that question already exists in this ward.");
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #7
0
 public function Save()
 {
     if (!$this->Name || !$this->WardID) {
         return false;
     }
     if (!$this->ID) {
         $this->ID = 0;
     }
     $this->Name = trim($this->Name);
     // Sanitize the name before we use it in our query below...
     $safeName = DB::Safe($this->Name);
     // Make sure the calling title is unique
     $q = "SELECT 1 FROM Callings WHERE Name='{$safeName}' AND WardID='{$this->WardID}' AND ID!='{$this->ID}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         fail("Oops. Could not save Calling information; the name of the calling already exists in this ward.");
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #8
0
 public function Save()
 {
     if (!$this->GroupName || !$this->WardID) {
         return false;
     }
     if (!$this->ID) {
         $this->ID = 0;
     }
     // Pascal-case the FHE group name for consistency
     $this->GroupName = ucwords(strtolower(trim($this->GroupName)));
     // Sanitize the name before we use it in our query below...
     $safeName = DB::Safe($this->GroupName);
     // Make sure the group title is unique
     $q = "SELECT 1 FROM FheGroups WHERE GroupName='{$safeName}' AND ID!='{$this->ID}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         fail("Oops. Could not save the FHE group; the name is already the name of another group, and they must be unique.");
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }
Example #9
0
 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;
 }
Example #10
0
 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;
 }
Example #11
0
 public function Save()
 {
     if (!$this->Name || !$this->StakeID || !$this->Password) {
         return false;
     }
     if (!$this->ID) {
         $this->ID = 0;
     }
     $this->Name = trim(strip_tags(str_ireplace("ward", "", $this->Name)));
     // Sanitize the name before we use it in our query below... (and strip tags)
     $safeName = DB::Safe($this->Name);
     // Make sure the ward name is unique
     $q = "SELECT 1 FROM Wards WHERE Name='{$safeName}' AND StakeID='{$this->StakeID}' AND ID!='{$this->ID}' LIMIT 1";
     if (mysql_num_rows(DB::Run($q)) > 0) {
         fail("Oops. Could not save Ward information; the name of the ward already exists in its stake.");
     }
     $q = DB::BuildSaveQuery($this, get_object_vars($this));
     $r = DB::Run($q);
     if (!$this->ID) {
         $this->ID = mysql_insert_id();
     }
     return $r ? true : false;
 }