Fix: Lien invalide sur PDF expedition

This commit is contained in:
Laurent Destailleur 2005-09-14 03:47:27 +00:00
parent 17fd57841c
commit 2f0816b4a7
3 changed files with 75 additions and 82 deletions

View File

@ -183,41 +183,42 @@ class Expedition
* Lit une commande
*
*/
function fetch ($id)
function fetch ($id)
{
$sql = "SELECT e.rowid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut, e.fk_commande, e.fk_entrepot";
$sql .= ", ".$this->db->pdate("e.date_expedition")." as date_expedition ";
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
$sql .= " WHERE e.rowid = $id";
$result = $this->db->query($sql) ;
if ( $result )
{
$obj = $this->db->fetch_object();
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->statut = $obj->fk_statut;
$this->commande_id = $obj->fk_commande;
$this->user_author_id = $obj->fk_user_author;
$this->date = $obj->date_expedition;
$this->entrepot_id = $obj->fk_entrepot;
$this->db->free();
if ($this->statut == 0)
$this->brouillon = 1;
$file = $this->_dir() . $this->id.".pdf";
$this->pdf_filename = $file;
return 1;
}
else
{
print $this->db->error();
return -1;
}
global $conf;
$sql = "SELECT e.rowid, e.date_creation, e.ref, e.fk_user_author, e.fk_statut, e.fk_commande, e.fk_entrepot";
$sql .= ", ".$this->db->pdate("e.date_expedition")." as date_expedition ";
$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
$sql .= " WHERE e.rowid = $id";
$result = $this->db->query($sql) ;
if ( $result )
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->statut = $obj->fk_statut;
$this->commande_id = $obj->fk_commande;
$this->user_author_id = $obj->fk_user_author;
$this->date = $obj->date_expedition;
$this->entrepot_id = $obj->fk_entrepot;
$this->db->free();
if ($this->statut == 0) $this->brouillon = 1;
$file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id) . "/" . $this->id.".pdf";
$this->pdf_filename = $file;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
@ -407,50 +408,42 @@ class Expedition
print $this->db->error() . ' in ' . $sql;
}
}
/*
* Renvoie le répertoire ou est/sera stocké le document
*/
function _dir()
{
$dir = DOL_DATA_ROOT . "/expedition/" . get_exdir($this->id) ;
return $dir;
}
/**
* Genere le pdf
*
*
*/
function PdfWrite()
/**
* Genere le pdf
*/
function PdfWrite()
{
//EXPEDITION_ADDON_PDF
if (defined("EXPEDITION_ADDON_PDF") && strlen(EXPEDITION_ADDON_PDF) > 0)
{
$module_file_name = DOL_DOCUMENT_ROOT."/expedition/mods/pdf/pdf_expedition_".EXPEDITION_ADDON_PDF.".modules.php";
$mod = "pdf_expedition_".EXPEDITION_ADDON_PDF;
$this->fetch_commande();
require_once $module_file_name;
$pdf = new $mod($this->db);
$dir = $this->_dir();
if (! file_exists($dir))
{
create_exdir($dir);
}
$file = $dir . $this->id . ".pdf";
if (file_exists($dir))
{
$pdf->generate($this, $file);
}
}
global $conf;
//EXPEDITION_ADDON_PDF
if (defined("EXPEDITION_ADDON_PDF") && strlen(EXPEDITION_ADDON_PDF) > 0)
{
$module_file_name = DOL_DOCUMENT_ROOT."/expedition/mods/pdf/pdf_expedition_".EXPEDITION_ADDON_PDF.".modules.php";
$mod = "pdf_expedition_".EXPEDITION_ADDON_PDF;
$this->fetch_commande();
require_once($module_file_name);
$pdf = new $mod($this->db);
$dir = $conf->expedition->dir_output . "/" .get_exdir($this->id);
if (! file_exists($dir))
{
create_exdir($dir);
}
$file = $dir . $this->id . ".pdf";
if (file_exists($dir))
{
$pdf->generate($this, $file);
}
}
}
/*
* Lit la commande associée
*

View File

@ -19,7 +19,6 @@
*
* $Id$
* $Source$
*
*/
// Code identique a /expedition/commande.php
@ -490,7 +489,8 @@ else
$var=true;
print "<br>\n";
$html->show_documents('expedition',$filename,$filedir,$urlsource,$genallowed,$delallowed,$propal->modelpdf);
$html->show_documents('expedition',$filename,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf);
/*

View File

@ -1572,12 +1572,14 @@ class Form
*/
function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='')
{
// filedir = conf->...dir_ouput."/".get_exdir(id)
global $langs,$bc;
$var=true;
$filename = sanitize_string($filename);
$relativepath = "${filename}/${filename}.pdf";
$fullpathfile = $filedir . "/" . $filename . ".pdf";
if ($modulepart != 'expedition') $relativepath = "${filename}/${filename}.pdf";
else $relativepath = get_exdir("${filename}")."${filename}.pdf";
$i=0;
if (is_dir($filedir))
@ -1632,9 +1634,7 @@ class Form
if (eregi('\-detail\.pdf',$file)) print '<td nowrap>PDF Détaillé</td>';
else print '<td nowrap>PDF</td>';
$relativepathdetail = "${filename}/$file";
print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepathdetail).'">'.$file.'</a></td>';
print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepath).'">'.$file.'</a></td>';
print '<td align="right">'.filesize($filedir."/".$file). ' bytes</td>';
print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($filedir."/".$file)).'</td>';
print '</tr>';