Example #1
0
 function SaveProfile($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         //Get InfusionSoft Api
         $app = $this->getInfusionSoftApi();
         $returnFields = array('Id');
         $conInfo = $app->findByEmail($data['Email'], $returnFields);
         //Check for another member with the same email address
         if ($member = DataObject::get_one("Member", "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
             $form->addErrorMessage("Email", 'Sorry, that Email address already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return $this->redirectBack();
         } elseif ($CurrentMember->Email != $data['Email'] && !empty($conInfo)) {
             $form->addErrorMessage("Email", 'Sorry, that Email address already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return $this->redirectBack();
         } else {
             //Update the InfusionSoft contact details
             $isConID = $CurrentMember->ISContactID;
             $conDat = array('FirstName' => $data['FirstName'], 'LastName' => $data['Surname'], 'Email' => $data['Email']);
             $app->updateCon($isConID, $conDat);
             //Update the member on site
             $form->saveInto($CurrentMember);
             $CurrentMember->write();
             $this->setMessage('Success', 'Your profile has been saved!');
             return $this->redirectBack();
         }
     } else {
         return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:');
     }
 }
 /**
  * @return EditProfilePage|SS_HTTPResponse
  */
 public function Form()
 {
     if (!Member::currentUser()) {
         return Security::PermissionFailure($this->controller, null);
     } else {
         $form = EditProfileForm::create($this, 'Form');
         $this->extend('updateEditProfileForm', $form);
         return $form;
     }
 }
 /**
  * @param $data
  * @param $form
  * @return SS_HTTPResponse
  */
 function SaveProfile($data, $form)
 {
     // Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         // Check for another member with the same email address
         if ($member = DataObject::get_one("Member", "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
             $form->addErrorMessage("Name", 'Sorry, that name already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return Director::redirectBack();
         } else {
             $form->saveInto($CurrentMember);
             $CurrentMember->write();
             return $this->redirect($this->Link('?saved=1'));
         }
     } else {
         return Security::PermissionFailure($this->controller, 'you must be logged in to edit your profile');
     }
 }
 function SaveProfile($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         //Check for another member with the same email address
         if ($member = DataObject::get_one("Member", "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
             //Set error message
             $form->sessionMessage($data['Email'] . ". Sorry, that email address already exists. Please choose another.", 'bad');
             //Return back to form
             return $this->redirectBack();
             //return Director::redirectBack();
         } else {
             $form->saveInto($CurrentMember);
             $CurrentMember->write();
             return $this->redirect($this->Link('?saved=1'));
         }
     } else {
         return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:');
     }
 }
 /**
  * @param $data
  * @param $form
  * @return bool|SS_HTTPResponse
  */
 public function SaveProfile($data, $form)
 {
     if ($CurrentMember = Member::currentUser()) {
         if ($member = DataObject::get_one('Member', "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
             $form->addErrorMessage('Email', _t('EditProfilePage.EmailErrorText', 'Sorry, that Email already exists.'), 'validation');
             return $this->redirectBack();
         } else {
             // If no password don't save the field
             if (!isset($data['password'])) {
                 unset($data['password']);
             }
             $this->setFlash(_t('EditProfilePage.EmailSuccessText', 'Your profile has been updated'), 'success');
             $form->saveInto($CurrentMember);
             $CurrentMember->write();
             return $this->redirect($this->Link());
         }
     } else {
         return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:');
     }
 }
 /**
  * @param $data
  * @param $form
  * @return bool|SS_HTTPResponse|void
  * @throws ValidationException
  * @throws null
  */
 public function Save($data, $form)
 {
     /** @var Form $form */
     $data = $form->getData();
     if ($CurrentMember = Member::currentUser()) {
         if ($member = DataObject::get_one('Member', "Email = '" . Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
             $form->addErrorMessage('Email', 'Sorry, that Email already exists.', 'validation');
             return $this->controller->redirectBack();
         } else {
             /** If no password don't save the field */
             if (!isset($data['password'])) {
                 unset($data['password']);
             }
             $this->controller->setFlash('Your profile has been updated', 'success');
             $form->saveInto($CurrentMember);
             $CurrentMember->write();
             return $this->controller->redirect($this->controller->Link());
         }
     } else {
         /** Get registration page otherwise display warning.
          *
          * @var RegistrationPage $registerPage
          */
         if ($registerPage = DataObject::get_one('RegistrationPage')) {
             return Security::PermissionFailure($this->controller, 'You must <a href="' . $registerPage->Link() . '">registered</a> and logged in to edit your profile.');
         } else {
             $this->controller->setFlash('You must registered and logged in to edit your profile.', 'warning');
             return $this->controller->redirect(Director::absoluteBaseURL());
         }
     }
 }
 function SaveProfile($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         //Check for another member with the same email address
         if (Member::get()->filter(array('Email' => Convert::raw2sql($data['Email']), 'ID:not' => $CurrentMember->ID))->count() > 0) {
             $form->addErrorMessage("Email", 'Sorry, that email address already exists.', "bad");
             Session::set("FormInfo.Form_EditProfileForm.data", $data);
             return $this->redirect($this->Link('?error=1'));
         } else {
             // Clean up bio
             if ($data["Bio"]) {
                 $config = HTMLPurifier_Config::createDefault();
                 // Remove any CSS or inline styles
                 $config->set('CSS.AllowedProperties', array());
                 $purifier = new HTMLPurifier($config);
                 $cleanedBio = $purifier->purify($data["Bio"]);
             }
             $form->saveInto($CurrentMember);
             if (isset($cleanedBio)) {
                 $CurrentMember->Bio = $cleanedBio;
             }
             if ($data['Gender'] == 'Specify') {
                 $CurrentMember->Gender = $data['GenderSpecify'];
             }
             if ($CurrentMember->isChanged('Email')) {
                 $sender = new MemberRegistrationSenderService();
                 $sender->send($CurrentMember->resetConfirmation());
             }
             $CurrentMember->write();
             $speaker = PresentationSpeaker::get()->filter('MemberID', $CurrentMember->ID)->first();
             if ($speaker) {
                 if ($data['ReplaceName'] == 1) {
                     $speaker->FirstName = $data['FirstName'];
                 }
                 if ($data['ReplaceSurname'] == 1) {
                     $speaker->Surname = $data['Surname'];
                 }
                 if ($data['ReplaceBio'] == 1) {
                     $speaker->Bio = $data['Bio'];
                 }
                 $speaker->write();
             }
             // If they do not have a photo uploaded, but they have provided a twitter URL, attempt to grab a photo from twitter
             if ($CurrentMember->TwitterName && !$CurrentMember->Photo()->Exists()) {
                 $this->ProfilePhotoFromTwitter($CurrentMember);
             }
             return $this->redirect($this->Link('?saved=1'));
         }
     } else {
         return Security::PermissionFailure($this->controller, 'You must be <a href="/join">registered</a> and logged in to edit your profile:');
     }
 }
 function addAction($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         // Find a site member (in any group) based on the MemberID field
         $id = Convert::raw2sql($data['MemberID']);
         $member = DataObject::get_by_id("Member", $id);
         if ($data['SpeakerID'] && is_numeric($data['SpeakerID'])) {
             $speaker = PresentationSpeaker::get()->byID(intval($data['SpeakerID']));
         } elseif ($member) {
             $speaker = PresentationSpeaker::get()->filter('MemberID', $member->ID)->first();
         }
         if (!$speaker) {
             $speaker = new PresentationSpeaker();
         }
         //Find or create the 'speaker' group
         if (!($userGroup = DataObject::get_one('Group', "Code = 'speakers'"))) {
             $userGroup = new Group();
             $userGroup->Code = "speakers";
             $userGroup->Title = "Speakers";
             $userGroup->Write();
             $member->Groups()->add($userGroup);
         }
         //Add member to the group
         $member->Groups()->add($userGroup);
         if ($data['Country'] != '' && $data['Country'] != $member->Country) {
             $member->Country = convert::raw2sql($data['Country']);
         }
         if ($data['ReplaceName'] == 1) {
             $member->FirstName = $data['FirstName'];
         }
         if ($data['ReplaceSurname'] == 1) {
             $member->Surname = $data['LastName'];
         }
         if ($data['ReplaceBio'] == 1) {
             $member->Bio = $data['Bio'];
         }
         $member->write();
         $form->saveInto($speaker);
         $speaker->MemberID = $member->ID;
         $speaker->AdminID = Member::currentUser()->ID;
         // Attach Photo
         if ($member->PhotoID && $speaker->PhotoID == 0) {
             $speaker->PhotoID = $member->PhotoID;
         }
         $speaker->AskedAboutBureau = TRUE;
         // Languages
         foreach ($speaker->Languages() as $currentlang) {
             $currentlang->delete();
         }
         foreach ($data['Language'] as $lang) {
             if (trim($lang) != '') {
                 $spoken_lang = SpeakerLanguage::create(array('Language' => $lang));
                 $speaker->Languages()->add($spoken_lang);
             }
         }
         // Expertise
         $speaker->AreasOfExpertise()->removeAll();
         foreach ($data['Expertise'] as $exp) {
             if (trim($exp) != '') {
                 $expertise = SpeakerExpertise::create(array('Expertise' => $exp));
                 $speaker->AreasOfExpertise()->add($expertise);
             }
         }
         // Presentation Link
         $speaker->OtherPresentationLinks()->removeAll();
         foreach ($data['PresentationLink'] as $key => $link) {
             if (trim($link) != '') {
                 $presentation_title = trim($data['PresentationTitle'][$key]);
                 $presentation_link = SpeakerPresentationLink::create(array('LinkUrl' => $link, 'Title' => $presentation_title));
                 $speaker->OtherPresentationLinks()->add($presentation_link);
             }
         }
         // Travel Preferences
         $speaker->TravelPreferences()->removeAll();
         foreach ($data['CountriesToTravel'] as $travel_country) {
             $travel_pref = SpeakerTravelPreference::create(array('Country' => $travel_country));
             $speaker->TravelPreferences()->add($travel_pref);
         }
         $speaker->write();
         $form->sessionMessage('Your profile has been updated', 'good');
         Session::clear("FormInfo.{$form->FormName()}.data", $data);
         return $this->controller()->redirectBack();
     } else {
         return Security::PermissionFailure($this->controller, 'You must be <a href="/join">registered</a> and logged in to edit your profile:');
     }
 }
 function addAction($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         // Find a site member (in any group) based on the MemberID field
         $id = Convert::raw2sql($data['MemberID']);
         $member = DataObject::get_by_id("Member", $id);
         if ($data['SpeakerID'] && is_numeric($data['SpeakerID'])) {
             $speaker = PresentationSpeaker::get()->byID(intval($data['SpeakerID']));
         } elseif ($member) {
             $speaker = PresentationSpeaker::get()->filter('MemberID', $member->ID)->first();
         }
         if (!$speaker) {
             $speaker = new PresentationSpeaker();
         }
         //Find or create the 'speaker' group
         if (!($userGroup = DataObject::get_one('Group', "Code = 'speakers'"))) {
             $userGroup = new Group();
             $userGroup->Code = "speakers";
             $userGroup->Title = "Speakers";
             $userGroup->Write();
             $member->Groups()->add($userGroup);
         }
         //Add member to the group
         $member->Groups()->add($userGroup);
         if ($data['Country'] != '' && $data['Country'] != $member->Country) {
             $member->Country = convert::raw2sql($data['Country']);
         }
         if ($data['ReplaceName'] == 1) {
             $member->FirstName = $data['FirstName'];
         }
         if ($data['ReplaceSurname'] == 1) {
             $member->Surname = $data['LastName'];
         }
         if ($data['ReplaceBio'] == 1) {
             $member->Bio = $data['Bio'];
         }
         $member->write();
         $form->saveInto($speaker);
         $speaker->MemberID = $member->ID;
         $speaker->AdminID = Member::currentUser()->ID;
         // Attach Photo
         if ($member->PhotoID && $speaker->PhotoID == 0) {
             $speaker->PhotoID = $member->PhotoID;
         }
         $speaker->AskedAboutBureau = TRUE;
         $speaker->write();
         $this->controller->redirect($this->controller()->Link() . 'speaker?saved=1');
     } else {
         return Security::PermissionFailure($this->controller, 'You must be <a href="/join">registered</a> and logged in to edit your profile:');
     }
 }