예제 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['organization_name' => 'required', 'display_name' => 'required', 'sort_name' => 'required', 'email_primary' => 'email', 'url_main' => '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', 'phone_main_phone' => 'phone', 'phone_main_fax' => 'phone', 'avatar' => 'image|max:5000', 'attachment' => 'file|mimes:pdf,doc,docx|max:10000', 'attachment_description' => 'string|max:200']);
     $vendor = \montserrat\Contact::with('address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax', 'email_primary.location', 'website_main', 'notes')->findOrFail($request->input('id'));
     $vendor->organization_name = $request->input('organization_name');
     $vendor->display_name = $request->input('display_name');
     $vendor->sort_name = $request->input('sort_name');
     $vendor->save();
     if (empty($vendor->address_primary)) {
         $address_primary = new \montserrat\Address();
     } else {
         $address_primary = \montserrat\Address::findOrNew($vendor->address_primary->id);
     }
     $address_primary->contact_id = $vendor->id;
     $address_primary->location_type_id = LOCATION_TYPE_MAIN;
     $address_primary->is_primary = 1;
     $address_primary->street_address = $request->input('street_address');
     $address_primary->supplemental_address_1 = $request->input('supplemental_address_1');
     $address_primary->city = $request->input('city');
     $address_primary->state_province_id = $request->input('state_province_id');
     $address_primary->postal_code = $request->input('postal_code');
     $address_primary->country_id = $request->input('country_id');
     $address_primary->save();
     if (empty($vendor->phone_primary)) {
         $phone_primary = new \montserrat\Address();
     } else {
         $phone_primary = \montserrat\Phone::findOrNew($vendor->phone_primary->id);
     }
     $phone_primary->contact_id = $vendor->id;
     $phone_primary->location_type_id = LOCATION_TYPE_MAIN;
     $phone_primary->is_primary = 1;
     $phone_primary->phone_type = 'Phone';
     $phone_primary->phone = $request->input('phone_main_phone');
     $phone_primary->save();
     if (empty($vendor->phone_main_fax)) {
         $phone_main_fax = new \montserrat\Phone();
     } else {
         $phone_main_fax = \montserrat\Phone::findOrNew($vendor->phone_main_fax->id);
     }
     $phone_main_fax->contact_id = $vendor->id;
     $phone_main_fax->location_type_id = LOCATION_TYPE_MAIN;
     $phone_main_fax->phone_type = 'Fax';
     $phone_main_fax->phone = $request->input('phone_main_fax');
     $phone_main_fax->save();
     if (empty($vendor->email_primary)) {
         $email_primary = new \montserrat\Email();
     } else {
         $email_primary = \montserrat\Email::findOrNew($vendor->email_primary->id);
     }
     $email_primary->contact_id = $vendor->id;
     $email_primary->is_primary = 1;
     $email_primary->location_type_id = LOCATION_TYPE_MAIN;
     $email_primary->email = $request->input('email_primary');
     $email_primary->save();
     if (null !== $request->file('avatar')) {
         $description = 'Avatar for ' . $vendor->organization_name;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('avatar'), 'contact', $vendor->id, 'avatar', $description);
     }
     if (null !== $request->file('attachment')) {
         $description = $request->input('attachment_description');
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('attachment'), 'contact', $vendor->id, 'attachment', $description);
     }
     $url_main = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'Main']);
     $url_main->contact_id = $vendor->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'Work']);
     $url_work->contact_id = $vendor->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'Facebook']);
     $url_facebook->contact_id = $vendor->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'Google']);
     $url_google->contact_id = $vendor->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'Instagram']);
     $url_instagram->contact_id = $vendor->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'LinkedIn']);
     $url_linkedin->contact_id = $vendor->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = \montserrat\Website::firstOrNew(['contact_id' => $vendor->id, 'website_type' => 'Twitter']);
     $url_twitter->contact_id = $vendor->id;
     $url_twitter->url = $request->input('url_twitter');
     $url_twitter->website_type = 'Twitter';
     $url_twitter->save();
     return Redirect::action('VendorsController@index');
 }
예제 #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $this->validate($request, ['organization_name' => 'required', 'display_name' => 'required', 'sort_name' => 'required', 'bishop_id' => 'integer|min:0', 'email_main' => 'email', 'url_main' => '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', 'phone_main_phone' => 'phone', 'phone_main_fax' => 'phone', 'avatar' => 'image|max:5000', 'attachment' => 'file|mimes:pdf,doc,docx|max:10000', 'attachment_description' => 'string|max:200']);
     $diocese = \montserrat\Contact::with('bishops.contact_b', 'parishes.contact_b', 'address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax.location', 'email_primary.location', 'website_main', 'notes')->findOrFail($id);
     $diocese->organization_name = $request->input('organization_name');
     $diocese->display_name = $request->input('display_name');
     $diocese->sort_name = $request->input('sort_name');
     $diocese->contact_type = CONTACT_TYPE_ORGANIZATION;
     $diocese->subcontact_type = CONTACT_TYPE_DIOCESE;
     $diocese->save();
     $address_primary = \montserrat\Address::findOrNew($diocese->address_primary->id);
     $address_primary->contact_id = $diocese->id;
     $address_primary->location_type_id = LOCATION_TYPE_MAIN;
     $address_primary->is_primary = 1;
     $address_primary->street_address = $request->input('street_address');
     $address_primary->supplemental_address_1 = $request->input('supplemental_address_1');
     $address_primary->city = $request->input('city');
     $address_primary->state_province_id = $request->input('state_province_id');
     $address_primary->postal_code = $request->input('postal_code');
     $address_primary->country_id = COUNTRY_ID_USA;
     $address_primary->is_primary = 1;
     $address_primary->save();
     $phone_primary = \montserrat\Phone::findOrNew($diocese->phone_primary->id);
     $phone_primary->contact_id = $diocese->id;
     $phone_primary->location_type_id = LOCATION_TYPE_MAIN;
     $phone_primary->is_primary = 1;
     $phone_primary->phone = $request->input('phone_main_phone');
     $phone_primary->phone_type = 'Phone';
     $phone_primary->save();
     if (empty($diocese->phone_main_fax)) {
         $phone_main_fax = new \montserrat\Phone();
     } else {
         $phone_main_fax = \montserrat\Phone::findOrNew($diocese->phone_main_fax->id);
     }
     $phone_main_fax->contact_id = $diocese->id;
     $phone_main_fax->location_type_id = LOCATION_TYPE_MAIN;
     $phone_main_fax->phone = $request->input('phone_main_fax');
     $phone_main_fax->phone_type = 'Fax';
     $phone_main_fax->save();
     $email_primary = \montserrat\Email::findOrNew($diocese->email_primary->id);
     $email_primary->contact_id = $diocese->id;
     $email_primary->is_primary = 1;
     $email_primary->location_type_id = LOCATION_TYPE_MAIN;
     $email_primary->email = $request->input('email_primary');
     $email_primary->save();
     $url_main = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'Main']);
     $url_main->contact_id = $diocese->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'Work']);
     $url_work->contact_id = $diocese->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'Facebook']);
     $url_facebook->contact_id = $diocese->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'Google']);
     $url_google->contact_id = $diocese->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'Instagram']);
     $url_instagram->contact_id = $diocese->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'LinkedIn']);
     $url_linkedin->contact_id = $diocese->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = \montserrat\Website::firstOrNew(['contact_id' => $diocese->id, 'website_type' => 'Twitter']);
     $url_twitter->contact_id = $diocese->id;
     $url_twitter->url = $request->input('url_twitter');
     $url_twitter->website_type = 'Twitter';
     $url_twitter->save();
     if ($request->input('bishop_id') > 0) {
         $bishop_id = $request->input('bishop_id');
         $relationship_bishop = \montserrat\Relationship::firstOrNew(['contact_id_a' => $diocese->id, 'contact_id_b' => $bishop_id, 'relationship_type_id' => RELATIONSHIP_TYPE_BISHOP, 'is_active' => 1]);
         $relationship_bishop->contact_id_a = $diocese->id;
         $relationship_bishop->contact_id_b = $bishop_id;
         $relationship_bishop->relationship_type_id = RELATIONSHIP_TYPE_BISHOP;
         $relationship_bishop->is_active = 1;
         $relationship_bishop->save();
     }
     if (null !== $request->file('avatar')) {
         $description = 'Avatar for ' . $diocese->organization_name;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('avatar'), 'contact', $diocese->id, 'avatar', $description);
     }
     if (null !== $request->file('attachment')) {
         $description = $request->input('attachment_description');
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('attachment'), 'contact', $diocese->id, 'attachment', $description);
     }
     return Redirect::action('DiocesesController@index');
 }
예제 #3
0
 /**
  * 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, ['idnumber' => 'required|unique:retreats,idnumber,' . $id, 'start_date' => 'required|date|before:end_date', 'end_date' => 'required|date|after:start_date', 'title' => 'required', 'innkeeper_id' => 'integer|min:0', 'assistant_id' => 'integer|min:0', 'year' => 'integer|min:1990|max:2020', 'amount' => 'numeric|min:0|max:100000', 'attending' => 'integer|min:0|max:150', 'silent' => 'boolean', 'contract' => 'file|mimes:pdf|max:5000', 'schedule' => 'file|mimes:pdf|max:5000', 'evaluations' => 'file|mimes:pdf|max:10000', 'group_photo' => 'image|max:10000']);
     $retreat = \montserrat\Retreat::findOrFail($request->input('id'));
     $retreat->idnumber = $request->input('idnumber');
     $retreat->start_date = $request->input('start_date');
     $retreat->end_date = $request->input('end_date');
     $retreat->title = $request->input('title');
     $retreat->description = $request->input('description');
     $retreat->event_type_id = $request->input('event_type');
     //TODO: Figure out how to use event type or some other way of tracking the silent retreats, possibly silent boolean field in event table
     //$retreat->silent = $request->input('silent');
     //$retreat->amount = $request->input('amount');
     // attending field not needed - will calculate with count on registrations
     //$retreat->attending = $request->input('attending');
     //$retreat->year = $request->input('year');
     $retreat->innkeeper_id = $request->input('innkeeper_id');
     $retreat->assistant_id = $request->input('assistant_id');
     $retreat->save();
     if (null !== $request->file('contract')) {
         $description = 'Contract for ' . $retreat->idnumber . '-' . $retreat->title;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('contract'), 'event', $retreat->id, 'contract', $description);
     }
     if (null !== $request->file('schedule')) {
         $description = 'Schedule for ' . $retreat->idnumber . '-' . $retreat->title;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('schedule'), 'event', $retreat->id, 'schedule', $description);
     }
     if (null !== $request->file('evaluations')) {
         $description = 'Evaluations for ' . $retreat->idnumber . '-' . $retreat->title;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('evaluations'), 'event', $retreat->id, 'evaluations', $description);
     }
     if (null !== $request->file('group_photo')) {
         $description = 'Group photo for ' . $retreat->idnumber . '-' . $retreat->title;
         $attachment = new AttachmentsController();
         $attachment->update_attachment($request->file('group_photo'), 'event', $retreat->id, 'group_photo', $description);
     }
     if (empty($request->input('directors')) or in_array(0, $request->input('directors'))) {
         $retreat->retreatmasters()->detach();
     } else {
         $retreat->retreatmasters()->sync($request->input('directors'));
     }
     if (empty($request->input('captains')) or in_array(0, $request->input('captains'))) {
         $retreat->captains()->detach();
     } else {
         $retreat->captains()->sync($request->input('captains'));
     }
     return Redirect::action('RetreatsController@index');
 }
예제 #4
0
 /**
  * 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);
     //
 }