/** * Append all the extra PDFs */ protected function attachPdfs() { foreach ($this->appendQueue as $blob) { $pdfPath = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; if ($pdftkPath = $this->_controller->getConfig()->getPdftkPath()) { $tmpFile = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; file_put_contents($tmpFile, $blob); $output = array(); $status = 0; $return = exec("{$pdftkPath} {$tmpFile} output {$pdfPath} flatten", $output, $status); if ($status != 0) { throw new \Jazzee\Exception("Problem flattening PDF, return: {$return}, status: {$status}, output was: " . var_export($output, true)); } unlink($tmpFile); } else { $this->_controller->log("You do not have PDFTK installed or you have not set the pdftkPath configuration variable. Some PDFs may be generated without all of their data."); file_put_contents($pdfPath, $blob); } $doc = $this->pdf->open_pdi_document($pdfPath, 'shrug=true'); //loop through each page for ($i = 1; $i <= $this->pdf->pcos_get_number($doc, "length:pages"); $i++) { $page = $this->pdf->open_pdi_page($doc, $i, ''); $this->pdf->begin_page_ext($this->pageWidth, $this->pageHeight, ""); $this->pdf->fit_pdi_page($page, 0, 20, 'adjustpage'); $this->pdf->close_pdi_page($page); $this->pdf->end_page_ext(''); } $this->pdf->close_pdi_document($doc); unlink($pdfPath); } }
public function do_unskip() { $answers = $this->_applicant->findAnswersByPage($this->_applicationPage->getPage()); if (count($answers) and $answers[0]->getPageStatus() == self::SKIPPED) { $this->_applicant->getAnswers()->removeElement($answers[0]); $this->_controller->getEntityManager()->remove($answers[0]); } }
/** * Before any action do some setup * If we know the program and cycle load the applicant var * If we only know the program fill that in * @return null */ protected function beforeAction() { parent::beforeAction(); if (!empty($this->actionParams['programShortName'])) { $this->program = $this->_em->getRepository('Jazzee\\Entity\\Program')->findOneByShortName($this->actionParams['programShortName']); } if (!empty($this->actionParams['cycleName'])) { $this->cycle = $this->_em->getRepository('Jazzee\\Entity\\Cycle')->findOneByName($this->actionParams['cycleName']); } if (!is_null($this->program) and !is_null($this->cycle)) { $this->application = $this->_em->getRepository('Jazzee\\Entity\\Application')->findOneByProgramAndCycle($this->program, $this->cycle); } }
/** * Check an IP address against the allowed address list * @param string $clientIp * @return boolean */ protected function isAllowedIp($clientIp) { $allowedIps = explode(',', $this->_controller->getConfig()->getNoAuthIpAddresses()); if (in_array($clientIp, $allowedIps)) { return true; } foreach ($allowedIps as $allowedIp) { if (\Foundation\Utility::ipInRange($clientIp, $allowedIp)) { return true; } } return false; }
/** * By default just set the varialbe dont check it * @param string $name * @param string $value */ public function setVar($name, $value) { $var = $this->_applicationPage->getPage()->setVar($name, $value); $this->_controller->getEntityManager()->persist($var); }
/** * Find application as an array * @param interger $id * * @return array */ public function findArray($id) { $cache = \Jazzee\Controller::getCache(); $cacheId = Application::ARRAY_CACHE_PREFIX . $id; if ($cache->contains($cacheId)) { return $cache->fetch($cacheId); } $queryBuilder = $this->makeQuery(); $queryBuilder->andWhere('application.id = :id'); $queryBuilder->setParameter('id', $id); $query = $queryBuilder->getQuery(); if ($result = $query->getArrayResult()) { $application = $result[0]; $keys = array('title', 'min', 'max', 'isRequired', 'answerStatusDisplay', 'instructions', 'leadingText', 'trailingText'); foreach ($application['applicationPages'] as &$appPage) { foreach ($keys as $key) { if (is_null($appPage[$key])) { $appPage[$key] = $appPage['page'][$key]; } } } $query = $this->_em->createQuery('SELECT distinct tag from \\Jazzee\\Entity\\Tag as tag LEFT JOIN tag.applicants applicant WHERE applicant.id IN (SELECT a.id from Jazzee\\Entity\\Applicant a WHERE a.application = :applicationId)'); $query->setParameter('applicationId', $application['id']); $application['tags'] = $query->getArrayResult(); $cache->save($cacheId, $application); return $application; } return false; }
/** * Logout the user */ public function logoutUser() { $this->_user = null; $this->_controller->getStore()->expire(); }
protected function generatePDF(array $elements) { $pdf = $this->getPdf(); $pdf->set_info("Title", $pdf->convert_to_unicode('utf8', $elements['applicant']['fullName'], '') . ' Application'); $document = $pdf->open_pdi_document($this->_template->getTmpFilePath(), ''); $pagecount = $pdf->pcos_get_number($document, "length:pages"); for ($pageNum = 0; $pageNum < $pagecount; $pageNum++) { $page = $pdf->open_pdi_page($document, $pageNum + 1, ""); $width = $pdf->pcos_get_number($document, "pages[{$pageNum}]/width"); $height = $pdf->pcos_get_number($document, "pages[{$pageNum}]/height"); $pdf->begin_page_ext($width, $height, ""); $pdf->fit_pdi_page($page, 0, 0, ""); $blockcount = $pdf->pcos_get_number($document, "length:pages[{$pageNum}]/blocks"); for ($blockNum = 0; $blockNum < $blockcount; $blockNum++) { $blockName = $pdf->pcos_get_string($document, "pages[{$pageNum}]/blocks[{$blockNum}]/Name"); $blockType = $pdf->pcos_get_string($document, "pages[{$pageNum}]/blocks[{$blockNum}]/Subtype"); if ($this->_template->hasBlock($blockName)) { $string = ''; $blockData = $this->_template->getBlock($blockName); switch ($blockData['type']) { case 'applicant': $string = $elements['applicant'][$blockData['element']]; break; case 'page': if (array_key_exists($blockData['pageId'], $elements['pages']) and array_key_exists($blockData['elementId'], $elements['pages'][$blockData['pageId']])) { $string = $elements['pages'][$blockData['pageId']][$blockData['elementId']]; } break; } switch ($blockType) { case 'Text': $mime = $this->binarymimetype($string); if ($mime === false) { $string = $pdf->convert_to_unicode('utf8', $string, ''); $length = strlen($string); $pdf->fill_textblock($page, $blockName, $string, "encoding=unicode textlen={$length}"); } else { $this->_controller->log("Binary data found in Text field, mime:" . $mime . ", page: " . $page . ", block: " . $blockName . ", block num: " . $blockNum, \Monolog\Logger::ERROR); } break; case 'PDF': if ($string) { $pdfPath = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; if ($pdftkPath = $this->_controller->getConfig()->getPdftkPath()) { $tmpFile = tempnam($this->_controller->getConfig()->getVarPath() . '/tmp/', '') . '.pdf'; file_put_contents($tmpFile, $string); $output = array(); $status = 0; $return = exec("{$pdftkPath} {$tmpFile} output {$pdfPath} flatten", $output, $status); if ($status != 0) { throw new \Jazzee\Exception("Problem flattening PDF, return: {$return}, status: {$status}, output was: " . var_export($output, true)); } unlink($tmpFile); } else { $this->_controller->log("You do not have PDFTK installed or you have not set the pdftkPath configuration variable. Some PDFs may be generated without all of their data."); file_put_contents($pdfPath, $string); } $doc = $pdf->open_pdi_document($pdfPath, 'shrug=true'); $contents = $pdf->open_pdi_page($doc, 1, ''); $pdf->fill_pdfblock($page, $blockName, $contents, ''); $pdf->close_pdi_document($doc); unlink($pdfPath); } break; } } } $pdf->end_page_ext(""); $pdf->close_pdi_page($page); } $pdf->end_document(""); $pdf->close_pdi_document($document); return $pdf->get_buffer(); }
/** * Delete any references to the application in the cache * */ public function clearCache() { \Jazzee\Controller::getCache()->delete(self::ARRAY_CACHE_PREFIX . $this->id); }