diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index cb0fe8728b2..6aac42331bc 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -578,11 +578,9 @@ class FormFile
$var=!$var;
// Define relative path for download link (depends on module)
- $relativepath=$file["name"]; // Cas general
+ $relativepath=$file["name"]; // Cas general
if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture...
- // Autre cas
- 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"]; // Other case
$out.= "
";
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index 7eb6d9c5dcf..daae392cd39 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -1399,7 +1399,7 @@ function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta
/**
* Security check when accessing to a document (used by document.php, viewimage.php and webservices)
*
- * @param string $modulepart Module of document (module, module_user_temp, module_user or module_temp)
+ * @param string $modulepart Module of document ('module', 'module_user_temp', 'module_user' or 'module_temp')
* @param string $original_file Relative path with filename
* @param string $entity Restrict onto entity
* @param User $fuser User object (forced)
@@ -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,0,null,'cheque').$original_file;
+ $original_file=$conf->banque->dir_output.'/bordereau/'.$original_file; // original_file should contains relative path so include the get_exdir result
}
// Wrapping for export module
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 01615391adb..6d5f1fe7a65 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3713,13 +3713,16 @@ function yn($yesno, $case=1, $color=0)
* @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,$object=null,$modulepart='')
+function get_exdir($num,$level,$alpha,$withoutslash,$object,$modulepart)
{
global $conf;
$path = '';
- if (! empty($level) && in_array($modulepart, array('shipment', 'member','don','donation','supplier_invoice','invoice_supplier')))
+ // TODO if object is null, load it from id and modulepart.
+
+
+ if (! empty($level) && in_array($modulepart, array('cheque','user','category','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);
diff --git a/htdocs/core/modules/askpricesupplier/doc/pdf_aurore.modules.php b/htdocs/core/modules/askpricesupplier/doc/pdf_aurore.modules.php
index 6acbb1fc4d0..db021bcb89e 100644
--- a/htdocs/core/modules/askpricesupplier/doc/pdf_aurore.modules.php
+++ b/htdocs/core/modules/askpricesupplier/doc/pdf_aurore.modules.php
@@ -165,7 +165,7 @@ class pdf_aurore extends ModelePDFAskPriceSupplier
$objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product);
- $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$object,'product') . $object->lines[$i]->fk_product ."/photos/";
+ $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
$dir = $conf->product->dir_output.'/'.$pdir;
$realpath='';
diff --git a/htdocs/core/modules/dons/html_cerfafr.modules.php b/htdocs/core/modules/dons/html_cerfafr.modules.php
index 9da0d45db50..69c862d916d 100644
--- a/htdocs/core/modules/dons/html_cerfafr.modules.php
+++ b/htdocs/core/modules/dons/html_cerfafr.modules.php
@@ -105,7 +105,7 @@ class html_cerfafr extends ModeleDon
else
{
$donref = dol_sanitizeFileName($don->ref);
- $dir = $conf->don->dir_output . "/" . get_exdir($donref,2,0,0,$don,'donation');
+ $dir = $conf->don->dir_output . "/" . get_exdir($donref,2,0,1,$don,'donation') . "/" . dol_sanitizeFileName($don->ref);
$file = $dir . "/" . $donref . ".html";
}
diff --git a/htdocs/don/card.php b/htdocs/don/card.php
index 2047c9b5f8f..d066f3ee6ff 100644
--- a/htdocs/don/card.php
+++ b/htdocs/don/card.php
@@ -173,6 +173,10 @@ if ($action == 'add')
header("Location: index.php");
exit;
}
+ else
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
}
}
if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->don->supprimer)
@@ -232,7 +236,7 @@ if ($action == 'set_paid')
if ($action == 'builddoc')
{
$object = new Don($db);
- $object->fetch($id);
+ $result=$object->fetch($id);
// Save last template used to generate document
if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
@@ -380,6 +384,7 @@ if (! empty($id) && $action == 'edit')
dol_print_error($db); exit;
}
+ $hselected='card';
$head = donation_prepare_head($object);
dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
@@ -507,6 +512,8 @@ if (! empty($id) && $action != 'edit')
dol_print_error($db); exit;
}
+ $hselected='card';
+
$head = donation_prepare_head($object);
dol_fiche_head($head, $hselected, $langs->trans("Donation"), 0, 'generic');
@@ -720,7 +727,7 @@ if (! empty($id) && $action != 'edit')
* Documents generes
*/
$filename=dol_sanitizeFileName($object->id);
- $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2,0,0,$object,'donation');
+ $filedir=$conf->don->dir_output . '/' . get_exdir($filename,2,0,1,$object,'donation'). '/'. dol_sanitizeFileName($object->ref);
$urlsource=$_SERVER['PHP_SELF'].'?rowid='.$object->id;
// $genallowed=($fac->statut == 1 && ($fac->paye == 0 || $user->admin) && $user->rights->facture->creer);
// $delallowed=$user->rights->facture->supprimer;
@@ -730,7 +737,7 @@ if (! empty($id) && $action != 'edit')
$var=true;
print '
';
- $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed);
+ $formfile->show_documents('donation',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf);
print ' | ';
diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php
index 33706ddd841..e3910b6fe51 100644
--- a/htdocs/don/class/don.class.php
+++ b/htdocs/don/class/don.class.php
@@ -60,9 +60,10 @@ class Don extends CommonObject
var $note_private;
var $note_public;
var $statut;
-
+ var $modelpdf;
var $projet;
+
/**
* Constructor
*
@@ -306,14 +307,14 @@ class Don extends CommonObject
* @return int <0 if KO, id of created donation if OK
* TODO add numbering module for Ref
*/
- function create($user, $notrigger)
+ function create($user, $notrigger=0)
{
global $conf, $langs;
-
+
$error = 0;
$ret = 0;
$now=dol_now();
-
+
// Clean parameters
$this->address=($this->address>0?$this->address:$this->address);
$this->zip=($this->zip>0?$this->zip:$this->zip);
@@ -391,7 +392,7 @@ class Don extends CommonObject
$this->errno = $this->db->lasterrno();
$error++;
}
-
+
// Update extrafield
if (!$error) {
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
@@ -403,7 +404,7 @@ class Don extends CommonObject
}
}
}
-
+
if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
{
$res = $this->setValid($user);
@@ -434,7 +435,7 @@ class Don extends CommonObject
global $langs, $conf;
$error=0;
-
+
// Clean parameters
$this->address=($this->address>0?$this->address:$this->address);
$this->zip=($this->zip>0?$this->zip:$this->zip);
@@ -523,11 +524,11 @@ class Don extends CommonObject
{
global $conf, $langs;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
-
+
$error = 0;
-
+
$this->db->begin();
-
+
// Delete donation
if (! $error)
{
@@ -601,7 +602,7 @@ class Don extends CommonObject
$sql = "SELECT d.rowid, d.datec, d.tms as datem, d.datedon,";
$sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, ";
$sql.= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, cp.libelle, d.email, d.phone, ";
- $sql.= " d.phone_mobile, d.fk_projet,";
+ $sql.= " d.phone_mobile, d.fk_projet, d.model_pdf,";
$sql.= " p.title as project_label,";
$sql.= " c.code as country_code, c.label as country";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d";
@@ -651,12 +652,13 @@ class Don extends CommonObject
$this->public = $obj->public;
$this->modepaymentid = $obj->fk_payment;
$this->modepayment = $obj->libelle;
- $this->paid = $obj->paid;
+ $this->paid = $obj->paid;
$this->amount = $obj->amount;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
+ $this->modelpdf = $obj->model_pdf;
$this->commentaire = $obj->note; // deprecated
-
+
// Retrieve all extrafield for thirdparty
// fetch optionals attributes and labels
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
@@ -821,7 +823,7 @@ class Don extends CommonObject
if ($withpicto != 2) $result.=$link.$this->id.$linkend;
return $result;
}
-
+
/**
* Information on record
*
diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php
index d546e796fa1..010e9b95ae6 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -309,7 +309,7 @@ if ($resql)
$facturestatic->ref_supplier=$obj->ref_supplier;
print $facturestatic->getNomUrl(1);
$filename=dol_sanitizeFileName($obj->ref);
- $filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$object,'invoice_supplier').dol_sanitizeFileName($object->ref?$obj->ref:$obj->facid);
+ $filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref);
print $formfile->getDocumentsLink('facture_fournisseur', $filename, $filedir);
print "\n";
diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
index ea80e18b213..1d5ba017aab 100755
--- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
+++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
@@ -19,7 +19,7 @@
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
-UPDATE TABLE llx_facture_fourn set ref=id where ref IS NULL;
+UPDATE llx_facture_fourn set ref=rowid where ref IS NULL;
ALTER TABLE llx_facture_fourn MODIFY COLUMN ref varchar(255) NOT NULL;
@@ -451,6 +451,7 @@ ALTER TABLE llx_don ADD COLUMN fk_country integer NOT NULL after country;
ALTER TABLE llx_don CHANGE COLUMN fk_paiement fk_payment integer;
ALTER TABLE llx_don ADD COLUMN paid smallint default 0 NOT NULL after fk_payment;
ALTER TABLE llx_don CHANGE COLUMN fk_don_projet fk_projet integer NULL;
+ALTER TABLE llx_don CHANGE COLUMN fk_project fk_projet integer NULL;
create table llx_don_extrafields
(