commit
616219c99c
@ -1,21 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* or see http://www.gnu.org/
|
* or see http://www.gnu.org/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php
|
* \file htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php
|
||||||
@ -86,84 +86,84 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
* @param Object $object Main object to use as data source
|
* @param Object $object Main object to use as data source
|
||||||
* @param Translate $outputlangs Lang object to use for output
|
* @param Translate $outputlangs Lang object to use for output
|
||||||
* @return array Array of substitution
|
* @return array Array of substitution
|
||||||
*/
|
*/
|
||||||
function get_substitutionarray_object($object,$outputlangs)
|
function get_substitutionarray_object($object,$outputlangs)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$resarray=array(
|
$resarray=array(
|
||||||
'object_id'=>$object->id,
|
'object_id'=>$object->id,
|
||||||
'object_ref'=>$object->ref,
|
'object_ref'=>$object->ref,
|
||||||
'object_ref_ext'=>$object->ref_ext,
|
'object_ref_ext'=>$object->ref_ext,
|
||||||
'object_ref_customer'=>$object->ref_client,
|
'object_ref_customer'=>$object->ref_client,
|
||||||
'object_date'=>dol_print_date($object->date,'day'),
|
'object_date'=>dol_print_date($object->date,'day'),
|
||||||
'object_date_delivery'=>dol_print_date($object->date_livraison,'dayhour'),
|
'object_date_delivery'=>dol_print_date($object->date_livraison,'dayhour'),
|
||||||
'object_date_creation'=>dol_print_date($object->date_creation,'day'),
|
'object_date_creation'=>dol_print_date($object->date_creation,'day'),
|
||||||
'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
|
'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
|
||||||
'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
|
'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
|
||||||
'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
|
'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
|
||||||
'object_date_close'=>dol_print_date($object->date_cloture,'dayhour'),
|
'object_date_close'=>dol_print_date($object->date_cloture,'dayhour'),
|
||||||
'object_payment_mode_code'=>$object->mode_reglement_code,
|
'object_payment_mode_code'=>$object->mode_reglement_code,
|
||||||
'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
|
'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
|
||||||
'object_payment_term_code'=>$object->cond_reglement_code,
|
'object_payment_term_code'=>$object->cond_reglement_code,
|
||||||
'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement),
|
'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement),
|
||||||
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
'object_total_ht'=>price($object->total_ht,0,$outputlangs),
|
||||||
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
'object_total_vat'=>price($object->total_tva,0,$outputlangs),
|
||||||
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
'object_total_ttc'=>price($object->total_ttc,0,$outputlangs),
|
||||||
'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs),
|
'object_total_discount_ht' => price($object->getTotalDiscount(), 0, $outputlangs),
|
||||||
'object_vatrate'=>vatrate($object->tva),
|
'object_vatrate'=>vatrate($object->tva),
|
||||||
'object_note_private'=>$object->note,
|
'object_note_private'=>$object->note,
|
||||||
'object_note'=>$object->note_public,
|
'object_note'=>$object->note_public,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add vat by rates
|
// Add vat by rates
|
||||||
foreach ($object->lines as $line)
|
foreach ($object->lines as $line)
|
||||||
{
|
{
|
||||||
if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0;
|
if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0;
|
||||||
$resarray['object_total_vat_'.$line->tva_tx]+=$line->total_tva;
|
$resarray['object_total_vat_'.$line->tva_tx]+=$line->total_tva;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $resarray;
|
return $resarray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
* @param array $line Array of lines
|
* @param array $line Array of lines
|
||||||
* @param Translate $outputlangs Lang object to use for output
|
* @param Translate $outputlangs Lang object to use for output
|
||||||
* @return array Return a substitution array
|
* @return array Return a substitution array
|
||||||
*/
|
*/
|
||||||
function get_substitutionarray_lines($line,$outputlangs)
|
function get_substitutionarray_lines($line,$outputlangs)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
|
'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
|
||||||
'line_product_ref'=>$line->product_ref,
|
'line_product_ref'=>$line->product_ref,
|
||||||
'line_product_label'=>$line->product_label,
|
'line_product_label'=>$line->product_label,
|
||||||
'line_desc'=>$line->desc,
|
'line_desc'=>$line->desc,
|
||||||
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
|
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
|
||||||
'line_up'=>price($line->subprice, 0, $outputlangs),
|
'line_up'=>price($line->subprice, 0, $outputlangs),
|
||||||
'line_qty'=>$line->qty,
|
'line_qty'=>$line->qty,
|
||||||
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
|
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
|
||||||
'line_price_ht'=>price($line->total_ht, 0, $outputlangs),
|
'line_price_ht'=>price($line->total_ht, 0, $outputlangs),
|
||||||
'line_price_ttc'=>price($line->total_ttc, 0, $outputlangs),
|
'line_price_ttc'=>price($line->total_ttc, 0, $outputlangs),
|
||||||
'line_price_vat'=>price($line->total_tva, 0, $outputlangs),
|
'line_price_vat'=>price($line->total_tva, 0, $outputlangs),
|
||||||
'line_date_start'=>$line->date_start,
|
'line_date_start'=>$line->date_start,
|
||||||
'line_date_end'=>$line->date_end
|
'line_date_end'=>$line->date_end
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return description of a module
|
* Return description of a module
|
||||||
*
|
*
|
||||||
* @param Translate $langs Lang object to use for output
|
* @param Translate $langs Lang object to use for output
|
||||||
* @return string Description
|
* @return string Description
|
||||||
*/
|
*/
|
||||||
function info($langs)
|
function info($langs)
|
||||||
@ -191,7 +191,9 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
{
|
{
|
||||||
$tmpdir=trim($tmpdir);
|
$tmpdir=trim($tmpdir);
|
||||||
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
||||||
if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
if (! $tmpdir) {
|
||||||
|
unset($listofdir[$key]); continue;
|
||||||
|
}
|
||||||
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
|
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -202,19 +204,19 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
|
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
|
||||||
// Add list of substitution keys
|
// Add list of substitution keys
|
||||||
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
|
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
|
||||||
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
|
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
|
||||||
|
|
||||||
$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
|
$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
|
||||||
$texte.= '<table><tr><td>';
|
$texte.= '<table><tr><td>';
|
||||||
$texte.= '<textarea class="flat" cols="60" name="value1">';
|
$texte.= '<textarea class="flat" cols="60" name="value1">';
|
||||||
$texte.=$conf->global->COMMANDE_ADDON_PDF_ODT_PATH;
|
$texte.=$conf->global->COMMANDE_ADDON_PDF_ODT_PATH;
|
||||||
$texte.= '</textarea>';
|
$texte.= '</textarea>';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '<td align="center"> ';
|
$texte.= '<td align="center"> ';
|
||||||
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '</tr>';
|
$texte.= '</tr>';
|
||||||
$texte.= '</table>';
|
$texte.= '</table>';
|
||||||
|
|
||||||
// Scan directories
|
// Scan directories
|
||||||
if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
|
if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
|
||||||
@ -228,7 +230,7 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
$texte.= '</tr>';
|
$texte.= '</tr>';
|
||||||
|
|
||||||
/*$texte.= '<tr>';
|
/*$texte.= '<tr>';
|
||||||
$texte.= '<td align="center">';
|
$texte.= '<td align="center">';
|
||||||
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '</tr>';*/
|
$texte.= '</tr>';*/
|
||||||
@ -245,9 +247,9 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
* @param Commande $object Object source to build document
|
* @param Commande $object Object source to build document
|
||||||
* @param Translate $outputlangs Lang output object
|
* @param Translate $outputlangs Lang output object
|
||||||
* @param string $srctemplatepath Full path of source filename for generator using a template file
|
* @param string $srctemplatepath Full path of source filename for generator using a template file
|
||||||
* @param int $hidedetails Do not show line details
|
* @param int $hidedetails Do not show line details
|
||||||
* @param int $hidedesc Do not show desc
|
* @param int $hidedesc Do not show desc
|
||||||
* @param int $hideref Do not show ref
|
* @param int $hideref Do not show ref
|
||||||
* @return int 1 if OK, <=0 if KO
|
* @return int 1 if OK, <=0 if KO
|
||||||
*/
|
*/
|
||||||
function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
|
function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
|
||||||
@ -260,14 +262,14 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add odtgeneration hook
|
// Add odtgeneration hook
|
||||||
if (! is_object($hookmanager))
|
if (! is_object($hookmanager))
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
||||||
$hookmanager=new HookManager($this->db);
|
$hookmanager=new HookManager($this->db);
|
||||||
}
|
}
|
||||||
$hookmanager->initHooks(array('odtgeneration'));
|
$hookmanager->initHooks(array('odtgeneration'));
|
||||||
global $action;
|
global $action;
|
||||||
|
|
||||||
if (! is_object($outputlangs)) $outputlangs=$langs;
|
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||||
$sav_charset_output=$outputlangs->charset_output;
|
$sav_charset_output=$outputlangs->charset_output;
|
||||||
@ -314,7 +316,7 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
|
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
|
||||||
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
|
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
|
||||||
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
|
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
|
||||||
$newfiletmp=$objectref.'_'.$newfiletmp;
|
$newfiletmp=$objectref.'_'.$newfiletmp;
|
||||||
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
|
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
|
||||||
$file=$dir.'/'.$newfiletmp.'.odt';
|
$file=$dir.'/'.$newfiletmp.'.odt';
|
||||||
//print "newdir=".$dir;
|
//print "newdir=".$dir;
|
||||||
@ -325,64 +327,64 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
dol_mkdir($conf->commande->dir_temp);
|
dol_mkdir($conf->commande->dir_temp);
|
||||||
|
|
||||||
|
|
||||||
// If BILLING contact defined on invoice, we use it
|
// If BILLING contact defined on invoice, we use it
|
||||||
$usecontact=false;
|
$usecontact=false;
|
||||||
$arrayidcontact=$object->getIdContact('external','BILLING');
|
$arrayidcontact=$object->getIdContact('external','BILLING');
|
||||||
if (count($arrayidcontact) > 0)
|
if (count($arrayidcontact) > 0)
|
||||||
{
|
{
|
||||||
$usecontact=true;
|
$usecontact=true;
|
||||||
$result=$object->fetch_contact($arrayidcontact[0]);
|
$result=$object->fetch_contact($arrayidcontact[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recipient name
|
// Recipient name
|
||||||
if (! empty($usecontact))
|
if (! empty($usecontact))
|
||||||
{
|
{
|
||||||
// On peut utiliser le nom de la societe du contact
|
// On peut utiliser le nom de la societe du contact
|
||||||
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
|
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
|
||||||
else $socobject = $object->client;
|
else $socobject = $object->client;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$socobject=$object->client;
|
$socobject=$object->client;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make substitution
|
// Make substitution
|
||||||
$substitutionarray=array(
|
$substitutionarray=array(
|
||||||
'__FROM_NAME__' => $this->emetteur->nom,
|
'__FROM_NAME__' => $this->emetteur->nom,
|
||||||
'__FROM_EMAIL__' => $this->emetteur->email,
|
'__FROM_EMAIL__' => $this->emetteur->email,
|
||||||
'__TOTAL_TTC__' => $object->total_ttc,
|
'__TOTAL_TTC__' => $object->total_ttc,
|
||||||
'__TOTAL_HT__' => $object->total_ht,
|
'__TOTAL_HT__' => $object->total_ht,
|
||||||
'__TOTAL_VAT__' => $object->total_vat
|
'__TOTAL_VAT__' => $object->total_vat
|
||||||
);
|
);
|
||||||
complete_substitutions_array($substitutionarray, $langs, $object);
|
complete_substitutions_array($substitutionarray, $langs, $object);
|
||||||
// Call the ODTSubstitution hook
|
// Call the ODTSubstitution hook
|
||||||
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
|
||||||
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
// Line of free text
|
// Line of free text
|
||||||
$newfreetext='';
|
$newfreetext='';
|
||||||
$paramfreetext='COMMANDE_FREE_TEXT';
|
$paramfreetext='COMMANDE_FREE_TEXT';
|
||||||
if (! empty($conf->global->$paramfreetext))
|
if (! empty($conf->global->$paramfreetext))
|
||||||
{
|
{
|
||||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open and load template
|
// Open and load template
|
||||||
require_once ODTPHP_PATH.'odf.php';
|
require_once ODTPHP_PATH.'odf.php';
|
||||||
$odfHandler = new odf(
|
$odfHandler = new odf(
|
||||||
$srctemplatepath,
|
$srctemplatepath,
|
||||||
array(
|
array(
|
||||||
'PATH_TO_TMP' => $conf->commande->dir_temp,
|
'PATH_TO_TMP' => $conf->commande->dir_temp,
|
||||||
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
|
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
|
||||||
'DELIMITER_LEFT' => '{',
|
'DELIMITER_LEFT' => '{',
|
||||||
'DELIMITER_RIGHT' => '}'
|
'DELIMITER_RIGHT' => '}'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// After construction $odfHandler->contentXml contains content and
|
// After construction $odfHandler->contentXml contains content and
|
||||||
// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
|
// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
|
||||||
// [!-- BEGIN lines --]*[!-- END lines --]
|
// [!-- BEGIN lines --]*[!-- END lines --]
|
||||||
//print html_entity_decode($odfHandler->__toString());
|
//print html_entity_decode($odfHandler->__toString());
|
||||||
//print exit;
|
//print exit;
|
||||||
|
|
||||||
|
|
||||||
// Make substitutions into odt of freetext
|
// Make substitutions into odt of freetext
|
||||||
@ -393,29 +395,29 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make substitutions into odt of user info
|
// Make substitutions into odt of user info
|
||||||
$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
|
$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
|
||||||
//var_dump($tmparray); exit;
|
//var_dump($tmparray); exit;
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (preg_match('/logo$/',$key)) // Image
|
if (preg_match('/logo$/',$key)) // Image
|
||||||
{
|
{
|
||||||
//var_dump($value);exit;
|
//var_dump($value);exit;
|
||||||
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
||||||
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
||||||
}
|
}
|
||||||
else // Text
|
else // Text
|
||||||
{
|
{
|
||||||
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make substitutions into odt of mysoc
|
// Make substitutions into odt of mysoc
|
||||||
$tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
|
$tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
|
||||||
//var_dump($tmparray); exit;
|
//var_dump($tmparray); exit;
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
@ -435,7 +437,7 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make substitutions into odt of thirdparty
|
// Make substitutions into odt of thirdparty
|
||||||
$tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
|
$tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
@ -455,73 +457,73 @@ class doc_generic_order_odt extends ModelePDFCommandes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace tags of object + external modules
|
// Replace tags of object + external modules
|
||||||
$tmparray=$this->get_substitutionarray_object($object,$outputlangs);
|
$tmparray=$this->get_substitutionarray_object($object,$outputlangs);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object);
|
complete_substitutions_array($tmparray, $outputlangs, $object);
|
||||||
// Call the ODTSubstitution hook
|
// Call the ODTSubstitution hook
|
||||||
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
|
$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
|
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (preg_match('/logo$/',$key)) // Image
|
if (preg_match('/logo$/',$key)) // Image
|
||||||
{
|
{
|
||||||
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
||||||
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
||||||
}
|
}
|
||||||
else // Text
|
else // Text
|
||||||
{
|
{
|
||||||
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace tags of lines
|
// Replace tags of lines
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$listlines = $odfHandler->setSegment('lines');
|
$listlines = $odfHandler->setSegment('lines');
|
||||||
foreach ($object->lines as $line)
|
foreach ($object->lines as $line)
|
||||||
{
|
{
|
||||||
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
|
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
|
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
|
||||||
// Call the ODTSubstitutionLine hook
|
// Call the ODTSubstitutionLine hook
|
||||||
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
|
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
|
||||||
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$listlines->setVars($key, $val, true, 'UTF-8');
|
$listlines->setVars($key, $val, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
catch(SegmentException $e)
|
catch(SegmentException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$listlines->merge();
|
$listlines->merge();
|
||||||
}
|
}
|
||||||
$odfHandler->mergeSegment($listlines);
|
$odfHandler->mergeSegment($listlines);
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
$this->error=$e->getMessage();
|
$this->error=$e->getMessage();
|
||||||
dol_syslog($this->error, LOG_WARNING);
|
dol_syslog($this->error, LOG_WARNING);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the beforeODTSave hook
|
// Call the beforeODTSave hook
|
||||||
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
|
$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
|
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
//$result=$odfHandler->exportAsAttachedFile('toto');
|
//$result=$odfHandler->exportAsAttachedFile('toto');
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
|
|
||||||
$odfHandler=null; // Destroy object
|
$odfHandler=null; // Destroy object
|
||||||
|
|
||||||
|
|||||||
@ -2,20 +2,20 @@
|
|||||||
/* Copyright (C) 2010-2012 Laurent Destailleur <ely@users.sourceforge.net>
|
/* Copyright (C) 2010-2012 Laurent Destailleur <ely@users.sourceforge.net>
|
||||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* or see http://www.gnu.org/
|
* or see http://www.gnu.org/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
|
* \file htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
|
||||||
@ -86,55 +86,55 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
* @param Object $object Main object to use as data source
|
* @param Object $object Main object to use as data source
|
||||||
* @param Translate $outputlangs Lang object to use for output
|
* @param Translate $outputlangs Lang object to use for output
|
||||||
* @return array Array of substitution
|
* @return array Array of substitution
|
||||||
*/
|
*/
|
||||||
function get_substitutionarray_object($object,$outputlangs)
|
function get_substitutionarray_object($object,$outputlangs)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$invoice_source=new Facture($this->db);
|
$invoice_source=new Facture($this->db);
|
||||||
if ($object->fk_facture_source > 0)
|
if ($object->fk_facture_source > 0)
|
||||||
{
|
{
|
||||||
$invoice_source->fetch($object->fk_facture_source);
|
$invoice_source->fetch($object->fk_facture_source);
|
||||||
}
|
}
|
||||||
$sumpayed = $object->getSommePaiement();
|
$sumpayed = $object->getSommePaiement();
|
||||||
$alreadypayed=price($sumpayed,0,$outputlangs);
|
$alreadypayed=price($sumpayed,0,$outputlangs);
|
||||||
|
|
||||||
$resarray=array(
|
$resarray=array(
|
||||||
'object_id'=>$object->id,
|
'object_id'=>$object->id,
|
||||||
'object_ref'=>$object->ref,
|
'object_ref'=>$object->ref,
|
||||||
'object_ref_ext'=>$object->ref_ext,
|
'object_ref_ext'=>$object->ref_ext,
|
||||||
'object_ref_customer'=>$object->ref_client,
|
'object_ref_customer'=>$object->ref_client,
|
||||||
'object_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''),
|
'object_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''),
|
||||||
'object_source_invoice_ref'=>$invoice_source->ref,
|
'object_source_invoice_ref'=>$invoice_source->ref,
|
||||||
'object_date'=>dol_print_date($object->date,'day'),
|
'object_date'=>dol_print_date($object->date,'day'),
|
||||||
'object_date_limit'=>dol_print_date($object->date_lim_reglement,'day'),
|
'object_date_limit'=>dol_print_date($object->date_lim_reglement,'day'),
|
||||||
'object_date_creation'=>dol_print_date($object->date_creation,'day'),
|
'object_date_creation'=>dol_print_date($object->date_creation,'day'),
|
||||||
'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
|
'object_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
|
||||||
'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
|
'object_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
|
||||||
'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
|
'object_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
|
||||||
'object_payment_mode_code'=>$object->mode_reglement_code,
|
'object_payment_mode_code'=>$object->mode_reglement_code,
|
||||||
'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
|
'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
|
||||||
'object_payment_term_code'=>$object->cond_reglement_code,
|
'object_payment_term_code'=>$object->cond_reglement_code,
|
||||||
'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement),
|
'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement),
|
||||||
'object_total_ht'=>price2num($object->total_ht),
|
'object_total_ht'=>price2num($object->total_ht),
|
||||||
'object_total_vat'=>price2num($object->total_tva),
|
'object_total_vat'=>price2num($object->total_tva),
|
||||||
'object_total_ttc'=>price2num($object->total_ttc),
|
'object_total_ttc'=>price2num($object->total_ttc),
|
||||||
'object_total_discount_ht' => price2num($object->getTotalDiscount(), 0, $outputlangs),
|
'object_total_discount_ht' => price2num($object->getTotalDiscount(), 0, $outputlangs),
|
||||||
'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''),
|
'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''),
|
||||||
'object_note_private'=>$object->note,
|
'object_note_private'=>$object->note,
|
||||||
'object_note'=>$object->note_public,
|
'object_note'=>$object->note_public,
|
||||||
// Payments
|
// Payments
|
||||||
'object_already_payed'=>$alreadypayed,
|
'object_already_payed'=>$alreadypayed,
|
||||||
'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed)
|
'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add vat by rates
|
// Add vat by rates
|
||||||
foreach ($object->lines as $line)
|
foreach ($object->lines as $line)
|
||||||
{
|
{
|
||||||
if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0;
|
if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0;
|
||||||
@ -152,41 +152,41 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
|
|
||||||
$resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key='object',$outputlangs);
|
$resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key='object',$outputlangs);
|
||||||
}
|
}
|
||||||
return $resarray;
|
return $resarray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
* @param array $line Array of lines
|
* @param array $line Array of lines
|
||||||
* @param Translate $outputlangs Lang object to use for output
|
* @param Translate $outputlangs Lang object to use for output
|
||||||
* @return array Return substitution array
|
* @return array Return substitution array
|
||||||
*/
|
*/
|
||||||
function get_substitutionarray_lines($line,$outputlangs)
|
function get_substitutionarray_lines($line,$outputlangs)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
|
'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
|
||||||
'line_product_ref'=>$line->product_ref,
|
'line_product_ref'=>$line->product_ref,
|
||||||
'line_product_label'=>$line->product_label,
|
'line_product_label'=>$line->product_label,
|
||||||
'line_desc'=>$line->desc,
|
'line_desc'=>$line->desc,
|
||||||
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
|
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
|
||||||
'line_up'=>price($line->subprice, 0, $outputlangs),
|
'line_up'=>price($line->subprice, 0, $outputlangs),
|
||||||
'line_qty'=>$line->qty,
|
'line_qty'=>$line->qty,
|
||||||
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
|
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
|
||||||
'line_price_ht'=>price2num($line->total_ht),
|
'line_price_ht'=>price2num($line->total_ht),
|
||||||
'line_price_ttc'=>price2num($line->total_ttc),
|
'line_price_ttc'=>price2num($line->total_ttc),
|
||||||
'line_price_vat'=>price2num($line->total_tva),
|
'line_price_vat'=>price2num($line->total_tva),
|
||||||
'line_date_start'=>dol_print_date($line->date_start, 'day', false, $outputlangs),
|
'line_date_start'=>dol_print_date($line->date_start, 'day', false, $outputlangs),
|
||||||
'line_date_end'=>dol_print_date($line->date_end, 'day', false, $outputlangs),
|
'line_date_end'=>dol_print_date($line->date_end, 'day', false, $outputlangs),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return description of a module
|
* Return description of a module
|
||||||
*
|
*
|
||||||
* @param Translate $langs Lang object to use for output
|
* @param Translate $langs Lang object to use for output
|
||||||
* @return string Description
|
* @return string Description
|
||||||
*/
|
*/
|
||||||
function info($langs)
|
function info($langs)
|
||||||
@ -214,7 +214,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
{
|
{
|
||||||
$tmpdir=trim($tmpdir);
|
$tmpdir=trim($tmpdir);
|
||||||
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
||||||
if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
if (! $tmpdir) {
|
||||||
|
unset($listofdir[$key]); continue;
|
||||||
|
}
|
||||||
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
|
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -225,19 +227,19 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
|
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
|
||||||
// Add list of substitution keys
|
// Add list of substitution keys
|
||||||
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
|
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
|
||||||
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
|
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
|
||||||
|
|
||||||
$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
|
$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
|
||||||
$texte.= '<table><tr><td>';
|
$texte.= '<table><tr><td>';
|
||||||
$texte.= '<textarea class="flat" cols="60" name="value1">';
|
$texte.= '<textarea class="flat" cols="60" name="value1">';
|
||||||
$texte.=$conf->global->FACTURE_ADDON_PDF_ODT_PATH;
|
$texte.=$conf->global->FACTURE_ADDON_PDF_ODT_PATH;
|
||||||
$texte.= '</textarea>';
|
$texte.= '</textarea>';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '<td align="center"> ';
|
$texte.= '<td align="center"> ';
|
||||||
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '</tr>';
|
$texte.= '</tr>';
|
||||||
$texte.= '</table>';
|
$texte.= '</table>';
|
||||||
|
|
||||||
// Scan directories
|
// Scan directories
|
||||||
if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
|
if (count($listofdir)) $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>';
|
||||||
@ -251,7 +253,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
$texte.= '</tr>';
|
$texte.= '</tr>';
|
||||||
|
|
||||||
/*$texte.= '<tr>';
|
/*$texte.= '<tr>';
|
||||||
$texte.= '<td align="center">';
|
$texte.= '<td align="center">';
|
||||||
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '</tr>';*/
|
$texte.= '</tr>';*/
|
||||||
@ -268,9 +270,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
* @param Facture $object Object source to build document
|
* @param Facture $object Object source to build document
|
||||||
* @param Translate $outputlangs Lang output object
|
* @param Translate $outputlangs Lang output object
|
||||||
* @param string $srctemplatepath Full path of source filename for generator using a template file
|
* @param string $srctemplatepath Full path of source filename for generator using a template file
|
||||||
* @param int $hidedetails Do not show line details
|
* @param int $hidedetails Do not show line details
|
||||||
* @param int $hidedesc Do not show desc
|
* @param int $hidedesc Do not show desc
|
||||||
* @param int $hideref Do not show ref
|
* @param int $hideref Do not show ref
|
||||||
* @return int 1 if OK, <=0 if KO
|
* @return int 1 if OK, <=0 if KO
|
||||||
*/
|
*/
|
||||||
function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
|
function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
|
||||||
@ -283,14 +285,14 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add odtgeneration hook
|
// Add odtgeneration hook
|
||||||
if (! is_object($hookmanager))
|
if (! is_object($hookmanager))
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
||||||
$hookmanager=new HookManager($this->db);
|
$hookmanager=new HookManager($this->db);
|
||||||
}
|
}
|
||||||
$hookmanager->initHooks(array('odtgeneration'));
|
$hookmanager->initHooks(array('odtgeneration'));
|
||||||
global $action;
|
global $action;
|
||||||
|
|
||||||
if (! is_object($outputlangs)) $outputlangs=$langs;
|
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||||
$sav_charset_output=$outputlangs->charset_output;
|
$sav_charset_output=$outputlangs->charset_output;
|
||||||
@ -337,7 +339,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
|
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
|
||||||
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
|
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
|
||||||
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
|
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
|
||||||
$newfiletmp=$objectref.'_'.$newfiletmp;
|
$newfiletmp=$objectref.'_'.$newfiletmp;
|
||||||
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
|
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
|
||||||
$file=$dir.'/'.$newfiletmp.'.odt';
|
$file=$dir.'/'.$newfiletmp.'.odt';
|
||||||
//print "newdir=".$dir;
|
//print "newdir=".$dir;
|
||||||
@ -348,70 +350,70 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
dol_mkdir($conf->facture->dir_temp);
|
dol_mkdir($conf->facture->dir_temp);
|
||||||
|
|
||||||
|
|
||||||
// If BILLING contact defined on invoice, we use it
|
// If BILLING contact defined on invoice, we use it
|
||||||
$usecontact=false;
|
$usecontact=false;
|
||||||
$arrayidcontact=$object->getIdContact('external','BILLING');
|
$arrayidcontact=$object->getIdContact('external','BILLING');
|
||||||
if (count($arrayidcontact) > 0)
|
if (count($arrayidcontact) > 0)
|
||||||
{
|
{
|
||||||
$usecontact=true;
|
$usecontact=true;
|
||||||
$result=$object->fetch_contact($arrayidcontact[0]);
|
$result=$object->fetch_contact($arrayidcontact[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recipient name
|
// Recipient name
|
||||||
if (! empty($usecontact))
|
if (! empty($usecontact))
|
||||||
{
|
{
|
||||||
// On peut utiliser le nom de la societe du contact
|
// On peut utiliser le nom de la societe du contact
|
||||||
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
|
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
|
||||||
else $socobject = $object->client;
|
else $socobject = $object->client;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$socobject=$object->client;
|
$socobject=$object->client;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch info for linked propal
|
// Fetch info for linked propal
|
||||||
$linked_propal = $object->fetchObjectLinked('','','','');
|
$linked_propal = $object->fetchObjectLinked('','','','');
|
||||||
//print_r($object->linkedObjects['propal']); exit;
|
//print_r($object->linkedObjects['propal']); exit;
|
||||||
|
|
||||||
$propal_object = $object->linkedObjects['propal'][0];
|
$propal_object = $object->linkedObjects['propal'][0];
|
||||||
|
|
||||||
// Make substitution
|
// Make substitution
|
||||||
$substitutionarray=array(
|
$substitutionarray=array(
|
||||||
'__FROM_NAME__' => $this->emetteur->nom,
|
'__FROM_NAME__' => $this->emetteur->nom,
|
||||||
'__FROM_EMAIL__' => $this->emetteur->email,
|
'__FROM_EMAIL__' => $this->emetteur->email,
|
||||||
'__TOTAL_TTC__' => $object->total_ttc,
|
'__TOTAL_TTC__' => $object->total_ttc,
|
||||||
'__TOTAL_HT__' => $object->total_ht,
|
'__TOTAL_HT__' => $object->total_ht,
|
||||||
'__TOTAL_VAT__' => $object->total_tva
|
'__TOTAL_VAT__' => $object->total_tva
|
||||||
);
|
);
|
||||||
complete_substitutions_array($substitutionarray, $langs, $object);
|
complete_substitutions_array($substitutionarray, $langs, $object);
|
||||||
// Call the ODTSubstitution hook
|
// Call the ODTSubstitution hook
|
||||||
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
|
||||||
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
// Line of free text
|
// Line of free text
|
||||||
$newfreetext='';
|
$newfreetext='';
|
||||||
$paramfreetext='FACTURE_FREE_TEXT';
|
$paramfreetext='FACTURE_FREE_TEXT';
|
||||||
if (! empty($conf->global->$paramfreetext))
|
if (! empty($conf->global->$paramfreetext))
|
||||||
{
|
{
|
||||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open and load template
|
// Open and load template
|
||||||
require_once ODTPHP_PATH.'odf.php';
|
require_once ODTPHP_PATH.'odf.php';
|
||||||
$odfHandler = new odf(
|
$odfHandler = new odf(
|
||||||
$srctemplatepath,
|
$srctemplatepath,
|
||||||
array(
|
array(
|
||||||
'PATH_TO_TMP' => $conf->facture->dir_temp,
|
'PATH_TO_TMP' => $conf->facture->dir_temp,
|
||||||
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
|
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
|
||||||
'DELIMITER_LEFT' => '{',
|
'DELIMITER_LEFT' => '{',
|
||||||
'DELIMITER_RIGHT' => '}'
|
'DELIMITER_RIGHT' => '}'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// After construction $odfHandler->contentXml contains content and
|
// After construction $odfHandler->contentXml contains content and
|
||||||
// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
|
// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
|
||||||
// [!-- BEGIN lines --]*[!-- END lines --]
|
// [!-- BEGIN lines --]*[!-- END lines --]
|
||||||
//print html_entity_decode($odfHandler->__toString());
|
//print html_entity_decode($odfHandler->__toString());
|
||||||
//print exit;
|
//print exit;
|
||||||
|
|
||||||
|
|
||||||
// Make substitutions into odt of freetext
|
// Make substitutions into odt of freetext
|
||||||
@ -422,7 +424,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make substitutions into odt of user info
|
// Make substitutions into odt of user info
|
||||||
$array_user=$this->get_substitutionarray_user($user,$outputlangs);
|
$array_user=$this->get_substitutionarray_user($user,$outputlangs);
|
||||||
$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
|
$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
|
||||||
$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
|
$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
|
||||||
@ -432,74 +434,74 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
|
|
||||||
$tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal);
|
$tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object);
|
complete_substitutions_array($tmparray, $outputlangs, $object);
|
||||||
// Call the ODTSubstitution hook
|
// Call the ODTSubstitution hook
|
||||||
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
|
$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
|
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
//var_dump($tmparray); exit;
|
//var_dump($tmparray); exit;
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (preg_match('/logo$/',$key)) // Image
|
if (preg_match('/logo$/',$key)) // Image
|
||||||
{
|
{
|
||||||
//var_dump($value);exit;
|
//var_dump($value);exit;
|
||||||
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
||||||
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
||||||
}
|
}
|
||||||
else // Text
|
else // Text
|
||||||
{
|
{
|
||||||
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace tags of lines
|
// Replace tags of lines
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$listlines = $odfHandler->setSegment('lines');
|
$listlines = $odfHandler->setSegment('lines');
|
||||||
foreach ($object->lines as $line)
|
foreach ($object->lines as $line)
|
||||||
{
|
{
|
||||||
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
|
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
|
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
|
||||||
// Call the ODTSubstitutionLine hook
|
// Call the ODTSubstitutionLine hook
|
||||||
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
|
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
|
||||||
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$listlines->setVars($key, $val, true, 'UTF-8');
|
$listlines->setVars($key, $val, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
catch(SegmentException $e)
|
catch(SegmentException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$listlines->merge();
|
$listlines->merge();
|
||||||
}
|
}
|
||||||
$odfHandler->mergeSegment($listlines);
|
$odfHandler->mergeSegment($listlines);
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
$this->error=$e->getMessage();
|
$this->error=$e->getMessage();
|
||||||
dol_syslog($this->error, LOG_WARNING);
|
dol_syslog($this->error, LOG_WARNING);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the beforeODTSave hook
|
// Call the beforeODTSave hook
|
||||||
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
|
$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
|
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
//$result=$odfHandler->exportAsAttachedFile('toto');
|
//$result=$odfHandler->exportAsAttachedFile('toto');
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
|
|
||||||
$odfHandler=null; // Destroy object
|
$odfHandler=null; // Destroy object
|
||||||
|
|
||||||
|
|||||||
@ -125,7 +125,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
'object_note_private'=>$object->note_private,
|
'object_note_private'=>$object->note_private,
|
||||||
'object_note_public'=>$object->note_public,
|
'object_note_public'=>$object->note_public,
|
||||||
'object_public'=>$object->public,
|
'object_public'=>$object->public,
|
||||||
'object_statut'=>html_entity_decode($object->getLibStatut())
|
'object_statut'=>$object->getLibStatut()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
function get_substitutionarray_project_reference($refdetail,$outputlangs)
|
function get_substitutionarray_project_reference($refdetail,$outputlangs)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'projref_type'=>$refdetail['type'],
|
'projref_type'=>$refdetail['type'],
|
||||||
'projref_ref'=>$refdetail['ref'],
|
'projref_ref'=>$refdetail['ref'],
|
||||||
@ -220,7 +220,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
'projref_status'=>$refdetail['status']
|
'projref_status'=>$refdetail['status']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
@ -242,7 +242,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
'taskressource_email'=>$taskressource['email']
|
'taskressource_email'=>$taskressource['email']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
@ -254,7 +254,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'tasktime_rowid'=>$tasktime['rowid'],
|
'tasktime_rowid'=>$tasktime['rowid'],
|
||||||
'tasktime_task_date'=>dol_print_date($tasktime['task_date'],'day'),
|
'tasktime_task_date'=>dol_print_date($tasktime['task_date'],'day'),
|
||||||
'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'],'all'),
|
'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'],'all'),
|
||||||
@ -265,7 +265,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
'tasktime_fullcivname'=>$tasktime['fullcivname']
|
'tasktime_fullcivname'=>$tasktime['fullcivname']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define array with couple substitution key => substitution value
|
* Define array with couple substitution key => substitution value
|
||||||
*
|
*
|
||||||
@ -276,7 +276,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
function get_substitutionarray_task_file($file,$outputlangs)
|
function get_substitutionarray_task_file($file,$outputlangs)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'tasksfile_name'=>$file['name'],
|
'tasksfile_name'=>$file['name'],
|
||||||
'tasksfile_date'=>dol_print_date($file['date'],'day'),
|
'tasksfile_date'=>dol_print_date($file['date'],'day'),
|
||||||
@ -384,6 +384,14 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
return -1;
|
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;
|
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||||
$sav_charset_output=$outputlangs->charset_output;
|
$sav_charset_output=$outputlangs->charset_output;
|
||||||
$outputlangs->charset_output='UTF-8';
|
$outputlangs->charset_output='UTF-8';
|
||||||
@ -470,7 +478,6 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
|
|
||||||
// Make substitutions into odt of user info
|
// Make substitutions into odt of user info
|
||||||
$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
|
$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
|
||||||
//var_dump($tmparray); exit;
|
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -504,6 +511,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
else // Text
|
else // Text
|
||||||
{
|
{
|
||||||
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
||||||
|
$odfHandler->setVarsHeadFooter($key, $value, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
@ -534,6 +542,9 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
// Replace tags of object + external modules
|
// Replace tags of object + external modules
|
||||||
$tmparray=$this->get_substitutionarray_object($object,$outputlangs);
|
$tmparray=$this->get_substitutionarray_object($object,$outputlangs);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object);
|
complete_substitutions_array($tmparray, $outputlangs, $object);
|
||||||
|
// 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)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -564,7 +575,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
if (!empty($object->fk_soc)) $socid = $object->fk_soc;
|
if (!empty($object->fk_soc)) $socid = $object->fk_soc;
|
||||||
|
|
||||||
$tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
|
$tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($tasksarray as $task)
|
foreach ($tasksarray as $task)
|
||||||
@ -584,10 +595,10 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$taskobj=new Task($this->db);
|
$taskobj=new Task($this->db);
|
||||||
$taskobj->fetch($task->id);
|
$taskobj->fetch($task->id);
|
||||||
|
|
||||||
// Replace tags of lines for contacts task
|
// Replace tags of lines for contacts task
|
||||||
$sourcearray=array('internal','external');
|
$sourcearray=array('internal','external');
|
||||||
$contact_arrray=array();
|
$contact_arrray=array();
|
||||||
@ -601,7 +612,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
if ((is_array($contact_arrray) && count($contact_arrray) > 0))
|
if ((is_array($contact_arrray) && count($contact_arrray) > 0))
|
||||||
{
|
{
|
||||||
$listlinestaskres = $listlines->__get('tasksressources');
|
$listlinestaskres = $listlines->__get('tasksressources');
|
||||||
|
|
||||||
foreach ($contact_arrray as $contact)
|
foreach ($contact_arrray as $contact)
|
||||||
{
|
{
|
||||||
if ($contact['source']=='internal') {
|
if ($contact['source']=='internal') {
|
||||||
@ -611,15 +622,15 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
} elseif ($contact['source']=='external') {
|
} elseif ($contact['source']=='external') {
|
||||||
$objectdetail=new Contact($this->db);
|
$objectdetail=new Contact($this->db);
|
||||||
$objectdetail->fetch($contact['id']);
|
$objectdetail->fetch($contact['id']);
|
||||||
|
|
||||||
$soc=new Societe($this->db);
|
$soc=new Societe($this->db);
|
||||||
$soc->fetch($contact['socid']);
|
$soc->fetch($contact['socid']);
|
||||||
$contact['socname']=$soc->name;
|
$contact['socname']=$soc->name;
|
||||||
}
|
}
|
||||||
$contact['fullname']=$objectdetail->getFullName($outputlangs,1);
|
$contact['fullname']=$objectdetail->getFullName($outputlangs,1);
|
||||||
|
|
||||||
$tmparray=$this->get_substitutionarray_tasksressource($contact,$outputlangs);
|
$tmparray=$this->get_substitutionarray_tasksressource($contact,$outputlangs);
|
||||||
|
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -645,7 +656,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
$sql .= " WHERE t.fk_task =".$task->id;
|
$sql .= " WHERE t.fk_task =".$task->id;
|
||||||
$sql .= " AND t.fk_user = u.rowid";
|
$sql .= " AND t.fk_user = u.rowid";
|
||||||
$sql .= " ORDER BY t.task_date DESC";
|
$sql .= " ORDER BY t.task_date DESC";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -663,9 +674,9 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
} else {
|
} else {
|
||||||
$row['fullcivname']='';
|
$row['fullcivname']='';
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmparray=$this->get_substitutionarray_taskstime($row,$outputlangs);
|
$tmparray=$this->get_substitutionarray_taskstime($row,$outputlangs);
|
||||||
|
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -684,15 +695,15 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
}
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Replace tags of project files
|
// Replace tags of project files
|
||||||
$listtasksfiles = $listlines->__get('tasksfiles');
|
$listtasksfiles = $listlines->__get('tasksfiles');
|
||||||
|
|
||||||
$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref).'/'.dol_sanitizeFileName($task->ref);
|
$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref).'/'.dol_sanitizeFileName($task->ref);
|
||||||
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$','name',SORT_ASC,1);
|
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$','name',SORT_ASC,1);
|
||||||
|
|
||||||
|
|
||||||
foreach ($filearray as $filedetail)
|
foreach ($filearray as $filedetail)
|
||||||
{
|
{
|
||||||
$tmparray=$this->get_substitutionarray_task_file($filedetail,$outputlangs);
|
$tmparray=$this->get_substitutionarray_task_file($filedetail,$outputlangs);
|
||||||
@ -731,7 +742,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref);
|
$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref);
|
||||||
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$','name',SORT_ASC,1);
|
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$','name',SORT_ASC,1);
|
||||||
|
|
||||||
|
|
||||||
foreach ($filearray as $filedetail)
|
foreach ($filearray as $filedetail)
|
||||||
{
|
{
|
||||||
//dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true));
|
//dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true));
|
||||||
@ -794,7 +805,6 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
$contact['fullname']=$objectdetail->getFullName($outputlangs,1);
|
$contact['fullname']=$objectdetail->getFullName($outputlangs,1);
|
||||||
|
|
||||||
$tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs);
|
$tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $contact, $contact, "completesubstitutionarray_lines");
|
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -891,27 +901,27 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
{
|
{
|
||||||
$ref_array=array();
|
$ref_array=array();
|
||||||
$ref_array['type']=$langs->trans($classname);
|
$ref_array['type']=$langs->trans($classname);
|
||||||
|
|
||||||
$element = new $classname($this->db);
|
$element = new $classname($this->db);
|
||||||
$element->fetch($elementarray[$i]);
|
$element->fetch($elementarray[$i]);
|
||||||
$element->fetch_thirdparty();
|
$element->fetch_thirdparty();
|
||||||
|
|
||||||
//Ref object
|
//Ref object
|
||||||
$ref_array['ref']=$element->ref;
|
$ref_array['ref']=$element->ref;
|
||||||
|
|
||||||
//Date object
|
//Date object
|
||||||
$dateref=$element->date;
|
$dateref=$element->date;
|
||||||
if (empty($dateref)) $dateref=$element->datep;
|
if (empty($dateref)) $dateref=$element->datep;
|
||||||
if (empty($dateref)) $dateref=$element->date_contrat;
|
if (empty($dateref)) $dateref=$element->date_contrat;
|
||||||
$ref_array['date']=$dateref;
|
$ref_array['date']=$dateref;
|
||||||
|
|
||||||
//Soc object
|
//Soc object
|
||||||
if (is_object($element->thirdparty)) {
|
if (is_object($element->thirdparty)) {
|
||||||
$ref_array['socname']=$element->thirdparty->name;
|
$ref_array['socname']=$element->thirdparty->name;
|
||||||
} else {
|
} else {
|
||||||
$ref_array['socname']='';
|
$ref_array['socname']='';
|
||||||
}
|
}
|
||||||
|
|
||||||
//Amount object
|
//Amount object
|
||||||
if (empty($valueref['disableamount'])) {
|
if (empty($valueref['disableamount'])) {
|
||||||
if (!empty($element->total_ht)) {
|
if (!empty($element->total_ht)) {
|
||||||
@ -925,9 +935,9 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
$ref_array['amountht']='';
|
$ref_array['amountht']='';
|
||||||
$ref_array['amountttc']='';
|
$ref_array['amountttc']='';
|
||||||
}
|
}
|
||||||
|
|
||||||
$ref_array['status']=html_entity_decode($element->getLibStatut(0));
|
$ref_array['status']=$element->getLibStatut(0);
|
||||||
|
|
||||||
$tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs);
|
$tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs);
|
||||||
|
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
@ -945,7 +955,7 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
}
|
}
|
||||||
$listlines->merge();
|
$listlines->merge();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$odfHandler->mergeSegment($listlines);
|
$odfHandler->mergeSegment($listlines);
|
||||||
@ -958,8 +968,14 @@ class doc_generic_project_odt extends ModelePDFProjects
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Write new file
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
//$odfHandler->exportAsAttachedPDF($file);
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* or see http://www.gnu.org/
|
* or see http://www.gnu.org/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php
|
* \file htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php
|
||||||
@ -89,7 +89,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
/**
|
/**
|
||||||
* Return description of a module
|
* Return description of a module
|
||||||
*
|
*
|
||||||
* @param Translate $langs Lang object to use for output
|
* @param Translate $langs Lang object to use for output
|
||||||
* @return string Description
|
* @return string Description
|
||||||
*/
|
*/
|
||||||
function info($langs)
|
function info($langs)
|
||||||
@ -123,7 +123,9 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
{
|
{
|
||||||
$tmpdir=trim($tmpdir);
|
$tmpdir=trim($tmpdir);
|
||||||
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
||||||
if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
if (! $tmpdir) {
|
||||||
|
unset($listofdir[$key]); continue;
|
||||||
|
}
|
||||||
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
|
if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -134,19 +136,19 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
|
$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
|
||||||
// Add list of substitution keys
|
// Add list of substitution keys
|
||||||
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
|
$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
|
||||||
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
|
$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it
|
||||||
|
|
||||||
$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
|
$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
|
||||||
$texte.= '<table><tr><td>';
|
$texte.= '<table><tr><td>';
|
||||||
$texte.= '<textarea class="flat" cols="60" name="value1">';
|
$texte.= '<textarea class="flat" cols="60" name="value1">';
|
||||||
$texte.=$conf->global->PROPALE_ADDON_PDF_ODT_PATH;
|
$texte.=$conf->global->PROPALE_ADDON_PDF_ODT_PATH;
|
||||||
$texte.= '</textarea>';
|
$texte.= '</textarea>';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '<td align="center"> ';
|
$texte.= '<td align="center"> ';
|
||||||
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '</tr>';
|
$texte.= '</tr>';
|
||||||
$texte.= '</table>';
|
$texte.= '</table>';
|
||||||
|
|
||||||
// Scan directories
|
// Scan directories
|
||||||
if (count($listofdir))
|
if (count($listofdir))
|
||||||
@ -190,7 +192,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
$texte.= '</tr>';
|
$texte.= '</tr>';
|
||||||
|
|
||||||
/*$texte.= '<tr>';
|
/*$texte.= '<tr>';
|
||||||
$texte.= '<td align="center">';
|
$texte.= '<td align="center">';
|
||||||
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
|
||||||
$texte.= '</td>';
|
$texte.= '</td>';
|
||||||
$texte.= '</tr>';*/
|
$texte.= '</tr>';*/
|
||||||
@ -207,9 +209,9 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
* @param Propale $object Object source to build document
|
* @param Propale $object Object source to build document
|
||||||
* @param Translate $outputlangs Lang output object
|
* @param Translate $outputlangs Lang output object
|
||||||
* @param string $srctemplatepath Full path of source filename for generator using a template file
|
* @param string $srctemplatepath Full path of source filename for generator using a template file
|
||||||
* @param int $hidedetails Do not show line details
|
* @param int $hidedetails Do not show line details
|
||||||
* @param int $hidedesc Do not show desc
|
* @param int $hidedesc Do not show desc
|
||||||
* @param int $hideref Do not show ref
|
* @param int $hideref Do not show ref
|
||||||
* @return int 1 if OK, <=0 if KO
|
* @return int 1 if OK, <=0 if KO
|
||||||
*/
|
*/
|
||||||
function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
|
function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
|
||||||
@ -222,14 +224,14 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add odtgeneration hook
|
// Add odtgeneration hook
|
||||||
if (! is_object($hookmanager))
|
if (! is_object($hookmanager))
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
||||||
$hookmanager=new HookManager($this->db);
|
$hookmanager=new HookManager($this->db);
|
||||||
}
|
}
|
||||||
$hookmanager->initHooks(array('odtgeneration'));
|
$hookmanager->initHooks(array('odtgeneration'));
|
||||||
global $action;
|
global $action;
|
||||||
|
|
||||||
if (! is_object($outputlangs)) $outputlangs=$langs;
|
if (! is_object($outputlangs)) $outputlangs=$langs;
|
||||||
$sav_charset_output=$outputlangs->charset_output;
|
$sav_charset_output=$outputlangs->charset_output;
|
||||||
@ -276,7 +278,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
|
$newfiletmp=preg_replace('/\.odt/i','',$newfile);
|
||||||
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
|
$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
|
||||||
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
|
$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
|
||||||
$newfiletmp=$objectref.'_'.$newfiletmp;
|
$newfiletmp=$objectref.'_'.$newfiletmp;
|
||||||
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
|
//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
|
||||||
$file=$dir.'/'.$newfiletmp.'.odt';
|
$file=$dir.'/'.$newfiletmp.'.odt';
|
||||||
//print "newdir=".$dir;
|
//print "newdir=".$dir;
|
||||||
@ -287,64 +289,64 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
dol_mkdir($conf->propal->dir_temp);
|
dol_mkdir($conf->propal->dir_temp);
|
||||||
|
|
||||||
|
|
||||||
// If BILLING contact defined on invoice, we use it
|
// If BILLING contact defined on invoice, we use it
|
||||||
$usecontact=false;
|
$usecontact=false;
|
||||||
$arrayidcontact=$object->getIdContact('external','BILLING');
|
$arrayidcontact=$object->getIdContact('external','BILLING');
|
||||||
if (count($arrayidcontact) > 0)
|
if (count($arrayidcontact) > 0)
|
||||||
{
|
{
|
||||||
$usecontact=true;
|
$usecontact=true;
|
||||||
$result=$object->fetch_contact($arrayidcontact[0]);
|
$result=$object->fetch_contact($arrayidcontact[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recipient name
|
// Recipient name
|
||||||
if (! empty($usecontact))
|
if (! empty($usecontact))
|
||||||
{
|
{
|
||||||
// On peut utiliser le nom de la societe du contact
|
// On peut utiliser le nom de la societe du contact
|
||||||
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
|
if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact;
|
||||||
else $socobject = $object->client;
|
else $socobject = $object->client;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$socobject=$object->client;
|
$socobject=$object->client;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make substitution
|
// Make substitution
|
||||||
$substitutionarray=array(
|
$substitutionarray=array(
|
||||||
'__FROM_NAME__' => $this->emetteur->nom,
|
'__FROM_NAME__' => $this->emetteur->nom,
|
||||||
'__FROM_EMAIL__' => $this->emetteur->email,
|
'__FROM_EMAIL__' => $this->emetteur->email,
|
||||||
'__TOTAL_TTC__' => $object->total_ttc,
|
'__TOTAL_TTC__' => $object->total_ttc,
|
||||||
'__TOTAL_HT__' => $object->total_ht,
|
'__TOTAL_HT__' => $object->total_ht,
|
||||||
'__TOTAL_VAT__' => $object->total_vat
|
'__TOTAL_VAT__' => $object->total_vat
|
||||||
);
|
);
|
||||||
complete_substitutions_array($substitutionarray, $langs, $object);
|
complete_substitutions_array($substitutionarray, $langs, $object);
|
||||||
// Call the ODTSubstitution hook
|
// Call the ODTSubstitution hook
|
||||||
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
|
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
|
||||||
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
// Line of free text
|
// Line of free text
|
||||||
$newfreetext='';
|
$newfreetext='';
|
||||||
$paramfreetext='PROPALE_FREE_TEXT';
|
$paramfreetext='PROPALE_FREE_TEXT';
|
||||||
if (! empty($conf->global->$paramfreetext))
|
if (! empty($conf->global->$paramfreetext))
|
||||||
{
|
{
|
||||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open and load template
|
// Open and load template
|
||||||
require_once ODTPHP_PATH.'odf.php';
|
require_once ODTPHP_PATH.'odf.php';
|
||||||
$odfHandler = new odf(
|
$odfHandler = new odf(
|
||||||
$srctemplatepath,
|
$srctemplatepath,
|
||||||
array(
|
array(
|
||||||
'PATH_TO_TMP' => $conf->propal->dir_temp,
|
'PATH_TO_TMP' => $conf->propal->dir_temp,
|
||||||
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
|
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
|
||||||
'DELIMITER_LEFT' => '{',
|
'DELIMITER_LEFT' => '{',
|
||||||
'DELIMITER_RIGHT' => '}'
|
'DELIMITER_RIGHT' => '}'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// After construction $odfHandler->contentXml contains content and
|
// After construction $odfHandler->contentXml contains content and
|
||||||
// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
|
// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
|
||||||
// [!-- BEGIN lines --]*[!-- END lines --]
|
// [!-- BEGIN lines --]*[!-- END lines --]
|
||||||
//print html_entity_decode($odfHandler->__toString());
|
//print html_entity_decode($odfHandler->__toString());
|
||||||
//print exit;
|
//print exit;
|
||||||
|
|
||||||
|
|
||||||
// Make substitutions into odt of freetext
|
// Make substitutions into odt of freetext
|
||||||
@ -355,29 +357,29 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make substitutions into odt of user info
|
// Make substitutions into odt of user info
|
||||||
$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
|
$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
|
||||||
//var_dump($tmparray); exit;
|
//var_dump($tmparray); exit;
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (preg_match('/logo$/',$key)) // Image
|
if (preg_match('/logo$/',$key)) // Image
|
||||||
{
|
{
|
||||||
//var_dump($value);exit;
|
//var_dump($value);exit;
|
||||||
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
||||||
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
||||||
}
|
}
|
||||||
else // Text
|
else // Text
|
||||||
{
|
{
|
||||||
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make substitutions into odt of mysoc
|
// Make substitutions into odt of mysoc
|
||||||
$tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
|
$tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
|
||||||
//var_dump($tmparray); exit;
|
//var_dump($tmparray); exit;
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
@ -397,7 +399,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Make substitutions into odt of thirdparty
|
// Make substitutions into odt of thirdparty
|
||||||
$tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
|
$tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
@ -417,74 +419,74 @@ class doc_generic_proposal_odt extends ModelePDFPropales
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace tags of object + external modules
|
// Replace tags of object + external modules
|
||||||
$tmparray=$this->get_substitutionarray_propal($object,$outputlangs);
|
$tmparray=$this->get_substitutionarray_propal($object,$outputlangs);
|
||||||
//print_r($tmparray); exit;
|
//print_r($tmparray); exit;
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object);
|
complete_substitutions_array($tmparray, $outputlangs, $object);
|
||||||
// Call the ODTSubstitution hook
|
// Call the ODTSubstitution hook
|
||||||
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
|
$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
|
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
foreach($tmparray as $key=>$value)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (preg_match('/logo$/',$key)) // Image
|
if (preg_match('/logo$/',$key)) // Image
|
||||||
{
|
{
|
||||||
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
if (file_exists($value)) $odfHandler->setImage($key, $value);
|
||||||
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
|
||||||
}
|
}
|
||||||
else // Text
|
else // Text
|
||||||
{
|
{
|
||||||
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
$odfHandler->setVars($key, $value, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace tags of lines
|
// Replace tags of lines
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$listlines = $odfHandler->setSegment('lines');
|
$listlines = $odfHandler->setSegment('lines');
|
||||||
foreach ($object->lines as $line)
|
foreach ($object->lines as $line)
|
||||||
{
|
{
|
||||||
$tmparray=$this->get_substitutionarray_propal_lines($line,$outputlangs);
|
$tmparray=$this->get_substitutionarray_propal_lines($line,$outputlangs);
|
||||||
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
|
complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
|
||||||
// Call the ODTSubstitutionLine hook
|
// Call the ODTSubstitutionLine hook
|
||||||
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
|
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
|
||||||
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$listlines->setVars($key, $val, true, 'UTF-8');
|
$listlines->setVars($key, $val, true, 'UTF-8');
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
catch(SegmentException $e)
|
catch(SegmentException $e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$listlines->merge();
|
$listlines->merge();
|
||||||
}
|
}
|
||||||
$odfHandler->mergeSegment($listlines);
|
$odfHandler->mergeSegment($listlines);
|
||||||
}
|
}
|
||||||
catch(OdfException $e)
|
catch(OdfException $e)
|
||||||
{
|
{
|
||||||
$this->error=$e->getMessage();
|
$this->error=$e->getMessage();
|
||||||
dol_syslog($this->error, LOG_WARNING);
|
dol_syslog($this->error, LOG_WARNING);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the beforeODTSave hook
|
// Call the beforeODTSave hook
|
||||||
$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
|
$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
|
$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
|
||||||
// Write new file
|
// Write new file
|
||||||
//$result=$odfHandler->exportAsAttachedFile('toto');
|
//$result=$odfHandler->exportAsAttachedFile('toto');
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
@chmod($file, octdec($conf->global->MAIN_UMASK));
|
||||||
|
|
||||||
$odfHandler=null; // Destroy object
|
$odfHandler=null; // Destroy object
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once 'zip/PclZipProxy.php';
|
|
||||||
require_once 'zip/PhpZipProxy.php';
|
|
||||||
require 'Segment.php';
|
require 'Segment.php';
|
||||||
class OdfException extends Exception
|
class OdfException extends Exception
|
||||||
{}
|
{}
|
||||||
@ -129,6 +127,33 @@ class Odf
|
|||||||
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
|
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assing a template variable
|
||||||
|
*
|
||||||
|
* @param string $key name of the variable within the template
|
||||||
|
* @param string $value replacement value
|
||||||
|
* @param bool $encode if true, special XML characters are encoded
|
||||||
|
* @throws OdfException
|
||||||
|
* @return odf
|
||||||
|
*/
|
||||||
|
public function setVarsHeadFooter($key, $value, $encode = true, $charset = 'ISO-8859')
|
||||||
|
{
|
||||||
|
$tag = $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT'];
|
||||||
|
// TODO Warning string may be:
|
||||||
|
// <text:span text:style-name="T13">{</text:span><text:span text:style-name="T12">aaa</text:span><text:span text:style-name="T13">}</text:span>
|
||||||
|
// instead of {aaa} so we should enhance this function.
|
||||||
|
//print $key.'-'.$value.'-'.strpos($this->contentXml, $this->config['DELIMITER_LEFT'] . $key . $this->config['DELIMITER_RIGHT']).'<br>';
|
||||||
|
if (strpos($this->stylesXml, $tag) === false && strpos($this->stylesXml , $tag) === false) {
|
||||||
|
//if (strpos($this->contentXml, '">'. $key . '</text;span>') === false) {
|
||||||
|
throw new OdfException("var $key not found in the document");
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
$value = $encode ? htmlspecialchars($value) : $value;
|
||||||
|
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
|
||||||
|
$this->vars[$tag] = str_replace("\n", "<text:line-break/>", $value);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code
|
* Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code
|
||||||
|
|||||||
@ -1061,4 +1061,4 @@ print '</form>'."\n";
|
|||||||
llxFooterSurvey();
|
llxFooterSurvey();
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -120,7 +120,7 @@ function get_server_name()
|
|||||||
/**
|
/**
|
||||||
* is_error
|
* is_error
|
||||||
*
|
*
|
||||||
* @param string $cerr Error value
|
* @param unknown_type $cerr error number
|
||||||
* @return boolean Error key found or not
|
* @return boolean Error key found or not
|
||||||
*/
|
*/
|
||||||
function is_error($cerr)
|
function is_error($cerr)
|
||||||
@ -290,4 +290,4 @@ define('TITLE_EMPTY', 0x0100000000);
|
|||||||
define('INVALID_DATE', 0x1000000000);
|
define('INVALID_DATE', 0x1000000000);
|
||||||
$err = 0;
|
$err = 0;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -72,10 +72,9 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
|
|||||||
$mailfile = new CMailFile(
|
$mailfile = new CMailFile(
|
||||||
'New subscription payed',
|
'New subscription payed',
|
||||||
$sendto,
|
$sendto,
|
||||||
$from,
|
$from,
|
||||||
'New subscription payed '.$fulltag
|
'New subscription payed '.$fulltag);
|
||||||
);
|
|
||||||
|
|
||||||
$result=$mailfile->sendfile();
|
$result=$mailfile->sendfile();
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -103,8 +103,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
|
|||||||
'New subscription payed',
|
'New subscription payed',
|
||||||
$sendto,
|
$sendto,
|
||||||
$from,
|
$from,
|
||||||
'New subscription payed '.$fulltag
|
'New subscription payed '.$fulltag);
|
||||||
);
|
|
||||||
|
|
||||||
$result=$mailfile->sendfile();
|
$result=$mailfile->sendfile();
|
||||||
if ($result)
|
if ($result)
|
||||||
|
|||||||
@ -81,8 +81,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
|
|||||||
'New subscription payed',
|
'New subscription payed',
|
||||||
$sendto,
|
$sendto,
|
||||||
$from,
|
$from,
|
||||||
'New subscription payed '.$fulltag
|
'New subscription payed '.$fulltag);
|
||||||
);
|
|
||||||
|
|
||||||
$result=$mailfile->sendfile();
|
$result=$mailfile->sendfile();
|
||||||
if ($result)
|
if ($result)
|
||||||
|
|||||||
@ -140,8 +140,7 @@ if ($PAYPALTOKEN)
|
|||||||
'New subscription payed',
|
'New subscription payed',
|
||||||
$sendto,
|
$sendto,
|
||||||
$from,
|
$from,
|
||||||
'New subscription payed '.$fulltag
|
'New subscription payed '.$fulltag);
|
||||||
);
|
|
||||||
|
|
||||||
$result=$mailfile->sendfile();
|
$result=$mailfile->sendfile();
|
||||||
if ($result)
|
if ($result)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user