From 1348c03ca01ab93f3b358c82addba72eb5f58b4a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 13 Oct 2020 14:46:17 +0200 Subject: [PATCH 1/4] FIX avoid spaces in file name --- htdocs/admin/system/phpinfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/system/phpinfo.php b/htdocs/admin/system/phpinfo.php index 05038c13bbc..c9f98457aee 100644 --- a/htdocs/admin/system/phpinfo.php +++ b/htdocs/admin/system/phpinfo.php @@ -265,8 +265,8 @@ $db->close(); */ function getActivatedExtensions() { - $file = getConfigFilePath(); - $handle = fopen(GetConfigFilePath(), "r"); + $file = trim(getConfigFilePath()); + $handle = fopen($file, "r"); $content = fread($handle, filesize($file)); fclose($handle); From 00ee1a743316238c82ae1f5868990d66e17e6107 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 13 Oct 2020 15:08:43 +0200 Subject: [PATCH 2/4] FIX compatibility with LF (Line Feed) --- htdocs/admin/system/phpinfo.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/system/phpinfo.php b/htdocs/admin/system/phpinfo.php index c9f98457aee..9f1766a5d22 100644 --- a/htdocs/admin/system/phpinfo.php +++ b/htdocs/admin/system/phpinfo.php @@ -273,6 +273,11 @@ function getActivatedExtensions() $configLines = explode("\r", $content); + // For compatibility with LF (Line Feed) + if (empty($configLines) || count($configLines) < 2) { + $configLines = explode("\n", $content); + } + $extensions = array(); $lastLine = ""; @@ -281,11 +286,13 @@ function getActivatedExtensions() $line = trim($line); // ignore comment lines - if (substr($line, 0, 1) === ";") + if (substr($line, 0, 1) === ";" || empty($line)) { continue; } + // var_dump($line); + // extension if (substr($line, 0, 9) === "extension" && substr($line, 0, 10) !== "extension_") { From 02fcee5d94aaef9a63b2b7b3ae96d188142310dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Oct 2020 12:21:31 +0200 Subject: [PATCH 3/4] Fix make the default sender email mandatory into setup (if not defined, no emails can be sent). --- htdocs/admin/mails.php | 70 +++++++++++++++++++++-------------- htdocs/langs/en_US/admin.lang | 1 + 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php index 8971f5a69d4..55316e47332 100644 --- a/htdocs/admin/mails.php +++ b/htdocs/admin/mails.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $langs->loadLangs(array("companies", "products", "admin", "mails", "other", "errors")); $action = GETPOST('action', 'aZ09'); +$cancel = GETPOST('cancel', 'aZ09'); if (!$user->admin) accessforbidden(); @@ -64,33 +65,46 @@ complete_substitutions_array($substitutionarrayfortest, $langs); * Actions */ -if ($action == 'update' && empty($_POST["cancel"])) +if ($action == 'update' && !$cancel) { - dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS", 'int'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT", 'int'), 'chaine', 0, '', $conf->entity); - // Send mode parameters - dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE", 'aZ09'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT", 'int'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'none'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS", 'int'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS", 'int'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", 'int'), 'chaine', 0, '', $conf->entity); + if (! $error && ! GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MAIN_MAIL_EMAIL_FROM")), null, 'errors'); + $action = 'edit'; + } + if (! $error && ! isValidEmail(GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'))) { + $error++; + setEventMessages($langs->trans("ErrorBadEMail", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')), null, 'errors'); + $action = 'edit'; + } - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED", 'int'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - // Content parameters - dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE', 'alphanohtml'), 'chaine', 0, '', $conf->entity); + if (! $error) { + dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS", 'int'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT", 'int'), 'chaine', 0, '', $conf->entity); + // Send mode parameters + dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE", 'aZ09'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT", 'int'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'none'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS", 'int'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS", 'int'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", 'int'), 'chaine', 0, '', $conf->entity); - header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); - exit; + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED", 'int'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + // Content parameters + dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE', 'alphanohtml'), 'chaine', 0, '', $conf->entity); + + header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); + exit; + } } @@ -462,8 +476,8 @@ if ($action == 'edit') print ''.$langs->trans("OtherOptions").''; // From - print ''.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).''; - print ''.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).''; + print ''; // Default from type @@ -538,7 +552,7 @@ if ($action == 'edit') print $text; if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) { - print $form->textwithpicto('', $langs->trans("WarningPHPMail").'
'.$langs->trans("WarningPHPMailA").'
'.$langs->trans("WarningPHPMailB").'
'.$langs->trans("WarningPHPMailC"), 1, 'warning'); + print $form->textwithpicto('', $langs->trans("WarningPHPMail").'
'.$langs->trans("WarningPHPMailA").'
'.$langs->trans("WarningPHPMailB").'
'.$langs->trans("WarningPHPMailC").'

'.$langs->trans("WarningPHPMailD"), 1, 'warning'); } print ''; @@ -637,7 +651,7 @@ if ($action == 'edit') print ''; if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) { - print info_admin($langs->trans("WarningPHPMail").'
'.$langs->trans("WarningPHPMailA").'
'.$langs->trans("WarningPHPMailB").'
'.$langs->trans("WarningPHPMailC"), 0, 0, 'warning'); + print info_admin($langs->trans("WarningPHPMail").'
'.$langs->trans("WarningPHPMailA").'
'.$langs->trans("WarningPHPMailB").'
'.$langs->trans("WarningPHPMailC").'

'.$langs->trans("WarningPHPMailD"), 0, 0, 'warning'); } print '
'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 3091efcf7fd..e887b29879d 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -483,6 +483,7 @@ WarningPHPMail=WARNING: The setup to send emails from the application is using t WarningPHPMailA=- Using the server of the Email Service Provider increase the trustability of your email, so it increase the deliverablity without being flagging as SPAM WarningPHPMailB=- Some Email Service Providers (like Yahoo) do not allow you to send an email from another server than their own server. Your current setup uses the server of the application to send email and not the server of your email provider, so some recipients (the one compatible with the restrictive DMARC protocol), will ask your email provider if they can accept your email and some email providers (like Yahoo) may respond "no" because the server is not theirs, so few of your sent Emails may not be accepted for delivery (be careful also of your email provider's sending quota). WarningPHPMailC=- Using the SMTP server of your own Email Service Provider to send emails is also interesting so all emails sent from application will also be saved into your "Sent" directory of your mailbox. +WarningPHPMailD=If the method 'PHP Mail' is really the method you would like to use, you can remove this warning by adding the constant MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP to 1 in Home - Setup - Other. WarningPHPMail2=If your email SMTP provider need to restrict email client to some IP addresses (very rare), this is the IP address of the mail user agent (MUA) for your ERP CRM application: %s. WarningPHPMailSPF=If the domain name in your sender email address is protected by a SPF record (ask you domain name registar), you must add the following IPs in the SPF record of the DNS of your domain: %s. ClickToShowDescription=Click to show description From a0b17635fdf3816beaafaa7c3a1dcfa85ad076ea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Oct 2020 14:02:07 +0200 Subject: [PATCH 4/4] NEW When creating a user from a member linked to a thirdparty, you can decide if it is an internal or external (default) user. --- htdocs/adherents/card.php | 19 ++++++++++++++----- htdocs/core/class/html.form.class.php | 5 +++-- htdocs/langs/en_US/users.lang | 1 + htdocs/main.inc.php | 2 +- htdocs/societe/class/societe.class.php | 11 ++++++----- htdocs/user/class/user.class.php | 3 ++- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index d0a67153209..cd432aa12d6 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -181,7 +181,12 @@ if (empty($reshook)) { if ($result > 0) { // Creation user $nuser = new User($db); - $result = $nuser->create_from_member($object, GETPOST('login', 'alphanohtml')); + $tmpuser = dol_clone($object); + if (GETPOST('internalorexternal', 'aZ09') == 'internal') { + $tmpuser->fk_soc = 0; + } + + $result = $nuser->create_from_member($tmpuser, GETPOST('login', 'alphanohtml')); if ($result < 0) { $langs->load("errors"); @@ -1279,11 +1284,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $formquestion = array( array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login) ); - $text = $langs->trans("ConfirmCreateLogin").'
'; - if (!empty($conf->societe->enabled)) { - if ($object->socid > 0) $text .= $langs->trans("UserWillBeExternalUser"); - else $text .= $langs->trans("UserWillBeInternalUser"); + if (!empty($conf->societe->enabled) && $object->socid > 0) { + $object->fetch_thirdparty(); + $formquestion[] = array('label' => $langs->trans("UserWillBe"), 'type' => 'radio', 'name' => 'internalorexternal', 'default'=>'external', 'values' => array('external'=>$langs->trans("External").' - '.$langs->trans("LinkedToDolibarrThirdParty").' '.$object->thirdparty->getNomUrl(1, '', 0, 1), 'internal'=>$langs->trans("Internal"))); } + $text = ''; + if (!empty($conf->societe->enabled) && $object->socid <= 0) { + $text .= $langs->trans("UserWillBeInternalUser").'
'; + } + $text .= $langs->trans("ConfirmCreateLogin"); print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes'); } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 452454ced5b..e58ba5d5a8e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4213,10 +4213,11 @@ class Form $more .= '
'; if ($i == 0) $more .= '
'.$input['label'].'
'; else $more .= '
 
'; - $more .= '
'.$selval.''; $more .= '
'."\n"; $i++; } diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index d6ffb849aa8..996ba20ab7d 100644 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -75,6 +75,7 @@ CreateInternalUserDesc=This form allows you to create an internal user in your c InternalExternalDesc=An internal user is a user that is part of your company/organization.
An external user is a customer, vendor or other (Creating an external user for a third-party can be done from the contact record of the third-party).

In both cases, permissions defines rights on Dolibarr, also external user can have a different menu manager than internal user (See Home - Setup - Display) PermissionInheritedFromAGroup=Permission granted because inherited from one of a user's group. Inherited=Inherited +UserWillBe=Created user will be UserWillBeInternalUser=Created user will be an internal user (because not linked to a particular third party) UserWillBeExternalUser=Created user will be an external user (because linked to a particular third party) IdPhoneCaller=Id phone caller diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index e2c4b605dcc..9ecd00ca36f 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -375,7 +375,7 @@ if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && !empty($conf->gl // Check all cases that need a token (all POST actions, all actions and mass actions on pages with CSRFCHECK_WITH_TOKEN set, all sensitive GET actions) if ($_SERVER['REQUEST_METHOD'] == 'POST' || ((GETPOSTISSET('action') || GETPOSTISSET('massaction')) && defined('CSRFCHECK_WITH_TOKEN')) || - in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deleteprof', 'deletepayment'))) + in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deleteprof', 'deletepayment', 'confirm_create_user', 'confirm_create_thirdparty'))) { if (!GETPOSTISSET('token')) { if (GETPOST('uploadform', 'int')) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index ac1aa5b8f98..fee36c3ff1b 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2358,11 +2358,12 @@ class Societe extends CommonObject $code .= $this->code_fournisseur.' - '; } - if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) - { - $name = $code.' '.$name; - } else { - $name = $code; + if ($code) { + if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) { + $name = $code.' '.$name; + } else { + $name = $code; + } } } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index c82eafb353a..1649032fc8d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1318,7 +1318,8 @@ class User extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Create a user into database from a member object + * Create a user into database from a member object. + * If $member->fk_soc is set, it will be an external user. * * @param Adherent $member Object member source * @param string $login Login to force