public function render(Am_View $view, $user = null) { $html = $this->html; if (strpos($html, '%user.') !== false) { $t = new Am_SimpleTemplate(); if ($user) { $t->assign('user', $user); } $t->assignStdVars(); $html = $t->render($html); } if ($this->use_layout) { $view->content = '<div class="am-content-page">' . $html . '</div>'; $view->title = $this->title; $view->meta_title = $this->meta_title ? $this->meta_title : $this->title; if ($this->meta_keywords) { $view->headMeta()->setName('keywords', $this->meta_keywords); } if ($this->meta_description) { $view->headMeta()->setName('description', $this->meta_description); } return $view->render($this->tpl ? $this->tpl : 'layout.phtml'); } else { return $html; } }
function onThanksPage(Am_Event $event) { if (!$event->getInvoice()) { return; } $url = null; foreach ($event->getInvoice()->getProducts() as $pr) { if ($url = $pr->data()->get('thanks_redirect_url')) { break; } } $t = new Am_SimpleTemplate(); $t->assign('invoice', $event->getInvoice()); $t->assign('user', $event->getInvoice()->getUser()); $url = $t->render($url); if ($url) { $event->getController()->redirectLocation($url); } }
public function displaysnippetsAction() { if (!$this->strategy->canUseSnippets()) { throw new Am_Exception_AccessDenied(); } $ticket = $this->getDi()->helpdeskTicketTable->load($this->getParam('ticket'), false); $tpl = null; if ($ticket) { $tpl = new Am_SimpleTemplate(); $tpl->assign('user', $ticket->getUser()); } $ds = new Am_Query($this->getDi()->helpdeskSnippetTable); $grid = new Am_Grid_Editable('_snippet', ___('Snippets'), $ds, $this->getRequest(), $this->view, $this->getDi()); $grid->addField('title', ___('Title'))->setRenderFunction(function ($record, $fieldName, $grid) use($tpl) { $c = $record->content; if ($tpl) { $c = $tpl->render($c); } return sprintf('<td><a href="javascript:;" class="local am-helpdesk-insert-snippet" data-snippet-content="%s">%s</a></td>', Am_Controller::escape($c), Am_Controller::escape($record->title)); }); $grid->setForm(array($this, 'createForm')); $grid->actionGet('insert')->setTarget(null); $grid->setPermissionId(Bootstrap_Helpdesk::ADMIN_PERM_ID); $grid->isAjax($this->isAjax() && $this->isGridRequest('_snippet')); echo $grid->run(); }
public function getFileName() { $filename = $this->getDi()->config->get('invoice_filename', 'amember-invoice-%public_id%.pdf'); $filename = str_replace('%payment.date%', date('Y-m-d', amstrtotime($this->payment->dattm)), $filename); $tmp = new Am_SimpleTemplate(); $tmp->assign('public_id', $this->invoice->public_id); $tmp->assign('receipt_id', $this->payment->receipt_id); $tmp->assign('payment', $this->payment); $tmp->assign('invoice', $this->invoice); $tmp->assign('user', $this->invoice->getUser()); return $tmp->render($filename); }
protected function _parse($text, $layout = null) { $tpl = new Am_SimpleTemplate(); $tpl->assignStdVars(); $tpl->assign($this->getArrayCopy()); $tpl->assign(get_object_vars($this)); $text = $tpl->render($text); if ($layout) { $tpl->assign('content', $text); $text = $tpl->render($layout); } return $text; }
public function run() { $form = $this->grid->getForm(); if ($form->isSubmitted() && $form->validate()) { $values = $form->getValue(); if (defined('AM_ADMIN') && AM_ADMIN && isset($values['from']) && $values['from'] == 'user') { $user = Am_Di::getInstance()->userTable->findFirstByLogin($values['loginOrEmail']); if (!$user) { $user = Am_Di::getInstance()->userTable->findFirstByEmail($values['loginOrEmail']); } if (!$user) { throw new Am_Exception_InputError("User not found with username or email equal to {$values['loginOrEmail']}"); } $this->switchStrategy(new Am_Helpdesk_Strategy_User(Am_Di::getInstance(), $user->pk())); } $ticket = Am_Di::getInstance()->helpdeskTicketRecord; $ticket->subject = $values['subject']; $ticket->created = Am_Di::getInstance()->sqlDateTime; $ticket->updated = Am_Di::getInstance()->sqlDateTime; $ticket->category_id = isset($values['category_id']) ? $values['category_id'] : null; if (($category = $ticket->getCategory()) && $category->owner_id) { $ticket->owner_id = $category->owner_id; } $ticket = $this->getStrategy()->fillUpTicketIdentity($ticket, $this->grid->getCompleteRequest()); // mask will be generated on insertion $ticket->insert(); $this->getStrategy()->onAfterInsertTicket($ticket); $content = $values['content']; if (defined('AM_ADMIN') && AM_ADMIN) { $user = $ticket->getUser(); $tpl = new Am_SimpleTemplate(); $tpl->assign('user', $user); $content = $tpl->render($content); } $message = Am_Di::getInstance()->helpdeskMessageRecord; $message->content = $content; $message->ticket_id = $ticket->pk(); $message->dattm = Am_Di::getInstance()->sqlDateTime; $message = $this->getStrategy()->fillUpMessageIdentity($message); $message->setAttachments(@$values['attachments']); $message->insert(); $this->getStrategy()->onAfterInsertMessage($message); $this->restoreStrategy(); echo $this->renderTicketSubmited($ticket); } else { echo $this->renderTitle(); echo $form; } }
public function batchSend(&$context, Am_BatchProcessor $batch) { if ($this->saved->count_users <= $this->saved->sent_users) { return true; } // we are done; $q = $this->searchUi->query($this->saved->sent_users, 10); $i = 0; $db = $this->getDi()->db; $foundrows = false; while ($r = $db->fetchRow($q)) { $foundrows = true; if (!$batch->checkLimits()) { return false; } $r['name'] = $r['name_f'] . ' ' . $r['name_l']; $this->saved->updateQuick(array('last_email' => $r['email'], 'sent_users' => $this->saved->sent_users + 1)); if ($r['email'] == '') { continue; } $m = $this->getDi()->mail; $m->setPeriodic(Am_Mail::ADMIN_REQUESTED); $m->addHeader('X-Amember-Queue-Id', $this->_request->getFiltered('queue_id')); $m->addUnsubscribeLink(Am_Mail::LINK_USER); $m->addTo($r['email'], $r['name']); if ($reply_to = $this->getParam('reply_to')) { switch ($reply_to) { case 'default': $email = false; break; case 'other': $email = $this->getParam('reply_to_other'); $name = null; break; default: preg_match('/^admin-(\\d+)$/', $reply_to, $match); $admin = $this->getDi()->adminTable->load($match[1], false); if ($admin) { $email = $admin->email; $name = $admin->getName(); } break; } if ($email = filter_var($email, FILTER_VALIDATE_EMAIL)) { $m->setReplyTo($email, $name); } } $subject = $this->getParam('subject'); $body = $this->getParam('body'); $tpl = new Am_SimpleTemplate(); $tpl->assignStdVars(); if (strpos($body, '%user.unsubscribe_link%') !== false || strpos($subject, '%user.unsubscribe_link%') !== false) { $r['unsubscribe_link'] = Am_Mail::getUnsubscribeLink($r['email'], Am_Mail::LINK_USER); } $tpl->user = $r; $this->getDi()->hook->call(Am_Event::MAIL_SIMPLE_TEMPLATE_BEFORE_PARSE, array('template' => $tpl, 'body' => $body, 'subject' => $subject, 'mail' => $m, 'request' => $this->getRequest())); $subject = $tpl->render($subject); $body = $tpl->render($body); if ($this->getParam('email_template_layout_id') && ($layout = $this->getDi()->emailTemplateLayoutTable->load($this->getParam('email_template_layout_id', false)))) { $tpl->assign('content', $body); $body = $tpl->render($layout->layout); } $m->setSubject($subject); if ($this->getParam('format') == 'text') { $m->setBodyText($body); } else { $text = strip_tags($body); $html = strpos($body, '<html') === false ? "<html><head><title>{$subject}</title></head><body>{$body}</body></html>" : $body; $m->setBodyHtml($html); $m->setBodyText($text); } foreach ($this->getAttachments() as $at) { $m->addAttachment($at); } try { $m->send(); } catch (Zend_Mail_Exception $e) { trigger_error("Error happened while sending e-mail to {$r['email']} : " . $e->getMessage(), E_USER_WARNING); } } $this->getDi()->db->freeResult($q); if (!$foundrows) { return true; } if ($this->saved->count_users <= $this->saved->sent_users) { return true; } // we are done; }
public function render() { $invoice = $this->invoice; $payment = $this->payment; $user = $invoice->getUser(); $pdf = $this->createPdfTemplate(); $event = new Am_Event(Am_Event::PDF_INVOICE_BEFORE_RENDER, array('amPdfInvoice' => $this, 'pdf' => $pdf, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user)); $event->setReturn(false); $this->getDi()->hook->call($event); // If event processing already rendered the Pdf. if ($event->getReturn() === true) { return $pdf->render(); } $width_num = 30; $width_qty = 40; $width_price = 80; $width_total = 120; $padd = 20; $left = $padd; $right = $this->getPaperWidth() - $padd; $fontH = $this->getFontRegular(); $fontHB = $this->getFontBold(); $styleBold = array('font' => array('face' => $fontHB, 'size' => 10)); $page = new Am_Pdf_Page_Decorator($pdf->pages[0]); $page->setFont($fontH, 10); $pointer = $this->getPointer(); $pointerL = $pointerR = $pointer; $leftCol = new stdClass(); $leftCol->invoiceNumber = ___('Corrective Invoice Number: ') . $payment->getDisplayInvoiceId(); $leftCol->recInvoiceNumber = ___('Rectifies Invoice Number: ') . $this->getOrigPayment()->getDisplayInvoiceId(); $leftCol->date = ___('Date: ') . amDate($payment->dattm); if ($user->tax_id) { $leftCol->taxId = ___('EU VAT ID: ') . $user->tax_id; } $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_LEFT, array('col' => $leftCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user)); foreach ($leftCol as $line) { $page->drawText($line, $left, $pointerL); $page->nl($pointerL); } $rightCol = new stdClass(); $rightCol->name = $invoice->getName(); $rightCol->email = $invoice->getEmail(); $rightCol->address = implode(', ', array_filter(array($invoice->getStreet(), $invoice->getCity()))); $rightCol->country = implode(', ', array_filter(array($this->getState($invoice), $invoice->getZip(), $this->getCountry($invoice)))); $this->getDi()->hook->call(Am_Event::PDF_INVOICE_COL_RIGHT, array('col' => $rightCol, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user)); foreach ($rightCol as $line) { $page->drawText($line, $right, $pointerR, 'UTF-8', Am_Pdf_Page_Decorator::ALIGN_RIGHT); $page->nl($pointerR); } $pointer = min($pointerR, $pointerL); $p = new stdClass(); $p->value =& $pointer; $this->getDi()->hook->call(Am_Event::PDF_INVOICE_BEFORE_TABLE, array('page' => $page, 'pointer' => $p, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user)); $table = new Am_Pdf_Table(); $table->setMargin($padd, $padd, $padd, $padd); $table->setStyleForRow(1, array('shape' => array('type' => Zend_Pdf_Page::SHAPE_DRAW_STROKE, 'color' => new Zend_Pdf_Color_Html("#cccccc")), 'font' => array('face' => $fontHB, 'size' => 10))); $table->setStyleForColumn(1, array('align' => 'right', 'width' => $width_num)); $table->setStyleForColumn(3, array('align' => 'right', 'width' => $width_qty)); $table->setStyleForColumn(4, array('align' => 'right', 'width' => $width_price)); $table->setStyleForColumn(5, array('align' => 'right', 'width' => $width_total)); $table->addRow(array(___('#'), ___('Subscription/Product Title'), ___('Qty'), ___('Unit Price'), ___('Total Price'))); $num = 0; foreach ($invoice->getItems() as $p) { /* @var $p InvoiceItem */ $table->addRow(array(++$num . '.', $p->item_title, $p->qty, $invoice->getCurrency($this->isFirstPayment() ? $p->first_price : $p->second_price), $invoice->getCurrency($this->isFirstPayment() ? $p->getFirstSubtotal() : $p->getSecondSubtotal()))); } $pointer = $page->drawTable($table, 0, $pointer); $table = new Am_Pdf_Table(); $table->setMargin($padd, $padd, $padd, $padd); $table->setStyleForColumn(2, array('align' => 'right', 'width' => $width_total)); $subtotal = $this->isFirstPayment() ? $invoice->first_subtotal : $invoice->second_subtotal; $total = $this->isFirstPayment() ? $invoice->first_total : $invoice->second_total; if ($subtotal != $total) { $table->addRow(array(___('Subtotal'), $invoice->getCurrency($subtotal)))->addStyle($styleBold); } if ($this->isFirstPayment() && $invoice->first_discount > 0 || !$this->isFirstPayment() && $invoice->second_discount > 0) { $table->addRow(array(___('Coupon Discount'), $invoice->getCurrency($this->isFirstPayment() ? $invoice->first_discount : $invoice->second_discount))); } $table->addRow(array(___('Total'), $invoice->getCurrency($total)))->addStyle($styleBold); $table->addRow(array(___('Taxable Income'), "-" . $invoice->getCurrency($this->getOrigPayment()->amount - $this->getOrigPayment()->tax)))->addStyle($styleBold); if ($this->getOrigPayment()->tax > 0) { $table->addRow(array(___('Tax') . " " . $invoice->tax_rate . "%", "-" . $invoice->getCurrency($this->getOrigPayment()->tax)))->addStyle($styleBold); } $table->addRow(array(___('Amount Paid'), $invoice->getCurrency(sprintf("%.2f", $this->getOrigPayment()->amount - $this->payment->amount))))->addStyle(array('font' => array('face' => $fontHB, 'size' => 10))); $x = $this->getPaperWidth() - ($width_qty + $width_price + $width_total) - 2 * $padd; $pointer = $page->drawTable($table, $x, $pointer); $page->nl($pointer); $page->nl($pointer); if (!$this->getDi()->config->get('invoice_do_not_include_terms')) { $termsText = new Am_TermsText($invoice); $page->drawTextWithFixedWidth(___('Subscription Terms') . ': ' . $termsText, $left, $pointer, $this->getPaperWidth() - 2 * $padd); $page->nl($pointer); } $p = new stdClass(); $p->value =& $pointer; $this->getDi()->hook->call(Am_Event::PDF_INVOICE_AFTER_TABLE, array('page' => $page, 'pointer' => $p, 'invoice' => $invoice, 'payment' => $payment, 'user' => $user)); if (!$this->getDi()->config->get('invoice_custom_template') || !$this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template'))) { if ($ifn = $this->getDi()->config->get('invoice_footer_note')) { $tmpl = new Am_SimpleTemplate(); $tmpl->assignStdVars(); $tmpl->assign('user', $user); $tmpl->assign('invoice', $invoice); $ifn = $tmpl->render($ifn); $page->nl($pointer); $page->drawTextWithFixedWidth($ifn, $left, $pointer, $this->getPaperWidth() - 2 * $padd); } } return $pdf->render(); }
protected function _parse($text) { $tpl = new Am_SimpleTemplate(); $tpl->assignStdVars(); $tpl->assign($this->getArrayCopy()); $tpl->assign(get_object_vars($this)); return $tpl->render($text); }