function renderForm($addHidden) { $this->initPossibleConditions(); $t = new Am_View(); $renderer = HTML_QuickForm2_Renderer::factory('array'); if (!$this->form) { $this->createForm(array()); } $this->form->render($renderer); $t->assign('form', $renderer->toArray()); $t->assign('description', $this->getDescription(true)); $t->assign('serialized', $this->serialize()); $t->assign('hidden', $addHidden); $t->assign('loadSearchOptions', Am_Controller::renderOptions($this->getLoadOptions(), $this->saved_search_id)); return $t->render($this->template); }
/** * Redirect customer to new url * @param $targetTop useful when doing a redirect in AJAX generated html */ function redirectHtml($url, $text = '', $title = 'Redirecting...', $targetTop = false, $proccessed = null, $total = null) { $this->view->assign('title', $title); $this->view->assign('text', $text); $this->view->assign('url', $url); if (!is_null($total)) { $width = 100 * $proccessed / $total; $this->view->width = min(100, round($width)); $this->view->showProgressBar = true; $this->view->total = $total; $this->view->proccessed = $proccessed; } if ($targetTop) { $this->view->assign('target', '_top'); } if (ob_get_level()) { ob_end_clean(); } $this->getResponse()->setBody($this->view->render(defined('AM_ADMIN') ? 'admin/redirect.phtml' : 'redirect.phtml')); throw new Am_Exception_Redirect($url); // exit gracefully }
public function viewAction() { $ticketIdentity = $this->getParam('ticket'); $ticket = $this->getDi()->helpdeskTicketTable->load($ticketIdentity); if (!$this->strategy->canViewTicket($ticket)) { throw new Am_Exception_AccessDenied(___('Access Denied')); } $grid = new Am_Helpdesk_Grid_Admin($this->getRequest(), $this->getView()); $grid->getDataSource()->getDataSourceQuery()->addWhere('m.user_id=?d', $ticket->user_id); $grid->actionsClear(); $grid->removeField('m_login'); $grid->addCallback(Am_Grid_ReadOnly::CB_TR_ATTRIBS, function (&$ret, $record) use($ticket) { if ($record->pk() == $ticket->pk()) { $ret['class'] = isset($ret['class']) ? $ret['class'] . ' emphase' : 'emphase'; } }); $grid->isAjax($this->isAjax() && $this->isGridRequest('_grid')); if ($grid->isAjax()) { echo $grid->run(); return; } $category = $ticket->getCategory(); $t = new Am_View(); $t->assign('ticket', $ticket); $t->assign('category', $category); $t->assign('user', $ticket->getUser()); $t->assign('strategy', $this->strategy); $t->assign('historyGrid', $grid->render()); $content = $t->render($this->strategy->getTemplatePath() . '/ticket.phtml'); if ($this->isAjax()) { header('Content-type: text/html; charset=UTF-8'); echo $content; } else { $this->view->assign('content', $content); $this->view->display($this->strategy->getTemplatePath() . '/index.phtml'); } }
function __exception(Exception $e) { if ($e instanceof Zend_Controller_Dispatcher_Exception && preg_match('/^Invalid controller specified/', $e->getMessage())) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } if ($e->getCode() == 404) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } try { static $in_fatal_error; //! $in_fatal_error++; if ($in_fatal_error > 2) { echo nl2br("<b>\n\n" . __METHOD__ . " called twice\n\n</b>"); exit; } if (!$this->initFinished) { $isApiError = false; } else { $request = Zend_Controller_Front::getInstance()->getRequest(); $isApiError = preg_match('#^/api/#', $request->getPathInfo()) && !preg_match('#^/api/admin($|/)#', $request->getPathInfo()); } if (!$isApiError && (defined('AM_DEBUG') && AM_DEBUG || APPLICATION_ENV == 'testing')) { $display_error = "<pre>" . $e . ':' . $e->getMessage() . "</pre>"; } else { if ($e instanceof Am_Exception) { $display_error = $e->getPublicError(); $display_title = $e->getPublicTitle(); } elseif ($e instanceof Zend_Controller_Dispatcher_Exception) { $display_error = ___("Error 404 - Not Found"); header("HTTP/1.0 404 Not Found"); } else { $display_error = ___('An internal error happened in the script, please contact webmaster for details'); } } /// special handling for API errors if ($isApiError) { $format = $request->getParam('_format', 'json'); if (!empty($display_title)) { $display_error = $display_title . ':' . $display_error; } $display_error = trim($display_error, " \t\n\r"); if ($format == 'xml') { $xml = new SimpleXMLElement('<error />'); $xml->ok = 'false'; $xml->message = $display_error; echo (string) $xml; } else { echo json_encode(array('ok' => false, 'error' => true, 'message' => $display_error)); } exit; } if (!$this->initFinished) { amDie($display_error); } // fixes http://bt.amember.com/issues/597 if (($router = Zend_Controller_Front::getInstance()->getRouter()) instanceof Zend_Controller_Router_Rewrite) { $router->addDefaultRoutes(); } // $t = new Am_View(); $t->assign('is_html', true); // must be already escaped here! if (isset($display_title)) { $t->assign('title', $display_title); } $t->assign('error', $display_error); $t->assign('admin_email', $this->di->config->get('admin_email')); if (defined('AM_DEBUG') && AM_DEBUG) { $t->assign('trace', $e->getTraceAsString()); } $t->display("error.phtml"); // log error if (!method_exists($e, 'getLogError') || $e->getLogError()) { $this->di->errorLogTable->logException($e); } } catch (Exception $e) { echo $e . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); } exit; }
public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) { try { $invoiceLog = $this->_logDirectAction($request, $response, $invokeArgs); $transaction = $this->createTransaction($request, $response, $invokeArgs); if (!$transaction) { throw new Am_Exception_InputError("Request not handled - createTransaction() returned null"); } $transaction->setInvoiceLog($invoiceLog); try { $transaction->process(); } catch (Exception $e) { if ($invoiceLog) { $invoiceLog->add($e); } throw $e; } if ($invoiceLog) { $invoiceLog->setProcessed(); } //show thanks page without redirect if ($transaction->isFirst()) { $this->displayThanks($request, $response, $invokeArgs, $transaction->getInvoice()); } } catch (Exception $e) { $message = $e->getMessage(); $view = new Am_View($this->getDi()); $view->assign('error', $e->getMessage()); $view->assign('is_html', false); $view->placeholder("head-start")->prepend(sprintf('<base href="%s://%s" />', empty($_SERVER['HTTPS']) ? 'http' : 'https', Am_Controller::escape($_SERVER['HTTP_HOST']))); $this->invoice = $transaction->getInvoice(); $view->placeholder("head-start")->prepend(sprintf('<meta http-equiv="refresh" content="0;url=%s">', $this->getCancelUrl())); $view->display('error.phtml'); } }
protected function populateForm() { $info = $this->getController()->getValue(); foreach ($info as $k => $v) { if ($k[0] == '_') { unset($info[$k]); } } if (@$info['table_prefix']) { foreach ($info['table'] as &$v) { $v = preg_replace('/^' . preg_quote($info['table_prefix']) . '/', '', $v); } } $userFields = array(); $guessFields = array(); foreach ($info['field']['user'] as $fn => $a) { if (empty($a['field'])) { continue; } $guessFields[] = $fn; $expr = $a['field']; if ($expr == 'string') { $expr = var_export(':' . $a['text'], true); } elseif ($expr == 'expr') { $expr = '"!' . $a['text'] . '"'; } $userFields[] = "array({$expr}, '{$fn}'),"; } $view = new Am_View(); $view->assign($info); $view->assign('guessFields', $guessFields); $view->assign('userFields', $userFields); $cnt = "<h2>Plugin Template Generated</h2>"; $cnt .= "Put the following code to <i>application/default/plugins/protect/{$info['plugin']}.php</i> and start customization"; $cnt .= "<div style='background-color: #eee; width: 90%; height: 300px; overflow-x: scroll; overflow-y: scroll;'>\n"; $cnt .= highlight_string($view->render('admin/plugin-template.phtml'), true); $cnt .= "</div>"; $el = $this->form->addStatic(null, array('class' => 'no-label'))->setContent($cnt); $gr = $this->form->addGroup(null, array('class' => 'no-label', 'style' => 'text-align:center')); $gr->addSubmit($this->getButtonName('back'), array('value' => 'Back')); $page = $this; while ($p = $page->getController()->previousPage($page)) { $page = $p; } $gr->addSubmit($page->getButtonName('jump'), array('value' => 'Start Over')); }
function __exception(Exception $e) { if ($e instanceof Zend_Controller_Dispatcher_Exception && preg_match('/^Invalid controller specified/', $e->getMessage())) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } if ($e->getCode() == 404) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } try { static $in_fatal_error; //! $in_fatal_error++; if ($in_fatal_error > 2) { echo nl2br("<b>\n\n" . __METHOD__ . " called twice\n\n</b>"); exit; } if (defined('AM_DEBUG') && AM_DEBUG || APPLICATION_ENV == 'testing') { $display_error = "<pre>" . $e . ':' . $e->getMessage() . "</pre>"; } else { if ($e instanceof Am_Exception) { $display_error = $e->getPublicError(); } elseif ($e instanceof Zend_Controller_Dispatcher_Exception) { $display_error = ___("Error 404 - Not Found"); header("HTTP/1.0 404 Not Found"); } else { $display_error = ___('An internal error happened in the script, please contact webmaster for details'); } } $t = new Am_View(); $t->assign('is_html', true); // must be already escaped here! $t->assign('error', $display_error); $t->assign('admin_email', $this->di->config->get('admin_email')); if (defined('AM_DEBUG') && AM_DEBUG) { $t->assign('trace', $e->getTraceAsString()); } $t->display("error.phtml"); // log error if (!method_exists($e, 'getLogError') || $e->getLogError()) { $this->di->errorLogTable->logException($e); } } catch (Exception $e) { echo $e . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); } exit; }
private function getReplyForm($ticket_id, $message = null, $type = 'message') { $content = ''; $hiddens = ''; if (!is_null($message) && $type == 'message') { $content = explode("\n", $message->content); $content = array_map(create_function('$v', 'return \'>\'.$v;'), $content); $content = "\n\n" . implode("\n", $content); } elseif (!is_null($message) && $type == 'comment') { $content = $message->content; $hiddens .= sprintf('<input type="hidden" name="message_id" value="%d" />', $message->message_id); } $t = new Am_View(); $t->assign('content', $content); $t->assign('type', $type); $t->assign('hiddens', $hiddens); $t->assign('ticket_id', $ticket_id); return $t->display($this->strategy->getTemplatePath() . '/_reply-form.phtml'); }