Fix: bug #16322 : Cration PDF fiche intervention impossible

This commit is contained in:
Laurent Destailleur 2006-04-29 01:28:16 +00:00
parent 5141b2ed6b
commit e283c1516c
5 changed files with 70 additions and 37 deletions

View File

@ -36,12 +36,8 @@ if (defined("FICHEINTER_ADDON") && is_readable(DOL_DOCUMENT_ROOT ."/includes/mod
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/ficheinter/".FICHEINTER_ADDON.".php");
}
// Sécurité accés client
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
$user->getrights("ficheinter");
if (!$user->rights->ficheinter->lire) accessforbidden();
if ($_GET["socidp"])
@ -50,6 +46,13 @@ if ($_GET["socidp"])
$objsoc->fetch($_GET["socidp"]);
}
// Sécurité accés client
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
/*
* Traitements des actions
@ -94,15 +97,14 @@ if ($_POST["action"] == 'update')
$_GET["id"]=$_POST["id"]; // Force raffraichissement sur fiche venant d'etre créée
}
/**
* Generation du pdf
*/
// Generation du pdf
if ($_GET["action"] == 'generate' && $_GET["id"])
{
fichinter_pdf_create($db, $_GET["id"]);
fichinter_pdf_create($db, $_GET["id"], $_POST['model']);
}
llxHeader();
$sel = new Form($db);
@ -164,7 +166,7 @@ if ($_GET["action"] == 'create')
if ($conf->projet->enabled)
{
// Projet associ
// Projet associe
$langs->load("project");
print '<tr><td valign="top">'.$langs->trans("Project").'</td><td><select name="projetidp">';
print '<option value="0"></option>';
@ -352,7 +354,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit')
$urlsource=$_SERVER["PHP_SELF"]."?id=".$fichinter->id;
//$genallowed=$user->rights->fichinter->creer;
//$delallowed=$user->rights->fichinter->supprimer;
$genallowed=0;
$genallowed=1;
$delallowed=0;
$var=true;

View File

@ -81,7 +81,7 @@ class Fichinter
*/
function create()
{
if (!strlen($this->duree)) { $this->duree = 0; }
if (! is_numeric($this->duree)) { $this->duree = 0; }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (fk_soc, datei, datec, ref, fk_user_author, note, duree";
if ($this->projet_id) {
@ -108,11 +108,12 @@ class Fichinter
}
/*
*
*
* \brief Met a jour une intervention
* \return int <0 si ko, >0 si ok
*/
function update($id)
{
if (! is_numeric($this->duree)) { $this->duree = 0; }
if (! strlen($this->projet_id))
{
$this->projet_id = 0;
@ -122,17 +123,18 @@ class Fichinter
* Insertion dans la base
*/
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET ";
$sql .= " datei = $this->date";
$sql .= " datei = ".$this->date;
$sql .= ", note = '".addslashes($this->note)."'";
$sql .= ", duree = $this->duree";
$sql .= ", fk_projet = $this->projet_id";
$sql .= ", duree = ".$this->duree;
$sql .= ", fk_projet = ".$this->projet_id;
$sql .= " WHERE rowid = $id";
if (! $this->db->query($sql) )
{
print $this->db->error() . '<b><br>'.$sql;
$this->error=$this->db->error().' sql='.$sql;
return -1;
}
return 1;
}
@ -183,13 +185,15 @@ class Fichinter
function fetch($rowid)
{
$sql = "SELECT ref,note,fk_soc,fk_statut,duree,".$this->db->pdate(datei)."as di, fk_projet FROM ".MAIN_DB_PREFIX."fichinter WHERE rowid=$rowid;";
$sql = "SELECT ref,note,fk_soc,fk_statut,duree,".$this->db->pdate(datei)." as di, fk_projet";
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter WHERE rowid=".$rowid;
if ($this->db->query($sql) )
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows())
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object();
$obj = $this->db->fetch_object($resql);
$this->id = $rowid;
$this->date = $obj->di;
@ -200,14 +204,14 @@ class Fichinter
$this->projet_id = $obj->fk_projet;
$this->statut = $obj->fk_statut;
$this->db->free();
$this->db->free($resql);
return 1;
}
}
else
{
print $this->db->error();
return 0;
$this->error=$this->db->error().' sql='.$sql;
return -1;
}
}

View File

@ -2253,6 +2253,16 @@ class Form
$model=new ModelePDFCommandes();
$modellist=$model->liste_modeles($this->db);
}
}
else if ($modulepart == 'ficheinter')
{
if (is_array($genallowed)) $modellist=$genallowed;
else
{
include_once(DOL_DOCUMENT_ROOT.'/includes/modules/fichinter/modules_fichinter.php');
$model=new ModelePDFFicheinter();
$modellist=$model->liste_modeles($this->db);
}
}
elseif ($modulepart == 'facture')
{

View File

@ -148,7 +148,7 @@ class ModeleNumRefFicheinter
\param outputlangs objet lang a utiliser pour traduction
\return int 0 si KO, 1 si OK
*/
function fichinter_pdf_create($db, $facid, $modele='', $outputlangs)
function fichinter_pdf_create($db, $id, $modele='', $outputlangs='')
{
global $conf,$langs;
$langs->load("ficheinter");

View File

@ -59,9 +59,15 @@ class pdf_soleil extends ModelePDFFicheinter
{
global $user,$langs,$conf;
$fich = new Fichinter($this->db,"",$id);
if ($fich->fetch($id))
if ($conf->fichinter->dir_output)
{
$fich = new Fichinter($this->db,"",$id);
$result=$fich->fetch($id);
if ($result < 0)
{
dolibarr_print_error($db,$fich->error);
}
$fichref = sanitize_string($fich->ref);
$dir = $conf->fichinter->dir_output . "/" . $fichref;
@ -79,12 +85,23 @@ class pdf_soleil extends ModelePDFFicheinter
$pdf->AddPage();
$pdf->SetXY(10,5);
if (defined("FAC_PDF_INTITULE"))
{
$pdf->SetTextColor(0,0,200);
$pdf->SetFont('Arial','B',14);
$pdf->MultiCell(60, 8, FAC_PDF_INTITULE, 0, 'L');
}
// Logo
$logo=$mysoc->logo;
if (defined("FAC_PDF_LOGO") && FAC_PDF_LOGO) $logo=DOL_DATA_ROOT.FAC_PDF_LOGO;
if ($logo)
{
if (is_readable($logo))
{
$pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
}
else
{
$pdf->SetTextColor(200,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(100, 3, $langs->trans("ErrorLogoFileNotFound",$logo), 0, 'L');
$pdf->MultiCell(100, 3, $langs->trans("ErrorGoToModuleSetup"), 0, 'L');
}
}
$pdf->SetTextColor(70,70,170);
if (defined("FAC_PDF_ADRESSE"))
@ -161,7 +178,7 @@ class pdf_soleil extends ModelePDFFicheinter
}
else
{
$this->error=$langs->trans("ErrorConstantNotDefined","FICHINTER_OUTPUTDIR");
$this->error=$langs->trans("ErrorConstantNotDefined","FICHEINTER_OUTPUTDIR");
return 0;
}
$this->error=$langs->trans("ErrorUnknown");