From 4d6b25eb45695ef638ea4f6de6e7f9a17b76208a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 May 2015 21:47:44 +0200 Subject: [PATCH] Prepare to generalize usage of get_exdir --- htdocs/core/class/html.formfile.class.php | 5 +-- htdocs/core/lib/functions.lib.php | 42 +++++++++++++------ .../modules/propale/doc/pdf_azur.modules.php | 42 +++++++++---------- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index cecbefa0dd9de..6464f653fd437 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -6,7 +6,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2014 Marcos García * Copyright (C) 2015 Bahfir Abbes - + * 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 * the Free Software Foundation; either version 3 of the License, or @@ -265,7 +265,6 @@ function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed if (! is_object($form)) $form=new Form($this->db); - // filedir = $conf->...->dir_ouput."/".get_exdir(id) include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // For backward compatibility @@ -707,7 +706,7 @@ function getDocumentsLink($modulepart, $modulesubdir, $filedir) $relativepath = $file["name"]; } if ($modulepart == 'facture_fournisseur') { - $relativepath = get_exdir($modulesubdir, 2). $modulesubdir. "/" . $file["name"]; + $relativepath = get_exdir($modulesubdir, 2). $modulesubdir. "/" . $file["name"]; } // Show file name with link to download diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 194a6b3c3bb3f..5938bc07eae77 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3701,26 +3701,42 @@ function yn($yesno, $case=1, $color=0) /** - * Return a path to have a directory according to an id + * Return a path to have a directory according to object. * Examples: '001' with level 3->"0/0/1/", '015' with level 3->"0/1/5/" * Examples: 'ABC-1' with level 3 ->"0/0/1/", '015' with level 1->"5/" * - * @param string $num Id to develop - * @param int $level Level of development (1, 2 or 3 level) + * @param string $num Id of object + * @param int $level Level of subdirs to return (1, 2 or 3 levels) * @param int $alpha Use alpha ref - * @param int $withoutslash 0=With slash at end, 1=without slash at end - * @return string Dir to use + * @param int $withoutslash 0=With slash at end, 1=without slash at end (except if '/', we return '') + * @param string $ref Not used yet. May be used to manage different option of directory path according to element. + * @param string $modulepart Not used yet. May be used to manage different option of directory path according to element. + * @return string Dir to use ending. Example '' or '1/' or '1/2/' */ -function get_exdir($num,$level=3,$alpha=0,$withoutslash=0) +function get_exdir($num,$level,$alpha=0,$withoutslash=0,$ref='',$modulepart='') { + global $conf; + $path = ''; - if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num); - else $num = preg_replace('/^.*\-/i','',$num); - $num = substr("000".$num, -$level); - if ($level == 1) $path = substr($num,0,1); - if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1); - if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1); - if (empty($withoutslash)) $path.='/'; + + if (in_array($modulepart, array('don','donation','supplier_invoice','invoice_supplier'))) + { + if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num); + else $num = preg_replace('/^.*\-/i','',$num); + $num = substr("000".$num, -$level); + if ($level == 1) $path = substr($num,0,1); + if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1); + if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1); + } + else + { + // TODO + // We will introduce here a common way of forging path for document storage + // Here, $num=id, ref and modulepart are required. + + } + + if (empty($withoutslash) && ! empty($path)) $path.='/'; return $path; } diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 3f8d7f542f73d..5463694f0e849 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -184,8 +184,8 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid } else { - $pdir[0] = dol_sanitizeFileName($objphoto->ref).'/'; - $pdir[1] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/"; + $pdir[0] = dol_sanitizeFileName($objphoto->ref).'/'; // default + $pdir[1] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/"; // alternative } $arephoto = false; @@ -331,7 +331,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); $tab_height = 130; $tab_height_newpage = 150; - + // Incoterm $height_incoterms = 0; if ($conf->incoterm->enabled) @@ -345,11 +345,11 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1); $nexY = $pdf->GetY(); $height_incoterms=$nexY-$tab_top; - + // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192,192,192); $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1); - + $tab_top = $nexY+6; $height_incoterms += 4; } @@ -644,7 +644,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); } */ - + // Customer signature area $posy=$this->_signature_area($pdf, $object, $posy, $outputlangs); @@ -653,33 +653,33 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); //If propal merge product PDF is active - if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) + if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) { require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php'; - + $already_merged = array (); foreach ( $object->lines as $line ) { if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) { // Find the desire PDF $filetomerge = new Propalmergepdfproduct($this->db); - + if ($conf->global->MAIN_MULTILANGS) { $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang); } else { $filetomerge->fetch_by_product($line->fk_product); } - + $already_merged[] = $line->fk_product; - + $product = new Product($this->db); $product->fetch($line->fk_product); - + if ($product->entity!=$conf->entity) { $entity_product_file=$product->entity; } else { $entity_product_file=$conf->entity; } - + // If PDF is selected and file is not empty if (count($filetomerge->lines) > 0) { foreach ( $filetomerge->lines as $linefile ) { @@ -688,9 +688,9 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid $filetomerge_dir = $conf->product->multidir_output[$entity_product_file] . '/' . dol_sanitizeFileName($line->product_ref); elseif (! empty($conf->service->enabled)) $filetomerge_dir = $conf->service->multidir_output[$entity_product_file] . '/' . dol_sanitizeFileName($line->product_ref); - + dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG); - + $infile = $filetomerge_dir . '/' . $linefile->file_name; if (is_file($infile)) { $pagecount = $pdf->setSourceFile($infile); @@ -707,11 +707,11 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid } } } - + //exit; - - - + + + $pdf->Close(); $pdf->Output($file,'F'); @@ -1567,10 +1567,10 @@ function _signature_area(&$pdf, $object, $posy, $outputlangs) $pdf->SetFillColor(255,255,255); $pdf->SetXY($posx, $tab_top + 0); $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1); - + $pdf->SetXY($posx, $tab_top + $tab_hl); $pdf->MultiCell($largcol, $tab_hl*6, '', 1, 'R'); - + return ($tab_hl*7); } }