html.formcompany.class.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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 ".MAIN_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 ".MAIN_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 ".MAIN_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" 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 ".MAIN_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" 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 .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_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 ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_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 ".MAIN_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 ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_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, $langs;
  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 ".MAIN_DB_PREFIX."societe as s";
  635. if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
  636. $sql .= " LEFT JOIN ".MAIN_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. $sql .= " ORDER BY s.nom ASC";
  644. $resql = $this->db->query($sql);
  645. if ($resql) {
  646. print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"';
  647. if ($conf->use_javascript_ajax) {
  648. $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;";
  649. print ' onChange="'.$javaScript.'"';
  650. }
  651. print '>';
  652. print '<option value="-1">&nbsp;</option>';
  653. $num = $this->db->num_rows($resql);
  654. $i = 0;
  655. if ($num) {
  656. while ($i < $num) {
  657. $obj = $this->db->fetch_object($resql);
  658. if ($i == 0) {
  659. $firstCompany = $obj->rowid;
  660. }
  661. $disabled = 0;
  662. if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
  663. $disabled = 1;
  664. }
  665. if ($selected > 0 && $selected == $obj->rowid) {
  666. print '<option value="'.$obj->rowid.'"';
  667. if ($disabled) {
  668. print ' disabled';
  669. }
  670. print ' selected>'.dol_trunc($obj->name, 24).'</option>';
  671. $firstCompany = $obj->rowid;
  672. } else {
  673. print '<option value="'.$obj->rowid.'"';
  674. if ($disabled) {
  675. print ' disabled';
  676. }
  677. print '>'.dol_trunc($obj->name, 24).'</option>';
  678. }
  679. $i++;
  680. }
  681. }
  682. print "</select>\n";
  683. print ajax_combobox($htmlname);
  684. return $firstCompany;
  685. } else {
  686. dol_print_error($this->db);
  687. return 0;
  688. }
  689. }
  690. }
  691. /**
  692. * Return a select list with types of contacts
  693. *
  694. * @param object $object Object to use to find type of contact
  695. * @param string $selected Default selected value
  696. * @param string $htmlname HTML select name
  697. * @param string $source Source ('internal' or 'external')
  698. * @param string $sortorder Sort criteria ('position', 'code', ...)
  699. * @param int $showempty 1=Add en empty line
  700. * @param string $morecss Add more css to select component
  701. * @param int $output 0=return HTML, 1= direct print
  702. * @param int $forcehidetooltip Force hide tooltip for admin
  703. * @return string|void Depending on $output param, return the HTML select list (recommended method) or nothing
  704. */
  705. public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1, $forcehidetooltip = 0)
  706. {
  707. global $user, $langs;
  708. $out = '';
  709. if (is_object($object) && method_exists($object, 'liste_type_contact')) {
  710. $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
  711. $out .= '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  712. if ($showempty) {
  713. $out .= '<option value="0">&nbsp;</option>';
  714. }
  715. foreach ($lesTypes as $key => $value) {
  716. $out .= '<option value="'.$key.'"';
  717. if ($key == $selected) {
  718. $out .= ' selected';
  719. }
  720. $out .= '>'.$value.'</option>';
  721. }
  722. $out .= "</select>";
  723. if ($user->admin && empty($forcehidetooltip)) {
  724. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  725. }
  726. $out .= ajax_combobox($htmlname);
  727. $out .= "\n";
  728. }
  729. if (empty($output)) {
  730. return $out;
  731. } else {
  732. print $out;
  733. }
  734. }
  735. /**
  736. * showContactRoles on view and edit mode
  737. *
  738. * @param string $htmlname Html component name and id
  739. * @param Contact $contact Contact Obejct
  740. * @param string $rendermode view, edit
  741. * @param array $selected $key=>$val $val is selected Roles for input mode
  742. * @return string String with contacts roles
  743. */
  744. public function showRoles($htmlname, Contact $contact, $rendermode = 'view', $selected = array())
  745. {
  746. if ($rendermode === 'view') {
  747. $toprint = array();
  748. foreach ($contact->roles as $key => $val) {
  749. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb;">'.$val['label'].'</li>';
  750. }
  751. return '<div class="select2-container-multi-dolibarr" style="width: 90%;" id="'.$htmlname.'"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
  752. }
  753. if ($rendermode === 'edit') {
  754. $contactType = $contact->listeTypeContacts('external', '', 1, '', '', 'agenda'); // We exclude agenda as there is no contact on such element
  755. if (count($selected) > 0) {
  756. $newselected = array();
  757. foreach ($selected as $key => $val) {
  758. if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) {
  759. $newselected[] = $val['id'];
  760. } else {
  761. break;
  762. }
  763. }
  764. if (count($newselected) > 0) {
  765. $selected = $newselected;
  766. }
  767. }
  768. return $this->multiselectarray($htmlname, $contactType, $selected, 0, 0, 'minwidth500');
  769. }
  770. return 'ErrorBadValueForParameterRenderMode'; // Should not happened
  771. }
  772. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  773. /**
  774. * Return a select list with zip codes and their town
  775. *
  776. * @param string $selected Preselected value
  777. * @param string $htmlname HTML select name
  778. * @param array $fields Array with key of fields to refresh after selection
  779. * @param int $fieldsize Field size
  780. * @param int $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs)
  781. * @param string $moreattrib Add more attribute on HTML input field
  782. * @param string $morecss More css
  783. * @return string
  784. */
  785. public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
  786. {
  787. // phpcs:enable
  788. global $conf;
  789. $out = '';
  790. $size = '';
  791. if (!empty($fieldsize)) {
  792. $size = 'size="'.$fieldsize.'"';
  793. }
  794. if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
  795. $out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
  796. $moreattrib .= ' autocomplete="off"';
  797. }
  798. $out .= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" type="text"'.($moreattrib ? ' '.$moreattrib : '').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
  799. return $out;
  800. }
  801. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  802. /**
  803. * Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
  804. *
  805. * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
  806. * @param string $htmlname Name of HTML select
  807. * @param string $preselected Default value to show
  808. * @param string $country_code FR, IT, ...
  809. * @param string $morecss More css
  810. * @return string HTML string with prof id
  811. */
  812. public function get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss = 'maxwidth100onsmartphone quatrevingtpercent')
  813. {
  814. // phpcs:enable
  815. global $conf, $langs, $hookmanager;
  816. $formlength = 0;
  817. if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
  818. if ($country_code == 'FR') {
  819. if (isset($idprof)) {
  820. if ($idprof == 1) {
  821. $formlength = 9;
  822. } elseif ($idprof == 2) {
  823. $formlength = 14;
  824. } elseif ($idprof == 3) {
  825. $formlength = 5; // 4 chiffres et 1 lettre depuis janvier
  826. } elseif ($idprof == 4) {
  827. $formlength = 32; // No maximum as we need to include a town name in this id
  828. }
  829. }
  830. } elseif ($country_code == 'ES') {
  831. if ($idprof == 1) {
  832. $formlength = 9; //CIF/NIF/NIE 9 digits
  833. }
  834. if ($idprof == 2) {
  835. $formlength = 12; //NASS 12 digits without /
  836. }
  837. if ($idprof == 3) {
  838. $formlength = 5; //CNAE 5 digits
  839. }
  840. if ($idprof == 4) {
  841. $formlength = 32; //depend of college
  842. }
  843. }
  844. }
  845. $selected = $preselected;
  846. if (!$selected && isset($idprof)) {
  847. if ($idprof == 1 && !empty($this->idprof1)) {
  848. $selected = $this->idprof1;
  849. } elseif ($idprof == 2 && !empty($this->idprof2)) {
  850. $selected = $this->idprof2;
  851. } elseif ($idprof == 3 && !empty($this->idprof3)) {
  852. $selected = $this->idprof3;
  853. } elseif ($idprof == 4 && !empty($this->idprof4)) {
  854. $selected = $this->idprof4;
  855. }
  856. }
  857. $maxlength = $formlength;
  858. if (empty($formlength)) {
  859. $formlength = 24;
  860. $maxlength = 128;
  861. }
  862. $out = '';
  863. // Execute hook getInputIdProf to complete or replace $out
  864. $parameters = array('formlength'=>$formlength, 'selected'=>$preselected, 'idprof'=>$idprof, 'htmlname'=>$htmlname, 'country_code'=>$country_code);
  865. $reshook = $hookmanager->executeHooks('getInputIdProf', $parameters);
  866. if (empty($reshook)) {
  867. $out .= '<input type="text" '.($morecss ? 'class="'.$morecss.'" ' : '').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
  868. }
  869. $out .= $hookmanager->resPrint;
  870. return $out;
  871. }
  872. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  873. /**
  874. * Return a HTML select with localtax values for thirdparties
  875. *
  876. * @param int $local LocalTax
  877. * @param int $selected Preselected value
  878. * @param string $htmlname HTML select name
  879. * @return void
  880. */
  881. public function select_localtax($local, $selected, $htmlname)
  882. {
  883. // phpcs:enable
  884. $tax = get_localtax_by_third($local);
  885. if ($tax) {
  886. $valors = explode(":", $tax);
  887. $nbvalues = count($valors);
  888. if ($nbvalues > 1) {
  889. //montar select
  890. print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  891. $i = 0;
  892. while ($i < $nbvalues) {
  893. if ($selected == $valors[$i]) {
  894. print '<option value="'.$valors[$i].'" selected>';
  895. } else {
  896. print '<option value="'.$valors[$i].'">';
  897. }
  898. print $valors[$i];
  899. print '</option>';
  900. $i++;
  901. }
  902. print '</select>';
  903. }
  904. }
  905. }
  906. /**
  907. * Return a HTML select for thirdparty type
  908. *
  909. * @param int $selected Selected value
  910. * @param string $htmlname HTML select name
  911. * @param string $htmlidname HTML select id
  912. * @param string $typeinput HTML output
  913. * @param string $morecss More css
  914. * @param string $allowempty Allow empty value or not
  915. * @return string HTML string
  916. */
  917. public function selectProspectCustomerType($selected, $htmlname = 'client', $htmlidname = 'customerprospect', $typeinput = 'form', $morecss = '', $allowempty = '')
  918. {
  919. global $conf, $langs;
  920. if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->fournisseur->enabled)) {
  921. return '' ;
  922. }
  923. $out = '<select class="flat '.$morecss.'" name="'.$htmlname.'" id="'.$htmlidname.'">';
  924. if ($typeinput == 'form') {
  925. if ($allowempty || ($selected == '' || $selected == '-1')) {
  926. $out .= '<option value="-1">';
  927. if (is_numeric($allowempty)) {
  928. $out .= '&nbsp;';
  929. } else {
  930. $out .= $langs->trans($allowempty);
  931. }
  932. $out .= '</option>';
  933. }
  934. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  935. $out .= '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
  936. }
  937. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
  938. $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
  939. }
  940. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  941. $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  942. }
  943. $out .= '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
  944. } elseif ($typeinput == 'list') {
  945. $out .= '<option value="-1"'.(($selected == '' || $selected == '-1') ? ' selected' : '').'>&nbsp;</option>';
  946. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  947. $out .= '<option value="2,3"'.($selected == '2,3' ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
  948. }
  949. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  950. $out .= '<option value="1,3"'.($selected == '1,3' ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  951. }
  952. if (!empty($conf->fournisseur->enabled)) {
  953. $out .= '<option value="4"'.($selected == '4' ? ' selected' : '').'>'.$langs->trans('Supplier').'</option>';
  954. }
  955. $out .= '<option value="0"'.($selected == '0' ? ' selected' : '').'>'.$langs->trans('Other').'</option>';
  956. } elseif ($typeinput == 'admin') {
  957. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
  958. $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
  959. }
  960. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  961. $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  962. }
  963. }
  964. $out .= '</select>';
  965. $out .= ajax_combobox($htmlidname);
  966. return $out;
  967. }
  968. /**
  969. * Output html select to select third-party type
  970. *
  971. * @param string $page Page
  972. * @param string $selected Id preselected
  973. * @param string $htmlname Name of HTML select
  974. * @param string $filter optional filters criteras
  975. * @param int $nooutput No print output. Return it only.
  976. * @return void|string
  977. */
  978. public function formThirdpartyType($page, $selected = '', $htmlname = 'socid', $filter = '', $nooutput = 0)
  979. {
  980. // phpcs:enable
  981. global $conf, $langs;
  982. $out = '';
  983. if ($htmlname != "none") {
  984. $out .= '<form method="post" action="'.$page.'">';
  985. $out .= '<input type="hidden" name="action" value="set_thirdpartytype">';
  986. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  987. $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.
  988. $out .= $this->selectarray($htmlname, $this->typent_array(0, $filter), $selected, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
  989. $out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
  990. $out .= '</form>';
  991. } else {
  992. if ($selected > 0) {
  993. $arr = $this->typent_array(0);
  994. $typent = $arr[$selected];
  995. $out .= $typent;
  996. } else {
  997. $out .= "&nbsp;";
  998. }
  999. }
  1000. if ($nooutput) {
  1001. return $out;
  1002. } else {
  1003. print $out;
  1004. }
  1005. }
  1006. }