From 11a3b7f6ebf5e8ca042ae26a403964c1a92f04c2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 4 Mar 2011 16:52:29 +0000 Subject: [PATCH] Fix: reencoding preview tabs, Imagick is a class today Fix: uniformize code --- htdocs/comm/propal/apercu.php | 21 +- htdocs/commande/apercu.php | 329 +++++++++++++----------------- htdocs/compta/facture/apercu.php | 183 +++++++---------- htdocs/compta/prelevement/bon.php | 59 ++---- htdocs/fichinter/apercu.php | 242 ++++++++++------------ 5 files changed, 355 insertions(+), 479 deletions(-) diff --git a/htdocs/comm/propal/apercu.php b/htdocs/comm/propal/apercu.php index 7ef62f9bbab..b71c3a908ad 100644 --- a/htdocs/comm/propal/apercu.php +++ b/htdocs/comm/propal/apercu.php @@ -36,9 +36,10 @@ $langs->load('propal'); $langs->load("bills"); $langs->load('compta'); -$id = isset($_GET["id"])?$_GET["id"]:''; - // Security check +$socid=0; +$id = GETPOST("id"); +$ref = GETPOST("ref"); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'propale', $id, 'propal'); @@ -57,7 +58,7 @@ $html = new Form($db); /* */ /* *************************************************************************** */ -if ($_GET["id"] > 0) +if ($id > 0 || ! empty($ref)) { $object = new Propal($db); @@ -118,16 +119,16 @@ if ($_GET["id"] > 0) /* * Documents */ - $propalref = dol_sanitizeFileName($object->ref); + $objectref = dol_sanitizeFileName($object->ref); $dir_output = $conf->propale->dir_output . "/"; - $filepath = $dir_output . $propalref . "/"; - $file = $filepath . $propalref . ".pdf"; - $filedetail = $filepath . $propalref . "-detail.pdf"; - $relativepath = "${propalref}/${propalref}.pdf"; - $relativepathdetail = "${propalref}/${propalref}-detail.pdf"; + $filepath = $dir_output . $objectref . "/"; + $file = $filepath . $objectref . ".pdf"; + $filedetail = $filepath . $objectref . "-detail.pdf"; + $relativepath = "${objectref}/${objectref}.pdf"; + $relativepathdetail = "${objectref}/${objectref}-detail.pdf"; // Chemin vers png apercus - $relativepathimage = "${propalref}/${propalref}.pdf.png"; + $relativepathimage = "${objectref}/${objectref}.pdf.png"; $fileimage = $file.".png"; // Si PDF d'1 page $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page diff --git a/htdocs/commande/apercu.php b/htdocs/commande/apercu.php index 4868df5e9be..7fb75545529 100644 --- a/htdocs/commande/apercu.php +++ b/htdocs/commande/apercu.php @@ -2,7 +2,7 @@ /* Copyright (C) 2002-2005 Rodolphe Quiedeville * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2005 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2011 Regis Houssin * * 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 @@ -20,20 +20,19 @@ */ /** - \file htdocs/commande/apercu.php - \ingroup commande - \brief Page de l'onglet apercu d'une commande - \version $Id$ -*/ + * \file htdocs/commande/apercu.php + * \ingroup commande + * \brief Page de l'onglet apercu d'une commande + * \version $Id$ + */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); -if (!$user->rights->commande->lire) accessforbidden(); - $langs->load('orders'); $langs->load('propal'); $langs->load("bills"); @@ -42,10 +41,10 @@ $langs->load('sendings'); // Security check $socid=0; -$comid = isset($_GET["id"])?$_GET["id"]:''; +$id = GETPOST("id"); +$ref = GETPOST("ref"); if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'commande',$comid,''); - +$result=restrictedArea($user,'commande',$id,''); /* @@ -62,208 +61,170 @@ $html = new Form($db); /* */ /* *************************************************************************** */ -if ($_GET["id"] > 0) { - $commande = new Commande($db); +if ($id > 0 || ! empty($ref)) +{ + $object = new Commande($db); - if ( $commande->fetch($_GET["id"], $user->societe_id) > 0) - { - $soc = new Societe($db, $commande->socid); - $soc->fetch($commande->socid); + if ($object->fetch($id,$ref) > 0) + { + $soc = new Societe($db, $object->socid); + $soc->fetch($object->socid); - $head = commande_prepare_head($commande); + $head = commande_prepare_head($object); dol_fiche_head($head, 'preview', $langs->trans("CustomerOrder"), 0, 'order'); + print ''; + + // Ref + print '"; + print ''; + print '"; + + // Ref cde client + print ''; + print ''; + $nbrow=6; + print '
'.$langs->trans("Ref")."'.$object->ref.''.$langs->trans("Source").' : '.$object->getLabelSource(); + if ($object->source == 0) + { + // Propale + $propal = new Propal($db); + $propal->fetch($object->propale_id); + print ' -> '.$propal->ref.''; + } + print "
'; + print ''; + print '
'; + print $langs->trans('RefCustomer').''; + print '
'; + print '
'; + print $object->ref_client; + print ''; /* - * Commande + * Documents */ - $sql = 'SELECT s.nom, s.rowid, c.amount_ht, c.fk_projet, c.remise, c.tva, c.total_ttc, c.ref, c.fk_statut, c.date_commande as dp, c.note,'; - $sql.= ' c.fk_user_author, c.fk_user_valid, c.fk_user_cloture, c.date_creation, c.date_valid, c.date_cloture'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; - $sql.= ', '.MAIN_DB_PREFIX.'commande as c'; - $sql.= ' WHERE c.fk_soc = s.rowid'; - $sql.= ' AND c.rowid = '.$commande->id; - if ($socid) $sql .= ' AND s.rowid = '.$socid; + $objectref = dol_sanitizeFileName($object->ref); + $dir_output = $conf->commande->dir_output . "/"; + $filepath = $dir_output . $objectref . "/"; + $file = $filepath . $objectref . ".pdf"; + $filedetail = $filepath . $objectref . "-detail.pdf"; + $relativepath = "${objectref}/${objectref}.pdf"; + $relativepathdetail = "${objectref}/${objectref}-detail.pdf"; - $result = $db->query($sql); + // Chemin vers png apercus + $relativepathimage = "${objectref}/${objectref}.pdf.png"; + $fileimage = $file.".png"; // Si PDF d'1 page + $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page - if ($result) + $var=true; + + // Si fichier PDF existe + if (file_exists($file)) { - if ($db->num_rows($result)) + $encfile = urlencode($file); + print_titre($langs->trans("Documents")); + print ''; + + print ""; + + print ''; + print ''; + print ''; + print ''; + + // Si fichier detail PDF existe + // TODO obsolete ? + if (file_exists($filedetail)) { - $obj = $db->fetch_object($result); + print ""; - $societe = new Societe($db); - $societe->fetch($obj->rowid); - - print '
".$langs->trans("Order")." PDF'.$object->ref.'.pdf'.dol_print_size(dol_filesize($file)).''.dol_print_date(dol_filemtime($file),'dayhour').'
Commande detaillee
'; - - // Ref - print '"; - print ''; - print '"; - - // Ref cde client - print ''; - print ''; - $nbrow=6; - print '"; - - - // Client - print ""; - print ''; - print ''; - - // Statut - print ''; - print "\n"; - print ''; - - // Date - print ''; - print "\n"; - print ''; - - // ligne 6 - // partie Gauche - print ''; - print ''; + print ''; + print ''; + print ''; print ''; - - // ligne 7 - // partie Gauche - print ''; - print ''; - print ''; - print '
'.$langs->trans("Ref")."'.$commande->ref.''.$langs->trans("Source").' : '.$commande->getLabelSource(); - if ($commande->source == 0) - { - // Propale - $propal = new Propal($db); - $propal->fetch($commande->propale_id); - print ' -> '.$propal->ref.''; - } - print "
'; - print ''; - print '
'; - print $langs->trans('RefCustomer').''; - print '
'; - print '
'; - print $commande->ref_client; - print ''; - - /* - * Documents - */ - $commanderef = dol_sanitizeFileName($commande->ref); - $dir_output = $conf->commande->dir_output . "/"; - $filepath = $dir_output . $commanderef . "/"; - $file = $filepath . $commanderef . ".pdf"; - $filedetail = $filepath . $commanderef . "-detail.pdf"; - $relativepath = "${commanderef}/${commanderef}.pdf"; - $relativepathdetail = "${commanderef}/${commanderef}-detail.pdf"; - - // Chemin vers png aper�us - $relativepathimage = "${commanderef}/${commanderef}.pdf.png"; - $fileimage = $file.".png"; // Si PDF d'1 page - $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page - - $var=true; - - // Si fichier PDF existe - if (file_exists($file)) - { - $encfile = urlencode($file); - print_titre($langs->trans("Documents")); - print ''; - - print ""; - - print ''; - print ''; - print ''; - print ''; - - // Si fichier detail PDF existe - if (file_exists($filedetail)) { // commande d�taill�e suppl�mentaire - print ""; - - print ''; - print ''; - print ''; - print ''; - } - print "
".$langs->trans("Order")." PDF'.$commande->ref.'.pdf'.dol_print_size(dol_filesize($file)).''.dol_print_date(dol_filemtime($file),'dayhour').'
Commande detaillee'.$commande->ref.'-detail.pdf'.dol_print_size(dol_filesize($filedetail)).''.dol_print_date(dol_filemtime($filedetail),'dayhour').'
\n"; - - // Conversion du PDF en image png si fichier png non existant - if (! file_exists($fileimage) && ! file_exists($fileimagebis)) - { - if (class_exists("Imagick")) - { - $handle = imagick_readimage( $file ) ; - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - imagick_convert( $handle, "PNG" ) ; - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - imagick_writeimages( $handle, $file .".png"); - } else { - $langs->load("other"); - print ''.$langs->trans("ErrorNoImagickReadimage").''; - } - } - } - - print "
".$langs->trans("Customer")."'; - print ''.$societe->nom.''; - print '
'.$langs->trans("Status").'".$commande->getLibStatut(4)."
'.$langs->trans("Date").'".dol_print_date($commande->date,"daytext")."
'.$langs->trans('GlobalDiscount').''.$commande->remise_percent.'%'.$object->ref.'-detail.pdf'.dol_print_size(dol_filesize($filedetail)).''.dol_print_date(dol_filemtime($filedetail),'dayhour').'
'.$langs->trans('AmountHT').''.price($commande->total_ht).''.$langs->trans("Currency".$conf->monnaie).'
'; } - } else { - dol_print_error($db); + print "
\n"; + + // Conversion du PDF en image png si fichier png non existant + if (! file_exists($fileimage) && ! file_exists($fileimagebis)) + { + if (class_exists("Imagick")) + { + $ret = dol_convert_file($file); + if ($ret < 0) $error++; + } + else + { + $langs->load("other"); + print ''.$langs->trans("ErrorNoImagickReadimage").''; + } + } } - } else { - // Commande non trouv�e - print $langs->trans("ErrorPropalNotFound",$_GET["id"]); + + print ""; + + // Client + print "".$langs->trans("Customer").""; + print ''; + print ''.$soc->nom.''; + print ''; + print ''; + + // Statut + print ''.$langs->trans("Status").''; + print "".$object->getLibStatut(4)."\n"; + print ''; + + // Date + print ''.$langs->trans("Date").''; + print "".dol_print_date($object->date,"daytext")."\n"; + print ''; + + // ligne 6 + // partie Gauche + print ''.$langs->trans('GlobalDiscount').''; + print ''.$object->remise_percent.'%'; + print ''; + + // ligne 7 + // partie Gauche + print ''.$langs->trans('AmountHT').''; + print ''.price($object->total_ht).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + print ''; + } + else + { + // Object not found + print $langs->trans("ErrorOrderNotFound",$id); } } -// Si fichier png PDF d'1 page trouv� +// Si fichier png PDF d'1 page trouve if (file_exists($fileimage)) - { +{ print ''; - } -// Si fichier png PDF de plus d'1 page trouv� +} +// Si fichier png PDF de plus d'1 page trouve elseif (file_exists($fileimagebis)) +{ + $multiple = $relativepathimage . "."; + + for ($i = 0; $i < 20; $i++) { - $multiple = $relativepathimage . "."; - - for ($i = 0; $i < 20; $i++) + $preview = $multiple.$i; + + if (file_exists($dir_output.$preview)) { - $preview = $multiple.$i; - - if (file_exists($dir_output.$preview)) - { - print '

'; - } + print '

'; } } - +} print ''; - - $db->close(); llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 653f963a0ef..18cbea2db3b 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -1,7 +1,8 @@ - * Copyright (C) 2004 �ric Seigne + * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2005-2011 Regis Houssin * * 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 @@ -21,38 +22,33 @@ */ /** - \file htdocs/compta/facture/apercu.php - \ingroup facture - \brief Page de l'onglet apercu d'une facture - \version $Revision$ -*/ + * \file htdocs/compta/facture/apercu.php + * \ingroup facture + * \brief Page de l'onglet apercu d'une facture + * \version $Revision$ + */ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); - -if (!$user->rights->facture->lire) - accessforbidden(); - $langs->load("bills"); - -// S�curit� acc�s client -if ($user->societe_id > 0) -{ - $action = ''; - $socid = $user->societe_id; -} - +// Security check +$socid=0; +$id = GETPOST("id"); +$ref = GETPOST("ref"); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'facture', $id); /* * View */ -$now=gmmktime(); +$now=dol_now(); llxHeader('',$langs->trans("Bill"),'Facture'); @@ -64,20 +60,22 @@ $html = new Form($db); /* */ /* *************************************************************************** */ -if ($_GET["facid"] > 0) +if ($id > 0 || ! empty($ref)) { - $fac = New Facture($db); - if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) + $object = New Facture($db); + + if ($object->fetch($id,$ref) > 0) { - $soc = new Societe($db, $fac->socid); - $soc->fetch($fac->socid); + $soc = new Societe($db, $object->socid); + $soc->fetch($object->socid); + $author = new User($db); - if ($fac->user_author) + if ($object->user_author) { - $author->fetch($fac->user_author); + $author->fetch($object->user_author); } - $head = facture_prepare_head($fac); + $head = facture_prepare_head($object); dol_fiche_head($head, 'preview', $langs->trans("InvoiceCustomer"), 0, 'bill'); @@ -88,7 +86,7 @@ if ($_GET["facid"] > 0) $rowspan=3; // Reference - print ''.$langs->trans('Ref').''.$fac->ref.''; + print ''.$langs->trans('Ref').''.$object->ref.''; // Societe print ''.$langs->trans("Company").''; @@ -97,58 +95,43 @@ if ($_GET["facid"] > 0) // Dates print ''.$langs->trans("Date").''; - print ''.dol_print_date($fac->date,"daytext").''; - print ''.$langs->trans("DateMaxPayment").'' . dol_print_date($fac->date_lim_reglement,"daytext"); - if ($fac->paye == 0 && $fac->date_lim_reglement < ($now - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); + print ''.dol_print_date($object->date,"daytext").''; + print ''.$langs->trans("DateMaxPayment").'' . dol_print_date($object->date_lim_reglement,"daytext"); + if ($object->paye == 0 && $object->date_lim_reglement < ($now - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); print ""; - // Conditions et modes de r�glement + // Conditions et modes de reglement print ''.$langs->trans("PaymentConditions").''; - $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none"); + $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->cond_reglement_id,"none"); print ''; print ''.$langs->trans("PaymentMode").''; - $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none"); + $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$object->id",$object->mode_reglement_id,"none"); print ''; // Remise globale print ''.$langs->trans('GlobalDiscount').''; -/* - if ($fac->brouillon == 1 && $user->rights->facture->creer) - { - print '

'; - print ''; - print ''; - print '% '; - print ''; - print '
'; - } - else - { -*/ - print ''.$fac->remise_percent.'%'; -// } + print ''.$object->remise_percent.'%'; $nbrows=5; if ($conf->projet->enabled) $nbrows++; - print ''; + print ''; /* * Documents */ - $facref = dol_sanitizeFileName($fac->ref); + $objectref = dol_sanitizeFileName($object->ref); $dir_output = $conf->facture->dir_output . "/"; - $filepath = $dir_output . $facref . "/"; - $file = $filepath . $facref . ".pdf"; - $filedetail = $filepath . $facref . "-detail.pdf"; - $relativepath = "${facref}/${facref}.pdf"; - $relativepathdetail = "${facref}/${facref}-detail.pdf"; + $filepath = $dir_output . $objectref . "/"; + $file = $filepath . $objectref . ".pdf"; + $filedetail = $filepath . $objectref . "-detail.pdf"; + $relativepath = "${objectref}/${objectref}.pdf"; + $relativepathdetail = "${objectref}/${objectref}-detail.pdf"; - // Chemin vers png aper�us - $relativepathimage = "${facref}/${facref}.pdf.png"; + // Chemin vers png apercus + $relativepathimage = "${obejctref}/${objectref}.pdf.png"; $fileimage = $file.".png"; // Si PDF d'1 page $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page - $var=true; // Si fichier PDF existe @@ -160,7 +143,7 @@ if ($_GET["facid"] > 0) print "".$langs->trans("Bill")." PDF"; - print ''.$fac->ref.'.pdf'; + print ''.$object->ref.'.pdf'; print ''.dol_print_size(dol_filesize($file)). ''; print ''.dol_print_date(dol_filemtime($file),'dayhour').''; print ''; @@ -168,9 +151,9 @@ if ($_GET["facid"] > 0) // Si fichier detail PDF existe if (file_exists($filedetail)) // facture detaillee supplementaire { - print "Facture d�taill�e"; + print "Facture detaillee"; - print ''.$fac->ref.'-detail.pdf'; + print ''.$object->ref.'-detail.pdf'; print ''.dol_print_size(dol_filesize($filedetail)).''; print ''.dol_print_date(dol_filemtime($filedetail),'dayhour').''; print ''; @@ -179,35 +162,17 @@ if ($_GET["facid"] > 0) print "\n"; // Conversion du PDF en image png si fichier png non existant - if (! file_exists($fileimage) && ! file_exists($fileimagebis)) - { - if (class_exists("Imagick")) - { - $handle = imagick_readimage( $file ) ; - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - - imagick_convert( $handle, "PNG" ) ; - - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - - imagick_writeimages( $handle, $file .".png"); + if (! file_exists($fileimage) && ! file_exists($fileimagebis)) + { + if (class_exists("Imagick")) + { + $ret = dol_convert_file($file); + if ($ret < 0) $error++; } else - { - $langs->load("other"); - print ''.$langs->trans("ErrorNoImagickReadimage").''; + { + $langs->load("other"); + print ''.$langs->trans("ErrorNoImagickReadimage").''; } } @@ -215,16 +180,16 @@ if ($_GET["facid"] > 0) print ""; print ''.$langs->trans("AmountHT").''; - print ''.price($fac->total_ht).''; + print ''.price($object->total_ht).''; print ''.$langs->trans("Currency".$conf->monnaie).''; - print ''.$langs->trans('AmountVAT').''.price($fac->total_tva).''; + print ''.$langs->trans('AmountVAT').''.price($object->total_tva).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; - print ''.$langs->trans('AmountTTC').''.price($fac->total_ttc).''; + print ''.$langs->trans('AmountTTC').''.price($object->total_ttc).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; // Statut - print ''.$langs->trans('Status').''.($fac->getLibStatut()).''; + print ''.$langs->trans('Status').''.($object->getLibStatut()).''; // Projet if ($conf->projet->enabled) @@ -232,11 +197,11 @@ if ($_GET["facid"] > 0) $langs->load("projects"); print ''; print ''.$langs->trans("Project").''; - if ($fac->fk_project > 0) + if ($object->fk_project > 0) { $project = New Project($db); - $project->fetch($fac->fk_project); - print ''.$project->title.''; + $project->fetch($object->fk_project); + print ''.$project->title.''; } else { @@ -250,36 +215,34 @@ if ($_GET["facid"] > 0) } else { - // Facture non trouv�e + // Facture non trouvee print $langs->trans("ErrorBillNotFound",$_GET["facid"]); } } -// Si fichier png PDF d'1 page trouv� +// Si fichier png PDF d'1 page trouve if (file_exists($fileimage)) { print ''; } -// Si fichier png PDF de plus d'1 page trouv� +// Si fichier png PDF de plus d'1 page trouve elseif (file_exists($fileimagebis)) +{ + $multiple = $relativepathimage . "."; + + for ($i = 0; $i < 20; $i++) { - $multiple = $relativepathimage . "."; - - for ($i = 0; $i < 20; $i++) + $preview = $multiple.$i; + + if (file_exists($dir_output.$preview)) { - $preview = $multiple.$i; - - if (file_exists($dir_output.$preview)) - { - print '

'; - } + print '

'; + } } } - print ''; - $db->close(); llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/compta/prelevement/bon.php b/htdocs/compta/prelevement/bon.php index cbafdbd4ccc..a991c0a97ca 100644 --- a/htdocs/compta/prelevement/bon.php +++ b/htdocs/compta/prelevement/bon.php @@ -27,76 +27,61 @@ require('../../main.inc.php'); require_once(DOL_DOCUMENT_ROOT."/lib/prelevement.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once DOL_DOCUMENT_ROOT."/compta/prelevement/class/bon-prelevement.class.php"; $langs->load("bills"); $langs->load("categories"); -/* - * Securite acces client - */ -if (!$user->rights->prelevement->bons->lire) accessforbidden(); +// Security check +$socid=0; +$id = GETPOST("id"); +$ref = GETPOST("ref"); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'prelevement', $id); llxHeader('','Bon de prelevement'); $html = new Form($db); -if ($_GET["id"]) +if ($id > 0 || ! empty($ref)) { - $bon = new BonPrelevement($db,""); + $object = new BonPrelevement($db,""); - if ($bon->fetch($_GET["id"]) == 0) + if ($object->fetch($id) == 0) { - $head = prelevement_prepare_head($bon); - dol_fiche_head($head, 'preview', 'Prelevement : '. $bon->ref); + $head = prelevement_prepare_head($object); + dol_fiche_head($head, 'preview', 'Prelevement : '. $object->ref); print ''; - print ''; - print ''; + print ''; + print ''; print ''; print '
'.$langs->trans("Ref").''.$bon->ref.'
'.$langs->trans("Amount").''.price($bon->amount).'
'.$langs->trans("Ref").''.$object->ref.'
'.$langs->trans("Amount").''.price($object->amount).'
'.$langs->trans("File").''; - $relativepath = 'bon/'.$bon->ref; + $relativepath = 'bon/'.$object->ref; - print ''.$bon->ref.''; + print ''.$object->ref.''; print '

'; - $fileimage = $conf->prelevement->dir_output.'/receipts/'.$bon->ref.'.ps.png.0'; - $fileps = $conf->prelevement->dir_output.'/receipts/'.$bon->ref.'.ps'; + $fileimage = $conf->prelevement->dir_output.'/receipts/'.$object->ref.'.ps.png.0'; + $fileps = $conf->prelevement->dir_output.'/receipts/'.$object->ref.'.ps'; // Conversion du PDF en image png si fichier png non existant if (!file_exists($fileimage)) { - print $fileimage; if (class_exists("Imagick")) { - - $handle = imagick_readimage( $fileps ) ; - - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - imagick_convert( $handle, "PNG" ) ; - - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - imagick_writeimage( $handle, $fileps .".png"); + $ret = dol_convert_file($file); + if ($ret < 0) $error++; } else { - print "Les fonctions imagick ne sont pas disponibles sur ce PHP"; + $langs->load("other"); + print ''.$langs->trans("ErrorNoImagickReadimage").''; } } diff --git a/htdocs/fichinter/apercu.php b/htdocs/fichinter/apercu.php index ccb8f9cf715..d59987a57a0 100644 --- a/htdocs/fichinter/apercu.php +++ b/htdocs/fichinter/apercu.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2011 Regis Houssin * * 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 @@ -27,17 +27,19 @@ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/fichinter.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); $langs->load('interventions'); -$fichinterid = isset($_GET["id"])?$_GET["id"]:''; // Security check +$socid=0; +$id = GETPOST("id"); +$ref = GETPOST("ref"); if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); - +$result = restrictedArea($user, 'ficheinter', $id, 'fichinter'); llxHeader(); @@ -49,158 +51,124 @@ $html = new Form($db); /* */ /* *************************************************************************** */ -if ($_GET["id"] > 0) { - $fichinter = new Fichinter($db); +if ($id > 0 || ! empty($ref)) +{ + $object = new Fichinter($db); - if ( $fichinter->fetch($_GET["id"], $user->societe_id) > 0) + if ($object->fetch($id,$ref) > 0) { - $soc = new Societe($db, $fichinter->socid); - $soc->fetch($fichinter->socid); + $soc = new Societe($db, $object->socid); + $soc->fetch($object->socid); - - $head = fichinter_prepare_head($fichinter); + $head = fichinter_prepare_head($object); dol_fiche_head($head, 'preview', $langs->trans("InterventionCard"), 0, 'intervention'); - /* * Fiche intervention */ - $sql = 'SELECT s.nom, s.rowid, fi.fk_projet, fi.ref, fi.description, fi.fk_statut, fi.datei as di,'; - $sql.= ' fi.fk_user_author, fi.fk_user_valid, fi.datec, fi.date_valid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'fichinter as fi'; - $sql.= ' WHERE fi.fk_soc = s.rowid'; - $sql.= ' AND fi.rowid = '.$fichinter->id; - $sql.= ' AND fi.entity = '.$conf->entity; - if ($socid) $sql .= ' AND s.rowid = '.$socid; - - $result = $db->query($sql); - - if ($result) + print ''; + + // Ref + print '"; + print ''; + + $nbrow=4; + print '
'.$langs->trans("Ref")."'.$object->ref.''; + + /* + * Documents + */ + $objectref = dol_sanitizeFileName($object->ref); + $dir_output = $conf->ficheinter->dir_output . "/"; + $filepath = $dir_output . $objectref . "/"; + $file = $filepath . $objectref . ".pdf"; + $filedetail = $filepath . $objectref . "-detail.pdf"; + $relativepath = "${objectref}/${objectref}.pdf"; + $relativepathdetail = "${objectref}/${objectref}-detail.pdf"; + + // Chemin vers png apercus + $relativepathimage = "${objectref}/${objectref}.pdf.png"; + $fileimage = $file.".png"; // Si PDF d'1 page + $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page + + $var=true; + + // Si fichier PDF existe + if (file_exists($file)) { - if ($db->num_rows($result)) + $encfile = urlencode($file); + print_titre($langs->trans("Documents")); + print ''; + + print ""; + + print ''; + print ''; + print ''; + print ''; + + // Si fichier detail PDF existe + if (file_exists($filedetail)) { - $obj = $db->fetch_object($result); - - $societe = new Societe($db); - $societe->fetch($obj->rowid); - - print '
".$langs->trans("Intervention")." PDF'.$object->ref.'.pdf'.dol_print_size(dol_filesize($file)).''.dol_print_date(dol_filemtime($file),'dayhour').'
'; - - // Ref - print '"; - print ''; - - $nbrow=4; - print '"; - - - // Client - print ""; - print ''; + print ""; + + print ''; + print ''; + print ''; print ''; - - // Statut - print ''; - print "\n"; - print ''; - - // Date - print ''; - print "\n"; - print ''; - - print '
'.$langs->trans("Ref")."'.$fichinter->ref.''; - - /* - * Documents - */ - $fichinterref = dol_sanitizeFileName($fichinter->ref); - $dir_output = $conf->ficheinter->dir_output . "/"; - $filepath = $dir_output . $fichinterref . "/"; - $file = $filepath . $fichinterref . ".pdf"; - $filedetail = $filepath . $fichinterref . "-detail.pdf"; - $relativepath = "${fichinterref}/${fichinterref}.pdf"; - $relativepathdetail = "${fichinterref}/${fichinterref}-detail.pdf"; - - // Chemin vers png apercus - $relativepathimage = "${fichinterref}/${fichinterref}.pdf.png"; - $fileimage = $file.".png"; // Si PDF d'1 page - $fileimagebis = $file.".png.0"; // Si PDF de plus d'1 page - - $var=true; - - // Si fichier PDF existe - if (file_exists($file)) - { - $encfile = urlencode($file); - print_titre($langs->trans("Documents")); - print ''; - - print ""; - - print ''; - print ''; - print ''; - print ''; - - // Si fichier detail PDF existe - if (file_exists($filedetail)) { // fichinter d�taill�e suppl�mentaire - print ""; - - print ''; - print ''; - print ''; - print ''; - } - print "
".$langs->trans("Intervention")." PDF'.$fichinter->ref.'.pdf'.dol_print_size(dol_filesize($file)).''.dol_print_date(dol_filemtime($file),'dayhour').'
Fiche d'intervention d�taill�e'.$fichinter->ref.'-detail.pdf'.dol_print_size(dol_filesize($filedetail)).''.dol_print_date(dol_filemtime($filedetail),'dayhour').'
\n"; - - // Conversion du PDF en image png si fichier png non existant - if (! file_exists($fileimage) && ! file_exists($fileimagebis)) - { - if (class_exists("Imagick")) - { - $handle = imagick_readimage( $file ) ; - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - imagick_convert( $handle, "PNG" ) ; - if ( imagick_iserror( $handle ) ) - { - $reason = imagick_failedreason( $handle ) ; - $description = imagick_faileddescription( $handle ) ; - print "handle failed!
\nReason: $reason
\nDescription: $description
\n"; - } - imagick_writeimages( $handle, $file .".png"); - } else { - $langs->load("other"); - print ''.$langs->trans("ErrorNoImagickReadimage").''; - } - } - } - - print "
".$langs->trans("Customer")."'; - print ''.$societe->nom.''; - print '
Fiche d'intervention detaillee'.$object->ref.'-detail.pdf'.dol_print_size(dol_filesize($filedetail)).''.dol_print_date(dol_filemtime($filedetail),'dayhour').'
'.$langs->trans("Status").'".$fichinter->getLibStatut(4)."
'.$langs->trans("Date").'".dol_print_date($fichinter->date,"daytext")."
'; } - } else { - dol_print_error($db); + print "
\n"; + + // Conversion du PDF en image png si fichier png non existant + if (! file_exists($fileimage) && ! file_exists($fileimagebis)) + { + if (class_exists("Imagick")) + { + $ret = dol_convert_file($file); + if ($ret < 0) $error++; + } + else + { + $langs->load("other"); + print ''.$langs->trans("ErrorNoImagickReadimage").''; + } + } } - } else { - // Intervention non trouv�e - print $langs->trans("ErrorFichinterNotFound",$_GET["id"]); + + print ""; + + // Client + print "".$langs->trans("Customer").""; + print ''; + print ''.$soc->nom.''; + print ''; + print ''; + + // Statut + print ''.$langs->trans("Status").''; + print "".$object->getLibStatut(4)."\n"; + print ''; + + // Date + print ''.$langs->trans("Date").''; + print "".dol_print_date($object->date,"daytext")."\n"; + print ''; + + print ''; + } + else + { + // Object not found + print $langs->trans("ErrorFichinterNotFound",$id); } } -// Si fichier png PDF d'1 page trouv� +// Si fichier png PDF d'1 page trouve if (file_exists($fileimage)) { print ''; } -// Si fichier png PDF de plus d'1 page trouv� +// Si fichier png PDF de plus d'1 page trouve elseif (file_exists($fileimagebis)) { $multiple = $relativepathimage . "."; @@ -216,10 +184,8 @@ elseif (file_exists($fileimagebis)) } } - print ''; - $db->close(); llxFooter('$Date$ - $Revision$');