Example #1
0
 /**
  * @param <array of strings> comma separated recipient addresses
  * @return array error flag and message
  */
 protected function checkDoNotEmailFields(InlineEmail $eml)
 {
     if (Yii::app()->settings->x2FlowRespectsDoNotEmail && !$eml->checkDoNotEmailFields()) {
         return array(false, Yii::t('studio', 'Email could not be sent because at least one of the ' . 'addressees has their "Do not email" attribute checked'));
     }
     return array(true, '');
 }
Example #2
0
 public function execute(&$params)
 {
     $eml = new InlineEmail();
     // make subject optional in order to support legacy flows
     $eml->requireSubjectOnCustom = false;
     $options =& $this->config['options'];
     $eml->to = $this->parseOption('to', $params);
     $historyFlag = false;
     if (isset($params['model'])) {
         $historyFlag = true;
         $eml->targetModel = $params['model'];
     }
     if (isset($options['cc']['value'])) {
         $eml->cc = $this->parseOption('cc', $params);
     }
     if (isset($options['bcc']['value'])) {
         $eml->bcc = $this->parseOption('bcc', $params);
     }
     //$eml->from = array('address'=>$this->parseOption('from',$params),'name'=>'');
     $eml->credId = $this->parseOption('from', $params);
     if ($eml->credentials && $eml->credentials->user) {
         $eml->setUserProfile($eml->credentials->user->profile);
     }
     //printR ($eml->from, true);
     $eml->subject = $this->parseOption('subject', $params);
     // "body" option (deliberately-entered content) takes precedence over template
     if (isset($options['body']['value']) && !empty($options['body']['value'])) {
         $eml->scenario = 'custom';
         $eml->message = InlineEmail::emptyBody($this->parseOption('body', $params));
         $prepared = $eml->prepareBody();
         // $eml->insertSignature(array('<br /><br /><span style="font-family:Arial,Helvetica,sans-serif; font-size:0.8em">','</span>'));
     } elseif (!empty($options['template']['value'])) {
         $eml->scenario = 'template';
         $eml->template = $this->parseOption('template', $params);
         $prepared = $eml->prepareBody();
     } else {
         $prepared = true;
         // no email body
     }
     if (!$prepared) {
         // InlineEmail failed validation
         $errors = $eml->getErrors();
         return array(false, array_shift($errors));
     }
     list($success, $message) = $this->checkDoNotEmailFields($eml);
     if (!$success) {
         return array($success, $message);
     }
     $result = $eml->send($historyFlag);
     if (isset($result['code']) && $result['code'] == 200) {
         if (YII_UNIT_TESTING) {
             return array(true, $eml->message);
         } else {
             return array(true, "");
         }
     } else {
         return array(false, Yii::t('app', "Email could not be sent"));
     }
 }
Example #3
0
 public function testActionHeader()
 {
     $this->eml = new InlineEmail('template');
     $template = $this->docs('testEmailTemplate');
     $this->eml->template = $template->id;
     $this->eml->modelId = $this->contacts('testAnyone')->id;
     $this->eml->modelName = 'Contacts';
     $this->eml->subject = 'Test Email Subject';
     $this->eml->from = array('name' => 'Sales Rep', 'address' => '*****@*****.**');
     $this->eml->to = '"Testfirstname Testlastname" <*****@*****.**>';
     $this->eml->prepareBody();
     $record = $this->eml->insertInBody($this->eml->actionHeader, 1, 1);
     $this->assertTrue((bool) preg_match('/<body>(.*)<\\/body>/um', $record, $matches), "Body isn't an HTML document. What's going on here? Body = " . $record);
     $content = $matches[1];
     //		$contentLines = explode('<br />', $content);
     //		$subjectLine = $contentLines[0];
     //		$fromLine = $contentLines[1];
     //		$toLine = $contentLines[2];
     $this->assertRegExp('/(<strong>Subject: <\\/strong>.*)<br \\/>/u', $content);
     $this->assertRegExp('/(<strong>From: <\\/strong>.*)<br \\/>/u', $content);
     $this->assertRegExp('/(<strong>To: <\\/strong>.*)<br \\/>/u', $content);
 }
Example #4
0
     if ($data->complete == 'Yes') {
         echo ' <b>' . Yii::t('workflow', 'Completed') . '</b> ' . Formatter::formatLongDateTime($data->completeDate);
     } else {
         echo ' <b>' . Yii::t('workflow', 'Started') . '</b> ' . Formatter::formatLongDateTime($data->createDate);
     }
     if (isset($data->actionDescription)) {
         echo '<br>' . CHtml::encode($data->actionDescription);
     }
 } elseif ($type == 'webactivity') {
     if (!empty($data->actionDescription)) {
         echo CHtml::encode($data->actionDescription), '<br>';
     }
     echo date('Y-m-d H:i:s', $data->completeDate);
 } elseif (in_array($data->type, array('email', 'emailFrom', 'email_quote', 'email_invoice', 'emailOpened', 'emailOpened_quote', 'emailOpened_invoice'))) {
     $legacy = false;
     if (!preg_match(InlineEmail::insertedPattern('ah', '(.*)', 1, 'mis'), $data->actionDescription, $matches)) {
         // Legacy pattern:
         preg_match('/<b>(.*?)<\\/b>(.*)/mis', $data->actionDescription, $matches);
         $legacy = true;
     }
     if (!empty($matches)) {
         $header = $matches[1];
         $body = '';
     } else {
         if (empty($data->subject)) {
             $header = "No subject found";
             $body = "(Error displaying email)";
         } else {
             $header = $data->subject . "<br>";
             $body = $data->actionDescription;
         }
Example #5
0
 public function actionViewEmail($id)
 {
     $this->redirectOnNullModel = false;
     $action = $this->loadModel($id);
     if (!Yii::app()->user->isGuest || Yii::app()->user->checkAccess(ucfirst($action->associationType) . 'View')) {
         header('Content-Type: text/html; charset=utf-8');
         if (!Yii::app()->user->isGuest) {
             echo preg_replace('/<\\!--BeginOpenedEmail-->(.*?)<\\!--EndOpenedEmail-->/s', '', $action->actionDescription);
         } else {
             // Strip out the action header since it's being viewed directly:
             $actionHeaderPattern = InlineEmail::insertedPattern('ah', '(.*)', 1, 'mis');
             if (!preg_match($actionHeaderPattern, $action->actionDescription, $matches)) {
                 // Legacy action header
                 echo preg_replace('/<b>(.*?)<\\/b>(.*)/mis', '', $action->actionDescription);
             } else {
                 // Current action header
                 echo preg_replace($actionHeaderPattern, '', $action->actionDescription);
             }
         }
     }
 }
Example #6
0
 /**
  * Send an email from X2Engine, returns an array with status code/message
  *
  * @param array addresses
  * @param string $subject the subject for the email
  * @param string $message the body of the email
  * @param array $attachments array of attachments to send
  * @param array|integer $from from and reply to address for the email array(name, address)
  *     or, if integer, the ID of a email credentials record to use for delivery.
  * @return array
  */
 public function sendUserEmail($addresses, $subject, $message, $attachments = null, $from = null)
 {
     $eml = new InlineEmail();
     if (is_array($addresses) ? count($addresses) == 0 : true) {
         throw new Exception('Invalid argument 1 sent to x2base.sendUserEmail(); expected a non-empty array, got instead: ' . var_export($addresses, 1));
     }
     // Set recipients:
     if (array_key_exists('to', $addresses) || array_key_exists('cc', $addresses) || array_key_exists('bcc', $addresses)) {
         $eml->mailingList = $addresses;
     } else {
         return array('code' => 500, 'message' => 'No recipients specified for email; array given for argument 1 of x2base.sendUserEmail does not have a "to", "cc" or "bcc" key.');
     }
     // Resolve sender (use stored email credentials or system default):
     if ($from === null || in_array($from, Credentials::$sysUseId)) {
         $from = (int) Credentials::model()->getDefaultUserAccount($from);
         // Set to the user's name/email if no valid defaults found:
         if ($from == Credentials::LEGACY_ID) {
             $from = array('name' => Yii::app()->params->profile->fullName, 'address' => Yii::app()->params->profile->emailAddress);
         }
     }
     if (is_numeric($from)) {
         $eml->credId = $from;
     } else {
         $eml->from = $from;
     }
     // Set other attributes
     $eml->subject = $subject;
     $eml->message = $message;
     $eml->attachments = $attachments;
     return $eml->deliver();
 }
Example #7
0
 public function actionInviteUsers()
 {
     if (isset($_POST['emails'])) {
         $list = $_POST['emails'];
         $body = "Hello,\n\nYou are receiving this email because your X2Engine administrator has invited you to create an account.\nPlease click on the link below to create an account at X2Engine!\n\n";
         $subject = "Create Your X2Engine User Account";
         $list = trim($list);
         $emails = explode(',', $list);
         foreach ($emails as &$email) {
             $key = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 16)), 0, 16);
             $user = new User('invite');
             $email = trim($email);
             $user->inviteKey = $key;
             $user->temporary = 1;
             $user->emailAddress = $email;
             $user->status = 0;
             $userList = User::model()->findAllByAttributes(array('emailAddress' => $email, 'temporary' => 1));
             foreach ($userList as $userRecord) {
                 if (isset($userRecord)) {
                     $userRecord->delete();
                 }
             }
             $user->save();
             $link = CHtml::link('Create Account', (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl('/users/users/createAccount', array('key' => $key)));
             $mail = new InlineEmail();
             $mail->to = $email;
             // Get email password
             $cred = Credentials::model()->getDefaultUserAccount(Credentials::$sysUseId['systemResponseEmail'], 'email');
             if ($cred == Credentials::LEGACY_ID) {
                 $cred = Credentials::model()->getDefaultUserAccount(Yii::app()->user->id, 'email');
             }
             if ($cred != Credentials::LEGACY_ID) {
                 $mail->credId = $cred;
             }
             $mail->subject = $subject;
             $mail->message = $body . "<br><br>" . $link;
             $mail->contactFlag = false;
             if ($mail->prepareBody()) {
                 $mail->deliver();
             } else {
             }
         }
         $this->redirect('admin');
     }
     $this->render('inviteUsers');
 }
Example #8
0
 public function rules()
 {
     return array_merge(parent::rules(), array(array('campaignId', 'required'), array('modelName', 'required'), array('recordName', 'safe'), array('modelName', 'validateModelName'), array('campaignId', 'validateCampaignId')));
 }
Example #9
0
 public function init()
 {
     $this->disableTemplates = $this->disableTemplates || in_array($this->associationType, array_keys(Docs::modelsWhichSupportEmailTemplates()));
     // Prepare the model for initially displayed input:
     $this->model = new InlineEmail();
     if (isset($this->targetModel)) {
         $this->model->targetModel = $this->targetModel;
     }
     if (!$this->associationType) {
         $this->associationType = X2Model::getModelName(Yii::app()->controller->module->name);
     }
     // Bring in attributes set in the configuration:
     $this->model->attributes = $this->attributes;
     if (empty($this->template)) {
         // check for a default template
         $defaultTemplateId = Yii::app()->params->profile->getDefaultEmailTemplate(Yii::app()->controller->module->name);
         // if there's a default set for this module
         if ($defaultTemplateId !== null) {
             $defaultTemplateDoc = Docs::model()->findByPk($defaultTemplateId);
             // ensure that template is still a valid default
             if ($defaultTemplateDoc && ($defaultTemplateDoc->associationType === $this->associationType || $defaultTemplateDoc->type === 'quote' && $this->model->targetModel instanceof Quote)) {
                 $this->template = $defaultTemplateId;
             }
         }
     }
     if (empty($this->template)) {
         if (empty($this->model->message)) {
             $this->model->message = InlineEmail::emptyBody();
         }
         $this->model->insertSignature();
     } else {
         // Fill in the body with a template:
         $this->model->scenario = 'template';
         if (!empty($this->template)) {
             $this->model->template = $this->template;
         }
         $this->model->prepareBody();
     }
     // If insertable attributes aren't set, use the inline email model's
     // getInsertableAttributes() method to generate them.
     if ((bool) $this->model->targetModel && !isset($this->insertableAttributes)) {
         $this->insertableAttributes = $this->model->insertableAttributes;
     }
     $this->registerJSClassInstantiation();
     // Load resources:
     Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/ckeditor/ckeditor.js');
     Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/ckeditor/adapters/jquery.js');
     Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/emailEditor.js');
     if (!empty($this->insertableAttributes)) {
         Yii::app()->clientScript->registerScript('setInsertableAttributes', 'x2.insertableAttributes = ' . CJSON::encode($this->insertableAttributes) . ';', CClientScript::POS_HEAD);
     }
     Yii::app()->clientScript->registerScript('storeOriginalInlineEmailMessage', 'x2.inlineEmailOriginalBody = $("#email-message").val();', CClientScript::POS_READY);
     //'.CJSON::encode($this->model->message).';',CClientScript::POS_READY);
     Yii::app()->clientScript->registerScript('toggleEmailForm', $this->startHidden ? "window.hideInlineEmail = true;\n" : "window.hideInlineEmail = false;\n", CClientScript::POS_HEAD);
     $this->registerPackages();
     parent::init();
 }