function SaveDeployment($data, $form) { $id = convert::raw2sql($data['DeploymentID']); // Only loaded if it belongs to current user $Deployment = $form->controller->LoadDeployment($id); // If a deployment wasn't returned, we'll create a new one if (!$Deployment) { $Deployment = new Deployment(); $Deployment->OrgID = Member::currentUser()->getCurrentOrganization()->ID; $newDeploy = true; } $form->saveInto($Deployment); $survey = $form->controller->GetCurrentSurvey(); $Deployment->DeploymentSurveyID = $survey->ID; $Deployment->UpdateDate = SS_Datetime::now()->Rfc2822(); $Deployment->OrgID = $survey->OrgID; $Deployment->write(); /**/ $survey->CurrentStep = 'MoreDeploymentDetails'; $survey->HighestStepAllowed = 'MoreDeploymentDetails'; $survey->UpdateDate = SS_Datetime::now()->Rfc2822(); $survey->write(); // If it is a new deployment and it is public, we send an email... if (isset($newDeploy) && $Deployment->IsPublic === 1) { global $email_new_deployment; global $email_from; $email = EmailFactory::getInstance()->buildEmail($email_from, $email_new_deployment, 'New Deployment'); $email->setTemplate('NewDeploymentEmail'); $email->populateTemplate(array('Deployment' => $Deployment)); $email->send(); } Session::set('CurrentDeploymentID', $Deployment->ID); Controller::curr()->redirect($form->controller->Link() . 'MoreDeploymentDetails'); }
public function member() { $EmailAddress = ""; $Member = ""; // Make sure the access is POST, not GET if (!$this->request->isPOST()) { return $this->httpError(403, 'Access Denied.'); } if (!defined('APPSEC')) { return $this->httpError(403, 'Access Denied.'); } // Make sure the APPSEC shared secret matches if ($this->request->postVar('APPSEC') != APPSEC) { return $this->httpError(403, 'Access Denied.'); } // Pull email address from POST variables $EmailAddress = $this->request->postVar('email'); // Sanitize the input $EmailAddress = convert::raw2sql($EmailAddress); // If an email address was provided, try to find a member with it if ($EmailAddress) { $Member = Member::get()->filter('Email', $EmailAddress)->first(); } $response = new SS_HTTPResponse(); // If a member was found return status 200 and 'OK' if ($Member && $Member->isFoundationMember()) { $response->setStatusCode(200); $response->setBody('OK'); $response->output(); } elseif ($EmailAddress) { $response->setStatusCode(404); $response->setBody('No Member Found.'); $response->output(); } else { $response->setStatusCode(500); $response->setBody('An error has occurred retrieving a member.'); $response->output(); } }
public function markForeignAccount() { try { $foreign_id = intval(convert::raw2sql($this->request->param('FOREIGN_MEMBER_ID'))); $current_member = Member::currentUser(); $this->manager->markAsNotMyAccount($current_member->ID, $foreign_id); return $this->ok(); } catch (NotFoundEntityException $ex1) { SS_Log::log($ex1, SS_Log::WARN); return $this->notFound($ex1->getMessage()); } catch (EntityValidationException $ex2) { SS_Log::log($ex2, SS_Log::WARN); return $this->validationError($ex2->getMessages()); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::ERR); return $this->serverError(); } }
public function getCompanyByURLSegment() { $Params = $this->getURLParams(); $Segment = convert::raw2sql($Params['ID']); if ($Params['ID'] && ($Company = Company::get()->filter('URLSegment', $Segment)->first())) { return $Company; } }
/** * Include some CSS and set the dataRecord to the current Product that is being viewed. * * @see Page_Controller::init() */ function init() { parent::init(); Requirements::css('swipestripe/css/Shop.css'); //Get current product page for products that are not part of the site tree //and do not have a ParentID set, they are accessed via this controller using //Director rules if ($this->dataRecord->ID == -1) { $params = $this->getURLParams(); if ($urlSegment = $params['ID']) { $product = DataObject::get_one('Product', "URLSegment = '" . convert::raw2sql($urlSegment) . "'"); if ($product && $product->exists()) { $this->dataRecord = $product; $this->failover = $this->dataRecord; $this->customise(array('Product' => $this->data())); } } } $this->extend('onInit'); }
protected function MigrateImageGalleryAlbum($id, $gallery) { try { //grab this album $album = $this->ImageGalleryAlbum($id); if (empty($album['ID'])) { throw new Exception("The target album does not exist"); } //grab its items $items = $this->ImageGalleryAlbumItems($album['ID']); if (empty($gallery->ID)) { throw new Exception("I can't migrate an album {$album->AlbumName} into an empty gallery"); } if (empty($gallery->Title)) { $gallery->Title = $album['AlbumName']; } if (empty($gallery->Description)) { $gallery->Description = $album['Description']; } $gallery->Migrated = 1; $gallery->write(); if (!empty($items)) { foreach ($items as $item) { //get the source image for this item $image = DataObject::get_by_id('File', $item['ImageID']); if (!empty($image->ID)) { //does the image exist ? $source_filename_path = BASE_PATH . "/" . $image->Filename; $target_filename = $target_filename_path = FALSE; $path_info = pathinfo($source_filename_path); if (!empty($path_info['dirname']) && !empty($path_info['basename'])) { $target_filename = "DA_copy_of_" . $path_info['basename']; $target_filename_path = $path_info['dirname'] . "/" . $target_filename; } //print $source_filename_path . "\n";print $target_filename . "\n";print $target_filename_path . "\n"; //we'll make a copy of it so that the old images can be deleted without touching the new files //if the target image exists, assume it's already been migrated and just update the record $migrated_file = FALSE; if (file_exists($target_filename_path)) { $copy = TRUE; //grab the file_id. this is an update $pattern = preg_quote(addslashes(BASE_PATH . "/")); $target_replaced = preg_replace("|^{$pattern}|", "", $target_filename_path); $migrated_file = DataObject::get_one("File", "Filename='" . convert::raw2sql(ltrim($target_replaced, "/")) . "'"); } else { if (is_readable($source_filename_path) && is_readable(dirname($target_filename_path)) && !file_exists($target_filename_path) && is_writable(dirname($target_filename_path))) { $copy = copy($source_filename_path, $target_filename_path); } } if ($copy) { $file = new DisplayAnythingFile(); $file->Visible = 1; $file->Caption = $item['Caption']; $file->GalleryID = $gallery->ID; $file->Filename = $target_filename_path; $file->ParentID = $image->ParentID; $file->OwnerID = $image->OwnerID; $file->Sort = $image->Sort; $file->Title = $image->Title; if (!empty($migrated_file->ID)) { /** * an update * note if the file already exists on the file system * but not in the DB, a new file will be created */ $file->ID = $migrated_file->ID; } //don't set ->Name, crazy crap happens thanks to File::setName(0 $file_id = $file->write(); } } } } } catch (Exception $e) { //failed } }
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:'); } }
public function RemoveDeployment() { if (isset($_GET['DeploymentID'])) { $id = convert::raw2sql($_GET['DeploymentID']); } if ($id && ($Deployment = $this->LoadDeployment($id))) { $Deployment->Delete(); $this->redirectBack(); } }
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:'); } }
/** * * retrieves and updates all the logs from session */ protected function retrieveFromSession() { $array = unserialize(Session::get("DatabasebackupLogs")); foreach ($array as $id => $values) { $obj = DatabasebackupLog::get()->filter(array("FullLocation" => $values["FullLocation"]))->first(); if ($obj) { $obj->Title = convert::raw2sql($values["Title"]); $obj->Notes = convert::raw2sql($values["Notes"]); $obj->Created = convert::raw2sql($values["Created"]); $obj->write(); } } }
public function getPresentationByURLSegment($featured = false) { $Params = $this->getURLParams(); $Segment = convert::raw2sql($Params['ID']); if ($featured == false && $Params['ID'] && ($Presentation = DataObject::get_one('VideoPresentation', "`URLSegment` = '" . $Segment . "' AND `PresentationCategoryPageID` = " . $this->ID))) { return $Presentation; } elseif ($featured == true && $Params['ID'] && ($FeaturedVideo = DataObject::get_one('FeaturedVideo', "`URLSegment` = '" . $Segment . "'"))) { return $FeaturedVideo; } }
function onBeforeWrite() { if (!empty($this->owner->Parameters)) { if (!empty($this->owner->Parameters["productquestions"])) { $answers = array(); $params = $this->owner->Parameters["productquestions"]; $params = urldecode($params); $items = explode("|", $params); if ($items && is_array($items) && count($items)) { foreach ($items as $item) { if ($item) { $itemArray = explode("=", $item); if (is_array($itemArray) && count($itemArray) == 2) { $key = intval(str_replace(array("ProductQuestions[", "]"), "", $itemArray[0])); $value = convert::raw2sql($itemArray[1]); $answers[$key] = $value; } } } } unset($this->owner->Parameters); $this->updateOrderItemWithProductAnswers($answers, false); } } }
/** * @return String */ protected function LiveName() { $obj = $this->liveOptionObject(); if (is_object($obj)) { $v = $obj->Name; if ($obj->ExplanationPageID) { $page = $obj->ExplanationPage(); if ($page) { $v .= '<div id="PickUpOrDeliveryModifierExplanationLink"><a href="' . $page->Link() . '" class="externalLink">' . convert::raw2sql($page->Title) . '</a></div>'; } } return $v; } return _t("PickUpOrDeliveryModifier.POSTAGEANDHANDLING", "Postage and Handling"); }