protected static function getViewFromEmailTemplateBuiltType(EmailTemplate $emailTemplate)
 {
     if ($emailTemplate->isBuilderTemplate()) {
         return 'BuilderEmailTemplateWizardView';
     }
     return 'ClassicEmailTemplateWizardView';
 }
 function sendLoginDetails($email)
 {
     global $sitename;
     global $logo;
     $query = MYSQL_QUERY("SELECT `Username`,`Password` FROM `ChallengeMembers` WHERE `Email` = '" . $email . "' ") or die(MYSQL_ERROR());
     if ($query) {
         if (MYSQL_NUM_ROWS($query)) {
             while ($row = MYSQL_FETCH_ARRAY($query)) {
                 $userpassword = $row['Password'];
                 $username = $row['Username'];
             }
             /*send email*/
             include 'email_class.php';
             $em = new EmailTemplate();
             $subject = ucfirst($sitename) . " Login Details";
             $headers = "From: " . ucwords($sitename) . " <*****@*****.**> \r\n" . 'X-Mailer: PHP/' . phpversion();
             $headers .= 'MIME-Version: 1.0' . "\r\n";
             $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
             $email_message = $username . ",<br /><br /> Thank you for your interest in joining our challenges.\n\t\t\t\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t\t\t\tThe following are your login data:\n\t\t\t\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\t\t\tUsername : <b>" . $username . "</b><br />\n\t\t\t\t\t\t\t\t\tPassword : <b>" . $userpassword . "</b>\n\t\t\t\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t\t\t\tThank you.<br />\n\t\t\t\t\t\t\t\t\t<b>" . $sitename . "</b>";
             $emailmessage = $em->get($logo, $sitename, $email_message);
             /*first send to guest */
             $sentmail = mail($email, $subject, $emailmessage, $headers);
             /*end of send email*/
             return "OK";
         } else {
             return $email . "not found in database.";
         }
     } else {
         return "Email not found in database.";
     }
 }
 function save($check_notify = false)
 {
     global $current_user, $sugar_config;
     parent::save($check_notify);
     $email_template = new EmailTemplate();
     if ($_REQUEST['module'] == 'Import') {
         //Don't send email on import
         return;
     }
     $signature = array();
     $addDelimiter = true;
     $aop_config = $sugar_config['aop'];
     if (!empty($this->contact_id)) {
         $emails = $this->getEmailForUser();
         if ($aop_config['user_email_template_id']) {
             $email_template->retrieve($aop_config['user_email_template_id']);
         }
         $addDelimiter = false;
     } elseif ($this->assigned_user_id && !$this->internal) {
         $emails = $this->getEmailForContact();
         if ($aop_config['contact_email_template_id']) {
             $email_template->retrieve($aop_config['contact_email_template_id']);
             $signature = $current_user->getDefaultSignature();
         }
     }
     if ($emails && $email_template) {
         $GLOBALS['log']->info("AOPCaseUpdates: Calling send email");
         $res = $this->sendEmail($emails, $email_template, $signature, $this->case_id, $addDelimiter);
     }
 }
function canSendPassword()
{
    global $mod_strings, $current_user, $app_strings;
    require_once "modules/OutboundEmailConfiguration/OutboundEmailConfigurationPeer.php";
    if ($current_user->is_admin) {
        $emailTemplate = new EmailTemplate();
        $emailTemplate->disable_row_level_security = true;
        if ($emailTemplate->retrieve($GLOBALS['sugar_config']['passwordsetting']['generatepasswordtmpl']) == '') {
            return $mod_strings['LBL_EMAIL_TEMPLATE_MISSING'];
        }
        if (empty($emailTemplate->body) && empty($emailTemplate->body_html)) {
            return $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT'];
        }
        if (!OutboundEmailConfigurationPeer::validSystemMailConfigurationExists($current_user)) {
            return $mod_strings['ERR_SERVER_SMTP_EMPTY'];
        }
        $emailErrors = $mod_strings['ERR_EMAIL_NOT_SENT_ADMIN'];
        try {
            $config = OutboundEmailConfigurationPeer::getSystemDefaultMailConfiguration();
            if ($config instanceof OutboundSmtpEmailConfiguration) {
                $emailErrors .= "<br>-{$mod_strings['ERR_SMTP_URL_SMTP_PORT']}";
                if ($config->isAuthenticationRequired()) {
                    $emailErrors .= "<br>-{$mod_strings['ERR_SMTP_USERNAME_SMTP_PASSWORD']}";
                }
            }
        } catch (MailerException $me) {
            // might want to report the error
        }
        $emailErrors .= "<br>-{$mod_strings['ERR_RECIPIENT_EMAIL']}";
        $emailErrors .= "<br>-{$mod_strings['ERR_SERVER_STATUS']}";
        return $emailErrors;
    }
    return $mod_strings['LBL_EMAIL_NOT_SENT'];
}
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = User::getByUsername('super');
     $super = User::getByUsername('super');
     $super->primaryEmail = new Email();
     $super->primaryEmail->emailAddress = '*****@*****.**';
     assert($super->save());
     // Not Coding Standard
     $bobby = UserTestHelper::createBasicUserWithEmailAddress('bobby');
     $sarah = UserTestHelper::createBasicUserWithEmailAddress('sarah');
     self::$superUserId = $super->id;
     self::$bobbyUserId = $bobby->id;
     self::$sarahUserId = $sarah->id;
     $emailTemplate = new EmailTemplate();
     $emailTemplate->modelClassName = 'WorkflowModelTestItem';
     $emailTemplate->type = 1;
     $emailTemplate->name = 'some template';
     $emailTemplate->subject = 'some subject [[LAST^NAME]]';
     $emailTemplate->htmlContent = 'html content [[STRING]]';
     $emailTemplate->textContent = 'text content [[PHONE]]';
     $saved = $emailTemplate->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     self::$emailTemplate = $emailTemplate;
 }
function canSendPassword()
{
    require_once 'include/SugarPHPMailer.php';
    global $mod_strings;
    global $current_user;
    global $app_strings;
    $mail = new SugarPHPMailer();
    $emailTemp = new EmailTemplate();
    $mail->setMailerForSystem();
    $emailTemp->disable_row_level_security = true;
    if ($current_user->is_admin) {
        if ($emailTemp->retrieve($GLOBALS['sugar_config']['passwordsetting']['generatepasswordtmpl']) == '') {
            return $mod_strings['LBL_EMAIL_TEMPLATE_MISSING'];
        }
        if (empty($emailTemp->body) && empty($emailTemp->body_html)) {
            return $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT'];
        }
        if ($mail->Mailer == 'smtp' && $mail->Host == '') {
            return $mod_strings['ERR_SERVER_SMTP_EMPTY'];
        }
        $email_errors = $mod_strings['ERR_EMAIL_NOT_SENT_ADMIN'];
        if ($mail->Mailer == 'smtp') {
            $email_errors .= "<br>-" . $mod_strings['ERR_SMTP_URL_SMTP_PORT'];
        }
        if ($mail->SMTPAuth) {
            $email_errors .= "<br>-" . $mod_strings['ERR_SMTP_USERNAME_SMTP_PASSWORD'];
        }
        $email_errors .= "<br>-" . $mod_strings['ERR_RECIPIENT_EMAIL'];
        $email_errors .= "<br>-" . $mod_strings['ERR_SERVER_STATUS'];
        return $email_errors;
    } else {
        return $mod_strings['LBL_EMAIL_NOT_SENT'];
    }
}
Exemple #7
0
 /**
  * Test asserts that body_html has variables after cleanBean call
  *
  * @group 60152
  * @dataProvider dataProvider
  * @return void
  */
 public function testCleanBean($html, $needle)
 {
     $bean = new EmailTemplate();
     $bean->body_html = $html;
     $bean->cleanBean();
     $this->assertContains($needle, $bean->body_html);
 }
Exemple #8
0
 /**
  * @dataProvider xssData
  */
 public function testXssFilterBean($before, $after)
 {
     $bean = new EmailTemplate();
     $bean->body_html = to_html($before);
     $bean->cleanBean();
     $this->assertEquals(to_html($after), $bean->body_html);
 }
 function forgotPasswordMail($argArrPOST)
 {
     $objTemplate = new EmailTemplate();
     $objValid = new Validate_fields();
     $objCore = new Core();
     $objGeneral = new General();
     $objValid->check_4html = true;
     $_SESSION['sessForgotValues'] = array();
     $objValid->add_text_field('Login ID', strip_tags($argArrPOST['frmUserName']), 'text', 'y', 255);
     $objValid->add_text_field('Verification Code', strip_tags($argArrPOST['frmSecurityCode']), 'text', 'y', 255);
     if (!$objValid->validation()) {
         $errorMsg = $objValid->create_msg();
     }
     if ($errorMsg) {
         $_SESSION['sessForgotValues'] = $argArrPOST;
         $objCore->setErrorMsg($errorMsg);
         return false;
     } else {
         if ($_SESSION['security_code'] == $argArrPOST['frmSecurityCode'] && !empty($_SESSION['security_code'])) {
             $varWhereCond = " AND ClientEmailAddress  ='" . $argArrPOST['frmUserName'] . "'";
             $userRecords = $this->getClientNumRows($varWhereCond);
             $userInfo = $this->getClientInfo($varWhereCond);
             if ($userRecords > 0) {
                 $varClientID = $userInfo['0']['pkClientID'];
                 $varMemberData = trim(strip_tags($argArrPOST['frmUserName']));
                 $varForgotPasswordCode = $objGeneral->getValidRandomKey(TABLE_CLIENTS, array('pkClientID'), 'ClientForgotPWCode', '25');
                 $varForgotPasswordLink = '<a href="' . SITE_ROOT_URL . 'clients/reset_password.php?mid=' . $varClientID . '&code=' . $varForgotPasswordCode . '">' . SITE_ROOT_URL . 'clients/reset_password.php?mid=' . $varClientID . '&code=' . $varForgotPasswordCode . '</a>';
                 $arrColumns = array('ClientForgotPWStatus' => 'Active', 'ClientForgotPWCode' => $varForgotPasswordCode);
                 $varWhereCondition = 'pkClientID = \'' . $varClientID . '\'';
                 $this->update(TABLE_CLIENTS, $arrColumns, $varWhereCondition);
                 $varClientEmail = $userInfo[0]['ClientEmailAddress'];
                 $varToUser = $varClientEmail;
                 $varFromUser = SITE_NAME . '<' . $varClientEmail . '>';
                 $varSiteName = SITE_NAME;
                 $varWhereTemplate = ' EmailTemplateTitle= \'Forgot password\' AND EmailTemplateStatus = \'Active\' ';
                 $arrMailTemplate = $objTemplate->getTemplateInfo($varWhereTemplate);
                 $varOutput = html_entity_decode(stripcslashes($arrMailTemplate[0]['EmailTemplateDescription']));
                 $varSubject = html_entity_decode(stripcslashes($arrMailTemplate[0]['EmailTemplateSubject']));
                 $varSubject = str_replace('{PROJECT_NAME}', SITE_NAME, html_entity_decode(stripcslashes($arrMailTemplate['0']['EmailTemplateSubject'])));
                 $varKeyword = array('{IMAGE_PATH}', '{MEMBER}', '{PROJECT_NAME}', '{USER_DATA}', '{FORGOT_PWD_LINK}', '{SITE_NAME}');
                 $varKeywordValues = array($varPathImage, 'Client', SITE_NAME, $varMemberData, $varForgotPasswordLink, SITE_NAME);
                 $varOutPutValues = str_replace($varKeyword, $varKeywordValues, $varOutput);
                 $objCore->sendMail($varToUser, $varFromUser, $varSubject, $varOutPutValues);
                 $_SESSION['sessForgotValues'] = '';
                 $objCore->setSuccessMsg(ADMIN_FORGOT_PASSWORD_CONFIRM_MSG);
                 return true;
             } else {
                 $_SESSION['sessForgotValues'] = $argArrPOST;
                 $objCore->setErrorMsg(EMAIL_NOT_EXIST_MSG);
                 return true;
             }
         } else {
             $_SESSION['sessForgotValues'] = $argArrPOST;
             $objCore->setErrorMsg(INVALID_SECURITY_CODE_MSG);
             return false;
         }
     }
 }
Exemple #10
0
 public function testAssignedUserName()
 {
     global $locale;
     require_once 'include/Localization/Localization.php';
     $locale = new Localization();
     $testName = $locale->getLocaleFormattedName($this->user->first_name, $this->user->last_name);
     $testTemplate = new EmailTemplate();
     $testTemplate->retrieve($this->emailTemplate->id);
     $this->assertEquals($testName, $testTemplate->assigned_user_name, 'Assert that the assigned_user_name is the locale formatted name value');
 }
Exemple #11
0
 /**
  * Testing EmailTemplate::parse_tracker_urls
  * @group 46984
  * @dataProvider templatesProvider
  */
 public function testParseTrackerUrl($data, $expects, $result)
 {
     $et = new EmailTemplate();
     $res = $et->parse_tracker_urls($data[0], $data[1], $data[2], $data[3]);
     if ($result) {
         $this->assertEquals($expects, $res);
     } else {
         $this->assertNotEquals($expects, $res);
     }
 }
 /**
  * Test sending an email that should go out as a processing that this job would typically do.
  * Also tests that item does not get trashed when deleting the WorkflowMessageInQueue.
  * Also tests that if there is more than one emailmessage against the workflow, that it does not send
  * to all of them
  * @depends testWorkflowMessageInQueueProperlySavesWithoutTrashingRelatedModelItem
  */
 public function testRun()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $emailTemplate = new EmailTemplate();
     $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML;
     $emailTemplate->name = 'the name';
     $emailTemplate->modelClassName = 'Account';
     $emailTemplate->type = 2;
     $emailTemplate->subject = 'subject';
     $emailTemplate->textContent = 'sample text content';
     $saved = $emailTemplate->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $model = ContactTestHelper::createContactByNameForOwner('Jason', Yii::app()->user->userModel);
     $model->primaryEmail->emailAddress = '*****@*****.**';
     $saved = $model->save();
     $this->assertTrue($saved);
     $modelId = $model->id;
     $model->forget();
     $model = Contact::getById($modelId);
     $trigger = array('attributeIndexOrDerivedType' => 'firstName', 'operator' => OperatorRules::TYPE_EQUALS, 'durationInterval' => '333');
     $actions = array(array('type' => ActionForWorkflowForm::TYPE_UPDATE_SELF, ActionForWorkflowForm::ACTION_ATTRIBUTES => array('description' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'some new description'))));
     $emailMessages = array();
     $emailMessages[0]['emailTemplateId'] = $emailTemplate->id;
     $emailMessages[0]['sendFromType'] = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
     $emailMessages[0]['sendAfterDurationSeconds'] = '0';
     $emailMessages[0][EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS] = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL, 'audienceType' => EmailMessageRecipient::TYPE_TO));
     $emailMessages[1]['emailTemplateId'] = $emailTemplate->id;
     $emailMessages[1]['sendFromType'] = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
     $emailMessages[1]['sendAfterDurationSeconds'] = '10000';
     $emailMessages[1][EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS] = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL, 'audienceType' => EmailMessageRecipient::TYPE_TO));
     $savedWorkflow = new SavedWorkflow();
     $savedWorkflow->name = 'some workflow';
     $savedWorkflow->description = 'description';
     $savedWorkflow->moduleClassName = 'ContactsModule';
     $savedWorkflow->triggerOn = Workflow::TRIGGER_ON_NEW_AND_EXISTING;
     $savedWorkflow->type = Workflow::TYPE_ON_SAVE;
     $data[ComponentForWorkflowForm::TYPE_TRIGGERS] = array($trigger);
     $data[ComponentForWorkflowForm::TYPE_ACTIONS] = $actions;
     $data[ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES] = $emailMessages;
     $savedWorkflow->serializedData = serialize($data);
     $savedWorkflow->isActive = true;
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     WorkflowTestHelper::createExpiredWorkflowMessageInQueue($model, $savedWorkflow, serialize(array($emailMessages[1])));
     RedBeanModelsCache::forgetAll(true);
     //simulates page change, required to confirm Item does not get trashed
     $this->assertEquals(1, WorkflowMessageInQueue::getCount());
     $job = new WorkflowMessageInQueueJob();
     $this->assertTrue($job->run());
     $this->assertEquals(0, WorkflowMessageInQueue::getCount());
     RedBeanModelsCache::forgetAll(true);
     //simulates page change, required to confirm Item does not get trashed
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
 }
 public function search()
 {
     $emailTemplate = new EmailTemplate('search');
     $emailTemplate->name = 'the name changed';
     $dataProvider = $emailTemplate->search();
     $data = $dataProvider->getData();
     $this->assertEquals($data[0]->name, 'the name changed');
     $this->assertEquals($data[0]->subject, 'the subject changed');
     $this->assertEquals($data[0]->heading, 'the heading changed');
     $this->assertEquals($data[0]->message, 'the message changed');
 }
 /**
  * Create
  */
 public function actionCreate()
 {
     $emailTemplate = new EmailTemplate('create');
     if (isset($_POST['EmailTemplate'])) {
         $emailTemplate->attributes = $_POST['EmailTemplate'];
         if ($emailTemplate->save()) {
             $this->redirect(array('template/view', 'id' => $emailTemplate->id));
         }
     }
     $this->render('create', array('emailTemplate' => $emailTemplate));
 }
 function sendemailVerification($username, $email, $verification_code)
 {
     global $sitename;
     global $logo;
     include 'email_class.php';
     $em = new EmailTemplate();
     $subject = ucfirst($sitename) . " Registration";
     $headers = "From: " . ucwords($sitename) . " <*****@*****.**> \r\n" . 'X-Mailer: PHP/' . phpversion();
     $headers .= 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $email_message = $username . ",<br /><br /> Thank you for your interest in joining our challenges.\n\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\tTo verify your account, please click <a href='http://" . $sitename . "/verify.html?code=" . $verification_code . "'>here</a>.\n\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t<b>" . $sitename . "</b>";
     $emailmessage = $em->get($logo, $sitename, $email_message);
     /*first send to guest */
     $sentmail = mail($email, $subject, $emailmessage, $headers);
 }
Exemple #16
0
 public function postInsert($event)
 {
     // send message to ticket creator and observers
     if (!$this->getSkipNotification()) {
         // to creator
         if ($this->getCreatedBy() != $this->getTicket()->getCreatedBy()) {
             $to = $this->getTicket()->getRealSender() ?: $this->getTicket()->getCreator()->getEmailAddress();
             Email::send($to, Email::generateSubject($this->getTicket()), EmailTemplate::newComment($this));
         }
         // to observers and responsibles
         $usersToNotify = $this->getTicket()->getResponsiblesAndObserversForNotification();
         foreach ($usersToNotify as $user) {
             if ($user->getId() != $this->getCreatedBy() and $user->getId() != $this->getTicket()->getCreatedBy()) {
                 Email::send($user->getEmailAddress(), Email::generateSubject($this->getTicket()), EmailTemplate::newComment($this));
             }
         }
     }
     // send messages to mentioned users
     $mentions = Helpdesk::findMentions($this->getText());
     foreach ($mentions as $mention) {
         if ($mention->getId() != $this->getCreatedBy() and $mention->getId() != $this->getTicket()->getCreatedBy()) {
             Email::send($mention->getEmailAddress(), Email::generateSubject($this->getTicket()), EmailTemplate::newComment($this, 'mention'));
             $observingAlready = Doctrine_Query::create()->from('RefTicketObserver ref')->addWhere('ref.user_id = ?', $mention->getId())->addWhere('ref.ticket_id = ?', $this->getTicket()->getId())->count() !== 0;
             $isResponsible = Doctrine_Query::create()->from('RefTicketResponsible ref')->addWhere('ref.user_id = ?', $mention->getId())->addWhere('ref.ticket_id = ?', $this->getTicket()->getId())->count() !== 0;
             if (!$observingAlready and !$isResponsible) {
                 $observeRecord = RefTicketObserver::createFromArray(['user_id' => $mention->getId(), 'ticket_id' => $this->getTicket()->getId()]);
                 // workaround for mentions in comments created from email
                 if (!sfContext::getInstance()->getUser()->getGuardUser()) {
                     $observeRecord->setCreatedBy($this->getCreatedBy());
                 }
                 $observeRecord->save();
             }
         }
     }
 }
Exemple #17
0
 /**
  * Check for orders without carrier chosen
  *
  * @return int
  */
 public function actionCheckPostponedOrders()
 {
     echo "Finding postponed orders..." . PHP_EOL;
     /** @var Order[] $orders */
     $orders = Order::model()->getPostponedOrders();
     $ordersCount = count($orders);
     Yii::log(sprintf("Found %s delayed %s" . PHP_EOL, $ordersCount, $this->pluralize('order', $ordersCount)), CLogger::LEVEL_ERROR, 'email_notification');
     foreach ($orders as $order) {
         Yii::log(sprintf("Sending notification email about postponed Order #%s to User #%s %s <%s>", $order->id, $order->creator_id, $order->creator->fullname, $order->creator->email), CLogger::LEVEL_INFO, 'email_notification');
         /** @var SwiftMailer $mailer */
         $mailer = Yii::app()->mailer;
         /** @var EmailTemplate $emailTemplateModel */
         $emailTemplateModel = EmailTemplate::model();
         $template = $emailTemplateModel->getEmailTemplateBySlug(EmailTemplate::TEMPLATE_ORDER_DELAYED);
         $replacements = [$order->creator->email => ['{{order}}' => CHtml::link('#' . $order->id, Yii::app()->createAbsoluteUrl('order/view', ['id' => $order->id]))]];
         if ($template) {
             $mailer->setSubject($template->subject)->setBody($template->body)->setTo($order->creator->email)->setDecoratorReplacements($replacements)->send();
         } else {
             Yii::log("Email template not found!", CLogger::LEVEL_ERROR, 'email_notification');
             return 1;
         }
     }
     echo "Done!" . PHP_EOL;
     return 0;
 }
 /**
  * Show / process email template form
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if ($this->active_template->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $locale = $this->request->get('locale', null);
     $template_data = $this->request->post('template');
     if (!is_array($template_data)) {
         $template_data = array('subject' => $this->active_template->getSubject($locale), 'body' => $this->active_template->getBody($locale));
     }
     // if
     $template_variables = $this->active_template->getVariables() ? explode("\n", $this->active_template->getVariables()) : null;
     $this->smarty->assign(array('template_data' => $template_data, 'template_variables' => $template_variables, 'locale' => $locale));
     if ($this->request->isSubmitted()) {
         if ($locale) {
             $this->active_template->writeLocaleProperties(array_var($template_data, 'subject'), array_var($template_data, 'body'), $locale);
         } else {
             $this->active_template->setAttributes($template_data);
         }
         // if
         $save = $this->active_template->save();
         if ($save && !is_error($save)) {
             flash_success('Email template has been updated');
             $this->redirectToUrl($this->active_template->getUrl());
         } else {
             $this->smarty->assign('errors', $save);
         }
         // if
     }
     // if
 }
Exemple #19
0
 public function postInsert($event)
 {
     $company = $this->getCreator()->getGroups()->getFirst();
     // notify it-admins
     if ($company) {
         $subject = Email::generateSubject($this);
         $text = 'Заявка от компании ' . $company->getName() . ', пользователь ' . $this->getCreator()->getUsername() . PHP_EOL . 'http://helpdesk.f1lab.ru/tickets/' . $this->getId();
         // sms
         if (true == ($notify = $company->getNotifySms())) {
             $phones = [];
             foreach ($notify as $user) {
                 if ($user->getPhone()) {
                     $phones[] = $user->getPhone();
                 }
             }
             Sms::send($phones, $text);
         }
         // email
         if (true == ($notify = $company->getNotifyEmail())) {
             $emails = [];
             foreach ($notify as $user) {
                 if ($user->getEmailAddress()) {
                     $emails[] = $user->getEmailAddress();
                 }
             }
             Email::send($emails, $subject, $text);
         }
     }
     // send email to creator
     $to = $this->getRealSender() ?: $this->getCreator()->getEmailAddress();
     Email::send($to, Email::generateSubject($this), EmailTemplate::newTicket($this));
 }
 protected function makeBuilderPredefinedEmailTemplate($name, $unserializedData, $subject = null, $modelClassName = null, $language = null, $type = null, $isDraft = 0, $textContent = null, $htmlContent = null)
 {
     $emailTemplate = new EmailTemplate();
     $emailTemplate->type = $type;
     //EmailTemplate::TYPE_WORKFLOW;
     $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_BUILDER_TEMPLATE;
     $emailTemplate->isDraft = $isDraft;
     $emailTemplate->modelClassName = $modelClassName;
     $emailTemplate->name = $name;
     if (empty($subject)) {
         $subject = $name;
     }
     $emailTemplate->subject = $subject;
     if (!isset($language)) {
         $language = Yii::app()->languageHelper->getForCurrentUser();
     }
     $emailTemplate->language = $language;
     $emailTemplate->htmlContent = $htmlContent;
     $emailTemplate->textContent = $textContent;
     $emailTemplate->serializedData = CJSON::encode($unserializedData);
     $emailTemplate->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
     $saved = $emailTemplate->save(false);
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $emailTemplate = EmailTemplate::getById($emailTemplate->id);
     ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($emailTemplate, Group::getByName(Group::EVERYONE_GROUP_NAME));
     $saved = $emailTemplate->save(false);
     assert('$saved');
 }
 /**
  * @param EmailTemplateWizardForm $formModel
  */
 protected function setUncommonAttributes(EmailTemplateWizardForm $formModel)
 {
     // handle any custom mappings between EmailTemplateWizardForm and EmailTemplate model here.
     if ($this->emailTemplate->isBuilderTemplate()) {
         $unserializedData = CJSON::decode($this->emailTemplate->serializedData);
         $formModel->baseTemplateId = $unserializedData['baseTemplateId'];
     }
 }
 public function loadModel($id)
 {
     $model = EmailTemplate::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('emailTemplate', 'The requested page does not exist.'));
     }
     return $model;
 }
function install_aoe()
{
    require_once 'modules/Administration/Administration.php';
    require_once 'modules/EmailTemplates/EmailTemplate.php';
    $emailTemp = new EmailTemplate();
    //$emailTemp->id = '7b618b3d-913b-6d2d-6bfb-519f7948a271';
    $emailTemp->date_entered = '2013-05-24 14:31:45';
    $emailTemp->date_modified = '2013-05-30 14:37:12';
    $emailTemp->name = 'Event Invite Template';
    $emailTemp->description = 'Default event invite template.';
    $emailTemp->published = 'off';
    $emailTemp->subject = "You have been invited to \$fp_events_name";
    $emailTemp->body = "Dear \$contact_name,\r\nYou have been invited to \$fp_events_name on \$fp_events_date_start to \$fp_events_date_end\r\n\$fp_events_description\r\nYours Sincerely,\r\n";
    $emailTemp->body_html = "\n<p>Dear \$contact_name,</p>\n<p>You have been invited to \$fp_events_name on \$fp_events_date_start to \$fp_events_date_end</p>\n<p>\$fp_events_description</p>\n<p>If you would like to accept this invititation please click accept.</p>\n<p> \$fp_events_link or \$fp_events_link_declined</p>\n<p>Yours Sincerely,</p>\n";
    $emailTemp->type = 'email';
    $emailTemp->save();
}
 function updateUser($bean, $event, $arguments)
 {
     if (isset($bean->joomla_account_access) && $bean->joomla_account_access != '') {
         global $sugar_config;
         $aop_config = $sugar_config['aop'];
         $template = new EmailTemplate();
         $template->retrieve($aop_config['joomla_account_creation_email_template_id']);
         $object_arr['Contacts'] = $bean->id;
         $body_html = aop_parse_template($template->body_html, $object_arr);
         $body_html = str_replace("\$joomla_pass", $bean->joomla_account_access, $body_html);
         $body_html = str_replace("\$portal_address", $aop_config['joomla_url'], $body_html);
         $body_plain = aop_parse_template($template->body, $object_arr);
         $body_plain = str_replace("\$joomla_pass", $bean->joomla_account_access, $body_plain);
         $body_plain = str_replace("\$portal_address", $aop_config['joomla_url'], $body_plain);
         $this->sendEmail($bean->email1, $template->subject, $body_html, $body_plain, $bean);
     }
 }
 public function action()
 {
     if (isset($_POST['action']['save'])) {
         $fields = $_POST['fields'];
         $et = new EmailTemplate();
         $et->subject = $fields['subject'];
         $et->type = $fields['type'];
         $et->body = $fields['body'];
         if (isset($fields['roles']) && strlen(trim($fields['roles'])) > 0) {
             $roles = preg_split('/\\s*,\\s*/i', $fields['roles'], -1, PREG_SPLIT_NO_EMPTY);
             foreach ($roles as $r) {
                 $et->addRoleFromName($r);
             }
         }
         EmailTemplate::save($et);
         redirect(extension_members::baseURL() . 'email_templates_edit/' . $et->id . '/created/');
     }
 }
Exemple #26
0
 /**
  * sharedTemplates()
  * Returns a query object of all the shared templates by default excluding the shared templates authored by the current user.
  * @param bool $showall
  * @return mixed
  */
 public static function sharedTemplates($showall = FALSE)
 {
     if ($showall) {
         $query = EmailTemplate::where('public', '=', '1')->orderBy('name', 'ASC')->get();
     } else {
         $query = EmailTemplate::where('public', '=', '1')->where('author', '!=', Auth::consoleuser()->get()->cid)->orderBy('name', 'ASC')->get();
     }
     return $query;
 }
 /**
  * @param $partialName
  * @param $pageSize
  * @param null|string $moduleClassName
  * @param null|string $type
  * @return Array of SavedReport models
  */
 public static function getEmailTemplatesByPartialName($partialName, $pageSize, $modelClassName = null, $type = null)
 {
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => intval($type)), 2 => array('attributeName' => 'modelClassName', 'operatorType' => 'equals', 'value' => $modelClassName), 3 => array('attributeName' => 'isDraft', 'operatorType' => 'equals', 'value' => intval(false)), 4 => array('attributeName' => 'name', 'operatorType' => 'contains', 'value' => $partialName));
     $searchAttributeData['structure'] = '1 and 2 and 3 and 4';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailTemplate');
     $where = RedBeanModelDataProvider::makeWhere('EmailTemplate', $searchAttributeData, $joinTablesAdapter);
     return EmailTemplate::getSubset($joinTablesAdapter, null, $pageSize, $where, 'name');
 }
Exemple #28
0
function local_course_notification_cron()
{
    global $DB;
    $runtime = time();
    echo "Running course notification cron at " . date('D M Y h:m:s', $runtime) . "\n";
    // Generate automatic reports.
    // Training reaching lifetime/expired.
    if ($checkcourses = $DB->get_records_sql('SELECT * from {local_course_notification} where expiryduration!=0')) {
        // We have some courses which we need to check against.
        foreach ($checkcourses as $checkcourse) {
            $course = $DB->get_record('course', array('id' => $checkcourse->courseid));
            if (!$course->visible) {
                // Don not send course notification for inactive course
                continue;
            }
            $expiredtext = "";
            $expiringtext = "";
            $latetext = "";
            echo "Get completion information for course: {$checkcourse->courseid} of company: {$checkcourse->companyid} \n";
            $sql = 'SELECT cc.* FROM {course_completions} cc' . ' JOIN {company_users} cu ON cu.userid = cc.userid ' . 'WHERE cc.course=:courseid AND cu.companyid = :companyid';
            $company = $DB->get_record('company', array('id' => $checkcourse->companyid, 'suspended' => 0));
            if (!$company) {
                echo "Either Company not exist or suspended";
                continue;
            }
            if ($coursecompletions = $DB->get_records_sql($sql, array('courseid' => $checkcourse->courseid, 'companyid' => $checkcourse->companyid))) {
                print_object($coursecompletions);
                // Get the course information.
                foreach ($coursecompletions as $completion) {
                    if (!empty($completion->timeenrolled) && empty($completion->timecompleted)) {
                        $user = $DB->get_record('user', array('id' => $completion->userid));
                        // Send course overdue email to user
                        /* echo "current time:-" . $runtime;
                           echo "<br>Timeenrol:-" . $completion->timeenrolled;
                           echo "<br>expiryduration:-" . $checkcourse->expiryduration;
                           echo "<br>warnexpire:-" . $checkcourse->warnexpire;
                           echo "warncourseoverdue:-" . $checkcourse->warncourseoverdue; */
                        if ($checkcourse->warncourseoverdue && $completion->timeenrolled + $checkcourse->expiryduration < $runtime && $runtime <= $completion->timeenrolled + $checkcourse->expiryduration + $checkcourse->warncourseoverdue) {
                            echo "<br>Sending course overdue email to {$user->email} \n";
                            EmailTemplate::send('expire', array('course' => $course, 'user' => $user));
                            /*$expiredtext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' .
                              date('D M Y', $completion->timecompleted) . "\n";*/
                        } else {
                            if ($checkcourse->warnexpire && $completion->timeenrolled + $checkcourse->expiryduration <= $checkcourse->warnexpire + $runtime && $completion->timeenrolled + $checkcourse->expiryduration > $runtime) {
                                echo "<br>Sending expiry warning email to {$user->email} \n";
                                EmailTemplate::send('expiry_warn_user', array('course' => $course, 'user' => $user));
                                /*$expiringtext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' .
                                  date('D M Y', $completion->timecompleted) . "\n";*/
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**
  * Update the specified emailtemplate in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $emailtemplate = EmailTemplate::findOrFail($id);
     $validator = Validator::make($data = Input::all(), EmailTemplate::rules($id));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $emailtemplate->update($data);
     return Redirect::route('admin.templates.index')->with("message", "Data berhasil disimpan");
 }
 function SendMail($to, $from, $message, $username, $username_from)
 {
     global $sitename;
     global $logo;
     include 'email_class.php';
     $em = new EmailTemplate();
     $subject = ucfirst($sitename) . " Challenge Sponsorship";
     $headers = "From: " . $username_from . " " . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
     $headers .= 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $email_message = "Hi " . $username . ",<br /><br /> " . ucfirst($username_from) . " has submitted sponsorship. And sent the message:\n\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t{$message}\n\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t<b>" . $sitename . "</b>";
     $emailmessage = $em->get($logo, $sitename, $email_message);
     /*first send to guest */
     if (mail($to, $subject, $emailmessage, $headers)) {
         return true;
     } else {
         return false;
     }
 }