ajaxcountries.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/societe/ajaxcountries.php
  21. * \brief File to return Ajax response on country request
  22. */
  23. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
  24. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  25. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  26. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  27. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  28. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  29. require '../main.inc.php';
  30. $country=GETPOST('country', 'alpha');
  31. /*
  32. * View
  33. */
  34. // Ajout directives pour resoudre bug IE
  35. //header('Cache-Control: Public, must-revalidate');
  36. //header('Pragma: public');
  37. //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
  38. top_httphead();
  39. print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  40. dol_syslog(join(',',$_POST));
  41. // Generate list of countries
  42. if (! empty($country))
  43. {
  44. global $langs;
  45. $langs->load("dict");
  46. $sql = "SELECT rowid, code, label, active";
  47. $sql.= " FROM ".MAIN_DB_PREFIX."c_country";
  48. $sql.= " WHERE active = 1 AND label LIKE '%" . $db->escape(utf8_decode($country)) . "%'";
  49. $sql.= " ORDER BY label ASC";
  50. $resql=$db->query($sql);
  51. if ($resql)
  52. {
  53. print '<ul>';
  54. while($country = $db->fetch_object($resql))
  55. {
  56. print '<li>';
  57. // Si traduction existe, on l'utilise, sinon on prend le libellé par défaut
  58. print ($country->code && $langs->trans("Country".$country->code)!="Country".$country->code?$langs->trans("Country".$country->code):($country->label!='-'?$country->label:'&nbsp;'));
  59. print '<span class="informal" style="display:none">'.$country->rowid.'-idcache</span>';
  60. print '</li>';
  61. }
  62. print '</ul>';
  63. }
  64. }