html.formcompany.class.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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 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 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. * @return string String with HTML select
  236. * @see select_country()
  237. */
  238. public function select_state($selected = 0, $country_codeid = 0, $htmlname = 'state_id')
  239. {
  240. // phpcs:enable
  241. global $conf, $langs, $user;
  242. dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid, LOG_DEBUG);
  243. $langs->load("dict");
  244. $out = '';
  245. // Serch departements/cantons/province active d'une region et pays actif
  246. $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";
  247. $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
  248. $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
  249. $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
  250. if ($country_codeid && is_numeric($country_codeid)) {
  251. $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
  252. }
  253. if ($country_codeid && !is_numeric($country_codeid)) {
  254. $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
  255. }
  256. $sql .= " ORDER BY c.code, d.code_departement";
  257. $result = $this->db->query($sql);
  258. if ($result) {
  259. if (!empty($htmlname)) {
  260. $out .= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
  261. }
  262. if ($country_codeid) {
  263. $out .= '<option value="0">&nbsp;</option>';
  264. }
  265. $num = $this->db->num_rows($result);
  266. $i = 0;
  267. dol_syslog(get_class($this)."::select_departement num=".$num, LOG_DEBUG);
  268. if ($num) {
  269. $country = '';
  270. while ($i < $num) {
  271. $obj = $this->db->fetch_object($result);
  272. if ($obj->code == '0') { // Le code peut etre une chaine
  273. $out .= '<option value="0">&nbsp;</option>';
  274. } else {
  275. if (!$country || $country != $obj->country) {
  276. // Show break if we are in list with multiple countries
  277. if (!$country_codeid && $obj->country_code) {
  278. $out .= '<option value="-1" disabled data-html="----- '.$obj->country.' -----">----- '.$obj->country." -----</option>\n";
  279. $country = $obj->country;
  280. }
  281. }
  282. if (!empty($selected) && $selected == $obj->rowid) {
  283. $out .= '<option value="'.$obj->rowid.'" selected>';
  284. } else {
  285. $out .= '<option value="'.$obj->rowid.'">';
  286. }
  287. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  288. if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
  289. ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
  290. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
  291. $out .= $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  292. } else {
  293. $out .= $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  294. }
  295. } else {
  296. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
  297. $out .= $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  298. } else {
  299. $out .= ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
  300. }
  301. }
  302. $out .= '</option>';
  303. }
  304. $i++;
  305. }
  306. }
  307. if (!empty($htmlname)) {
  308. $out .= '</select>';
  309. }
  310. if (!empty($htmlname) && $user->admin) {
  311. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  312. }
  313. } else {
  314. dol_print_error($this->db);
  315. }
  316. // Make select dynamic
  317. if (!empty($htmlname)) {
  318. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  319. $out .= ajax_combobox($htmlname);
  320. }
  321. return $out;
  322. }
  323. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  324. /**
  325. * Retourne la liste deroulante des regions actives dont le pays est actif
  326. * La cle de la liste est le code (il peut y avoir plusieurs entree pour
  327. * un code donnee mais dans ce cas, le champ pays et lang differe).
  328. * Ainsi les liens avec les regions se font sur une region independemment de son name.
  329. *
  330. * @param string $selected Preselected value
  331. * @param string $htmlname Name of HTML select field
  332. * @return void
  333. */
  334. public function select_region($selected = '', $htmlname = 'region_id')
  335. {
  336. // phpcs:enable
  337. global $conf, $langs;
  338. $langs->load("dict");
  339. $sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
  340. $sql .= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
  341. $sql .= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
  342. $sql .= " ORDER BY c.code, c.label ASC";
  343. dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
  344. $resql = $this->db->query($sql);
  345. if ($resql) {
  346. print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
  347. $num = $this->db->num_rows($resql);
  348. $i = 0;
  349. if ($num) {
  350. $country = '';
  351. while ($i < $num) {
  352. $obj = $this->db->fetch_object($resql);
  353. if ($obj->code == 0) {
  354. print '<option value="0">&nbsp;</option>';
  355. } else {
  356. if ($country == '' || $country != $obj->country) {
  357. // Show break
  358. $key = $langs->trans("Country".strtoupper($obj->country_code));
  359. $valuetoshow = ($key != "Country".strtoupper($obj->country_code)) ? $obj->country_code." - ".$key : $obj->country;
  360. print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
  361. $country = $obj->country;
  362. }
  363. if ($selected > 0 && $selected == $obj->code) {
  364. print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
  365. } else {
  366. print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
  367. }
  368. }
  369. $i++;
  370. }
  371. }
  372. print '</select>';
  373. print ajax_combobox($htmlname);
  374. } else {
  375. dol_print_error($this->db);
  376. }
  377. }
  378. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  379. /**
  380. * Return combo list with people title
  381. *
  382. * @param string $selected Civility/Title code preselected
  383. * @param string $htmlname Name of HTML select combo field
  384. * @param string $morecss Add more css on SELECT element
  385. * @param int $addjscombo Add js combo
  386. * @return string String with HTML select
  387. */
  388. public function select_civility($selected = '', $htmlname = 'civility_id', $morecss = 'maxwidth150', $addjscombo = 1)
  389. {
  390. // phpcs:enable
  391. global $conf, $langs, $user;
  392. $langs->load("dict");
  393. $out = '';
  394. $sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
  395. $sql .= " WHERE active = 1";
  396. dol_syslog("Form::select_civility", LOG_DEBUG);
  397. $resql = $this->db->query($sql);
  398. if ($resql) {
  399. $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  400. $out .= '<option value="">&nbsp;</option>';
  401. $num = $this->db->num_rows($resql);
  402. $i = 0;
  403. if ($num) {
  404. while ($i < $num) {
  405. $obj = $this->db->fetch_object($resql);
  406. if ($selected == $obj->code) {
  407. $out .= '<option value="'.$obj->code.'" selected>';
  408. } else {
  409. $out .= '<option value="'.$obj->code.'">';
  410. }
  411. // If translation exists, we use it, otherwise, we use tha had coded label
  412. $out .= ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
  413. $out .= '</option>';
  414. $i++;
  415. }
  416. }
  417. $out .= '</select>';
  418. if ($user->admin) {
  419. $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  420. }
  421. if ($addjscombo) {
  422. // Enhance with select2
  423. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  424. $out .= ajax_combobox($htmlname);
  425. }
  426. } else {
  427. dol_print_error($this->db);
  428. }
  429. return $out;
  430. }
  431. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  432. /**
  433. * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
  434. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays.
  435. *
  436. * @param string $selected Code forme juridique a pre-selectionne
  437. * @param mixed $country_codeid 0=liste tous pays confondus, sinon code du pays a afficher
  438. * @param string $filter Add a SQL filter on list
  439. * @return void
  440. * @deprecated Use print xxx->select_juridicalstatus instead
  441. * @see select_juridicalstatus()
  442. */
  443. public function select_forme_juridique($selected = '', $country_codeid = 0, $filter = '')
  444. {
  445. // phpcs:enable
  446. print $this->select_juridicalstatus($selected, $country_codeid, $filter);
  447. }
  448. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  449. /**
  450. * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
  451. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays
  452. *
  453. * @param string $selected Preselected code of juridical type
  454. * @param int $country_codeid 0=list for all countries, otherwise list only country requested
  455. * @param string $filter Add a SQL filter on list. Data must not come from user input.
  456. * @param string $htmlname HTML name of select
  457. * @param string $morecss More CSS
  458. * @return string String with HTML select
  459. */
  460. public function select_juridicalstatus($selected = '', $country_codeid = 0, $filter = '', $htmlname = 'forme_juridique_code', $morecss = '')
  461. {
  462. // phpcs:enable
  463. global $conf, $langs, $user;
  464. $langs->load("dict");
  465. $out = '';
  466. // On recherche les formes juridiques actives des pays actifs
  467. $sql = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
  468. $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
  469. $sql .= " WHERE f.fk_pays=c.rowid";
  470. $sql .= " AND f.active = 1 AND c.active = 1";
  471. if ($country_codeid) {
  472. $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
  473. }
  474. if ($filter) {
  475. $sql .= " ".$filter;
  476. }
  477. $sql .= " ORDER BY c.code";
  478. dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
  479. $resql = $this->db->query($sql);
  480. if ($resql) {
  481. $out .= '<div id="particulier2" class="visible">';
  482. $out .= '<select class="flat minwidth200'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  483. if ($country_codeid) {
  484. $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.
  485. }
  486. $num = $this->db->num_rows($resql);
  487. if ($num) {
  488. $i = 0;
  489. $country = '';
  490. $arraydata = array();
  491. while ($i < $num) {
  492. $obj = $this->db->fetch_object($resql);
  493. if ($obj->code) { // We exclude empty line, we will add it later
  494. $labelcountry = (($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
  495. $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)
  496. $arraydata[$obj->code] = array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
  497. }
  498. $i++;
  499. }
  500. $arraydata = dol_sort_array($arraydata, 'label_sort', 'ASC');
  501. if (empty($country_codeid)) { // Introduce empty value (if $country_codeid not empty, empty value was already added)
  502. $arraydata[0] = array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
  503. }
  504. foreach ($arraydata as $key => $val) {
  505. if (!$country || $country != $val['country']) {
  506. // Show break when we are in multi country mode
  507. if (empty($country_codeid) && $val['country_code']) {
  508. $out .= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
  509. $country = $val['country'];
  510. }
  511. }
  512. if ($selected > 0 && $selected == $val['code']) {
  513. $out .= '<option value="'.$val['code'].'" selected>';
  514. } else {
  515. $out .= '<option value="'.$val['code'].'">';
  516. }
  517. // If translation exists, we use it, otherwise we use default label in database
  518. $out .= $val['label'];
  519. $out .= '</option>';
  520. }
  521. }
  522. $out .= '</select>';
  523. if ($user->admin) {
  524. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  525. }
  526. // Make select dynamic
  527. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  528. $out .= ajax_combobox($htmlname);
  529. $out .= '</div>';
  530. } else {
  531. dol_print_error($this->db);
  532. }
  533. return $out;
  534. }
  535. /**
  536. * Output list of third parties.
  537. *
  538. * @param object $object Object we try to find contacts
  539. * @param string $var_id Name of id field
  540. * @param string $selected Pre-selected third party
  541. * @param string $htmlname Name of HTML form
  542. * @param array $limitto Disable answers that are not id in this array list
  543. * @param int $forceid This is to force another object id than object->id
  544. * @param string $moreparam String with more param to add into url when noajax search is used.
  545. * @param string $morecss More CSS on select component
  546. * @return int The selected third party ID
  547. */
  548. public function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany', $limitto = '', $forceid = 0, $moreparam = '', $morecss = '')
  549. {
  550. global $conf, $langs;
  551. if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
  552. // Use Ajax search
  553. $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT) ? $conf->global->COMPANY_USE_SEARCH_TO_SELECT : 2);
  554. $socid = 0;
  555. $name = '';
  556. if ($selected > 0) {
  557. $tmpthirdparty = new Societe($this->db);
  558. $result = $tmpthirdparty->fetch($selected);
  559. if ($result > 0) {
  560. $socid = $selected;
  561. $name = $tmpthirdparty->name;
  562. }
  563. }
  564. $events = array();
  565. // Add an entry 'method' to say 'yes, we must execute url with param action = method';
  566. // Add an entry 'url' to say which url to execute
  567. // Add an entry htmlname to say which element we must change once url is called
  568. // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines
  569. // To refresh contacts list on thirdparty list change
  570. $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
  571. if (count($events)) { // If there is some ajax events to run once selection is done, we add code here to run events
  572. print '<script type="text/javascript">
  573. jQuery(document).ready(function() {
  574. $("#search_'.$htmlname.'").change(function() {
  575. var obj = '.json_encode($events).';
  576. $.each(obj, function(key,values) {
  577. if (values.method.length) {
  578. runJsCodeForEvent'.$htmlname.'(values);
  579. }
  580. });
  581. $(this).trigger("blur");
  582. });
  583. // Function used to execute events when search_htmlname change
  584. function runJsCodeForEvent'.$htmlname.'(obj) {
  585. var id = $("#'.$htmlname.'").val();
  586. var method = obj.method;
  587. var url = obj.url;
  588. var htmlname = obj.htmlname;
  589. var showempty = obj.showempty;
  590. console.log("Run runJsCodeForEvent-'.$htmlname.' from selectCompaniesForNewContact id="+id+" method="+method+" showempty="+showempty+" url="+url+" htmlname="+htmlname);
  591. $.getJSON(url,
  592. {
  593. action: method,
  594. id: id,
  595. htmlname: htmlname
  596. },
  597. function(response) {
  598. if (response != null)
  599. {
  600. console.log("Change select#"+htmlname+" with content "+response.value)
  601. $.each(obj.params, function(key,action) {
  602. if (key.length) {
  603. var num = response.num;
  604. if (num > 0) {
  605. $("#" + key).removeAttr(action);
  606. } else {
  607. $("#" + key).attr(action, action);
  608. }
  609. }
  610. });
  611. $("select#" + htmlname).html(response.value);
  612. }
  613. }
  614. );
  615. };
  616. });
  617. </script>';
  618. }
  619. print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
  620. print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
  621. print ajax_autocompleter(($socid ? $socid : -1), $htmlname, DOL_URL_ROOT.'/societe/ajax/ajaxcompanies.php', '', $minLength, 0);
  622. return $socid;
  623. } else {
  624. // Search to list thirdparties
  625. $sql = "SELECT s.rowid, s.nom as name FROM";
  626. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  627. $sql .= " WHERE s.entity IN (".getEntity('societe').")";
  628. // For ajax search we limit here. For combo list, we limit later
  629. if (is_array($limitto) && count($limitto)) {
  630. $sql .= " AND s.rowid IN (".$this->db->sanitize(join(',', $limitto)).")";
  631. }
  632. $sql .= " ORDER BY s.nom ASC";
  633. $resql = $this->db->query($sql);
  634. if ($resql) {
  635. print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"';
  636. if ($conf->use_javascript_ajax) {
  637. $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;";
  638. print ' onChange="'.$javaScript.'"';
  639. }
  640. print '>';
  641. $num = $this->db->num_rows($resql);
  642. $i = 0;
  643. if ($num) {
  644. while ($i < $num) {
  645. $obj = $this->db->fetch_object($resql);
  646. if ($i == 0) {
  647. $firstCompany = $obj->rowid;
  648. }
  649. $disabled = 0;
  650. if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
  651. $disabled = 1;
  652. }
  653. if ($selected > 0 && $selected == $obj->rowid) {
  654. print '<option value="'.$obj->rowid.'"';
  655. if ($disabled) {
  656. print ' disabled';
  657. }
  658. print ' selected>'.dol_trunc($obj->name, 24).'</option>';
  659. $firstCompany = $obj->rowid;
  660. } else {
  661. print '<option value="'.$obj->rowid.'"';
  662. if ($disabled) {
  663. print ' disabled';
  664. }
  665. print '>'.dol_trunc($obj->name, 24).'</option>';
  666. }
  667. $i++;
  668. }
  669. }
  670. print "</select>\n";
  671. print ajax_combobox($htmlname);
  672. return $firstCompany;
  673. } else {
  674. dol_print_error($this->db);
  675. return 0;
  676. }
  677. }
  678. }
  679. /**
  680. * Return a select list with types of contacts
  681. *
  682. * @param object $object Object to use to find type of contact
  683. * @param string $selected Default selected value
  684. * @param string $htmlname HTML select name
  685. * @param string $source Source ('internal' or 'external')
  686. * @param string $sortorder Sort criteria ('position', 'code', ...)
  687. * @param int $showempty 1=Add en empty line
  688. * @param string $morecss Add more css to select component
  689. * @param int $output 0=return HTML, 1= direct print
  690. * @param int $forcehidetooltip Force hide tooltip for admin
  691. * @return void
  692. */
  693. public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1, $forcehidetooltip = 0)
  694. {
  695. global $user, $langs;
  696. $out = '';
  697. if (is_object($object) && method_exists($object, 'liste_type_contact')) {
  698. $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
  699. $out .= '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  700. if ($showempty) {
  701. $out .= '<option value="0"></option>';
  702. }
  703. foreach ($lesTypes as $key => $value) {
  704. $out .= '<option value="'.$key.'"';
  705. if ($key == $selected) {
  706. $out .= ' selected';
  707. }
  708. $out .= '>'.$value.'</option>';
  709. }
  710. $out .= "</select>";
  711. if ($user->admin && empty($forcehidetooltip)) {
  712. $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  713. }
  714. $out .= ajax_combobox($htmlname);
  715. $out .= "\n";
  716. }
  717. if (empty($output)) {
  718. return $out;
  719. } else {
  720. print $out;
  721. }
  722. }
  723. /**
  724. * showContactRoles on view and edit mode
  725. *
  726. * @param string $htmlname Html component name and id
  727. * @param Contact $contact Contact Obejct
  728. * @param string $rendermode view, edit
  729. * @param array $selected $key=>$val $val is selected Roles for input mode
  730. * @return string String with contacts roles
  731. */
  732. public function showRoles($htmlname, Contact $contact, $rendermode = 'view', $selected = array())
  733. {
  734. if ($rendermode === 'view') {
  735. $toprint = array();
  736. foreach ($contact->roles as $key => $val) {
  737. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb;">'.$val['label'].'</li>';
  738. }
  739. return '<div class="select2-container-multi-dolibarr" style="width: 90%;" id="'.$htmlname.'"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
  740. }
  741. if ($rendermode === 'edit') {
  742. $contactType = $contact->listeTypeContacts('external', '', 1, '', '', 'agenda'); // We exclude agenda as there is no contact on such element
  743. if (count($selected) > 0) {
  744. $newselected = array();
  745. foreach ($selected as $key => $val) {
  746. if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) {
  747. $newselected[] = $val['id'];
  748. } else {
  749. break;
  750. }
  751. }
  752. if (count($newselected) > 0) {
  753. $selected = $newselected;
  754. }
  755. }
  756. return $this->multiselectarray($htmlname, $contactType, $selected, 0, 0, 'minwidth500');
  757. }
  758. return 'ErrorBadValueForParameterRenderMode'; // Should not happened
  759. }
  760. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  761. /**
  762. * Return a select list with zip codes and their town
  763. *
  764. * @param string $selected Preselected value
  765. * @param string $htmlname HTML select name
  766. * @param array $fields Array with key of fields to refresh after selection
  767. * @param int $fieldsize Field size
  768. * @param int $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs)
  769. * @param string $moreattrib Add more attribute on HTML input field
  770. * @param string $morecss More css
  771. * @return string
  772. */
  773. public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
  774. {
  775. // phpcs:enable
  776. global $conf;
  777. $out = '';
  778. $size = '';
  779. if (!empty($fieldsize)) {
  780. $size = 'size="'.$fieldsize.'"';
  781. }
  782. if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
  783. $out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
  784. $moreattrib .= ' autocomplete="off"';
  785. }
  786. $out .= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" type="text"'.($moreattrib ? ' '.$moreattrib : '').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
  787. return $out;
  788. }
  789. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  790. /**
  791. * Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
  792. *
  793. * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
  794. * @param string $htmlname Name of HTML select
  795. * @param string $preselected Default value to show
  796. * @param string $country_code FR, IT, ...
  797. * @param string $morecss More css
  798. * @return string HTML string with prof id
  799. */
  800. public function get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss = 'maxwidth100onsmartphone quatrevingtpercent')
  801. {
  802. // phpcs:enable
  803. global $conf, $langs, $hookmanager;
  804. $formlength = 0;
  805. if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
  806. if ($country_code == 'FR') {
  807. if (isset($idprof)) {
  808. if ($idprof == 1) {
  809. $formlength = 9;
  810. } elseif ($idprof == 2) {
  811. $formlength = 14;
  812. } elseif ($idprof == 3) {
  813. $formlength = 5; // 4 chiffres et 1 lettre depuis janvier
  814. } elseif ($idprof == 4) {
  815. $formlength = 32; // No maximum as we need to include a town name in this id
  816. }
  817. }
  818. } elseif ($country_code == 'ES') {
  819. if ($idprof == 1) {
  820. $formlength = 9; //CIF/NIF/NIE 9 digits
  821. }
  822. if ($idprof == 2) {
  823. $formlength = 12; //NASS 12 digits without /
  824. }
  825. if ($idprof == 3) {
  826. $formlength = 5; //CNAE 5 digits
  827. }
  828. if ($idprof == 4) {
  829. $formlength = 32; //depend of college
  830. }
  831. }
  832. }
  833. $selected = $preselected;
  834. if (!$selected && isset($idprof)) {
  835. if ($idprof == 1 && !empty($this->idprof1)) {
  836. $selected = $this->idprof1;
  837. } elseif ($idprof == 2 && !empty($this->idprof2)) {
  838. $selected = $this->idprof2;
  839. } elseif ($idprof == 3 && !empty($this->idprof3)) {
  840. $selected = $this->idprof3;
  841. } elseif ($idprof == 4 && !empty($this->idprof4)) {
  842. $selected = $this->idprof4;
  843. }
  844. }
  845. $maxlength = $formlength;
  846. if (empty($formlength)) {
  847. $formlength = 24;
  848. $maxlength = 128;
  849. }
  850. $out = '';
  851. // Execute hook getInputIdProf to complete or replace $out
  852. $parameters = array('formlength'=>$formlength, 'selected'=>$preselected, 'idprof'=>$idprof, 'htmlname'=>$htmlname, 'country_code'=>$country_code);
  853. $reshook = $hookmanager->executeHooks('getInputIdProf', $parameters);
  854. if (empty($reshook)) {
  855. $out .= '<input type="text" '.($morecss ? 'class="'.$morecss.'" ' : '').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
  856. }
  857. $out .= $hookmanager->resPrint;
  858. return $out;
  859. }
  860. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  861. /**
  862. * Return a HTML select with localtax values for thirdparties
  863. *
  864. * @param int $local LocalTax
  865. * @param int $selected Preselected value
  866. * @param string $htmlname HTML select name
  867. * @return void
  868. */
  869. public function select_localtax($local, $selected, $htmlname)
  870. {
  871. // phpcs:enable
  872. $tax = get_localtax_by_third($local);
  873. $num = $this->db->num_rows($tax);
  874. $i = 0;
  875. if ($num) {
  876. $valors = explode(":", $tax);
  877. if (count($valors) > 1) {
  878. //montar select
  879. print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  880. while ($i <= (count($valors)) - 1) {
  881. if ($selected == $valors[$i]) {
  882. print '<option value="'.$valors[$i].'" selected>';
  883. } else {
  884. print '<option value="'.$valors[$i].'">';
  885. }
  886. print $valors[$i];
  887. print '</option>';
  888. $i++;
  889. }
  890. print'</select>';
  891. }
  892. }
  893. }
  894. /**
  895. * Return a HTML select for thirdparty type
  896. *
  897. * @param int $selected selected value
  898. * @param string $htmlname HTML select name
  899. * @param string $htmlidname HTML select id
  900. * @param string $typeinput HTML output
  901. * @param string $morecss More css
  902. * @return string HTML string
  903. */
  904. public function selectProspectCustomerType($selected, $htmlname = 'client', $htmlidname = 'customerprospect', $typeinput = 'form', $morecss = '')
  905. {
  906. global $conf, $langs;
  907. if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->fournisseur->enabled)) {
  908. return '' ;
  909. }
  910. $out = '<select class="flat '.$morecss.'" name="'.$htmlname.'" id="'.$htmlidname.'">';
  911. if ($typeinput == 'form') {
  912. if ($selected == '' || $selected == '-1') {
  913. $out .= '<option value="-1">&nbsp;</option>';
  914. }
  915. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  916. $out .= '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
  917. }
  918. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
  919. $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
  920. }
  921. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  922. $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  923. }
  924. $out .= '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
  925. } elseif ($typeinput == 'list') {
  926. $out .= '<option value="-1"'.(($selected == '' || $selected == '-1') ? ' selected' : '').'>&nbsp;</option>';
  927. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
  928. $out .= '<option value="2,3"'.($selected == '2,3' ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
  929. }
  930. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  931. $out .= '<option value="1,3"'.($selected == '1,3' ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  932. }
  933. if (!empty($conf->fournisseur->enabled)) {
  934. $out .= '<option value="4"'.($selected == '4' ? ' selected' : '').'>'.$langs->trans('Supplier').'</option>';
  935. }
  936. $out .= '<option value="0"'.($selected == '0' ? ' selected' : '').'>'.$langs->trans('Other').'</option>';
  937. } elseif ($typeinput == 'admin') {
  938. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
  939. $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
  940. }
  941. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  942. $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
  943. }
  944. }
  945. $out .= '</select>';
  946. $out .= ajax_combobox($htmlidname);
  947. return $out;
  948. }
  949. /**
  950. * Output html select to select third-party type
  951. *
  952. * @param string $page Page
  953. * @param string $selected Id preselected
  954. * @param string $htmlname Name of HTML select
  955. * @param string $filter optional filters criteras
  956. * @param int $nooutput No print output. Return it only.
  957. * @return void|string
  958. */
  959. public function formThirdpartyType($page, $selected = '', $htmlname = 'socid', $filter = '', $nooutput = 0)
  960. {
  961. // phpcs:enable
  962. global $conf, $langs;
  963. $out = '';
  964. if ($htmlname != "none") {
  965. $out .= '<form method="post" action="'.$page.'">';
  966. $out .= '<input type="hidden" name="action" value="set_thirdpartytype">';
  967. $out .= '<input type="hidden" name="token" value="'.newToken().'">';
  968. $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.
  969. $out .= $this->selectarray($htmlname, $this->typent_array(0, $filter), $selected, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
  970. $out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
  971. $out .= '</form>';
  972. } else {
  973. if ($selected > 0) {
  974. $arr = $this->typent_array(0);
  975. $typent = $arr[$selected];
  976. $out .= $typent;
  977. } else {
  978. $out .= "&nbsp;";
  979. }
  980. }
  981. if ($nooutput) {
  982. return $out;
  983. } else {
  984. print $out;
  985. }
  986. }
  987. }