MastodonHelp/web/admin/edinst.php

436 lines
17 KiB
PHP
Raw Normal View History

2020-03-09 22:16:54 +01:00
<?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'));
}
2020-03-24 23:22:07 +01:00
$dbg.='<pre>'.print_r($_GET,1).'</pre>';
2020-03-09 22:16:54 +01:00
2020-03-24 23:22:07 +01:00
if (array_key_exists('id',$_GET) && preg_match('/^[0-9]+$/',$_GET['id'])===1) {
$res=mysqli_query($link,'SELECT * FROM Instances WHERE ID='.$_GET['id'])
or muoribene(mysqli_error($link).'<br>Puoi <a href="instances.php">tornare allelenco delle istanze</a>.',true);
if (mysqli_num_rows($res)!=1)
muoribene('Non esiste alcuna istanza con ID='.$_GET['ID'].'<br>Puoi <a href="instances.php">tornare allelenco delle istanze</a>.');
$inst=mysqli_fetch_assoc($res);
}
2020-03-09 22:16:54 +01:00
2020-03-24 23:22:07 +01:00
function check($row,$col) {
if ($row[$col]>0)
echo(' checked');
}
2020-03-09 22:16:54 +01:00
?>
<!DOCTYPE HTML>
<html lang="it">
<head>
2020-03-24 23:22:07 +01:00
<title>Mastodon Startpage Admin - Modifica di «<?php echo($inst['URI']); ?>»</title>
2020-03-09 22:16:54 +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">
<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">
2020-03-11 17:25:06 +01:00
<script language="JavaScript" src="js/menu.js?v=<?php echo($cjrand); ?>"></script>
2020-03-09 22:16:54 +01:00
<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-03-24 23:22:07 +01:00
function getselarr(selid) {
var sel=document.getElementById(selid), selc=sel.length, i, arr=[], selected;
for (i=0; i<selc; i++) {
(!sel.options[i].selected) ? selected=false : selected=true;
arr.push([sel.options[i].text,sel.options[i].value,selected]);
}
return arr;
}
function filtsel(selarr,filt,selid,recbid,inpid,ocol,ecol) {
var sel=document.getElementById(selid), selarrc=selarr.length, i, ii, go=true;
if (!document.getElementById(recbid).checked) {
filt=filt.replace(/([.?*+^$[\]\\(){}|-])/g,'\\$1');
} else {
try { (RegExp(filt)); }
catch(e) { go=false; }
}
if (go) {
sel.length=0;
for (i=0; i<selarrc; i++) {
if (RegExp(filt,'i').test(selarr[i][0]))
sel.options.add(new Option(selarr[i][0],selarr[i][1],false,selarr[i][2]));
}
if (ocol!=null)
document.getElementById(inpid).style.backgroundColor=ocol;
} else if (ecol!=null) {
document.getElementById(inpid).style.backgroundColor=ecol;
}
}
function selup(selid) {
var sel=document.getElementById(selid), len=sel.length, i, prevopt, curopt;
if (sel.selectedIndex>0) {
for (i=0; i<len; i++) {
if (sel.options[i].selected) {
prevopt=sel.options[i-1];
curopt=sel.options[i];
sel.remove(i-1);
sel.remove(i-1);
sel.add(curopt,i-1);
sel.add(prevopt,i);
}
}
}
}
function seltop(selid) {
var sel=document.getElementById(selid);
while (sel.selectedIndex>0)
selup(selid);
}
function seldown(selid) {
var sel=document.getElementById(selid), len=sel.length, i, nextopt, curopt;
if (!sel.options[len-1].selected) {
for (i=len-1; i>-1; i--) {
if (sel.options[i].selected) {
curopt=sel.options[i];
nextopt=sel.options[i+1];
sel.remove(i);
sel.remove(i);
sel.add(curopt,i);
sel.add(nextopt,i);
}
}
}
}
function selbot(selid) {
var sel=document.getElementById(selid), len=sel.length;
if (sel.selectedIndex>=0) {
while (!sel.options[len-1].selected)
seldown(selid);
}
}
function rmelbyval(refarr,valindex,val) {
var len=refarr.length, i;
for (i=len-1; i>-1; i--) {
if (refarr[i][valindex]==val)
refarr.splice(i,1);
}
return refarr;
}
function seladd(fromselid,toselid,refarr) {
var fromsel=document.getElementById(fromselid), fslen=fromsel.length, tosel=document.getElementById(toselid), i;
// farlo a scalare invece che a crescere inverte nella select di destinazione l'ordine delle opzioni scelte in quella di origine, perciò lo faccio a crescere
for (i=0; i<fslen; i++) {
if (fromsel.options[i].selected) {
refarr=rmelbyval(refarr,1,fromsel.options[i].value);
tosel.add(fromsel.options[i]);
fslen--;
i--;
}
}
return refarr;
}
function sortByKey(array, key) {
return array.sort(function(a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
function selrem(fromselid,toselid,refarr) {
var fromsel=document.getElementById(fromselid), fslen=fromsel.length, tosel=document.getElementById(toselid), i;
for (i=fslen-1; i>-1; i--) {
if (fromsel.options[i].selected) {
refarr.push([fromsel.options[i].text,fromsel.options[i].value,true]);
fromsel.remove(i);
}
}
refarr=sortByKey(refarr,0);
tosel.length=0;
for (i=0; i<refarr.length; i++) {
tosel.add(new Option(refarr[i][0],refarr[i][1]));
}
return refarr;
}
function selordalf(selid) {
var sel=document.getElementById(selid), len=sel.length, arr=[], i;
for (i=0; i<len; i++)
arr.push([sel.options[i].text,sel.options[i].value,sel.options[i].selected]);
arr=sortByKey(arr,0);
sel.length=0;
for (i=0; i<len; i++)
sel.add(new Option(arr[i][0],arr[i][1],false,arr[i][2]));
}
function selordinv(selid) {
var sel=document.getElementById(selid), len=sel.length, arr=[], i;
for (i=0; i<len; i++)
arr.push([sel.options[i].text,sel.options[i].value,sel.options[i].selected]);
arr=arr.reverse();
sel.length=0;
for (i=0; i<len; i++)
sel.add(new Option(arr[i][0],arr[i][1],false,arr[i][2]));
}
function closeinpup() {
document.getElementById('inpopup').innerHTML='<div id="popupcont">...</div>';
document.getElementById('popup').style.display='none';
}
function edit(selid,what,mode) {
var act='', id=0;
if (mode=='edit')
act={0:'Modifica',1:'modificare'};
else if (mode=='add')
act={0:'Aggiungi',1:'aggiungere'};
else if (mode=='remove')
act={0:'Elimina',1:'eliminare'};
var sel=document.getElementById(selid);
if ((mode=='edit' || mode=='remove') && sel.selectedIndex<0) {
alerta('<p>Devi selezionare una voce da '+act[1]+' ;-)</p>');
} else {
if (mode=='edit' || mode=='remove')
id=sel.options[sel.selectedIndex].value;
document.getElementById('inpopup').innerHTML='<div class="hiftit"><img src="imgs/p.png" style="float:left;width:24px;height:24px">'+act[0]+' voce «'+what+'»<img src="imgs/close.svg" class="imgbut" style="float:right;" onclick="closeinpup()"></div><iframe src="edinsth.php?w='+selid+'&i='+id+'&m='+mode+'" class="hiframe"></iframe>';
document.getElementById('popup').style.display='table';
}
2020-03-09 22:16:54 +01:00
}
//-->
</script>
</head>
<body>
<nav>
<div id="hmenu">
<ul>
<?php echo($menuout); ?>
</ul>
<div id="rightdiv">
2020-03-11 08:43:56 +01:00
<a href="logout.php" class="rlinks"><img src="imgs/esci.svg" title="Esci"></a>
2020-03-09 22:16:54 +01:00
</div>
2020-03-24 23:22:07 +01:00
</div>
2020-03-09 22:16:54 +01:00
</nav>
<div id="popup">
<div id="inpopup">
<div id="popupcont">
...
</div>
</div>
</div>
<!-- <div id="footer">
</div> -->
<div id="fullscreen">
<div id="middlerow">
2020-03-24 23:22:07 +01:00
2020-03-09 22:16:54 +01:00
<table class="edtab">
2020-03-24 23:22:07 +01:00
<tr><td class="insthead"><?php echo($inst['URI']); ?></td></tr>
2020-03-09 22:16:54 +01:00
<tr><td>
2020-03-24 23:22:07 +01:00
2020-03-09 22:16:54 +01:00
<table class="cbtab">
2020-03-24 23:22:07 +01:00
<tr><td><label for="Blacklisted">Blacklistata:</label></td><td>&nbsp;<input type="checkbox" name="Blacklisted" id="Blacklisted"<?php check($inst,'Blacklisted'); ?>></td></tr>
<tr><td><label for="New">Nuova:</label></td><td>&nbsp;<input type="checkbox" name="New" id="New"<?php check($inst,'New'); ?>></td></tr>
<tr><td><label for="Chosen">Scelta:</label></td><td>&nbsp;<input type="checkbox" name="Chosen" id="Chosen"<?php check($inst,'Chosen'); ?>></td></tr>
<tr><td><label for="Visible">Visibile:</label></td><td>&nbsp;<input type="checkbox" name="Visible" id="Visible"<?php check($inst,'Visible'); ?>></td></tr>
2020-03-11 08:43:56 +01:00
</table>
2020-03-24 23:22:07 +01:00
2020-03-11 08:43:56 +01:00
<div class="ruler"></div>
<div class="tit"><label for="OurDesc">Descrizione nostra</label></div>
2020-03-24 23:22:07 +01:00
<textarea name="OurDesc" id="OurDesc" rows="10" class="tarea"><?php echo(hspech($inst['OurDesc'])); ?></textarea>
2020-03-11 08:43:56 +01:00
<div class="ruler"></div>
<div class="tit"><label for="LocalityID">Località</label></div>
2020-03-24 23:22:07 +01:00
<table class="picktab"><tr>
<td style="width:98%;"><input type="text" placeholder="Cerca ..." class="search" id="locsearch" onkeyup="filtsel(locselarr, this.value, 'LocalityID', 'locselre', 'locsearch', 'white', '#ff8080')"></td>
<td style="width:1%;padding-left:3px;padding-right:3px;"><label for="locselre">Regex:</label></td>
<td style="width:1%"><input type="checkbox" id="locselre" style="float:right;" onchange="filtsel(locselarr, document.getElementById('locsearch').value, 'LocalityID', 'locselre', 'locsearch', 'white', '#ff8080')"></td>
</tr></table>
<table class="picktab">
<tr>
<td style="width:99%;">
2020-03-11 08:43:56 +01:00
<select id="LocalityID" size="10" class="mselect">
2020-03-24 23:22:07 +01:00
<?php
$res=mysqli_query($link,'SELECT *, Localities.ID AS LocID FROM Localities LEFT JOIN States ON States.ID=Localities.StateID ORDER BY States.State ASC, Localities.Locality ASC') or muoribene(mysqli_error($link).'<br>Puoi <a href="instances.php">tornare allelenco delle istanze</a>.',true);
while ($row=mysqli_fetch_assoc($res)) {
($row['LocID']==$inst['LocalityID']) ? $selected=' selected' : $selected='';
echo('<option value="'.$row['LocID'].'"'.$selected.'>'.hspech($row['Locality']).' ('.hspech($row['State']).')</option>'.N);
}
?>
2020-03-11 08:43:56 +01:00
</select>
2020-03-24 23:22:07 +01:00
</td>
<td style="width:99%;">
<div class="butdiv"><img src="imgs/edit.svg" class="imgbut" title="Modifica la voce selezionata" onclick="edit('LocalityID','Località','edit')"></div>
<div class="butdiv"><img src="imgs/plus.svg" class="imgbut" title="Aggiungi una voce" onclick="edit('LocalityID','Località','add')"></div>
<div class="butdiv"><img src="imgs/minus.svg" class="imgbut" title="Elimina la voce selezionata" onclick="edit('LocalityID','Località','remove')"></div>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
selordalf('LocalityID');
var locselarr=getselarr('LocalityID');
//-->
</script>
<?php
function multi($o) {
global $link;
echo('<div class="ruler"></div>
<div class="tit"><label for="'.$o['dispselid'].'">'.$o['title'].'</label></div>
<table class="picktab"><tr>
<td style="width:98%"><input type="text" placeholder="Cerca ..." 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="Usa espressioni regolari">Regex:</label></td>
<td style="width:1%"><input type="checkbox" id="'.$o['regexcbid'].'" style="float:right;" title="Usa espressioni regolari" onchange="filtsel('.$o['disparr'].', document.getElementById(\''.$o['searchid'].'\').value, \''.$o['dispselid'].'\', \''.$o['regexcbid'].'\', \''.$o['searchid'].'\', \'white\', \'#ff8080\')"></td>
</tr></table>
2020-03-11 08:43:56 +01:00
<table class="picktab">
<tr>
<td style="width:99%;">
2020-03-24 23:22:07 +01:00
<select id="'.$o['dispselid'].'" multiple size="8" class="mselect">'.N);
$res=mysqli_query($link,$o['dispque'])
or muoribene(mysqli_error($link).'<br>Puoi <a href="instances.php">tornare allelenco delle istanze</a>.',true);
while ($row=mysqli_fetch_assoc($res)) {
echo('<option value="'.$row[$o['valcol']].'">'.hspech($row[$o['txtcol']]).'</option>'.N);
}
echo('</select>
<script type="text/javascript">
<!--
selordalf(\''.$o['dispselid'].'\');
var '.$o['disparr'].'=getselarr(\''.$o['dispselid'].'\');
//-->
</script>
2020-03-11 08:43:56 +01:00
</td>
<td style="width:1%;">
2020-03-24 23:22:07 +01:00
<div class="butdiv"><img src="imgs/edit.svg" class="imgbut" title="Modifica la voce selezionata" onclick="edit(\''.$o['dispselid'].'\',\''.$o['title'].'\')"></div>
<div class="butdiv"><img src="imgs/plus.svg" class="imgbut" title="Aggiungi una voce" onclick="edit(\''.$o['dispselid'].'\',\''.$o['title'].'\'),m=\'add\'"></div>
<div class="butdiv"><img src="imgs/minus.svg" class="imgbut" title="Elimina la voce selezionata" onclick="edit(\''.$o['dispselid'].'\',\''.$o['title'].'\',m=\'remove\')"></div>
2020-03-11 08:43:56 +01:00
</td>
</tr>
<tr>
<td style="width:99%;">
2020-03-24 23:22:07 +01:00
<div class="move">'.$o['dida'].'
<img src="imgs/fregiu.svg" class="imgbut" style="float:left;" title="Sposta sotto le voci selezionate sopra" onclick="'.$o['disparr'].'=seladd(\''.$o['dispselid'].'\', \''.$o['chosenselid'].'\', '.$o['disparr'].')">
<img src="imgs/fresu.svg" class="imgbut" style="float:right;" title="Sposta sopra le voci selezionate sotto" onclick="'.$o['disparr'].'=selrem(\''.$o['chosenselid'].'\', \''.$o['dispselid'].'\', '.$o['disparr'].'); filtsel('.$o['disparr'].', document.getElementById(\''.$o['searchid'].'\').value, \''.$o['dispselid'].'\', \''.$o['regexcbid'].'\', \''.$o['searchid'].'\', \'white\', \'#ff8080\')">
</div>
2020-03-11 08:43:56 +01:00
</td>
<td style="width:1%;">
</td>
</tr>
2020-03-24 23:22:07 +01:00
<tr>
<td style="width:99%;">
<select id="'.$o['chosenselid'].'" multiple size="12" class="mselect">'.N);
$res=mysqli_query($link,$o['chosenque'])
or muoribene(mysqli_error($link).'<br>Puoi <a href="instances.php">tornare allelenco delle istanze</a>.',true);
while ($row=mysqli_fetch_assoc($res)) {
echo('<option value="'.$row[$o['chosenvalcol']].'">'.hspech($row[$o['txtcol']]).'</option>'.N);
}
echo('</select>
</td>
<td style="width:1%;">
<div class="butdiv"><img src="imgs/fresucim.svg" class="imgbut" title="Sposta in cima" onclick="seltop(\''.$o['chosenselid'].'\')"></div>
<div class="butdiv"><img src="imgs/fresu.svg" class="imgbut" title="Sposta su" onclick="selup(\''.$o['chosenselid'].'\')"></div>
<div class="butdiv"><img src="imgs/fregiu.svg" class="imgbut" title="Sposta giù" onclick="seldown(\''.$o['chosenselid'].'\')"></div>
<div class="butdiv"><img src="imgs/fregiufon.svg" class="imgbut" title="Sposta in fondo" onclick="selbot(\''.$o['chosenselid'].'\')"></div>
<div class="butdiv"><img src="imgs/alph.svg" class="imgbut" title="Ordina alfabeticamente" onclick="selordalf(\''.$o['chosenselid'].'\')"></div>
<div class="butdiv"><img src="imgs/invert.svg" class="imgbut" title="Inverti ordine" onclick="selordinv(\''.$o['chosenselid'].'\')"></div>
</td>
</tr>
</table>'.N);
}
/*multi(array(
'dispselid'=>'DispLangs',
'title'=>'Lingue',
'searchid'=>'langsearch',
'searchtit'=>'Cerca tra le lingue disponibili',
'disparr'=>'langselarr',
'regexcbid'=>'langselre',
'dispque'=>'SELECT * FROM Languages WHERE ID NOT IN (SELECT OurLangID FROM InstOurLangs WHERE InstID='.$inst['ID'].') ORDER BY NameIT ASC',
'valcol'=>'ID',
'txtcol'=>'NameIT',
'dida'=>'Sopra: lingue disponibili; sotto: lingue scelte',
'chosenselid'=>'ChosenLangs',
'chosenque'=>'SELECT * FROM InstOurLangs LEFT JOIN Languages ON Languages.ID=OurLangID WHERE InstID='.$inst['ID'].' ORDER BY Pos ASC',
'chosenvalcol'=>'OurLangID'));*/
multi(array(
'dispselid'=>'DispFinModes',
'title'=>'Modalità di finanziamento',
'searchid'=>'finsearch',
'searchtit'=>'Cerca tra le modalità di finanziamento disponibili',
'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'=>'Sopra: mod. di fin. disponibili; sotto: mod. di fin. scelte',
'chosenselid'=>'ChosenFinModes',
'chosenque'=>'SELECT * FROM InstFinancing LEFT JOIN Financing ON Financing.ID=FinID WHERE InstID='.$inst['ID'].' ORDER BY Pos ASC',
'chosenvalcol'=>'FinID'));
multi(array(
'dispselid'=>'DispPolicies',
'title'=>'Restrizioni sui contenuti',
'searchid'=>'polsearch',
'searchtit'=>'Cerca tra le restrizioni sui contenuti disponibili',
'disparr'=>'polselarr',
'regexcbid'=>'polselre',
'dispque'=>'SELECT * FROM Policies WHERE ID NOT IN (SELECT PolID FROM InstPolicies WHERE InstID='.$inst['ID'].') ORDER BY Name ASC',
'valcol'=>'ID',
'txtcol'=>'Name',
'dida'=>'Sopra: rest. sui cont. disponibili; sotto: rest. sui cont. scelte',
'chosenselid'=>'ChosenPolicies',
'chosenque'=>'SELECT * FROM InstPolicies LEFT JOIN Policies ON Policies.ID=PolID WHERE InstID='.$inst['ID'].' ORDER BY Pos ASC',
'chosenvalcol'=>'PolID'));
multi(array(
'dispselid'=>'DispTags',
'title'=>'Tags',
'searchid'=>'tagsearch',
'searchtit'=>'Cerca tra le tags disponibili',
'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'=>'Sopra: tags disponibili; sotto: tags scelte',
'chosenselid'=>'ChosenTags',
'chosenque'=>'SELECT * FROM InstTags LEFT JOIN Tags ON Tags.ID=TagID WHERE InstID='.$inst['ID'].' ORDER BY Pos ASC',
'chosenvalcol'=>'TagID'));
?>
2020-03-09 22:16:54 +01:00
</td></tr>
</table>
</div>
</div>
2020-03-24 23:22:07 +01:00
<div id="debug">
<?php echo($dbg); ?>
</div>
2020-03-09 22:16:54 +01:00
</body>
</html>
2020-03-24 23:22:07 +01:00
<?php
mysqli_close($link);
?>