Skip to content

Commit

Permalink
#188 [ODT] add: manage pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Feb 16, 2023
1 parent f1fc1d7 commit 4b2af74
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 21 deletions.
33 changes: 33 additions & 0 deletions admin/dolimeetdocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,39 @@
$head = dolimeet_admin_prepare_head();
print dol_get_fiche_head($head, 'dolimeetdocuments', $title, -1, 'dolimeet_color@dolimeet');

print load_fiche_titre($langs->trans('DocumentsData'), '', '');

print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans("Name") . '</td>';
print '<td>' . $langs->trans("Description") . '</td>';
print '<td class="center">' . $langs->trans("Status") . '</td>';
print '</tr>';

// Automatic PDF generation
print '<tr class="oddeven"><td>';
print $langs->trans("AutomaticPdfGeneration");
print '</td><td>';
print $langs->trans('AutomaticPdfGenerationDescription');
print '</td>';
print '<td class="center">';
print ajax_constantonoff('DOLIMEET_AUTOMATIC_PDF_GENERATION');
print '</td>';
print '</tr>';

// Manual PDF generation
print '<tr class="oddeven"><td>';
print $langs->trans("ManualPdfGeneration");
print '</td><td>';
print $langs->trans('ManualPdfGenerationDescription');
print '</td>';
print '<td class="center">';
print ajax_constantonoff('DOLIMEET_MANUAL_PDF_GENERATION');
print '</td>';
print '</tr>';

print '</table>';

foreach ($types as $type => $documentType) {
$filelist = [];
if (preg_match('/_/', $documentType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,26 +435,33 @@ public function write_file(SessionDocument $objectDocument, Translate $outputlan
$parameters = ['odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray];
$hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

$fileInfos = pathinfo($filename);
$pdfName = $fileInfos['filename'] . '.pdf';

// Write new file
if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
try {
$odfHandler->exportAsAttachedPDF($file);
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage());
return -1;
}
} else {
try {
$odfHandler->saveToDisk($file);
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage());
return -1;
}
}
if (!empty($conf->global->MAIN_ODT_AS_PDF) && $conf->global->DOLIMEET_AUTOMATIC_PDF_GENERATION > 0) {
try {
$odfHandler->exportAsAttachedPDF($file);

$parameters = ['odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray];
global $moduleNameLowerCase;
$documentUrl = DOL_URL_ROOT . '/document.php';
setEventMessages($langs->trans('FileGenerated') . ' - ' . '<a href=' . $documentUrl . '?modulepart=' . $moduleNameLowerCase . '&file=' . urlencode('attendancesheetdocument/' . $object->ref . '/' . $pdfName) . '&entity='. $conf->entity .'"' . '>' . $pdfName . '</a>', []);
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage());
setEventMessages($langs->transnoentities('FileCouldNotBeGeneratedInPDF') . '<br>' . $langs->transnoentities('CheckDocumentationToEnablePDFGeneration'), [], 'errors');
}
} else {
try {
$odfHandler->saveToDisk($file);
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage());
return -1;
}
}

$parameters = ['odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray];
$hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

if (!empty($conf->global->MAIN_UMASK)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,21 @@ public function write_file(SessionDocument $objectDocument, Translate $outputlan
$parameters = ['odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray];
$hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

$fileInfos = pathinfo($filename);
$pdfName = $fileInfos['filename'] . '.pdf';

// Write new file
if (empty($conf->global->MAIN_ODT_AS_PDF)) {
if (!empty($conf->global->MAIN_ODT_AS_PDF) && $conf->global->DOLIMEET_AUTOMATIC_PDF_GENERATION > 0) {
try {
$odfHandler->exportAsAttachedPDF($file);

global $moduleNameLowerCase;
$documentUrl = DOL_URL_ROOT . '/document.php';
setEventMessages($langs->trans('FileGenerated') . ' - ' . '<a href=' . $documentUrl . '?modulepart=' . $moduleNameLowerCase . '&file=' . urlencode('completioncertificatedocument/' . $object->ref . '/' . $pdfName) . '&entity='. $conf->entity .'"' . '>' . $pdfName . '</a>', []);
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage());
return -1;
setEventMessages($langs->transnoentities('FileCouldNotBeGeneratedInPDF') . '<br>' . $langs->transnoentities('CheckDocumentationToEnablePDFGeneration'), [], 'errors');
}
} else {
try {
Expand Down
7 changes: 6 additions & 1 deletion core/modules/modDoliMeet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@ public function __construct($db)

// CONST MODULE
$i++ => ['DOLIMEET_VERSION','chaine', $this->version, '', 0, 'current'],
$i => ['DOLIMEET_DB_VERSION', 'chaine', $this->version, '', 0, 'current']
$i++ => ['DOLIMEET_DB_VERSION', 'chaine', $this->version, '', 0, 'current'],
$i++ => ['DOLIMEET_AUTOMATIC_PDF_GENERATION', 'integer', 0, '', 0, 'current'],
$i++ => ['DOLIMEET_MANUAL_PDF_GENERATION', 'integer', 0, '', 0, 'current'],

// CONST GENERAL CONST
$i => ['MAIN_ODT_AS_PDF', 'chaine', 'libreoffice', '', 0, 'current']
];

// Some keys to add into the overwriting translation tables
Expand Down

0 comments on commit 4b2af74

Please sign in to comment.