/** @return Am_Mail_TemplateTypes */ static function getInstance() { if (!self::$instance) { self::$instance = self::createInstance(); } return self::$instance; }
public function __construct($name) { parent::__construct('', array('id' => 'mail-editor')); $subject = $this->addElement('text', 'subject', array('size' => 80))->setLabel(___('Subject')); $subject->addRule('required'); $this->addStatic()->setContent('<br /><br />'); $format = $this->addGroup(null)->setLabel(___('E-Mail Format')); $format->addRadio('format', array('value' => 'html'))->setContent(___('HTML Message')); $format->addRadio('format', array('value' => 'text'))->setContent(___('Plain-Text Message')); $this->addStatic()->setContent('<br /><br />'); $this->editor = $this->addElement(new Am_Form_Element_HtmlEditor('txt', null, true)); $this->editor->addRule('required'); $this->addStatic()->setContent('<br /><br />'); $this->tagsOptions = Am_Mail_TemplateTypes::getInstance()->getTagsOptions($name); $tagsOptions = array(); foreach ($this->tagsOptions as $k => $v) { $tagsOptions[$k] = "{$k} - {$v}"; } $sel = $this->addSelect('', array('id' => 'insert-tags')); $sel->loadOptions(array_merge(array('' => ''), $tagsOptions)); $this->addStatic()->setContent('<br /><br />'); $this->addClass('no-label'); $fileChooser = new Am_Form_Element_Upload('attachments', array('multiple' => 1), array('prefix' => EmailTemplate::ATTACHMENT_FILE_PREFIX)); $this->addElement($fileChooser)->setLabel(___('Attachments')); }
/** @return Am_Mail_Template */ static function createFromEmailTemplate(EmailTemplate $et) { $t = new self(); $t->setTemplate($et->format, $et->subject, $et->plain_txt, $et->txt, $et->attachments, $et->email_template_id . '-' . $et->name . '-' . $et->lang, $et->name, $et->getLayout()); $t->admins = array_filter(explode(',', $et->recipient_admins)); $rec = Am_Mail_TemplateTypes::getInstance()->find($et->name); if ($rec) { $t->setMailPeriodic($rec['mailPeriodic']); } $bcc = $et->bcc ? array_map('trim', explode(',', $et->bcc)) : array(); if ($bcc) { $t->getMail()->addBcc($bcc); } if ($et->reply_to && ($admin = $et->getDi()->adminTable->load($et->reply_to, false))) { $t->getMail()->setReplyTo($admin->email, $admin->getName()); } return $t; }
function createForm() { $form = new Am_Form_Admin('am-form-email'); $form->setDataSources(array($this->getRequest())); $form->setAction($this->getUrl(null, 'preview')); if ($options = $this->getDi()->emailTemplateLayoutTable->getOptions()) { $form->addSelect('email_template_layout_id')->setLabel(___('Layout'))->loadOptions(array('' => ___('No Layout')) + $options); } $gr = $form->addGroup()->setLabel(___("Reply To\n" . "mailbox for replies to message"))->setSeparator(' '); $sel = $gr->addSelect('reply_to')->loadOptions($this->getReplyToOptions()); $id = $sel->getId(); $gr->addText('reply_to_other', array('placeholder' => ___('Email Address')))->setId($id . '-other')->persistentFreeze(true); // ??? why is it necessary? but it is $gr->addScript()->setScript(<<<CUT \$('#{$id}').change(function(){ \$('#{$id}-other').toggle(\$(this).val() == 'other'); }).change(); CUT ); $subj = $form->addText('subject', array('class' => 'el-wide'))->setLabel(___('Email Subject')); $subj->persistentFreeze(true); // ??? why is it necessary? but it is $subj->addRule('required', ___('Subject is required')); // $arch = $form->addElement('advcheckbox', 'do_archive')->setLabel(array('Archive Message', 'if you are sending it to newsletter subscribers')); $format = $form->addGroup(null)->setLabel(___('E-Mail Format')); $format->setSeparator(' '); $format->addRadio('format', array('value' => 'html'))->setContent(___('HTML Message')); $format->addRadio('format', array('value' => 'text'))->setContent(___('Plain-Text Message')); $group = $form->addGroup('', array('id' => 'body-group', 'class' => 'no-label'))->setLabel(___('Message Text')); $group->addStatic()->setContent('<div class="mail-editor">'); $group->addStatic()->setContent('<div class="mail-editor-element">'); $group->addElement('textarea', 'body', array('id' => 'body-0', 'rows' => '15', 'class' => 'el-wide')); $group->addStatic()->setContent('</div>'); $group->addStatic()->setContent('<div class="mail-editor-element">'); $this->tagsOptions = Am_Mail_TemplateTypes::getInstance()->getTagsOptions('send_signup_mail'); $tagsOptions = array(); foreach ($this->tagsOptions as $k => $v) { $tagsOptions[$k] = "{$k} - {$v}"; } $sel = $group->addSelect('', array('id' => 'insert-tags')); $sel->loadOptions(array_merge(array('' => ''), $tagsOptions)); $group->addStatic()->setContent('</div>'); $group->addStatic()->setContent('</div>'); $fileChooser = new Am_Form_Element_Upload('files', array('multiple' => '1'), array('prefix' => 'email')); $form->addElement($fileChooser)->setLabel(___('Attachments')); foreach ($this->searchUi->getHidden() as $k => $v) { $form->addHidden($k)->setValue($v); } $id = 'body-0'; $vars = ""; foreach ($this->tagsOptions as $k => $v) { $vars .= sprintf("[%s, %s],\n", Am_Controller::getJson($v), Am_Controller::getJson($k)); } $vars = trim($vars, "\n\r,"); if ($this->queue_id) { $form->addHidden('queue_id')->setValue($this->queue_id); } $form->addScript('_bodyscript')->setScript(<<<CUT \$(function(){ \$('select#insert-tags').change(function(){ var val = \$(this).val(); if (!val) return; \$("#{$id}").insertAtCaret(val); \$(this).prop("selectedIndex", -1); }); if (CKEDITOR.instances["{$id}"]) { delete CKEDITOR.instances["{$id}"]; } var editor = null; \$("input[name='format']").change(function() { if (window.configDisable_rte) return; if (!this.checked) return; if (this.value == 'html') { if (!editor) { editor = initCkeditor("{$id}", { placeholder_items: [ {$vars} ],entities_greek: false}); } \$('select#insert-tags').hide(); } else { if (editor) { editor.destroy(); editor = null; } \$('select#insert-tags').show(); } }).change(); }); CUT ); $this->getDi()->hook->call(Am_Event::MAIL_SIMPLE_INIT_FORM, array('form' => $form)); $buttons = $form->addGroup('buttons'); $buttons->addSubmit('send', array('value' => ___('Preview'))); return $form; }
protected function createForm() { $form = new Am_Form_Admin('EmailTemplate'); $form->addElement(new Am_Form_Element_Html('info'))->setLabel(___('Template'))->setHtml(sprintf('<div><strong>%s</strong><br /><small>%s</small></div>', $this->escape($this->getParam('name')), $this->escape($this->getParam('label')))); $form->addElement('hidden', 'name'); $langOptions = $this->getLanguageOptions($this->getDi()->config->get('lang.enabled', array($this->getDi()->config->get('lang.default', 'en')))); /* @var $lang HTML_QuickForm2_Element */ $lang = $form->addElement('select', 'lang')->setId('lang')->setLabel(___('Language'))->loadOptions($langOptions); if (count($langOptions) == 1) { $lang->toggleFrozen(true); } $lang->addRule('required'); if ($options = $this->getDi()->emailTemplateLayoutTable->getOptions()) { $form->addSelect('email_template_layout_id')->setLabel(___('Layout'))->loadOptions(array('' => ___('No Layout')) + $options); } $tt = Am_Mail_TemplateTypes::getInstance()->find($this->getParam('name')); if ($tt && !empty($tt['isAdmin'])) { $op = array('-1' => Am_Controller::escape(sprintf('%s <%s>', Am_Di::getInstance()->config->get('site_title') . ' Admin', Am_Di::getInstance()->config->get('admin_email')))); foreach (Am_Di::getInstance()->adminTable->findBy() as $admin) { $op[$admin->pk()] = Am_Controller::escape(sprintf('%s <%s>', $admin->getName(), $admin->email)); } $form->addMagicSelect('_admins', array('value' => 'default'))->setLabel(___('Admin Recipients'))->loadOptions($op)->addRule('required'); } else { $form->addText('bcc', array('class' => 'el-wide', 'placeholder' => ___('Email Addresses Separated by Comma')))->setLabel(___("BCC\n" . "blind carbon copy allows the sender of a message to conceal the person entered in the Bcc field from the other recipients"))->addRule('callback', ___('Please enter valid e-mail addresses'), array('Am_Validate', 'emails')); } $form->addScript()->setScript(<<<CUT \$("#checkbox-recipient-other").change(function(){ \$("#row-input-recipient-emails").toggle(this.checked); }).change(); CUT ); $body = $form->addElement(new Am_Form_Element_MailEditor($this->getParam('name'))); $form->addElement('hidden', 'label')->setValue($this->getParam('label')); return $form; }
/** @return Am_Mail_Template */ static function createFromEmailTemplate(EmailTemplate $et) { $t = new self(); $t->setTemplate($et->format, $et->subject, $et->plain_txt, $et->txt, $et->attachments, $et->email_template_id . '-' . $et->name . '-' . $et->lang, $et->name); $t->admins = $et->recipient_admins; $rec = Am_Mail_TemplateTypes::getInstance()->find($et->name); if ($rec) { $t->setMailPeriodic($rec['mailPeriodic']); } $bcc = $et->bcc ? array_map('trim', explode(',', $et->bcc)) : array(); if ($bcc) { $t->getMail()->addBcc($bcc); } return $t; }
/** @return Am_Mail_Template */ static function createFromEmailTemplate(EmailTemplate $et) { $t = new self(); $t->setTemplate($et->format, $et->subject, $et->plain_txt, $et->txt, $et->attachments, $et->email_template_id . '-' . $et->name . '-' . $et->lang); $rec = Am_Mail_TemplateTypes::getInstance()->find($et->name); if ($rec) { $t->setMailPeriodic($rec['mailPeriodic']); } return $t; }