PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/core/class/html.formcompany.class.php

https://github.com/asterix14/dolibarr
PHP | 677 lines | 465 code | 71 blank | 141 comment | 133 complexity | 49fcb0f992edba7f76f6dceafbe5119d MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/class/html.formcompany.class.php
  19. * \ingroup core
  20. * \brief File of class to build HTML component for third parties management
  21. */
  22. /**
  23. * \class FormCompany
  24. * \brief Class to build HTML component for third parties management
  25. * \remarks Only common components must be here.
  26. */
  27. class FormCompany
  28. {
  29. var $db;
  30. var $error;
  31. /**
  32. * \brief Constructeur
  33. * \param DB handler d'acces base de donnee
  34. */
  35. function FormCompany($DB)
  36. {
  37. $this->db = $DB;
  38. return 1;
  39. }
  40. /**
  41. * Return list of labels (translated) of third parties type
  42. * @param mode 0=Return id+label, 1=Return code+label
  43. * @param filter Add a SQL filter to select
  44. * @return array Array of types
  45. */
  46. function typent_array($mode=0, $filter='')
  47. {
  48. global $langs;
  49. $effs = array();
  50. $sql = "SELECT id, code, libelle";
  51. $sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
  52. $sql.= " WHERE active = 1";
  53. if ($filter) $sql.=" ".$filter;
  54. $sql.= " ORDER by id";
  55. dol_syslog('Form::typent_array sql='.$sql,LOG_DEBUG);
  56. $resql=$this->db->query($sql);
  57. if ($resql)
  58. {
  59. $num = $this->db->num_rows($resql);
  60. $i = 0;
  61. while ($i < $num)
  62. {
  63. $objp = $this->db->fetch_object($resql);
  64. if (! $mode) $key=$objp->id;
  65. else $key=$objp->code;
  66. if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
  67. else $effs[$key] = $objp->libelle;
  68. if ($effs[$key]=='-') $effs[$key]='';
  69. $i++;
  70. }
  71. $this->db->free($resql);
  72. }
  73. return $effs;
  74. }
  75. /**
  76. * \brief Renvoie la liste des types d'effectifs possibles (pas de traduction car nombre)
  77. * \param mode 0=renvoi id+libelle, 1=renvoi code+libelle
  78. * \return array tableau des types d'effectifs
  79. */
  80. function effectif_array($mode=0)
  81. {
  82. $effs = array();
  83. $sql = "SELECT id, code, libelle";
  84. $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
  85. $sql.= " WHERE active = 1";
  86. $sql .= " ORDER BY id ASC";
  87. dol_syslog('Form::effectif_array sql='.$sql,LOG_DEBUG);
  88. $resql=$this->db->query($sql);
  89. if ($resql)
  90. {
  91. $num = $this->db->num_rows($resql);
  92. $i = 0;
  93. while ($i < $num)
  94. {
  95. $objp = $this->db->fetch_object($resql);
  96. if (! $mode) $key=$objp->id;
  97. else $key=$objp->code;
  98. $effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
  99. $i++;
  100. }
  101. $this->db->free($resql);
  102. }
  103. return $effs;
  104. }
  105. /**
  106. * \brief Affiche formulaire de selection des modes de reglement
  107. * \param page Page
  108. * \param selected Id or code preselected
  109. * \param htmlname Nom du formulaire select
  110. * \param empty Add empty value in list
  111. */
  112. function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
  113. {
  114. global $langs;
  115. print '<form method="post" action="'.$page.'">';
  116. print '<input type="hidden" name="action" value="setprospectlevel">';
  117. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  118. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  119. print '<tr><td>';
  120. print '<select class="flat" name="'.$htmlname.'">';
  121. if ($empty) print '<option value="">&nbsp;</option>';
  122. dol_syslog('Form::form_prospect_level',LOG_DEBUG);
  123. $sql = "SELECT code, label";
  124. $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
  125. $sql.= " WHERE active > 0";
  126. $sql.= " ORDER BY sortorder";
  127. $resql = $this->db->query($sql);
  128. if ($resql)
  129. {
  130. $num = $this->db->num_rows($resql);
  131. $i = 0;
  132. while ($i < $num)
  133. {
  134. $obj = $this->db->fetch_object($resql);
  135. print '<option value="'.$obj->code.'"';
  136. if ($selected == $obj->code) print ' selected="selected"';
  137. print '>';
  138. $level=$langs->trans($obj->code);
  139. if ($level == $obj->code) $level=$langs->trans($obj->label);
  140. print $level;
  141. print '</option>';
  142. $i++;
  143. }
  144. }
  145. else dol_print_error($this->db);
  146. print '</select>';
  147. print '</td>';
  148. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  149. print '</tr></table></form>';
  150. }
  151. /**
  152. * \brief Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
  153. * \remarks Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
  154. * \remarks La cle de la liste est le code (il peut y avoir plusieurs entree pour
  155. * un code donnee mais dans ce cas, le champ pays differe).
  156. * Ainsi les liens avec les departements se font sur un departement independemment de son nom.
  157. * \param selected Code state preselected
  158. * \param pays_code 0=list for all countries, otherwise country code or country rowid to show
  159. * \param departement_id Id of department
  160. */
  161. function select_departement($selected='',$pays_code=0, $htmlname='departement_id')
  162. {
  163. print $this->select_state($selected,$pays_code, $htmlname);
  164. }
  165. /**
  166. * \brief Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
  167. * \remarks Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
  168. * \remarks La cle de la liste est le code (il peut y avoir plusieurs entree pour
  169. * un code donnee mais dans ce cas, le champ pays differe).
  170. * Ainsi les liens avec les departements se font sur un departement independemment de son nom.
  171. * \param selected Code state preselected
  172. * \param pays_code 0=list for all countries, otherwise country code or country rowid to show
  173. * \param departement_id Id of department
  174. */
  175. function select_state($selected='',$pays_code=0, $htmlname='departement_id')
  176. {
  177. global $conf,$langs,$user;
  178. dol_syslog("FormCompany::select_departement selected=$selected, pays_code=$pays_code",LOG_DEBUG);
  179. $langs->load("dict");
  180. $out='';
  181. // On recherche les departements/cantons/province active d'une region et pays actif
  182. $sql = "SELECT d.rowid, d.code_departement as code , d.nom, d.active, p.libelle as libelle_pays, p.code as code_pays FROM";
  183. $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_pays as p";
  184. $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid";
  185. $sql .= " AND d.active = 1 AND r.active = 1 AND p.active = 1";
  186. if ($pays_code && is_numeric($pays_code)) $sql .= " AND p.rowid = '".$pays_code."'";
  187. if ($pays_code && ! is_numeric($pays_code)) $sql .= " AND p.code = '".$pays_code."'";
  188. $sql .= " ORDER BY p.code, d.code_departement";
  189. dol_syslog("FormCompany::select_departement sql=".$sql);
  190. $result=$this->db->query($sql);
  191. if ($result)
  192. {
  193. if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
  194. if ($pays_code) $out.= '<option value="0">&nbsp;</option>';
  195. $num = $this->db->num_rows($result);
  196. $i = 0;
  197. dol_syslog("FormCompany::select_departement num=$num",LOG_DEBUG);
  198. if ($num)
  199. {
  200. $pays='';
  201. while ($i < $num)
  202. {
  203. $obj = $this->db->fetch_object($result);
  204. if ($obj->code == '0') // Le code peut etre une chaine
  205. {
  206. $out.= '<option value="0">&nbsp;</option>';
  207. }
  208. else {
  209. if (! $pays || $pays != $obj->libelle_pays)
  210. {
  211. // Affiche la rupture si on est en mode liste multipays
  212. if (! $pays_code && $obj->code_pays)
  213. {
  214. $out.= '<option value="-1" disabled="disabled">----- '.$obj->libelle_pays." -----</option>\n";
  215. $pays=$obj->libelle_pays;
  216. }
  217. }
  218. if ($selected > 0 && $selected == $obj->rowid)
  219. {
  220. $out.= '<option value="'.$obj->rowid.'" selected="selected">';
  221. }
  222. else
  223. {
  224. $out.= '<option value="'.$obj->rowid.'">';
  225. }
  226. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  227. $out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->nom!='-'?$obj->nom:''));
  228. $out.= '</option>';
  229. }
  230. $i++;
  231. }
  232. }
  233. $noselect.=$out;
  234. if (!empty($htmlname)) $out.= '</select>';
  235. if (!empty($htmlname) && $user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  236. }
  237. else
  238. {
  239. dol_print_error($this->db);
  240. }
  241. return $out;
  242. }
  243. /**
  244. * \brief Retourne la liste deroulante des regions actives dont le pays est actif
  245. * \remarks La cle de la liste est le code (il peut y avoir plusieurs entree pour
  246. * un code donnee mais dans ce cas, le champ pays et lang differe).
  247. * Ainsi les liens avec les regions se font sur une region independemment
  248. * de son nom.
  249. */
  250. function select_region($selected='',$htmlname='region_id')
  251. {
  252. global $conf,$langs;
  253. $langs->load("dict");
  254. $sql = "SELECT r.rowid, r.code_region as code, r.nom as libelle, r.active, p.code as pays_code, p.libelle as libelle_pays FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p";
  255. $sql .= " WHERE r.fk_pays=p.rowid AND r.active = 1 and p.active = 1 ORDER BY pays_code, libelle ASC";
  256. dol_syslog("Form::select_region sql=".$sql);
  257. $resql=$this->db->query($sql);
  258. if ($resql)
  259. {
  260. print '<select class="flat" name="'.$htmlname.'">';
  261. $num = $this->db->num_rows($resql);
  262. $i = 0;
  263. if ($num)
  264. {
  265. $pays='';
  266. while ($i < $num)
  267. {
  268. $obj = $this->db->fetch_object($resql);
  269. if ($obj->code == 0) {
  270. print '<option value="0">&nbsp;</option>';
  271. }
  272. else {
  273. if ($pays == '' || $pays != $obj->libelle_pays)
  274. {
  275. // Show break
  276. $key=$langs->trans("Country".strtoupper($obj->pays_code));
  277. $valuetoshow=($key != "Country".strtoupper($obj->pays_code))?$obj->pays_code." - ".$key:$obj->libelle_pays;
  278. print '<option value="-1" disabled="disabled">----- '.$valuetoshow." -----</option>\n";
  279. $pays=$obj->libelle_pays;
  280. }
  281. if ($selected > 0 && $selected == $obj->code)
  282. {
  283. print '<option value="'.$obj->code.'" selected="selected">'.$obj->libelle.'</option>';
  284. }
  285. else
  286. {
  287. print '<option value="'.$obj->code.'">'.$obj->libelle.'</option>';
  288. }
  289. }
  290. $i++;
  291. }
  292. }
  293. print '</select>';
  294. }
  295. else
  296. {
  297. dol_print_error($this->db);
  298. }
  299. }
  300. /**
  301. * Return combo list with people title
  302. *
  303. * @param string $selected Title preselected
  304. * @param string $htmlname Name of HTML select combo field
  305. * @return void
  306. */
  307. function select_civility($selected='',$htmlname='civilite_id')
  308. {
  309. global $conf,$langs,$user;
  310. $langs->load("dict");
  311. $out='';
  312. $sql = "SELECT rowid, code, civilite, active FROM ".MAIN_DB_PREFIX."c_civilite";
  313. $sql.= " WHERE active = 1";
  314. dol_syslog("Form::select_civility sql=".$sql);
  315. $resql=$this->db->query($sql);
  316. if ($resql)
  317. {
  318. $out.= '<select class="flat" name="'.$htmlname.'">';
  319. $out.= '<option value="">&nbsp;</option>';
  320. $num = $this->db->num_rows($resql);
  321. $i = 0;
  322. if ($num)
  323. {
  324. while ($i < $num)
  325. {
  326. $obj = $this->db->fetch_object($resql);
  327. if ($selected == $obj->code)
  328. {
  329. $out.= '<option value="'.$obj->code.'" selected="selected">';
  330. }
  331. else
  332. {
  333. $out.= '<option value="'.$obj->code.'">';
  334. }
  335. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  336. $out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite!='-'?$obj->civilite:''));
  337. $out.= '</option>';
  338. $i++;
  339. }
  340. }
  341. $out.= '</select>';
  342. if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  343. }
  344. else
  345. {
  346. dol_print_error($this->db);
  347. }
  348. return $out;
  349. }
  350. /**
  351. * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
  352. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays
  353. * @param selected Code forme juridique a pre-selectionne
  354. * @param pays_code 0=liste tous pays confondus, sinon code du pays a afficher
  355. * @param filter Add a SQL filter on list
  356. */
  357. function select_forme_juridique($selected='', $pays_code=0, $filter='')
  358. {
  359. print $this->select_juridicalstatus($selected, $pays_code, $filter);
  360. }
  361. /**
  362. * Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
  363. * Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays
  364. * @param selected Code forme juridique a pre-selectionne
  365. * @param pays_code 0=liste tous pays confondus, sinon code du pays a afficher
  366. * @param filter Add a SQL filter on list
  367. */
  368. function select_juridicalstatus($selected='', $pays_code=0, $filter='')
  369. {
  370. global $conf,$langs,$user;
  371. $langs->load("dict");
  372. $out='';
  373. // On recherche les formes juridiques actives des pays actifs
  374. $sql = "SELECT f.rowid, f.code as code , f.libelle as nom, f.active, p.libelle as libelle_pays, p.code as code_pays";
  375. $sql .= " FROM llx_c_forme_juridique as f, llx_c_pays as p";
  376. $sql .= " WHERE f.fk_pays=p.rowid";
  377. $sql .= " AND f.active = 1 AND p.active = 1";
  378. if ($pays_code) $sql .= " AND p.code = '".$pays_code."'";
  379. if ($filter) $sql .= " ".$filter;
  380. $sql .= " ORDER BY p.code, f.code";
  381. dol_syslog("Form::select_forme_juridique sql=".$sql);
  382. $result=$this->db->query($sql);
  383. if ($result)
  384. {
  385. $out.= '<div id="particulier2" class="visible">';
  386. $out.= '<select class="flat" name="forme_juridique_code">';
  387. if ($pays_code) $out.= '<option value="0">&nbsp;</option>';
  388. $num = $this->db->num_rows($result);
  389. $i = 0;
  390. if ($num)
  391. {
  392. $pays='';
  393. while ($i < $num)
  394. {
  395. $obj = $this->db->fetch_object($result);
  396. if ($obj->code == 0) {
  397. $out.= '<option value="0">&nbsp;</option>';
  398. }
  399. else {
  400. if (! $pays || $pays != $obj->libelle_pays) {
  401. // Affiche la rupture si on est en mode liste multipays
  402. if (! $pays_code && $obj->code_pays) {
  403. $out.= '<option value="0">----- '.$obj->libelle_pays." -----</option>\n";
  404. $pays=$obj->libelle_pays;
  405. }
  406. }
  407. if ($selected > 0 && $selected == $obj->code)
  408. {
  409. $out.= '<option value="'.$obj->code.'" selected="selected">';
  410. }
  411. else
  412. {
  413. $out.= '<option value="'.$obj->code.'">';
  414. }
  415. // Si translation exists, we use it, otherwise we use default label in database
  416. $out.= $obj->code . ' - ';
  417. $out.= ($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code?$langs->trans("JuridicalStatus".$obj->code):($obj->nom!='-'?$obj->nom:'')); // $obj->nom is alreay in output charset (converted by database driver)
  418. $out.= '</option>';
  419. }
  420. $i++;
  421. }
  422. }
  423. $out.= '</select>';
  424. if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  425. $out.= '</div>';
  426. }
  427. else
  428. {
  429. dol_print_error($this->db);
  430. }
  431. return $out;
  432. }
  433. /**
  434. * \brief Return list of third parties
  435. * \param object Object we try to find contacts
  436. * \param var_id Name of id field
  437. * \param selected Pre-selected third party
  438. * \param htmlname Name of HTML form
  439. * \param limitto Disable answers that are not id in this array list
  440. */
  441. function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='')
  442. {
  443. global $conf, $langs;
  444. // On recherche les societes
  445. $sql = "SELECT s.rowid, s.nom FROM";
  446. $sql.= " ".MAIN_DB_PREFIX."societe as s";
  447. if ($selected && $conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) $sql.= " WHERE rowid = ".$selected;
  448. else
  449. {
  450. // For ajax search we limit here. For combo list, we limit later
  451. if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT
  452. && is_array($limitto) && count($limitto))
  453. {
  454. $sql.= " WHERE rowid in (".join(',',$limitto).")";
  455. }
  456. }
  457. $sql .= " ORDER BY nom ASC";
  458. //print $sql;
  459. $resql = $this->db->query($sql);
  460. if ($resql)
  461. {
  462. if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT)
  463. {
  464. $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
  465. $socid=0;
  466. if ($selected)
  467. {
  468. $obj = $this->db->fetch_object($resql);
  469. $socid = $obj->rowid?$obj->rowid:'';
  470. }
  471. // We call a page after a small delay when a new input has been selected
  472. $javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;";
  473. $htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\');"'; // When we select with mouse
  474. $htmloption.= 'onKeyUp="if (event.keyCode== 13) { ac_delay(\''.$javaScript.'\',\'500\'); }"'; // When we select with keyboard
  475. print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
  476. print '<table class="nobordernopadding"><tr class="nobordernopadding">';
  477. print '<td class="nobordernopadding">';
  478. if ($obj->rowid == 0)
  479. {
  480. //$langs->load("companies");
  481. //print '<input type="text" size="30" id="'.$htmlname.'_label" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />';
  482. print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="" '.$htmloption.' />';
  483. }
  484. else
  485. {
  486. print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />';
  487. }
  488. print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','',$minLength);
  489. print '</td>';
  490. print '</tr>';
  491. print '</table>';
  492. print "\n";
  493. return $socid;
  494. }
  495. else
  496. {
  497. $javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
  498. print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'" onChange="'.$javaScript.'">';
  499. $num = $this->db->num_rows($resql);
  500. $i = 0;
  501. if ($num)
  502. {
  503. while ($i < $num)
  504. {
  505. $obj = $this->db->fetch_object($resql);
  506. if ($i == 0) $firstCompany = $obj->rowid;
  507. $disabled=0;
  508. if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
  509. if ($selected > 0 && $selected == $obj->rowid)
  510. {
  511. print '<option value="'.$obj->rowid.'"';
  512. if ($disabled) print ' disabled="disabled"';
  513. print ' selected="selected">'.dol_trunc($obj->nom,24).'</option>';
  514. $firstCompany = $obj->rowid;
  515. }
  516. else
  517. {
  518. print '<option value="'.$obj->rowid.'"';
  519. if ($disabled) print ' disabled="disabled"';
  520. print '>'.dol_trunc($obj->nom,24).'</option>';
  521. }
  522. $i ++;
  523. }
  524. }
  525. print "</select>\n";
  526. return $firstCompany;
  527. }
  528. }
  529. else
  530. {
  531. dol_print_error($this->db);
  532. }
  533. }
  534. /**
  535. * Return a select list with types of contacts
  536. * @param object Object to use to find type of contact
  537. * @param $selected Default selected value
  538. * @param htmlname
  539. * @param source
  540. * @param order
  541. * @param showempty 1=Add en empty line
  542. */
  543. function selectTypeContact($object, $selected, $htmlname = 'type', $source, $order='code', $showempty=0)
  544. {
  545. $lesTypes = $object->liste_type_contact($source, $order);
  546. print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  547. if ($showempty) print print '<option value="0"></option>';
  548. foreach($lesTypes as $key=>$value)
  549. {
  550. print '<option value="'.$key.'">'.$value.'</option>';
  551. }
  552. print "</select>\n";
  553. }
  554. /**
  555. * Return a select list with zip codes and their town
  556. * @param selected
  557. * @param htmlname
  558. * @param fields
  559. * @param fieldsize
  560. * @param disableautocomplete 1 To disable autocomplete features
  561. */
  562. function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0)
  563. {
  564. global $conf;
  565. $out='';
  566. $size='';
  567. if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
  568. if ($conf->use_javascript_ajax && empty($disableautocomplete)) $out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
  569. $out.= '<input id="'.$htmlname.'" type="text" name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
  570. return $out;
  571. }
  572. /**
  573. * Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
  574. * @param idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
  575. * @param htmlname Name of HTML select
  576. * @param preselected Default value to show
  577. * @param country_code FR, IT, ...
  578. */
  579. function get_input_id_prof($idprof,$htmlname,$preselected,$country_code)
  580. {
  581. global $conf,$langs;
  582. $formlength=24;
  583. if ($country_code == 'FR' && empty($conf->global->MAIN_DISABLEPROFIDRULES))
  584. {
  585. if ($idprof==1) $formlength=9;
  586. if ($idprof==2) $formlength=14;
  587. if ($idprof==3) $formlength=5; // 4 chiffres et 1 lettre depuis janvier
  588. if ($idprof==4) $formlength=32; // No maximum as we need to include a town name in this id
  589. }
  590. if ($country_code == 'ES' && empty($conf->global->MAIN_DISABLEPROFIDRULES))
  591. {
  592. if ($idprof==1) $formlength=9; //CIF/NIF/NIE 9 digits
  593. if ($idprof==2) $formlength=12; //NASS 12 digits without /
  594. if ($idprof==3) $formlength=5; //CNAE 5 digits
  595. if ($idprof==4) $formlength=32; //depend of college
  596. }
  597. $selected=$preselected;
  598. if (! $selected && $idprof==1) $selected=$this->siren;
  599. if (! $selected && $idprof==2) $selected=$this->siret;
  600. if (! $selected && $idprof==3) $selected=$this->ape;
  601. if (! $selected && $idprof==4) $selected=$this->idprof4;
  602. $out = '<input type="text" name="'.$htmlname.'" size="'.($formlength+1).'" maxlength="'.$formlength.'" value="'.$selected.'">';
  603. return $out;
  604. }
  605. }
  606. ?>