html.formcompany.class.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. <?php
  2. /* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
  6. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/class/html.formcompany.class.php
  23. * \ingroup core
  24. * \brief File of class to build HTML component for third parties management
  25. */
  26. /**
  27. * Class to build HTML component for third parties management
  28. * Only common components are here.
  29. */
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  31. /**
  32. * Class of forms component to manage companies
  33. */
  34. class FormCompany extends Form
  35. {
  36. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  37. /**
  38. * Return list of labels (translated) of third parties type
  39. *
  40. * @param int $mode 0=Return id+label, 1=Return code+label
  41. * @param string $filter Add a SQL filter to select. Data must not come from user input.
  42. * @return array Array of types
  43. */
  44. public function typent_array($mode = 0, $filter = '')
  45. {
  46. // phpcs:enable
  47. global $langs, $mysoc;
  48. $effs = array();
  49. $sql = "SELECT id, code, libelle";
  50. $sql .= " FROM ".$this->db->prefix()."c_typent";
  51. $sql .= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id) ? '0' : $mysoc->country_id).")";
  52. if ($filter) {
  53. $sql .= " ".$filter;
  54. }
  55. $sql .= " ORDER by position, id";
  56. dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
  57. $resql = $this->db->query($sql);
  58. if ($resql) {
  59. $num = $this->db->num_rows($resql);
  60. $i = 0;
  61. while ($i < $num) {
  62. $objp = $this->db->fetch_object($resql);
  63. if (!$mode) {
  64. $key = $objp->id;
  65. } else {
  66. $key = $objp->code;
  67. }
  68. if ($langs->trans($objp->code) != $objp->code) {
  69. $effs[$key] = $langs->trans($objp->code);
  70. } else {
  71. $effs[$key] = $objp->libelle;
  72. }
  73. if ($effs[$key] == '-') {
  74. $effs[$key] = '';
  75. }
  76. $i++;
  77. }
  78. $this->db->free($resql);
  79. }
  80. return $effs;
  81. }
  82. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  83. /**
  84. * Renvoie la liste des types d'effectifs possibles (pas de traduction car nombre)
  85. *
  86. * @param int $mode 0=renvoi id+libelle, 1=renvoi code+libelle
  87. * @param string $filter Add a SQL filter to select. Data must not come from user input.
  88. * @return array Array of types d'effectifs
  89. */
  90. public function effectif_array($mode = 0, $filter = '')
  91. {
  92. // phpcs:enable
  93. $effs = array();
  94. $sql = "SELECT id, code, libelle";
  95. $sql .= " FROM ".$this->db->prefix()."c_effectif";
  96. $sql .= " WHERE active = 1";
  97. if ($filter) {
  98. $sql .= " ".$filter;
  99. }
  100. $sql .= " ORDER BY id ASC";
  101. dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
  102. $resql = $this->db->query($sql);
  103. if ($resql) {
  104. $num = $this->db->num_rows($resql);
  105. $i = 0;
  106. while ($i < $num) {
  107. $objp = $this->db->fetch_object($resql);
  108. if (!$mode) {
  109. $key = $objp->id;
  110. } else {
  111. $key = $objp->code;
  112. }
  113. $effs[$key] = $objp->libelle != '-' ? $objp->libelle : '';
  114. $i++;
  115. }
  116. $this->db->free($resql);
  117. }
  118. return $effs;
  119. }
  120. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  121. /**
  122. * Affiche formulaire de selection des modes de reglement
  123. *
  124. * @param int $page Page
  125. * @param int $selected Id or code preselected
  126. * @param string $htmlname Nom du formulaire select
  127. * @param int $empty Add empty value in list
  128. * @return void
  129. */
  130. public function form_prospect_level($page, $selected = '', $htmlname = 'prospect_level_id', $empty = 0)
  131. {
  132. // phpcs:enable
  133. global $user, $langs;
  134. print '<form method="post" action="'.$page.'">';
  135. print '<input type="hidden" name="action" value="setprospectlevel">';
  136. print '<input type="hidden" name="token" value="'.newToken().'">';
  137. dol_syslog(get_class($this).'::form_prospect_level', LOG_DEBUG);
  138. $sql = "SELECT code, label";
  139. $sql .= " FROM ".$this->db->prefix()."c_prospectlevel";
  140. $sql .= " WHERE active > 0";
  141. $sql .= " ORDER BY sortorder";
  142. $resql = $this->db->query($sql);
  143. if ($resql) {
  144. $options = array();
  145. if ($empty) {
  146. $options[''] = '';
  147. }
  148. while ($obj = $this->db->fetch_object($resql)) {
  149. $level = $langs->trans($obj->code);
  150. if ($level == $obj->code) {
  151. $level = $langs->trans($obj->label);
  152. }
  153. $options[$obj->code] = $level;
  154. }
  155. print Form::selectarray($htmlname, $options, $selected);
  156. } else {
  157. dol_print_error($this->db);
  158. }
  159. if (!empty($htmlname) && $user->admin) {
  160. print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  161. }
  162. print '<input type="submit" class="button button-save valignmiddle small" value="'.$langs->trans("Modify").'">';
  163. print '</form>';
  164. }
  165. /**
  166. * Affiche formulaire de selection des niveau de prospection pour les contacts
  167. *
  168. * @param int $page Page
  169. * @param int $selected Id or code preselected
  170. * @param string $htmlname Nom du formulaire select
  171. * @param int $empty Add empty value in list
  172. * @return void
  173. */
  174. public function formProspectContactLevel($page, $selected = '', $htmlname = 'prospect_contact_level_id', $empty = 0)
  175. {
  176. global $user, $langs;
  177. print '<form method="post" action="'.$page.'">';
  178. print '<input type="hidden" name="action" value="setprospectcontactlevel">';
  179. print '<input type="hidden" name="token" value="'.newToken().'">';
  180. dol_syslog(__METHOD__, LOG_DEBUG);
  181. $sql = "SELECT code, label";
  182. $sql .= " FROM ".$this->db->prefix()."c_prospectcontactlevel";
  183. $sql .= " WHERE active > 0";
  184. $sql .= " ORDER BY sortorder";
  185. $resql = $this->db->query($sql);
  186. if ($resql) {
  187. $options = array();
  188. if ($empty) {
  189. $options[''] = '';
  190. }
  191. while ($obj = $this->db->fetch_object($resql)) {
  192. $level = $langs->trans($obj->code);
  193. if ($level == $obj->code) {
  194. $level = $langs->trans($obj->label);
  195. }
  196. $options[$obj->code] = $level;
  197. }
  198. print Form::selectarray($htmlname, $options, $selected);
  199. } else {
  200. dol_print_error($this->db);
  201. }
  202. if (!empty($htmlname) && $user->admin) {
  203. print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  204. }
  205. print '<input type="submit" class="button button-save valignmiddle small" value="'.$langs->trans("Modify").'">';
  206. print '</form>';
  207. }
  208. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  209. /**
  210. * Returns the drop-down list of departments/provinces/cantons for all countries or for a given country.
  211. * In the case of an all-country list, the display breaks on the country.
  212. * The key of the list is the code (there can be several entries for a given code but in this case, the country field differs).
  213. * Thus the links with the departments are done on a department independently of its name.
  214. *
  215. * @param string $selected Code state preselected
  216. * @param int $country_codeid 0=list for all countries, otherwise country code or country rowid to show
  217. * @param string $htmlname Id of department
  218. * @return void
  219. */
  220. public function select_departement($selected = '', $country_codeid = 0, $htmlname = 'state_id')
  221. {
  222. // phpcs:enable
  223. print $this->select_state($selected, $country_codeid, $htmlname);
  224. }
  225. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  226. /**
  227. * Returns the drop-down list of departments/provinces/cantons for all countries or for a given country.
  228. * In the case of an all-country list, the display breaks on the country.
  229. * The key of the list is the code (there can be several entries for a given code but in this case, the country field differs).
  230. * Thus the links with the departments are done on a department independently of its name.
  231. *
  232. * @param int $selected Code state preselected (mus be state id)
  233. * @param integer $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show
  234. * @param string $htmlname Id of department. If '', we want only the string with <option>
  235. * @param string $morecss Add more css
  236. * @return string String with HTML select
  237. * @see select_country()
  238. */
  239. public function select_state($selected = 0, $country_codeid = 0, $htmlname = 'state_id', $morecss = 'maxwidth200onsmartphone minwidth300')
  240. {
  241. // phpcs:enable
  242. global $conf, $langs, $user;
  243. dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid, LOG_DEBUG);
  244. $langs->load("dict");
  245. $out = '';
  246. // Serch departements/cantons/province active d'une region et pays actif
  247. $sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
  248. $sql .= " ".$this->db->prefix()."c_departements as d, ".$this->db->prefix()."c_regions as r,".$this->db->prefix()."c_country as c";
  249. $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
  250. $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
  251. if ($country_codeid && is_numeric($country_codeid)) {
  252. $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
  253. }
  254. if ($country_codeid && !is_numeric($country_codeid)) {
  255. $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
  256. }
  257. $sql .= " ORDER BY c.code, d.code_departement";
  258. $result = $this->db->query($sql);
  259. if ($result) {
  260. if (!empty($htmlname)) {
  261. $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
  262. }
  263. if ($country_codeid) {
  264. $out .= '<option value="0">&nbsp;</option>';
  265. }
  266. $num = $this->db->num_rows($result);
  267. $i = 0;
  268. dol_syslog(get_class($this)."::select_departement num=".$num, LOG_DEBUG);
  269. if ($num) {
  270. $country = '';
  271. while ($i < $num) {
  272. $obj = $this->db->fetch_object($result);
  273. if ($obj->code == '0') { // Le code peut etre une chaine
  274. $out .= '<option value="0">&nbsp;</option>';
  275. } else {
  276. if (!$country || $country != $obj->country) {
  277. // Show break if we are in list with multiple countries
  278. if (!$country_codeid && $obj->country_code) {
  279. $out .= '<option value="-1" disabled data-html="----- '.$obj->country.' -----">----- '.$obj->country." -----</option>\n";
  280. $country = $obj->country;
  281. }
  282. }
  283. if (!empty($selected) && $selected == $obj->rowid) {
  284. $out .= '<option value="'.$obj->rowid.'" selected>';
  285. } else {
  286. $out .= '<option value="'.$obj->rowid.'">';
  287. }
  288. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  289. if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
  290. ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
  291. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
  292. $out .= $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  293. } else {
  294. $out .= $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  295. }
  296. } else {
  297. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
  298. $out .= $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  299. } else {
  300. $out .= ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  301. }
  302. }
  303. $out .= '</option>';
  304. }
  305. $i++;
  306. }
  307. }
  308. if (!empty($htmlname)) {
  309. $out .= '</select>';
  310. }
  311. if (!empty($htmlname) && $user->admin) {
  312. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  313. }
  314. } else {
  315. dol_print_error($this->db);
  316. }
  317. // Make select dynamic
  318. if (!empty($htmlname)) {
  319. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  320. $out .= ajax_combobox($htmlname);
  321. }
  322. return $out;
  323. }
  324. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  325. /**
  326. * Retourne la liste deroulante des regions actives dont le pays est actif
  327. * La cle de la liste est le code (il peut y avoir plusieurs entree pour
  328. * un code donnee mais dans ce cas, le champ pays et lang differe).
  329. * Ainsi les liens avec les regions se font sur une region independemment de son name.
  330. *
  331. * @param string $selected Preselected value
  332. * @param string $htmlname Name of HTML select field
  333. * @return void
  334. */
  335. public function select_region($selected = '', $htmlname = 'region_id')
  336. {
  337. // phpcs:enable
  338. global $conf, $langs;
  339. $langs->load("dict");
  340. $sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
  341. $sql .= " FROM ".$this->db->prefix()."c_regions as r, ".$this->db->prefix()."c_country as c";
  342. $sql .= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
  343. $sql .= " ORDER BY c.code, c.label ASC";
  344. dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
  345. $resql = $this->db->query($sql);
  346. if ($resql) {
  347. print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
  348. $num = $this->db->num_rows($resql);
  349. $i = 0;
  350. if ($num) {
  351. $country = '';
  352. while ($i < $num) {
  353. $obj = $this->db->fetch_object($resql);
  354. if ($obj->code == 0) {
  355. print '<option value="0">&nbsp;</option>';
  356. } else {
  357. if ($country == '' || $country != $obj->country) {
  358. // Show break
  359. $key = $langs->trans("Country".strtoupper($obj->country_code));
  360. $valuetoshow = ($key != "Country".strtoupper($obj->country_code)) ? $obj->country_code." - ".$key : $obj->country;
  361. print '<option value="-2" disabled>----- '.$valuetoshow." -----</option>\n";
  362. $country = $obj->country;
  363. }
  364. if ($selected > 0 && $selected == $obj->code) {
  365. print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
  366. } else {
  367. print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
  368. }
  369. }
  370. $i++;
  371. }
  372. }
  373. print '</select>';
  374. print ajax_combobox($htmlname);
  375. } else {
  376. dol_print_error($this->db);
  377. }
  378. }
  379. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  380. /**
  381. * Return combo list with people title
  382. *
  383. * @param string $selected Civility/Title code preselected
  384. * @param string $htmlname Name of HTML select combo field
  385. * @param string $morecss Add more css on SELECT element
  386. * @param int $addjscombo Add js combo
  387. * @return string String with HTML select
  388. */
  389. public function select_civility($selected = '', $htmlname = 'civility_id', $morecss = 'maxwidth150', $addjscombo = 1)
  390. {
  391. // phpcs:enable
  392. global $conf, $langs, $user;
  393. $langs->load("dict");
  394. $out = '';
  395. $sql = "SELECT rowid, code, label, active FROM ".$this->db->prefix()."c_civility";
  396. $sql .= " WHERE active = 1";
  397. dol_syslog("Form::select_civility", LOG_DEBUG);
  398. $resql = $this->db->query($sql);
  399. if ($resql) {
  400. $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  401. $out .= '<option value="">&nbsp;</option>';
  402. $num = $this->db->num_rows($resql);
  403. $i = 0;
  404. if ($num) {
  405. while ($i < $num) {
  406. $obj = $this->db->fetch_object($resql);
  407. if ($selected == $obj->code) {
  408. $out .= '<option value="'.$obj->code.'" selected>';
  409. } else {
  410. $out .= '<option value="'.$obj->code.'">';
  411. }
  412. // If translation exists, we use it, otherwise, we use tha had coded label
  413. $out .= ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
  414. $out .= '</option>';
  415. $i++;
  416. }
  417. }
  418. $out .= '</select>';
  419. if ($user->admin) {
  420. $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  421. }
  422. if ($addjscombo) {
  423. // Enhance with select2
  424. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  425. $out .= ajax_combobox($htmlname);
  426. }
  427. } else {
  428. dol_print_error($this->db);
  429. }
  430. return $out;
  431. }
  432. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  433. /**
  434. * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
  435. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays.
  436. *
  437. * @param string $selected Code forme juridique a pre-selectionne
  438. * @param mixed $country_codeid 0=liste tous pays confondus, sinon code du pays a afficher
  439. * @param string $filter Add a SQL filter on list
  440. * @return void
  441. * @deprecated Use print xxx->select_juridicalstatus instead
  442. * @see select_juridicalstatus()
  443. */
  444. public function select_forme_juridique($selected = '', $country_codeid = 0, $filter = '')
  445. {
  446. // phpcs:enable
  447. print $this->select_juridicalstatus($selected, $country_codeid, $filter);
  448. }
  449. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  450. /**
  451. * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
  452. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays
  453. *
  454. * @param string $selected Preselected code of juridical type
  455. * @param int $country_codeid 0=list for all countries, otherwise list only country requested
  456. * @param string $filter Add a SQL filter on list. Data must not come from user input.
  457. * @param string $htmlname HTML name of select
  458. * @param string $morecss More CSS
  459. * @return string String with HTML select
  460. */
  461. public function select_juridicalstatus($selected = '', $country_codeid = 0, $filter = '', $htmlname = 'forme_juridique_code', $morecss = '')
  462. {
  463. // phpcs:enable
  464. global $conf, $langs, $user;
  465. $langs->load("dict");
  466. $out = '';
  467. // On recherche les formes juridiques actives des pays actifs
  468. $sql = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
  469. $sql .= " FROM ".$this->db->prefix()."c_forme_juridique as f, ".$this->db->prefix()."c_country as c";
  470. $sql .= " WHERE f.fk_pays=c.rowid";
  471. $sql .= " AND f.active = 1 AND c.active = 1";
  472. if ($country_codeid) {
  473. $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
  474. }
  475. if ($filter) {
  476. $sql .= " ".$filter;
  477. }
  478. $sql .= " ORDER BY c.code";
  479. dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
  480. $resql = $this->db->query($sql);
  481. if ($resql) {
  482. $out .= '<div id="particulier2" class="visible">';
  483. $out .= '<select class="flat minwidth200'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  484. if ($country_codeid) {
  485. $out .= '<option value="0">&nbsp;</option>'; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
  486. }
  487. $num = $this->db->num_rows($resql);
  488. if ($num) {
  489. $i = 0;
  490. $country = '';
  491. $arraydata = array();
  492. while ($i < $num) {
  493. $obj = $this->db->fetch_object($resql);
  494. if ($obj->code) { // We exclude empty line, we will add it later
  495. $labelcountry = (($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
  496. $labeljs = (($langs->trans("JuridicalStatus".$obj->code) != "JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label != '-' ? $obj->label : '')); // $obj->label is already in output charset (converted by database driver)
  497. $arraydata[$obj->code] = array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
  498. }
  499. $i++;
  500. }
  501. $arraydata = dol_sort_array($arraydata, 'label_sort', 'ASC');
  502. if (empty($country_codeid)) { // Introduce empty value (if $country_codeid not empty, empty value was already added)
  503. $arraydata[0] = array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
  504. }
  505. foreach ($arraydata as $key => $val) {
  506. if (!$country || $country != $val['country']) {
  507. // Show break when we are in multi country mode
  508. if (empty($country_codeid) && $val['country_code']) {
  509. $out .= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
  510. $country = $val['country'];
  511. }
  512. }
  513. if ($selected > 0 && $selected == $val['code']) {
  514. $out .= '<option value="'.$val['code'].'" selected>';
  515. } else {
  516. $out .= '<option value="'.$val['code'].'">';
  517. }
  518. // If translation exists, we use it, otherwise we use default label in database
  519. $out .= $val['label'];
  520. $out .= '</option>';
  521. }
  522. }
  523. $out .= '</select>';
  524. if ($user->admin) {
  525. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  526. }
  527. // Make select dynamic
  528. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  529. $out .= ajax_combobox($htmlname);
  530. $out .= '</div>';
  531. } else {
  532. dol_print_error($this->db);
  533. }
  534. return $out;
  535. }
  536. /**
  537. * Output list of third parties.
  538. *
  539. * @param object $object Object we try to find contacts
  540. * @param string $var_id Name of id field
  541. * @param string $selected Pre-selected third party
  542. * @param string $htmlname Name of HTML form
  543. * @param array $limitto Disable answers that are not id in this array list
  544. * @param int $forceid This is to force another object id than object->id
  545. * @param string $moreparam String with more param to add into url when noajax search is used.
  546. * @param string $morecss More CSS on select component
  547. * @return int The selected third party ID
  548. */
  549. public function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany', $limitto = '', $forceid = 0, $moreparam = '', $morecss = '')
  550. {
  551. global $conf, $hookmanager;
  552. if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
  553. // Use Ajax search
  554. $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT) ? $conf->global->COMPANY_USE_SEARCH_TO_SELECT : 2);
  555. $socid = 0;
  556. $name = '';
  557. if ($selected > 0) {
  558. $tmpthirdparty = new Societe($this->db);
  559. $result = $tmpthirdparty->fetch($selected);
  560. if ($result > 0) {
  561. $socid = $selected;
  562. $name = $tmpthirdparty->name;
  563. }
  564. }
  565. $events = array();
  566. // Add an entry 'method' to say 'yes, we must execute url with param action = method';
  567. // Add an entry 'url' to say which url to execute
  568. // Add an entry htmlname to say which element we must change once url is called
  569. // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines
  570. // To refresh contacts list on thirdparty list change
  571. $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
  572. if (count($events)) { // If there is some ajax events to run once selection is done, we add code here to run events
  573. print '<script type="text/javascript">
  574. jQuery(document).ready(function() {
  575. $("#search_'.$htmlname.'").change(function() {
  576. var obj = '.json_encode($events).';
  577. $.each(obj, function(key,values) {
  578. if (values.method.length) {
  579. runJsCodeForEvent'.$htmlname.'(values);
  580. }
  581. });
  582. $(this).trigger("blur");
  583. });
  584. // Function used to execute events when search_htmlname change
  585. function runJsCodeForEvent'.$htmlname.'(obj) {
  586. var id = $("#'.$htmlname.'").val();
  587. var method = obj.method;
  588. var url = obj.url;
  589. var htmlname = obj.htmlname;
  590. var showempty = obj.showempty;
  591. console.log("Run runJsCodeForEvent-'.$htmlname.' from selectCompaniesForNewContact id="+id+" method="+method+" showempty="+showempty+" url="+url+" htmlname="+htmlname);
  592. $.getJSON(url,
  593. {
  594. action: method,
  595. id: id,
  596. htmlname: htmlname
  597. },
  598. function(response) {
  599. if (response != null)
  600. {
  601. console.log("Change select#"+htmlname+" with content "+response.value)
  602. $.each(obj.params, function(key,action) {
  603. if (key.length) {
  604. var num = response.num;
  605. if (num > 0) {
  606. $("#" + key).removeAttr(action);
  607. } else {
  608. $("#" + key).attr(action, action);
  609. }
  610. }
  611. });
  612. $("select#" + htmlname).html(response.value);
  613. }
  614. }
  615. );
  616. };
  617. });
  618. </script>';
  619. }
  620. print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
  621. print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
  622. print ajax_autocompleter(($socid ? $socid : -1), $htmlname, DOL_URL_ROOT.'/societe/ajax/ajaxcompanies.php', '', $minLength, 0);
  623. return $socid;
  624. } else {
  625. // Search to list thirdparties
  626. $sql = "SELECT s.rowid, s.nom as name ";
  627. if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
  628. $sql .= ", s.code_client, s.code_fournisseur";
  629. }
  630. if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
  631. $sql .= ", s.address, s.zip, s.town";
  632. $sql .= ", dictp.code as country_code";
  633. }
  634. $sql .= " FROM ".$this->db->prefix()."societe as s";
  635. if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
  636. $sql .= " LEFT JOIN ".$this->db->prefix()."c_country as dictp ON dictp.rowid = s.fk_pays";
  637. }
  638. $sql .= " WHERE s.entity IN (".getEntity('societe').")";
  639. // For ajax search we limit here. For combo list, we limit later
  640. if (is_array($limitto) && count($limitto)) {
  641. $sql .= " AND s.rowid IN (".$this->db->sanitize(join(',', $limitto)).")";
  642. }
  643. // Add where from hooks
  644. $parameters = array();
  645. $reshook = $hookmanager->executeHooks('selectCompaniesForNewContactListWhere', $parameters); // Note that $action and $object may have been modified by hook
  646. $sql .= $hookmanager->resPrint;
  647. $sql .= " ORDER BY s.nom ASC";
  648. $resql = $this->db->query($sql);
  649. if ($resql) {
  650. print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"';
  651. if ($conf->use_javascript_ajax) {
  652. $javaScript = "window.location='".dol_escape_js($_SERVER['PHP_SELF'])."?".$var_id."=".($forceid > 0 ? $forceid : $object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
  653. print ' onChange="'.$javaScript.'"';
  654. }
  655. print '>';
  656. print '<option value="-1">&nbsp;</option>';
  657. $num = $this->db->num_rows($resql);
  658. $i = 0;
  659. if ($num) {
  660. while ($i < $num) {
  661. $obj = $this->db->fetch_object($resql);
  662. if ($i == 0) {
  663. $firstCompany = $obj->rowid;
  664. }
  665. $disabled = 0;
  666. if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
  667. $disabled = 1;
  668. }
  669. if ($selected > 0 && $selected == $obj->rowid) {
  670. print '<option value="'.$obj->rowid.'"';
  671. if ($disabled) {
  672. print ' disabled';
  673. }
  674. print ' selected>'.dol_trunc($obj->name, 24).'</option>';
  675. $firstCompany = $obj->rowid;
  676. } else {
  677. print '<option value="'.$obj->rowid.'"';
  678. if ($disabled) {
  679. print ' disabled';
  680. }
  681. print '>'.dol_trunc($obj->name, 24).'</option>';
  682. }
  683. $i++;
  684. }
  685. }
  686. print "</select>\n";
  687. print ajax_combobox($htmlname);
  688. return $firstCompany;
  689. } else {
  690. dol_print_error($this->db);
  691. return 0;
  692. }
  693. }
  694. }
  695. /**
  696. * Return a select list with types of contacts
  697. *
  698. * @param object $object Object to use to find type of contact
  699. * @param string $selected Default selected value
  700. * @param string $htmlname HTML select name
  701. * @param string $source Source ('internal' or 'external')
  702. * @param string $sortorder Sort criteria ('position', 'code', ...)
  703. * @param int $showempty 1=Add en empty line
  704. * @param string $morecss Add more css to select component
  705. * @param int $output 0=return HTML, 1= direct print
  706. * @param int $forcehidetooltip Force hide tooltip for admin
  707. * @return string|void Depending on $output param, return the HTML select list (recommended method) or nothing
  708. */
  709. public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1, $forcehidetooltip = 0)
  710. {
  711. global $user, $langs;
  712. $out = '';
  713. if (is_object($object) && method_exists($object, 'liste_type_contact')) {
  714. $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
  715. $out .= '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  716. if ($showempty) {
  717. $out .= '<option value="0">&nbsp;</option>';
  718. }
  719. foreach ($lesTypes as $key => $value) {
  720. $out .= '<option value="'.$key.'"';
  721. if ($key == $selected) {
  722. $out .= ' selected';
  723. }
  724. $out .= '>'.$value.'</option>';
  725. }
  726. $out .= "</select>";
  727. if ($user->admin && empty($forcehidetooltip)) {
  728. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  729. }
  730. $out .= ajax_combobox($htmlname);
  731. $out .= "\n";
  732. }
  733. if (empty($output)) {
  734. return $out;
  735. } else {
  736. print $out;
  737. }
  738. }
  739. /**
  740. * showContactRoles on view and edit mode
  741. *
  742. * @param string $htmlname Html component name and id
  743. * @param Contact $contact Contact Obejct
  744. * @param string $rendermode view, edit
  745. * @param array $selected $key=>$val $val is selected Roles for input mode
  746. * @param string $morecss More css
  747. * @return string String with contacts roles
  748. */
  749. public function showRoles($htmlname, Contact $contact, $rendermode = 'view', $selected = array(), $morecss = 'minwidth500')
  750. {
  751. if ($rendermode === 'view') {
  752. $toprint = array();
  753. foreach ($contact->roles as $key => $val) {
  754. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb;">'.$val['label'].'</li>';
  755. }
  756. return '<div class="select2-container-multi-dolibarr" style="width: 90%;" id="'.$htmlname.'"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
  757. }
  758. if ($rendermode === 'edit') {
  759. $contactType = $contact->listeTypeContacts('external', '', 1, '', '', 'agenda'); // We exclude agenda as there is no contact on such element
  760. if (count($selected) > 0) {
  761. $newselected = array();
  762. foreach ($selected as $key => $val) {
  763. if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) {
  764. $newselected[] = $val['id'];
  765. } else {
  766. break;
  767. }
  768. }
  769. if (count($newselected) > 0) {
  770. $selected = $newselected;
  771. }
  772. }
  773. return $this->multiselectarray($htmlname, $contactType, $selected, 0, 0, $morecss);
  774. }
  775. return 'ErrorBadValueForParameterRenderMode'; // Should not happened
  776. }
  777. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  778. /**
  779. * Return a select list with zip codes and their town
  780. *
  781. * @param string $selected Preselected value
  782. * @param string $htmlname HTML select name
  783. * @param array $fields Array with key of fields to refresh after selection
  784. * @param int $fieldsize Field size
  785. * @param int $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs)
  786. * @param string $moreattrib Add more attribute on HTML input field
  787. * @param string $morecss More css
  788. * @return string
  789. */
  790. public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
  791. {
  792. // phpcs:enable
  793. global $conf;
  794. $out = '';
  795. $size = '';
  796. if (!empty($fieldsize)) {
  797. $size = 'size="'.$fieldsize.'"';
  798. }
  799. if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
  800. $out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
  801. $moreattrib .= ' autocomplete="off"';
  802. }
  803. $out .= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" type="text"'.($moreattrib ? ' '.$moreattrib : '').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
  804. return $out;
  805. }
  806. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  807. /**
  808. * Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
  809. *
  810. * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
  811. * @param string $htmlname Name of HTML select
  812. * @param string $preselected Default value to show
  813. * @param string $country_code FR, IT, ...
  814. * @param string $morecss More css
  815. * @return string HTML string with prof id
  816. */
  817. public function get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss = 'maxwidth100onsmartphone quatrevingtpercent')
  818. {
  819. // phpcs:enable
  820. global $conf, $langs, $hookmanager;
  821. $formlength = 0;
  822. if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
  823. if ($country_code == 'FR') {
  824. if (isset($idprof)) {
  825. if ($idprof == 1) {
  826. $formlength = 9;
  827. } elseif ($idprof == 2) {
  828. $formlength = 14;
  829. } elseif ($idprof == 3) {
  830. $formlength = 5; // 4 chiffres et 1 lettre depuis janvier
  831. } elseif ($idprof == 4) {
  832. $formlength = 32; // No maximum as we need to include a town name in this id
  833. }
  834. }
  835. } elseif ($country_code == 'ES') {
  836. if ($idprof == 1) {
  837. $formlength = 9; //CIF/NIF/NIE 9 digits
  838. }
  839. if ($idprof == 2) {
  840. $formlength = 12; //NASS 12 digits without /
  841. }
  842. if ($idprof == 3) {
  843. $formlength = 5; //CNAE 5 digits
  844. }
  845. if ($idprof == 4) {
  846. $formlength = 32; //depend of college
  847. }
  848. }
  849. }
  850. $selected = $preselected;
  851. if (!$selected && isset($idprof)) {
  852. if ($idprof == 1 && !empty($this->idprof1)) {
  853. $selected = $this->idprof1;
  854. } elseif ($idprof == 2 && !empty($this->idprof2)) {
  855. $selected = $this->idprof2;
  856. } elseif ($idprof == 3 && !empty($this->idprof3)) {
  857. $selected = $this->idprof3;
  858. } elseif ($idprof == 4 && !empty($this->idprof4)) {
  859. $selected = $this->idprof4;
  860. }
  861. }
  862. $maxlength = $formlength;
  863. if (empty($formlength)) {
  864. $formlength = 24;
  865. $maxlength = 128;
  866. }
  867. $out = '';
  868. // Execute hook getInputIdProf to complete or replace $out
  869. $parameters = array('formlength'=>$formlength, 'selected'=>$preselected, 'idprof'=>$idprof, 'htmlname'=>$htmlname, 'country_code'=>$country_code);
  870. $reshook = $hookmanager->executeHooks('getInputIdProf', $parameters);
  871. if (empty($reshook)) {
  872. $out .= '<input type="text" '.($morecss ? 'class="'.$morecss.'" ' : '').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
  873. }
  874. $out .= $hookmanager->resPrint;
  875. return $out;
  876. }
  877. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  878. /**
  879. * Return a HTML select with localtax values for thirdparties
  880. *
  881. * @param int $local LocalTax
  882. * @param int $selected Preselected value
  883. * @param string $htmlname HTML select name
  884. * @return void
  885. */
  886. public function select_localtax($local, $selected, $htmlname)
  887. {
  888. // phpcs:enable
  889. $tax = get_localtax_by_third($local);
  890. if ($tax) {
  891. $valors = explode(":", $tax);
  892. $nbvalues = count($valors);
  893. if ($nbvalues > 1) {
  894. //montar select
  895. print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  896. $i = 0;
  897. while ($i < $nbvalues) {
  898. if ($selected == $valors[$i]) {
  899. print '<option value="'.$valors[$i].'" selected>';
  900. } else {
  901. print '<option value="'.$valors[$i].'">';
  902. }
  903. print $valors[$i];
  904. print '</option>';
  905. $i++;
  906. }
  907. print '</select>';
  908. }
  909. }
  910. }
  911. /**
  912. * Return a HTML select for thirdparty type
  913. *
  914. * @param int $selected Selected value
  915. * @param string $htmlname HTML select name
  916. * @param string $htmlidname HTML select id
  917. * @param string $typeinput HTML output
  918. * @param string $morecss More css
  919. * @param string $allowempty Allow empty value or not
  920. * @return string HTML string
  921. */
  922. public function selectProspectCustomerType($selected, $htmlname = 'client', $htmlidname = 'customerprospect', $typeinput = 'form', $morecss = '', $allowempty = '')
  923. {
  924. global $conf, $langs;
  925. if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->fournisseur->enabled)) {
  926. return '' ;
  927. }
  928. $out = '<select class="flat '.$morecss.'" name="'.$htmlname.'" id="'.$htmlidname.'">';
  929. if ($typeinput == 'form') {
  930. if ($allowempty || ($selected == '' || $selected == '-1')) {
  931. $out .= '<option value="-1">';
  932. if (is_numeric($allowempty)) {
  933. $out .= '&nbsp;';
  934. } else {
  935. $out .= $langs->trans($allowempty);
  936. }
  937. $out .= '</option>';
  938. }
  939. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  940. $out .= '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
  941. }
  942. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
  943. $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
  944. }
  945. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  946. $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  947. }
  948. $out .= '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
  949. } elseif ($typeinput == 'list') {
  950. $out .= '<option value="-1"'.(($selected == '' || $selected == '-1') ? ' selected' : '').'>&nbsp;</option>';
  951. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  952. $out .= '<option value="2,3"'.($selected == '2,3' ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
  953. }
  954. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  955. $out .= '<option value="1,3"'.($selected == '1,3' ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  956. }
  957. if (!empty($conf->fournisseur->enabled)) {
  958. $out .= '<option value="4"'.($selected == '4' ? ' selected' : '').'>'.$langs->trans('Supplier').'</option>';
  959. }
  960. $out .= '<option value="0"'.($selected == '0' ? ' selected' : '').'>'.$langs->trans('Other').'</option>';
  961. } elseif ($typeinput == 'admin') {
  962. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
  963. $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
  964. }
  965. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  966. $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  967. }
  968. }
  969. $out .= '</select>';
  970. $out .= ajax_combobox($htmlidname);
  971. return $out;
  972. }
  973. /**
  974. * Output html select to select third-party type
  975. *
  976. * @param string $page Page
  977. * @param string $selected Id preselected
  978. * @param string $htmlname Name of HTML select
  979. * @param string $filter optional filters criteras
  980. * @param int $nooutput No print output. Return it only.
  981. * @return void|string
  982. */
  983. public function formThirdpartyType($page, $selected = '', $htmlname = 'socid', $filter = '', $nooutput = 0)
  984. {
  985. // phpcs:enable
  986. global $conf, $langs;
  987. $out = '';
  988. if ($htmlname != "none") {
  989. $out .= '<form method="post" action="'.$page.'">';
  990. $out .= '<input type="hidden" name="action" value="set_thirdpartytype">';
  991. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  992. $sortparam = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
  993. $out .= $this->selectarray($htmlname, $this->typent_array(0, $filter), $selected, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
  994. $out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
  995. $out .= '</form>';
  996. } else {
  997. if ($selected > 0) {
  998. $arr = $this->typent_array(0);
  999. $typent = $arr[$selected];
  1000. $out .= $typent;
  1001. } else {
  1002. $out .= "&nbsp;";
  1003. }
  1004. }
  1005. if ($nooutput) {
  1006. return $out;
  1007. } else {
  1008. print $out;
  1009. }
  1010. }
  1011. }