예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['organization_name' => 'required', 'vendor_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']);
     $vendor = new \montserrat\Contact();
     $vendor->organization_name = $request->input('organization_name');
     $vendor->display_name = $request->input('organization_name');
     $vendor->sort_name = $request->input('organization_name');
     $vendor->contact_type = CONTACT_TYPE_ORGANIZATION;
     $vendor->subcontact_type = CONTACT_TYPE_VENDOR;
     $vendor->save();
     $vendor_address = new \montserrat\Address();
     $vendor_address->contact_id = $vendor->id;
     $vendor_address->location_type_id = LOCATION_TYPE_MAIN;
     $vendor_address->is_primary = 1;
     $vendor_address->street_address = $request->input('street_address');
     $vendor_address->supplemental_address_1 = $request->input('supplemental_address_1');
     $vendor_address->city = $request->input('city');
     $vendor_address->state_province_id = $request->input('state_province_id');
     $vendor_address->postal_code = $request->input('postal_code');
     $vendor_address->country_id = $request->input('country_id');
     $vendor_address->save();
     $vendor_main_phone = new \montserrat\Phone();
     $vendor_main_phone->contact_id = $vendor->id;
     $vendor_main_phone->location_type_id = LOCATION_TYPE_MAIN;
     $vendor_main_phone->is_primary = 1;
     $vendor_main_phone->phone = $request->input('phone_main_phone');
     $vendor_main_phone->phone_type = 'Phone';
     $vendor_main_phone->save();
     $vendor_fax_phone = new \montserrat\Phone();
     $vendor_fax_phone->contact_id = $vendor->id;
     $vendor_fax_phone->location_type_id = LOCATION_TYPE_MAIN;
     $vendor_fax_phone->phone = $request->input('phone_main_fax');
     $vendor_fax_phone->phone_type = 'Fax';
     $vendor_fax_phone->save();
     $vendor_email_main = new \montserrat\Email();
     $vendor_email_main->contact_id = $vendor->id;
     $vendor_email_main->is_primary = 1;
     $vendor_email_main->location_type_id = LOCATION_TYPE_MAIN;
     $vendor_email_main->email = $request->input('email_main');
     $vendor_email_main->save();
     //TODO: add contact_id which is the id of the creator of the note
     if (!empty($request->input('note'))) {
         $vendor_note = new \montserrat\Note();
         $vendor_note->entity_table = 'contact';
         $vendor_note->entity_id = $vendor->id;
         $vendor_note->note = $request->input('note');
         $vendor_note->subject = 'Vendor note';
         $vendor_note->save();
     }
     $url_main = new \montserrat\Website();
     $url_main->contact_id = $vendor->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = new \montserrat\Website();
     $url_work->contact_id = $vendor->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = new \montserrat\Website();
     $url_facebook->contact_id = $vendor->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = new \montserrat\Website();
     $url_google->contact_id = $vendor->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = new \montserrat\Website();
     $url_instagram->contact_id = $vendor->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = new \montserrat\Website();
     $url_linkedin->contact_id = $vendor->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = new \montserrat\Website();
     $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
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $this->validate($request, ['organization_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']);
     $diocese = new \montserrat\Contact();
     $diocese->organization_name = $request->input('organization_name');
     $diocese->display_name = $request->input('organization_name');
     $diocese->sort_name = $request->input('organization_name');
     $diocese->contact_type = CONTACT_TYPE_ORGANIZATION;
     $diocese->subcontact_type = CONTACT_TYPE_DIOCESE;
     $diocese->save();
     $diocese_address = new \montserrat\Address();
     $diocese_address->contact_id = $diocese->id;
     $diocese_address->location_type_id = LOCATION_TYPE_MAIN;
     $diocese_address->is_primary = 1;
     $diocese_address->street_address = $request->input('street_address');
     $diocese_address->supplemental_address_1 = $request->input('supplemental_address_1');
     $diocese_address->city = $request->input('city');
     $diocese_address->state_province_id = $request->input('state_province_id');
     $diocese_address->postal_code = $request->input('postal_code');
     $diocese_address->country_id = $request->input('country_id');
     $diocese_address->save();
     $diocese_main_phone = new \montserrat\Phone();
     $diocese_main_phone->contact_id = $diocese->id;
     $diocese_main_phone->location_type_id = LOCATION_TYPE_MAIN;
     $diocese_main_phone->is_primary = 1;
     $diocese_main_phone->phone = $request->input('phone_main_phone');
     $diocese_main_phone->phone_type = 'Phone';
     $diocese_main_phone->save();
     $diocese_fax_phone = new \montserrat\Phone();
     $diocese_fax_phone->contact_id = $diocese->id;
     $diocese_fax_phone->location_type_id = LOCATION_TYPE_MAIN;
     $diocese_fax_phone->phone = $request->input('phone_main_fax');
     $diocese_fax_phone->phone_type = 'Fax';
     $diocese_fax_phone->save();
     $diocese_email_main = new \montserrat\Email();
     $diocese_email_main->contact_id = $diocese->id;
     $diocese_email_main->is_primary = 1;
     $diocese_email_main->location_type_id = LOCATION_TYPE_MAIN;
     $diocese_email_main->email = $request->input('email_main');
     $diocese_email_main->save();
     $url_main = new \montserrat\Website();
     $url_main->contact_id = $diocese->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = new \montserrat\Website();
     $url_work->contact_id = $diocese->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = new \montserrat\Website();
     $url_facebook->contact_id = $diocese->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = new \montserrat\Website();
     $url_google->contact_id = $diocese->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = new \montserrat\Website();
     $url_instagram->contact_id = $diocese->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = new \montserrat\Website();
     $url_linkedin->contact_id = $diocese->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = new \montserrat\Website();
     $url_twitter->contact_id = $diocese->id;
     $url_twitter->url = $request->input('url_twitter');
     $url_twitter->website_type = 'Twitter';
     $url_twitter->save();
     //TODO: add contact_id which is the id of the creator of the note
     if (!empty($request->input('note'))) {
     }
     $diocese_note = new \montserrat\Note();
     $diocese_note->entity_table = 'contact';
     $diocese_note->entity_id = $diocese->id;
     $diocese_note->note = $request->input('note');
     $diocese_note->subject = 'Diocese note';
     $diocese_note->save();
     if ($request->input('bishop_id') > 0) {
         $relationship_bishop = new \montserrat\Relationship();
         $relationship_bishop->contact_id_a = $diocese->id;
         $relationship_bishop->contact_id_b = $request->input('bishop_id');
         $relationship_bishop->relationship_type_id = RELATIONSHIP_TYPE_BISHOP;
         $relationship_bishop->is_active = 1;
         $relationship_bishop->save();
     }
     return Redirect::action('DiocesesController@index');
 }
예제 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $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', 'url_google' => 'url', 'url_instagram' => 'url', 'url_linkedin' => 'url', 'url_twitter' => 'url', 'parish_id' => 'integer|min:0', 'gender_id' => 'integer|min:0', 'ethnicity_id' => 'integer|min:0', 'religion_id' => 'integer|min:0']);
     $contact = new \montserrat\Contact();
     // name info
     $contact->title = $request->input('title');
     $contact->first_name = $request->input('first_name');
     $contact->middle_name = $request->input('middle_name');
     $contact->last_name = $request->input('last_name');
     $contact->suffix_id = $request->input('suffix_id');
     $contact->nickname = $request->input('nick_name');
     if (empty($request->input('display_name'))) {
         $contact->display_name = $contact->first_name . ' ' . $contact->last_name;
     } else {
         $contact->display_name = $request->input('display_name');
     }
     if (empty($request->input('sort_name'))) {
         $contact->sort_name = $contact->last_name . ', ' . $contact->first_name;
     } else {
         $contact->sort_name = $request->input('sort_name');
     }
     // emergency contact info
     $emergency_contact = new \montserrat\EmergencyContact();
     $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();
     // demographic info
     $contact->gender_id = $request->input('gender_id');
     $contact->birth_date = $request->input('birth_date');
     $contact->ethnicity_id = $request->input('ethnicity_id');
     $contact->religion_id = $request->input('religion_id');
     $contact->languages = $request->input('languages');
     // health related info
     $contact->medical = $request->input('medical');
     $contact->dietary = $request->input('dietary');
     // misc
     $contact->notes = $request->input('notes');
     $contact->roompreference = $request->input('roompreference');
     // roles, groups, etc.
     $contact->is_donor = $request->input('is_donor');
     $contact->is_retreatant = $request->input('is_retreatant');
     $contact->is_director = $request->input('is_director');
     $contact->is_innkeeper = $request->input('is_innkeeper');
     $contact->is_assistant = $request->input('is_assistant');
     $contact->is_captain = $request->input('is_captain');
     $contact->is_staff = $request->input('is_staff');
     $contact->is_volunteer = $request->input('is_volunteer');
     $contact->is_pastor = $request->input('is_pastor');
     $contact->is_bishop = $request->input('is_bishop');
     $contact->is_catholic = $request->input('is_catholic');
     $contact->is_board = $request->input('is_board');
     $contact->is_formerboard = $request->input('is_formerboard');
     $contact->is_jesuit = $request->input('is_jesuit');
     if (empty($request->input('is_deceased'))) {
         $contact->is_deceased = 0;
     } else {
         $contact->is_deceased = $request->input('is_deceased');
     }
     $contact->save();
     $home_address = new \montserrat\Address();
     $home_address->contact_id = $contact->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 = new \montserrat\Address();
     $work_address->contact_id = $contact->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 = new \montserrat\Address();
     $other_address->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_home_phone->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_home_mobile->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_home_fax->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_work_phone->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_work_mobile->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_work_fax->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_other_phone->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_other_mobile->contact_id = $contact->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 = new \montserrat\Phone();
     $phone_other_fax->contact_id = $contact->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 = new \montserrat\Email();
     $email_home->contact_id = $contact->id;
     $email_home->location_type_id = LOCATION_TYPE_HOME;
     $email_home->email = $request->input('email_home');
     $email_home->save();
     $email_work = new \montserrat\Email();
     $email_work->contact_id = $contact->id;
     $email_work->location_type_id = LOCATION_TYPE_WORK;
     $email_work->email = $request->input('email_work');
     $email_work->save();
     $email_other = new \montserrat\Email();
     $email_other->contact_id = $contact->id;
     $email_other->location_type_id = LOCATION_TYPE_OTHER;
     $email_other->email = $request->input('email_other');
     $email_other->save();
     $url_main = new \montserrat\Website();
     $url_main->contact_id = $contact->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = new \montserrat\Website();
     $url_work->contact_id = $contact->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = new \montserrat\Website();
     $url_facebook->contact_id = $contact->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = new \montserrat\Website();
     $url_google->contact_id = $contact->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = new \montserrat\Website();
     $url_instagram->contact_id = $contact->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = new \montserrat\Website();
     $url_linkedin->contact_id = $contact->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = new \montserrat\Website();
     $url_twitter->contact_id = $contact->id;
     $url_twitter->url = $request->input('url_twitter');
     $url_twitter->website_type = 'Twitter';
     $url_twitter->save();
     return Redirect::action('ContactsController@index');
     //
 }
예제 #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //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', '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']);
     $person = new \montserrat\Contact();
     // name info
     $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');
     // the sort and display names are not available on creation so that we create a default and then it can be customized or tweaked individually
     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
     if (empty($request->input('do_not_mail'))) {
         $person->do_not_mail = 0;
     } else {
         $person->do_not_mail = $request->input('do_not_mail');
     }
     if (empty($request->input('do_not_email'))) {
         $person->do_not_email = 0;
     } else {
         $person->do_not_email = $request->input('do_not_email');
     }
     if (empty($request->input('do_not_phone'))) {
         $person->do_not_phone = 0;
     } else {
         $person->do_not_phone = $request->input('do_not_phone');
     }
     if (empty($request->input('do_not_sms'))) {
         $person->do_not_sms = 0;
     } else {
         $person->do_not_sms = $request->input('do_not_sms');
     }
     // 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->store_attachment($request->file('avatar'), 'contact', $person->id, 'avatar', $description);
     }
     // emergency contact information - not part of CiviCRM squema
     $emergency_contact = new \montserrat\EmergencyContact();
     $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();
     // relationships: parishioner, donor, retreatant, volunteer, captain, director, innkeeper, assistant, staff, board
     // save parishioner relationship
     if ($request->input('parish_id') > 0) {
         $relationship_parishioner = new \montserrat\Relationship();
         $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();
     }
     // save donor relationship
     if ($request->input('is_donor') > 0) {
         $relationship_donor = new \montserrat\Relationship();
         $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();
     }
     // save retreatant relationship
     if ($request->input('is_retreatant') > 0) {
         $relationship_retreatant = new \montserrat\Relationship();
         $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();
     }
     // save volunteer relationship
     if ($request->input('is_volunteer') > 0) {
         $relationship_volunteer = new \montserrat\Relationship();
         $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();
         $group_volunteer = new \montserrat\GroupContact();
         $group_volunteer->group_id = GROUP_ID_VOLUNTEER;
         $group_volunteer->contact_id = $person->id;
         $group_volunteer->status = 'Added';
         $group_volunteer->save();
     }
     // save captain relationship
     if ($request->input('is_captain') > 0) {
         $relationship_captain = new \montserrat\Relationship();
         $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();
         $group_captain = new \montserrat\GroupContact();
         $group_captain->group_id = GROUP_ID_CAPTAIN;
         $group_captain->contact_id = $person->id;
         $group_captain->status = 'Added';
         $group_captain->save();
     }
     // save retreat director relationship
     if ($request->input('is_director') > 0) {
         $relationship_director = new \montserrat\Relationship();
         $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();
         $group_director = new \montserrat\GroupContact();
         $group_director->group_id = GROUP_ID_DIRECTOR;
         $group_director->contact_id = $person->id;
         $group_director->status = 'Added';
         $group_director->save();
     }
     // save retreat innkeeper relationship
     if ($request->input('is_innkeeper') > 0) {
         $relationship_innkeeper = new \montserrat\Relationship();
         $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();
         $group_innkeeper = new \montserrat\GroupContact();
         $group_innkeeper->group_id = GROUP_ID_INNKEEPER;
         $group_innkeeper->contact_id = $person->id;
         $group_innkeeper->status = 'Added';
         $group_innkeeper->save();
     }
     // save retreat assistant relationship
     if ($request->input('is_assistant') > 0) {
         $relationship_assistant = new \montserrat\Relationship();
         $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();
         $group_assistant = new \montserrat\GroupContact();
         $group_assistant->group_id = GROUP_ID_ASSISTANT;
         $group_assistant->contact_id = $person->id;
         $group_assistant->status = 'Added';
         $group_assistant->save();
     }
     // save staff relationship - nb that the individual is contact_a and organization is contact_b
     if ($request->input('is_staff') > 0) {
         $relationship_staff = new \montserrat\Relationship();
         $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();
         $group_staff = new \montserrat\GroupContact();
         $group_staff->group_id = GROUP_ID_STAFF;
         $group_staff->contact_id = $person->id;
         $group_staff->status = 'Added';
         $group_staff->save();
     }
     // save steward group
     if ($request->input('is_steward') > 0) {
         $group_steward = new \montserrat\GroupContact();
         $group_steward->group_id = GROUP_ID_STEWARD;
         $group_steward->contact_id = $person->id;
         $group_steward->status = 'Added';
         $group_steward->save();
     }
     // save board member relationship
     if ($request->input('is_board') > 0) {
         $relationship_board = new \montserrat\Relationship();
         $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();
         $group_board = new \montserrat\GroupContact();
         $group_board->group_id = GROUP_ID_BOARD;
         $group_board->contact_id = $person->id;
         $group_board->status = 'Added';
         $group_board->save();
     }
     //groups: deacon, priest, bishop, pastor, jesuit, provincial, superior, captain, board, innkeeper, director, assistant, staff
     if ($request->input('is_bishop') > 0) {
         $group_bishop = new \montserrat\GroupContact();
         $group_bishop->group_id = GROUP_ID_BISHOP;
         $group_bishop->contact_id = $person->id;
         $group_bishop->status = 'Added';
         $group_bishop->save();
     }
     if ($request->input('is_priest') > 0) {
         $group_priest = new \montserrat\GroupContact();
         $group_priest->group_id = GROUP_ID_PRIEST;
         $group_priest->contact_id = $person->id;
         $group_priest->status = 'Added';
         $group_priest->save();
     }
     if ($request->input('is_deacon') > 0) {
         $group_deacon = new \montserrat\GroupContact();
         $group_deacon->group_id = GROUP_ID_DEACON;
         $group_deacon->contact_id = $person->id;
         $group_deacon->status = 'Added';
         $group_deacon->save();
     }
     if ($request->input('is_pastor') > 0) {
         $group_pastor = new \montserrat\GroupContact();
         $group_pastor->group_id = GROUP_ID_PASTOR;
         $group_pastor->contact_id = $person->id;
         $group_pastor->status = 'Added';
         $group_pastor->save();
     }
     if ($request->input('is_jesuit') > 0) {
         $group_jesuit = new \montserrat\GroupContact();
         $group_jesuit->group_id = GROUP_ID_JESUIT;
         $group_jesuit->contact_id = $person->id;
         $group_jesuit->status = 'Added';
         $group_jesuit->save();
     }
     if ($request->input('is_superior') > 0) {
         $group_superior = new \montserrat\GroupContact();
         $group_superior->group_id = GROUP_ID_SUPERIOR;
         $group_superior->contact_id = $person->id;
         $group_superior->status = 'Added';
         $group_superior->save();
     }
     if ($request->input('is_provincial') > 0) {
         $group_provincial = new \montserrat\GroupContact();
         $group_provincial->group_id = GROUP_ID_PROVINCIAL;
         $group_provincial->contact_id = $person->id;
         $group_provincial->status = 'Added';
         $group_provincial->save();
     }
     /* 
     $this->save_relationship('parish_id',$parish_id,$person->id,RELATIONSHIP_TYPE_PARISHIONER);
     $this->save_relationship('is_donor',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_DONOR);
     $this->save_relationship('is_retreatant',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_RETREATANT);
     $this->save_relationship('is_volunteer',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_VOLUNTEER);
     $this->save_relationship('is_captain',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_CAPTAIN);
     $this->save_relationship('is_director',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_RETREAT_DIRECTOR);
     $this->save_relationship('is_innkeeper',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_RETREAT_INNKEEPER);
     $this->save_relationship('is_assistant',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_RETREAT_ASSISTANT);
     $this->save_relationship('is_staff',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_STAFF);
     $this->save_relationship('is_board',CONTACT_MONTSERRAT,$person->id,RELATIONSHIP_TYPE_BOARD_MEMBER);
     */
     // save health, dietary, general and room preference notes
     if (!empty($request->input('note_health'))) {
         $person_note_health = new \montserrat\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 (!empty($request->input('note_dietary'))) {
         $person_note_dietary = new \montserrat\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 (!empty($request->input('note_contact'))) {
         $person_note_contact = new \montserrat\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 (!empty($request->input('note_room_preference'))) {
         $person_note_room_preference = new \montserrat\Note();
         $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();
     }
     if (empty($request->input('languages')) or in_array(0, $request->input('languages'))) {
         $person->languages()->detach();
     } else {
         $person->languages()->sync($request->input('languages'));
     }
     $home_address = new \montserrat\Address();
     $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 = new \montserrat\Address();
     $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 = new \montserrat\Address();
     $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 = new \montserrat\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 = new \montserrat\Phone();
     $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 = new \montserrat\Phone();
     $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 = new \montserrat\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 = new \montserrat\Phone();
     $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 = new \montserrat\Phone();
     $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 = new \montserrat\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 = new \montserrat\Phone();
     $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 = new \montserrat\Phone();
     $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 = new \montserrat\Email();
     $email_home->contact_id = $person->id;
     $email_home->location_type_id = LOCATION_TYPE_HOME;
     $email_home->email = $request->input('email_home');
     $email_home->is_primary = 1;
     $email_home->save();
     $email_work = new \montserrat\Email();
     $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 = new \montserrat\Email();
     $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 = new \montserrat\Website();
     $url_main->contact_id = $person->id;
     $url_main->url = $request->input('url_main');
     $url_main->website_type = 'Main';
     $url_main->save();
     $url_work = new \montserrat\Website();
     $url_work->contact_id = $person->id;
     $url_work->url = $request->input('url_work');
     $url_work->website_type = 'Work';
     $url_work->save();
     $url_facebook = new \montserrat\Website();
     $url_facebook->contact_id = $person->id;
     $url_facebook->url = $request->input('url_facebook');
     $url_facebook->website_type = 'Facebook';
     $url_facebook->save();
     $url_google = new \montserrat\Website();
     $url_google->contact_id = $person->id;
     $url_google->url = $request->input('url_google');
     $url_google->website_type = 'Google';
     $url_google->save();
     $url_instagram = new \montserrat\Website();
     $url_instagram->contact_id = $person->id;
     $url_instagram->url = $request->input('url_instagram');
     $url_instagram->website_type = 'Instagram';
     $url_instagram->save();
     $url_linkedin = new \montserrat\Website();
     $url_linkedin->contact_id = $person->id;
     $url_linkedin->url = $request->input('url_linkedin');
     $url_linkedin->website_type = 'LinkedIn';
     $url_linkedin->save();
     $url_twitter = new \montserrat\Website();
     $url_twitter->contact_id = $person->id;
     $url_twitter->url = $request->input('url_twitter');
     $url_twitter->website_type = 'Twitter';
     $url_twitter->save();
     return Redirect::action('PersonsController@show', $person->id);
     //
     //return Redirect::action('PersonsController@index');//
 }