コード例 #1
0
 function process(Am_Form $f)
 {
     $vars = $f->getValue();
     $user = Am_Di::getInstance()->userTable->findFirstByLogin($vars['user']);
     if (!$user) {
         list($el) = $f->getElementsByName('user');
         $el->setError(___('User %s not found', $vars['user']));
         return false;
     }
     $product = Am_Di::getInstance()->productTable->load($vars['product_id']);
     $template = $this->grid->getRecord();
     $mail = Am_Mail_Template::createFromEmailTemplate($template);
     switch ($template->name) {
         case EmailTemplate::AUTORESPONDER:
             $mail->setLast_product_title($product->title);
             break;
         case EmailTemplate::EXPIRE:
             $mail->setProduct_title($product->title);
             $mail->setExpires($vars['expires']);
             break;
         default:
             throw new Am_Exception_InternalError('Unknown email template name [%s]', $template->name);
     }
     $mail->setUser($user);
     $mail->send($user, new Am_Mail_Transport_Null());
     if ($template->format == 'text') {
         printf('<div style="margin-bottom:0.5em;">%s: <strong>%s</strong></div><div style="border:1px solid #2E2E2E; width:%s"><pre>%s</pre></div>', ___('Subject'), Am_Controller::escape($this->getSubject($mail)), '100%', Am_Controller::escape($mail->getMail()->getBodyText()->getRawContent()));
     } else {
         $session = new Zend_Session_Namespace('email_preview');
         $session->output = $mail->getMail()->getBodyHtml()->getRawContent();
         printf('<div style="margin-bottom:0.5em;">%s: <strong>%s</strong></div><iframe  style="border:1px solid #2E2E2E; width:%s; height:300px" src="%s/default/admin-content/p/emails/index?_emails_a=preview&_emails_id=67&_emails_preview=1"></iframe>', ___('Subject'), Am_Controller::escape($this->getSubject($mail)), '100%', REL_ROOT_URL);
     }
     return true;
 }
コード例 #2
0
 function sendCronMailNotCompleted()
 {
     return;
     $mails = $this->findBy(array('name' => EmailTemplate::NOT_COMPLETED));
     if (!$mails) {
         return;
     }
     // nothing to send
     $byDate = array();
     // templates by expiration date
     foreach ($mails as $et) {
         $day = -$et->day;
         if (!$day) {
             continue;
         }
         // must be an error
         $string = $day . ' days';
         $date = date('Y-m-d', strtotime($string));
         $byDate[$date] = $et;
         $whereDates[] = "(i.tm_added BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59')";
     }
     $whereDates = implode(' OR ', $whereDates);
     $q = $this->_db->queryResultOnly("SELECT u.*, \n                i.invoice_id AS _invoice_id,\n                DATE(i.tm_added) AS _invoice_date_added\n            FROM ?_invoice i \n                LEFT JOIN ?_user u USING (user_id)\n            WHERE \n                i.status = ?d \n                AND ({$whereDates})\n                AND u.status = ? \n            ", Invoice::PENDING, User::STATUS_PENDING);
     $sent = array();
     $userTable = $this->getDi()->userTable;
     while ($row = $this->_db->fetchRow($q)) {
         if (array_key_exists($row['user_id'], $sent)) {
             continue;
         }
         $et = $byDate[$row['_invoice_date_added']];
         if (!$et) {
             continue;
         }
         $user = $userTable->createRecord($row);
         $tpl = Am_Mail_Template::createFromEmailTemplate($et);
         $tpl->user = $user;
         $tpl->send($user);
         $sent[$row['user_id']] = true;
     }
 }
コード例 #3
0
 public function sendCronExpires()
 {
     $mails = $this->findBy(array('name' => EmailTemplate::EXPIRE));
     if (!$mails) {
         return;
     }
     // nothing to send
     $byDate = array();
     // templates by expiration date
     foreach ($mails as $et) {
         $et->_productIds = $et->findMatchingProductIds();
         ///
         $day = -$et->day;
         $string = $day . ' days';
         if ($day >= 0) {
             $string = "+{$string}";
         }
         if ($day == 0) {
             $string = 'today';
         }
         $date = date('Y-m-d', strtotime($string, $this->getDi()->time));
         $byDate[$date][] = $et;
     }
     $userTable = $this->getDi()->userTable;
     // now query expirations
     $q = $this->getDi()->accessTable->queryExpirations(array_keys($byDate));
     $sent = array();
     // user_id => array('tpl_id')
     while ($row = $this->_db->fetchRow($q)) {
         $user = $userTable->createRecord($row);
         if ($user->unsubscribed || !$user->is_approved) {
             continue;
         }
         foreach ($byDate[$row['_expire_date']] as $et) {
             // do not send same template agian to the same user
             if (!empty($sent[$user->user_id]) && array_search($et->pk(), $sent[$user->user_id]) !== false) {
                 continue;
             }
             if ($et->_productIds == ResourceAccess::ANY_PRODUCT || in_array($row['_product_id'], $et->_productIds)) {
                 // check if no matching not_conditions
                 if (!$et->checkNotConditions($user)) {
                     continue;
                 }
                 $recipients = array();
                 if ($et->recipient_user) {
                     $recipients[] = $user;
                 }
                 if ($et->recipient_aff && $user->aff_id && ($aff = $this->getDi()->userTable->load($user->aff_id, false))) {
                     $recipients[] = $aff;
                 }
                 if ($et->recipient_admin) {
                     $recipients[] = Am_Mail_Template::TO_ADMIN;
                 }
                 if ($et->recipient_emails) {
                     foreach (array_map('trim', explode(',', $et->recipient_emails)) as $email) {
                         if ($email) {
                             $recipients[] = $email;
                         }
                     }
                 }
                 foreach ($recipients as $recipient) {
                     $tpl = Am_Mail_Template::createFromEmailTemplate($et);
                     $tpl->setUser($user);
                     $tpl->setExpires(amDate($row['_expire_date']));
                     $tpl->setProduct_title($this->getDi()->productTable->load($row['_product_id'])->title);
                     $tpl->send($recipient);
                 }
                 $sent[$user->user_id][] = $et->pk();
             }
         }
     }
 }