/** * @param \Nette\DI\IContainer */ protected function processRequests(\Nette\DI\IContainer $container) { $this->updating(); $httpRequest = $container->httpRequest; $httpResponse = $container->httpResponse; if ($httpRequest->getHeader(self::XHR_HEADER, FALSE)) { $data = FALSE; $this->translator->setLang($httpRequest->getPost('lang')); switch($httpRequest->getPost('action')) { case 'get': break; case 'extract': $this->extractor->run(); break; case 'save': $data = $httpRequest->getPost('data', ""); break; } $dictionaries = $this->getDictionaries($data); $response = new \Nette\Application\Responses\JsonResponse(array( 'status' => "OK", 'lang' => $this->translator->dictionaries, 'data' => $dictionaries, )); $response->send($httpRequest, $httpResponse); exit(255); } $this->freeze(); }
/* require framework */ require 'php/Nette/nette.phar'; /* configure neccessary */ $configurator = new Nette\Configurator(); $configurator->setTempDirectory(__DIR__ . '/php/temp'); $container = $configurator->createContainer(); /* get post */ $httpRequest = $container->getService('httpRequest'); $httpResponse = $container->getService('httpResponse'); $post = $httpRequest->getPost(); if ($httpRequest->isAjax()) { /* compose htmlContent */ $htmlContent .= '<table>'; foreach ($post as $key => $value) { if (isset($fields[$key])) { $htmlContent .= "<tr><th>{$fields[$key]}</th><td>{$value}</td></tr>"; } } $htmlContent .= '</table>'; /* compose html body */ $htmlBody = $htmlHeader . $htmlContent . $htmlFooter; /* send email */ $mail = new Message(); $mail->setFrom($from)->addTo($sendTo)->setSubject($subject)->setHtmlBody($htmlBody, FALSE); $mailer = new SendmailMailer(); $mailer->send($mail); $responseArray = array('type' => 'success', 'message' => $okMessage); $httpResponse->setCode(200); $response = new \Nette\Application\Responses\JsonResponse($responseArray); $response->send($httpRequest, $httpResponse); }