edinst.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php
  2. require('include/glob.php');
  3. require('include/muoribene.php');
  4. require('include/sessionstart.php');
  5. require('include/menu.php');
  6. $menu['istanze']['href']=null;
  7. $menu['istanze']['selected']=true;
  8. $menu['istanze']['submenu']['modifica']['href']=null;
  9. $menu['istanze']['submenu']['modifica']['selected']=true;
  10. buildmenu($menu);
  11. require('include/myconn.php');
  12. $dbg='';
  13. use function mysqli_real_escape_string as myesc;
  14. // praticamente una macro
  15. function hspech($str) {
  16. return(htmlspecialchars($str,ENT_QUOTES|ENT_HTML5,'UTF-8'));
  17. }
  18. $dbg.='<pre>'.print_r($_POST,1).'</pre>';
  19. mysqli_close($link);
  20. ?>
  21. <!DOCTYPE HTML>
  22. <html lang="it">
  23. <head>
  24. <title>Mastodon Startpage Admin - Modifica di «<?php echo($data['URI']); ?>»</title>
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <meta name="description" content="Admin pages for Mastodon Startpage">
  27. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  28. <link rel="icon" type="image/png" href="imgs/icona-32.png" sizes="32x32">
  29. <link rel="icon" type="image/png" href="imgs/icona-192.png" sizes="192x192">
  30. <link rel="icon" type="image/png" href="imgs/icona-512.png" sizes="512x512">
  31. <link rel="apple-touch-icon-precomposed" href="imgs/icona-180.png">
  32. <script language="JavaScript" src="js/confirma.js?v=<?php echo($cjrand); ?>"></script>
  33. <script language="JavaScript" src="js/alerta.js?v=<?php echo($cjrand); ?>"></script>
  34. <link rel="stylesheet" type="text/css" href="theme.css?v=<?php echo($cjrand); ?>">
  35. <script language="JavaScript">
  36. <!--
  37. function chulsh(el,sh) {
  38. if (sh)
  39. el.querySelector('ul').style.display='block';
  40. else
  41. el.querySelector('ul').style.display='none';
  42. }
  43. function ulsh(el,sh) {
  44. if (sh)
  45. el.style.display='block';
  46. else
  47. el.style.display='none';
  48. }
  49. function shideplancia() {
  50. var plancia=document.getElementById('plancia');
  51. var plctrl=document.getElementById('plctrl');
  52. if (plancia.style.display=='block') {
  53. plancia.style.display='none';
  54. plctrl.innerHTML='Mostra plancia';
  55. } else {
  56. plancia.style.display='block';
  57. plctrl.innerHTML='Nascondi plancia';
  58. }
  59. }
  60. function truncsel(el) {
  61. var sel=document.getElementById(el), len=sel.length, i=0;
  62. for (i=len-1; i>=0; i--)
  63. sel.remove(i);
  64. }
  65. function addselopt(el,val,txt) {
  66. option=new Option(txt,val);
  67. el.add(option);
  68. }
  69. function inpdisif(index) {
  70. console.log('inpdisif index: '+index);
  71. var source=document.getElementById('condsel-'+index);
  72. var inp=document.getElementById('valueinp-'+index);
  73. var sel=document.getElementById('valuesel-'+index);
  74. var conds=['IS NULL','IS NOT NULL'];
  75. if (conds.includes(source.value)) {
  76. inp.disabled=true;
  77. sel.disabled=true;
  78. } else {
  79. if (inp.style.display!='none') inp.disabled=false;
  80. if (sel.style.display!='none') sel.disabled=false;
  81. }
  82. }
  83. function popusels(index,valselval) {
  84. console.log('popusels index: '+index);
  85. var key=document.getElementById('fieldsel-'+index).value;
  86. var type=key.replace(/^.*:(.*):.*$/,'$1');
  87. var subtype=key.replace(/^.*:.*:(.*)$/,'$1');
  88. key=key.replace(/^(.*):.*:.*$/,'$1');
  89. var condsel=document.getElementById('condsel-'+index);
  90. var valsel=document.getElementById('valuesel-'+index);
  91. var valinp=document.getElementById('valueinp-'+index);
  92. condsel.setAttribute('onchange','inpdisif('+index+');');
  93. if (type=='joini')
  94. type=subtype;
  95. if (type=='bool') {
  96. truncsel('condsel-'+index);
  97. addselopt(condsel,'IS','è');
  98. truncsel('valuesel-'+index);
  99. addselopt(valsel,'TRUE','vero');
  100. addselopt(valsel,'FALSE','falso');
  101. addselopt(valsel,'NOT NULL','definit@');
  102. addselopt(valsel,'NULL','non definit@');
  103. if (valselval!==false)
  104. selind('valuesel-'+index,valselval);
  105. valinp.style.display='none';
  106. valinp.disabled=true;
  107. valsel.style.display='block';
  108. valsel.disabled=false;
  109. } else if (type=='text') {
  110. truncsel('condsel-'+index);
  111. addselopt(condsel,'LIKE','contiene');
  112. addselopt(condsel,'NOT LIKE','non contiene');
  113. addselopt(condsel,'=','è uguale a');
  114. addselopt(condsel,'!=','è divers@ da');
  115. addselopt(condsel,'>=','è maggiore o uguale a');
  116. addselopt(condsel,'<=','è minore o uguale a');
  117. addselopt(condsel,'>','è maggiore di');
  118. addselopt(condsel,'<','è minore di');
  119. addselopt(condsel,'IS NOT NULL','è definit@');
  120. addselopt(condsel,'IS NULL','non è definit@');
  121. valsel.style.display='none';
  122. valsel.disabled=true;
  123. valinp.style.display='block';
  124. valinp.disabled=false;
  125. } else if (type=='int' || type=='time') {
  126. truncsel('condsel-'+index);
  127. addselopt(condsel,'>=','è maggiore o uguale a');
  128. addselopt(condsel,'<=','è minore o uguale a');
  129. addselopt(condsel,'>','è maggiore di');
  130. addselopt(condsel,'<','è minore di');
  131. addselopt(condsel,'=','è uguale a');
  132. addselopt(condsel,'!=','è divers@ da');
  133. addselopt(condsel,'IS NOT NULL','è definit@');
  134. addselopt(condsel,'IS NULL','non è definit@');
  135. valsel.style.display='none';
  136. valsel.disabled=true;
  137. valinp.style.display='block';
  138. valinp.disabled=false;
  139. } else if (type=='join') {
  140. truncsel('condsel-'+index);
  141. addselopt(condsel,'=','è uguale a');
  142. addselopt(condsel,'!=','è divers@ da');
  143. addselopt(condsel,'IS NOT NULL','è definit@');
  144. addselopt(condsel,'IS NULL','non è definit@');
  145. valsel.style.display='block';
  146. valsel.disabled=false;
  147. valinp.style.display='none';
  148. valinp.disabled=true;
  149. truncsel('valuesel-'+index);
  150. pupwait(true);
  151. let xhr=new XMLHttpRequest();
  152. xhr.open('GET','instancesh.php?key='+key);
  153. xhr.responseType='json';
  154. xhr.send();
  155. xhr.onload=function() {
  156. let jarr=xhr.response;
  157. for (i=0; i<jarr.length; i++)
  158. addselopt(valsel,jarr[i][0],jarr[i][1]);
  159. console.log('valsel pronto!');
  160. if (valselval!==false)
  161. selind('valuesel-'+index,valselval);
  162. pupwait(false);
  163. };
  164. xhr.onerror=function() {
  165. alert('Request failed');
  166. };
  167. } else {
  168. alert('Attenziò: non so che farmene del tipo "'+type+'": diglielo, al programmatore.');
  169. }
  170. }
  171. function addrow(index,refresh) {
  172. var table=document.getElementById('planciafil');
  173. var newrow=table.insertRow(index);
  174. var newcell0=newrow.insertCell(0);
  175. var newcell1=newrow.insertCell(1);
  176. var newcell2=newrow.insertCell(2);
  177. var newcell3=newrow.insertCell(3);
  178. var newcell4=newrow.insertCell(4);
  179. var newcell5=newrow.insertCell(5);
  180. var newcell6=newrow.insertCell(6);
  181. var newcell7=newrow.insertCell(7);
  182. newcell0.innerHTML='<select class="openpar"><option value="null"></option><option value="(">(</option><option value="((">((</option><option value="(((">(((</option></select>';
  183. newcell1.innerHTML='<select class="fieldsel"></select>';
  184. newcell2.innerHTML='<select class="condsel"></select>';
  185. newcell3.innerHTML='<select class="valuesel" style="display:none;"></select><input type="text" class="valueinp" maxlength="256" style="display:none;">';
  186. newcell4.innerHTML='<select class="closepar"><option value="null"></option><option value=")">)</option><option value="))">))</option><option value=")))">)))</option></select>';
  187. newcell5.innerHTML='<select class="andor"><option value="AND">E</option><option value="OR">O</option></select>';
  188. newcell6.innerHTML='<img class="plus" src="imgs/plus.svg">';
  189. newcell7.innerHTML='<img class="minus" src="imgs/minus.svg">';
  190. if (refresh) {
  191. synctai();
  192. popusels(index,false);
  193. }
  194. }
  195. function ordaddrow(index,refresh) {
  196. var table=document.getElementById('planciaord');
  197. var newrow=table.insertRow(index);
  198. var newcell0=newrow.insertCell(0);
  199. var newcell1=newrow.insertCell(1);
  200. var newcell2=newrow.insertCell(2);
  201. var newcell3=newrow.insertCell(3);
  202. newcell0.style.width='97%';
  203. newcell1.style.width='1%';
  204. newcell2.style.width='1%';
  205. newcell3.style.width='1%';
  206. newcell0.innerHTML='<select class="ordfieldsel"></select>';
  207. newcell1.innerHTML='<select class="ascdesc"><option value="ASC">Crescente</option><option value="DESC">Decrescente</option></select>';
  208. newcell2.innerHTML='<img class="plus" src="imgs/plus.svg">';
  209. newcell3.innerHTML='<img class="minus" src="imgs/minus.svg">';
  210. if (refresh)
  211. synctoi();
  212. }
  213. function synctai() {
  214. var i=0;
  215. var table=document.getElementById('planciafil');
  216. var nodes=table.querySelectorAll('.minus');
  217. var cnodes=nodes.length;
  218. for (i=0; i<cnodes; i++)
  219. // +1 sempre per via della row iniziale
  220. nodes[i].setAttribute('onclick','remrow('+(i+1)+');');
  221. nodes=table.querySelectorAll('.plus');
  222. for (i=0; i<cnodes; i++)
  223. // +2 perché la devi aggiungere dopo la corrente
  224. nodes[i].setAttribute('onclick','addrow('+(i+2)+',true);');
  225. // da qui in poi faccio a scendere per non avere mai id e nomi duplicati
  226. cnodes--;
  227. nodes=table.querySelectorAll('.openpar');
  228. for (i=cnodes; i>-1; i--) {
  229. nodes[i].setAttribute('id','openpar-'+(i+1));
  230. nodes[i].setAttribute('name','openpar-'+(i+1));
  231. }
  232. nodes=table.querySelectorAll('.fieldsel');
  233. for (i=cnodes; i>-1; i--) {
  234. nodes[i].setAttribute('id','fieldsel-'+(i+1));
  235. nodes[i].setAttribute('name','fieldsel-'+(i+1));
  236. nodes[i].setAttribute('onchange','popusels('+(i+1)+',false);');
  237. }
  238. nodes=table.querySelectorAll('.condsel');
  239. for (i=cnodes; i>-1; i--) {
  240. nodes[i].setAttribute('id','condsel-'+(i+1));
  241. nodes[i].setAttribute('name','condsel-'+(i+1));
  242. nodes[i].setAttribute('onchange','inpdisif('+(i+1)+');');
  243. }
  244. nodes=table.querySelectorAll('.valuesel');
  245. for (i=cnodes; i>-1; i--) {
  246. nodes[i].setAttribute('id','valuesel-'+(i+1));
  247. nodes[i].setAttribute('name','valuesel-'+(i+1));
  248. }
  249. nodes=table.querySelectorAll('.valueinp');
  250. for (i=cnodes; i>-1; i--) {
  251. nodes[i].setAttribute('id','valueinp-'+(i+1));
  252. nodes[i].setAttribute('name','valueinp-'+(i+1));
  253. }
  254. nodes=table.querySelectorAll('.closepar');
  255. for (i=cnodes; i>-1; i--) {
  256. nodes[i].setAttribute('id','closepar-'+(i+1));
  257. nodes[i].setAttribute('name','closepar-'+(i+1));
  258. }
  259. nodes=table.querySelectorAll('.andor');
  260. for (i=cnodes; i>-1; i--) {
  261. nodes[i].setAttribute('id','andor-'+(i+1));
  262. nodes[i].setAttribute('name','andor-'+(i+1));
  263. nodes[i].disabled=false;
  264. }
  265. if (cnodes>=0)
  266. nodes[cnodes].disabled=true;
  267. }
  268. function synctoi() {
  269. var i=0;
  270. var table=document.getElementById('planciaord');
  271. var nodes=table.querySelectorAll('.minus');
  272. var cnodes=nodes.length;
  273. for (i=0; i<cnodes; i++)
  274. // +1 sempre per via della row iniziale
  275. nodes[i].setAttribute('onclick','ordremrow('+(i+1)+');');
  276. nodes=table.querySelectorAll('.plus');
  277. for (i=0; i<cnodes; i++)
  278. // +2 perché la devi aggiungere dopo la corrente
  279. nodes[i].setAttribute('onclick','ordaddrow('+(i+2)+',true);');
  280. // da qui in poi faccio a scendere per non avere mai id e nomi duplicati
  281. cnodes--;
  282. nodes=table.querySelectorAll('.ordfieldsel');
  283. for (i=cnodes; i>-1; i--) {
  284. nodes[i].setAttribute('id','ordfieldsel-'+(i+1));
  285. nodes[i].setAttribute('name','ordfieldsel-'+(i+1));
  286. }
  287. nodes=table.querySelectorAll('.ascdesc');
  288. for (i=cnodes; i>-1; i--) {
  289. nodes[i].setAttribute('id','ascdesc-'+(i+1));
  290. nodes[i].setAttribute('name','ascdesc-'+(i+1));
  291. }
  292. }
  293. function selind(id,val) {
  294. var el=document.getElementById(id), i=0, found=false;
  295. while (!found && i<el.length) {
  296. if (el[i].value==val) {
  297. el.selectedIndex=i;
  298. found=true;
  299. }
  300. i++;
  301. }
  302. if (!found)
  303. console.log('"'+val+'" non è stato trovato in "'+id+'"');
  304. }
  305. function setrow(index,openparv,fieldselv,condselv,valueselv,valueinpv,closeparv,andorv) {
  306. selind('openpar-'+index,openparv);
  307. selind('fieldsel-'+index,fieldselv);
  308. popusels(index,valueselv);
  309. selind('condsel-'+index,condselv);
  310. // selind('valuesel-'+index,valueselv);
  311. document.getElementById('valueinp-'+index).value=valueinpv;
  312. if (condselv=='IS NULL' || condselv=='IS NOT NULL') {
  313. document.getElementById('valueinp-'+index).disabled=true;
  314. document.getElementById('valuesel-'+index).disabled=true;
  315. }
  316. selind('closepar-'+index,closeparv);
  317. selind('andor-'+index,andorv);
  318. }
  319. function ordsetrow(index,ordfieldselv,ascdescv) {
  320. selind('ordfieldsel-'+index,ordfieldselv);
  321. selind('ascdesc-'+index,ascdescv);
  322. }
  323. function remrow(index) {
  324. var table=document.getElementById('planciafil');
  325. table.deleteRow(index);
  326. synctai();
  327. if (table.rows.length<2)
  328. document.getElementById('filbut').value='Aggiungi criteri di ricerca';
  329. }
  330. function ordremrow(index) {
  331. var table=document.getElementById('planciaord');
  332. table.deleteRow(index);
  333. synctoi();
  334. if (table.rows.length<2)
  335. document.getElementById('ordbut').value='Aggiungi criteri di ordinamento';
  336. }
  337. function truncfil() {
  338. var table=document.getElementById('planciafil');
  339. while (table.rows.length>1)
  340. remrow(1);
  341. }
  342. function truncord() {
  343. var table=document.getElementById('planciaord');
  344. while (table.rows.length>1)
  345. ordremrow(1);
  346. }
  347. function manfil() {
  348. var filbut=document.getElementById('filbut');
  349. var table=document.getElementById('planciafil');
  350. var crows=table.rows.length;
  351. if (crows<2) {
  352. addrow(1,true);
  353. filbut.value='Rimuovi tutti i criteri di ricerca';
  354. } else {
  355. confirma('<p>Confermi di voler rimuovere tutti i criteri di ricerca?</p>','truncfil();filbut.value=\'Aggiungi criteri di ricerca\'');
  356. }
  357. }
  358. function manord() {
  359. var ordbut=document.getElementById('ordbut');
  360. var table=document.getElementById('planciaord');
  361. var crows=table.rows.length;
  362. if (crows<2) {
  363. ordaddrow(1,true);
  364. ordbut.value='Rimuovi tutti i criteri di ordinamento';
  365. } else {
  366. confirma('<p>Confermi di voler rimuovere tutti i criteri di ordinamento?</p>','truncord();ordbut.value=\'Aggiungi criteri di ordinamento\'');
  367. }
  368. }
  369. function ckpar() {
  370. var i=0;
  371. var table=document.getElementById('planciafil');
  372. var nodes=table.querySelectorAll('.openpar');
  373. var cnodes=nodes.length;
  374. var opars=[];
  375. var cpars=[];
  376. for (i=0; i<cnodes; i++)
  377. opars.push(nodes[i].value);
  378. nodes=table.querySelectorAll('.closepar');
  379. for (i=0; i<cnodes; i++)
  380. cpars.push(nodes[i].value);
  381. var spars='';
  382. for (i=0; i<cnodes; i++) {
  383. if (opars[i]!='null') spars+=opars[i];
  384. if (cpars[i]!='null') spars+=cpars[i];
  385. }
  386. var opq=0, cpq=0, ok=true;
  387. for (i=0; i<spars.length; i++) {
  388. if (spars[i]=='(') {
  389. opq++;
  390. } else if (spars[i]==')') {
  391. cpq++;
  392. }
  393. if (cpq>opq)
  394. break;
  395. }
  396. if (opq!=cpq)
  397. ok=false;
  398. console.log(i+'/'+spars.length+': '+ok);
  399. return ok;
  400. }
  401. function ckf() {
  402. var emsg='';
  403. if (!ckpar()) emsg+='Qualcosa non va con le parentesi!<br>\n';
  404. // emsg+='Comunque NO!<br>\n';
  405. if (emsg=='') {
  406. var table=document.getElementById('planciafil');
  407. var crows=table.rows.length;
  408. if (crows>1)
  409. document.getElementById('andor-'+(crows-1)).disabled=false;
  410. document.getElementById('f').submit();
  411. } else {
  412. alerta('<p>'+emsg+'</p>');
  413. }
  414. }
  415. function pupwait(on) {
  416. var pup=document.getElementById('popup'), inpup=document.getElementById('inpopup');
  417. if (on) {
  418. if (pup.style.display!='table') {
  419. inpup.innerHTML='<div class="waitbub"><img src="imgs/loading.gif"><br>&nbsp;<br>Caricamento in corso...</div>';
  420. pup.style.display='table';
  421. } else {
  422. console.log('Sto già aspettando...');
  423. }
  424. } else {
  425. inpup.innerHTML='<div id="popupcont">...</div>';
  426. pup.style.display='none';
  427. }
  428. }
  429. //-->
  430. </script>
  431. </head>
  432. <body>
  433. <nav>
  434. <div id="hmenu">
  435. <ul>
  436. <?php echo($menuout); ?>
  437. </ul>
  438. <div id="rightdiv">
  439. <div id="logout" class="rlinks" onclick="document.location.href='logout.php'"><a href="logout.php">Esci</a></div>
  440. </div>
  441. </div>
  442. </nav>
  443. <div id="popup">
  444. <div id="inpopup">
  445. <div id="popupcont">
  446. ...
  447. </div>
  448. </div>
  449. </div>
  450. <!-- <div id="footer">
  451. </div> -->
  452. <div id="debug">
  453. <?php //echo($dbg); ?>
  454. </div>
  455. <div id="fullscreen">
  456. <div id="middlerow">
  457. <table class="edtab">
  458. <tr><td class="insthead">Ciao sono una istanza</td></tr>
  459. <tr><td>
  460. <table class="cbtab">
  461. <tr><td><label for="Blacklisted">Blacklistata:</label></td><td>&nbsp;<input type="checkbox" name="Blacklisted" id="Blacklisted"></td></tr>
  462. <tr><td><label for="New">Nuova:</label></td><td>&nbsp;<input type="checkbox" name="New" id="New"></td></tr>
  463. <tr><td><label for="Good">Papabile:</label></td><td>&nbsp;<input type="checkbox" name="Good" id="Good"></td></tr>
  464. <tr><td><label for="Chosen">Scelta:</label></td><td>&nbsp;<input type="checkbox" name="Chosen" id="Chosen"></td></tr>
  465. <tr><td><label for="Visible">Visibile:</label></td><td>&nbsp;<input type="checkbox" name="Visible" id="Visible"></td></tr>
  466. </table>
  467. <label for="OurDesc">Descrizione nostra:</label><textarea name="OurDesc" id="OurDesc" rows="10" class="tarea"></textarea><br>
  468. <label for="LocalityID">Località:</label> Orpo
  469. </td></tr>
  470. </table>
  471. </div>
  472. </div>
  473. </body>
  474. </html>