Prepare code for generic solution where all path are forged using

get_exdir.
This commit is contained in:
Laurent Destailleur 2015-05-18 22:25:51 +02:00
parent 4d6b25eb45
commit a258370f8a
32 changed files with 223 additions and 232 deletions

View File

@ -322,15 +322,15 @@ if (empty($reshook))
if ($result >= 0 && ! count($object->errors)) if ($result >= 0 && ! count($object->errors))
{ {
// Logo/Photo save // 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']); $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK) if ($file_OK)
{ {
if (GETPOST('deletephoto')) if (GETPOST('deletephoto'))
{ {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; 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; $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).'/photos/thumbs'; $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'member').'/photos/thumbs';
dol_delete_file($fileimg); dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs); dol_delete_dir_recursive($dirthumbs);
} }

View File

@ -60,7 +60,6 @@ if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name"; if (! $sortfield) $sortfield="name";
$upload_dir = $conf->adherent->dir_output . "/" . get_exdir($id,2,0,1) . '/' . $id;
$form = new Form($db); $form = new Form($db);
$object=new Adherent($db); $object=new Adherent($db);
$membert=new AdherentType($db); $membert=new AdherentType($db);
@ -70,6 +69,9 @@ if ($result < 0)
dol_print_error($db); dol_print_error($db);
exit; exit;
} }
$upload_dir = $conf->adherent->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'member') . '/' . dol_sanitizeFileName($object->ref);
/* /*
* Actions * Actions
*/ */

View File

@ -1302,7 +1302,7 @@ class Categorie extends CommonObject
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 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/"; $dir .= "photos/";
if (! file_exists($dir)) if (! file_exists($dir))

View File

@ -224,7 +224,7 @@ if ($object->id)
$maxWidth = 160; $maxWidth = 160;
$maxHeight = 120; $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; $dir = $upload_dir.'/'.$pdir;
print '<br>'; print '<br>';

View File

@ -153,7 +153,7 @@ if (empty($reshook))
} }
else 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) if ($object->statut == 0)
{ {
@ -398,7 +398,7 @@ if (empty($reshook))
{ {
$error=0; $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"]; $object->sendto = $_POST["sendto"];
if (! $object->sendto) if (! $object->sendto)
@ -495,7 +495,7 @@ if (empty($reshook))
// Action update description of emailing // Action update description of emailing
if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto') 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')); if ($action == 'settitre') $object->titre = trim(GETPOST('titre','alpha'));
else if ($action == 'setemail_from') $object->email_from = trim(GETPOST('email_from','alpha')); else if ($action == 'setemail_from') $object->email_from = trim(GETPOST('email_from','alpha'));
@ -527,7 +527,7 @@ if (empty($reshook))
*/ */
if (! empty($_POST['addfile'])) 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'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -540,7 +540,7 @@ if (empty($reshook))
// Action remove file // Action remove file
if (! empty($_POST["removedfile"])) 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'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -719,7 +719,7 @@ else
{ {
if ($object->id > 0) 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); $head = emailing_prepare_head($object);

View File

@ -262,7 +262,7 @@ else if ($action == 'remove_file' && $user->rights->banque->cheque)
$langs->load("other"); $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); $ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors');
@ -704,7 +704,7 @@ if ($action != 'new')
if ($object->statut == 1) if ($object->statut == 1)
{ {
$filename=dol_sanitizeFileName($object->ref); $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; $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
$formfile->show_documents('remisecheque', $filename, $filedir, $urlsource, 1, 1); $formfile->show_documents('remisecheque', $filename, $filedir, $urlsource, 1, 1);

View File

@ -132,7 +132,7 @@ class FileUpload
$object_ref = dol_sanitizeFileName($object->ref); $object_ref = dol_sanitizeFileName($object->ref);
if ($element == 'invoice_supplier') { 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') { } else if ($element == 'project_task') {
$object_ref = $object->project->ref . '/' . $object_ref; $object_ref = $object->project->ref . '/' . $object_ref;
} }

View File

@ -4806,19 +4806,19 @@ class Form
else if ($modulepart=='userphoto') else if ($modulepart=='userphoto')
{ {
$dir=$conf->user->dir_output; $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 if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email; $email=$object->email;
} }
else if ($modulepart=='memberphoto') else if ($modulepart=='memberphoto')
{ {
$dir=$conf->adherent->dir_output; $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 if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email; $email=$object->email;
}else { }else {
$dir=$conf->$modulepart->dir_output; $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 if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
$email=$object->email; $email=$object->email;
} }

View File

@ -581,7 +581,7 @@ class FormFile
$relativepath=$file["name"]; // Cas general $relativepath=$file["name"]; // Cas general
if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
// Autre cas // 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"]; } if ($modulepart == 'export') { $relativepath = $file["name"]; }
$out.= "<tr ".$bc[$var].">"; $out.= "<tr ".$bc[$var].">";
@ -700,14 +700,14 @@ class FormFile
if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
// Autre cas // Autre cas
if ($modulepart == 'donation') { if ($modulepart == 'donation') {
$relativepath = get_exdir($modulesubdir,2).$file["name"]; $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"];
} }
if ($modulepart == 'export') { if ($modulepart == 'export') {
$relativepath = $file["name"]; $relativepath = $file["name"];
} }
if ($modulepart == 'facture_fournisseur') { if ($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_fournisseur') {
$relativepath = get_exdir($modulesubdir, 2). $modulesubdir. "/" . $file["name"]; $relativepath = get_exdir($modulesubdir, 2,0,0,null,'invoice_supplier'). $modulesubdir. "/" . $file["name"];
} }
// Show file name with link to download // Show file name with link to download
$out.= '<a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"'; $out.= '<a data-ajax="false" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'"';
@ -801,8 +801,8 @@ class FormFile
if (empty($relativepath)) if (empty($relativepath))
{ {
$relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/'; $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 == '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).$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_.'; if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.';
} }

View File

@ -1817,7 +1817,7 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu
$accessallowed=1; $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 // Wrapping for export module

View File

@ -69,7 +69,7 @@ function facturefourn_prepare_head($object)
} }
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 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)$')); $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][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
$head[$h][1] = $langs->trans('Documents'); $head[$h][1] = $langs->trans('Documents');

View File

@ -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 $level Level of subdirs to return (1, 2 or 3 levels)
* @param int $alpha Use alpha ref * @param int $alpha Use alpha ref
* @param int $withoutslash 0=With slash at end, 1=without slash at end (except if '/', we return '') * @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 Object $object Object
* @param string $modulepart Not used yet. May be used to manage different option of directory path according to element. * @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...')
* @return string Dir to use ending. Example '' or '1/' or '1/2/' * @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; global $conf;
$path = ''; $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); if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
else $num = preg_replace('/^.*\-/i','',$num); else $num = preg_replace('/^.*\-/i','',$num);
$num = substr("000".$num, -$level); $num = substr("000".$num, -$level);

View File

@ -165,7 +165,7 @@ class pdf_aurore extends ModelePDFAskPriceSupplier
$objphoto = new Product($this->db); $objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product); $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; $dir = $conf->product->dir_output.'/'.$pdir;
$realpath=''; $realpath='';

View File

@ -98,7 +98,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts
$outputlangs->load("products"); $outputlangs->load("products");
$outputlangs->load("compta"); $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)) if (! is_dir($dir))
{ {

View File

@ -105,7 +105,7 @@ class html_cerfafr extends ModeleDon
else else
{ {
$donref = dol_sanitizeFileName($don->ref); $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"; $file = $dir . "/" . $donref . ".html";
} }

View File

@ -190,7 +190,7 @@ class pdf_crabe extends ModelePDFFactures
$objphoto = new Product($this->db); $objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product); $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; $dir = $conf->product->dir_output.'/'.$pdir;
$realpath=''; $realpath='';

View File

@ -96,7 +96,7 @@ class pdf_standard extends CommonStickerGenerator
$dir=$conf->adherent->dir_output; $dir=$conf->adherent->dir_output;
if (! empty($photo)) if (! empty($photo))
{ {
$file=get_exdir($idmember,2).'photos/'.$photo; $file=get_exdir($idmember,2,0,0,null,'member').'photos/'.$photo;
$photo=$dir.'/'.$file; $photo=$dir.'/'.$file;
if (! is_readable($photo)) $photo=''; if (! is_readable($photo)) $photo='';
} }

View File

@ -179,13 +179,13 @@ class pdf_azur extends ModelePDFPropales
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
{ {
$pdir[0] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/"; $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/";
$pdir[1] = dol_sanitizeFileName($objphoto->ref).'/'; $pdir[1] = dol_sanitizeFileName($objphoto->ref).'/';
} }
else else
{ {
$pdir[0] = dol_sanitizeFileName($objphoto->ref).'/'; // default $pdir[0] = dol_sanitizeFileName($objphoto->ref).'/'; // default
$pdir[1] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/"; // alternative $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/"; // alternative
} }
$arephoto = false; $arephoto = false;

View File

@ -173,7 +173,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
{ {
$objectref = dol_sanitizeFileName($object->ref); $objectref = dol_sanitizeFileName($object->ref);
$objectrefsupplier = dol_sanitizeFileName($object->ref_supplier); $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
$dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$objectref; $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$objectref;
$file = $dir . "/" . $objectref . ".pdf"; $file = $dir . "/" . $objectref . ".pdf";
if (! empty($conf->global->SUPPLIER_REF_IN_NAME)) $file = $dir . "/" . $objectref . ($objectrefsupplier?"_".$objectrefsupplier:"").".pdf"; if (! empty($conf->global->SUPPLIER_REF_IN_NAME)) $file = $dir . "/" . $objectref . ($objectrefsupplier?"_".$objectrefsupplier:"").".pdf";
} }

View File

@ -720,7 +720,7 @@ if (! empty($id) && $action != 'edit')
* Documents generes * Documents generes
*/ */
$filename=dol_sanitizeFileName($object->id); $filename=dol_sanitizeFileName($object->id);
$filedir=$conf->don->dir_output . '/' . get_exdir($filename,2); $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2,0,0,$object,'donation');
$urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id; $urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id;
// $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer); // $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer);
// $delallowed=$user->rights->facture->supprimer; // $delallowed=$user->rights->facture->supprimer;

View File

@ -497,7 +497,7 @@ class Expedition extends CommonObject
if ($this->statut == 0) $this->brouillon = 1; if ($this->statut == 0) $this->brouillon = 1;
$file = $conf->expedition->dir_output . "/" .get_exdir($this->id, 2) . "/" . $this->id.".pdf"; $file = $conf->expedition->dir_output . "/" .get_exdir($this->id, 2, 0, 0, $this, 'shipment') . "/" . $this->id.".pdf";
$this->pdf_filename = $file; $this->pdf_filename = $file;
// Tracking url // Tracking url

View File

@ -736,7 +736,7 @@ class FactureFournisseur extends CommonInvoice
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$ref = dol_sanitizeFileName($this->ref); $ref = dol_sanitizeFileName($this->ref);
$dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2).$ref; $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoive_supplier').$ref;
$file = $dir . "/" . $ref . ".pdf"; $file = $dir . "/" . $ref . ".pdf";
if (file_exists($file)) if (file_exists($file))
{ {
@ -975,8 +975,8 @@ class FactureFournisseur extends CommonInvoice
$oldref = dol_sanitizeFileName($this->ref); $oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$oldref; $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2,0,0, $this, 'invoive_supplier').$oldref;
$dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$newref; $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2,0,0, $this, 'invoive_supplier').$newref;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
@ -985,7 +985,7 @@ class FactureFournisseur extends CommonInvoice
{ {
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref // Rename docs starting with $oldref with $newref
$listoffiles=dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$newref, 'files', 1, '^'.preg_quote($oldref,'/')); $listoffiles=dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2,0,0, $this, 'invoive_supplier').$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry) foreach($listoffiles as $fileentry)
{ {
$dirsource=$fileentry['name']; $dirsource=$fileentry['name'];

View File

@ -926,143 +926,131 @@ if (empty($reshook))
$result=$object->fetch_thirdparty(); $result=$object->fetch_thirdparty();
if ($result > 0) if ($result > 0)
{ {
// $ref = dol_sanitizeFileName($object->ref); if ($_POST['sendto'])
// $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; {
// Le destinataire a ete fourni via le champ libre
$sendto = $_POST['sendto'];
$sendtoid = 0;
}
elseif ($_POST['receiver'] != '-1')
{
// Recipient was provided from combo list
if ($_POST['receiver'] == 'thirdparty') // Id of third party
{
$sendto = $object->client->email;
$sendtoid = 0;
}
else // Id du contact
{
$sendto = $object->client->contact_get_property($_POST['receiver'],'email');
$sendtoid = $_POST['receiver'];
}
}
// if (is_readable($file)) if (dol_strlen($sendto))
// { {
if ($_POST['sendto']) $langs->load("commercial");
{
// Le destinataire a ete fourni via le champ libre
$sendto = $_POST['sendto'];
$sendtoid = 0;
}
elseif ($_POST['receiver'] != '-1')
{
// Recipient was provided from combo list
if ($_POST['receiver'] == 'thirdparty') // Id of third party
{
$sendto = $object->client->email;
$sendtoid = 0;
}
else // Id du contact
{
$sendto = $object->client->contact_get_property($_POST['receiver'],'email');
$sendtoid = $_POST['receiver'];
}
}
if (dol_strlen($sendto)) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
{ $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
$langs->load("commercial"); $message = $_POST['message'];
$sendtocc = $_POST['sendtocc'];
$deliveryreceipt = $_POST['deliveryreceipt'];
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; if ($action == 'send')
$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; {
$message = $_POST['message']; if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
$sendtocc = $_POST['sendtocc']; else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
$deliveryreceipt = $_POST['deliveryreceipt']; $actiontypecode='AC_SUP_INV';
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
if ($message)
{
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
$actionmsg = dol_concatdesc($actionmsg, $message);
}
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
if ($action == 'send') // Create form object
{ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
if (dol_strlen($_POST['subject'])) $subject=$_POST['subject']; $formmail = new FormMail($db);
else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
$actiontypecode='AC_SUP_INV';
$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
if ($message)
{
if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
$actionmsg = dol_concatdesc($actionmsg, $message);
}
$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
}
// Create form object $attachedfiles=$formmail->get_attached_files();
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $filepath = $attachedfiles['paths'];
$formmail = new FormMail($db); $filename = $attachedfiles['names'];
$mimetype = $attachedfiles['mimes'];
$attachedfiles=$formmail->get_attached_files(); // Send mail
$filepath = $attachedfiles['paths']; require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$filename = $attachedfiles['names']; $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
$mimetype = $attachedfiles['mimes']; if ($mailfile->error)
{
setEventMessage($mailfile->error,'errors');
}
else
{
$result=$mailfile->sendfile();
if ($result)
{
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
setEventMessage($mesg);
// Send mail $error=0;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
if ($mailfile->error)
{
setEventMessage($mailfile->error,'errors');
}
else
{
$result=$mailfile->sendfile();
if ($result)
{
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
setEventMessage($mesg);
$error=0; // Initialisation donnees
$object->sendtoid = $sendtoid;
$object->actiontypecode = $actiontypecode;
$object->actionmsg = $actionmsg;
$object->actionmsg2 = $actionmsg2;
$object->fk_element = $object->id;
$object->elementtype = $object->element;
// Initialisation donnees // Appel des triggers
$object->sendtoid = $sendtoid; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$object->actiontypecode = $actiontypecode; $interface=new Interfaces($db);
$object->actionmsg = $actionmsg; $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
$object->actionmsg2 = $actionmsg2; if ($result < 0) {
$object->fk_element = $object->id; $error++; $object->errors=$interface->errors;
$object->elementtype = $object->element; }
// Fin appel triggers
// Appel des triggers if ($error)
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; {
$interface=new Interfaces($db); dol_print_error($db);
$result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf); }
if ($result < 0) { else
$error++; $object->errors=$interface->errors; {
} // Redirect here
// Fin appel triggers // This avoid sending mail twice if going out and then back to page
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
}
else
{
$langs->load("other");
if ($mailfile->error)
{
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
$mesg.='<br>'.$mailfile->error;
}
else
{
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
setEventMessage($mesg, 'errors');
}
}
}
if ($error) else
{ {
dol_print_error($db); $langs->load("other");
} setEventMessage($langs->trans('ErrorMailRecipientIsEmpty'), 'errors');
else dol_syslog('Recipient email is empty');
{ }
// Redirect here
// This avoid sending mail twice if going out and then back to page
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
}
else
{
$langs->load("other");
if ($mailfile->error)
{
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
$mesg.='<br>'.$mailfile->error;
}
else
{
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
}
setEventMessage($mesg, 'errors');
}
}
}
else
{
$langs->load("other");
setEventMessage($langs->trans('ErrorMailRecipientIsEmpty'), 'errors');
dol_syslog('Recipient email is empty');
}
/* }
else
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
dol_syslog('Failed to read file: '.$file);
}*/
} }
else else
{ {
@ -2405,8 +2393,8 @@ else
*/ */
$ref=dol_sanitizeFileName($object->ref); $ref=dol_sanitizeFileName($object->ref);
$subdir = get_exdir($object->id,2).$ref; $subdir = get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref;
$filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref; $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref;
$urlsource=$_SERVER['PHP_SELF'].'?id='.$object->id; $urlsource=$_SERVER['PHP_SELF'].'?id='.$object->id;
$genallowed=$user->rights->fournisseur->facture->creer; $genallowed=$user->rights->fournisseur->facture->creer;
$delallowed=$user->rights->fournisseur->facture->supprimer; $delallowed=$user->rights->fournisseur->facture->supprimer;
@ -2512,7 +2500,7 @@ else
{ {
$ref = dol_sanitizeFileName($object->ref); $ref = dol_sanitizeFileName($object->ref);
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref,'/')); $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref, preg_quote($ref,'/'));
$file=$fileparams['fullname']; $file=$fileparams['fullname'];
// Define output language // Define output language
@ -2539,7 +2527,7 @@ else
dol_print_error($db,$result); dol_print_error($db,$result);
exit; exit;
} }
$fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref,'/')); $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref, preg_quote($ref,'/'));
$file=$fileparams['fullname']; $file=$fileparams['fullname'];
} }

View File

@ -64,7 +64,7 @@ if ($object->fetch($id, $ref))
{ {
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$ref=dol_sanitizeFileName($object->ref); $ref=dol_sanitizeFileName($object->ref);
$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref; $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$ref;
} }

View File

@ -309,7 +309,7 @@ if ($resql)
$facturestatic->ref_supplier=$obj->ref_supplier; $facturestatic->ref_supplier=$obj->ref_supplier;
print $facturestatic->getNomUrl(1); print $facturestatic->getNomUrl(1);
$filename=dol_sanitizeFileName($obj->ref); $filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2).dol_sanitizeFileName($object->ref?$obj->ref:$obj->facid); $filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$object,'invoice_supplier').dol_sanitizeFileName($object->ref?$obj->ref:$obj->facid);
print $formfile->getDocumentsLink('facture_fournisseur', $filename, $filedir); print $formfile->getDocumentsLink('facture_fournisseur', $filename, $filedir);
print "</td>\n"; print "</td>\n";

View File

@ -138,7 +138,7 @@ if ($id)
$nbphoto=0; $nbphoto=0;
$nbbyrow=5; $nbbyrow=5;
$pdir = get_exdir($object->id,2) . $object->id ."/photos/"; $pdir = get_exdir($object->id,2,0,0,$object,'product') . $object->id ."/photos/";
$dir = $conf->product->multidir_output[$object->entity] . '/'. $pdir; $dir = $conf->product->multidir_output[$object->entity] . '/'. $pdir;
print '<br><table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; print '<br><table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';

View File

@ -3383,7 +3383,7 @@ class Product extends CommonObject
$result = 0; $result = 0;
$dir = $sdir; $dir = $sdir;
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2) . $this->id ."/photos"; if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos";
else $dir .= '/'.dol_sanitizeFileName($this->ref); else $dir .= '/'.dol_sanitizeFileName($this->ref);
dol_mkdir($dir); dol_mkdir($dir);
@ -3421,7 +3421,7 @@ class Product extends CommonObject
global $conf; global $conf;
$dir = $sdir; $dir = $sdir;
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2) . $this->id ."/photos/"; if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $dir .= '/'. get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
else $dir .= '/'.dol_sanitizeFileName($this->ref).'/'; else $dir .= '/'.dol_sanitizeFileName($this->ref).'/';
$nbphoto=0; $nbphoto=0;
@ -3468,8 +3468,8 @@ class Product extends CommonObject
$pdir = '/'; $pdir = '/';
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
{ {
$dir .= get_exdir($this->id,2) . $this->id ."/photos/"; $dir .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
$pdir .= get_exdir($this->id,2) . $this->id ."/photos/"; $pdir .= get_exdir($this->id,2,0,0,$this,'product') . $this->id ."/photos/";
} }
else else
{ {

View File

@ -434,8 +434,8 @@ foreach ($listofreferent as $key => $value)
} }
else if($element_doc === 'invoice_supplier') { else if($element_doc === 'invoice_supplier') {
$element_doc='facture_fournisseur'; $element_doc='facture_fournisseur';
$filename = get_exdir($element->id,2).dol_sanitizeFileName($element->ref); $filename = get_exdir($element->id,2,0,0,$this,'product').dol_sanitizeFileName($element->ref);
$filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($element->id,2).dol_sanitizeFileName($element->ref); $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($element->id,2,0,0,null,'invoice_supplier').dol_sanitizeFileName($element->ref);
} }
print $formfile->getDocumentsLink($element_doc, $filename, $filedir); print $formfile->getDocumentsLink($element_doc, $filename, $filedir);

View File

@ -65,7 +65,7 @@ if ($id > 0 || ! empty($ref))
$result = $object->fetch($id, $ref); $result = $object->fetch($id, $ref);
$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ; $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
$courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id); $courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id,0,0,0,$object,'thirdparty');
} }

View File

@ -438,15 +438,15 @@ if ($action == 'update' && ! $_POST["cancel"])
{ {
if (GETPOST('deletephoto') && $object->photo) if (GETPOST('deletephoto') && $object->photo)
{ {
$fileimg=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1).'/logos/'.$object->photo; $fileimg=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'user').'/logos/'.$object->photo;
$dirthumbs=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1).'/logos/thumbs'; $dirthumbs=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'user').'/logos/thumbs';
dol_delete_file($fileimg); dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs); dol_delete_dir_recursive($dirthumbs);
} }
if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name']))
{ {
$dir= $conf->user->dir_output . '/' . get_exdir($object->id,2,0,1); $dir= $conf->user->dir_output . '/' . get_exdir($object->id,2,0,1,$object,'user');
dol_mkdir($dir); dol_mkdir($dir);

View File

@ -217,7 +217,7 @@ function getCategory($authentication,$id)
if ($result > 0) if ($result > 0)
{ {
$dir = (!empty($conf->categorie->dir_output)?$conf->categorie->dir_output:$conf->service->dir_output); $dir = (!empty($conf->categorie->dir_output)?$conf->categorie->dir_output:$conf->service->dir_output);
$pdir = get_exdir($categorie->id,2) . $categorie->id ."/photos/"; $pdir = get_exdir($categorie->id,2,0,0,$categorie,'category') . $categorie->id ."/photos/";
$dir = $dir . '/'. $pdir; $dir = $dir . '/'. $pdir;
$cat = array( $cat = array(
@ -238,7 +238,7 @@ function getCategory($authentication,$id)
foreach($cats as $fille) foreach($cats as $fille)
{ {
$dir = (!empty($conf->categorie->dir_output)?$conf->categorie->dir_output:$conf->service->dir_output); $dir = (!empty($conf->categorie->dir_output)?$conf->categorie->dir_output:$conf->service->dir_output);
$pdir = get_exdir($fille->id,2) . $fille->id ."/photos/"; $pdir = get_exdir($fille->id,2,0,0,$categorie,'category') . $fille->id ."/photos/";
$dir = $dir . '/'. $pdir; $dir = $dir . '/'. $pdir;
$cat['filles'][] = array( $cat['filles'][] = array(
'id'=>$fille->id, 'id'=>$fille->id,

View File

@ -374,7 +374,7 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang=''
$product->load_stock(); $product->load_stock();
$dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output); $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output);
$pdir = get_exdir($product->id,2) . $product->id ."/photos/"; $pdir = get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos/";
$dir = $dir . '/'. $pdir; $dir = $dir . '/'. $pdir;
if (! empty($product->multilangs[$langs->defaultlang]["label"])) $product->label = $product->multilangs[$langs->defaultlang]["label"]; if (! empty($product->multilangs[$langs->defaultlang]["label"])) $product->label = $product->multilangs[$langs->defaultlang]["label"];
@ -1055,7 +1055,7 @@ function getProductsForCategory($authentication,$id,$lang='')
if($obj->status > 0 ) if($obj->status > 0 )
{ {
$dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output); $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output);
$pdir = get_exdir($obj->id,2) . $obj->id ."/photos/"; $pdir = get_exdir($obj->id,2,0,0,$product,'product') . $obj->id ."/photos/";
$dir = $dir . '/'. $pdir; $dir = $dir . '/'. $pdir;
$products[] = array( $products[] = array(