/** * @return bool */ public function AjaxMessageGetPdfFromHtml() { $oAccount = $this->getAccountFromParam(); if ($oAccount) { $sSubject = (string) $this->getParamValue('Subject', ''); $sHtml = (string) $this->getParamValue('Html', ''); $sFileName = $sSubject . '.pdf'; $sMimeType = 'application/pdf'; $sSavedName = 'pdf-' . $oAccount->IdAccount . '-' . md5($sFileName . microtime(true)) . '.pdf'; include_once PSEVEN_APP_ROOT_PATH . 'libraries/other/CssToInlineStyles.php'; $oCssToInlineStyles = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($sHtml); $oCssToInlineStyles->setEncoding('utf-8'); $oCssToInlineStyles->setUseInlineStylesBlock(true); $sExec = \CApi::DataPath() . '/system/wkhtmltopdf/linux/wkhtmltopdf'; if (!file_exists($sExec)) { $sExec = \CApi::DataPath() . '/system/wkhtmltopdf/win/wkhtmltopdf.exe'; if (!file_exists($sExec)) { $sExec = ''; } } if (0 < strlen($sExec)) { $oSnappy = new \Knp\Snappy\Pdf($sExec); $oSnappy->setOption('quiet', true); $oSnappy->setOption('disable-javascript', true); $oSnappy->generateFromHtml($oCssToInlineStyles->convert(), $this->ApiFileCache()->generateFullFilePath($oAccount, $sSavedName), array(), true); return $this->DefaultResponse($oAccount, __FUNCTION__, array('Name' => $sFileName, 'TempName' => $sSavedName, 'MimeType' => $sMimeType, 'Size' => (int) $this->ApiFileCache()->fileSize($oAccount, $sSavedName), 'Hash' => \CApi::EncodeKeyValues(array('TempFile' => true, 'AccountID' => $oAccount->IdAccount, 'Name' => $sFileName, 'TempName' => $sSavedName)))); } } return $this->FalseResponse($oAccount, __FUNCTION__); }
public function addDocuments($fileInfo) { $pdf = new \Knp\Snappy\Pdf($this->config->item('pdf_binary')); $image = new \Knp\Snappy\Image($this->config->item('image_binary')); $userP = array($fileInfo['formData']['user_permission']); $deptP = array($fileInfo['formData']['department_permission']); if ($this->session->admin && isset($fileInfo['formData']['file_department'])) { $currentUserDept = $fileInfo['formData']['file_department']; } else { $currentUserDept = $this->session->department; } if ($this->session->admin && isset($fileInfo['formData']['file_owner'])) { $ownerId = $fileInfo['formData']['file_owner']; } else { $ownerId = $this->session->id; } foreach ($fileInfo['fileData'] as $file) { $dbData = array('category' => $fileInfo['formData']['category'], 'owner' => $ownerId, 'realname' => $file['originalName'], 'created' => date('Y-m-d H:i:s'), 'description' => strip_tags($fileInfo['formData']['description']), 'comment' => strip_tags($fileInfo['formData']['comment']), 'status' => 0, 'department' => $currentUserDept, 'default_rights' => 0, 'publishable' => 0, 'location' => $file['newName']); $this->db->insert('documents', $dbData); $fileId = $this->db->insert_id(); foreach ($userP as $userO) { foreach ($userO as $u => $p) { $userPermsData = array('fid' => $fileId, 'uid' => $u, 'rights' => $p); $this->db->insert('user_perms', $userPermsData); } } foreach ($deptP as $deptO) { foreach ($deptO as $dId => $p) { $deptData = array('fid' => $fileId, 'rights' => $p, 'dept_id' => $dId); $this->db->insert('dept_perms', $deptData); } } $userName = $this->session->username; // Add a file history entry $data = array('id' => $fileId, 'modified_on' => date('Y-m-d H:i:s'), 'modified_by' => $userName, 'note' => 'Initial Import', 'revision' => 'current'); $this->db->insert('log', $data); Accesslog_Model::addLogEntry($fileId, 'A'); switch ($file['fileExt']) { case '.html': case '.php': case '.htm': //create PDF from HTML $html = $this->load->file(FCPATH . $this->config->item('dataDir') . $file['newName'], true); $newPdf = $this->config->item('dataDir') . 'pdf/' . $file['rawName'] . '.pdf'; $options = array('viewport-size' => '1250', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $pdf->generateFromHtml($html, $newPdf, $options, true); //create thumbnail from HTML $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $newImage = $this->config->item('dataDir') . 'thumbnails/' . $file['rawName'] . '.jpg'; $image->generateFromHtml($html, $newImage, $options, true); break; case '.png': case '.jpg': $config['source_image'] = $this->config->item('dataDir') . $file['newName']; $config['new_image'] = $this->config->item('dataDir') . 'thumbnails/' . $file['newName']; $config['maintain_ratio'] = true; $config['height'] = 200; $this->load->library('image_lib', $config); $this->image_lib->resize(); break; default: break; } $this->emailPeople($fileId); } $msg = array('status' => 'success', 'msg' => 'All files were successfully uploaded.'); return json_encode($msg); }