document_id = isset($_GET['id']) ? $_GET['id'] : 0; $this->get_file_document_id = isset($_GET['getfile']) ? $_GET['getfile'] : 0; $this->page_number = (int)isset($_GET['p']) ? $_GET['p'] : 0; $this->attachment = (int)isset($_GET['attachment']) ? $_GET['attachment'] : 0; $this->source_id = (int)isset($_GET['s']) ? $_GET['s'] : 1; $this->binary_id = isset($_GET['binary_id']) ? $_GET['binary_id'] : 0; require_once($this->module->getLocalPath().'B2BDocument.php'); } public function initContent() { parent::initContent(); if (!Context::getContext()->customer->isLogged()) Tools::redirect('index.php?controller=authentication&redirect=module&module=firmesb2b&action=documents'); if (Context::getContext()->customer->id) { $id_customer = Context::getContext()->customer->id; $this->setTemplate('module:firmesb2b/views/templates/front/firmesb2b-documents.tpl'); $start = $this->page_number * $this->results_on_page; // Generowanie linku dla dokumentów if ($this->get_file_document_id > 0 && $this->attachment < 1) { $document = B2BDocument::getCustomerDocumentById((int)$id_customer, (int)$this->get_file_document_id, (int)$this->source_id, $this->binary_id); if ($document['db_documentId'] > 0) { $file = $document['db_file']; if($this->binary_id < 0) { $filename = str_replace(array('/','\\'),'_',$document['db_name']).'.epp'; } else { $filename = str_replace(array('/','\\'),'_',$document['db_name']).'.pdf'; } if (!file_exists($file)) { Tools::displayError('Brak pliku na serwerze'); } if (ob_get_level()) ob_end_clean(); /* Set headers for download */ header('Content-Transfer-Encoding: binary'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-Length: '.filesize($file)); $fp = fopen($file, 'rb'); while (!feof($fp)) echo fgets($fp, 16384); exit; } else { Tools::displayError('Nieprawidłowe odwołanie do pliku.'); } } // Generowanie linku dla załączników if ($this->get_file_document_id > 0 && $this->attachment > 0) { $document = B2BDocument::getRelatedDocumentById((int)$this->get_file_document_id, (int)$this->source_id); if ($document['bi_binaryId'] > 0) { $file = $document['bi_file']; $filename = str_replace(array('/','\\'),'_',$document['bi_name']).'.pdf'; if (!file_exists($file)) { Tools::displayError('Brak pliku na serwerze'); } if (ob_get_level()) ob_end_clean(); /* Set headers for download */ header('Content-Transfer-Encoding: binary'); //header('Content-Type: application/pdf'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($file)); header('Content-Disposition: attachment; filename="'.$filename.'"'); $fp = fopen($file, 'rb'); while (!feof($fp)) echo fgets($fp, 16384); exit; } else { Tools::displayError('Nieprawidłowe odwołanie do pliku.'); } } if ($this->document_id > 0) { $this->setTemplate('module:firmesb2b/views/templates/front/firmesb2b-document.tpl'); $document = B2BDocument::getCustomerDocumentById((int)$id_customer, (int)$this->document_id, (int)$this->source_id); $documentDetails = array(); $B2BrelatedDocuments = array(); $B2BrelatedDocumentsCount = 0; if (isset($document['document_id']) && $document['document_id'] == $this->document_id) { $documentDetails = B2BDocument::getDocumentDetails((int)$this->document_id, (int)$this->source_id); foreach ($documentDetails as $key => $value) { $pn = $value['price_net']; $pg = $value['price_gros']; $dis = $value['discount']; if($dis>0) { $documentDetails[$key]['price_net'] = round($pn-($pn*($dis/100)), 2); $documentDetails[$key]['price_gros'] = round($pg-($pg*($dis/100)), 2); } } $B2BrelatedDocuments = B2BDocument::getRelatedDocuments((int)$this->document_id, (int)$this->source_id); $B2BrelatedDocumentsCount = count($B2BrelatedDocuments); // echo $B2BrelatedDocumentsCount; } $this->context->smarty->assign(array( 'B2BrelatedDocuments' => $B2BrelatedDocuments, 'B2BrelatedDocumentsCount' => $B2BrelatedDocumentsCount, 'document' => $document, 'details' => $documentDetails, 'return_page' => $this->page_number, 'module_dir' => $this->module->getPathUri(), 'module_template_dir' => __PS_BASE_URI__.'modules/'.$this->module->name.'/' )); } else { $this->setTemplate('module:firmesb2b/views/templates/front/firmesb2b-documents.tpl'); $result = B2BDocument::getCustomerDocumentsCount((int)$id_customer); $documentCount = (int)$result['count']; $B2Bdocuments = array(); if ($documentCount > 0) { $B2Bdocuments = B2BDocument::getCustomerDocuments((int)$id_customer, (int)$this->results_on_page, (int)$start); } $this->context->smarty->assign(array( 'B2Bdocuments' => $B2Bdocuments, 'current_page' => $this->page_number, 'pages' => (int)(ceil($documentCount/$this->results_on_page)-1), 'module_dir' => $this->module->getPathUri(), 'module_template_dir' => __PS_BASE_URI__.'modules/'.$this->module->name.'/' )); } } } }