1
0
Fork 0
MastodonStartpage/web/admin/edinst.php
pezcurrel bd2c5a80cb ...
2020-03-10 11:28:30 +01:00

492 lines
16 KiB
PHP

<?php
require('include/glob.php');
require('include/muoribene.php');
require('include/sessionstart.php');
require('include/menu.php');
$menu['istanze']['href']=null;
$menu['istanze']['selected']=true;
$menu['istanze']['submenu']['modifica']['href']=null;
$menu['istanze']['submenu']['modifica']['selected']=true;
buildmenu($menu);
require('include/myconn.php');
$dbg='';
use function mysqli_real_escape_string as myesc;
// praticamente una macro
function hspech($str) {
return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8'));
}
$dbg.='<pre>'.print_r($_POST,1).'</pre>';
mysqli_close($link);
?>
<!DOCTYPE HTML>
<html lang="it">
<head>
<title>Mastodon Startpage Admin - Modifica di «<?php echo($data['URI']); ?>»</title>
<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">
<link rel="icon" type="image/png" href="imgs/icona-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="imgs/icona-192.png" sizes="192x192">
<link rel="icon" type="image/png" href="imgs/icona-512.png" sizes="512x512">
<link rel="apple-touch-icon-precomposed" href="imgs/icona-180.png">
<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">
<!--
function chulsh(el,sh) {
if (sh)
el.querySelector('ul').style.display='block';
else
el.querySelector('ul').style.display='none';
}
function ulsh(el,sh) {
if (sh)
el.style.display='block';
else
el.style.display='none';
}
function shideplancia() {
var plancia=document.getElementById('plancia');
var plctrl=document.getElementById('plctrl');
if (plancia.style.display=='block') {
plancia.style.display='none';
plctrl.innerHTML='Mostra plancia';
} else {
plancia.style.display='block';
plctrl.innerHTML='Nascondi plancia';
}
}
function truncsel(el) {
var sel=document.getElementById(el), len=sel.length, i=0;
for (i=len-1; i>=0; i--)
sel.remove(i);
}
function addselopt(el,val,txt) {
option=new Option(txt,val);
el.add(option);
}
function inpdisif(index) {
console.log('inpdisif index: '+index);
var source=document.getElementById('condsel-'+index);
var inp=document.getElementById('valueinp-'+index);
var sel=document.getElementById('valuesel-'+index);
var conds=['IS NULL','IS NOT NULL'];
if (conds.includes(source.value)) {
inp.disabled=true;
sel.disabled=true;
} else {
if (inp.style.display!='none') inp.disabled=false;
if (sel.style.display!='none') sel.disabled=false;
}
}
function popusels(index,valselval) {
console.log('popusels index: '+index);
var key=document.getElementById('fieldsel-'+index).value;
var type=key.replace(/^.*:(.*):.*$/,'$1');
var subtype=key.replace(/^.*:.*:(.*)$/,'$1');
key=key.replace(/^(.*):.*:.*$/,'$1');
var condsel=document.getElementById('condsel-'+index);
var valsel=document.getElementById('valuesel-'+index);
var valinp=document.getElementById('valueinp-'+index);
condsel.setAttribute('onchange','inpdisif('+index+');');
if (type=='joini')
type=subtype;
if (type=='bool') {
truncsel('condsel-'+index);
addselopt(condsel,'IS','è');
truncsel('valuesel-'+index);
addselopt(valsel,'TRUE','vero');
addselopt(valsel,'FALSE','falso');
addselopt(valsel,'NOT NULL','definit@');
addselopt(valsel,'NULL','non definit@');
if (valselval!==false)
selind('valuesel-'+index,valselval);
valinp.style.display='none';
valinp.disabled=true;
valsel.style.display='block';
valsel.disabled=false;
} else if (type=='text') {
truncsel('condsel-'+index);
addselopt(condsel,'LIKE','contiene');
addselopt(condsel,'NOT LIKE','non contiene');
addselopt(condsel,'=','è uguale a');
addselopt(condsel,'!=','è divers@ da');
addselopt(condsel,'>=','è maggiore o uguale a');
addselopt(condsel,'<=','è minore o uguale a');
addselopt(condsel,'>','è maggiore di');
addselopt(condsel,'<','è minore di');
addselopt(condsel,'IS NOT NULL','è definit@');
addselopt(condsel,'IS NULL','non è definit@');
valsel.style.display='none';
valsel.disabled=true;
valinp.style.display='block';
valinp.disabled=false;
} else if (type=='int' || type=='time') {
truncsel('condsel-'+index);
addselopt(condsel,'>=','è maggiore o uguale a');
addselopt(condsel,'<=','è minore o uguale a');
addselopt(condsel,'>','è maggiore di');
addselopt(condsel,'<','è minore di');
addselopt(condsel,'=','è uguale a');
addselopt(condsel,'!=','è divers@ da');
addselopt(condsel,'IS NOT NULL','è definit@');
addselopt(condsel,'IS NULL','non è definit@');
valsel.style.display='none';
valsel.disabled=true;
valinp.style.display='block';
valinp.disabled=false;
} else if (type=='join') {
truncsel('condsel-'+index);
addselopt(condsel,'=','è uguale a');
addselopt(condsel,'!=','è divers@ da');
addselopt(condsel,'IS NOT NULL','è definit@');
addselopt(condsel,'IS NULL','non è definit@');
valsel.style.display='block';
valsel.disabled=false;
valinp.style.display='none';
valinp.disabled=true;
truncsel('valuesel-'+index);
pupwait(true);
let xhr=new XMLHttpRequest();
xhr.open('GET','instancesh.php?key='+key);
xhr.responseType='json';
xhr.send();
xhr.onload=function() {
let jarr=xhr.response;
for (i=0; i<jarr.length; i++)
addselopt(valsel,jarr[i][0],jarr[i][1]);
console.log('valsel pronto!');
if (valselval!==false)
selind('valuesel-'+index,valselval);
pupwait(false);
};
xhr.onerror=function() {
alert('Request failed');
};
} else {
alert('Attenziò: non so che farmene del tipo "'+type+'": diglielo, al programmatore.');
}
}
function addrow(index,refresh) {
var table=document.getElementById('planciafil');
var newrow=table.insertRow(index);
var newcell0=newrow.insertCell(0);
var newcell1=newrow.insertCell(1);
var newcell2=newrow.insertCell(2);
var newcell3=newrow.insertCell(3);
var newcell4=newrow.insertCell(4);
var newcell5=newrow.insertCell(5);
var newcell6=newrow.insertCell(6);
var newcell7=newrow.insertCell(7);
newcell0.innerHTML='<select class="openpar"><option value="null"></option><option value="(">(</option><option value="((">((</option><option value="(((">(((</option></select>';
newcell1.innerHTML='<select class="fieldsel"></select>';
newcell2.innerHTML='<select class="condsel"></select>';
newcell3.innerHTML='<select class="valuesel" style="display:none;"></select><input type="text" class="valueinp" maxlength="256" style="display:none;">';
newcell4.innerHTML='<select class="closepar"><option value="null"></option><option value=")">)</option><option value="))">))</option><option value=")))">)))</option></select>';
newcell5.innerHTML='<select class="andor"><option value="AND">E</option><option value="OR">O</option></select>';
newcell6.innerHTML='<img class="plus" src="imgs/plus.svg">';
newcell7.innerHTML='<img class="minus" src="imgs/minus.svg">';
if (refresh) {
synctai();
popusels(index,false);
}
}
function ordaddrow(index,refresh) {
var table=document.getElementById('planciaord');
var newrow=table.insertRow(index);
var newcell0=newrow.insertCell(0);
var newcell1=newrow.insertCell(1);
var newcell2=newrow.insertCell(2);
var newcell3=newrow.insertCell(3);
newcell0.style.width='97%';
newcell1.style.width='1%';
newcell2.style.width='1%';
newcell3.style.width='1%';
newcell0.innerHTML='<select class="ordfieldsel"></select>';
newcell1.innerHTML='<select class="ascdesc"><option value="ASC">Crescente</option><option value="DESC">Decrescente</option></select>';
newcell2.innerHTML='<img class="plus" src="imgs/plus.svg">';
newcell3.innerHTML='<img class="minus" src="imgs/minus.svg">';
if (refresh)
synctoi();
}
function synctai() {
var i=0;
var table=document.getElementById('planciafil');
var nodes=table.querySelectorAll('.minus');
var cnodes=nodes.length;
for (i=0; i<cnodes; i++)
// +1 sempre per via della row iniziale
nodes[i].setAttribute('onclick','remrow('+(i+1)+');');
nodes=table.querySelectorAll('.plus');
for (i=0; i<cnodes; i++)
// +2 perché la devi aggiungere dopo la corrente
nodes[i].setAttribute('onclick','addrow('+(i+2)+',true);');
// da qui in poi faccio a scendere per non avere mai id e nomi duplicati
cnodes--;
nodes=table.querySelectorAll('.openpar');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','openpar-'+(i+1));
nodes[i].setAttribute('name','openpar-'+(i+1));
}
nodes=table.querySelectorAll('.fieldsel');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','fieldsel-'+(i+1));
nodes[i].setAttribute('name','fieldsel-'+(i+1));
nodes[i].setAttribute('onchange','popusels('+(i+1)+',false);');
}
nodes=table.querySelectorAll('.condsel');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','condsel-'+(i+1));
nodes[i].setAttribute('name','condsel-'+(i+1));
nodes[i].setAttribute('onchange','inpdisif('+(i+1)+');');
}
nodes=table.querySelectorAll('.valuesel');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','valuesel-'+(i+1));
nodes[i].setAttribute('name','valuesel-'+(i+1));
}
nodes=table.querySelectorAll('.valueinp');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','valueinp-'+(i+1));
nodes[i].setAttribute('name','valueinp-'+(i+1));
}
nodes=table.querySelectorAll('.closepar');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','closepar-'+(i+1));
nodes[i].setAttribute('name','closepar-'+(i+1));
}
nodes=table.querySelectorAll('.andor');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','andor-'+(i+1));
nodes[i].setAttribute('name','andor-'+(i+1));
nodes[i].disabled=false;
}
if (cnodes>=0)
nodes[cnodes].disabled=true;
}
function synctoi() {
var i=0;
var table=document.getElementById('planciaord');
var nodes=table.querySelectorAll('.minus');
var cnodes=nodes.length;
for (i=0; i<cnodes; i++)
// +1 sempre per via della row iniziale
nodes[i].setAttribute('onclick','ordremrow('+(i+1)+');');
nodes=table.querySelectorAll('.plus');
for (i=0; i<cnodes; i++)
// +2 perché la devi aggiungere dopo la corrente
nodes[i].setAttribute('onclick','ordaddrow('+(i+2)+',true);');
// da qui in poi faccio a scendere per non avere mai id e nomi duplicati
cnodes--;
nodes=table.querySelectorAll('.ordfieldsel');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','ordfieldsel-'+(i+1));
nodes[i].setAttribute('name','ordfieldsel-'+(i+1));
}
nodes=table.querySelectorAll('.ascdesc');
for (i=cnodes; i>-1; i--) {
nodes[i].setAttribute('id','ascdesc-'+(i+1));
nodes[i].setAttribute('name','ascdesc-'+(i+1));
}
}
function selind(id,val) {
var el=document.getElementById(id), i=0, found=false;
while (!found && i<el.length) {
if (el[i].value==val) {
el.selectedIndex=i;
found=true;
}
i++;
}
if (!found)
console.log('"'+val+'" non è stato trovato in "'+id+'"');
}
function setrow(index,openparv,fieldselv,condselv,valueselv,valueinpv,closeparv,andorv) {
selind('openpar-'+index,openparv);
selind('fieldsel-'+index,fieldselv);
popusels(index,valueselv);
selind('condsel-'+index,condselv);
// selind('valuesel-'+index,valueselv);
document.getElementById('valueinp-'+index).value=valueinpv;
if (condselv=='IS NULL' || condselv=='IS NOT NULL') {
document.getElementById('valueinp-'+index).disabled=true;
document.getElementById('valuesel-'+index).disabled=true;
}
selind('closepar-'+index,closeparv);
selind('andor-'+index,andorv);
}
function ordsetrow(index,ordfieldselv,ascdescv) {
selind('ordfieldsel-'+index,ordfieldselv);
selind('ascdesc-'+index,ascdescv);
}
function remrow(index) {
var table=document.getElementById('planciafil');
table.deleteRow(index);
synctai();
if (table.rows.length<2)
document.getElementById('filbut').value='Aggiungi criteri di ricerca';
}
function ordremrow(index) {
var table=document.getElementById('planciaord');
table.deleteRow(index);
synctoi();
if (table.rows.length<2)
document.getElementById('ordbut').value='Aggiungi criteri di ordinamento';
}
function truncfil() {
var table=document.getElementById('planciafil');
while (table.rows.length>1)
remrow(1);
}
function truncord() {
var table=document.getElementById('planciaord');
while (table.rows.length>1)
ordremrow(1);
}
function manfil() {
var filbut=document.getElementById('filbut');
var table=document.getElementById('planciafil');
var crows=table.rows.length;
if (crows<2) {
addrow(1,true);
filbut.value='Rimuovi tutti i criteri di ricerca';
} else {
confirma('<p>Confermi di voler rimuovere tutti i criteri di ricerca?</p>','truncfil();filbut.value=\'Aggiungi criteri di ricerca\'');
}
}
function manord() {
var ordbut=document.getElementById('ordbut');
var table=document.getElementById('planciaord');
var crows=table.rows.length;
if (crows<2) {
ordaddrow(1,true);
ordbut.value='Rimuovi tutti i criteri di ordinamento';
} else {
confirma('<p>Confermi di voler rimuovere tutti i criteri di ordinamento?</p>','truncord();ordbut.value=\'Aggiungi criteri di ordinamento\'');
}
}
function ckpar() {
var i=0;
var table=document.getElementById('planciafil');
var nodes=table.querySelectorAll('.openpar');
var cnodes=nodes.length;
var opars=[];
var cpars=[];
for (i=0; i<cnodes; i++)
opars.push(nodes[i].value);
nodes=table.querySelectorAll('.closepar');
for (i=0; i<cnodes; i++)
cpars.push(nodes[i].value);
var spars='';
for (i=0; i<cnodes; i++) {
if (opars[i]!='null') spars+=opars[i];
if (cpars[i]!='null') spars+=cpars[i];
}
var opq=0, cpq=0, ok=true;
for (i=0; i<spars.length; i++) {
if (spars[i]=='(') {
opq++;
} else if (spars[i]==')') {
cpq++;
}
if (cpq>opq)
break;
}
if (opq!=cpq)
ok=false;
console.log(i+'/'+spars.length+': '+ok);
return ok;
}
function ckf() {
var emsg='';
if (!ckpar()) emsg+='Qualcosa non va con le parentesi!<br>\n';
// emsg+='Comunque NO!<br>\n';
if (emsg=='') {
var table=document.getElementById('planciafil');
var crows=table.rows.length;
if (crows>1)
document.getElementById('andor-'+(crows-1)).disabled=false;
document.getElementById('f').submit();
} else {
alerta('<p>'+emsg+'</p>');
}
}
function pupwait(on) {
var pup=document.getElementById('popup'), inpup=document.getElementById('inpopup');
if (on) {
if (pup.style.display!='table') {
inpup.innerHTML='<div class="waitbub"><img src="imgs/loading.gif"><br>&nbsp;<br>Caricamento in corso...</div>';
pup.style.display='table';
} else {
console.log('Sto già aspettando...');
}
} else {
inpup.innerHTML='<div id="popupcont">...</div>';
pup.style.display='none';
}
}
//-->
</script>
</head>
<body>
<nav>
<div id="hmenu">
<ul>
<?php echo($menuout); ?>
</ul>
<div id="rightdiv">
<div id="logout" class="rlinks" onclick="document.location.href='logout.php'"><a href="logout.php">Esci</a></div>
</div>
</div>
</nav>
<div id="popup">
<div id="inpopup">
<div id="popupcont">
...
</div>
</div>
</div>
<!-- <div id="footer">
</div> -->
<div id="debug">
<?php //echo($dbg); ?>
</div>
<div id="fullscreen">
<div id="middlerow">
<table class="edtab">
<tr><td class="insthead">Ciao sono una istanza</td></tr>
<tr><td>
<table class="cbtab">
<tr><td><label for="Blacklisted">Blacklistata:</label></td><td>&nbsp;<input type="checkbox" name="Blacklisted" id="Blacklisted"></td></tr>
<tr><td><label for="New">Nuova:</label></td><td>&nbsp;<input type="checkbox" name="New" id="New"></td></tr>
<tr><td><label for="Good">Papabile:</label></td><td>&nbsp;<input type="checkbox" name="Good" id="Good"></td></tr>
<tr><td><label for="Chosen">Scelta:</label></td><td>&nbsp;<input type="checkbox" name="Chosen" id="Chosen"></td></tr>
<tr><td><label for="Visible">Visibile:</label></td><td>&nbsp;<input type="checkbox" name="Visible" id="Visible"></td></tr>
</table>
<label for="OurDesc">Descrizione nostra:</label><textarea name="OurDesc" id="OurDesc" rows="10" class="tarea"></textarea><br>
<label for="LocalityID">Località:</label> Orpo
</td></tr>
</table>
</div>
</div>
</body>
</html>