public static function Create($name, $stakeID, $rawPwd) { if (!strlen(trim($name)) || !$stakeID || !strlen(trim($rawPwd))) { fail("Cannot create a ward without a name, stake ID, and password (and residences are strongly recommended, if possible)."); } if (!Stake::Load($stakeID)) { fail("Could not create ward because stake ID was found to be invalid."); } $ward = new Ward(); $ward->Name = strip_tags($name); $ward->StakeID = $stakeID; $ward->Salt = salt(); $ward->Password = hashPwd($rawPwd, $ward->Salt); $ward->Balance = 2.5; $ward->Deleted = false; if (!$ward->Save()) { return null; } // Set up pre-defined callings, privileges, permissions, and a sample survey question or two. $callings = array(); $callings[1] = new Calling("Bishop", $ward->ID, true); $callings[2] = new Calling("Bishopric 1st Counselor", $ward->ID, true); $callings[3] = new Calling("Bishopric 2nd Counselor", $ward->ID, true); $callings[4] = new Calling("Executive Secretary", $ward->ID, true); $callings[5] = new Calling("Elders Quorum President", $ward->ID, true); $callings[6] = new Calling("Elders Quorum 1st Counselor", $ward->ID, true); $callings[7] = new Calling("Elders Quorum 2nd Counselor", $ward->ID, true); $callings[8] = new Calling("Elders Quorum Secretary", $ward->ID, true); $callings[9] = new Calling("Relief Society President", $ward->ID, true); $callings[10] = new Calling("Relief Society 1st Counselor", $ward->ID, true); $callings[11] = new Calling("Relief Society 2nd Counselor", $ward->ID, true); $callings[12] = new Calling("Relief Society Secretary", $ward->ID, true); $callings[13] = new Calling("Ward Clerk", $ward->ID, true); $callings[14] = new Calling("Membership Clerk", $ward->ID, true); foreach ($callings as $c) { $c->Save(); } // Save each calling // Compile an array of each privilege in the database; currently, we have IDs 1 through 13 $privileges = array(); $priv_count = mysql_fetch_row(DB::Run("SELECT COUNT(1) FROM Privileges"))[0]; for ($i = 1; $i <= $priv_count; $i++) { $privileges[$i] = Privilege::Load($i); } // Bishopric (excluding executive secretary) can mass email all ward members, // see everything in the export file, and manage privileges, and send texts for ($i = 1; $i <= 3; $i++) { $privileges[PRIV_EMAIL_ALL]->GrantToCalling($callings[$i]->ID()); $privileges[PRIV_EXPORT_EMAIL]->GrantToCalling($callings[$i]->ID()); $privileges[PRIV_EXPORT_PHONE]->GrantToCalling($callings[$i]->ID()); $privileges[PRIV_EXPORT_BDATE]->GrantToCalling($callings[$i]->ID()); $privileges[PRIV_MNG_SITE_PRIV]->GrantToCalling($callings[$i]->ID()); $privileges[PRIV_TEXT_ALL]->GrantToCalling($callings[$i]->ID()); } // Executive secretary gets all privileges (except redundant ones 2 and 3 - mass email brothers/sisters) for ($i = PRIV_EMAIL_ALL; $i <= PRIV_TEXT_ALL; $i++) { if ($i != PRIV_EMAIL_BRO && $i != PRIV_EMAIL_SIS) { $privileges[$i]->GrantToCalling($callings[4]->ID()); } } // EQ presidency gets to mass-email all brothers for ($i = 5; $i <= 8; $i++) { $privileges[PRIV_EMAIL_BRO]->GrantToCalling($callings[$i]->ID()); } // The EQ president needs to see more in the export file $privileges[PRIV_EXPORT_EMAIL]->GrantToCalling($callings[5]->ID()); $privileges[PRIV_EXPORT_PHONE]->GrantToCalling($callings[5]->ID()); $privileges[PRIV_EXPORT_BDATE]->GrantToCalling($callings[5]->ID()); // RS presidency gets to mass-email all sisters for ($i = 9; $i <= 12; $i++) { $privileges[PRIV_EMAIL_SIS]->GrantToCalling($callings[$i]->ID()); } // RS president can see more in the export file, too $privileges[PRIV_EXPORT_EMAIL]->GrantToCalling($callings[9]->ID()); $privileges[PRIV_EXPORT_PHONE]->GrantToCalling($callings[9]->ID()); $privileges[PRIV_EXPORT_BDATE]->GrantToCalling($callings[9]->ID()); // Ward clerks can see all info in export file and manage site privileges $privileges[PRIV_EXPORT_EMAIL]->GrantToCalling($callings[13]->ID()); $privileges[PRIV_EXPORT_PHONE]->GrantToCalling($callings[13]->ID()); $privileges[PRIV_EXPORT_BDATE]->GrantToCalling($callings[13]->ID()); $privileges[PRIV_MNG_SITE_PRIV]->GrantToCalling($callings[13]->ID()); // Membership clerks needs to see all info in export file, and can // manage callings, profile pictures, and delete accounts $privileges[PRIV_EXPORT_EMAIL]->GrantToCalling($callings[14]->ID()); $privileges[PRIV_EXPORT_PHONE]->GrantToCalling($callings[14]->ID()); $privileges[PRIV_EXPORT_BDATE]->GrantToCalling($callings[14]->ID()); $privileges[PRIV_MNG_CALLINGS]->GrantToCalling($callings[14]->ID()); $privileges[PRIV_MNG_PROFILE_PICS]->GrantToCalling($callings[14]->ID()); $privileges[PRIV_DELETE_ACCTS]->GrantToCalling($callings[14]->ID()); // --------------------------------------------------- // // Create a sample/starter question. $qu = new SurveyQuestion(); $qu->Question = "Welcome to the singles ward! Do you prefer blue, brown, or green eyes?"; $qu->QuestionType = QuestionType::MultipleChoice; $qu->Required = false; $qu->Visible = true; $qu->WardID = $ward->ID(); $qu->Save(); $qu->AddAnswerOption("Brown eyes"); $qu->AddAnswerOption("Blue eyes"); $qu->AddAnswerOption("Green eyes"); // Let a few people see it: Bishop, Exec. Sec, EQP, and RSP $p = new Permission(); $p->QuestionID($qu->ID()); $p->Allow($callings[1]->ID(), "Calling", true); $p->Allow($callings[4]->ID(), "Calling", true); $p->Allow($callings[5]->ID(), "Calling", true); $p->Allow($callings[9]->ID(), "Calling", true); // I think we're all done here! return $ward; }
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; }
$stakes[$sid] = array(); } $stakes[$sid][] = $wid; } ?> <select size="1" name="ward_id" id="wardid"> <option value="" <?php if (!isset($WARD)) { echo 'selected'; } ?> >Select a ward</option> <?php foreach ($stakes as $sid => $wards) { $stakeObj = Stake::Load($sid); ?> <optgroup label="<?php echo $stakeObj->Name; ?> "> <?php foreach ($wards as $wid) { // Get the bishop's name, if any. $ward = Ward::Load($wid); $bishop = $ward->GetBishop(); ?> <option value="<?php echo $wid; ?> "<?php