This commit is contained in:
pezcurrel 2020-04-21 12:35:53 +02:00
parent 1915458d27
commit 48e64bb81e
12 changed files with 330 additions and 264 deletions

View file

@ -557,12 +557,13 @@ function langs($instid, $uri, $auto) {
or mexit(__LINE__.': '.mysqli_error($link).N,3);
if (mysqli_num_rows($res)<1) {
$code=myesc($link,truncs($lang,'Languages','Code','«'.$instrow['URI'].'»'));
$NameIt=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,'it')),'Languages','NameIT','«'.$instrow['URI'].'»'));
$NameOrig=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,$lang)),'Languages','NameOrig','«'.$instrow['URI'].'»'));
$NameCa=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,'ca')),'Languages','NameCA','«'.$instrow['URI'].'»'));
$NameEn=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,'en')),'Languages','NameEN','«'.$instrow['URI'].'»'));
$NameEs=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,'es')),'Languages','NameES','«'.$instrow['URI'].'»'));
$NameFr=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,'fr')),'Languages','NameFR','«'.$instrow['URI'].'»'));
$NameOrig=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,$lang)),'Languages','NameOrig','«'.$instrow['URI'].'»'));
$q = 'INSERT INTO Languages (ID, Code, NameIT, NameEN, NameES, NameFR, NameOrig) VALUES (NULL, \''.$code.'\', \''.$NameIt.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameOrig.'\')';
$NameIt=myesc($link,truncs(mb_ucfirst(locale_get_display_name($lang,'it')),'Languages','NameIT','«'.$instrow['URI'].'»'));
$q = 'INSERT INTO Languages (ID, Code, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameIt.'\')';
mysqli_query($link, $q)
or mexit(__LINE__.': '.mysqli_error($link).N,3);
$langid=mysqli_insert_id($link);

View file

@ -3,24 +3,31 @@
* fatto
# in corso
* l'icona per l'uscita senza div o quel che è, come in instances.php
* edinsth.php: su edit e add, nel js, selezionare solo il valore editato/aggiunto, perché nella finestrella elenco valori mostra il primo selezionato
* edinstres.php deve mostrare scheda istanza completa
* guestinsts.php, edinst.php e edinstres.php devono avere menu particolare per "guest" con la possibilità di andare alla vista delle istanze
* edinsth.php: per "guest" deve tenere conto dei limiti impostati con MaxLocalities ecc.
- edinst.php: un'icona per deselezionare Locality
- nei vari helper, sarebbe meglio morisse in json, alla bisogna
- sanificazione input: edinsth.php: su edit e add controllare sempre che il valore "nuovo" non ci sia già
- aggiungere colonna NameCA a Languages e Localities, e relativi pimpumpam nel codice
- troncare tabella languages e far rigirare tools/popudb.php per ricrearla: my_ucfirst metteva in minuscolo tutta la stringa, a parte il primo carattere maiuscolo
* aggiungere colonna "OSMID" a Localities, in modo che se aggiungiamo altre lingue in seguito sia più facile recuperarle per aggiornare la tabella
* aggiungere colonna NameCA a Languages e Localities, e relativi pimpumpam nel codice (greppare "NameES" e "\'es\'" dappertutto)
* troncare tabella languages e far rigirare tools/popudb.php per ricrearla: my_ucfirst metteva in minuscolo tutta la stringa, a parte il primo carattere maiuscolo
- aggiungere notifiche quando "guest" edita istanza, località, lingua, modalità di finanziamento, ecc.
* aggiungere colonna "timestamp" "LastGuestEdit" a Instances: null quando non è stata mai editata da "guest", altrimenti time() php
# edinst.php: su languages se account "Level" è "guest", "lock this list" dev'essere checkato per default *se "guest" non ha ancora mai modificato i dati dell'istanza*
- index.php: lunghezza automatica di username
? index.php: lunghezza automatica di username
* tutto: visualizzazione notifiche (campanellina e div a s/comparsa)
- serve un "notifs.php" (è già linkato dalla lista notifiche accessibile dalla campanella) per la gestione accurata delle notifiche (possibilità di marcarle tutte o "precedenti a" come lette, possibilità di cancellarle tutte o "precedenti a")
- rinominare tutto da "Mastodon Startpage Admin" a "MastoStartAdm"
- crawler.php: ricorsivizzarlo?
- crawler.php: le notifiche, invece di edinst.php, devono linkare un viewinst.php che mostri l'istanza
- crawler.php: deve controllare se nella tabella Instances OurAdmID è definito; se è definito e la mail del corrispettivo account "guest" è cambiata, deve aggiornare l'account "guest" corrispettivo in Admins con la mail e il nome utente attuali e creare nuova password; se i dati dell'istanza sono già stati editati, mandare mail di "aggiornamento"; se non lo sono, mandare invito
- instances.php: tradurre tutto in inglese
- tutto: possibilità di *scegliere* la lingua da usare tra quelle supportate
- edinsth.php: finire Localities
- implementare la faccenda dell'invio di mail preformattate agli admin con invito a editare i propri dati (quindi implementare "livelli di admin" e relative restrizioni: admin invitat* può vedere solo la pagina relativa alla propria istanza, solo aggiungere valori - non in tutti i casi, editare ed eliminare solo valori che ha aggiunto e solo se non sono già stati linkati da altr*)
- instances.php: possibilità di *scegliere* la lingua da usare tra quelle supportate per il filtraggio su Localities e Languages
* edinsth.php: finire Localities
# implementare la faccenda dell'invio di mail preformattate agli admin con invito a editare i propri dati (quindi implementare "livelli di admin" e relative restrizioni: admin invitat* può vedere solo la pagina relativa alla propria istanza, solo aggiungere valori - non in tutti i casi, editare ed eliminare solo valori che ha aggiunto e solo se non sono già stati linkati da altr*)
? instances.php: bottoni per pagina precedente-successiva
- instances.php: alerta su cambio pagina quando è stato modificato filtro/ordinamento
- instances.php: possibilità di vedere solo le istanze che non rispondono da tot giorni (o forse farla a parte?)

View file

@ -7,6 +7,7 @@ require('include/myconn.php');
require('include/getadmacc.php');
require('include/menu.php');
$menu['menu']['selected']=true;
$menu['menu']['submenu']['instances']['selected']=true;
buildmenu($menu);
$dbg='';
@ -259,6 +260,8 @@ function edit(selid,what,mode) {
}
}
function ckf() {
// questo qua sotto resetta eventuale filtro su LocalityID in modo che se c'è valore selezionato ma non mostrato viene passato
filtsel(locselarr, '', 'LocalityID', 'locselre', 'locsearch', 'white', '#ff8080');
var selids=['ChosenLangs[]','ChosenFinModes[]','ChosenPolicies[]','ChosenTags[]'], len=selids.length, i, sel, ii;
for (i=0; i<len; i++) {
sel=document.getElementById(selids[i]).options;
@ -280,7 +283,7 @@ function ckf() {
<div class="mtit">Editing «<?php echo($inst['URI']); ?>»</div>
<div id="rightdiv">
<?php if ($account['Level']!='guest') echo('<img src="'.$notifs['imgoff'].'" id="bell" class="rlinks" title="Show notifications" onclick="shidenotifs();">'.N); ?>
<a href="logout.php" class="rlinks"><img src="imgs/esci.svg" title="Sign out"></a>
<img src="imgs/esci.svg" class="rlinks" title="Logout" onclick="document.location.href='logout.php';">
</div>
</div>
</nav>
@ -318,21 +321,23 @@ if ($account['Level']!='guest')
<div class="ruler"></div>'.N);
?>
<div class="tit"><label for="OurDesc">Our description (original language)</label></div>
<div class="tit"><label for="OurDesc">Description (local language)</label></div>
<textarea name="OurDesc" id="OurDesc" rows="10" class="tarea"><?php echo(hspech($inst['OurDesc'])); ?></textarea>
<div class="ruler"></div>
<div class="tit"><label for="OurDescEN">Our description (english)</label></div>
<div class="tit"><label for="OurDescEN">Description (english)</label></div>
<textarea name="OurDescEN" id="OurDescEN" rows="10" class="tarea"><?php echo(hspech($inst['OurDescEN'])); ?></textarea>
<?php
function selbox($o) {
global $link;
global $link, $account;
($o['multi']) ? $seladdprops=' multiple' : $seladdprops=' name="'.$o['dispselid'].'"';
echo('<div class="ruler"></div>
<div class="tit"><label for="'.$o['dispselid'].'">'.$o['title'].'</label></div>
<table class="picktab"><tr>
<div class="tit"><label for="'.$o['dispselid'].'">'.$o['title'].'</label></div>'.N);
if ($account['Level']=='guest')
echo('<div class="desc">'.$o['desc'].'</div>'.N);
echo('<table class="picktab"><tr>
<td style="width:98%"><input type="text" placeholder="Filter ..." class="search" title="'.$o['searchtit'].'" id="'.$o['searchid'].'" onkeyup="filtsel('.$o['disparr'].', this.value, \''.$o['dispselid'].'\', \''.$o['regexcbid'].'\', \''.$o['searchid'].'\', \'white\', \'#ff8080\')"></td>
<td style="width:1%;padding-left:3px;padding-right:3px;"><label for="'.$o['regexcbid'].'" title="Use regular espression">RegEx:</label></td>
<td style="width:1%"><input type="checkbox" id="'.$o['regexcbid'].'" style="float:right;" title="Use regular espression" onchange="filtsel('.$o['disparr'].', document.getElementById(\''.$o['searchid'].'\').value, \''.$o['dispselid'].'\', \''.$o['regexcbid'].'\', \''.$o['searchid'].'\', \'white\', \'#ff8080\')"></td>
@ -400,12 +405,13 @@ echo('</td>
}
selbox(array(
'desc'=>'If your instance is mainly bound to a particular location (from neighbourhood to country) you can specify it here. You can add up to '.$account['MaxLocalities'].' location[s]. You can edit or remove only the location[s] you added, and only as long as they have not yet been referenced by others. For particular needs dont hesitate to <a href="contact.php" target="_blank">contact us</a>.',
'multi'=>false,
'dispselid'=>'LocalityID',
'instselid'=>$inst['LocalityID'],
'title'=>'Locality',
'title'=>'Location',
'searchid'=>'locsearch',
'searchtit'=>'Filter available localities',
'searchtit'=>'Filter available locations',
'disparr'=>'locselarr',
'regexcbid'=>'locselre',
'dispque'=>'SELECT ID, Name'.$dlang.' FROM Localities ORDER BY NameOrig ASC',
@ -413,6 +419,7 @@ selbox(array(
'txtcol'=>'Name'.$dlang));
$o=array(
'desc'=>'Here you can specify the languages which are mostly used on your instance, in order of importance. The list of available languages to choose from should be fairly complete, but if you find out it is not dont hesitate to <a href="contact.php" target="_blank">contact us</a>. The list of chosen languages is often pre-populated by our crawler, which tries and guess them automatically, but you can always modify it and prevent the crawler from changing it on its next runs by ticking the “Lock this list” checkbox you find under the list.',
'multi'=>true,
'dispselid'=>'DispLangs',
'title'=>'Languages',
@ -443,27 +450,29 @@ selbox($o);
<?php
selbox(array(
'desc'=>'Here you can specify the modalities by which your instance is financed, in order of importance. You can add up to '.$account['MaxFinancing'].' modalities to the list of available modalities. You can edit or remove only the modalities you added, and only as long as they have not yet been referenced by others.<br>For particular needs dont hesitate to <a href="contact.php" target="_blank">contact us</a>.',
'multi'=>true,
'dispselid'=>'DispFinModes',
'title'=>'Financing methods',
'title'=>'Financing modalities',
'searchid'=>'finsearch',
'searchtit'=>'Filter available financing methods',
'searchtit'=>'Filter available financing modalities',
'disparr'=>'finselarr',
'regexcbid'=>'finselre',
'dispque'=>'SELECT * FROM Financing WHERE ID NOT IN (SELECT FinID FROM InstFinancing WHERE InstID='.$inst['ID'].') ORDER BY Type ASC',
'valcol'=>'ID',
'txtcol'=>'Type',
'dida'=>'Above: available fin. methods; below: chosen fin. methods',
'dida'=>'Above: available fin. modes; below: chosen fin. modes',
'chosenselid'=>'ChosenFinModes[]',
'chosenque'=>'SELECT * FROM InstFinancing LEFT JOIN Financing ON Financing.ID=FinID WHERE InstID='.$inst['ID'].' ORDER BY Pos ASC',
'chosenvalcol'=>'FinID'));
selbox(array(
'desc'=>'Here you can specify the policies defining which kind of contents are allowed or not allowed on your instance. You can add up to '.$account['MaxPolicies'].' policies to the list of available policies. You can edit or remove only the policies you added, and only as long as they have not yet been referenced by others.<br>For particular needs dont hesitate to <a href="contact.php" target="_blank">contact us</a>.',
'multi'=>true,
'dispselid'=>'DispPolicies',
'title'=>'Policies',
'searchid'=>'polsearch',
'searchtit'=>'Filter policies',
'searchtit'=>'Filter available policies',
'disparr'=>'polselarr',
'regexcbid'=>'polselre',
'dispque'=>'SELECT * FROM Policies WHERE ID NOT IN (SELECT PolID FROM InstPolicies WHERE InstID='.$inst['ID'].') ORDER BY Name ASC',
@ -475,17 +484,18 @@ selbox(array(
'chosenvalcol'=>'PolID'));
selbox(array(
'desc'=>'Here you can specify the “thematic” categories your instance is dedicated to, if any. If your instance isnt particularly dedicated to any particular topic, please just associate it with the “General” category. You can add '.$account['MaxTags'].' categories to the list of available categories. You can edit or remove only the categories you added, and only as long as they have not yet been referenced by others. For particular needs dont hesitate to <a href="contact.php" target="_blank">contact us</a>.',
'multi'=>true,
'dispselid'=>'DispTags',
'title'=>'Tags',
'title'=>'Categories',
'searchid'=>'tagsearch',
'searchtit'=>'Filter tags',
'searchtit'=>'Filter available categories',
'disparr'=>'tagselarr',
'regexcbid'=>'tagselre',
'dispque'=>'SELECT * FROM Tags WHERE ID NOT IN (SELECT TagID FROM InstTags WHERE InstID='.$inst['ID'].') ORDER BY Name ASC',
'valcol'=>'ID',
'txtcol'=>'Name',
'dida'=>'Above: available tags; below: chosen tags',
'dida'=>'Above: available categories; below: chosen categories',
'chosenselid'=>'ChosenTags[]',
'chosenque'=>'SELECT * FROM InstTags LEFT JOIN Tags ON Tags.ID=TagID WHERE InstID='.$inst['ID'].' ORDER BY Pos ASC',
'chosenvalcol'=>'TagID'));

View file

@ -29,20 +29,54 @@ $contextopts=array(
$context=stream_context_create($contextopts);
$email='pezcurrel@tiscali.it';
$langs=array('xx'=>'Local language','en'=>'English','es'=>'Español','fr'=>'Français','it'=>'Italiano');
$langs=array('xx'=>'Local language','ca'=>'Català','en'=>'English','es'=>'Español','fr'=>'Français','it'=>'Italiano');
$exvalsjsarr='null;'.N;
$morejs='';
$dbg.='<pre>GET:'.N.print_r($_GET,1).'POST:'.N.print_r($_POST,1).'</pre>';
function check(&$link,&$account,$mode,$table,$lntable,$lncolumn,$id) {
if ($mode=='edit' || $mode=='remove') {
$res=mysqli_query($link,'SELECT * FROM '.$table.' WHERE ID='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
if (mysqli_num_rows($res)==1) {
$row=mysqli_fetch_assoc($res);
if ($account['Level']=='guest') {
if ($row['AddedBy']!=$account['ID'])
muoribene('You cant modify an entry you didnt add.',true);
if ($table!='Localities') {
$que='SELECT * FROM '.$lntable.' LEFT JOIN Instances ON Instances.ID='.$lntable.'.InstID WHERE '.$lntable.'.'.$lncolumn.'='.$id.' AND Instances.ID NOT IN (SELECT ID FROM Instances WHERE OurAdmID='.$account['ID'].')';
} else {
$que='SELECT * FROM Instances WHERE LocalityID='.$id.' AND Instances.ID NOT IN (SELECT ID FROM Instances WHERE OurAdmID='.$account['ID'].')';
}
$rres=mysqli_query($link,$que)
or muoribene(__LINE__.': '.mysqli_error($link).'<br>Query: '.hspech($que),true);
if (mysqli_num_rows($rres)>0)
muoribene('You cant modify an entry that<br>has already been linked by others.',true);
}
} else {
muoribene('There is no «'.$table.'» entry with ID='.$id.N,true);
}
} elseif ($mode=='add') {
if ($account['Level']=='guest') {
$res=mysqli_query($link,'SELECT * FROM '.$table.' WHERE AddedBy='.$account['ID'])
or muoribene(__LINE__.': '.mysqli_error($link),true);
if (mysqli_num_rows($res)>=$account['Max'.$table])
muoribene('You cant add more «'.$table.'»<br>entries ('.$account['Max'.$table].' max).',true);
}
}
}
function edaddrem($id,$table,$column,$dispselarr,$lntable,$lncolumn,$searchid,$dispselid,$recbid) {
global $link, $morejs, $account, $dlang;
check($link,$account,$_POST['m'],$table,$lntable,$lncolumn,$id);
if ($_POST['m']=='edit') {
if ($table!='Languages') {
mysqli_query($link,'UPDATE '.$table.' SET '.$column.'=\''.myesc($link,$_POST['v']).'\' WHERE ID='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
} else {
$langs=array('NameOrig'=>mb_ucfirst(locale_get_display_name($_POST['v'],$_POST['v'])),
'NameCA'=>mb_ucfirst(locale_get_display_name($_POST['v'],'ca')),
'NameEN'=>mb_ucfirst(locale_get_display_name($_POST['v'],'en')),
'NameES'=>mb_ucfirst(locale_get_display_name($_POST['v'],'es')),
'NameFR'=>mb_ucfirst(locale_get_display_name($_POST['v'],'fr')),
@ -50,7 +84,7 @@ function edaddrem($id,$table,$column,$dispselarr,$lntable,$lncolumn,$searchid,$d
if ($_POST['v']==$langs['NameOrig']) {
muoribene('«'.$_POST['v'].'»: unknown language identifier.',true);
} else {
mysqli_query($link,'UPDATE '.$table.' SET Code=\''.myesc($link,$_POST['v']).'\', NameOrig=\''.myesc($link,$langs['NameOrig']).'\', NameEN=\''.myesc($link,$langs['NameEN']).'\', NameES=\''.myesc($link,$langs['NameES']).'\', NameFR=\''.myesc($link,$langs['NameFR']).'\', NameIT=\''.myesc($link,$langs['NameIT']).'\' WHERE ID='.$id)
mysqli_query($link,'UPDATE '.$table.' SET Code=\''.myesc($link,$_POST['v']).'\', NameOrig=\''.myesc($link,$langs['NameOrig']).'\', NameCA=\''.myesc($link,$langs['NameCA']).'\', NameEN=\''.myesc($link,$langs['NameEN']).'\', NameES=\''.myesc($link,$langs['NameES']).'\', NameFR=\''.myesc($link,$langs['NameFR']).'\', NameIT=\''.myesc($link,$langs['NameIT']).'\' WHERE ID='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
$_POST['v']=$langs['Name'.$dlang].' ['.$_POST['v'].']';
}
@ -65,6 +99,7 @@ function edaddrem($id,$table,$column,$dispselarr,$lntable,$lncolumn,$searchid,$d
$newid=mysqli_insert_id($link);
} else {
$langs=array('NameOrig'=>mb_ucfirst(locale_get_display_name($_POST['v'],$_POST['v'])),
'NameCA'=>mb_ucfirst(locale_get_display_name($_POST['v'],'ca')),
'NameEN'=>mb_ucfirst(locale_get_display_name($_POST['v'],'en')),
'NameES'=>mb_ucfirst(locale_get_display_name($_POST['v'],'es')),
'NameFR'=>mb_ucfirst(locale_get_display_name($_POST['v'],'fr')),
@ -72,7 +107,7 @@ function edaddrem($id,$table,$column,$dispselarr,$lntable,$lncolumn,$searchid,$d
if (strtolower($_POST['v'])==strtolower($langs['NameOrig'])) {
muoribene('«'.$_POST['v'].'»: unknown language identifier.',true);
} else {
mysqli_query($link,'INSERT INTO '.$table.' (ID, Code, NameOrig, NameEN, NameES, NameFR, NameIT, AddedBy) VALUES (NULL, \''.myesc($link,$_POST['v']).'\', \''.myesc($link,$langs['NameOrig']).'\', \''.myesc($link,$langs['NameEN']).'\', \''.myesc($link,$langs['NameES']).'\', \''.myesc($link,$langs['NameFR']).'\', \''.myesc($link,$langs['NameIT']).'\', '.$account['ID'].')')
mysqli_query($link,'INSERT INTO '.$table.' (ID, Code, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT, AddedBy) VALUES (NULL, \''.myesc($link,$_POST['v']).'\', \''.myesc($link,$langs['NameOrig']).'\', \''.myesc($link,$langs['NameCA']).'\', \''.myesc($link,$langs['NameEN']).'\', \''.myesc($link,$langs['NameES']).'\', \''.myesc($link,$langs['NameFR']).'\', \''.myesc($link,$langs['NameIT']).'\', '.$account['ID'].')')
or muoribene(__LINE__.': '.mysqli_error($link),true);
$newid=mysqli_insert_id($link);
$_POST['v']=$langs['Name'.$dlang].' ['.$_POST['v'].']';
@ -139,7 +174,7 @@ if (array_key_exists('w',$_GET) && array_key_exists('i',$_GET) && preg_match('/^
$exvalsjsarr=setjsarr('Languages','Code');
break;
case 'DispFinModes':
$out=buildform($id,'Financing','Type','Financing method','InstFinancing','FinID');
$out=buildform($id,'Financing','Type','Financing modality','InstFinancing','FinID');
$exvalsjsarr=setjsarr('Financing','Type');
break;
case 'DispPolicies':
@ -165,53 +200,79 @@ if (array_key_exists('w',$_GET) && array_key_exists('i',$_GET) && preg_match('/^
$url='https://nominatim.openstreetmap.org/search?q='.urlencode($_POST['v']).'&format=json&email='.$email;
$osmd=@file_get_contents($url,false,$context);
if ($osmd!==false) {
$out.='<form action="edinsth.php" method="post" id="f">'.N;
$addrkeys=array('suburb','city','county','state','country');
$osmd=json_decode($osmd,true);
if (count($osmd)>0) {
$some=false;
$out.='<p><strong>Please choose the most detailed appropriate entry</strong></p>'.N;
$addrkeys=array('neighbourhood','borough','suburb','city','municipality','county','district','province','region','state','country');
$onegood=false;
$divs='';
foreach ($osmd as $loc) {
$good=false;
$div='';
//$loc=array(); // simula errore
if (array_key_exists('osm_id',$loc) && array_key_exists('osm_type',$loc) && $loc['osm_type']=='relation') {
$out.='<div class="hifloc" onclick="subosmd(\''.$loc['osm_id'].'\');">'.N;
$out.='<ul class="hiful">'.N;
$div.='<input type="hidden" id="OSMID-'.$loc['osm_id'].'" value="'.$loc['osm_id'].'">'.N;
$div.='<ul class="hiful">'.N;
foreach ($langs as $code=>$lang) {
$hidval='';
$url='https://nominatim.openstreetmap.org/lookup?osm_ids=R'.$loc['osm_id'].'&format=json&accept-language='.$code.'&addressdetails=1&email='.$email;
$osmdil=@file_get_contents($url,false,$context);
if ($osmdil!==false) {
$some=true; //+++
$osmdil=json_decode($osmdil,true);
if (array_key_exists(0,$osmdil) && array_key_exists('address',$osmdil[0])) {
$dispname='';
//$osmdil[0]['address']=array(); // simula errore
$dispname=array();
foreach ($addrkeys as $addrkey)
if (array_key_exists($addrkey,$osmdil[0]['address']))
$dispname.=$osmdil[0]['address'][$addrkey].', ';
$dispname=substr($dispname,0,-2);
$out.='<li><strong>'.$lang.':</strong> '.hspech($dispname).'</li>'.N;
$out.='<input type="hidden" id="Loc'.strtoupper($code).'-'.$loc['osm_id'].'" value="'.jsencode($dispname).'">'.N;
$dispname[]=$osmdil[0]['address'][$addrkey];
if (count($dispname)>0) {
$dispname=array_unique($dispname);
$dispname=implode(', ',$dispname);
$div.='<li><strong>'.$lang.':</strong> '.hspech($dispname).'</li>'.N;
$hidval=jsencode($dispname);
if ($code=='xx') {
$res=mysqli_query($link,'SELECT NameOrig FROM Localities WHERE NameOrig=\''.myesc($link,$dispname).'\'')
or muoribene(__LINE__.': '.mysqli_error($link),true);
if (mysqli_num_rows($res)==0)
$good=true;
}
} else {
$div.='<li><strong>'.$lang.':</strong> <span class="hiferr">No useful «address» data found in OpenStreetMap lookup data.</span></li>'.N;
}
} else {
$out.='<li class="hiferr"><strong>'.$lang.':</strong> Couldnt parse OpenStreetMap lookup data.</li>'.N;
$out.='<input type="hidden" id="Loc'.strtoupper($code).'-'.$loc['osm_id'].'" value="">'.N;
$div.='<li><strong>'.$lang.':</strong> <span class="hiferr">No «address» found in OpenStreetMap lookup data.</span></li>'.N;
}
} else {
$out.='<li class="hiferr"><strong>'.$lang.':</strong> Couldnt fetch OpenStreetMap lookup data.</li>'.N;
$div.='<li><strong>'.$lang.':</strong> <span class="hiferr">Couldnt fetch OpenStreetMap lookup data.</span></li>'.N;
}
$div.='<input type="hidden" id="Loc'.strtoupper($code).'-'.$loc['osm_id'].'" value="'.$hidval.'">'.N;
}
$out.='</ul>'.N.'</div>'.N;
if ($good) {
$onegood=true;
$divs.='<div class="hifloc" onclick="subosmd(\''.$loc['osm_id'].'\');">'.N.$div;
} else {
$divs.='<div class="hiflocno">'.N.$div;
}
$divs.='</ul>'.N.'</div>'.N;
}
}
if ($some) {
if ($onegood) {
$out.='<form action="edinsth.php" method="post" id="f">'.N;
$out.='<p><strong>Please choose the most appropriate entry<br>among those with green background</strong></p>'.N;
$out.=$divs;
$out.='<input type="hidden" id="i" name="i" value="'.$_POST['i'].'">'.N;
$out.='<input type="hidden" id="t" name="t" value="'.$_POST['t'].'">'.N;
$out.='<input type="hidden" id="m" name="m" value="'.$_POST['m'].'">'.N;
$out.='<input type="hidden" id="OSMID" name="OSMID" value="">'.N;
$out.='<input type="hidden" id="LocXX" name="LocXX" value="">'.N;
$out.='<input type="hidden" id="LocCA" name="LocCA" value="">'.N;
$out.='<input type="hidden" id="LocEN" name="LocEN" value="">'.N;
$out.='<input type="hidden" id="LocES" name="LocES" value="">'.N;
$out.='<input type="hidden" id="LocFR" name="LocFR" value="">'.N;
$out.='<input type="hidden" id="LocIT" name="LocIT" value="">'.N;
$out.='</form>'.N;
} else {
$out='<p class="hiferr">Couldnt find localized OpenStreetMap data for «'.hspech($_POST['v']).'».</p>';
$out.='<p><strong>Sorry, no good OpenStreetMap entry was found<br>(they are either incomplete or already in our database)</strong></p>'.N;
$out.=$divs;
}
} else {
$out='<p class="hiferr">Couldnt find OpenStreetMap data for «'.hspech($_POST['v']).'».</p>';
@ -221,6 +282,7 @@ if (array_key_exists('w',$_GET) && array_key_exists('i',$_GET) && preg_match('/^
}
} else {
// locality remove
check($link,$account,$_POST['m'],'Localities','Instances','LocalityID',$id);
$out='CANCELLO!';
if (!array_key_exists('subst',$_POST) || preg_match('/^[0-9]+$/',$_POST['subst'])!==1)
muoribene(__LINE__.': Malformed input.',true);
@ -250,17 +312,18 @@ if (array_key_exists('w',$_GET) && array_key_exists('i',$_GET) && preg_match('/^
// questo è ridondante ma fa niente
muoribene(__LINE__.': Malformed input.',true);
}
} elseif (array_key_exists('LocXX',$_POST) && array_key_exists('LocEN',$_POST) && array_key_exists('LocES',$_POST) && array_key_exists('LocFR',$_POST) && array_key_exists('LocIT',$_POST)) {
} elseif (array_key_exists('OSMID',$_POST) && preg_match('/^[0-9]+$/',$_POST['OSMID'])===1 && array_key_exists('LocXX',$_POST) && array_key_exists('LocCA',$_POST) && array_key_exists('LocEN',$_POST) && array_key_exists('LocES',$_POST) && array_key_exists('LocFR',$_POST) && array_key_exists('LocIT',$_POST)) {
// locality edit/add
check($link,$account,$_POST['m'],'Localities','Instances','LocalityID',$id);
$out='EDITO/AGGIUNGO!';
// qui, sia su add sia su edit, serve check che non esista già +++
if ($_POST['m']=='add') {
mysqli_query($link,'INSERT INTO Localities (ID, NameOrig, NameEN, NameES, NameFR, NameIT, AddedBy) VALUES (NULL, \''.myesc($link,$_POST['LocXX']).'\', \''.myesc($link,$_POST['LocEN']).'\', \''.myesc($link,$_POST['LocES']).'\', \''.myesc($link,$_POST['LocFR']).'\', \''.myesc($link,$_POST['LocIT']).'\', \''.$account['ID'].'\')')
mysqli_query($link,'INSERT INTO Localities (ID, OSMID, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT, AddedBy) VALUES (NULL, \''.myesc($link,$_POST['OSMID']).'\', \''.myesc($link,$_POST['LocXX']).'\', \''.myesc($link,$_POST['LocCA']).'\', \''.myesc($link,$_POST['LocEN']).'\', \''.myesc($link,$_POST['LocES']).'\', \''.myesc($link,$_POST['LocFR']).'\', \''.myesc($link,$_POST['LocIT']).'\', \''.$account['ID'].'\')')
or muoribene(__LINE__.': '.mysqli_error($link),true);
$id=mysqli_insert_id($link);
$morejs.='parent.locselarr.push(["'.jsencode($_POST['Loc'.$dlang]).'",'.$id.',true]);'.N;
} elseif ($_POST['m']=='edit') {
mysqli_query($link,'UPDATE Localities SET NameOrig=\''.myesc($link,$_POST['LocXX']).'\', NameEN=\''.myesc($link,$_POST['LocEN']).'\', NameES=\''.myesc($link,$_POST['LocES']).'\', NameFR=\''.myesc($link,$_POST['LocFR']).'\', NameIT=\''.myesc($link,$_POST['LocIT']).'\' WHERE ID='.$id)
mysqli_query($link,'UPDATE Localities SET OSMID=\''.myesc($link,$_POST['OSMID']).'\', NameOrig=\''.myesc($link,$_POST['LocXX']).'\', NameCA=\''.myesc($link,$_POST['LocCA']).'\', NameEN=\''.myesc($link,$_POST['LocEN']).'\', NameES=\''.myesc($link,$_POST['LocES']).'\', NameFR=\''.myesc($link,$_POST['LocFR']).'\', NameIT=\''.myesc($link,$_POST['LocIT']).'\' WHERE ID='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
$morejs.='parent.locselarr=parent.cheltxtbyval(parent.locselarr,'.$id.',"'.jsencode($_POST['Loc'.$dlang]).'");'.N;
}
@ -277,54 +340,43 @@ if (array_key_exists('w',$_GET) && array_key_exists('i',$_GET) && preg_match('/^
function buildform($id,$table,$column,$title,$lntable,$lncolumn) {
global $account, $tables, $link;
check($link,$account,$_GET['m'],$table,$lntable,$lncolumn,$id);
$out='';
if ($_GET['m']=='edit' || $_GET['m']=='remove') {
$res=mysqli_query($link,'SELECT * FROM '.$table.' WHERE ID='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
if (mysqli_num_rows($res)==1) {
$row=mysqli_fetch_assoc($res);
if ($account['Level']=='guest') {
if ($row['AddedBy']!=$account['ID'])
muoribene('You cant modify an entry you didnt add.',true);
$rres=mysqli_query($link,'SELECT * FROM '.$lntable.' WHERE '.$lncolumn.'='.$id.' AND AddedBy!='.$account['ID'])
$row=mysqli_fetch_assoc($res);
if ($_GET['m']=='edit') {
$out.='<div class="hiflab"><label for="v">'.$title.'</label></div>'.N;
$out.='<input type="text" class="hifinp" name="v" id="v" maxlength="'.$tables[$table][$column].'" value="'.hspech($row[$column]).'">'.N;
$out.='<script language="JavaScript">'.N;
$out.='<!--'.N;
$out.='document.getElementById(\'v\').focus();'.N;
$out.='document.getElementById(\'v\').select();'.N;
$out.='//-->'.N;
$out.='</script>'.N;
} elseif ($_GET['m']=='remove') {
$lnres=mysqli_query($link,'SELECT * FROM '.$lntable.' WHERE '.$lncolumn.'='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
$nlinking=mysqli_num_rows($lnres);
if ($nlinking>0) {
$out.='<div class="hiflab">«'.hspech($row[$column]).'» is referenced by '.$nlinking.' '.(($nlinking==1) ? 'instance' : 'instances').'!</div>'.N;
$out.='<div class="hifdiv">What do you want to do with '.(($nlinking==1) ? 'this reference' : 'those '.$nlinking.' references').'?<br>If you choose “Delete” '.(($nlinking==1) ? 'it' : 'they').' will be removed; otherwise you can select a substitution record.</div>'.N;
$out.='<select id="subst" name="subst" class="hifinp">'.N;
$out.='<option value="0">Delete</option>'.N;
$lnres=mysqli_query($link,'SELECT * FROM '.$table.' WHERE ID!='.$id.' ORDER BY '.$column.' ASC')
or muoribene(__LINE__.': '.mysqli_error($link),true);
if (mysqli_num_rows($rres)>0)
muoribene('You cant modify an entry that has already been linked by others.',true);
}
if ($_GET['m']=='edit') {
$out.='<div class="hiflab"><label for="v">'.$title.'</label></div>'.N;
$out.='<input type="text" class="hifinp" name="v" id="v" maxlength="'.$tables[$table][$column].'" value="'.hspech($row[$column]).'">'.N;
$out.='<script language="JavaScript">'.N;
$out.='<!--'.N;
$out.='document.getElementById(\'v\').focus();'.N;
$out.='document.getElementById(\'v\').select();'.N;
$out.='//-->'.N;
$out.='</script>'.N;
} elseif ($_GET['m']=='remove') {
$lnres=mysqli_query($link,'SELECT * FROM '.$lntable.' WHERE '.$lncolumn.'='.$id)
or muoribene(__LINE__.': '.mysqli_error($link),true);
$nlinking=mysqli_num_rows($lnres);
if ($nlinking>0) {
$out.='<div class="hiflab">«'.hspech($row[$column]).'» is referenced by '.$nlinking.' '.(($nlinking==1) ? 'instance' : 'instances').'!</div>'.N;
$out.='<div class="hifdiv">What do you want to do with '.(($nlinking==1) ? 'this reference' : 'those '.$nlinking.' references').'?<br>If you choose “Delete” '.(($nlinking==1) ? 'it' : 'they').' will be removed; otherwise you can select a substitution record.</div>'.N;
$out.='<select id="subst" name="subst" class="hifinp">'.N;
$out.='<option value="0">Delete</option>'.N;
$lnres=mysqli_query($link,'SELECT * FROM '.$table.' WHERE ID!='.$id.' ORDER BY '.$column.' ASC')
or muoribene(__LINE__.': '.mysqli_error($link),true);
while ($lnrow=mysqli_fetch_assoc($lnres)) {
$out.='<option value="'.$lnrow['ID'].'">Subst. with «'.hspech($lnrow[$column]).'»</option>'.N;
}
$out.='</select>'.N;
} else {
$out.='<input type="hidden" name="subst" value="0">'.N;
while ($lnrow=mysqli_fetch_assoc($lnres)) {
$out.='<option value="'.$lnrow['ID'].'">Subst. with «'.hspech($lnrow[$column]).'»</option>'.N;
}
$out.='<div class="hiflab">Are you sure you want to remove «'.$row[$column].'»?</div>'.N;
$out.='<input type="hidden" name="v" value="IGNORAMI">'.N;
$out.='</select>'.N;
} else {
$out.='<input type="hidden" name="subst" value="0">'.N;
}
$out.='<input type="hidden" name="i" value="'.$id.'">'.N;
} else {
$out.='<p>There is no '.$title.' with ID='.$id.'</p>'.N;
$out.='<div class="hiflab">Are you sure you want to remove «'.$row[$column].'»?</div>'.N;
$out.='<input type="hidden" name="v" value="IGNORAMI">'.N;
}
$out.='<input type="hidden" name="i" value="'.$id.'">'.N;
} elseif ($_GET['m']=='add') {
$out.='<div class="hiflab"><label for="v">'.$title.'</label></div>'.N;
$out.='<input type="text" class="hifinp" name="v" id="v" maxlength="'.$tables[$table][$column].'" value="">'.N;
@ -403,7 +455,7 @@ function ckf(mode,table) {
if (ok) {
var wdiv=document.getElementById('wait');
if (table=='Localities' && mode!='remove')
wdiv.innerHTML='Fetching data from OpenStreetMap.org ...';
wdiv.innerHTML='Fetching data from OpenStreetMap.org (can take some time) ...';
else
wdiv.innerHTML='Sending data ...';
wdiv.style.display='block';
@ -414,14 +466,16 @@ function ckf(mode,table) {
}
function subosmd(osmid) {
document.getElementById('LocXX').value=document.getElementById('LocXX-'+osmid).value;
document.getElementById('LocEN').value=document.getElementById('LocEN-'+osmid).value;
document.getElementById('LocES').value=document.getElementById('LocES-'+osmid).value;
document.getElementById('LocFR').value=document.getElementById('LocFR-'+osmid).value;
document.getElementById('LocIT').value=document.getElementById('LocIT-'+osmid).value;
if (document.getElementById('LocXX').value=='' || document.getElementById('LocEN').value=='' || document.getElementById('LocES').value=='' || document.getElementById('LocFR').value=='' || document.getElementById('LocIT').value=='') {
alert('NO GOOD!');
if (document.getElementById('OSMID-'+osmid).value=='' || document.getElementById('LocXX-'+osmid).value=='' || document.getElementById('LocCA-'+osmid).value=='' || document.getElementById('LocEN-'+osmid).value=='' || document.getElementById('LocES-'+osmid).value=='' || document.getElementById('LocFR-'+osmid).value=='' || document.getElementById('LocIT-'+osmid).value=='') {
alerta('<p>Couldnt save this entry: missing data for one or more languages.</p>',true);
} else {
document.getElementById('OSMID').value=document.getElementById('OSMID-'+osmid).value;
document.getElementById('LocXX').value=document.getElementById('LocXX-'+osmid).value;
document.getElementById('LocCA').value=document.getElementById('LocCA-'+osmid).value;
document.getElementById('LocEN').value=document.getElementById('LocEN-'+osmid).value;
document.getElementById('LocES').value=document.getElementById('LocES-'+osmid).value;
document.getElementById('LocFR').value=document.getElementById('LocFR-'+osmid).value;
document.getElementById('LocIT').value=document.getElementById('LocIT-'+osmid).value;
document.getElementById('f').submit();
}
}
@ -437,11 +491,20 @@ function subosmd(osmid) {
<?php echo($out); ?>
</div>
</div>
<!--
<div id="debugh">
<?php echo($dbg); ?>
</div>
-->
<div id="wait">
...
</div>
<div id="popup">
<div id="inpopup">
<div id="popupcont">
...
</div>
</div>
</div>
</body>
</html>

View file

@ -7,6 +7,7 @@ require('include/myconn.php');
require('include/getadmacc.php');
require('include/menu.php');
$menu['menu']['selected']=true;
$menu['menu']['submenu']['instances']['selected']=true;
buildmenu($menu);
$dbg='';
@ -21,11 +22,10 @@ $dbg.='<pre>'.print_r($_POST,1).'</pre>';
if (array_key_exists('id',$_POST) && preg_match('/^[0-9]+$/',$_POST['id'])===1) {
$instid=$_POST['id']+0;
$res=mysqli_query($link,'SELECT *, ID AS IID FROM Instances WHERE ID='.$instid)
$res=mysqli_query($link,'SELECT ID FROM Instances WHERE ID='.$instid)
or muoribene(__LINE__.': '.mysqli_error($link),true);
if (mysqli_num_rows($res)!=1)
muoribene(__LINE__.': There is no instance with ID='.$instid.'.');
$inst=mysqli_fetch_assoc($res);
}
if (!array_key_exists('id',$_POST) || !array_key_exists('OurDesc',$_POST) || !array_key_exists('OurDescEN',$_POST))
@ -59,7 +59,7 @@ if (array_key_exists('LocalityID',$_POST)) {
$sets[]='LocalityID=NULL';
}
$que.=implode(', ',$sets).' WHERE ID='.$instid;
$que.=implode(', ',$sets).', LastGuestEdit='.time().' WHERE ID='.$instid;
$dbg.='QUERONA: '.hspech($que).'<br>'.N;
mysqli_query($link,$que) or muoribene(__LINE__.': '.mysqli_error($link),true);
@ -95,6 +95,9 @@ multi($link,$instid,$dbg,'ChosenFinModes','InstFinancing','FinID',__LINE__);
multi($link,$instid,$dbg,'ChosenPolicies','InstPolicies','PolID',__LINE__);
multi($link,$instid,$dbg,'ChosenTags','InstTags','TagID',__LINE__);
$res=mysqli_query($link,'SELECT *, ID AS IID FROM Instances WHERE ID='.$instid)
or muoribene(__LINE__.': '.mysqli_error($link),true);
$inst=mysqli_fetch_assoc($res);
require('include/columns.php');
require('include/dispinst.php');
$out=dispinst($inst,$cols,$link,$dlang,false,0,0);
@ -131,7 +134,7 @@ mysqli_close($link);
</ul>
<div class="mtit">Editing results for «<?php echo($inst['URI']); ?>»</div>
<div id="rightdiv">
<a href="logout.php" class="rlinks"><img src="imgs/esci.svg" title="Sign out"></a>
<img src="imgs/esci.svg" class="rlinks" title="Logout" onclick="document.location.href='logout.php';">
</div>
</div>
</nav>

View file

@ -48,7 +48,7 @@ function hspech($str) {
</ul>
<div class="mtit">Your instances</div>
<div id="rightdiv">
<a href="logout.php" class="rlinks"><img src="imgs/esci.svg" title="Sign out"></a>
<img src="imgs/esci.svg" class="rlinks" title="Logout" onclick="document.location.href='logout.php';">
</div>
</div>
</nav>

View file

@ -5,7 +5,7 @@ header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0"); // Proxies.
define('N',"\n");
$cjrand=rand(0,999999);
$supplangs=['en','es','fr','it'];
$supplangs=['ca','en','es','fr','it'];
$dlang=substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
$dlang=in_array($dlang,$supplangs) ? strtoupper($dlang) : 'EN';

View file

@ -1,70 +1,6 @@
<?php
if ($account['Level']!='guest') {
// questo qua sotto è per fare le prove
/*$menu=array(
'menu'=>array('liadd'=>null, 'href'=>null, 'title'=>'Menu', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>null),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
)
),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'certo'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Certo', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>null),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
)
),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
),
),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
)
),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'forse'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Forse', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>
array(
'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>null),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
)
),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
),
),
'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Log out', 'selected'=>false, 'submenu'=>null)
)
)
);*/
$menu=array(
'menu'=>array('liadd'=>null, 'href'=>null, 'title'=>'Menu', 'selected'=>false, 'submenu'=>
array(
@ -72,7 +8,7 @@ if ($account['Level']!='guest') {
'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null),
'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null),
'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifications', 'selected'=>false, 'submenu'=>null),
'signout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Sign out', 'selected'=>false, 'submenu'=>null)
'signout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Logout', 'selected'=>false, 'submenu'=>null)
)
)
);
@ -82,13 +18,13 @@ if ($account['Level']!='guest') {
array(
'instances'=>array('liadd'=>null, 'href'=>'guestinsts.php', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'account'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Account', 'selected'=>false, 'submenu'=>null),
'signout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Sign out', 'selected'=>false, 'submenu'=>null),
'signout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Logout', 'selected'=>false, 'submenu'=>null),
)
)
);
}
// $menuout va sempre wrappato in <ul></ul> che abbia una classe css come quella che si vede in theme.css (#hmenu ul ecc.)
// $menuout va sempre wrappato in <ul></ul> che abbia una classe css come quella che si vede in theme.css ("#hmenu ul" ecc.)
$menuout='';
function buildmenu($menu,$submenu=false) {
@ -99,10 +35,14 @@ function buildmenu($menu,$submenu=false) {
if (!is_null($arr['submenu'])) $menuout.=' onmouseover="chulsh(this,true)" onmouseout="chulsh(this,false)"';
if ($arr['selected']) $menuout.=' class="hil"';
$menuout.='>';
if (!is_null($arr['href']))
$menuout.='<a href="'.$arr['href'].'">'.$arr['title'].'</a>';
else
if (!is_null($arr['href'])) {
if (!$arr['selected'])
$menuout.='<a href="'.$arr['href'].'">'.$arr['title'].'</a>';
else
$menuout.='<a href="'.$arr['href'].'" class="shref">'.$arr['title'].'</a>';
} else {
$menuout.=$arr['title'];
}
if (!is_null($arr['submenu'])) {
($submenu) ? $class='ulb' : $class='ula';
$menuout.=N.'<ul class="'.$class.'" onmouseover="ulsh(this,true)" onmouseout="ulsh(this,false)">'.N;

View file

@ -936,7 +936,7 @@ function pupoff() {
<div id="rightdiv">
<img src="<?php echo($filtordimgoff); ?>" id="lente" class="rlinks" title="Mostra il pannello di filtraggio e ordinamento" onclick="shideplancia();">
<img src="<?php echo($notifs['imgoff']); ?>" id="bell" class="rlinks" title="Show notifications" onclick="shidenotifs();">
<img src="imgs/esci.svg" class="rlinks" title="Esci" onclick="document.location.href='logout.php';">
<img src="imgs/esci.svg" class="rlinks" title="Logout" onclick="document.location.href='logout.php';">
</div>
</div>
</nav>

View file

@ -361,6 +361,13 @@ input {
display: block;
color: var(--HiColor);
}
#hmenu .shref {
color: black;
}
#hmenu .shref:hover {
color: var(--HiColor);
text-decoration: underline;
}
#hmenu .ula {
position: absolute;
top: 32px;
@ -566,6 +573,10 @@ input {
height: 24px;
line-height: 24px;
}
.edtab .desc {
margin-bottom: 6px;
}
.edtab .butdiv {
width: 22px;
margin-bottom: 1px;
@ -607,13 +618,12 @@ input {
height: 200px;
}
.hifbody {
padding: 5px;
font-size:10pt;
background-color:lightgrey;
background-color: lightgrey;
}
.hifbody p {
margin-top: 0px;
margin-bottom: 5px;
margin: 5px;
font-size: 10pt;
}
.hiftit {
background-color: #6f916f;
@ -663,16 +673,21 @@ input {
.hiferr {
color: red;
}
.hifloc {
.hifloc, .hiflocno {
text-align: left;
background-color: #fff6d5;
background-color: #ccffaa;
border-radius: 3px;
padding: 5px;
margin-bottom: 5px;
margin-left: 5px;
margin-right: 5px;
}
.hifloc:hover {
cursor: pointer;
background-color: #ffe6d5;
background-color: #b3ff80;
}
.hiflocno {
background-color: #ffaaaa;
}
.hiful {
margin: 0;

104
web/admin/tools/addlang.php Executable file
View file

@ -0,0 +1,104 @@
#!/bin/php
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$newlang='CA';
$newlangcode=strtolower($newlang);
$email='pezcurrel@tiscali.it';
require(__DIR__.'/../include/mb_ucfirst.php');
define('N',"\n");
use function mysqli_real_escape_string as myesc;
$inifp=__DIR__.'/../sec/mastostartadmin.ini';
$iniarr=@parse_ini_file($inifp)
or mexit('Impossibile aprire il file di configurazione «'.$inifp.'»'.N,1);
$link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
or mexit('Impossibile connettersi al server MySQL: '.mysqli_connect_error().N,1);
mysqli_set_charset($link,'utf8mb4')
or mexit(mysqli_error($link).N,1);
$res=mysqli_query($link,'SELECT ID, Code FROM Languages')
or mexit(mysqli_error($link).N,2);
while ($row=mysqli_fetch_assoc($res)) {
$que='UPDATE Languages SET Name'.$newlang.'=\''.myesc($link,mb_ucfirst(locale_get_display_name($row['Code'],$newlangcode))).'\' WHERE ID='.$row['ID'];
echo($que.N);
mysqli_query($link,$que)
or mexit(mysqli_error($link).N,3);
}
$contextopts=array(
'http'=>array(
'timeout'=>5
),
'socket'=>array(
'tcp_nodelay'=>true
)
);
$context=stream_context_create($contextopts);
$addrkeys=array('neighbourhood','borough','suburb','city','municipality','county','district','province','region','state','country');
$res=mysqli_query($link,'SELECT ID, OSMID, NameIT FROM Localities')
or mexit(mysqli_error($link).N,2);
while ($row=mysqli_fetch_assoc($res)) {
$good=false;
$url='https://nominatim.openstreetmap.org/lookup?osm_ids=R'.$row['OSMID'].'&format=json&accept-language='.$newlangcode.'&addressdetails=1&email='.$email;
$osmdil=@file_get_contents($url,false,$context);
if ($osmdil!==false) {
$osmdil=json_decode($osmdil,true);
if (array_key_exists(0,$osmdil) && array_key_exists('address',$osmdil[0])) {
//$osmdil[0]['address']=array(); // simula errore
$dispname=array();
foreach ($addrkeys as $addrkey)
if (array_key_exists($addrkey,$osmdil[0]['address']))
$dispname[]=$osmdil[0]['address'][$addrkey];
if (count($dispname)>0) {
$dispname=array_unique($dispname);
$dispname=implode(', ',$dispname);
$good=true;
} else {
echo($row['NameIT'].': No useful «address» data found in OpenStreetMap lookup data for lang «'.$newlangcode.'».'.N);
}
} else {
echo($row['NameIT'].': No «address» found in OpenStreetMap lookup data for lang «'.$newlangcode.'».'.N);
}
} else {
echo($row['NameIT'].': Couldnt fetch OpenStreetMap lookup data for lang «'.$newlangcode.'».'.N);
}
if ($good) {
$que='UPDATE Localities SET Name'.$newlang.'=\''.myesc($link,$dispname).'\' WHERE ID='.$row['ID'];
echo($que.N);
mysqli_query($link,$que)
or mexit(mysqli_error($link).N,3);
}
}
mysqli_close($link);
exit(0);
function mexit($msg,$rv) {
global $link;
if ($link)
mysqli_close($link);
echo($msg);
exit($rv);
}
?>

View file

@ -30,86 +30,8 @@ $link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_ad
mysqli_set_charset($link,'utf8mb4')
or mexit(mysqli_error($link).N,1);
$tables=array();
$res=mysqli_query($link,'SHOW TABLES')
or mexit(mysqli_error($link).N,1);
while ($row=mysqli_fetch_row($res)) {
$resb=mysqli_query($link,'SHOW COLUMNS FROM '.$row[0])
or mexit(mysqli_error($link).N,1);
$fields=array();
// lo uso solo per alcuni tipi, quindi non sto a cercare completezza
while ($rowb=mysqli_fetch_assoc($resb)) {
if (preg_match('/(\w+)\((.*)\)( unsigned)?/',$rowb['Type'],$buf)===1) {
switch ($buf[1]) {
case 'char':
case 'varchar':
$fields[$rowb['Field']]=$buf[2];
break;
case 'tinyint':
if (array_key_exists(3,$buf))
$fields[$rowb['Field']]=array('min'=>0,'max'=>255);
else
$fields[$rowb['Field']]=array('min'=>-128,'max'=>127);
break;
case 'smallint':
if (array_key_exists(3,$buf))
$fields[$rowb['Field']]=array('min'=>0,'max'=>65535);
else
$fields[$rowb['Field']]=array('min'=>-32768,'max'=>32767);
break;
case 'mediumint':
if (array_key_exists(3,$buf))
$fields[$rowb['Field']]=array('min'=>0,'max'=>16777215);
else
$fields[$rowb['Field']]=array('min'=>-8388608,'max'=>8388607);
break;
case 'int':
if (array_key_exists(3,$buf))
$fields[$rowb['Field']]=array('min'=>0,'max'=>4294967295);
else
$fields[$rowb['Field']]=array('min'=>-2147483648,'max'=>2147483647);
break;
// bigint non ci sta in php a meno di usare bcmath o gmp che non è detto siano abilitate sul server, in ogni caso poco importa perché valori bigint vengono usati solo internamente al db, non "vengono da fuori"
case 'bigint':
if (array_key_exists(3,$buf))
$fields[$rowb['Field']]=array('min'=>'0','max'=>'18446744073709551615');
else
$fields[$rowb['Field']]=array('min'=>'-9223372036854775808','max'=>'9223372036854775807');
break;
case 'decimal':
// questo è da testare contro un decimale vero
// fatto, il risultato è che in mysql devo usare decimal(14,4)
if (preg_match('/,/',$buf[2])===1) {
$lim=explode(',',$buf[2]);
} else {
$lim[0]=$buf[2];
$lim[1]=0;
}
$int=$lim[0]-$lim[1];
$sint='';
for ($i=0; $i<$int; $i++)
$sint.='9';
$sdec='';
for ($i=0; $i<$lim[1]; $i++)
$sdec.='9';
$max=$sint.'.'.$sdec;
if (array_key_exists(3,$buf))
$fields[$rowb['Field']]=array('min'=>0,'max'=>floatval($max));
else
$fields[$rowb['Field']]=array('min'=>floatval('-'.$max),'max'=>floatval($max));
break;
default:
$fields[$rowb['Field']]=$rowb['Type'];
break;
}
} elseif ($rowb['Type']=='text') {
$fields[$rowb['Field']]=65535;
} else {
$fields[$rowb['Field']]=$rowb['Type'];
}
}
$tables[$row[0]]=$fields;
}
require(__DIR__.'/../include/tables.php');
$tables=tables($link);
$localesfp='locales.json';
$locales=@file_get_contents($localesfp);
@ -119,12 +41,13 @@ $locales=json_decode($locales,true);
print_r($locales);
foreach ($locales as $key=>$val) {
$code=myesc($link,$key);
$NameIt=myesc($link,mb_ucfirst(locale_get_display_name($key,'it')));
$NameOrig=myesc($link,mb_ucfirst(locale_get_display_name($key,$key)));
$NameCa=myesc($link,mb_ucfirst(locale_get_display_name($key,'ca')));
$NameEn=myesc($link,mb_ucfirst(locale_get_display_name($key,'en')));
$NameEs=myesc($link,mb_ucfirst(locale_get_display_name($key,'es')));
$NameFr=myesc($link,mb_ucfirst(locale_get_display_name($key,'fr')));
$NameOrig=myesc($link,mb_ucfirst(locale_get_display_name($key,$key)));
$que='INSERT INTO Languages (ID, Code, NameIT, NameEN, NameES, NameFR, NameOrig) VALUES (NULL, \''.$code.'\', \''.$NameIt.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameOrig.'\')';
$NameIt=myesc($link,mb_ucfirst(locale_get_display_name($key,'it')));
$que='INSERT INTO Languages (ID, Code, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameIt.'\')';
echo($que.N);
mysqli_query($link,$que)
or mexit(mysqli_error($link).N,2);