diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 71c3f98420a..882717e5e02 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -267,11 +267,22 @@ if (! $error && $massaction == 'confirm_presend') if ($_POST['addmaindocfile']) { - // 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); - $file = $filedir . '/' . $filename; + // 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'; + $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,'/').'([^\-])+'); + $file = $fileparams['fullname']; + } + $mime = dol_mimetype($file); if (dol_is_file($file)) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index d455d1058fc..b5908e9bb08 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -394,6 +394,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/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index ccb6edeb2ee..1883ffd0304 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -326,7 +326,7 @@ class FormOther * @param int $showempty Add also an empty line * @param string $morecss More CSS * @return string Html combo list code - * @see select_all_categories + * @see select_all_categories() */ function select_categories($type, $selected=0, $htmlname='search_categ', $nocateg=0, $showempty=1, $morecss='') { @@ -389,10 +389,11 @@ 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='') { // phpcs:enable - global $conf,$langs; + global $conf, $langs; + $langs->load('users'); $out = ''; @@ -414,17 +415,44 @@ 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.= " 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 + { + $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.= " 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 + { + $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; diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 4f46cc8d496..fe3f80d76e7 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -508,7 +508,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';