populangs.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/php
  2. <?php
  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 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. define('N',"\n");
  16. require __DIR__.'/../lib/mb_ucfirst.php';
  17. use function mysqli_real_escape_string as myesc;
  18. $inifp=__DIR__.'/../conf/mustard.ini';
  19. $iniarr=@parse_ini_file($inifp)
  20. or mexit('Impossibile aprire il file di configurazione «'.$inifp.'»'.N,1);
  21. $link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
  22. or mexit('Impossibile connettersi al server MySQL: '.mysqli_connect_error().N,1);
  23. mysqli_set_charset($link,'utf8mb4')
  24. or mexit(mysqli_error($link).N,1);
  25. $localesfp='locales.json';
  26. $locales=@file_get_contents($localesfp);
  27. if ($locales===false)
  28. mexit('Non ho potuto aprire il file «'.$localesfp.'».'.N,1);
  29. $locales=json_decode($locales,true);
  30. print_r($locales);
  31. //mexit('Ecco.'.N,1);
  32. foreach ($locales as $key=>$val) {
  33. $code=myesc($link,$key);
  34. $NameOrig=myesc($link,mb_ucfirst(locale_get_display_name($key,$key)));
  35. $NameCa=myesc($link,mb_ucfirst(locale_get_display_name($key,'ca')));
  36. $NameEn=myesc($link,mb_ucfirst(locale_get_display_name($key,'en')));
  37. $NameEs=myesc($link,mb_ucfirst(locale_get_display_name($key,'es')));
  38. $NameFr=myesc($link,mb_ucfirst(locale_get_display_name($key,'fr')));
  39. $NameIt=myesc($link,mb_ucfirst(locale_get_display_name($key,'it')));
  40. $que='INSERT INTO Languages (ID, Code, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameIt.'\')';
  41. echo($que.N);
  42. mysqli_query($link,$que)
  43. or mexit(mysqli_error($link).N,2);
  44. }
  45. mysqli_close($link);
  46. exit(0);
  47. function mexit($msg,$rv) {
  48. global $link;
  49. if ($link)
  50. mysqli_close($link);
  51. echo($msg);
  52. exit($rv);
  53. }
  54. ?>