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 Permissions($removeOverlap = true) { $permissions = array(); $wardID = DB::Safe($_SESSION['wardID']); $questionQuery = DB::Run("SELECT ID FROM SurveyQuestions WHERE WardID='{$wardID}'"); while ($questionRow = mysql_fetch_array($questionQuery)) { $per = new Permission(); // Ad-hoc part. We're not looking up permissions by calling or name. $per->QuestionID($questionRow['ID']); $permissions[] = $per; } return $permissions; }
} if ($allCallings && $callingID) { fail("You selected to set this permission for ALL callings but chose a specific calling. Which one? Please go back and try again."); } if ($allMembers && $callingID || $allCallings && $memberID) { fail("You chose a wildcard permission across all callings or members but also chose a specific member or calling. Please select only one or the other."); } // Make sure the selected member or calling is in this ward if ($callingID) { $c = Calling::Load($callingID); if ($c->WardID() != $MEMBER->WardID) { fail("The calling you chose is not in your ward."); } } else { if ($memberID) { $m = Member::Load($memberID); if ($m->WardID != $MEMBER->WardID) { fail("The member you chose is not in your ward."); } } } $objID = $callingID ? $callingID : $memberID; $objType = $callingID ? "Calling" : "Member"; $n = count($questionID); for ($i = 0; $i < $n; $i++) { $p = new Permission(); $p->QuestionID($questionID[$i]); $p->Allow($objID, $objType, true); } // Must do a redirect because this form isn't ajax-ified... header("Location: ../permissions.php");