/**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $parishes = \montserrat\Contact::whereSubcontactType(CONTACT_TYPE_PARISH)->orderBy('organization_name', 'asc')->with('address_primary.state', 'diocese.contact_a')->get();
     $parish_list[0] = 'N/A';
     // while probably not the most efficient way of doing this it gets me the result
     foreach ($parishes as $parish) {
         $parish_list[$parish->id] = $parish->organization_name . ' (' . $parish->address_primary->city . ') - ' . $parish->diocese->contact_a->organization_name;
     }
     $countries = \montserrat\Country::orderBy('iso_code')->pluck('iso_code', 'id');
     $countries->prepend('N/A', 0);
     $ethnicities = \montserrat\Ethnicity::orderBy('ethnicity')->pluck('ethnicity', 'ethnicity');
     $ethnicities->prepend('N/A', 0);
     $genders = \montserrat\Gender::orderBy('name')->pluck('name', 'id');
     $genders->prepend('N/A', 0);
     $languages = \montserrat\Language::orderBy('label')->whereIsActive(1)->pluck('label', 'id');
     $languages->prepend('N/A', 0);
     $prefixes = \montserrat\Prefix::orderBy('name')->pluck('name', 'id');
     $prefixes->prepend('N/A', 0);
     $religions = \montserrat\Religion::orderBy('name')->whereIsActive(1)->pluck('name', 'id');
     $religions->prepend('N/A', 0);
     $states = \montserrat\StateProvince::orderBy('name')->whereCountryId(1228)->pluck('name', 'id');
     $states->prepend('N/A', 0);
     $suffixes = \montserrat\Suffix::orderBy('name')->pluck('name', 'id');
     $suffixes->prepend('N/A', 0);
     return view('contacts.create', compact('parish_list', 'ethnicities', 'states', 'countries', 'suffixes', 'prefixes', 'languages', 'genders', 'religions'));
 }
Example #2
0
 public function search()
 {
     $person = new \montserrat\Contact();
     $parishes = \montserrat\Contact::whereSubcontactType(CONTACT_TYPE_PARISH)->orderBy('organization_name', 'asc')->with('address_primary.state', 'diocese.contact_a')->get();
     $parish_list[0] = 'N/A';
     $contact_types = \montserrat\ContactType::whereIsReserved(TRUE)->pluck('label', 'id');
     $contact_types->prepend('N/A', 0);
     $subcontact_types = \montserrat\ContactType::whereIsReserved(FALSE)->whereIsActive(TRUE)->pluck('label', 'id');
     $subcontact_types->prepend('N/A', 0);
     // while probably not the most efficient way of doing this it gets me the result
     foreach ($parishes as $parish) {
         $parish_list[$parish->id] = $parish->organization_name . ' (' . $parish->address_primary_city . ') - ' . $parish->diocese_name;
     }
     $countries = \montserrat\Country::orderBy('iso_code')->pluck('iso_code', 'id');
     $countries->prepend('N/A', 0);
     $ethnicities = \montserrat\Ethnicity::orderBy('ethnicity')->pluck('ethnicity', 'id');
     $ethnicities->prepend('N/A', 0);
     $genders = \montserrat\Gender::orderBy('name')->pluck('name', 'id');
     $genders->prepend('N/A', 0);
     $languages = \montserrat\Language::orderBy('label')->whereIsActive(1)->pluck('label', 'id');
     $languages->prepend('N/A', 0);
     $prefixes = \montserrat\Prefix::orderBy('name')->pluck('name', 'id');
     $prefixes->prepend('N/A', 0);
     $religions = \montserrat\Religion::orderBy('name')->whereIsActive(1)->pluck('name', 'id');
     $religions->prepend('N/A', 0);
     $states = \montserrat\StateProvince::orderBy('name')->whereCountryId(1228)->pluck('name', 'id');
     $states->prepend('N/A', 0);
     $suffixes = \montserrat\Suffix::orderBy('name')->pluck('name', 'id');
     $suffixes->prepend('N/A', 0);
     $occupations = \montserrat\Ppd_occupation::orderBy('name')->pluck('name', 'id');
     $occupations->prepend('N/A', 0);
     //create defaults array for easier pre-populating of default values on edit/update blade
     // initialize defaults to avoid undefined index errors
     $defaults = array();
     $defaults['Home']['street_address'] = '';
     $defaults['Home']['supplemental_address_1'] = '';
     $defaults['Home']['city'] = '';
     $defaults['Home']['state_province_id'] = '';
     $defaults['Home']['postal_code'] = '';
     $defaults['Home']['country_id'] = '';
     $defaults['Home']['Phone'] = '';
     $defaults['Home']['Mobile'] = '';
     $defaults['Home']['Fax'] = '';
     $defaults['Home']['email'] = '';
     $defaults['Work']['street_address'] = '';
     $defaults['Work']['supplemental_address_1'] = '';
     $defaults['Work']['city'] = '';
     $defaults['Work']['state_province_id'] = '';
     $defaults['Work']['postal_code'] = '';
     $defaults['Work']['country_id'] = '';
     $defaults['Work']['Phone'] = '';
     $defaults['Work']['Mobile'] = '';
     $defaults['Work']['Fax'] = '';
     $defaults['Work']['email'] = '';
     $defaults['Other']['street_address'] = '';
     $defaults['Other']['supplemental_address_1'] = '';
     $defaults['Other']['city'] = '';
     $defaults['Other']['state_province_id'] = '';
     $defaults['Other']['postal_code'] = '';
     $defaults['Other']['country_id'] = '';
     $defaults['Other']['Phone'] = '';
     $defaults['Other']['Mobile'] = '';
     $defaults['Other']['Fax'] = '';
     $defaults['Other']['email'] = '';
     $defaults['Main']['url'] = '';
     $defaults['Work']['url'] = '';
     $defaults['Facebook']['url'] = '';
     $defaults['Google']['url'] = '';
     $defaults['Instagram']['url'] = '';
     $defaults['LinkedIn']['url'] = '';
     $defaults['Twitter']['url'] = '';
     foreach ($person->addresses as $address) {
         $defaults[$address->location->name]['street_address'] = $address->street_address;
         $defaults[$address->location->name]['supplemental_address_1'] = $address->supplemental_address_1;
         $defaults[$address->location->name]['city'] = $address->city;
         $defaults[$address->location->name]['state_province_id'] = $address->state_province_id;
         $defaults[$address->location->name]['postal_code'] = $address->postal_code;
         $defaults[$address->location->name]['country_id'] = $address->country_id;
     }
     foreach ($person->phones as $phone) {
         $defaults[$phone->location->name][$phone->phone_type] = $phone->phone;
     }
     foreach ($person->emails as $email) {
         $defaults[$email->location->name]['email'] = $email->email;
     }
     foreach ($person->websites as $website) {
         $defaults[$website->website_type]['url'] = $website->url;
     }
     //dd($person);
     return view('search.search', compact('prefixes', 'suffixes', 'person', 'parish_list', 'ethnicities', 'states', 'countries', 'genders', 'languages', 'defaults', 'religions', 'occupations', 'contact_types', 'subcontact_types'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //dd($request);
     $this->validate($request, ['first_name' => 'required', 'last_name' => 'required', 'email_home' => 'email', 'email_work' => 'email', 'email_other' => 'email', 'birth_date' => 'date', 'deceased_date' => 'date', 'url_main' => 'url', 'url_work' => 'url', 'url_facebook' => 'url|regex:/facebook\\.com\\/.+/i', 'url_google' => 'url|regex:/plus\\.google\\.com\\/.+/i', 'url_twitter' => 'url|regex:/twitter\\.com\\/.+/i', 'url_instagram' => 'url|regex:/instagram\\.com\\/.+/i', 'url_linkedin' => 'url|regex:/linkedin\\.com\\/.+/i', 'parish_id' => 'integer|min:0', 'gender_id' => 'integer|min:0', 'ethnicity_id' => 'integer|min:0', 'religion_id' => 'integer|min:0', 'contact_type' => 'integer|min:0', 'subcontact_type' => 'integer|min:0', 'occupation_id' => 'integer|min:0', 'avatar' => 'image|max:5000', 'attachment' => 'file|mimes:pdf,doc,docx|max:10000', 'attachment_description' => 'string|max:200', 'emergency_contact_phone' => 'phone', 'emergency_contact_phone_alternate' => 'phone', 'phone_home_phone' => 'phone', 'phone_home_mobile' => 'phone', 'phone_home_fax' => 'phone', 'phone_work_phone' => 'phone', 'phone_work_mobile' => 'phone', 'phone_work_fax' => 'phone', 'phone_other_phone' => 'phone', 'phone_other_mobile' => 'phone', 'phone_other_fax' => 'phone']);
     //dd($request);
     //name
     $person = \montserrat\Contact::with('addresses.location', 'emails.location', 'phones.location', 'websites', 'emergency_contact', 'parish')->findOrFail($id);
     $person->prefix_id = $request->input('prefix_id');
     $person->first_name = $request->input('first_name');
     $person->middle_name = $request->input('middle_name');
     $person->last_name = $request->input('last_name');
     $person->suffix_id = $request->input('suffix_id');
     $person->nick_name = $request->input('nick_name');
     $person->contact_type = $request->input('contact_type');
     $person->subcontact_type = $request->input('subcontact_type');
     if (empty($request->input('display_name'))) {
         $person->display_name = $person->first_name . ' ' . $person->last_name;
     } else {
         $person->display_name = $request->input('display_name');
     }
     if (empty($request->input('sort_name'))) {
         $person->sort_name = $person->last_name . ', ' . $person->first_name;
     } else {
         $person->sort_name = $request->input('sort_name');
     }
     //demographic info
     $person->gender_id = $request->input('gender_id');
     $person->birth_date = $request->input('birth_date');
     $person->ethnicity_id = $request->input('ethnicity_id');
     $person->religion_id = $request->input('religion_id');
     $person->occupation_id = $request->input('occupation_id');
     // communication preferences
     $person->do_not_mail = $request->input('do_not_mail');
     $person->do_not_email = $request->input('do_not_email');
     $person->do_not_phone = $request->input('do_not_phone');
     $person->do_not_sms = $request->input('do_not_sms');
     if (empty($request->input('languages')) or in_array(0, $request->input('languages'))) {
         $person->languages()->detach();
     } else {
         $person->languages()->sync($request->input('languages'));
     }
     // CiviCRM stores the language name rather than the language id in the contact's preferred_language field
     if (!empty($request->input('preferred_language_id'))) {
         $language = \montserrat\Language::findOrFail($request->input('preferred_language_id'));
         $person->preferred_language = $language->name;
     }
     if (empty($request->input('is_deceased'))) {
         $person->is_deceased = 0;
     } else {
         $person->is_deceased = $request->input('is_deceased');
     }
     if (empty($request->input('deceased_date'))) {
         $person->deceased_date = NULL;
     } else {
         $person->deceased_date = $request->input('deceased_date');
     }
     $person->save();
     if (null !== $request->file('avatar')) {
         $description = 'Avatar for ' . $person->full_name;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('avatar'), 'contact', $person->id, 'avatar', $description);
     }
     //dd($request);
     if (null !== $request->file('attachment')) {
         $description = $request->input('attachment_description');
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('attachment'), 'contact', $person->id, 'attachment', $description);
     }
     //emergency contact info
     $emergency_contact = \montserrat\EmergencyContact::firstOrNew(['contact_id' => $person->id]);
     $emergency_contact->contact_id = $person->id;
     $emergency_contact->name = $request->input('emergency_contact_name');
     $emergency_contact->relationship = $request->input('emergency_contact_relationship');
     $emergency_contact->phone = $request->input('emergency_contact_phone');
     $emergency_contact->phone_alternate = $request->input('emergency_contact_phone_alternate');
     $emergency_contact->save();
     //dd($person);
     // save parishioner relationship
     // TEST: does unset work?
     if ($request->input('parish_id') > 0) {
         $relationship_parishioner = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_PARISHIONER, 'is_active' => 1]);
         $relationship_parishioner->contact_id_a = $request->input('parish_id');
         $relationship_parishioner->contact_id_b = $person->id;
         $relationship_parishioner->relationship_type_id = RELATIONSHIP_TYPE_PARISHIONER;
         $relationship_parishioner->is_active = 1;
         $relationship_parishioner->save();
     }
     if ($request->input('parish_id') == 0) {
         $relationship_parishioner = \montserrat\Relationship::whereContactIdB($person->id)->whereRelationshipTypeId(RELATIONSHIP_TYPE_PARISHIONER)->whereIsActive(1)->first();
         if (isset($relationship_parishioner)) {
             $relationship_parishioner->delete();
         }
     }
     // save health, dietary, general and room preference notes
     if (null !== $request->input('note_health')) {
         $person_note_health = \montserrat\Note::firstOrNew(['entity_table' => 'contact', 'entity_id' => $person->id, 'subject' => 'Health Note']);
         $person_note_health->entity_table = 'contact';
         $person_note_health->entity_id = $person->id;
         $person_note_health->note = $request->input('note_health');
         $person_note_health->subject = 'Health Note';
         $person_note_health->save();
     }
     if (null !== $request->input('note_dietary')) {
         $person_note_dietary = \montserrat\Note::firstOrNew(['entity_table' => 'contact', 'entity_id' => $person->id, 'subject' => 'Dietary Note']);
         $person_note_dietary->entity_table = 'contact';
         $person_note_dietary->entity_id = $person->id;
         $person_note_dietary->note = $request->input('note_dietary');
         $person_note_dietary->subject = 'Dietary Note';
         $person_note_dietary->save();
     }
     if (null !== $request->input('note_contact')) {
         $person_note_contact = \montserrat\Note::firstOrNew(['entity_table' => 'contact', 'entity_id' => $person->id, 'subject' => 'Contact Note']);
         $person_note_contact->entity_table = 'contact';
         $person_note_contact->entity_id = $person->id;
         $person_note_contact->note = $request->input('note_contact');
         $person_note_contact->subject = 'Contact Note';
         $person_note_contact->save();
     }
     if (null !== $request->input('note_room_preference')) {
         $person_note_room_preference = \montserrat\Note::firstOrNew(['entity_table' => 'contact', 'entity_id' => $person->id, 'subject' => 'Room Preference']);
         $person_note_room_preference->entity_table = 'contact';
         $person_note_room_preference->entity_id = $person->id;
         $person_note_room_preference->note = $request->input('note_room_preference');
         $person_note_room_preference->subject = 'Room Preference';
         $person_note_room_preference->save();
     }
     $home_address = \montserrat\Address::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_HOME]);
     $home_address->contact_id = $person->id;
     $home_address->location_type_id = LOCATION_TYPE_HOME;
     $home_address->is_primary = 1;
     $home_address->street_address = $request->input('address_home_address1');
     $home_address->supplemental_address_1 = $request->input('address_home_address2');
     $home_address->city = $request->input('address_home_city');
     $home_address->state_province_id = $request->input('address_home_state');
     $home_address->postal_code = $request->input('address_home_zip');
     $home_address->country_id = $request->input('address_home_country');
     $home_address->save();
     $work_address = \montserrat\Address::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_WORK]);
     $work_address->contact_id = $person->id;
     $work_address->location_type_id = LOCATION_TYPE_WORK;
     $work_address->is_primary = 0;
     $work_address->street_address = $request->input('address_work_address1');
     $work_address->supplemental_address_1 = $request->input('address_work_address2');
     $work_address->city = $request->input('address_work_city');
     $work_address->state_province_id = $request->input('address_work_state');
     $work_address->postal_code = $request->input('address_work_zip');
     $work_address->country_id = $request->input('address_work_country');
     $work_address->save();
     $other_address = \montserrat\Address::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_OTHER]);
     $other_address->contact_id = $person->id;
     $other_address->location_type_id = LOCATION_TYPE_OTHER;
     $other_address->is_primary = 0;
     $other_address->street_address = $request->input('address_other_address1');
     $other_address->supplemental_address_1 = $request->input('address_other_address2');
     $other_address->city = $request->input('address_other_city');
     $other_address->state_province_id = $request->input('address_other_state');
     $other_address->postal_code = $request->input('address_other_zip');
     $other_address->country_id = $request->input('address_other_country');
     $other_address->save();
     $phone_home_phone = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_HOME, 'phone_type' => 'Phone']);
     $phone_home_phone->contact_id = $person->id;
     $phone_home_phone->location_type_id = LOCATION_TYPE_HOME;
     $phone_home_phone->phone = $request->input('phone_home_phone');
     $phone_home_phone->phone_type = 'Phone';
     $phone_home_phone->save();
     $phone_home_mobile = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_HOME, 'phone_type' => 'Mobile']);
     $phone_home_mobile->contact_id = $person->id;
     $phone_home_mobile->location_type_id = LOCATION_TYPE_HOME;
     $phone_home_mobile->phone = $request->input('phone_home_mobile');
     $phone_home_mobile->phone_type = 'Mobile';
     $phone_home_mobile->save();
     $phone_home_fax = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_HOME, 'phone_type' => 'Fax']);
     $phone_home_fax->contact_id = $person->id;
     $phone_home_fax->location_type_id = LOCATION_TYPE_HOME;
     $phone_home_fax->phone = $request->input('phone_home_fax');
     $phone_home_fax->phone_type = 'Fax';
     $phone_home_fax->save();
     $phone_work_phone = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_WORK, 'phone_type' => 'Phone']);
     $phone_work_phone->contact_id = $person->id;
     $phone_work_phone->location_type_id = LOCATION_TYPE_WORK;
     $phone_work_phone->phone = $request->input('phone_work_phone');
     $phone_work_phone->phone_type = 'Phone';
     $phone_work_phone->save();
     $phone_work_mobile = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_WORK, 'phone_type' => 'Mobile']);
     $phone_work_mobile->contact_id = $person->id;
     $phone_work_mobile->location_type_id = LOCATION_TYPE_WORK;
     $phone_work_mobile->phone = $request->input('phone_work_mobile');
     $phone_work_mobile->phone_type = 'Mobile';
     $phone_work_mobile->save();
     $phone_work_fax = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_WORK, 'phone_type' => 'Fax']);
     $phone_work_fax->contact_id = $person->id;
     $phone_work_fax->location_type_id = LOCATION_TYPE_WORK;
     $phone_work_fax->phone = $request->input('phone_work_fax');
     $phone_work_fax->phone_type = 'Fax';
     $phone_work_fax->save();
     $phone_other_phone = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_OTHER, 'phone_type' => 'Phone']);
     $phone_other_phone->contact_id = $person->id;
     $phone_other_phone->location_type_id = LOCATION_TYPE_OTHER;
     $phone_other_phone->phone = $request->input('phone_other_phone');
     $phone_other_phone->phone_type = 'Phone';
     $phone_other_phone->save();
     $phone_other_mobile = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_OTHER, 'phone_type' => 'Mobile']);
     $phone_other_mobile->contact_id = $person->id;
     $phone_other_mobile->location_type_id = LOCATION_TYPE_OTHER;
     $phone_other_mobile->phone = $request->input('phone_other_mobile');
     $phone_other_mobile->phone_type = 'Mobile';
     $phone_other_mobile->save();
     $phone_other_fax = \montserrat\Phone::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_OTHER, 'phone_type' => 'Fax']);
     $phone_other_fax->contact_id = $person->id;
     $phone_other_fax->location_type_id = LOCATION_TYPE_OTHER;
     $phone_other_fax->phone = $request->input('phone_other_fax');
     $phone_other_fax->phone_type = 'Fax';
     $phone_other_fax->save();
     $email_home = \montserrat\Email::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_HOME]);
     $email_home->contact_id = $person->id;
     $email_home->location_type_id = LOCATION_TYPE_HOME;
     $email_home->email = $request->input('email_home');
     $email_home->save();
     $email_work = \montserrat\Email::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_WORK]);
     $email_work->contact_id = $person->id;
     $email_work->location_type_id = LOCATION_TYPE_WORK;
     $email_work->email = $request->input('email_work');
     $email_work->save();
     $email_other = \montserrat\Email::firstOrNew(['contact_id' => $person->id, 'location_type_id' => LOCATION_TYPE_OTHER]);
     $email_other->contact_id = $person->id;
     $email_other->location_type_id = LOCATION_TYPE_OTHER;
     $email_other->email = $request->input('email_other');
     $email_other->save();
     $url_main = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'Main']);
     $url_main->contact_id = $person->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'Work']);
     $url_work->contact_id = $person->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'Facebook']);
     $url_facebook->contact_id = $person->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'Google']);
     $url_google->contact_id = $person->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'Instagram']);
     $url_instagram->contact_id = $person->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'LinkedIn']);
     $url_linkedin->contact_id = $person->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = \montserrat\Website::firstOrNew(['contact_id' => $person->id, 'website_type' => 'Twitter']);
     $url_twitter->contact_id = $person->id;
     $url_twitter->url = $request->input('url_twitter');
     $url_twitter->website_type = 'Twitter';
     $url_twitter->save();
     // relationships: donor, retreatant, volunteer, captain, director, innkeeper, assistant, staff, board
     $relationship_donor = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_DONOR, 'is_active' => 1]);
     if ($request->input('is_donor') == 0) {
         $relationship_donor->delete();
     } else {
         $relationship_donor->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_donor->contact_id_b = $person->id;
         $relationship_donor->relationship_type_id = RELATIONSHIP_TYPE_DONOR;
         $relationship_donor->is_active = 1;
         $relationship_donor->save();
     }
     $relationship_retreatant = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_RETREATANT, 'is_active' => 1]);
     if ($request->input('is_retreatant') == 0) {
         $relationship_retreatant->delete();
     } else {
         $relationship_retreatant->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_retreatant->contact_id_b = $person->id;
         $relationship_retreatant->relationship_type_id = RELATIONSHIP_TYPE_RETREATANT;
         $relationship_retreatant->is_active = 1;
         $relationship_retreatant->save();
     }
     $relationship_volunteer = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_VOLUNTEER, 'is_active' => 1]);
     if ($request->input('is_volunteer') == 0) {
         $relationship_volunteer->delete();
     } else {
         $relationship_volunteer->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_volunteer->contact_id_b = $person->id;
         $relationship_volunteer->relationship_type_id = RELATIONSHIP_TYPE_VOLUNTEER;
         $relationship_volunteer->is_active = 1;
         $relationship_volunteer->save();
     }
     $relationship_captain = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_CAPTAIN, 'is_active' => 1]);
     if ($request->input('is_captain') == 0) {
         $relationship_captain->delete();
     } else {
         $relationship_captain->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_captain->contact_id_b = $person->id;
         $relationship_captain->relationship_type_id = RELATIONSHIP_TYPE_CAPTAIN;
         $relationship_captain->is_active = 1;
         $relationship_captain->save();
     }
     $relationship_director = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_RETREAT_DIRECTOR, 'is_active' => 1]);
     if ($request->input('is_director') == 0) {
         $relationship_director->delete();
     } else {
         $relationship_director->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_director->contact_id_b = $person->id;
         $relationship_director->relationship_type_id = RELATIONSHIP_TYPE_RETREAT_DIRECTOR;
         $relationship_director->is_active = 1;
         $relationship_director->save();
     }
     $relationship_innkeeper = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_RETREAT_INNKEEPER, 'is_active' => 1]);
     if ($request->input('is_innkeeper') == 0) {
         $relationship_innkeeper->delete();
     } else {
         $relationship_innkeeper->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_innkeeper->contact_id_b = $person->id;
         $relationship_innkeeper->relationship_type_id = RELATIONSHIP_TYPE_RETREAT_INNKEEPER;
         $relationship_innkeeper->is_active = 1;
         $relationship_innkeeper->save();
     }
     $relationship_assistant = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_RETREAT_ASSISTANT, 'is_active' => 1]);
     if ($request->input('is_assistant') == 0) {
         $relationship_assistant->delete();
     } else {
         $relationship_assistant->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_assistant->contact_id_b = $person->id;
         $relationship_assistant->relationship_type_id = RELATIONSHIP_TYPE_RETREAT_ASSISTANT;
         $relationship_assistant->is_active = 1;
         $relationship_assistant->save();
     }
     $relationship_staff = \montserrat\Relationship::firstOrNew(['contact_id_a' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_STAFF, 'is_active' => 1]);
     if ($request->input('is_staff') == 0) {
         $relationship_staff->delete();
     } else {
         $relationship_staff->contact_id_a = $person->id;
         $relationship_staff->contact_id_b = CONTACT_MONTSERRAT;
         $relationship_staff->relationship_type_id = RELATIONSHIP_TYPE_STAFF;
         $relationship_staff->is_active = 1;
         $relationship_staff->save();
     }
     // for Board Members we are not deleting the relationship but ending it and making it inactive
     $relationship_board = \montserrat\Relationship::firstOrNew(['contact_id_b' => $person->id, 'relationship_type_id' => RELATIONSHIP_TYPE_BOARD_MEMBER]);
     if ($request->input('is_board') == 0) {
         if (isset($relationship_board->id)) {
             $relationship_board->end_date = \Carbon\Carbon::now();
             $relationship_board->is_active = 0;
             $relationship_board->save();
         }
     } else {
         $relationship_board->contact_id_a = CONTACT_MONTSERRAT;
         $relationship_board->contact_id_b = $person->id;
         $relationship_board->relationship_type_id = RELATIONSHIP_TYPE_BOARD_MEMBER;
         $relationship_board->start_date = \Carbon\Carbon::now();
         $relationship_board->is_active = 1;
         $relationship_board->save();
     }
     //groups:
     $group_captain = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_CAPTAIN, 'status' => 'Added']);
     if ($request->input('is_captain') == 0) {
         $group_captain->delete();
     } else {
         $group_captain->contact_id = $person->id;
         $group_captain->group_id = GROUP_ID_CAPTAIN;
         $group_captain->status = 'Added';
         $group_captain->save();
     }
     $group_volunteer = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_VOLUNTEER, 'status' => 'Added']);
     if ($request->input('is_volunteer') == 0) {
         $group_volunteer->delete();
     } else {
         $group_volunteer->contact_id = $person->id;
         $group_volunteer->group_id = GROUP_ID_VOLUNTEER;
         $group_volunteer->status = 'Added';
         $group_volunteer->save();
     }
     $group_bishop = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_BISHOP, 'status' => 'Added']);
     if ($request->input('is_bishop') == 0) {
         $group_bishop->delete();
     } else {
         $group_bishop->contact_id = $person->id;
         $group_bishop->group_id = GROUP_ID_BISHOP;
         $group_bishop->status = 'Added';
         $group_bishop->save();
     }
     $group_priest = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_PRIEST, 'status' => 'Added']);
     if ($request->input('is_priest') == 0) {
         $group_priest->delete();
     } else {
         $group_priest->contact_id = $person->id;
         $group_priest->group_id = GROUP_ID_PRIEST;
         $group_priest->status = 'Added';
         $group_priest->save();
     }
     $group_deacon = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_DEACON, 'status' => 'Added']);
     if ($request->input('is_deacon') == 0) {
         $group_deacon->delete();
     } else {
         $group_deacon->contact_id = $person->id;
         $group_deacon->group_id = GROUP_ID_DEACON;
         $group_deacon->status = 'Added';
         $group_deacon->save();
     }
     $group_pastor = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_PASTOR, 'status' => 'Added']);
     if ($request->input('is_pastor') == 0) {
         $group_pastor->delete();
     } else {
         $group_pastor->contact_id = $person->id;
         $group_pastor->group_id = GROUP_ID_PASTOR;
         $group_pastor->status = 'Added';
         $group_pastor->save();
     }
     $group_jesuit = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_JESUIT, 'status' => 'Added']);
     if ($request->input('is_jesuit') == 0) {
         $group_jesuit->delete();
     } else {
         $group_jesuit->contact_id = $person->id;
         $group_jesuit->group_id = GROUP_ID_JESUIT;
         $group_jesuit->status = 'Added';
         $group_jesuit->save();
     }
     $group_provincial = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_PROVINCIAL, 'status' => 'Added']);
     if ($request->input('is_provincial') == 0) {
         $group_provincial->delete();
     } else {
         $group_provincial->contact_id = $person->id;
         $group_provincial->group_id = GROUP_ID_PROVINCIAL;
         $group_provincial->status = 'Added';
         $group_provincial->save();
     }
     $group_superior = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_SUPERIOR, 'status' => 'Added']);
     if ($request->input('is_superior') == 0) {
         $group_superior->delete();
     } else {
         $group_superior->contact_id = $person->id;
         $group_superior->group_id = GROUP_ID_SUPERIOR;
         $group_superior->status = 'Added';
         $group_superior->save();
     }
     $group_board = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_BOARD]);
     if ($request->input('is_board') == 0) {
         if (isset($group_board->id)) {
             $group_board->status = 'Removed';
             $group_board->save();
         }
     } else {
         $group_board->contact_id = $person->id;
         $group_board->group_id = GROUP_ID_BOARD;
         $group_board->status = 'Added';
         $group_board->save();
     }
     $group_staff = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_STAFF, 'status' => 'Added']);
     if ($request->input('is_staff') == 0) {
         $group_staff->delete();
     } else {
         $group_staff->contact_id = $person->id;
         $group_staff->group_id = GROUP_ID_STAFF;
         $group_staff->status = 'Added';
         $group_staff->save();
     }
     $group_steward = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_STEWARD, 'status' => 'Added']);
     if ($request->input('is_steward') == 0) {
         $group_steward->delete();
     } else {
         $group_steward->contact_id = $person->id;
         $group_steward->group_id = GROUP_ID_STEWARD;
         $group_steward->status = 'Added';
         $group_steward->save();
     }
     $group_director = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_DIRECTOR, 'status' => 'Added']);
     if ($request->input('is_director') == 0) {
         $group_director->delete();
     } else {
         $group_director->contact_id = $person->id;
         $group_director->group_id = GROUP_ID_DIRECTOR;
         $group_director->status = 'Added';
         $group_director->save();
     }
     $group_innkeeper = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_INNKEEPER, 'status' => 'Added']);
     if ($request->input('is_innkeeper') == 0) {
         $group_innkeeper->delete();
     } else {
         $group_innkeeper->contact_id = $person->id;
         $group_innkeeper->group_id = GROUP_ID_INNKEEPER;
         $group_innkeeper->status = 'Added';
         $group_innkeeper->save();
     }
     $group_assistant = \montserrat\GroupContact::firstOrNew(['contact_id' => $person->id, 'group_id' => GROUP_ID_ASSISTANT, 'status' => 'Added']);
     if ($request->input('is_assistant') == 0) {
         $group_assistant->delete();
     } else {
         $group_assistant->contact_id = $person->id;
         $group_assistant->group_id = GROUP_ID_ASSISTANT;
         $group_assistant->status = 'Added';
         $group_assistant->save();
     }
     return Redirect::action('PersonsController@show', $person->id);
     //
 }