public function create($survey_id = null) { $this->tinymce = true; $survey = self::load_survey($survey_id); $question = new SurveyQuestion(); $question->survey = $survey; $question->survey_id = $survey->id; if ($this->post) { $question->name = $this->PostData("name"); $question->description = $this->PostData("description"); $question->type = $this->PostData("type"); $question->regex = $this->PostData("regex"); $question->required = $this->PostData("required"); if ($question->Save()) { Site::Flash("notice", "The question has been created"); Redirect("admin/surveys/{$survey->id}#questions"); } } $this->assign("survey", $survey); $this->assign("question", $question); $this->title = "New Question"; $this->render("survey_question/create.tpl"); }
} } // Is this question designed to have answer choices/options? $multAns = $qtype == QuestionType::MultipleChoice || $qtype == QuestionType::MultipleAnswer; // Make sure that multiple-answer/choice questions have at least one // to choose from if ($multAns && $ansEmpty) { Response::Send(401, "Oops - for that type of question, it requires at least one possible answer (you have to add one). Go BACK and try again."); } // Create question. $qu = new SurveyQuestion(); $qu->Question = $question; $qu->QuestionType = $qtype; $qu->Required = $req; $qu->Visible = $visible; $qu->WardID = $MEMBER->WardID; // Save what we have (it needs an ID in order to add answer options) if (!$qu->Save()) { fail("Could not save this question. Please report this and try again..."); } // Add answer options, if applicable if ($multAns) { foreach ($ansArray as $ans) { if (strlen(trim($ans)) > 0 && $ans != ' ' && !$qu->AddAnswerOption($ans)) { echo "Could not add answer {$ans} to this question; go back, refresh, and add this answer manually."; } } } // Set session variable so the user is notified of success, then redirect $_SESSION['created'] = true; header("Location: ../survey.php");
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; }