public function run($request) { $sent = 0; if (WorkflowInstance::get()->count()) { // Don't attempt the filter if no instances -- prevents a crash $active = WorkflowInstance::get()->innerJoin('WorkflowDefinition', '"DefinitionID" = "WorkflowDefinition"."ID"')->filter(array('WorkflowStatus' => array('Active', 'Paused'), 'RemindDays:GreaterThan' => '0')); $active->filter(array('RemindDays:GreaterThan' => '0')); if ($active) { foreach ($active as $instance) { $edited = strtotime($instance->LastEdited); $days = $instance->Definition()->RemindDays; if ($edited + $days * 3600 * 24 > time()) { continue; } $email = new Email(); $bcc = ''; $members = $instance->getAssignedMembers(); $target = $instance->getTarget(); if (!$members || !count($members)) { continue; } $email->setSubject("Workflow Reminder: {$instance->Title}"); $email->setBcc(implode(', ', $members->column('Email'))); $email->setTemplate('WorkflowReminderEmail'); $email->populateTemplate(array('Instance' => $instance, 'Link' => $target instanceof SiteTree ? "admin/show/{$target->ID}" : '')); $email->send(); $sent++; $instance->LastEdited = time(); $instance->write(); } } } echo "Sent {$sent} workflow reminder emails.\n"; }
public function run($request) { $sent = 0; $filter = '"WorkflowStatus" IN (\'Active\', \'Paused\') AND "RemindDays" > 0'; $join = 'INNER JOIN "WorkflowDefinition" ON "DefinitionID" = "WorkflowDefinition"."ID"'; $active = DataObject::get('WorkflowInstance', $filter, null, $join); if ($active) { foreach ($active as $instance) { $edited = strtotime($instance->LastEdited); $days = $instance->Definition()->RemindDays; if ($edited + $days * 3600 * 24 > time()) { continue; } $email = new Email(); $bcc = ''; $members = $instance->getAssignedMembers(); $target = $instance->getTarget(); if (!$members || !count($members)) { continue; } $email->setSubject("Workflow Reminder: {$instance->Title}"); $email->setBcc(implode(', ', $members->column('Email'))); $email->setTemplate('WorkflowReminderEmail'); $email->populateTemplate(array('Instance' => $instance, 'Link' => $target instanceof SiteTree ? "admin/show/{$target->ID}" : '')); $email->send(); $sent++; $instance->LastEdited = time(); $instance->write(); } } echo "Sent {$sent} workflow reminder emails.\n"; }
/** * Adds or modifies a job on the website. * * @param array $data * @param Form $form */ public function doJobForm() { $data = $this->request->postVars(); $form = new JobBoardForm($this); $form->loadDataFrom($data); $existed = false; if (!isset($data['JobID']) && !$data['JobID']) { $job = new Job(); } else { $job = Job::get()->byId($data['JobID']); $existed = true; if ($job && !$job->canEdit()) { return $this->owner->httpError(404); } else { $job = new Job(); } } $form->saveInto($job); $job->isActive = true; $job->write(); Session::set('JobID', $job->ID); $member = Member::get()->filter(array('Email' => $data['Email']))->first(); if (!$member) { $member = new Member(); $member->Email = $SQL_email; $member->FirstName = isset($data['Company']) ? $data['Company'] : false; $password = Member::create_new_password(); $member->Password = $password; $member->write(); $member->addToGroupByCode('job-posters', _t('Jobboard.JOBPOSTERSGROUP', 'Job Posters')); } $member->logIn(); $job->MemberID = $member->ID; $job->write(); if (!$existed) { $email = new Email(); $email->setSubject($data['EmailSubject']); $email->setFrom($data['EmailFrom']); $email->setTo($member->Email); // send the welcome email. $email->setTemplate('JobPosting'); $email->populateTemplate(array('Member' => $member, 'Password' => isset($password) ? $password : false, 'FirstPost' => $password ? true : false, 'Holder' => $this, 'Job' => $job)); if ($notify = $form->getController()->getJobNotifyAddress()) { $email->setBcc($notify); } $email->send(); } return $this->redirect($data['BackURL']); }
/** * Send a mail of the order to the client (and another to the admin). * * @param $template - the class name of the email you wish to send * @param $subject - subject of the email * @param $copyToAdmin - true by default, whether it should send a copy to the admin */ public function sendEmail($template, $subject, $copyToAdmin = true) { $from = ShopConfig::config()->email_from ? ShopConfig::config()->email_from : Email::config()->admin_email; $to = $this->order->getLatestEmail(); $checkoutpage = CheckoutPage::get()->first(); $completemessage = $checkoutpage ? $checkoutpage->PurchaseComplete : ""; $email = new Email(); $email->setTemplate($template); $email->setFrom($from); $email->setTo($to); $email->setSubject($subject); if ($copyToAdmin) { $email->setBcc(Email::config()->admin_email); } $email->populateTemplate(array('PurchaseCompleteMessage' => $completemessage, 'Order' => $this->order, 'BaseURL' => Director::absoluteBaseURL())); return $email->send(); }
public function process() { $sent = 0; $filter = array('WorkflowStatus' => array('Active', 'Paused'), 'Definition.RemindDays:GreaterThan' => 0); $active = WorkflowInstance::get()->filter($filter); foreach ($active as $instance) { $edited = strtotime($instance->LastEdited); $days = $instance->Definition()->RemindDays; if ($edited + $days * 3600 * 24 > time()) { continue; } $email = new Email(); $bcc = ''; $members = $instance->getAssignedMembers(); $target = $instance->getTarget(); if (!$members || !count($members)) { continue; } $email->setSubject("Workflow Reminder: {$instance->Title}"); $email->setBcc(implode(', ', $members->column('Email'))); $email->setTemplate('WorkflowReminderEmail'); $email->populateTemplate(array('Instance' => $instance, 'Link' => $target instanceof SiteTree ? "admin/show/{$target->ID}" : '')); $email->send(); $sent++; // add a comment to the workflow if possible $action = $instance->CurrentAction(); $currentComment = $action->Comment; $action->Comment = sprintf(_t('AdvancedWorkflow.JOB_REMINDER_COMMENT', '%s: Reminder email sent\\n\\n'), date('Y-m-d H:i:s')) . $currentComment; try { $action->write(); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::WARN); } $instance->LastEdited = time(); try { $instance->write(); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::WARN); } } $this->currentStep = 2; $this->isComplete = true; $nextDate = date('Y-m-d H:i:s', time() + $this->repeatInterval); $this->queuedJobService->queueJob(new WorkflowReminderJob($this->repeatInterval), $nextDate); }
public function execute(WorkflowInstance $workflow) { $email = new Email(); $members = $workflow->getAssignedMembers(); $emails = ''; if (!$members || !count($members)) { return; } foreach ($members as $member) { if ($member->Email) { $emails .= "{$member->Email}, "; } } $context = $this->getContextFields($workflow->getTarget()); $member = $this->getMemberFields(); $variables = array(); foreach ($context as $field => $val) { $variables["\$Context.{$field}"] = $val; } foreach ($member as $field => $val) { $variables["\$Member.{$field}"] = $val; } $subject = str_replace(array_keys($variables), array_values($variables), $this->EmailSubject); if ($this->ListingTemplateID) { $item = $workflow->customise(array('Items' => $workflow->Actions(), 'Member' => Member::currentUser(), 'Context' => $workflow->getTarget())); $template = DataObject::get_by_id('ListingTemplate', $this->ListingTemplateID); $view = SSViewer::fromString($template->ItemTemplate); $body = $view->process($item); } else { $body = str_replace(array_keys($variables), array_values($variables), $this->EmailTemplate); } $email->setSubject($subject); $email->setFrom($this->EmailFrom); $email->setBcc(substr($emails, 0, -2)); $email->setBody($body); $email->send(); return true; }
/** * Attempts to save either a registration or add member form submission * into a new member object, returning NULL on validation failure. * * @return Member|null */ protected function addMember($form) { $member = new Member(); $groupIds = $this->getSettableGroupIdsFrom($form); $form->saveInto($member); $member->ProfilePageID = $this->ID; $member->NeedsValidation = $this->EmailType == 'Validation'; $member->NeedsApproval = $this->RequireApproval; try { $member->write(); } catch (ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return; } // set after member is created otherwise the member object does not exist $member->Groups()->setByIDList($groupIds); // If we require admin approval, send an email to the admin and delay // sending an email to the member. if ($this->RequireApproval) { $groups = $this->ApprovalGroups(); $emails = array(); if ($groups) { foreach ($groups as $group) { foreach ($group->Members() as $_member) { if ($member->Email) { $emails[] = $_member->Email; } } } } if ($emails) { $email = new Email(); $config = SiteConfig::current_site_config(); $approve = Controller::join_links(Director::baseURL(), 'member-approval', $member->ID, '?token=' . $member->ValidationKey); $email->setSubject("Registration Approval Requested for {$config->Title}"); $email->setBcc(implode(',', array_unique($emails))); $email->setTemplate('MemberRequiresApprovalEmail'); $email->populateTemplate(array('SiteConfig' => $config, 'Member' => $member, 'ApproveLink' => Director::absoluteURL($approve))); $email->send(); } } elseif ($this->EmailType != 'None') { $email = new MemberConfirmationEmail($this, $member); $email->send(); } $this->extend('onAddMember', $member); return $member; }
public function SendEnquiryForm($data, $form) { $From = $this->EmailFrom; $To = $this->EmailTo; $Subject = $this->EmailSubject; $email = new Email($From, $To, $Subject); $replyTo = $this->EnquiryFormFields()->filter(array('FieldType' => 'Email'))->First(); if ($replyTo) { $postField = $this->keyGen($replyTo->FieldName, $replyTo->SortOrder); if (isset($data[$postField]) && Email::validEmailAddress($data[$postField])) { $email->replyTo($data[$postField]); } } if ($this->EmailBcc) { $email->setBcc($this->EmailBcc); } //abuse / tracking $email->addCustomHeader('X-Sender-IP', $_SERVER['REMOTE_ADDR']); //set template $email->setTemplate('EnquiryFormEmail'); //populate template $templateData = $this->getTemplateData($data); $email->populateTemplate($templateData); //send mail $email->send(); //return to submitted message if (Director::is_ajax()) { return $this->renderWith('EnquiryPageAjaxSuccess'); } $this->redirect($this->Link('?success=1#thankyou')); }
/** * standard SS Method * Sends an email to the member letting her / him know that the account has been approved. */ function onAfterWrite() { if ($this->owner->isApprovedCorporateCustomer()) { if (!$this->owner->ApprovalEmailSent) { $config = SiteConfig::current_site_config(); $ecommerceConfig = EcommerceDBConfig::current_ecommerce_db_config(); $email = new Email(); $email->setTo($this->owner->Email); $email->setSubject(_t("EcommerceCorporateAccount.ACCOUNTAPPROVEDFOR", "Account approved for ") . $config->Title); $email->setBcc(Order_Email::get_from_email()); $email->setTemplate('EcommerceCorporateGroupApprovalEmail'); $email->populateTemplate(array('SiteConfig' => $config, 'EcommerceConfig' => $ecommerceConfig, 'Member' => $this->owner)); $email->send(); $this->owner->ApprovalEmailSent = 1; $this->owner->write(); } } }
/** * Sent the e-mail. * * @param Array $data * @param Form $form */ function sendmail($data, $form) { $email = Convert::raw2sql($data["EmailDownloadPageEmail"]); $obj = EmailDownloadPage_Registration::get()->filter(array("Email" => $email, "DownloadFileID" => $this->DownloadFileID))->first(); if (!$obj) { $obj = new EmailDownloadPage_Registration(); $obj->Email = $email; $obj->DownloadFileID = $this->DownloadFileID; } else { $obj->Used = false; } $obj->EmailDownloadPageID = $this->ID; $obj->write(); $adminEmail = Email::getAdminEmail(); if (!$adminEmail) { user_error("You need to set an admin email in order to use this page", E_USER_NOTICE); } $email = new Email($adminEmail, $data["EmailDownloadPageEmail"], $this->EmailSubject); if ($this->CopyOfAllEmailsToAdmin) { $email->setBcc($adminEmail); } $email->setTemplate($this->config()->get("email_template")); // You can call this multiple times or bundle everything into an array, including DataSetObjects $email->populateTemplate(new ArrayData(array("EmailSubject" => DBField::create_field('Varchar', $this->EmailSubject), "TitleOfFile" => DBField::create_field('Varchar', $this->TitleOfFile), "ValidUntil" => date('Y-M-d', strtotime("+" . $this->ValidityInDays * 86400 . " seconds")), "HasLink" => $this->LinkToThirdPartyDownload ? true : false, "HasFile" => $this->DownloadFileID ? true : false, "LinkToThirdPartyDownload" => $this->LinkToThirdPartyDownload, "File" => $this->DownloadFile(), "DownloadLink" => Director::absoluteURL($this->Link("dodownload/" . $obj->ID . "/" . $obj->Code . '/')), "FileLocation" => Director::absoluteURL($this->DownloadFile()->Link())))); $outcome = $email->send(); Session::set($this->sessionVarNameForSending(), $outcome); $this->redirect($this->Link("thankyou/" . ($outcome ? "success" : "fail") . "/")); return array(); }