';
diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php
index d352b996ef2..991e3cb37cc 100644
--- a/htdocs/core/class/html.formother.class.php
+++ b/htdocs/core/class/html.formother.class.php
@@ -110,7 +110,7 @@ class FormOther
* @param string $htmlname Nom de la zone select
* @param string $type Type des modeles recherches
* @param int $useempty Show an empty value in list
- * @param int $fk_user User that has created the template (this is set to null to get all export model when EXPORTS_SHARE_MODELS is on)
+ * @param int $fk_user User we want templates
* @return void
*/
public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
@@ -121,8 +121,8 @@ class FormOther
$sql = "SELECT rowid, label, fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."export_model";
$sql .= " WHERE type = '".$this->db->escape($type)."'";
- if (!empty($fk_user)) {
- $sql .= " AND fk_user IN (0, ".$fk_user.")"; // An export model
+ if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
+ $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
}
$sql .= " ORDER BY label";
$result = $this->db->query($sql);
@@ -132,6 +132,8 @@ class FormOther
print '';
}
+ $tmpuser = new User($this->db);
+
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num) {
@@ -140,8 +142,7 @@ class FormOther
$label = $obj->label;
if ($obj->fk_user == 0) {
$label .= ' ('.$langs->trans("Everybody").')';
- } elseif (!empty($conf->global->EXPORTS_SHARE_MODELS) && empty($fk_user) && is_object($user) && $user->id != $obj->fk_user) {
- $tmpuser = new User($this->db);
+ } elseif ($obj->fk_user > 0) {
$tmpuser->fetch($obj->fk_user);
$label .= ' ('.$tmpuser->getFullName($langs).')';
}
@@ -171,7 +172,7 @@ class FormOther
* @param string $htmlname Nom de la zone select
* @param string $type Type des modeles recherches
* @param int $useempty Affiche valeur vide dans liste
- * @param int $fk_user User that has created the template (this is set to null to get all export model when EXPORTS_SHARE_MODELS is on)
+ * @param int $fk_user User that has created the template
* @return void
*/
public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
@@ -182,10 +183,10 @@ class FormOther
$sql = "SELECT rowid, label, fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."import_model";
$sql .= " WHERE type = '".$this->db->escape($type)."'";
- if (!empty($fk_user)) {
- $sql .= " AND fk_user IN (0, ".$fk_user.")"; // An export model
+ if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
+ $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
}
- $sql .= " ORDER BY rowid";
+ $sql .= " ORDER BY label";
$result = $this->db->query($sql);
if ($result) {
print '