2020-03-24 23:22:07 +01:00
< ? php
require ( 'include/glob.php' );
require ( 'include/muoribene.php' );
require ( 'include/sessionstart.php' );
require ( 'include/myconn.php' );
2020-04-07 19:39:06 +02:00
require ( 'include/getadmacc.php' );
2020-04-03 10:59:02 +02:00
require ( 'include/tables.php' );
$tables = tables ( $link );
2020-04-07 19:39:06 +02:00
require ( 'include/mb_ucfirst.php' );
2020-05-01 06:51:22 +02:00
require ( 'include/jsencode.php' );
2020-04-03 10:59:02 +02:00
2020-03-24 23:22:07 +01:00
$dbg = '' ;
use function mysqli_real_escape_string as myesc ;
// praticamente una macro
function hspech ( $str ) {
return ( htmlspecialchars ( $str , ENT_QUOTES | ENT_HTML5 , 'UTF-8' ));
}
2020-04-03 10:59:02 +02:00
$contextopts = array (
'http' => array (
'timeout' => 5
),
'socket' => array (
'tcp_nodelay' => true
)
);
$context = stream_context_create ( $contextopts );
2020-03-24 23:22:07 +01:00
2020-04-21 12:35:53 +02:00
$langs = array ( 'xx' => 'Local language' , 'ca' => 'Català' , 'en' => 'English' , 'es' => 'Español' , 'fr' => 'Français' , 'it' => 'Italiano' );
2020-04-03 10:59:02 +02:00
$exvalsjsarr = 'null;' . N ;
$morejs = '' ;
2020-03-24 23:22:07 +01:00
2020-04-03 10:59:02 +02:00
$dbg .= '<pre>GET:' . N . print_r ( $_GET , 1 ) . 'POST:' . N . print_r ( $_POST , 1 ) . '</pre>' ;
2020-04-21 12:35:53 +02:00
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 can’ t modify an entry you didn’ t add.' , true );
if ( $table != 'Localities' ) {
2020-05-01 06:51:22 +02:00
$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 GuestID=' . $account [ 'ID' ] . ')' ;
2020-04-21 12:35:53 +02:00
} else {
2020-05-01 06:51:22 +02:00
$que = 'SELECT * FROM Instances WHERE LocalityID=' . $id . ' AND Instances.ID NOT IN (SELECT ID FROM Instances WHERE GuestID=' . $account [ 'ID' ] . ')' ;
2020-04-21 12:35:53 +02:00
}
$rres = mysqli_query ( $link , $que )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ) . '<br>Query: ' . hspech ( $que ), true );
if ( mysqli_num_rows ( $rres ) > 0 )
muoribene ( 'You can’ t 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 can’ t add more «' . $table . '»<br>entries (' . $account [ 'Max' . $table ] . ' max).' , true );
}
}
}
2020-04-07 19:39:06 +02:00
function edaddrem ( $id , $table , $column , $dispselarr , $lntable , $lncolumn , $searchid , $dispselid , $recbid ) {
global $link , $morejs , $account , $dlang ;
2020-04-21 12:35:53 +02:00
check ( $link , $account , $_POST [ 'm' ], $table , $lntable , $lncolumn , $id );
2020-04-21 15:37:25 +02:00
if ( $_POST [ 'm' ] == 'edit' || $_POST [ 'm' ] == 'add' ) {
$res = mysqli_query ( $link , 'SELECT * FROM ' . $table . ' WHERE ' . $column . '=\'' . myesc ( $link , $_POST [ 'v' ]) . '\'' )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
if ( mysqli_num_rows ( $res ) > 0 )
muoribene ( '«' . hspech ( $_POST [ 'v' ]) . '» already exists!' , true );
}
2020-04-07 19:39:06 +02:00
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' ])),
2020-04-21 12:35:53 +02:00
'NameCA' => mb_ucfirst ( locale_get_display_name ( $_POST [ 'v' ], 'ca' )),
2020-04-07 19:39:06 +02:00
'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' )),
'NameIT' => mb_ucfirst ( locale_get_display_name ( $_POST [ 'v' ], 'it' )));
if ( $_POST [ 'v' ] == $langs [ 'NameOrig' ]) {
muoribene ( '«' . $_POST [ 'v' ] . '»: unknown language identifier.' , true );
} else {
2020-04-21 12:35:53 +02:00
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 )
2020-04-07 19:39:06 +02:00
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$_POST [ 'v' ] = $langs [ 'Name' . $dlang ] . ' [' . $_POST [ 'v' ] . ']' ;
}
}
$morejs .= 'parent.' . $dispselarr . '=parent.cheltxtbyval(parent.' . $dispselarr . ',' . $id . ',"' . jsencode ( $_POST [ 'v' ]) . '");' . N ;
$morejs .= 'parent.' . $dispselarr . '=parent.sortByKey(parent.' . $dispselarr . ',0);' . N ;
2020-04-16 22:56:12 +02:00
$morejs .= 'parent.' . $dispselarr . '=parent.selonebyval(parent.' . $dispselarr . ',' . $id . ');' . N ;
2020-04-07 19:39:06 +02:00
} elseif ( $_POST [ 'm' ] == 'add' ) {
if ( $table != 'Languages' ) {
mysqli_query ( $link , 'INSERT INTO ' . $table . ' (ID, ' . $column . ', AddedBy) VALUES (NULL, \'' . myesc ( $link , $_POST [ 'v' ]) . '\', \'' . $account [ 'ID' ] . '\')' )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$newid = mysqli_insert_id ( $link );
} else {
$langs = array ( 'NameOrig' => mb_ucfirst ( locale_get_display_name ( $_POST [ 'v' ], $_POST [ 'v' ])),
2020-04-21 12:35:53 +02:00
'NameCA' => mb_ucfirst ( locale_get_display_name ( $_POST [ 'v' ], 'ca' )),
2020-04-07 19:39:06 +02:00
'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' )),
'NameIT' => mb_ucfirst ( locale_get_display_name ( $_POST [ 'v' ], 'it' )));
2020-04-16 22:56:12 +02:00
if ( strtolower ( $_POST [ 'v' ]) == strtolower ( $langs [ 'NameOrig' ])) {
2020-04-07 19:39:06 +02:00
muoribene ( '«' . $_POST [ 'v' ] . '»: unknown language identifier.' , true );
} else {
2020-04-21 12:35:53 +02:00
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' ] . ')' )
2020-04-07 19:39:06 +02:00
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$newid = mysqli_insert_id ( $link );
$_POST [ 'v' ] = $langs [ 'Name' . $dlang ] . ' [' . $_POST [ 'v' ] . ']' ;
}
}
2020-04-03 10:59:02 +02:00
$morejs .= 'parent.' . $dispselarr . '.push(["' . jsencode ( $_POST [ 'v' ]) . '",' . $newid . ',true]);' . N ;
$morejs .= 'parent.' . $dispselarr . '=parent.sortByKey(parent.' . $dispselarr . ',0);' . N ;
2020-04-16 22:56:12 +02:00
$morejs .= 'parent.' . $dispselarr . '=parent.selonebyval(parent.' . $dispselarr . ',' . $newid . ');' . N ;
2020-04-03 10:59:02 +02:00
} elseif ( $_POST [ 'm' ] == 'remove' ) {
if ( ! array_key_exists ( 'subst' , $_POST ) || preg_match ( '/^[0-9]+$/' , $_POST [ 'subst' ]) !== 1 )
muoribene ( __LINE__ . ': Malformed input.' , true );
$newid = $_POST [ 'subst' ] + 0 ;
mysqli_query ( $link , 'DELETE FROM ' . $table . ' WHERE ID=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
if ( $newid == 0 ) {
$res = mysqli_query ( $link , 'SELECT * FROM ' . $lntable . ' WHERE ' . $lncolumn . '=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
mysqli_query ( $link , 'DELETE FROM ' . $lntable . ' WHERE ' . $lncolumn . '=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
2020-03-24 23:22:07 +01:00
while ( $row = mysqli_fetch_assoc ( $res )) {
2020-04-03 10:59:02 +02:00
$rres = mysqli_query ( $link , 'SELECT * FROM ' . $lntable . ' WHERE InstID=' . $row [ 'InstID' ] . ' ORDER BY Pos ASC' ) or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$pos = 0 ;
while ( $rrow = mysqli_fetch_assoc ( $rres )) {
$pos ++ ;
mysqli_query ( $link , 'UPDATE ' . $lntable . ' SET Pos=' . $pos . ' WHERE InstID=' . $rrow [ 'InstID' ] . ' AND ' . $lncolumn . '=' . $rrow [ $lncolumn ] . ' AND Pos=' . $rrow [ 'Pos' ])
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
}
2020-03-24 23:22:07 +01:00
}
} else {
2020-04-03 10:59:02 +02:00
$res = mysqli_query ( $link , 'SELECT * FROM ' . $lntable . ' WHERE ' . $lncolumn . '=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
while ( $row = mysqli_fetch_assoc ( $res )) {
$rres = mysqli_query ( $link , 'SELECT * FROM ' . $lntable . ' WHERE InstID=' . $row [ 'InstID' ] . ' AND ' . $lncolumn . '=' . $newid ) or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
if ( mysqli_num_rows ( $rres ) == 0 ) {
mysqli_query ( $link , 'UPDATE ' . $lntable . ' SET ' . $lncolumn . '=' . $newid . ' WHERE InstID=' . $row [ 'InstID' ] . ' AND ' . $lncolumn . '=' . $id . ' AND Pos=' . $row [ 'Pos' ]) or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
2020-04-04 19:17:10 +02:00
//+++ potrebbe aver senso mettere js qui che sposti la voce agli associati se non è già lì, magari con un alerta
2020-04-03 10:59:02 +02:00
} else {
mysqli_query ( $link , 'DELETE FROM ' . $lntable . ' WHERE InstID=' . $row [ 'InstID' ] . ' AND ' . $lncolumn . '=' . $id . ' AND Pos=' . $row [ 'Pos' ]) or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$rres = mysqli_query ( $link , 'SELECT * FROM ' . $lntable . ' WHERE InstID=' . $row [ 'InstID' ] . ' ORDER BY Pos ASC' ) or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$pos = 0 ;
while ( $rrow = mysqli_fetch_assoc ( $rres )) {
$pos ++ ;
mysqli_query ( $link , 'UPDATE ' . $lntable . ' SET Pos=' . $pos . ' WHERE InstID=' . $rrow [ 'InstID' ] . ' AND ' . $lncolumn . '=' . $rrow [ $lncolumn ] . ' AND Pos=' . $rrow [ 'Pos' ])
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
}
}
}
2020-03-24 23:22:07 +01:00
}
2020-04-03 10:59:02 +02:00
$morejs .= 'parent.' . $dispselarr . '=parent.rmelbyval(parent.' . $dispselarr . ',' . $id . ');' . N ;
}
$morejs .= 'parent.filtsel (parent.' . $dispselarr . ', parent.document.getElementById("' . $searchid . '").value, "' . $dispselid . '", "' . $recbid . '", "' . $searchid . '", "white", "#ff8080");' . N ;
2020-04-16 22:56:12 +02:00
$morejs .= 'parent.closeinpup();' . N ;
2020-04-03 10:59:02 +02:00
}
if ( array_key_exists ( 'w' , $_GET ) && array_key_exists ( 'i' , $_GET ) && preg_match ( '/^[0-9]+$/' , $_GET [ 'i' ]) === 1 && array_key_exists ( 'm' , $_GET ) && in_array ( $_GET [ 'm' ], array ( 'edit' , 'add' , 'remove' ))) {
$id = $_GET [ 'i' ] + 0 ;
switch ( $_GET [ 'w' ]) {
case 'LocalityID' :
2020-05-01 06:51:22 +02:00
$out = buildform ( $id , 'Localities' , 'Name' . $dlang , 'Location name' , 'Instances' , 'LocalityID' );
2020-04-04 19:17:10 +02:00
$exvalsjsarr = setjsarr ( 'Localities' , 'Name' . $dlang );
2020-04-03 10:59:02 +02:00
break ;
2020-04-07 19:39:06 +02:00
case 'DispLangs' :
$out = buildform ( $id , 'Languages' , 'Code' , 'Language code' , 'InstOurLangs' , 'OurLangID' );
$exvalsjsarr = setjsarr ( 'Languages' , 'Code' );
break ;
2020-03-24 23:22:07 +01:00
case 'DispFinModes' :
2020-04-21 12:35:53 +02:00
$out = buildform ( $id , 'Financing' , 'Type' , 'Financing modality' , 'InstFinancing' , 'FinID' );
2020-04-03 10:59:02 +02:00
$exvalsjsarr = setjsarr ( 'Financing' , 'Type' );
2020-03-24 23:22:07 +01:00
break ;
case 'DispPolicies' :
2020-04-07 19:39:06 +02:00
$out = buildform ( $id , 'Policies' , 'Name' , 'Policy' , 'InstPolicies' , 'PolID' );
2020-04-03 10:59:02 +02:00
$exvalsjsarr = setjsarr ( 'Policies' , 'Name' );
2020-03-24 23:22:07 +01:00
break ;
case 'DispTags' :
2020-04-07 19:39:06 +02:00
$out = buildform ( $id , 'Tags' , 'Name' , 'Tag' , 'InstTags' , 'TagID' );
2020-04-03 10:59:02 +02:00
$exvalsjsarr = setjsarr ( 'Tags' , 'Name' );
2020-03-24 23:22:07 +01:00
break ;
default :
2020-04-03 10:59:02 +02:00
muoribene ( __LINE__ . ': Malformed input.' , true );
2020-03-24 23:22:07 +01:00
break ;
}
2020-04-07 19:39:06 +02:00
} elseif ( array_key_exists ( 'm' , $_POST ) && in_array ( $_POST [ 'm' ], array ( 'edit' , 'add' , 'remove' )) && array_key_exists ( 't' , $_POST ) && in_array ( $_POST [ 't' ], array ( 'Localities' , 'Languages' , 'Financing' , 'Policies' , 'Tags' )) && array_key_exists ( 'i' , $_POST ) && preg_match ( '/^[0-9]+$/' , $_POST [ 'i' ]) === 1 ) {
2020-04-16 22:56:12 +02:00
$id = $_POST [ 'i' ] + 0 ;
2020-04-03 10:59:02 +02:00
if ( array_key_exists ( 'v' , $_POST )) {
2020-04-07 19:39:06 +02:00
$out = '' ;
2020-04-03 10:59:02 +02:00
if ( $_POST [ 't' ] == 'Localities' ) {
2020-04-16 22:56:12 +02:00
if ( $_POST [ 'm' ] != 'remove' ) {
2020-04-03 10:59:02 +02:00
//https://nominatim.openstreetmap.org/search?q=bresso,+milano&format=json&accept-language=fr&email=pezcurrel@tiscali.it
//https://nominatim.openstreetmap.org/lookup?osm_ids=R45266&format=json&accept-language=fr&addressdetails=1&email=pezcurrel@tiscali.it
2020-05-03 19:55:24 +02:00
$url = 'https://nominatim.openstreetmap.org/search?q=' . urlencode ( $_POST [ 'v' ]) . '&format=json&email=' . $iniarr [ 'ref_email' ];
2020-04-16 22:56:12 +02:00
$osmd =@ file_get_contents ( $url , false , $context );
if ( $osmd !== false ) {
$osmd = json_decode ( $osmd , true );
if ( count ( $osmd ) > 0 ) {
2020-04-21 12:35:53 +02:00
$addrkeys = array ( 'neighbourhood' , 'borough' , 'suburb' , 'city' , 'municipality' , 'county' , 'district' , 'province' , 'region' , 'state' , 'country' );
$onegood = false ;
$divs = '' ;
2020-04-16 22:56:12 +02:00
foreach ( $osmd as $loc ) {
2020-04-21 12:35:53 +02:00
$good = false ;
$div = '' ;
//$loc=array(); // simula errore
2020-04-16 22:56:12 +02:00
if ( array_key_exists ( 'osm_id' , $loc ) && array_key_exists ( 'osm_type' , $loc ) && $loc [ 'osm_type' ] == 'relation' ) {
2020-04-21 12:35:53 +02:00
$div .= '<input type="hidden" id="OSMID-' . $loc [ 'osm_id' ] . '" value="' . $loc [ 'osm_id' ] . '">' . N ;
$div .= '<ul class="hiful">' . N ;
2020-04-16 22:56:12 +02:00
foreach ( $langs as $code => $lang ) {
2020-04-21 12:35:53 +02:00
$hidval = '' ;
2020-05-03 19:55:24 +02:00
$url = 'https://nominatim.openstreetmap.org/lookup?osm_ids=R' . $loc [ 'osm_id' ] . '&format=json&accept-language=' . $code . '&addressdetails=1&email=' . $iniarr [ 'ref_email' ];
2020-04-16 22:56:12 +02:00
$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 ])) {
2020-04-21 12:35:53 +02:00
//$osmdil[0]['address']=array(); // simula errore
$dispname = array ();
2020-04-16 22:56:12 +02:00
foreach ( $addrkeys as $addrkey )
if ( array_key_exists ( $addrkey , $osmdil [ 0 ][ 'address' ]))
2020-04-21 12:35:53 +02:00
$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 ;
}
2020-04-16 22:56:12 +02:00
} else {
2020-04-21 12:35:53 +02:00
$div .= '<li><strong>' . $lang . ':</strong> <span class="hiferr">No «address» found in OpenStreetMap lookup data.</span></li>' . N ;
2020-04-16 22:56:12 +02:00
}
2020-04-03 10:59:02 +02:00
} else {
2020-04-21 12:35:53 +02:00
$div .= '<li><strong>' . $lang . ':</strong> <span class="hiferr">Couldn’ t fetch OpenStreetMap lookup data.</span></li>' . N ;
2020-04-03 10:59:02 +02:00
}
2020-04-21 12:35:53 +02:00
$div .= '<input type="hidden" id="Loc' . strtoupper ( $code ) . '-' . $loc [ 'osm_id' ] . '" value="' . $hidval . '">' . N ;
}
if ( $good ) {
$onegood = true ;
$divs .= '<div class="hifloc" onclick="subosmd(\'' . $loc [ 'osm_id' ] . '\');">' . N . $div ;
} else {
$divs .= '<div class="hiflocno">' . N . $div ;
2020-04-03 10:59:02 +02:00
}
2020-04-21 12:35:53 +02:00
$divs .= '</ul>' . N . '</div>' . N ;
2020-04-03 10:59:02 +02:00
}
}
2020-04-21 12:35:53 +02:00
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 ;
2020-04-16 22:56:12 +02:00
$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 ;
2020-04-21 12:35:53 +02:00
$out .= '<input type="hidden" id="OSMID" name="OSMID" value="">' . N ;
2020-04-16 22:56:12 +02:00
$out .= '<input type="hidden" id="LocXX" name="LocXX" value="">' . N ;
2020-04-21 12:35:53 +02:00
$out .= '<input type="hidden" id="LocCA" name="LocCA" value="">' . N ;
2020-04-16 22:56:12 +02:00
$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 {
2020-04-21 12:35:53 +02:00
$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 ;
2020-04-16 22:56:12 +02:00
}
2020-04-03 10:59:02 +02:00
} else {
2020-04-16 22:56:12 +02:00
$out = '<p class="hiferr">Couldn’ t find OpenStreetMap data for «' . hspech ( $_POST [ 'v' ]) . '».</p>' ;
2020-04-03 10:59:02 +02:00
}
} else {
2020-04-16 22:56:12 +02:00
$out = '<p class="hiferr">Couldn’ t fetch OpenStreetMap search data.</p>' . N ;
2020-04-03 10:59:02 +02:00
}
} else {
2020-04-16 22:56:12 +02:00
// locality remove
2020-04-21 12:35:53 +02:00
check ( $link , $account , $_POST [ 'm' ], 'Localities' , 'Instances' , 'LocalityID' , $id );
2020-04-16 22:56:12 +02:00
$out = 'CANCELLO!' ;
if ( ! array_key_exists ( 'subst' , $_POST ) || preg_match ( '/^[0-9]+$/' , $_POST [ 'subst' ]) !== 1 )
muoribene ( __LINE__ . ': Malformed input.' , true );
$_POST [ 'subst' ] += 0 ;
if ( $_POST [ 'subst' ] == 0 ) {
mysqli_query ( $link , 'UPDATE Instances SET LocalityID=NULL WHERE LocalityID=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
} else {
mysqli_query ( $link , 'UPDATE Instances SET LocalityID=' . $_POST [ 'subst' ] . ' WHERE LocalityID=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
}
mysqli_query ( $link , 'DELETE FROM Localities WHERE ID=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$morejs .= 'parent.locselarr=parent.rmelbyval(parent.locselarr,' . $id . ');' . N ;
$morejs .= 'parent.filtsel (parent.locselarr, parent.document.getElementById("locsearch").value, "LocalityID", "locselre", "locsearch", "white", "#ff8080");' . N ;
$morejs .= 'parent.closeinpup();' . N ;
2020-04-03 10:59:02 +02:00
}
2020-04-07 19:39:06 +02:00
} elseif ( $_POST [ 't' ] == 'Languages' ) {
edaddrem ( $id , 'Languages' , 'Name' . $dlang , 'langselarr' , 'InstOurLangs' , 'OurLangID' , 'langsearch' , 'DispLangs' , 'langselre' );
2020-04-03 10:59:02 +02:00
} elseif ( $_POST [ 't' ] == 'Financing' ) {
2020-04-07 19:39:06 +02:00
edaddrem ( $id , 'Financing' , 'Type' , 'finselarr' , 'InstFinancing' , 'FinID' , 'finsearch' , 'DispFinModes' , 'finselre' );
2020-04-03 10:59:02 +02:00
} elseif ( $_POST [ 't' ] == 'Policies' ) {
2020-04-07 19:39:06 +02:00
edaddrem ( $id , 'Policies' , 'Name' , 'polselarr' , 'InstPolicies' , 'PolID' , 'polsearch' , 'DispPolicies' , 'polselre' );
2020-04-03 10:59:02 +02:00
} elseif ( $_POST [ 't' ] == 'Tags' ) {
2020-04-07 19:39:06 +02:00
edaddrem ( $id , 'Tags' , 'Name' , 'tagselarr' , 'InstTags' , 'TagID' , 'tagsearch' , 'DispTags' , 'tagselre' );
} else {
// questo è ridondante ma fa niente
muoribene ( __LINE__ . ': Malformed input.' , true );
2020-04-03 10:59:02 +02:00
}
2020-04-21 12:35:53 +02:00
} 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 )) {
2020-04-16 22:56:12 +02:00
// locality edit/add
2020-04-21 12:35:53 +02:00
check ( $link , $account , $_POST [ 'm' ], 'Localities' , 'Instances' , 'LocalityID' , $id );
2020-04-21 15:37:25 +02:00
$res = mysqli_query ( $link , 'SELECT * FROM Localities WHERE Name' . $dlang . '=\'' . myesc ( $link , $_POST [ 'Loc' . $dlang ]) . '\'' )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
if ( mysqli_num_rows ( $res ) > 0 )
muoribene ( '«' . hspech ( $_POST [ 'Loc' . $dlang ]) . '» already exists!' , true );
2020-04-16 22:56:12 +02:00
$out = 'EDITO/AGGIUNGO!' ;
if ( $_POST [ 'm' ] == 'add' ) {
2020-04-21 12:35:53 +02:00
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' ] . '\')' )
2020-04-16 22:56:12 +02:00
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' ) {
2020-04-21 12:35:53 +02:00
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 )
2020-04-16 22:56:12 +02:00
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
$morejs .= 'parent.locselarr=parent.cheltxtbyval(parent.locselarr,' . $id . ',"' . jsencode ( $_POST [ 'Loc' . $dlang ]) . '");' . N ;
}
$morejs .= 'parent.locselarr=parent.sortByKey(parent.locselarr,0);' . N ;
$morejs .= 'parent.locselarr=parent.selonebyval(parent.locselarr,' . $id . ');' . N ;
$morejs .= 'parent.filtsel (parent.locselarr, parent.document.getElementById("locsearch").value, "LocalityID", "locselre", "locsearch", "white", "#ff8080");' . N ;
$morejs .= 'parent.closeinpup();' . N ;
2020-04-03 10:59:02 +02:00
} else {
muoribene ( __LINE__ . ': Malformed input.' , true );
}
2020-03-24 23:22:07 +01:00
} else {
2020-04-03 10:59:02 +02:00
muoribene ( __LINE__ . ': Malformed input.' , true );
}
function buildform ( $id , $table , $column , $title , $lntable , $lncolumn ) {
2020-04-05 22:45:21 +02:00
global $account , $tables , $link ;
2020-04-21 12:35:53 +02:00
check ( $link , $account , $_GET [ 'm' ], $table , $lntable , $lncolumn , $id );
2020-04-07 19:39:06 +02:00
$out = '' ;
2020-04-03 10:59:02 +02:00
if ( $_GET [ 'm' ] == 'edit' || $_GET [ 'm' ] == 'remove' ) {
$res = mysqli_query ( $link , 'SELECT * FROM ' . $table . ' WHERE ID=' . $id )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
2020-04-21 12:35:53 +02:00
$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' )
2020-04-03 10:59:02 +02:00
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
2020-04-21 12:35:53 +02:00
while ( $lnrow = mysqli_fetch_assoc ( $lnres )) {
$out .= '<option value="' . $lnrow [ 'ID' ] . '">Subst. with «' . hspech ( $lnrow [ $column ]) . '»</option>' . N ;
2020-04-03 10:59:02 +02:00
}
2020-04-21 12:35:53 +02:00
$out .= '</select>' . N ;
} else {
$out .= '<input type="hidden" name="subst" value="0">' . N ;
2020-04-03 10:59:02 +02:00
}
2020-04-21 12:35:53 +02:00
$out .= '<div class="hiflab">Are you sure you want to remove «' . $row [ $column ] . '»?</div>' . N ;
$out .= '<input type="hidden" name="v" value="IGNORAMI">' . N ;
2020-04-03 10:59:02 +02:00
}
2020-04-21 12:35:53 +02:00
$out .= '<input type="hidden" name="i" value="' . $id . '">' . N ;
2020-04-03 10:59:02 +02:00
} elseif ( $_GET [ 'm' ] == 'add' ) {
2020-04-07 19:39:06 +02:00
$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 ;
$out .= '<script language="JavaScript">' . N ;
$out .= '<!--' . N ;
$out .= 'document.getElementById(\'v\').focus();' . N ;
$out .= 'document.getElementById(\'v\').select();' . N ;
$out .= '//-->' . N ;
$out .= '</script>' . N ;
$out .= '<input type="hidden" name="i" value="0">' . N ;
2020-04-03 10:59:02 +02:00
}
2020-04-07 19:39:06 +02:00
$out .= '<input type="hidden" name="m" value="' . $_GET [ 'm' ] . '">' . N ;
$out .= '<input type="hidden" name="t" value="' . $table . '">' . N ;
$out .= '<div id="errmsg"></div>' . N ;
$out .= '<table class="hiftab"><tr><td style="width:50%"><input type="button" value="Cancel" class="hifbut" onclick="parent.closeinpup()"></td><td style="width:50%"><input type="button" value="Ok" class="hifbut" onclick="ckf(\'' . $_GET [ 'm' ] . '\',\'' . $table . '\')"></td></tr></table>' . N ;
$out = '<form action="edinsth.php" method="post" id="f" onsubmit="return ckf(\'' . $_GET [ 'm' ] . '\',\'' . $table . '\');">' . N . $out . '</form>' . N ;
return ( $out );
2020-04-03 10:59:02 +02:00
}
function setjsarr ( $table , $column ) {
global $link ;
$jsarr = array ();
$res = mysqli_query ( $link , 'SELECT ' . $column . ' FROM ' . $table )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ), true );
while ( $row = mysqli_fetch_assoc ( $res )) {
$jsarr [] = jsencode ( strtolower ( $row [ $column ]));
}
$jsarr = '["' . implode ( '","' , $jsarr ) . '"];' . N ;
return ( $jsarr );
2020-03-24 23:22:07 +01:00
}
mysqli_close ( $link );
?>
<! DOCTYPE HTML >
2020-04-03 10:59:02 +02:00
< html lang = " en " >
2020-03-24 23:22:07 +01:00
< head >
2020-05-01 06:51:22 +02:00
< title > Mustard - Little edit’ s helper </ title >
2020-03-24 23:22:07 +01:00
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " >
< meta name = " description " content = " Admin pages for Mastodon Startpage " >
< meta name = " viewport " content = " width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no " >
< script language = " JavaScript " src = " js/confirma.js?v=<?php echo( $cjrand ); ?> " ></ script >
< script language = " JavaScript " src = " js/alerta.js?v=<?php echo( $cjrand ); ?> " ></ script >
< link rel = " stylesheet " type = " text/css " href = " theme.css?v=<?php echo( $cjrand ); ?> " >
< script language = " JavaScript " >
<!--
2020-04-03 10:59:02 +02:00
exvalsarr =< ? php echo ( $exvalsjsarr ); ?>
function ckf ( mode , table ) {
var ok = false ;
if ( mode == 'remove' ) {
ok = true ;
} else if ( mode == 'add' || mode == 'edit' ) {
var val = document . getElementById ( 'v' ) . value . trim (), vallow = val . toLowerCase (), len = exvalsarr . length , i = 0 , found = false ;
document . getElementById ( 'v' ) . value = val ;
if ( val != '' ) {
for ( i = 0 ; i < len ; i ++ ) {
if ( exvalsarr [ i ] == vallow ) {
found = true ;
break ;
}
}
if ( found ) {
document . getElementById ( 'errmsg' ) . innerHTML = '«' + val + '» already exists!' ;
} else {
ok = true ;
}
} else {
document . getElementById ( 'errmsg' ) . innerHTML = 'You can’ t submit an empty value!' ;
}
}
if ( ok ) {
var wdiv = document . getElementById ( 'wait' );
2020-04-16 22:56:12 +02:00
if ( table == 'Localities' && mode != 'remove' )
2020-04-21 12:35:53 +02:00
wdiv . innerHTML = 'Fetching data from OpenStreetMap.org (can take some time) ...' ;
2020-04-03 10:59:02 +02:00
else
wdiv . innerHTML = 'Sending data ...' ;
wdiv . style . display = 'block' ;
document . getElementById ( 'f' ) . submit ();
} else {
return false ;
}
}
function subosmd ( osmid ) {
2020-04-21 12:35:53 +02:00
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 == '' ) {
2020-05-01 06:51:22 +02:00
alerta ( 'Error' , '<p>Couldn’ t save this entry: missing data for one or more languages.</p>' );
2020-04-03 10:59:02 +02:00
} else {
2020-04-21 12:35:53 +02:00
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 ;
2020-04-03 10:59:02 +02:00
document . getElementById ( 'f' ) . submit ();
}
}
< ? php echo ( $morejs ); ?>
2020-03-24 23:22:07 +01:00
//-->
</ script >
</ head >
2020-04-03 10:59:02 +02:00
< body class = " hifbody " >
2020-03-24 23:22:07 +01:00
< div id = " fullscreen " >
< div id = " middlerow " >
2020-04-07 19:39:06 +02:00
< ? php echo ( $out ); ?>
2020-03-24 23:22:07 +01:00
</ div >
</ div >
2020-04-21 12:35:53 +02:00
<!--
2020-04-16 22:56:12 +02:00
< div id = " debugh " >
2020-03-24 23:22:07 +01:00
< ? php echo ( $dbg ); ?>
2020-04-16 22:56:12 +02:00
</ div >
2020-04-21 12:35:53 +02:00
-->
2020-04-03 10:59:02 +02:00
< div id = " wait " >
...
</ div >
2020-04-21 12:35:53 +02:00
< div id = " popup " >
< div id = " inpopup " >
< div id = " popupcont " >
...
</ div >
</ div >
</ div >
2020-03-24 23:22:07 +01:00
</ body >
</ html >