Fix debug management of docs in ticket module

This commit is contained in:
Laurent Destailleur 2020-12-16 19:01:26 +01:00
parent 82710e54a8
commit 9c759e91f0
22 changed files with 710 additions and 70 deletions

View File

@ -111,11 +111,9 @@ if ($action == 'updateMask')
}
// Activate a model
elseif ($action == 'set')
{
elseif ($action == 'set') {
$ret = addDocumentModel($value, $type, $label, $scandir);
} elseif ($action == 'del')
{
} elseif ($action == 'del') {
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
@ -124,8 +122,7 @@ elseif ($action == 'set')
}
// Set default model
elseif ($action == 'setdoc')
{
elseif ($action == 'setdoc') {
if (dolibarr_set_const($db, "COMMANDE_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
{
// The constant that was read before the new set
@ -139,8 +136,7 @@ elseif ($action == 'setdoc')
{
$ret = addDocumentModel($value, $type, $label, $scandir);
}
} elseif ($action == 'setmod')
{
} elseif ($action == 'setmod') {
// TODO Check if numbering module chosen can be activated
// by calling method canBeActivated
@ -254,6 +250,7 @@ print dol_get_fiche_head($head, 'general', $langs->trans("Orders"), -1, 'order')
print load_fiche_titre($langs->trans("OrdersNumberingModules"), '', '');
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Name").'</td>';
@ -346,7 +343,7 @@ foreach ($dirmodels as $reldir)
}
}
}
print "</table><br>\n";
print "</table></div><br>\n";
/*
@ -377,6 +374,7 @@ if ($resql)
}
print '<div class="div-table-responsive-no-min">';
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print '<td>'.$langs->trans("Name").'</td>';
@ -501,6 +499,7 @@ foreach ($dirmodels as $reldir)
}
print '</table>';
print '</div>';
/*

View File

@ -44,10 +44,13 @@ $type = 'ticket';
$error = 0;
/*
* Actions
*/
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
if ($action == 'updateMask') {
$maskconstticket = GETPOST('maskconstticket', 'alpha');
$maskticket = GETPOST('maskticket', 'alpha');
@ -66,7 +69,37 @@ if ($action == 'updateMask') {
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
} elseif ($action == 'setmod') {
}
// Activate a model
elseif ($action == 'set') {
$ret = addDocumentModel($value, $type, $label, $scandir);
} elseif ($action == 'del') {
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
if ($conf->global->TICKET_ADDON_PDF == "$value") dolibarr_del_const($db, 'TICKET_ADDON_PDF', $conf->entity);
}
}
// Set default model
elseif ($action == 'setdoc') {
if (dolibarr_set_const($db, "TICKET_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
{
// The constant that was read before the new set
// We therefore requires a variable to have a coherent view
$conf->global->TICKET_ADDON_PDF = $value;
}
// On active le modele
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
$ret = addDocumentModel($value, $type, $label, $scandir);
}
}
elseif ($action == 'setmod') {
// TODO Verifier si module numerotation choisi peut etre active
// par appel methode canBeActivated
@ -190,7 +223,7 @@ print dol_get_fiche_end();
/*
* Projects Numbering model
* Tickets numbering model
*/
print load_fiche_titre($langs->trans("TicketNumberingModules"), '', '');
@ -291,6 +324,162 @@ print '</table>';
print '</div>';
print '<br>';
/*
* Document templates generators
*/
print load_fiche_titre($langs->trans("TicketsModelModule"), '', '');
// Load array def with activated templates
$def = array();
$sql = "SELECT nom";
$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
$sql .= " WHERE type = '".$db->escape($type)."'";
$sql .= " AND entity = ".$conf->entity;
$resql = $db->query($sql);
if ($resql)
{
$i = 0;
$num_rows = $db->num_rows($resql);
while ($i < $num_rows)
{
$array = $db->fetch_array($resql);
array_push($def, $array[0]);
$i++;
}
} else {
dol_print_error($db);
}
print '<div class="div-table-responsive-no-min">';
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print '<td>'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
print "</tr>\n";
clearstatcache();
foreach ($dirmodels as $reldir)
{
foreach (array('', '/doc') as $valdir)
{
$realpath = $reldir."core/modules/ticket".$valdir;
$dir = dol_buildpath($realpath);
if (is_dir($dir))
{
$handle = opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
$filelist[] = $file;
}
closedir($handle);
arsort($filelist);
foreach ($filelist as $file)
{
if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
{
if (file_exists($dir.'/'.$file))
{
$name = substr($file, 4, dol_strlen($file) - 16);
$classname = substr($file, 0, dol_strlen($file) - 12);
require_once $dir.'/'.$file;
$module = new $classname($db);
$modulequalified = 1;
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
if ($modulequalified)
{
print '<tr class="oddeven"><td width="100">';
print (empty($module->name) ? $name : $module->name);
print "</td><td>\n";
if (method_exists($module, 'info')) print $module->info($langs);
else print $module->description;
print '</td>';
// Active
if (in_array($name, $def))
{
print '<td class="center">'."\n";
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
print img_picto($langs->trans("Enabled"), 'switch_on');
print '</a>';
print '</td>';
} else {
print '<td class="center">'."\n";
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=set&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
print "</td>";
}
// Default
print '<td class="center">';
if ($conf->global->TICKET_ADDON_PDF == $name)
{
print img_picto($langs->trans("Default"), 'on');
} else {
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;token='.newToken().'&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
}
print '</td>';
// Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
if ($module->type == 'pdf')
{
$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
}
$htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
$htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
//$htmltooltip .= '<br>'.$langs->trans("Discounts").': '.yn($module->option_escompte,1,1);
//$htmltooltip .= '<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
//$htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
print '<td class="center">';
print $form->textwithpicto('', $htmltooltip, 1, 0);
print '</td>';
// Preview
print '<td class="center">';
if ($module->type == 'pdf')
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
} else {
print img_object($langs->trans("PreviewNotAvailable"), 'generic');
}
print '</td>';
print "</tr>\n";
}
}
}
}
}
}
}
}
print '</table>';
print '</div><br>';
if (!$conf->use_javascript_ajax) {
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data" >';
print '<input type="hidden" name="token" value="'.newToken().'">';

View File

@ -162,10 +162,10 @@ class doc_generic_bom_odt extends ModelePDFBom
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=boms&file=invoices/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -170,13 +170,9 @@ class doc_generic_order_odt extends ModelePDFCommandes
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
foreach ($listoffiles as $file)
{
// Show list of found files
foreach ($listoffiles as $file)
{
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=orders/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=orders/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -169,10 +169,10 @@ class doc_generic_shipment_odt extends ModelePdfExpedition
}
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=shipments/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -170,8 +170,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
{
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file)
{
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=invoices/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';

View File

@ -156,9 +156,11 @@ class doc_generic_member_odt extends ModelePDFMember
if (count($listofdir))
{
$texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= $file['name'].'<br>';
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=members/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -105,9 +105,11 @@ class modTicket extends DolibarrModules
// Example:
$this->const = array(
1 => array('TICKET_ENABLE_PUBLIC_INTERFACE', 'chaine', '0', 'Enable ticket public interface', 0),
2 => array('TICKET_ADDON', 'chaine', 'mod_ticket_simple', 'Ticket ref module', 0)
2 => array('TICKET_ADDON', 'chaine', 'mod_ticket_simple', 'Ticket ref module', 0),
3 => array('TICKET_ADDON_PDF_ODT_PATH', 'chaine', 'DOL_DATA_ROOT/doctemplates/tickets', 'Ticket templates ODT/ODS directory for templates', 0)
);
$this->tabs = array(
'thirdparty:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?socid=__ID__',
'project:+ticket:Tickets:@ticket:$user->rights->ticket->read:/ticket/list.php?projectid=__ID__',
@ -280,12 +282,36 @@ class modTicket extends DolibarrModules
*/
public function init($options = '')
{
global $conf, $langs;
// Permissions
$this->remove($options);
//ODT template
$src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt';
$dirodt = DOL_DATA_ROOT.'/doctemplates/tickets';
$dest = $dirodt.'/template_order.odt';
if (file_exists($src) && !file_exists($dest))
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_mkdir($dirodt);
$result = dol_copy($src, $dest, 0, 0);
if ($result < 0)
{
$langs->load("errors");
$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
return 0;
}
}
$sql = array(
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110120, 'ticket', 'internal', 'SUPPORTTEC', 'Utilisateur assigné au ticket', 1);", "ignoreerror" => 1),
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110122, 'ticket', 'external', 'SUPPORTCLI', 'Contact client suivi incident', 1);", "ignoreerror" => 1),
array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1),
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".$conf->entity,
"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".$conf->entity.")"
);
return $this->_init($sql, $options);

View File

@ -169,10 +169,10 @@ class doc_generic_mo_odt extends ModelePDFMo
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=mrps&file=invoices/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -440,10 +440,10 @@ class doc_generic_project_odt extends ModelePDFProjects
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=projects/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -409,10 +409,10 @@ class doc_generic_task_odt extends ModelePDFTask
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=tasks/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -174,8 +174,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
{
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file)
{
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=proposals/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';

View File

@ -163,11 +163,11 @@ class doc_generic_reception_odt extends ModelePdfReception
}
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
}
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=receptions/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -152,10 +152,10 @@ class doc_generic_odt extends ModeleThirdPartyDoc
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=thirdparties/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -166,10 +166,10 @@ class doc_generic_stock_odt extends ModelePDFStock
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=stocks/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -170,10 +170,10 @@ class doc_generic_supplier_order_odt extends ModelePDFSuppliersOrders
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=supplier_orders/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}

View File

@ -174,10 +174,10 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal
if ($nbofiles)
{
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
foreach ($listoffiles as $file)
{
$texte .= $file['name'].'<br>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=supplier_proposal/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';

View File

@ -0,0 +1,429 @@
<?php
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php
* \ingroup ticket
* \brief File of class to build ODT documents for tickets
*/
require_once DOL_DOCUMENT_ROOT.'/core/modules/ticket/modules_ticket.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php';
/**
* Class to build documents using ODF templates generator
*/
class doc_generic_ticket_odt extends ModelePDFTicket
{
/**
* @var Societe Issuer
*/
public $emetteur;
/**
* @var array Minimum version of PHP required by module.
* e.g.: PHP 5.6 = array(5, 6)
*/
public $phpmin = array(5, 6);
/**
* Dolibarr version of the loaded document
* @var string
*/
public $version = 'dolibarr';
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
global $conf, $langs, $mysoc;
// Load translation files required by the page
$langs->loadLangs(array("main", "companies"));
$this->db = $db;
$this->name = "ODT templates";
$this->description = $langs->trans("DocumentModelOdt");
$this->scandir = 'TICKET_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
// Page size for A4 format
$this->type = 'odt';
$this->page_largeur = 0;
$this->page_hauteur = 0;
$this->format = array($this->page_largeur, $this->page_hauteur);
$this->marge_gauche = 0;
$this->marge_droite = 0;
$this->marge_haute = 0;
$this->marge_basse = 0;
$this->option_logo = 1; // Affiche logo
$this->option_tva = 0; // Gere option tva USER_TVAOPTION
$this->option_multilang = 1; // Dispo en plusieurs langues
$this->option_freetext = 0; // Support add of a personalised text
$this->option_draft_watermark = 0; // Support add of a watermark on drafts
// Recupere emetteur
$this->emetteur = $mysoc;
if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
}
/**
* Return description of a module
*
* @param Translate $langs Lang object to use for output
* @return string Description
*/
public function info($langs)
{
global $conf, $langs;
// Load translation files required by the page
$langs->loadLangs(array('companies', 'errors'));
$form = new Form($this->db);
$texte = $this->description.".<br>\n";
$texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">';
$texte .= '<input type="hidden" name="token" value="'.newToken().'">';
$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
$texte .= '<input type="hidden" name="param1" value="TICKET_ADDON_PDF_ODT_PATH">';
$texte .= '<table class="nobordernopadding" width="100%">';
// List of directories area
$texte .= '<tr><td>';
$texttitle = $langs->trans("ListOfDirectories");
$listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->TICKET_ADDON_PDF_ODT_PATH)));
$listoffiles = array();
foreach ($listofdir as $key=>$tmpdir)
{
$tmpdir = trim($tmpdir);
$tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
if (!$tmpdir) {
unset($listofdir[$key]); continue;
}
if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
else {
$tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)');
if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
}
}
$texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
// Add list of substitution keys
$texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
$texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
$texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
$texte .= '<textarea class="flat" cols="60" name="value1">';
$texte .= $conf->global->TICKET_ADDON_PDF_ODT_PATH;
$texte .= '</textarea>';
$texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
$texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
$texte .= '<br></div></div>';
// Scan directories
if (count($listofdir))
{
$texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=tickets/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}
// Add input to upload a new template file.
$texte .= '<div>'.$langs->trans("UploadNewTemplate").' <input type="file" name="uploadfile">';
$texte .= '<input type="hidden" value="TICKET_ADDON_PDF_ODT_PATH" name="keyforuploaddir">';
$texte .= '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Upload")).'" name="upload">';
$texte .= '</div>';
$texte .= '</td>';
$texte .= '<td rowspan="2" class="tdtop hideonsmartphone">';
$texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
$texte .= '</td>';
$texte .= '</tr>';
$texte .= '</table>';
$texte .= '</form>';
return $texte;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build a document on disk using the generic odt module.
*
* @param User $object Object source to build document
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int $hidedetails Do not show line details
* @param int $hidedesc Do not show desc
* @param int $hideref Do not show ref
* @return int 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
// phpcs:enable
global $user, $langs, $conf, $mysoc, $hookmanager;
if (empty($srctemplatepath))
{
dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
return -1;
}
// Add odtgeneration hook
if (!is_object($hookmanager))
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager = new HookManager($this->db);
}
$hookmanager->initHooks(array('odtgeneration'));
global $action;
if (!is_object($outputlangs)) $outputlangs = $langs;
$sav_charset_output = $outputlangs->charset_output;
$outputlangs->charset_output = 'UTF-8';
// Load translation files required by the page
$outputlangs->loadLangs(array("main", "companies", "bills", "dict"));
if ($conf->user->dir_output)
{
// If $object is id instead of object
if (!is_object($object))
{
$id = $object;
$object = new User($this->db);
$result = $object->fetch($id);
if ($result < 0)
{
dol_print_error($this->db, $object->error);
return -1;
}
}
$object->fetch_thirdparty();
$dir = $conf->user->dir_output;
$objectref = dol_sanitizeFileName($object->ref);
if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref;
$file = $dir."/".$objectref.".odt";
if (!file_exists($dir))
{
if (dol_mkdir($dir) < 0)
{
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}
}
if (file_exists($dir))
{
//print "srctemplatepath=".$srctemplatepath; // Src filename
$newfile = basename($srctemplatepath);
$newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile);
$newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
$newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
$newfiletmp = $objectref.'_'.$newfiletmp;
// Get extension (ods or odt)
$newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
if (!empty($conf->global->MAIN_DOC_USE_TIMING))
{
$format = $conf->global->MAIN_DOC_USE_TIMING;
if ($format == '1') $format = '%Y%m%d%H%M%S';
$filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat;
} else {
$filename = $newfiletmp.'.'.$newfileformat;
}
$file = $dir.'/'.$filename;
//print "newdir=".$dir;
//print "newfile=".$newfile;
//print "file=".$file;
//print "conf->user->dir_temp=".$conf->user->dir_temp;
dol_mkdir($conf->user->dir_temp);
// If CUSTOMER contact defined on user, we use it
$usecontact = false;
$arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
if (count($arrayidcontact) > 0)
{
$usecontact = true;
$result = $object->fetch_contact($arrayidcontact[0]);
}
// Recipient name
if (!empty($usecontact))
{
if ($usecontact && ($object->contact->fk_soc != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
$socobject = $object->contact;
} else {
$socobject = $object->thirdparty;
// if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use
$contactobject = $object->contact;
}
} else {
$socobject = $object->thirdparty;
}
// Open and load template
require_once ODTPHP_PATH.'odf.php';
try {
$odfHandler = new odf(
$srctemplatepath,
array(
'PATH_TO_TMP' => $conf->user->dir_temp,
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
'DELIMITER_LEFT' => '{',
'DELIMITER_RIGHT' => '}'
)
);
} catch (Exception $e)
{
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_WARNING);
return -1;
}
// Make substitutions into odt
$array_user = $this->get_substitutionarray_user($object, $outputlangs);
$array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
$array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
$array_other = $this->get_substitutionarray_other($outputlangs);
// retrieve contact information for use in object as contact_xxx tags
$array_thirdparty_contact = array();
if ($usecontact && is_object($contactobject)) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact');
$tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other, $array_thirdparty_contact);
complete_substitutions_array($tmparray, $outputlangs, $object);
$object->fetch_optionals();
// Call the ODTSubstitution hook
$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach ($tmparray as $key=>$value)
{
try {
if (preg_match('/logo$/', $key)) // Image
{
if (file_exists($value)) $odfHandler->setImage($key, $value);
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
} else // Text
{
$odfHandler->setVars($key, $value, true, 'UTF-8');
}
} catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_WARNING);
}
}
// Replace labels translated
$tmparray = $outputlangs->get_translations_for_substitutions();
foreach ($tmparray as $key=>$value)
{
try {
$odfHandler->setVars($key, $value, true, 'UTF-8');
} catch (OdfException $e)
{
dol_syslog($e->getMessage(), LOG_WARNING);
}
}
// Call the beforeODTSave hook
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
// 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(), LOG_WARNING);
return -1;
}
} else {
try {
$odfHandler->saveToDisk($file);
} catch (Exception $e) {
$this->error = $e->getMessage();
dol_syslog($e->getMessage(), LOG_WARNING);
return -1;
}
}
$reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if (!empty($conf->global->MAIN_UMASK))
@chmod($file, octdec($conf->global->MAIN_UMASK));
$odfHandler = null; // Destroy object
$this->result = array('fullpath'=>$file);
return 1; // Success
} else {
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return -1;
}
}
return -1;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* get substitution array for object
*
* @param User $object user
* @param Translate $outputlangs translation object
* @param string $array_key key for array
* @return array array of substitutions
*/
public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object')
{
// phpcs:enable
$array_other = array();
foreach ($object as $key => $value) {
if (!is_array($value) && !is_object($value)) {
$array_other[$array_key.'_'.$key] = $value;
}
}
return $array_other;
}
}

View File

@ -19,8 +19,8 @@
*/
/**
* \file htdocs/core/modules/ticket/modules_ticket.php
* \ingroup project
* \file htdocs/core/modules/ticket/modules_ticket.php
* \ingroup ticket
* \brief File that contain parent class for projects models
* and parent class for projects numbering models
*/

View File

@ -187,9 +187,10 @@ class doc_generic_user_odt extends ModelePDFUser
$texte .= "</td></tr>";
$texte .= '</table>';
}
$texte .= '<div id="div_'.get_class($this).'" class="hidden">';
$texte .= '<div id="div_'.get_class($this).'" class="hiddenx">';
// Show list of found files
foreach ($listoffiles as $file) {
$texte .= $file['name'].'<br>';
$texte .= '- '.$file['name'].' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=users/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a><br>';
}
$texte .= '</div>';
}