From 7fd1051efc87a6171ea096ef6178b3a5700a6eda Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 16 Apr 2019 10:16:20 +0200 Subject: [PATCH 1/7] FIX missing compatibility with multicompany transverse mode Conflicts: htdocs/core/class/html.formother.class.php --- htdocs/core/class/html.formother.class.php | 46 ++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 991a92ec445..a35a73546bb 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -372,9 +372,10 @@ class FormOther * @param string $morecss More CSS * @return string Html combo list code */ - function select_salesrepresentatives($selected,$htmlname,$user,$showstatus=0,$showempty=1,$morecss='') + function select_salesrepresentatives($selected, $htmlname, $user, $showstatus=0, $showempty=1, $morecss='') { - global $conf,$langs; + // phpcs:enable + global $conf, $langs; $langs->load('users'); $out = ''; @@ -396,17 +397,48 @@ class FormOther // Get list of users allowed to be viewed $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login"; $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")"; + + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) + { + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { + $sql_usr.= " WHERE u.entity IS NOT NULL"; // Show all users + } else { + $sql_usr.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql_usr.= " WHERE ((ug.fk_user = u.rowid"; + $sql_usr.= " AND ug.entity IN (".getEntity('user')."))"; + $sql_usr.= " OR u.entity = 0)"; // Show always superadmin + } + } + else + { + $sql_usr.= " WHERE u.entity IN (".getEntity('user').")"; + } + if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id; - if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id; + if (! empty($user->socid)) $sql_usr.=" AND u.fk_soc = ".$user->socid; // Add existing sales representatives of thirdparty of external user - if (empty($user->rights->user->user->lire) && $user->societe_id) + if (empty($user->rights->user->user->lire) && $user->socid) { $sql_usr.=" UNION "; $sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login"; $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")"; - $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id; + + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) + { + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { + $sql_usr.= " WHERE u2.entity IS NOT NULL"; // Show all users + } else { + $sql_usr.= ",".MAIN_DB_PREFIX."usergroup_user as ug2"; + $sql_usr.= " WHERE ug2.fk_user = u2.rowid"; + $sql_usr.= " AND ug2.entity IN (".getEntity('user').")"; + } + } + else + { + $sql_usr.= " WHERE u2.entity IN (".getEntity('user').")"; + } + + $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->socid; } $sql_usr.= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION. //print $sql_usr;exit; From 5726b40a10e66789efda7804d3610d18fad89466 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 10 May 2019 12:07:15 +0200 Subject: [PATCH 2/7] FIX try to use WHERE EXISTS instead DISTINCT --- htdocs/core/class/html.formother.class.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index a35a73546bb..b3d41d80ffb 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -395,7 +395,7 @@ class FormOther if ($showempty) $out.=''; // Get list of users allowed to be viewed - $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login"; + $sql_usr = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.statut, u.login"; $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u"; if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) @@ -428,9 +428,7 @@ class FormOther if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { $sql_usr.= " WHERE u2.entity IS NOT NULL"; // Show all users } else { - $sql_usr.= ",".MAIN_DB_PREFIX."usergroup_user as ug2"; - $sql_usr.= " WHERE ug2.fk_user = u2.rowid"; - $sql_usr.= " AND ug2.entity IN (".getEntity('user').")"; + $sql_usr.= " WHERE EXISTS (SELECT ug2.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('user').") )"; } } else From 25031e534dacd664bdbb69ba2da2001f266a2352 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Wed, 12 Jun 2019 12:05:02 +0200 Subject: [PATCH 3/7] fix massaction presend --- htdocs/core/actions_massactions.inc.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 064acb0b1c6..bb8b03d9366 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -260,6 +260,11 @@ if (! $error && $massaction == 'confirm_presend') $filename=dol_sanitizeFileName($objectobj->ref).'.pdf'; $filedir=$uploaddir . '/' . dol_sanitizeFileName($objectobj->ref); $file = $filedir . '/' . $filename; + if ($object->element == 'invoice_supplier') + { + $fileparams = dol_most_recent_file($uploaddir . '/' . get_exdir($objectobj->id,2,0,0,$objectobj,$objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,'/').'([^\-])+'); + $file = $fileparams['fullname']; + } $mime = dol_mimetype($file); if (dol_is_file($file)) From 9ba102b6b93239599626fe8c60cf0569ad12bcb5 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Wed, 12 Jun 2019 12:08:16 +0200 Subject: [PATCH 4/7] bad object used --- htdocs/core/actions_massactions.inc.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index bb8b03d9366..2d0750bbefe 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -260,11 +260,13 @@ if (! $error && $massaction == 'confirm_presend') $filename=dol_sanitizeFileName($objectobj->ref).'.pdf'; $filedir=$uploaddir . '/' . dol_sanitizeFileName($objectobj->ref); $file = $filedir . '/' . $filename; - if ($object->element == 'invoice_supplier') + + if ($objectobj->element == 'invoice_supplier') { $fileparams = dol_most_recent_file($uploaddir . '/' . get_exdir($objectobj->id,2,0,0,$objectobj,$objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,'/').'([^\-])+'); $file = $fileparams['fullname']; } + $mime = dol_mimetype($file); if (dol_is_file($file)) From 47746fd17d77bb61c965130c325922daa30a01e3 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Wed, 12 Jun 2019 12:30:49 +0200 Subject: [PATCH 5/7] fix template type --- htdocs/core/class/html.formmail.class.php | 1 + htdocs/fourn/facture/list.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index e8693af943a..ac742f0dbb7 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -359,6 +359,7 @@ class FormMail extends Form if ($this->param['models'] != 'none') { $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); + if ($result < 0) { setEventMessages($this->error, $this->errors, 'errors'); diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 4b208a99af7..c14c037dc97 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -496,7 +496,7 @@ if ($resql) print_barre_liste($langs->trans("BillsSuppliers").($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit); $topicmail="SendBillRef"; - $modelmail="supplier_invoice_send"; + $modelmail="invoice_supplier_send"; $objecttmp=new FactureFournisseur($db); $trackid='sinv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; From 0bf7512f288411d3e3e982c5522bab6606e920e8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 12 Jun 2019 12:33:31 +0200 Subject: [PATCH 6/7] Update actions_massactions.inc.php --- htdocs/core/actions_massactions.inc.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 2d0750bbefe..34ba465ebff 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -257,10 +257,14 @@ if (! $error && $massaction == 'confirm_presend') { // TODO Use future field $objectobj->fullpathdoc to know where is stored default file // TODO If not defined, use $objectobj->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc. - $filename=dol_sanitizeFileName($objectobj->ref).'.pdf'; - $filedir=$uploaddir . '/' . dol_sanitizeFileName($objectobj->ref); + $filename = dol_sanitizeFileName($objectobj->ref).'.pdf'; + $subdir = ''; + // TODO Set subdir to be compatible with multi levels dir trees + // $subdir = get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element) + $filedir = $uploaddir . '/' . $subdir . dol_sanitizeFileName($objectobj->ref); $file = $filedir . '/' . $filename; + // For supplier invoices, we use the file provided by supplier, not the one we generate if ($objectobj->element == 'invoice_supplier') { $fileparams = dol_most_recent_file($uploaddir . '/' . get_exdir($objectobj->id,2,0,0,$objectobj,$objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,'/').'([^\-])+'); From 4cbfb67d63b10f6ac189c809ba6c95c1fbff62ae Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 13 Jun 2019 09:59:10 +0200 Subject: [PATCH 7/7] Update html.formother.class.php --- htdocs/core/class/html.formother.class.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index b3d41d80ffb..6cf3c816a24 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -374,7 +374,6 @@ class FormOther */ function select_salesrepresentatives($selected, $htmlname, $user, $showstatus=0, $showempty=1, $morecss='') { - // phpcs:enable global $conf, $langs; $langs->load('users'); @@ -395,7 +394,7 @@ class FormOther if ($showempty) $out.=''; // Get list of users allowed to be viewed - $sql_usr = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.statut, u.login"; + $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login"; $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u"; if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) @@ -403,10 +402,9 @@ class FormOther if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { $sql_usr.= " WHERE u.entity IS NOT NULL"; // Show all users } else { - $sql_usr.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; - $sql_usr.= " WHERE ((ug.fk_user = u.rowid"; - $sql_usr.= " AND ug.entity IN (".getEntity('user')."))"; - $sql_usr.= " OR u.entity = 0)"; // Show always superadmin + $sql_usr.= ", + $sql_usr.= " WHERE EXISTS (SELECT ug.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (".getEntity('user')."))"; + $sql_usr.= " OR u.entity = 0"; // Show always superadmin } } else @@ -428,7 +426,7 @@ class FormOther if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { $sql_usr.= " WHERE u2.entity IS NOT NULL"; // Show all users } else { - $sql_usr.= " WHERE EXISTS (SELECT ug2.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('user').") )"; + $sql_usr.= " WHERE EXISTS (SELECT ug2.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('user')."))"; } } else