Skip to content

Commit

Permalink
Prepare to generalize usage of get_exdir
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 18, 2015
1 parent 6d03ba2 commit 4d6b25e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
5 changes: 2 additions & 3 deletions htdocs/core/class/html.formfile.class.php
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 29 additions & 13 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -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;
}

Expand Down
42 changes: 21 additions & 21 deletions htdocs/core/modules/propale/doc/pdf_azur.modules.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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 ) {
Expand All @@ -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);
Expand All @@ -707,11 +707,11 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
}
}
}

//exit;



$pdf->Close();

$pdf->Output($file,'F');
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 4d6b25e

Please sign in to comment.