From 99fb702833340ccfb5070a5d5acdc9f535746889 Mon Sep 17 00:00:00 2001
From: wdammak <26695620+wdammak@users.noreply.github.com>
Date: Tue, 26 Feb 2019 18:42:05 +0100
Subject: [PATCH] Add Select Establishment
---
htdocs/core/class/html.form.class.php | 70 +++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 47cc9893c96..21d16f9f9ce 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3681,6 +3681,76 @@ class Form
return $num;
}
+
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
+ /**
+ * Return a HTML select list of establishment
+ *
+ * @param string $selected Id establishment pre-selected
+ * @param string $htmlname Name of select zone
+ * @param int $statut Status of searched establishment (0=open, 1=closed, 2=both)
+ * @param string $filtre To filter list
+ * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
+ * @param string $moreattrib To add more attribute on select
+ * @return int <0 if error, Num of establishment found if OK (0, 1, 2, ...)
+ */
+ function select_establishments($selected = '', $htmlname = 'entity', $statut = 0, $filtre = '', $useempty = 0, $moreattrib = '')
+ {
+ // phpcs:enable
+ global $langs, $conf;
+
+ $langs->load("admin");
+ $num = 0;
+
+ $sql = "SELECT rowid, name, fk_country, status, entity";
+ $sql.= " FROM ".MAIN_DB_PREFIX."establishment";
+ $sql.= " WHERE 1=1";
+ if ($statut != 2) $sql.= " AND status = '".$statut."'";
+ if ($filtre) $sql.=" AND ".$filtre;
+ $sql.= " ORDER BY name";
+
+ dol_syslog(get_class($this)."::select_establishment", LOG_DEBUG);
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+ if ($num)
+ {
+ print '";
+ }
+ else
+ {
+ if ($statut == 0) print ''.$langs->trans("NoActiveEstablishmentDefined").'';
+ else print ''.$langs->trans("NoEstablishmentFound").'';
+ }
+ }
+ else {
+ dol_print_error($this->db);
+ }
+ }
/**
* Display form to select bank account