예제 #1
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;
 }
 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;
 }
 public function update()
 {
     $emailTemplate = EmailTemplate::model()->findByPk($this->emailTemplate->id);
     $emailTemplate->name = 'the name changed';
     $emailTemplate->subject = 'the subject changed';
     $emailTemplate->heading = 'the heading changed';
     $emailTemplate->message = 'the message changed';
     $save = $emailTemplate->save();
     $this->assertTrue($save);
     $this->codeGuy->seeInDatabase('email_template', array('name' => 'the name changed', 'subject' => 'the subject changed', 'heading' => 'the heading changed', 'message' => 'the message changed'));
 }
예제 #4
0
 public function actionReply($id)
 {
     $model = $this->loadModel($id);
     $model->scenario = 'replyFeedback';
     if (isset($_POST['Manager'])) {
         $managerPhone = isset($_POST['Manager']['phone']) ? $_POST['Manager']['phone'] : NULL;
         $model->template = isset($_POST['Feedback']['template']) ? $_POST['Feedback']['template'] : NULL;
         if (isset($_POST['Feedback']['variables'])) {
             foreach ($_POST['Feedback']['variables'] as $key => $var) {
                 $model->variables[$key] = isset($_POST['Feedback']['variables'][$key]) ? strip_tags($_POST['Feedback']['variables'][$key]) : NULL;
             }
         }
         if ($model->validate('template', 'variables')) {
             $modelEmailTemplate = EmailTemplate::model()->findByPK($model->template);
             if ($modelEmailTemplate !== NULL) {
                 $manager = User::model()->find(Yii::app()->user->id);
                 $managerName = $manager->first_name . ' ' . $manager->last_name;
                 $managerEmail = $manager->email;
                 $clientEmail = $model->email;
                 $final_array = Yii::app()->extraFunctions->emailSendArray($modelEmailTemplate->description, $model->variables);
                 //replace varibles
                 if (!empty($managerPhone)) {
                     $appendContent = '<br/><p>Nếu quý khách cần tư vấn trực tiếp, vui lòng liên lạc qua số điện thoại:<strong> ' . $managerPhone . '</strong></p>';
                     $final_array .= $appendContent;
                 }
                 $send_mail_data = array('subject' => $modelEmailTemplate->subject, 'firstName' => ucwords($model->name), 'content' => $final_array);
                 $message = $this->renderPartial('//site/_emailTemplate', $send_mail_data, true);
                 //call a template view
                 $result = Yii::app()->extraFunctions->sendEmail($clientEmail, $modelEmailTemplate->subject, $message, $model->name, $managerEmail);
                 //send mail
                 if ($result) {
                     Feedback::model()->updateStatus($id, 0);
                 }
             } else {
                 Yii::app()->user->setFlash('error', Yii::t('backend', 'Your request failed. Please contact administrators.'));
             }
             $this->redirect(array('/' . backend . '/feedback/reply', 'id' => $id));
         }
     }
     $this->render(strtolower($this->action->id), array('model' => $model));
 }
예제 #5
0
 /**
  * Send mail
  *
  * @return mixed
  */
 public function sendNotification()
 {
     /** @var OrderBids $orderBid */
     $orderBid = $this->sender;
     $currentUser = $this->controller->acl->getUser();
     /** @var SwiftMailer $mailer */
     $mailer = $this->getMailer();
     $orderAbsoluteUrl = Yii::app()->createAbsoluteUrl('order/view', ['id' => $orderBid->id]);
     $emailTemplate = $this->getTemplate();
     if ($emailTemplate) {
         $mailer->setSubject($emailTemplate->subject)->setBody($emailTemplate->body);
         $replacements = [];
         $users = [$orderBid->user->email];
         $mailer->addAddress($users);
         foreach ($users as $email) {
             $replacements[$email] = ['{{order}}' => CHtml::link('#' . $orderBid->id, $orderAbsoluteUrl), '{{carrier}}' => CHtml::link($orderBid->user->fullname, Yii::app()->createAbsoluteUrl('user/view', ['id' => $currentUser->id])), '{{reason}}' => $this->form->reason, '{{bids_url}}' => CHtml::link(Yii::app()->createAbsoluteUrl('orderBids/index'), Yii::app()->createAbsoluteUrl('orderBids/index', ['orderId' => $orderBid->order_id]))];
         }
         $mailer->setDecoratorReplacements($replacements)->send();
         Yii::log(sprintf('Sent email notification about withdrawn order bid for order #%s by user #%s. Reason: %s', $orderBid->order_id, $orderBid->user_id, $this->form->reason));
     } else {
         Yii::log(sprintf('Failed to send notification. Not found template %s', $this->getTemplateName()), CLogger::LEVEL_ERROR);
     }
     $supervisorEmailTemplate = EmailTemplate::model()->findByAttributes(['slug' => $this->getSupervisorTemplateName()]);
     if ($supervisorEmailTemplate) {
         $mailer->setSubject($supervisorEmailTemplate->subject)->setBody($supervisorEmailTemplate->body);
         $users = [];
         $supervisors = User::model()->findAllSupervisors();
         $replacements = [];
         foreach ($supervisors as $supervisor) {
             $users[] = $supervisor->email;
         }
         $mailer->addAddress($users);
         foreach ($users as $email) {
             $replacements[$email] = ['{{order}}' => CHtml::link('#' . $orderBid->id, $orderAbsoluteUrl), '{{carrier}}' => CHtml::link($orderBid->user->fullname, Yii::app()->createAbsoluteUrl('user/view', ['id' => $currentUser->id])), '{{reason}}' => $this->form->reason, '{{currency}}' => $orderBid->order->currency->title, '{{cost}}' => $orderBid->cost, '{{bids_number}}' => $orderBid->order->orderBidsCount, '{{bids_url}}' => CHtml::link(Yii::app()->createAbsoluteUrl('orderBids/index'), Yii::app()->createAbsoluteUrl('orderBids/index', ['orderId' => $orderBid->order_id]))];
         }
         $mailer->setDecoratorReplacements($replacements)->send();
     } else {
         Yii::log(sprintf('Failed to send notification. Not found template %s', $this->getSupervisorTemplateName()), CLogger::LEVEL_ERROR);
     }
 }
예제 #6
0
 /**
  * @param $template string
  * @param $viewParams array
  * @param string $layout
  * @throws CException
  * @return array
  */
 private function buildTemplateMessage_db($template, $viewParams = array(), $layout = null)
 {
     // load template
     $emailTemplate = EmailTemplate::model()->findByAttributes(array('name' => $template));
     if (!$emailTemplate) {
         throw new CException('missing EmailTemplate - ' . $template);
     }
     // load layout
     $emailLayout = $layout ? EmailTemplate::model()->findByAttributes(array('name' => $layout)) : false;
     if ($layout && !$emailLayout) {
         throw new CException('missing EmailTemplate - ' . $layout);
     }
     // parse template
     $message = array();
     Yii::setPathOfAlias('mustache', realpath($this->mustachePath));
     Yii::import('mustache.Mustache');
     $mustache = new Mustache_Engine();
     foreach ($this->templateFields as $field) {
         $viewParams['contents'] = $mustache->render($emailTemplate->{$field}, $viewParams);
         if (!$layout) {
             $viewParams[$field] = $message[$field] = $viewParams['contents'];
         } else {
             $viewParams[$field] = $message[$field] = $mustache->render($emailLayout->{$field}, $viewParams);
         }
         unset($viewParams['contents']);
     }
     return $message;
 }
예제 #7
0
 protected function beforeSave()
 {
     $this->user_id = Yii::app()->user->id;
     //Смотрим, определен ли шаблон, если определен - используем
     if (!empty($this->template_id) && ($model_template = EmailTemplate::model()->findByPk($this->template_id))) {
         $this->body = str_replace('%email_body%', $this->body, $model_template->body);
     }
     Yii::app()->mailer->send(array('email' => $this->to_email, 'subject' => $this->title, 'body' => $this->body));
     $this->status = 1;
     $this->send_date = date('Y-m-d h:m:s');
     return true;
 }
예제 #8
0
                                    <?php 
echo CHtml::label(Yii::t('feedback', 'Phone'), 'phone', array('style' => 'padding-right:23px', 'class' => 'control-label col-lg-2'));
?>
                                    <div class="col-lg-10">
                                        <?php 
echo CHtml::textField('Manager[phone]', '', array('size' => 30, 'maxlength' => 255, 'class' => 'form-control', 'placeholder' => 'If you want to reply via phone number.'));
?>

                                        <?php 
//echo CHtml::error('Phone', 'phone');
?>
                                    </div>
                                </div>

                                <?php 
$listTemplates = EmailTemplate::model()->findAll('status=1 AND autoload=0');
?>
                                <div class="form-group">
                                    <?php 
echo $form->labelEx($model, 'template', array('style' => 'padding-right:23px', 'class' => 'control-label col-lg-2'));
?>
                                    <div class="col-lg-10">
                                        <?php 
echo $form->dropDownList($model, 'template', CHtml::listData($listTemplates, 'id', 'name'), array('empty' => Yii::t('feedback', '--- Select an email template ---'), 'class' => 'form-control'));
?>

                                        <?php 
echo $form->error($model, 'template');
?>
                                    </div>
                                </div>
예제 #9
0
echo Yii::t("Bootstrap", "PHRASE.FIELDS_REQUIRED");
?>
</p>-->

	<?php 
echo $form->errorSummary($model);
?>

<?php 
/* echo $form->dropDownListRow($model, "user_id",
       CHtml::listData( User::model()->findAll(), "id", "title"),
       array("empty" => "Не выбран")
   ); */
echo $form->textFieldRow($model, 'to_email', array('class' => 'span5', 'maxlength' => 250));
echo $form->textFieldRow($model, 'title', array('class' => 'span5', 'maxlength' => 250));
echo $form->dropDownListRow($model, 'template_id', CHtml::listData(EmailTemplate::model()->findAll(), "id", "name"), array("empty" => "Не выбран", 'class' => 'span5'));
?>

<?php 
//$model->body="sssssss!";
Yii::import('ext.imperavi-redactor-widget-master.ImperaviRedactorWidget');
$this->widget('ImperaviRedactorWidget', array('model' => $model, 'attribute' => 'body', 'options' => array('lang' => 'ru', 'imageUpload' => Yii::app()->createAbsoluteUrl('/messages/messages/imageUpload')), 'plugins' => array('fullscreen' => array('js' => array('fullscreen.js')), 'video' => array('js' => array('video.js')), 'table' => array('js' => array('table.js')), 'fontcolor' => array('js' => array('fontcolor.js')), 'fontfamily' => array('js' => array('fontfamily.js')), 'fontsize' => array('js' => array('fontsize.js')))));
?>

<?php 
/*
echo $form->DatePickerRow($model, 'created_at', array(
				'options'=>array(
					'autoclose' => true,
					//'showAnim'=>'fold',
					'type' => 'Component',
예제 #10
0
 public function findEMailTempalte($name)
 {
     return EmailTemplate::model()->find("name='" . $name . "' AND status='1'");
 }
예제 #11
0
 /**
  * @return EmailTemplate
  */
 public function getTemplate()
 {
     $emailTemplate = EmailTemplate::model()->findByAttributes(['slug' => $this->getTemplateName()]);
     return $emailTemplate;
 }
 /**
  * Delete Email Template action
  */
 public function actionDelete()
 {
     // Check Access
     checkAccessThrowException('op_emailtemplate_delete');
     if (isset($_GET['id']) && ($model = EmailTemplate::model()->findByPk($_GET['id']))) {
         alog(at("Deleted Email Template '{name}'.", array('{name}' => $model->title)));
         $model->delete();
         fok(at('Email Template Deleted.'));
         $this->redirect(array('emailtemplate/index'));
     } else {
         $this->redirect(array('emailtemplate/index'));
     }
 }
예제 #13
0
 public function actionSendMailResetPassword()
 {
     if (isset($_POST['ForgotPasswordForm'])) {
         $model = new ForgotPasswordForm();
         $model->attributes = $_POST['ForgotPasswordForm'];
         if ($model->validate()) {
             $modelBarcode = new UserBarcode();
             $modelBarcode->id = UserBarcode::model()->getMaxId() + 1;
             $modelEmailTemplate = EmailTemplate::model()->findEMailTempalte('User Reset Password');
             $modelUser = User::model()->findByAttributes(array('email' => $model->emailReset));
             $modelBarcode->barcode = Yii::app()->extraFunctions->randomString(32);
             if ($modelEmailTemplate !== NULL && $modelUser !== NULL) {
                 $description = $modelEmailTemplate->description;
                 $subject = $modelEmailTemplate->subject;
                 $variables = array('{link}' => CHtml::link(Yii::app()->createAbsoluteUrl('site/resetPassword', array('barcodeId' => $modelBarcode->id)), Yii::app()->createAbsoluteUrl('site/resetPassword', array('barcodeId' => $modelBarcode->id))), '{barcode}' => $modelBarcode->barcode);
                 $final_array = Yii::app()->extraFunctions->emailSendArray($description, $variables);
                 //replace varibles
                 $send_mail_data = array('subject' => $subject, 'firstName' => ucwords($modelUser->first_name), 'content' => $final_array);
                 $message = $this->renderPartial('_emailTemplate', $send_mail_data, true);
                 //call a template view
                 $result = Yii::app()->extraFunctions->sendEmail($modelUser->email, $subject, $message, $modelUser->first_name . ' ' . $modelUser->last_name);
                 //send mail
                 if ($result === TRUE) {
                     $modelBarcode->userid = $modelUser->id;
                     $modelBarcode->start_time = date('Y-m-d H:i:s');
                     $temp_startTime = Yii::app()->extraFunctions->getFormatDate($modelBarcode->start_time);
                     $modelBarcode->end_time = Yii::app()->extraFunctions->getEndTime($temp_startTime, 1);
                     $modelBarcode->action = 'resetPassword';
                     $modelBarcode->save();
                 }
             } else {
                 Yii::app()->user->setFlash('error', Yii::t('backend', 'Your request failed. Please contact administrators.'));
             }
             $this->redirect(array('site/login'));
         } else {
             Yii::app()->user->setFlash('error', Yii::t('backend', 'Your email has not registered in our system.'));
             $this->redirect('login');
         }
     }
 }
예제 #14
0
 public function actionView($template_id, $group_id, $campaign_id)
 {
     $this->layout = '/layouts/vanilla';
     $fromEmailDomain = Yii::app()->params['insiderEmailDomain'];
     $testEmailInvalid = false;
     $EmailTemplate = EmailTemplate::model()->findByPK($template_id);
     if (is_null($EmailTemplate)) {
         throw new CHttpException(404, 'Unable to find template.');
     }
     $CampaignGroup = CampaignGroup::model()->with(array('campaign'))->findByPK($group_id);
     if (is_null($CampaignGroup)) {
         throw new CHttpException(404, 'Unable to find campaign group.');
     }
     if (isset($_POST['delete'])) {
         $path = dirname(Yii::app()->request->scriptFile) . '/templates/' . $EmailTemplate->folder;
         $this->deleteDir($path);
         $EmailTemplate->delete();
         $this->redirect(array('emailTemplate/create', 'campaign_id' => $campaign_id, 'group_id' => $group_id));
     }
     //send a test email
     if (isset($_POST['EmailTemplate']['email_test_recipient']) && $_POST['EmailTemplate']['email_test_recipient']) {
         $insiderEmailDomain = 'abc123.mailgun.org';
         $mailgunApiVerify = new MailgunCampaign($fromEmailDomain, Yii::app()->params['mailgun']['public-key']);
         try {
             $emails = explode(',', $_POST['EmailTemplate']['email_test_recipient']);
             foreach ($emails as $key => $email) {
                 $emails[$key] = trim($email);
                 $validEmailResponse = $mailgunApiVerify->validateEmailAddress($emails[$key]);
                 if ($validEmailResponse['is_valid'] != true) {
                     unset($emails[$key]);
                 }
             }
             if (sizeof($emails)) {
                 // send it
                 foreach ($emails as $key => $email) {
                     $mailgunApi = new MailgunCampaign($fromEmailDomain, Yii::app()->params['mailgun']['key']);
                     $message = $mailgunApi->newMessage();
                     $message->setFrom('email@' . $fromEmailDomain, 'Application Name');
                     $message->addTo($email);
                     $html = $EmailTemplate->exampleEmail;
                     $html = preg_replace("@%recipient.warehouse_id%@", '000', $html);
                     foreach ($CampaignGroup->campaign->outcomes as $Outcome) {
                         if (strlen($Outcome->url)) {
                             $html = preg_replace("@%recipient.outcome_" . $Outcome->id . "%@", $Outcome->url, $html);
                         }
                     }
                     $message->setHtml($html);
                     $message->setSubject($CampaignGroup->subject);
                     $message->send();
                 }
                 Yii::app()->user->setFlash('success', "Emails sent to " . implode(', ', $emails) . '.');
             } else {
                 Yii::app()->user->setFlash('danger', 'No valid email addresses found to send to');
             }
             $this->refresh();
         } catch (Exception $e) {
             var_dump($e);
             exit;
             $testEmailInvalid = true;
         }
     }
     //check template for first_name
     if (stripos($EmailTemplate->html, '%recipient.first_name%') === false) {
         $EmailTemplate->addNotice('Are you aware that the template.html file does not have a recipient first name tag?: "%recipient.first_name%');
     }
     //check template for last_name
     if (stripos($EmailTemplate->html, '%recipient.last_name%') === false) {
         $EmailTemplate->addNotice('Are you aware that the template.html file does not have a recipient last name tag?: "%recipient.last_name%');
     }
     //check we have an email subject
     if (!strlen($CampaignGroup->subject)) {
         $EmailTemplate->addNotice('You have not set an email subject for this group.');
     }
     //check for outcomes in the template
     preg_match_all("/%recipient.outcome_(\\d+)%/", $EmailTemplate->html, $outcomes);
     if (!sizeof($outcomes[0])) {
         $EmailTemplate->addNotice('Are you aware there are no outcome tags in the template?');
     } else {
         foreach ($outcomes[0] as $tag) {
             $EmailTemplate->addNotice('We found the following tag in your template: ' . $tag);
         }
     }
     $this->breadcrumbs = array('Campaigns' => array('campaign/index'), $CampaignGroup->campaign->name => array('campaign/createUpdate', 'id' => $CampaignGroup->campaign_id), 'Group ' . $CampaignGroup->name => array('campaignGroup/update', 'id' => $CampaignGroup->id, 'campaign_id' => $CampaignGroup->campaign_id), 'View Email Template');
     $this->render('view', array('EmailTemplate' => $EmailTemplate, 'subject' => $CampaignGroup->subject, 'has_ran' => $CampaignGroup->campaign->hasBeenRun, 'testEmailInvalid' => $testEmailInvalid));
 }
예제 #15
0
<legend><?php 
echo Yii::t("Bootstrap", "LIST.EmailTemplate");
?>
</legend>

<?php 
$assetsDir = Yii::app()->basePath;
$labels = EmailTemplate::model()->attributeLabels();
echo '<a href="/admin/' . Yii::app()->controller->module->id . '/' . Yii::app()->controller->id . '/create" class="btn" style="margin-bottom:20px;">Добавить</a>';
$this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'email-template-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $model->search(), 'filter' => null, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => $labels["name"], 'name' => "name"), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update}  {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap')))));