Fix: bug #9908 overview: PDF de fiche d'intervention non généré

This commit is contained in:
Laurent Destailleur 2005-04-02 20:14:13 +00:00
parent e9ee2df17c
commit c816fa9d08
3 changed files with 401 additions and 423 deletions

View File

@ -20,7 +20,8 @@
* $Source$ * $Source$
*/ */
/** \file htdocs/fichinter/fiche.php /**
\file htdocs/fichinter/fiche.php
\brief Fichier fiche intervention \brief Fichier fiche intervention
\ingroup ficheinter \ingroup ficheinter
\version $Revision$ \version $Revision$
@ -46,24 +47,20 @@ if ($_GET["socidp"])
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
if ( $db->num_rows() ) if ( $db->num_rows($result) )
{ {
$objsoc = $db->fetch_object($result); $objsoc = $db->fetch_object($result);
} }
$db->free(); $db->free($result);
} }
else { else {
dolibarr_print_error($db); dolibarr_print_error($db);
} }
} }
llxHeader();
/* /*
* Traitements des actions * Traitements des actions
*
*
*/ */
if ($_GET["action"] == 'valid') if ($_GET["action"] == 'valid')
@ -106,17 +103,21 @@ if ($_POST["action"] == 'update')
$_GET["id"]=$_POST["id"]; // Force raffraichissement sur fiche venant d'etre créée $_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"]) if ($_GET["action"] == 'generate' && $_GET["id"])
{ {
fichinter_pdf_create($db, $_GET["id"]); fichinter_pdf_create($db, $_GET["id"]);
$mesg = "PDF généré";
} }
llxHeader();
$sel = new Form($db);
/* /*
* *
* Mode creation * Mode creation
@ -125,7 +126,7 @@ if ($_GET["action"] == 'generate' && $_GET["id"])
*/ */
if ($_GET["action"] == 'create') if ($_GET["action"] == 'create')
{ {
print_titre("Création d'une fiche d'intervention"); print_titre($langs->trans("AddIntervention"));
if ( $objsoc->prefix_comm ) if ( $objsoc->prefix_comm )
{ {
@ -133,10 +134,11 @@ if ($_GET["action"] == 'create')
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal WHERE ref like '$numpr%'"; $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal WHERE ref like '$numpr%'";
if ( $db->query($sql) ) $result=$db->query($sql);
if ($result)
{ {
$num = $db->result(0, 0); $num = $db->result(0, 0);
$db->free(); $db->free($result);
if ($num > 0) if ($num > 0)
{ {
$numpr .= "." . ($num + 1); $numpr .= "." . ($num + 1);
@ -148,19 +150,6 @@ if ($_GET["action"] == 'create')
print "<form action=\"fiche.php\" method=\"post\">"; print "<form action=\"fiche.php\" method=\"post\">";
$strmonth[1] = "Janvier";
$strmonth[2] = "F&eacute;vrier";
$strmonth[3] = "Mars";
$strmonth[4] = "Avril";
$strmonth[5] = "Mai";
$strmonth[6] = "Juin";
$strmonth[7] = "Juillet";
$strmonth[8] = "Ao&ucirc;t";
$strmonth[9] = "Septembre";
$strmonth[10] = "Octobre";
$strmonth[11] = "Novembre";
$strmonth[12] = "D&eacute;cembre";
$smonth = 1; $smonth = 1;
$syear = date("Y", time()); $syear = date("Y", time());
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -169,41 +158,8 @@ if ($_GET["action"] == 'create')
print "<tr><td>".$langs->trans("Company")."</td><td><b>".$objsoc->nom."</td></tr>"; print "<tr><td>".$langs->trans("Company")."</td><td><b>".$objsoc->nom."</td></tr>";
print "<tr><td>".$langs->trans("Date")."</td><td>"; print "<tr><td>".$langs->trans("Date")."</td><td>";
$cday = date("d", time()); $sel->select_date(time(),"p");
print "<select name=\"pday\">"; print "</td></tr>";
for ($day = 1 ; $day < $sday + 32 ; $day++)
{
if ($day == $cday)
{
print "<option value=\"$day\" selected>$day";
}
else
{
print "<option value=\"$day\">$day";
}
}
print "</select>";
$cmonth = date("n", time());
print "<select name=\"pmonth\">";
for ($month = $smonth ; $month < $smonth + 12 ; $month++) {
if ($month == $cmonth)
{
print "<option value=\"$month\" selected>" . $strmonth[$month];
}
else
{
print "<option value=\"$month\">" . $strmonth[$month];
}
}
print "</select>";
print "<select name=\"pyear\">";
for ($year = $syear ; $year < $syear + 5 ; $year++)
{
print "<option value=\"$year\">$year";
}
print "</select></td></tr>";
print "<input type=\"hidden\" name=\"action\" value=\"add\">"; print "<input type=\"hidden\" name=\"action\" value=\"add\">";
@ -211,7 +167,7 @@ if ($_GET["action"] == 'create')
print "<tr><td>".$langs->trans("Duration")." (".$langs->trans("days").")</td><td><input name=\"duree\"></td></tr>\n"; print "<tr><td>".$langs->trans("Duration")." (".$langs->trans("days").")</td><td><input name=\"duree\"></td></tr>\n";
if ($conf->projet->enabled) { if ($conf->projet->enabled) {
// Projet associé // Projet associ
$langs->load("project"); $langs->load("project");
print '<tr><td valign="top">'.$langs->trans("Project").'</td><td><select name="projetidp">'; print '<tr><td valign="top">'.$langs->trans("Project").'</td><td><select name="projetidp">';
print '<option value="0"></option>'; print '<option value="0"></option>';
@ -258,7 +214,6 @@ if ($_GET["action"] == 'create')
} }
$sel = new Form($db);
/* /*
* *
@ -279,7 +234,7 @@ if ($_GET["action"] == 'edit')
$listeprj = $prj->liste_array($fichinter->societe_id); $listeprj = $prj->liste_array($fichinter->societe_id);
print_titre("Mettre à jour Fiche d'intervention"); print_titre($langs->trans("EditIntervention"));
print "<form action=\"fiche.php\" method=\"post\">"; print "<form action=\"fiche.php\" method=\"post\">";
@ -289,13 +244,13 @@ if ($_GET["action"] == 'edit')
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print "<tr><td>".$langs->trans("Date")."</td><td>"; print "<tr><td>".$langs->trans("Date")."</td><td>";
$sel->select_date($fichinter->date); $sel->select_date($fichinter->date);
print "</select></td></tr>"; print "</td></tr>";
print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$fichinter->ref.'</td></tr>'; print '<tr><td>'.$langs->trans("Ref").'</td><td>'.$fichinter->ref.'</td></tr>';
print '<tr><td>'.$langs->trans("Duration")." (".$langs->trans("days").')</td><td><input name="duree" value="'.$fichinter->duree.'"></td></tr>'; print '<tr><td>'.$langs->trans("Duration")." (".$langs->trans("days").')</td><td><input name="duree" value="'.$fichinter->duree.'"></td></tr>';
if ($conf->projet->enabled) { if ($conf->projet->enabled) {
// Projet associé // Projet associ
print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>'; print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
$sel->select_array("projetidp",$listeprj,$fichinter->projet_id); $sel->select_array("projetidp",$listeprj,$fichinter->projet_id);
@ -330,7 +285,7 @@ if ($_GET["action"] == 'edit')
if ($_GET["id"] && $_GET["action"] != 'edit') if ($_GET["id"] && $_GET["action"] != 'edit')
{ {
print_fiche_titre("Fiche d'intervention",$mesg); print_fiche_titre($langs->trans("Intervention"),$mesg);
$fichinter = new Fichinter($db); $fichinter = new Fichinter($db);
if ($fichinter->fetch($_GET["id"])) if ($fichinter->fetch($_GET["id"]))
@ -346,6 +301,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit')
$fichinter->fetch_projet(); $fichinter->fetch_projet();
print '<tr><td valign="top">'.$langs->trans("Ref").'</td><td>'.$fichinter->projet.'</td></tr>'; print '<tr><td valign="top">'.$langs->trans("Ref").'</td><td>'.$fichinter->projet.'</td></tr>';
} }
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$fichinter->statut.'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("Description").'</td>'; print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
print nl2br($fichinter->note); print nl2br($fichinter->note);
@ -370,25 +326,26 @@ if ($_GET["id"] && $_GET["action"] != 'edit')
print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=edit">'.$langs->trans("Edit").'</a>'; print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=edit">'.$langs->trans("Edit").'</a>';
} }
$file = $conf->fichinter->dir_output . "/$fichinter->ref/$fichinter->ref.pdf"; if ($fichinter->statut == 0)
{
print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=valid">'.$langs->trans("Valid").'</a>';
}
$file = $conf->fichinter->dir_output."/".$fichinter->ref."/".$fichinter->ref.pdf;
if ($fichinter->statut == 0 or !file_exists($file)) if ($fichinter->statut == 0 or !file_exists($file))
{ {
$langs->load("bills"); $langs->load("bills");
print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=generate">'.$langs->trans("BuildPDF").'</a>'; print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=generate">'.$langs->trans("BuildPDF").'</a>';
} }
if ($fichinter->statut == 0)
{
print '<a class="tabAction" href="fiche.php?id='.$_GET["id"].'&action=valid">'.$langs->trans("Valid").'</a>';
}
} }
print '</div>'; print '</div>';
print '<br>'; print '<br>';
print '<table width="50%" cellspacing="2"><tr><td width="50%" valign="top">'; print '<table width="50%" cellspacing="2"><tr><td width="50%" valign="top">';
print_titre("Documents générés");
print_titre($langs->trans("Documents"));
print '<table width="100%" class="border">'; print '<table width="100%" class="border">';
$file = $conf->fichinter->dir_output . "/$fichinter->ref/$fichinter->ref.pdf"; $file = $conf->fichinter->dir_output . "/$fichinter->ref/$fichinter->ref.pdf";

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* 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
@ -22,7 +22,8 @@
* *
*/ */
/*! \file htdocs/includes/modules/fichinter/modules_fichinter.php /**
\file htdocs/includes/modules/fichinter/modules_fichinter.php
\ingroup ficheinter \ingroup ficheinter
\brief Fichier contenant la classe mère de generation des fiches interventions en PDF \brief Fichier contenant la classe mère de generation des fiches interventions en PDF
et la classe mère de numérotation des fiches interventions et la classe mère de numérotation des fiches interventions
@ -30,7 +31,8 @@
*/ */
/*! \class ModelePDFFicheinter /**
\class ModelePDFFicheinter
\brief Classe mère des modèles de fiche intervention \brief Classe mère des modèles de fiche intervention
*/ */
@ -38,14 +40,14 @@ class ModelePDFFicheinter extends FPDF
{ {
var $error=''; var $error='';
/*! \brief Constructeur /** \brief Constructeur
*/ */
function ModelePDFFicheinter() function ModelePDFFicheinter()
{ {
} }
/*! /**
\brief Renvoi le dernier message d'erreur de création de fiche intervention \brief Renvoi le dernier message d'erreur de création de fiche intervention
*/ */
function pdferror() function pdferror()
@ -56,7 +58,7 @@ class ModelePDFFicheinter extends FPDF
} }
/*! \class ModeleNumRefFicheinter /** \class ModeleNumRefFicheinter
\brief Classe mère des modèles de numérotation des références de fiches d'intervention \brief Classe mère des modèles de numérotation des références de fiches d'intervention
*/ */
@ -64,7 +66,7 @@ class ModeleNumRefFicheinter
{ {
var $error=''; var $error='';
/*! \brief Renvoi la description par defaut du modele de numérotation /** \brief Renvoi la description par defaut du modele de numérotation
* \return string Texte descripif * \return string Texte descripif
*/ */
function info() function info()
@ -74,7 +76,7 @@ class ModeleNumRefFicheinter
return $langs->trans("NoDescription"); return $langs->trans("NoDescription");
} }
/*! \brief Renvoi un exemple de numérotation /** \brief Renvoi un exemple de numérotation
* \return string Example * \return string Example
*/ */
function getExample() function getExample()
@ -84,7 +86,7 @@ class ModeleNumRefFicheinter
return $langs->trans("NoExample"); return $langs->trans("NoExample");
} }
/*! /**
\brief Renvoi le dernier message d'erreur de création de fiche intervention \brief Renvoi le dernier message d'erreur de création de fiche intervention
*/ */
function numreferror() function numreferror()
@ -95,10 +97,11 @@ class ModeleNumRefFicheinter
} }
/*! /**
\brief Crée une fiche intervention sur disque en fonction du modèle de FICHEINTER_ADDON_PDF \brief Crée une fiche intervention sur disque en fonction du modèle de FICHEINTER_ADDON_PDF
\param db objet base de donnée \param db objet base de donnée
\param facid id de la facture à créer \param facid id de la facture à créer
\return int 0 si KO, 1 si OK
*/ */
function fichinter_pdf_create($db, $facid) function fichinter_pdf_create($db, $facid)
{ {

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* 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
@ -21,21 +22,24 @@
* *
*/ */
/*! \file htdocs/includes/modules/fichinter/pdf_soleil.modules.php /**
\file htdocs/includes/modules/fichinter/pdf_soleil.modules.php
\ingroup ficheinter \ingroup ficheinter
\brief Fichier de la classe permettant de générer les fiches d'intervention au modèle Soleil \brief Fichier de la classe permettant de générer les fiches d'intervention au modèle Soleil
\version $Revision$ \version $Revision$
*/ */
/*! \class pdf_soleil /**
\class pdf_soleil
\brief Classe permettant de générer les fiches d'intervention au modèle Soleil \brief Classe permettant de générer les fiches d'intervention au modèle Soleil
*/ */
class pdf_soleil extends ModelePDFFicheinter class pdf_soleil extends ModelePDFFicheinter
{ {
/*! \brief Constructeur /**
\brief Constructeur
\param db handler accès base de donnée \param db handler accès base de donnée
*/ */
function pdf_soleil($db=0) function pdf_soleil($db=0)
@ -44,24 +48,32 @@ class pdf_soleil extends ModelePDFFicheinter
$this->description = "Modèle de fiche d'intervention stantdard"; $this->description = "Modèle de fiche d'intervention stantdard";
} }
/*! /**
\brief Fonction générant la fiche d'intervention sur le disque \brief Fonction générant la fiche d'intervention sur le disque
\param id id de la fiche intervention à générer \param id id de la fiche intervention à générer
\return int 1=ok, 0=ko
*/ */
function write_pdf_file($id) function write_pdf_file($id)
{ {
global $conf; global $user,$langs,$conf;
$fich = new Fichinter($this->db,"",$id); $fich = new Fichinter($this->db,"",$id);
if ($fich->fetch($id)) if ($fich->fetch($id))
{ {
$dir = $conf->fichinter->dir_output . "/" . $fich->ref . "/" ; $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
$file = $dir . $fich->ref . ".pdf"; $fichref = str_replace($forbidden_chars,"_",$fich->ref);
$dir = $conf->fichinter->dir_output . "/" . $fichref;
$file = $dir . "/" . $fichref . ".pdf";
if (! file_exists($dir)) if (! file_exists($dir))
{ {
umask(0); umask(0);
mkdir($dir, 0755); if (! mkdir($dir, 0755))
{
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return 0;
}
} }
if (file_exists($dir)) if (file_exists($dir))
@ -122,11 +134,6 @@ class pdf_soleil extends ModelePDFFicheinter
$pdf->Text(11, 88, "Date : " . strftime("%d %b %Y", $fich->date)); $pdf->Text(11, 88, "Date : " . strftime("%d %b %Y", $fich->date));
$pdf->Text(11, 94, "Fiche d'intervention : ".$fich->ref); $pdf->Text(11, 94, "Fiche d'intervention : ".$fich->ref);
/*
*/
/*
*/
$pdf->SetFillColor(220,220,220); $pdf->SetFillColor(220,220,220);
$pdf->SetTextColor(0,0,0); $pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','',12); $pdf->SetFont('Arial','',12);
@ -139,20 +146,31 @@ class pdf_soleil extends ModelePDFFicheinter
$pdf->line(10, $tab_top + 8, 200, $tab_top + 8 ); $pdf->line(10, $tab_top + 8, 200, $tab_top + 8 );
$pdf->Rect(10, $tab_top, 190, $tab_height); $pdf->Rect(10, $tab_top, 190, $tab_height);
/*
*
*/
$pdf->SetFont('Arial','', 10); $pdf->SetFont('Arial','', 10);
$pdf->SetXY (10, $tab_top + 8 ); $pdf->SetXY (10, $tab_top + 8 );
$pdf->MultiCell(190, 5, $fich->note, 0, 'J', 0); $pdf->MultiCell(190, 5, $fich->note, 0, 'J', 0);
/* $pdf->Close();
*
*/
$pdf->Output($file); $pdf->Output($file);
return 1;
}
else
{
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return 0;
} }
} }
else
{
$this->error=$langs->trans("ErrorConstantNotDefined","FICHINTER_OUTPUTDIR");
return 0;
}
$this->error=$langs->trans("ErrorUnknown");
return 0; // Erreur par defaut
} }
} }