popudb.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. require(__DIR__.'/../include/mb_ucfirst.php');
  16. define('N',"\n");
  17. use function mysqli_real_escape_string as myesc;
  18. $inifp=__DIR__.'/../sec/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. require(__DIR__.'/../include/tables.php');
  26. $tables=tables($link);
  27. $localesfp='locales.json';
  28. $locales=@file_get_contents($localesfp);
  29. if ($locales===false)
  30. mexit('Non ho potuto aprire il file «'.$localesfp.'».'.N,1);
  31. $locales=json_decode($locales,true);
  32. print_r($locales);
  33. foreach ($locales as $key=>$val) {
  34. $code=myesc($link,$key);
  35. $NameOrig=myesc($link,mb_ucfirst(locale_get_display_name($key,$key)));
  36. $NameCa=myesc($link,mb_ucfirst(locale_get_display_name($key,'ca')));
  37. $NameEn=myesc($link,mb_ucfirst(locale_get_display_name($key,'en')));
  38. $NameEs=myesc($link,mb_ucfirst(locale_get_display_name($key,'es')));
  39. $NameFr=myesc($link,mb_ucfirst(locale_get_display_name($key,'fr')));
  40. $NameIt=myesc($link,mb_ucfirst(locale_get_display_name($key,'it')));
  41. $que='INSERT INTO Languages (ID, Code, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameIt.'\')';
  42. echo($que.N);
  43. mysqli_query($link,$que)
  44. or mexit(mysqli_error($link).N,2);
  45. }
  46. mysqli_close($link);
  47. exit(0);
  48. function mexit($msg,$rv) {
  49. global $link;
  50. if ($link)
  51. mysqli_close($link);
  52. echo($msg);
  53. exit($rv);
  54. }
  55. function truncs($str,$tab,$col,$ctx) {
  56. global $tables, $tronconi, $iswin;
  57. if ($iswin)
  58. $tab=strtolower($tab);
  59. $size=$tables[$tab][$col];
  60. $len=mb_strlen($str,'UTF-8');
  61. if ($len>$size) {
  62. $tronconi[]=array('id'=>null,'tab'=>$tab,'col'=>$col,'ctx'=>$ctx,'len'=>$len,'size'=>$size);
  63. $str=mb_substr($str,0,$size-1,'UTF-8').'…';
  64. }
  65. return($str);
  66. }
  67. function truncn($num,$tab,$col,$ctx) {
  68. global $tables, $iswin;
  69. if ($iswin)
  70. $tab=strtolower($tab);
  71. if (is_numeric($num)) {
  72. if ($num>$tables[$tab][$col]['max']) {
  73. notify($ctx.': ho dovuto troncare «'.$num.'» al valore massimo «'.$tables[$tab][$col]['max'].'» che può avere nella colonna «'.$col.'» della tabella «'.$tab.'»).',2);
  74. $num=$tables[$tab][$col]['max'];
  75. } elseif ($num<$tables[$tab][$col]['min']) {
  76. notify($ctx.': ho dovuto troncare «'.$num.'» al valore minimo «'.$tables[$tab][$col]['min'].'» che può avere nella colonna «'.$col.'» della tabella «'.$tab.'»).',2);
  77. $num=$tables[$tab][$col]['min'];
  78. }
  79. } else {
  80. notify($ctx.': truncn(): mi aspettavo un numero, invece non lo era; ritorno «0».',3);
  81. $num=0;
  82. }
  83. return($num);
  84. }
  85. ?>