Skip to content

Commit

Permalink
Prepare code for generic solution where all path are forged using
Browse files Browse the repository at this point in the history
get_exdir.
  • Loading branch information
eldy committed May 18, 2015
1 parent 4d6b25e commit a258370
Show file tree
Hide file tree
Showing 32 changed files with 227 additions and 236 deletions.
6 changes: 3 additions & 3 deletions htdocs/adherents/card.php
Expand Up @@ -322,15 +322,15 @@
if ($result >= 0 && ! count($object->errors))
{
// Logo/Photo save
$dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1).'/photos';
$dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1,$object,'member').'/photos';
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (GETPOST('deletephoto'))
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/'.$object->photo;
$dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1).'/photos/thumbs';
$fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'member').'/photos/'.$object->photo;
$dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'member').'/photos/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
}
Expand Down
4 changes: 3 additions & 1 deletion htdocs/adherents/document.php
Expand Up @@ -60,7 +60,6 @@
if (! $sortfield) $sortfield="name";


$upload_dir = $conf->adherent->dir_output . "/" . get_exdir($id,2,0,1) . '/' . $id;
$form = new Form($db);
$object=new Adherent($db);
$membert=new AdherentType($db);
Expand All @@ -70,6 +69,9 @@
dol_print_error($db);
exit;
}
$upload_dir = $conf->adherent->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'member') . '/' . dol_sanitizeFileName($object->ref);


/*
* Actions
*/
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/class/categorie.class.php
Expand Up @@ -1302,7 +1302,7 @@ function add_photo($sdir, $file)
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';

$dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/";
$dir = $sdir .'/'. get_exdir($this->id,2,0,0,$this,'category') . $this->id ."/";
$dir .= "photos/";

if (! file_exists($dir))
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/photos.php
Expand Up @@ -224,7 +224,7 @@
$maxWidth = 160;
$maxHeight = 120;

$pdir = get_exdir($object->id,2) . $object->id ."/photos/";
$pdir = get_exdir($object->id,2,0,0,$object,'category') . $object->id ."/photos/";
$dir = $upload_dir.'/'.$pdir;

print '<br>';
Expand Down
12 changes: 6 additions & 6 deletions htdocs/comm/mailing/card.php
Expand Up @@ -153,7 +153,7 @@
}
else
{
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');

if ($object->statut == 0)
{
Expand Down Expand Up @@ -398,7 +398,7 @@
{
$error=0;

$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');

$object->sendto = $_POST["sendto"];
if (! $object->sendto)
Expand Down Expand Up @@ -495,7 +495,7 @@
// Action update description of emailing
if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto')
{
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');

if ($action == 'settitre') $object->titre = trim(GETPOST('titre','alpha'));
else if ($action == 'setemail_from') $object->email_from = trim(GETPOST('email_from','alpha'));
Expand Down Expand Up @@ -527,7 +527,7 @@
*/
if (! empty($_POST['addfile']))
{
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');

require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';

Expand All @@ -540,7 +540,7 @@
// Action remove file
if (! empty($_POST["removedfile"]))
{
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');

require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';

Expand Down Expand Up @@ -719,7 +719,7 @@
{
if ($object->id > 0)
{
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1);
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');

$head = emailing_prepare_head($object);

Expand Down
8 changes: 4 additions & 4 deletions htdocs/compta/paiement/cheque/card.php
Expand Up @@ -262,7 +262,7 @@

$langs->load("other");

$file=$dir.get_exdir($object->number,2,1) . GETPOST('file');
$file=$dir.get_exdir($object->number,2,1,0,$object,'cheque') . GETPOST('file');
$ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors');
Expand Down Expand Up @@ -322,7 +322,7 @@
if ($action == 'delete')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteCheckReceipt"), $langs->trans("ConfirmDeleteCheckReceipt"), 'confirm_delete','','',1);

}

/*
Expand All @@ -331,7 +331,7 @@
if ($action == 'valide')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_valide','','',1);

}
}

Expand Down Expand Up @@ -704,7 +704,7 @@
if ($object->statut == 1)
{
$filename=dol_sanitizeFileName($object->ref);
$filedir=$dir.get_exdir($object->number,2,1) . dol_sanitizeFileName($object->ref);
$filedir=$dir.get_exdir($object->number,2,1,0,$object,'cheque') . dol_sanitizeFileName($object->ref);
$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;

$formfile->show_documents('remisecheque', $filename, $filedir, $urlsource, 1, 1);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/fileupload.class.php
Expand Up @@ -132,7 +132,7 @@ function __construct($options=null,$fk_element=null,$element=null)

$object_ref = dol_sanitizeFileName($object->ref);
if ($element == 'invoice_supplier') {
$object_ref = get_exdir($object->id, 2) . $object_ref;
$object_ref = get_exdir($object->id,2,0,0,$object,'invoice_supplier') . $object_ref;
} else if ($element == 'project_task') {
$object_ref = $object->project->ref . '/' . $object_ref;
}
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -4806,19 +4806,19 @@ static function showphoto($modulepart,$object,$width=100)
else if ($modulepart=='userphoto')
{
$dir=$conf->user->dir_output;
if ($object->photo) $file=get_exdir($id, 2).$object->photo;
if ($object->photo) $file=get_exdir($id, 2, 0, 0, $object, 'user').$object->photo;
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email;
}
else if ($modulepart=='memberphoto')
{
$dir=$conf->adherent->dir_output;
if ($object->photo) $file=get_exdir($id, 2).'photos/'.$object->photo;
if ($object->photo) $file=get_exdir($id, 2, 0, 0, $object, 'invoice_supplier').'photos/'.$object->photo;
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email;
}else {
$dir=$conf->$modulepart->dir_output;
if ($object->photo) $file=get_exdir($id, 2).'photos/'.$object->photo;
if ($object->photo) $file=get_exdir($id, 2, 0, 0, $adherent, 'member').'photos/'.$object->photo;
if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email;
}
Expand Down
14 changes: 7 additions & 7 deletions htdocs/core/class/html.formfile.class.php
Expand Up @@ -581,7 +581,7 @@ function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed
$relativepath=$file["name"]; // Cas general
if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
// Autre cas
if ($modulepart == 'donation') { $relativepath = get_exdir($modulesubdir,2).$file["name"]; }
if ($modulepart == 'donation') { $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"]; }
if ($modulepart == 'export') { $relativepath = $file["name"]; }

$out.= "<tr ".$bc[$var].">";
Expand Down Expand Up @@ -700,14 +700,14 @@ function getDocumentsLink($modulepart, $modulesubdir, $filedir)
if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
// Autre cas
if ($modulepart == 'donation') {
$relativepath = get_exdir($modulesubdir,2).$file["name"];
$relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
}
if ($modulepart == 'export') {
$relativepath = $file["name"];
}
if ($modulepart == 'facture_fournisseur') {
$relativepath = get_exdir($modulesubdir, 2). $modulesubdir. "/" . $file["name"];
}
if ($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_fournisseur') {
$relativepath = get_exdir($modulesubdir, 2,0,0,null,'invoice_supplier'). $modulesubdir. "/" . $file["name"];
}

// Show file name with link to download
$out.= '<a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
Expand Down Expand Up @@ -801,8 +801,8 @@ function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownlo
if (empty($relativepath))
{
$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/';
if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2).$relativepath; // TODO Call using a defined value for $relativepath
if ($object->element == 'member') $relativepath=get_exdir($object->id,2).$relativepath; // TODO Call using a defined value for $relativepath
if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath
if ($object->element == 'member') $relativepath=get_exdir($object->id,2,0,0,$object,'member').$relativepath; // TODO Call using a defined value for $relativepath
if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
}

Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/files.lib.php
Expand Up @@ -1817,7 +1817,7 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
$accessallowed=1;
}

$original_file=$conf->banque->dir_output.'/bordereau/'.get_exdir(basename($original_file,".pdf"),2,1).$original_file;
$original_file=$conf->banque->dir_output.'/bordereau/'.get_exdir(basename($original_file,".pdf"),2,1,0,null,'cheque').$original_file;
}

// Wrapping for export module
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/fourn.lib.php
Expand Up @@ -69,7 +69,7 @@ function facturefourn_prepare_head($object)
}

require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$object->ref;
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$object->ref;
$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
$head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
$head[$h][1] = $langs->trans('Documents');
Expand Down
9 changes: 5 additions & 4 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -3709,18 +3709,19 @@ function yn($yesno, $case=1, $color=0)
* @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 (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.
* @param Object $object Object
* @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...')
* @return string Dir to use ending. Example '' or '1/' or '1/2/'
*/
function get_exdir($num,$level,$alpha=0,$withoutslash=0,$ref='',$modulepart='')
function get_exdir($num,$level,$alpha=0,$withoutslash=0,$object=null,$modulepart='')
{
global $conf;

$path = '';

if (in_array($modulepart, array('don','donation','supplier_invoice','invoice_supplier')))
if (! empty($level) && in_array($modulepart, array('shipment', 'member','don','donation','supplier_invoice','invoice_supplier')))
{
// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided
if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
else $num = preg_replace('/^.*\-/i','',$num);
$num = substr("000".$num, -$level);
Expand Down
Expand Up @@ -165,7 +165,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
$objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product);

$pdir = get_exdir($object->lines[$i]->fk_product,2) . $object->lines[$i]->fk_product ."/photos/";
$pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$object,'product') . $object->lines[$i]->fk_product ."/photos/";
$dir = $conf->product->dir_output.'/'.$pdir;

$realpath='';
Expand Down Expand Up @@ -708,7 +708,7 @@ function _tableau_info(&$pdf, $object, $posy, $outputlangs)

$pdf->SetFont('','', $default_font_size - 2);
$pdf->SetXY($posxval, $posy);

$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
$pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');

Expand Down Expand Up @@ -1266,7 +1266,7 @@ function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
$pdf->SetTextColor(0,0,60);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("AskPriceSupplierDate")." : " . dol_print_date($object->date_livraison,"day",false,$outputlangs,true), '', 'R');
*/

if ($object->client->code_client)
{
$posy+=4;
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/cheque/pdf/pdf_blochet.class.php
Expand Up @@ -98,7 +98,7 @@ function write_file($_dir, $number, $outputlangs)
$outputlangs->load("products");
$outputlangs->load("compta");

$dir = $_dir . "/".get_exdir($number,2,1).$number;
$dir = $_dir . "/".get_exdir($number,2,1,0,null,'cheque').$number;

if (! is_dir($dir))
{
Expand Down
20 changes: 10 additions & 10 deletions htdocs/core/modules/dons/html_cerfafr.modules.php
Expand Up @@ -3,7 +3,7 @@
* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@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
Expand Down Expand Up @@ -105,7 +105,7 @@ function write_file($don,$outputlangs)
else
{
$donref = dol_sanitizeFileName($don->ref);
$dir = $conf->don->dir_output . "/" . get_exdir($donref,2);
$dir = $conf->don->dir_output . "/" . get_exdir($donref,2,0,0,$don,'donation');
$file = $dir . "/" . $donref . ".html";
}

Expand Down Expand Up @@ -168,18 +168,18 @@ function write_file($don,$outputlangs)
$form = str_replace('__Message__',$outputlangs->trans("Message"),$form);
$form = str_replace('__IConfirmDonationReception__',$outputlangs->trans("IConfirmDonationReception"),$form);
$form = str_replace('__DonationMessage__',$conf->global->DONATION_MESSAGE,$form);

$frencharticle='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) $frencharticle='<font size="+1">Article 200, 238 bis et 885-0 V bis A du code général des impôts (CGI)</font>';
$form = str_replace('__FrenchArticle__',$frencharticle,$form);

$frencheligibility='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) $frencheligibility='Le bénéficiaire certifie sur l\'honneur que les dons et versements qu\'il reçoit ouvrent droit à la réduction d\'impôt prévue à l\'article :';
$form = str_replace('__FrenchEligibility__',$frencheligibility,$form);

$art200='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) {
if ($conf->global->DONATION_ART200 >= 1)
if ($conf->global->DONATION_ART200 >= 1)
{
$art200='<input type="checkbox" checked>200 du CGI';
}
Expand All @@ -192,7 +192,7 @@ function write_file($don,$outputlangs)

$art238='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) {
if ($conf->global->DONATION_ART238 >= 1)
if ($conf->global->DONATION_ART238 >= 1)
{
$art238='<input type="checkbox" checked>238 bis du CGI';
}
Expand All @@ -202,10 +202,10 @@ function write_file($don,$outputlangs)
}
}
$form = str_replace('__ARTICLE238__',$art238,$form);

$art885='';
if (preg_match('/fr/i',$outputlangs->defaultlang)) {
if ($conf->global->DONATION_ART885 >= 1)
if ($conf->global->DONATION_ART885 >= 1)
{
$art885='<input type="checkbox" checked>885-0 V bis du CGI';
}
Expand All @@ -215,7 +215,7 @@ function write_file($don,$outputlangs)
}
}
$form = str_replace('__ARTICLE885__',$art885,$form);

// Save file on disk
dol_syslog("html_cerfafr::write_file $file");
$handle=fopen($file,"w");
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/modules/facture/doc/pdf_crabe.modules.php
Expand Up @@ -190,7 +190,7 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid
$objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product);

$pdir = get_exdir($object->lines[$i]->fk_product,2) . $object->lines[$i]->fk_product ."/photos/";
$pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,'product') . $object->lines[$i]->fk_product ."/photos/";
$dir = $conf->product->dir_output.'/'.$pdir;

$realpath='';
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/member/doc/pdf_standard.class.php
Expand Up @@ -45,7 +45,7 @@ class pdf_standard extends CommonStickerGenerator
function addSticker(&$pdf,$outputlangs,$param) {
// use this method in future refactoring
}

/**
* Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
* - %LOGO% is replace with company logo
Expand Down Expand Up @@ -96,7 +96,7 @@ function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright=''
$dir=$conf->adherent->dir_output;
if (! empty($photo))
{
$file=get_exdir($idmember,2).'photos/'.$photo;
$file=get_exdir($idmember,2,0,0,null,'member').'photos/'.$photo;
$photo=$dir.'/'.$file;
if (! is_readable($photo)) $photo='';
}
Expand Down

0 comments on commit a258370

Please sign in to comment.