'; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy.
if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
@@ -495,6 +512,7 @@ class FormMail extends Form
}
else
{
+ // Note withto may be a text like 'AllRecipientSelected'
$out.= (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
}
}
@@ -524,10 +542,22 @@ class FormMail extends Form
$out.= "\n";
}
+ // withoptiononeemailperrecipient
+ if (! empty($this->withoptiononeemailperrecipient))
+ {
+ $out.= '
';
+ }
+
// CC
if (! empty($this->withtocc) || is_array($this->withtocc))
{
- $out.= '
';
- $out.= '| '.$langs->trans("MailText").' | ';
+ $out.= ''.$langs->trans("MailText").' | ';
$out.= '';
if ($this->withbodyreadonly)
{
@@ -999,7 +1030,7 @@ class FormMail extends Form
$sql = "SELECT rowid, label, topic, content, content_lines, lang, fk_user, private, position";
$sql.= " FROM ".MAIN_DB_PREFIX.'c_email_templates';
$sql.= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
- $sql.= " AND entity IN (".getEntity('c_email_templates', 0).")";
+ $sql.= " AND entity IN (".getEntity('c_email_templates', 1).")";
$sql.= " AND (private = 0 OR fk_user = ".$user->id.")"; // See all public templates or templates I own.
if ($active >= 0) $sql.=" AND active = ".$active;
//if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')"; // Return all languages
@@ -1038,8 +1069,7 @@ class FormMail extends Form
/**
- * Set substit array from object. This is call when suggesting the email template into forms to send email.
- * TODO Replace with getCommonSubstitutionArray with param onlykey = 2
+ * Set substit array from object. This is call when suggesting the email template into forms before sending email.
*
* @param CommonObject $object Object to use
* @param Translate $outputlangs Object lang
@@ -1049,34 +1079,12 @@ class FormMail extends Form
function setSubstitFromObject($object, $outputlangs=null)
{
global $conf, $user;
- $this->substit['__REF__'] = $object->ref;
- $this->substit['__REFCLIENT__'] = isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer : '');
- $this->substit['__REFSUPPLIER__'] = isset($object->ref_supplier) ? $object->ref_supplier : '';
- $this->substit['__DATE_YMD__'] = isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '';
- $this->substit['__DATE_DUE_YMD__'] = isset($object->date_lim_reglement)? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '';
- $this->substit['__AMOUNT__'] = price($object->total_ttc);
- $this->substit['__AMOUNT_WO_TAX__'] = price($object->total_ht);
- $this->substit['__AMOUNT_VAT__'] = price($object->total_tva);
+ $parameters=array('mode'=>$mode);
+ $tmparray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
+ complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
- $this->substit['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
- $this->substit['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
-
- $this->substit['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
- $this->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
- $this->substit['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
-
- $this->substit['__SIGNATURE__'] = $user->signature;
- $this->substit['__PERSONALIZED__'] = '';
- $this->substit['__CONTACTCIVNAME__'] = ''; // Will be replace just before sending
-
- // Create dynamic tags for __EXTRAFIELD_FIELD__
- $extrafields = new ExtraFields($this->db);
- $extralabels = $extrafields->fetch_name_optionals_label($object->table_element, true);
- $object->fetch_optionals($object->id, $extralabels);
- foreach ($extrafields->attribute_label as $key => $label) {
- $this->substit['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
- }
+ $this->substit=$tmparray;
// Fill substit_lines with each object lines content
if (is_array($object->lines))
@@ -1094,7 +1102,7 @@ class FormMail extends Form
'__QUANTITY__' => $line->qty,
'__SUBPRICE__' => price($line->subprice),
'__AMOUNT__' => price($line->total_ttc),
- '__AMOUNT_WO_TAX__' => price($line->total_ht),
+ '__AMOUNT_EXCL_TAX__' => price($line->total_ht),
//'__PRODUCT_EXTRAFIELD_FIELD__' Done dinamically just after
);
@@ -1127,54 +1135,43 @@ class FormMail extends Form
{
global $conf, $langs;
- $vars=array();
-
if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines')
{
- $vars=array(
- '__REF__'=>'__REF__',
- '__REFCLIENT__'=>'__REFCLIENT__',
- '__REFSUPPLIER__'=>'__REFSUPPLIER__',
- '__THIRDPARTY_ID__'=>'__THIRDPARTY_ID__',
- '__THIRDPARTY_NAME__'=>'__THIRDPARTY_NAME__',
- '__PROJECT_ID__'=>'__PROJECT_ID__',
- '__PROJECT_REF__'=>'__PROJECT_REF__',
- '__PROJECT_NAME__'=>'__PROJECT_NAME__',
- '__CONTACTCIVNAME__'=>'__CONTACTCIVNAME__',
- '__AMOUNT__'=>'__AMOUNT__',
- '__AMOUNT_WO_TAX__'=>'__AMOUNT_WO_TAX__',
- '__AMOUNT_VAT__'=>'__AMOUNT_VAT__',
- '__PERSONALIZED__'=>'__PERSONALIZED__', // Paypal link will be added here in form mode
- '__SIGNATURE__'=>'__SIGNATURE__',
- );
+ $parameters=array('mode'=>$mode);
+ $tmparray=getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
+ complete_substitutions_array($tmparray, $langs, null, $parameters);
+
if ($mode == 'formwithlines')
{
- $vars[] = '__LINES__'; // Will be set by the get_form function
+ $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
}
if ($mode == 'formforlines')
{
- $vars[] = '__QUANTITY__'; // Will be set by the get_form function
+ $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
}
}
+
if ($mode == 'emailing')
{
+ $parameters=array('mode'=>$mode);
+ $tmparray=getCommonSubstitutionArray($langs, 2, array('object','objectamount'), $object); // Note: On email templated edition, this is null because it is related to all type of objects
+ complete_substitutions_array($tmparray, $langs, null, $parameters);
+
// For mass emailing, we have different keys
- $vars=array(
- '__ID__' => 'IdRecord',
- '__EMAIL__' => 'EMailRecipient',
- '__LASTNAME__' => 'Lastname',
- '__FIRSTNAME__' => 'Firstname',
- '__MAILTOEMAIL__' => 'TagMailtoEmail',
- '__OTHER1__' => 'Other1',
- '__OTHER2__' => 'Other2',
- '__OTHER3__' => 'Other3',
- '__OTHER4__' => 'Other4',
- '__OTHER5__' => 'Other5',
- '__SIGNATURE__' => 'TagSignature',
- '__CHECK_READ__' => 'TagCheckMail',
- '__UNSUBSCRIBE__' => 'TagUnsubscribe'
+ $tmparray['__ID__'] = 'IdRecord';
+ $tmparray['__EMAIL__'] = 'EMailRecipient';
+ $tmparray['__LASTNAME__'] = 'Lastname';
+ $tmparray['__FIRSTNAME__'] = 'Firstname';
+ $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
+ $tmparray['__OTHER1__'] = 'Other1';
+ $tmparray['__OTHER2__'] = 'Other2';
+ $tmparray['__OTHER3__'] = 'Other3';
+ $tmparray['__OTHER4__'] = 'Other4';
+ $tmparray['__OTHER5__'] = 'Other5';
+ $tmparray['__SIGNATURE__'] = 'TagSignature';
+ $tmparray['__CHECK_READ__'] = 'TagCheckMail';
+ $tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
//,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
- );
$onlinepaymentenabled = 0;
if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
@@ -1182,13 +1179,13 @@ class FormMail extends Form
if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
{
- $vars['__SECUREKEYPAYMENT__']=$conf->global->PAYMENT_SECURITY_TOKEN;
+ $tmparray['__SECUREKEYPAYMENT__']=$conf->global->PAYMENT_SECURITY_TOKEN;
if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
{
- if ($conf->adherent->enabled) $vars['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
- if ($conf->facture->enabled) $vars['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
- if ($conf->commande->enabled) $vars['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
- if ($conf->contrat->enabled) $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
+ if ($conf->adherent->enabled) $tmparray['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
+ if ($conf->facture->enabled) $tmparray['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
+ if ($conf->commande->enabled) $tmparray['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
+ if ($conf->contrat->enabled) $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
}
}
else
@@ -1201,36 +1198,16 @@ class FormMail extends Form
$vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
*/
}
-
- // Old vars removed from doc
- /*
- if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
- {
- $vars['__SECUREKEYPAYPAL__']='SecureKeyPaypal';
- if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
- {
- if ($conf->adherent->enabled) $vars['__SECUREKEYPAYPAL_MEMBER__']='SecureKeyPaypalUniquePerMember';
- if ($conf->facture->enabled) $vars['__SECUREKEYPAYPAL_INVOICE__']='SecureKeyPaypalUniquePerInvoice';
- if ($conf->commande->enabled) $vars['__SECUREKEYPAYPAL_ORDER__']='SecureKeyPaypalUniquePerOrder';
- if ($conf->contrat->enabled) $vars['__SECUREKEYPAYPAL_CONTRACTLINE__']='SecureKeyPaypalUniquePerContractLine';
- }
- }
- else
- {
- $vars['__SECUREKEYPAYPAL__']='';
- $vars['__SECUREKEYPAYPAL_MEMBER__']='';
- }*/
}
- $parameters=array('mode'=>$mode);
- $tmparray=getCommonSubstitutionArray($langs, 2, null, $object);
- complete_substitutions_array($tmparray, $langs, null, $parameters);
+ $tmparray['__(AnyTranslationKey)__']="Translation";
+
foreach($tmparray as $key => $val)
{
- $vars[$key]=$key;
+ if (empty($val)) $tmparray[$key]=$key;
}
- return $vars;
+ return $tmparray;
}
}
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index 238728068c9..cdcebae7099 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -1369,8 +1369,8 @@ function dol_meta_create($object)
DATE=\"" . dol_print_date($object->date,'') . "\"
NB_ITEMS=\"" . $nblignes . "\"
CLIENT=\"" . $client . "\"
- AMOUNT_WO_TAX=\"" . $object->total_ht . "\"
- AMOUNT_INC_TAX=\"" . $object->total_ttc . "\"\n";
+ AMOUNT_EXCL_TAX=\"" . $object->total_ht . "\"
+ AMOUNT=\"" . $object->total_ttc . "\"\n";
for ($i = 0 ; $i < $nblignes ; $i++)
{
@@ -1537,7 +1537,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
$ecmfile=new EcmFiles($db);
$ecmfile->filepath = $rel_dir;
$ecmfile->filename = $filename;
- $ecmfile->label = md5_file(dol_osencode($destfull));
+ $ecmfile->label = md5_file(dol_osencode($destfull)); // MD5 of file content
$ecmfile->fullpath_orig = $TFile['name'][$i];
$ecmfile->gen_or_uploaded = 'uploaded';
$ecmfile->description = ''; // indexed content
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index f7b0bdd5ad9..704653ade84 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -129,7 +129,7 @@ function getEntity($element, $shared=1)
else
{
$out='';
- $addzero = array('user', 'usergroup', 'email_template', 'default_values');
+ $addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
if (in_array($element, $addzero)) $out.= '0,';
$out.= $conf->entity;
return $out;
@@ -5227,46 +5227,116 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
'__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id
));
}
- if (is_object($object) && (empty($exclude) || ! in_array('object', $exclude)))
+ if (($onlykey || is_object($object)) && (empty($exclude) || ! in_array('object', $exclude)))
{
- $substitutionarray['__ID__'] = $object->id;
- $substitutionarray['__REF__'] = $object->ref;
- $substitutionarray['__REFCLIENT__'] = (isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer : ''));
- $substitutionarray['__REFSUPPLIER__'] = (isset($object->ref_supplier) ? $object->ref_supplier : '');
-
- if (is_object($object->thirdparty) && $object->thirdparty->id > 0)
+ if ($onlykey)
{
- $substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
- $substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
+ $substitutionarray['__ID__'] = '__ID__';
+ $substitutionarray['__REF__'] = '__REF__';
+ $substitutionarray['__REFCLIENT__'] = '__REFCLIENT__';
+ $substitutionarray['__REFSUPPLIER__'] = '__REFSUPPLIER__';
+ $substitutionarray['__EXTRAFIELD_XXX__'] = '__EXTRAFIELD_XXX__';
+
+ $substitutionarray['__THIRDPARTY_ID__'] = '__THIRDPARTY_ID__';
+ $substitutionarray['__THIRDPARTY_NAME__'] = '__THIRDPARTY_NAME__';
+
+ $substitutionarray['__MEMBER_CIVILITY__'] = '__MEMBER_CIVILITY__';
+ $substitutionarray['__MEMBER_FIRSTNAME__'] = '__MEMBER_FIRSTNAME__';
+ $substitutionarray['__MEMBER_LASTNAME__'] = '__MEMBER_LASTNAME__';
+
+ $substitutionarray['__PROJECT_ID__'] = '__PROJECT_ID__';
+ $substitutionarray['__PROJECT_REF__'] = '__PROJECT_REF__';
+ $substitutionarray['__PROJECT_NAME__'] = '__PROJECT_REF__';
+
+ $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = 'Highest date planned for a service start';
+ $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = 'Highest date and hour planned for service start';
+ $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATE__'] = 'Lowest data for planned expiration of service';
+ $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] = 'Lowest date and hour for planned expiration of service';
+
+ $substitutionarray['__ONLINE_PAYMENT_URL__'] = 'LinkToPayOnlineIfApplicable';
+ $substitutionarray['__SECUREKEYPAYMENT__'] = 'Security key (if key is not unique per record)';
+ $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = 'Security key for payment on a member subscription (one key per member)';
+ $substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = 'Security key for payment on an order';
+ $substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = 'Security key for payment on an invoice';
+ $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'Security key for payment on a a service';
}
-
- if (is_object($object->projet) && $object->projet->id > 0)
+ else
{
- $substitutionarray['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
- $substitutionarray['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
- $substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
- }
+ $substitutionarray['__ID__'] = $object->id;
+ $substitutionarray['__REF__'] = $object->ref;
+ $substitutionarray['__REFCLIENT__'] = (isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer : ''));
+ $substitutionarray['__REFSUPPLIER__'] = (isset($object->ref_supplier) ? $object->ref_supplier : '');
- // Create dynamic tags for __EXTRAFIELD_FIELD__
- if ($object->table_element && $object->id > 0)
- {
- $extrafieldstmp = new ExtraFields($db);
- $extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true);
- $object->fetch_optionals($object->id, $extralabels);
- foreach ($extrafieldstmp->attribute_label as $key => $label) {
- $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
+ // TODO USe this ?
+ $msgishtml = 0;
+
+ if (method_exists($object, 'getCivilityLabel')) $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
+ $substitutionarray['__MEMBER_FIRSTNAME__']=$msgishtml?dol_htmlentitiesbr($object->firstname):$object->firstname;
+ $substitutionarray['__MEMBER_LASTNAME__']=$msgishtml?dol_htmlentitiesbr($object->lastname):$object->lastname;
+ if (method_exists($object, 'getFullName')) $substitutionarray['__MEMBER_FULLNAME__']=$msgishtml?dol_htmlentitiesbr($object->getFullName($langs)):$object->getFullName($langs);
+ $substitutionarray['__MEMBER_COMPANY__']=$msgishtml?dol_htmlentitiesbr($object->societe):$object->societe;
+ $substitutionarray['__MEMBER_ADDRESS__']=$msgishtml?dol_htmlentitiesbr($object->address):$object->address;
+ $substitutionarray['__MEMBER_ZIP__']=$msgishtml?dol_htmlentitiesbr($object->zip):$object->zip;
+ $substitutionarray['__MEMBER_TOWN__']=$msgishtml?dol_htmlentitiesbr($object->town):$object->town;
+ $substitutionarray['__MEMBER_COUNTRY__']=$msgishtml?dol_htmlentitiesbr($object->country):$object->country;
+ $substitutionarray['__MEMBER_EMAIL__']=$msgishtml?dol_htmlentitiesbr($object->email):$object->email;
+ $substitutionarray['__MEMBER_BIRTH__']=$msgishtml?dol_htmlentitiesbr($birthday):$birthday;
+ $substitutionarray['__MEMBER_PHOTO__']=$msgishtml?dol_htmlentitiesbr($object->photo):$object->photo;
+ $substitutionarray['__MEMBER_LOGIN__']=$msgishtml?dol_htmlentitiesbr($object->login):$object->login;
+ $substitutionarray['__MEMBER_PASSWORD__']=$msgishtml?dol_htmlentitiesbr($object->pass):$object->pass;
+ $substitutionarray['__MEMBER_PHONE__']=$msgishtml?dol_htmlentitiesbr($object->phone):$object->phone;
+ $substitutionarray['__MEMBER_PHONEPRO__']=$msgishtml?dol_htmlentitiesbr($object->phone_perso):$object->phone_perso;
+ $substitutionarray['__MEMBER_PHONEMOBILE__']=$msgishtml?dol_htmlentitiesbr($object->phone_mobile):$object->phone_mobile;
+
+ if (is_object($object->thirdparty) && $object->thirdparty->id > 0)
+ {
+ $substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
+ $substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
}
- }
- $substitutionarray['__ONLINE_PAYMENT_URL__'] = 'LinkToPayOnlineIfApplicable';
+ if (is_object($object->projet) && $object->projet->id > 0)
+ {
+ $substitutionarray['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
+ $substitutionarray['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
+ $substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
+ }
+
+ // Create dynamic tags for __EXTRAFIELD_FIELD__
+ if ($object->table_element && $object->id > 0)
+ {
+ $extrafieldstmp = new ExtraFields($db);
+ $extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true);
+ $object->fetch_optionals($object->id, $extralabels);
+ foreach ($extrafieldstmp->attribute_label as $key => $label) {
+ $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
+ }
+ }
+
+ if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))
+ {
+ $dateplannedstart='';
+ $datenextexpiration='';
+ foreach($object->lines as $line)
+ {
+ if ($line->date_ouverture_prevue > $dateplannedstart) $dateplannedstart = $line->date_ouverture_prevue;
+ if ($line->statut == 4 && $line->date_fin_prevue && (! $datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) $datenextexpiration = $line->date_fin_prevue;
+ }
+ $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = dol_print_date($dateplannedstart, 'dayrfc');
+ $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = dol_print_date($dateplannedstart, 'standard');
+ $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc');
+ $substitutionarray['__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard');
+ }
+
+ $substitutionarray['__ONLINE_PAYMENT_URL__'] = 'TODO';
+ }
}
if (empty($exclude) || ! in_array('objectamount', $exclude))
{
- $substitutionarray['__DATE_YMD__'] = is_object($object)?(isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '') : '';
- $substitutionarray['__DATE_DUE_YMD__'] = is_object($object)?(isset($object->date_lim_reglement)? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '') : '';
- $substitutionarray['__AMOUNT__'] = is_object($object)?$object->total_ttc:'';
- $substitutionarray['__AMOUNT_WO_TAX__']= is_object($object)?$object->total_ht:'';
- $substitutionarray['__AMOUNT_VAT__'] = is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
+ $substitutionarray['__DATE_YMD__'] = is_object($object)?(isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '') : '';
+ $substitutionarray['__DATE_DUE_YMD__'] = is_object($object)?(isset($object->date_lim_reglement)? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '') : '';
+ $substitutionarray['__AMOUNT__'] = is_object($object)?$object->total_ttc:'';
+ $substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object)?$object->total_ht:'';
+ $substitutionarray['__AMOUNT_VAT__'] = is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
// For backward compatibility
if ($onlykey != 2)
{
@@ -5280,41 +5350,35 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- if (! empty($onlykey))
- {
- $tmp=$tmp2=$tmp3=$tmp4=$tmp5=array();
- }
- else
- {
- $tmp=dol_getdate(dol_now(), true);
- $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']);
- $tmp3=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']);
- $tmp4=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
- $tmp5=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']);
- }
+ $tmp=dol_getdate(dol_now(), true);
+ $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']);
+ $tmp3=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']);
+ $tmp4=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
+ $tmp5=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']);
+
$substitutionarray=array_merge($substitutionarray, array(
- '__DAY__' => $tmp['mday'],
- '__MONTH__' => $tmp['mon'],
- '__YEAR__' => $tmp['year'],
- '__PREVIOUS_DAY__' => $tmp2['day'],
- '__PREVIOUS_MONTH__' => $tmp3['month'],
- '__PREVIOUS_YEAR__' => ($tmp['year'] - 1),
- '__NEXT_DAY__' => $tmp4['day'],
- '__NEXT_MONTH__' => $tmp5['month'],
- '__NEXT_YEAR__' => ($tmp['year'] + 1),
+ '__DAY__' => (string) $tmp['mday'],
+ '__MONTH__' => (string) $tmp['mon'],
+ '__YEAR__' => (string) $tmp['year'],
+ '__PREVIOUS_DAY__' => (string) $tmp2['day'],
+ '__PREVIOUS_MONTH__' => (string) $tmp3['month'],
+ '__PREVIOUS_YEAR__' => (string) ($tmp['year'] - 1),
+ '__NEXT_DAY__' => (string) $tmp4['day'],
+ '__NEXT_MONTH__' => (string) $tmp5['month'],
+ '__NEXT_YEAR__' => (string) ($tmp['year'] + 1),
));
}
if (empty($exclude) || ! in_array('user', $exclude))
{
$substitutionarray=array_merge($substitutionarray, array(
- '__USER_ID__' => $user->id,
- '__USER_LOGIN__' => $user->login,
- '__USER_LASTNAME__' => $user->lastname,
- '__USER_FIRSTNAME__' => $user->firstname,
- '__USER_FULLNAME__' => $user->getFullName($outputlangs),
- '__USER_SUPERVISOR_ID__' => $user->fk_user,
- '__SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($user->signature), 30) : $user->signature) : '')
+ '__USER_ID__' => (string) $user->id,
+ '__USER_LOGIN__' => (string) $user->login,
+ '__USER_LASTNAME__' => (string) $user->lastname,
+ '__USER_FIRSTNAME__' => (string) $user->firstname,
+ '__USER_FULLNAME__' => (string) $user->getFullName($outputlangs),
+ '__USER_SUPERVISOR_ID__' => (string) $user->fk_user,
+ '__SIGNATURE__' => (string) (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($user->signature), 30) : $user->signature) : '')
));
}
if (! empty($conf->multicompany->enabled))
@@ -5369,8 +5433,8 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
}
/**
- * Complete the $substitutionarray with more entries.
- * Can also add substitution keys coming from external module that had set the "substitutions=1" into module_part array. In this case, method completesubstitutionarray provided by module is called.
+ * Complete the $substitutionarray with more entries coming from external module that had set the "substitutions=1" into module_part array.
+ * In this case, method completesubstitutionarray provided by module is called.
*
* @param array $substitutionarray Array substitution old value => new value value
* @param Translate $outputlangs Output language
@@ -5386,13 +5450,8 @@ function complete_substitutions_array(&$substitutionarray, $outputlangs, $object
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- // Add a substitution key for each object property
- if (is_object($object))
- {
- // TODO
- }
-
// Add a substitution key for each extrafields, using key __EXTRA_XXX__
+ // TODO Remove this. Already available into the getCommonSubstitutionArray used to build the substitution array.
if (is_object($object) && is_array($object->array_options))
{
foreach($object->array_options as $key => $val)
diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql
index 917cfd74891..6a02f67c6d4 100644
--- a/htdocs/core/menus/init_menu_auguria.sql
+++ b/htdocs/core/menus/init_menu_auguria.sql
@@ -175,7 +175,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1700__+MAX_llx_menu__, 'billing', 'customer_bills', 6__+MAX_llx_menu__, '/compta/facture/list.php?leftmenu=customers_bills', 'BillsCustomers', 0, 'bills', '$user->rights->facture->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1701__+MAX_llx_menu__, 'billing', '', 1700__+MAX_llx_menu__, '/compta/facture/card.php?action=create&leftmenu=customers_bills', 'NewBill', 1, 'bills', '$user->rights->facture->creer', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1705__+MAX_llx_menu__, 'billing', '', 1700__+MAX_llx_menu__, '/compta/facture/list.php?leftmenu=customers_bills', 'List', 1, 'bills', '$user->rights->facture->lire', '', 2, 4, __ENTITY__);
-insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1702__+MAX_llx_menu__, 'billing', '', 1700__+MAX_llx_menu__, '/compta/facture/fiche-rec.php?leftmenu=customers_bills', 'ListOfTemplates', 1, 'bills', '$user->rights->facture->lire', '', 2, 5, __ENTITY__);
+insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1702__+MAX_llx_menu__, 'billing', '', 1700__+MAX_llx_menu__, '/compta/facture/invoicetemplate_list.php?leftmenu=customers_bills', 'ListOfTemplates', 1, 'bills', '$user->rights->facture->lire', '', 2, 5, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1720__+MAX_llx_menu__, 'billing', '', 1705__+MAX_llx_menu__, '/compta/facture/list.php?leftmenu=customers_bills&search_status=0', 'BillShortStatusDraft', 2, 'bills', '$user->rights->facture->lire', '', 2, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1721__+MAX_llx_menu__, 'billing', '', 1705__+MAX_llx_menu__, '/compta/facture/list.php?leftmenu=customers_bills&search_status=1', 'BillShortStatusNotPaid', 2, 'bills', '$user->rights->facture->lire', '', 2, 2, __ENTITY__);
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index 55d3b75fe13..8c03d0c1ffc 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -811,7 +811,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_paid&search_status=2",$langs->trans("BillShortStatusPaid"),2,$user->rights->facture->lire);
$newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_canceled&search_status=3",$langs->trans("BillShortStatusCanceled"),2,$user->rights->facture->lire);
}
- $newmenu->add("/compta/facture/fiche-rec.php",$langs->trans("ListOfTemplates"),1,$user->rights->facture->creer); // No need to see recurring invoices, if user has no permission to create invoice.
+ $newmenu->add("/compta/facture/invoicetemplate_list.php",$langs->trans("ListOfTemplates"),1,$user->rights->facture->creer); // No need to see recurring invoices, if user has no permission to create invoice.
$newmenu->add("/compta/paiement/list.php",$langs->trans("Payments"),1,$user->rights->facture->lire);
diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php
index 062e9777b40..e24fbb44f7a 100644
--- a/htdocs/core/tpl/card_presend.tpl.php
+++ b/htdocs/core/tpl/card_presend.tpl.php
@@ -73,13 +73,16 @@ if ($action == 'presend')
// Build document if it not exists
if (! $file || ! is_readable($file)) {
- $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0) {
- dol_print_error($db, $object->error, $object->errors);
- exit();
+ if ($object->element != 'member')
+ {
+ $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0) {
+ dol_print_error($db, $object->error, $object->errors);
+ exit();
+ }
+ $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
+ $file = $fileparams['fullname'];
}
- $fileparams = dol_most_recent_file($diroutput . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
- $file = $fileparams['fullname'];
}
print '';
@@ -120,6 +123,10 @@ if ($action == 'presend')
$liste[$key] = $value;
}
}
+ elseif ($object->element == 'member')
+ {
+ $liste['thirdparty'] = $object->getFullName($langs)." <".$object->email.">";
+ }
else
{
foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) {
@@ -139,43 +146,8 @@ if ($action == 'presend')
// Make substitution in email content
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
$substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? ' ' : '';
- $substitutionarray['__PERSONALIZED__'] = '';
+ $substitutionarray['__PERSONALIZED__'] = ''; // deprecated
$substitutionarray['__CONTACTCIVNAME__'] = '';
- // Add specific substitution for contracts
- if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))
- {
- $datenextexpiration = '';
- foreach ($object->lines as $line)
- {
- if ($line->statut != 4)
- continue;
- if ($line->date_fin_prevue > $datenextexpiration)
- $datenextexpiration = $line->date_fin_prevue;
- }
- $substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc');
- $substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard');
- }
-
- // Choose one contact for the __CONTACTCIVNAME__ TODO Really not reliable.
- /*
- $custcontact = '';
- $contactarr = array();
- $contactarr = $object->liste_contact(-1, 'external');
- if (is_array($contactarr) && count($contactarr) > 0)
- {
- foreach ($contactarr as $contact)
- {
- if ($contact['libelle'] == $langs->trans('TypeContact_commande_external_CUSTOMER')) { // TODO Use code and not label
- $contactstatic = new Contact($db);
- $contactstatic->fetch($contact ['id']);
- $custcontact = $contactstatic->getFullName($langs, 1);
- }
- }
-
- if (! empty($custcontact)) {
- $formmail->substit['__CONTACTCIVNAME__'] = $custcontact;
- }
- }*/
$parameters = array(
'mode' => 'formemail'
diff --git a/htdocs/core/tpl/massactions_form.tpl.php b/htdocs/core/tpl/massactions_form.tpl.php
index 4f8c7d15aeb..4087d988c3b 100644
--- a/htdocs/core/tpl/massactions_form.tpl.php
+++ b/htdocs/core/tpl/massactions_form.tpl.php
@@ -74,7 +74,7 @@ if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAI
$formmail->frommail = dolAddEmailTrackId($formmail->frommail, $trackid);
}
$formmail->withfrom = 1;
-$liste = $langs->trans("AllRecipientSelected", count($listofselectedthirdparties));
+$liste = $langs->trans("AllRecipientSelected", count($arrayofselected));
if (count($listofselectedthirdparties) == 1) // Only 1 different recipient selected, we can suggest contacts
{
$liste = array();
@@ -97,8 +97,10 @@ if (count($listofselectedthirdparties) == 1) // Only 1 different recipient selec
} else {
$formmail->withtoreadonly = 1;
}
-$formmail->withto = $liste;
-$formmail->withtofree = 0;
+
+$formmail->withoptiononeemailperrecipient = empty($liste)?0:((GETPOST('oneemailperrecipient')=='on')?1:-1);
+$formmail->withto = empty($liste)?(GETPOST('sendto','alpha')?GETPOST('sendto','alpha'):array()):$liste;
+$formmail->withtofree = empty($liste)?1:0;
$formmail->withtocc = 1;
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
$formmail->withtopic = $langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
@@ -117,22 +119,8 @@ $formmail->withcancel = 1;
$substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
$substitutionarray['__EMAIL__'] = $sendto;
$substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? ' ' : '';
-$substitutionarray['__PERSONALIZED__'] = '';
+$substitutionarray['__PERSONALIZED__'] = ''; // deprecated
$substitutionarray['__CONTACTCIVNAME__'] = '';
-// Add specific substitution for contracts
-if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))
-{
- $datenextexpiration = '';
- foreach ($object->lines as $line)
- {
- if ($line->statut != 4)
- continue;
- if ($line->date_fin_prevue > $datenextexpiration)
- $datenextexpiration = $line->date_fin_prevue;
- }
- $substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc');
- $substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard');
-}
$parameters = array(
'mode' => 'formemail'
diff --git a/htdocs/document.php b/htdocs/document.php
index d35021005e6..11017f52cc2 100644
--- a/htdocs/document.php
+++ b/htdocs/document.php
@@ -59,24 +59,27 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$encoding = '';
$action=GETPOST('action','alpha');
-$original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP).
+$original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP).
+$hashp=GETPOST('hashp','aZ09');
$modulepart=GETPOST('modulepart','alpha');
$urlsource=GETPOST('urlsource','alpha');
$entity=GETPOST('entity','int')?GETPOST('entity','int'):$conf->entity;
// Security check
-if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
+if (empty($modulepart)) accessforbidden('Bad link. Bad value for parameter modulepart',0,0,1);
+if (empty($original_file) && empty($hashp)) accessforbidden('Bad link. Missing identification to find file (original_file or hashp)',0,0,1);
if ($modulepart == 'fckeditor') $modulepart='medias'; // For backward compatibility
$socid=0;
if ($user->societe_id > 0) $socid = $user->societe_id;
// For some module part, dir may be privates
-if (in_array($modulepart,array('facture_paiement','unpaid')))
+if (in_array($modulepart, array('facture_paiement','unpaid')))
{
if (! $user->rights->societe->client->voir || $socid) $original_file='private/'.$user->id.'/'.$original_file; // If user has no permission to see all, output dir is specific to user
}
+
/*
* Action
*/
@@ -99,6 +102,33 @@ if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false;
if (isset($_GET["attachment"])) $attachment = GETPOST("attachment",'alpha')?true:false;
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false;
+// If we have a hash public (hashp), we guess the original_file.
+if (! empty($hashp))
+{
+ include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+ $ecmfile=new EcmFiles($db);
+ $result = $ecmfile->fetch(0, '', '', '', $hashp);
+ if ($result > 0)
+ {
+ $tmp = explode('/', $ecmfile->filepath, 2); // $ecmfile->filepatch is relative to document directory
+ $moduleparttocheck = $tmp[0];
+ if ($moduleparttocheck == $modulepart)
+ {
+ $original_file = (($tmp[1]?$tmp[1].'/':'').$ecmfile->filename); // this is relative to module dir
+ //var_dump($original_file); exit;
+ }
+ else
+ {
+ accessforbidden('Bad link. File owns to another module part.',0,0,1);
+ }
+ }
+ else
+ {
+ accessforbidden('Bad link. File was not found or sharing attribute removed recently.',0,0,1);
+ }
+}
+
+
// Security: Delete string ../ into $original_file
$original_file = str_replace("../","/", $original_file);
diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php
index f1090757dad..0035b18d3c7 100644
--- a/htdocs/ecm/class/ecmfiles.class.php
+++ b/htdocs/ecm/class/ecmfiles.class.php
@@ -46,7 +46,9 @@ class EcmFiles //extends CommonObject
/**
*/
- public $label;
+ public $ref; // hash of file path
+ public $label; // hash of file content (md5_file(dol_osencode($destfull))
+ public $share; // hash for file sharing. empty by default
public $entity;
public $filename;
public $filepath;
@@ -94,10 +96,15 @@ class EcmFiles //extends CommonObject
$error = 0;
// Clean parameters
-
+ if (isset($this->ref)) {
+ $this->ref = trim($this->ref);
+ }
if (isset($this->label)) {
$this->label = trim($this->label);
}
+ if (isset($this->share)) {
+ $this->share = trim($this->share);
+ }
if (isset($this->entity)) {
$this->entity = trim($this->entity);
}
@@ -136,6 +143,10 @@ class EcmFiles //extends CommonObject
}
if (empty($this->date_c)) $this->date_c = dol_now();
+ // If ref not defined
+ if (empty($ref)) $ref = dol_hash($this->filepath.'/'.$this->filename, 3);
+
+
$maxposition=0;
if (empty($this->position)) // Get max used
{
@@ -157,7 +168,9 @@ class EcmFiles //extends CommonObject
// Insert request
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
+ $sql.= 'ref,';
$sql.= 'label,';
+ $sql.= 'share,';
$sql.= 'entity,';
$sql.= 'filename,';
$sql.= 'filepath,';
@@ -174,7 +187,9 @@ class EcmFiles //extends CommonObject
$sql.= 'fk_user_m,';
$sql.= 'acl';
$sql .= ') VALUES (';
+ $sql .= " '".$ref."', ";
$sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
+ $sql .= ' '.(! isset($this->share)?'NULL':"'".$this->db->escape($this->share)."'").',';
$sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).',';
$sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").',';
$sql .= ' '.(! isset($this->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").',';
@@ -232,11 +247,13 @@ class EcmFiles //extends CommonObject
* Load object in memory from the database
*
* @param int $id Id object
- * @param string $ref Not used yet. Will contains a hash id from filename+filepath
+ * @param string $ref Hash of file name (filename+filepath). Not always defined on some version.
* @param string $relativepath Relative path of file from document directory. Example: path/path2/file
+ * @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed.
+ * @param string $hashforshare Hash of file sharing.
* @return int <0 if KO, 0 if not found, >0 if OK
*/
- public function fetch($id, $ref = null, $relativepath = '')
+ public function fetch($id, $ref = '', $relativepath = '', $hashoffile='', $hashforshare='')
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -244,6 +261,7 @@ class EcmFiles //extends CommonObject
$sql .= ' t.rowid,';
$sql .= " t.ref,";
$sql .= " t.label,";
+ $sql .= " t.share,";
$sql .= " t.entity,";
$sql .= " t.filename,";
$sql .= " t.filepath,";
@@ -268,11 +286,20 @@ class EcmFiles //extends CommonObject
if ($relativepath) {
$sql .= " AND t.filepath = '" . $this->db->escape(dirname($relativepath)) . "' AND t.filename = '".$this->db->escape(basename($relativepath))."'";
}
- elseif (null !== $ref) {
+ elseif (! empty($ref)) {
$sql .= " AND t.ref = '".$this->db->escape($ref)."'";
+ }
+ elseif (! empty($hashoffile)) {
+ $sql .= " AND t.label = '".$this->db->escape($hashoffile)."'";
+ }
+ elseif (! empty($hashforshare)) {
+ $sql .= " AND t.share = '".$this->db->escape($hashforshare)."'";
} else {
$sql .= ' AND t.rowid = ' . $id;
}
+ // When we search on hash of content, we take the first one. Solve also hash conflict.
+ $this->db->plimit(1);
+ $this->db->order('t.rowid', 'ASC');
$resql = $this->db->query($sql);
if ($resql) {
@@ -283,6 +310,7 @@ class EcmFiles //extends CommonObject
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->label = $obj->label;
+ $this->share = $obj->share;
$this->entity = $obj->entity;
$this->filename = $obj->filename;
$this->filepath = $obj->filepath;
@@ -344,6 +372,7 @@ class EcmFiles //extends CommonObject
$sql = 'SELECT';
$sql .= ' t.rowid,';
$sql .= " t.label,";
+ $sql .= " t.share,";
$sql .= " t.entity,";
$sql .= " t.filename,";
$sql .= " t.filepath,";
@@ -393,8 +422,9 @@ class EcmFiles //extends CommonObject
$line = new EcmfilesLine();
$line->id = $obj->rowid;
-
+ $line->ref = $obj->ref;
$line->label = $obj->label;
+ $line->share = $obj->share;
$line->entity = $obj->entity;
$line->filename = $obj->filename;
$line->filepath = $obj->filepath;
@@ -438,9 +468,15 @@ class EcmFiles //extends CommonObject
// Clean parameters
+ if (isset($this->ref)) {
+ $this->ref = trim($this->ref);
+ }
if (isset($this->label)) {
$this->label = trim($this->label);
}
+ if (isset($this->share)) {
+ $this->share = trim($this->share);
+ }
if (isset($this->entity)) {
$this->entity = trim($this->entity);
}
@@ -484,7 +520,9 @@ class EcmFiles //extends CommonObject
// Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
+ $sql .= " ref = '".dol_hash($this->filepath.'/'.$this->filename, 3)."',";
$sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
+ $sql .= ' share = '.(! empty($this->share)?"'".$this->db->escape($this->share)."'":"null").',';
$sql .= ' entity = '.(isset($this->entity)?$this->entity:$conf->entity).',';
$sql .= ' filename = '.(isset($this->filename)?"'".$this->db->escape($this->filename)."'":"null").',';
$sql .= ' filepath = '.(isset($this->filepath)?"'".$this->db->escape($this->filepath)."'":"null").',';
diff --git a/htdocs/ecm/docfile.php b/htdocs/ecm/docfile.php
index 192240b4943..a856ab22c36 100644
--- a/htdocs/ecm/docfile.php
+++ b/htdocs/ecm/docfile.php
@@ -19,12 +19,12 @@
* \file htdocs/ecm/docfile.php
* \ingroup ecm
* \brief Card of a file for ECM module
- * \author Laurent Destailleur
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
+require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
@@ -39,6 +39,9 @@ $langs->load("bills");
$langs->load("contracts");
$langs->load("categories");
+$action = GETPOST('action', 'aZ09');
+$cancel = GETPOST('cancel', 'alpha');
+
if (!$user->rights->ecm->setup) accessforbidden();
// Get parameters
@@ -61,8 +64,6 @@ $pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="label";
-$cancel=GETPOST('cancel','alpha');
-$action=GETPOST('action','aZ09');
$section=GETPOST("section");
if (! $section)
{
@@ -87,29 +88,33 @@ if (! $result > 0)
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
+$fullpath=$conf->ecm->dir_output.'/'.$relativepath.$urlfile;
+
+$file = new stdClass();
+$file->section_id=$ecmdir->id;
+$file->label=$urlfile;
+
+$relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document
+$filepath=$relativepath.$file->label;
+$filepathtodocument=$relativetodocument.$file->label;
+
+// Try to load object from index
+$object = new ECMFiles($db);
+$result=$object->fetch(0, '', $filepathtodocument);
+if (! ($result >= 0))
+{
+ dol_print_error($db, $object->error, $object->errors);
+ exit;
+}
+
+
+
/*
-$ecmfile = new ECMFile($db);
-if (! empty($_GET["fileid"]))
-{
- $result=$ecmfile->fetch($_GET["fileid"]);
- if (! $result > 0)
- {
- dol_print_error($db,$ecmfile->error);
- exit;
- }
-}
-*/
+ * Actions
+ */
-
-
-/*******************************************************************
- * ACTIONS
- *
- * Put here all code to do according to value of "action" parameter
- ********************************************************************/
-
-if ($action == 'cancel')
+if ($cancel)
{
$action ='';
if ($backtourl)
@@ -119,7 +124,7 @@ if ($action == 'cancel')
}
else
{
- header("Location: ".DOL_URL_ROOT.'/ecm/index.php?action=file_manager§ion='.$section);
+ header("Location: ".DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.$urlfile.'§ion='.$section);
exit;
}
}
@@ -129,8 +134,9 @@ if ($action == 'update')
{
$error=0;
- $oldlabel=GETPOST('urlfile');
- $newlabel=GETPOST('label');
+ $oldlabel=GETPOST('urlfile', 'alpha');
+ $newlabel=GETPOST('label', 'alpha');
+ $shareenabled = GETPOST('shareenabled', 'alpha');
//$db->begin();
@@ -144,7 +150,7 @@ if ($action == 'update')
//print $oldfile.' - '.$newfile;
if ($newlabel != $oldlabel)
{
- $result=dol_move($oldfile, $newfile);
+ $result=dol_move($oldfile, $newfile); // This include update of database
if (! $result)
{
$langs->load('errors');
@@ -153,44 +159,62 @@ if ($action == 'update')
}
}
+ // Now we update index of file
+ $db->begin();
+
if (! $error)
{
- //$db->commit();
+ if (is_object($object))
+ {
+ if ($shareenabled)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
+ $object->share = getRandomPassword(true);
+ }
+ else
+ {
+ $object->share = '';
+ }
+ $result = $object->update($user);
+ if ($result < 0)
+ {
+ $error++;
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
+ }
+
+ if (!$error)
+ {
+ $db->commit();
$urlfile=$newlabel;
}
else
{
- //$db->rollback();
+ $db->rollback();
}
}
-/*******************************************************************
- * PAGE
- *
- * Put here all code to do according to value of "action" parameter
- ********************************************************************/
-
-llxHeader();
+/*
+ * View
+ */
$form=new Form($db);
-$fullpath=$conf->ecm->dir_output.'/'.$relativepath.$urlfile;
-
-$file = new stdClass();
-$file->section_id=$ecmdir->id;
-$file->label=$urlfile;
+llxHeader();
$head = ecm_file_prepare_head($file);
-if ($_GET["action"] == 'edit')
+if ($action == 'edit')
{
print ' |
';
+
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
-print '