2019-12-26 21:57:36 +01:00
< ? php
require ( 'include/glob.php' );
require ( 'include/muoribene.php' );
require ( 'include/sessionstart.php' );
2020-04-05 22:45:21 +02:00
require ( 'include/myconn.php' );
require ( 'include/getadmacc.php' );
if ( $account [ 'Level' ] == 'guest' )
muoribene ( 'Sorry, you are not authorized.' , true );
2019-12-26 21:57:36 +01:00
require ( 'include/menu.php' );
2020-04-17 23:57:02 +02:00
$menu [ 'menu' ][ 'selected' ] = true ;
$menu [ 'menu' ][ 'submenu' ][ 'instances' ][ 'href' ] = null ;
$menu [ 'menu' ][ 'submenu' ][ 'instances' ][ 'selected' ] = true ;
2019-12-26 21:57:36 +01:00
buildmenu ( $menu );
2020-01-08 14:52:20 +01:00
$dbg = '' ;
2020-04-04 19:17:10 +02:00
$dbg .= '$account: <pre>' . print_r ( $account , 1 ) . '</pre>' . N ;
2020-01-08 14:52:20 +01:00
use function mysqli_real_escape_string as myesc ;
2020-01-05 05:46:29 +01:00
// praticamente una macro
function hspech ( $str ) {
return ( htmlspecialchars ( $str , ENT_QUOTES | ENT_HTML5 , 'UTF-8' ));
}
2020-04-07 19:39:06 +02:00
require ( 'include/columns.php' );
2020-01-02 13:19:25 +01:00
2020-01-08 14:52:20 +01:00
$types = array ( 'bool' , 'int' , 'time' , 'text' , 'join' , 'joini' );
2020-01-05 05:46:29 +01:00
$fieldselopts = '' ;
2020-01-11 20:05:15 +01:00
$ordfieldselopts = '' ;
2020-01-12 07:14:48 +01:00
foreach ( $cols as $key => $arr ) {
if ( ! array_key_exists ( 'search' , $arr ) || $arr [ 'search' ] == true ) {
if ( $arr [ 'type' ] == 'joini' ) {
$fieldselopts .= '<option value="' . $key . ':' . $arr [ 'type' ] . ':' . $arr [ 'subtype' ] . '">' . $arr [ 'name' ] . '</option>' ;
2020-01-11 20:05:15 +01:00
} else {
2020-01-12 07:14:48 +01:00
$fieldselopts .= '<option value="' . $key . ':' . $arr [ 'type' ] . ':null">' . $arr [ 'name' ] . '</option>' ;
2020-01-11 20:05:15 +01:00
}
}
2020-01-12 07:14:48 +01:00
if ( ! array_key_exists ( 'ord' , $arr ) || $arr [ 'ord' ] == true ) {
2020-01-20 21:23:02 +01:00
if ( ! array_key_exists ( 'ordname' , $arr ))
$name = $arr [ 'name' ];
else
$name = $arr [ 'ordname' ];
2020-01-12 07:14:48 +01:00
if ( $arr [ 'type' ] == 'joini' ) {
2020-01-20 21:23:02 +01:00
$ordfieldselopts .= '<option value="' . $key . ':' . $arr [ 'type' ] . ':' . $arr [ 'subtype' ] . '">' . $name . '</option>' ;
2020-01-11 20:05:15 +01:00
} else {
2020-01-20 21:23:02 +01:00
$ordfieldselopts .= '<option value="' . $key . ':' . $arr [ 'type' ] . ':null">' . $name . '</option>' ;
2020-01-11 20:05:15 +01:00
}
2020-01-08 14:52:20 +01:00
}
}
2020-04-04 19:17:10 +02:00
$dbg .= '$_POST: <pre>' . print_r ( $_POST , 1 ) . '</pre>' ;
$page = $account [ 'Page' ];
if ( array_key_exists ( 'filt' , $_POST ) && $_POST [ 'filt' ] == 'filt' ) {
$page = 0 ;
$blocks = 0 ;
foreach ( $_POST as $key => $val )
if ( preg_match ( '/^openpar-\d+$/' , $key ) === 1 )
$blocks ++ ;
$fi = 0 ;
$oi = 0 ;
$admpresques = array ( 'DELETE FROM PresFiltCondsAdm WHERE AdmID=' . $account [ 'ID' ], 'DELETE FROM PresOrdCondsAdm WHERE AdmID=' . $account [ 'ID' ]);
foreach ( $_POST as $key => $val ) {
if ( preg_match ( '/^openpar-\d+$/' , $key ) === 1 ) {
$fi ++ ;
$admpresque = 'INSERT INTO PresFiltCondsAdm SET AdmID=' . $account [ 'ID' ] . ', ' ;
if ( preg_match ( '/^\(+$/' , $val ) === 1 )
$admpresque .= 'OpenPar=\'' . myesc ( $link , $val ) . '\', ' ;
else
$admpresque .= 'OpenPar=NULL, ' ;
}
if ( preg_match ( '/^fieldsel-\d+$/' , $key ) === 1 && preg_match ( '/^(.+):(.+):(.+)$/' , $val , $buf ) === 1 ) {
$tagk = $buf [ 1 ];
$type = $buf [ 2 ];
$subtype = $buf [ 3 ];
if ( array_key_exists ( $tagk , $cols ) && in_array ( $type , $types )) {
$admpresque .= 'Field=\'' . myesc ( $link , $val ) . '\', ' ;
} else {
muoribene ( $dbg . '<br>Dati POST corrotti.<br>Puoi <a href="instances.php">riprovare resettando i parametri</a> o <a href="index.php">tornare al login</a>.' , true );
}
}
if ( preg_match ( '/^condsel-\d+$/' , $key ) === 1 ) {
$admpresque .= 'Cond=\'' . myesc ( $link , $val ) . '\', ' ;
}
if ( preg_match ( '/^valuesel-\d+$/' , $key ) === 1 ) {
$admpresque .= 'ValueSel=\'' . myesc ( $link , $val ) . '\', ' ;
}
if ( preg_match ( '/^valueinp-\d+$/' , $key ) === 1 ) {
$admpresque .= 'ValueInp=\'' . myesc ( $link , $val ) . '\', ' ;
}
if ( preg_match ( '/^closepar-\d+$/' , $key ) === 1 ) {
if ( preg_match ( '/^\)+$/' , $val ) === 1 )
$admpresque .= 'ClosePar=\'' . myesc ( $link , $val ) . '\', ' ;
else
$admpresque .= 'ClosePar=NULL, ' ;
}
if ( preg_match ( '/^andor-\d+$/' , $key ) === 1 && preg_match ( '/^AND|OR$/' , $val ) === 1 ) {
if ( $fi < $blocks )
$admpresque .= 'AndOr=\'' . myesc ( $link , $val ) . '\', ' ;
else
$admpresque .= 'AndOr=NULL, ' ;
$admpresque .= 'Pos=' . $fi ;
$admpresques [] = $admpresque ;
}
if ( preg_match ( '/^ordfieldsel-\d+$/' , $key ) === 1 && preg_match ( '/^(.+):(.+):(.+)$/' , $val , $buf ) === 1 ) {
$oi ++ ;
$tagk = $buf [ 1 ];
$type = $buf [ 2 ];
$subtype = $buf [ 3 ];
if ( array_key_exists ( $tagk , $cols ) && in_array ( $type , $types )) {
$admpresque = 'INSERT INTO PresOrdCondsAdm SET AdmID=' . $account [ 'ID' ] . ', Field=\'' . myesc ( $link , $val ) . '\', ' ;
} else {
muoribene ( $dbg . '<br>Dati POST corrotti.<br>Puoi <a href="instances.php">riprovare resettando i parametri</a> o <a href="index.php">tornare al login</a>.' , true );
}
}
if ( preg_match ( '/^ascdesc-\d+$/' , $key ) === 1 && preg_match ( '/^ASC|DESC$/' , $val ) === 1 ) {
$admpresque .= 'Sort=\'' . myesc ( $link , $val ) . '\', Pos=' . $oi ;
$admpresques [] = $admpresque ;
}
}
$dbg .= '$admpresques: <pre>' . print_r ( $admpresques , 1 ) . '</pre>' . N ;
foreach ( $admpresques as $que )
mysqli_query ( $link , $que )
or muoribene ( __LINE__ . ': ' . $dbg . '<br>' . N . mysqli_error ( $link ), true );
} elseif ( array_key_exists ( 'pageselect' , $_POST ) && preg_match ( '/^[0-9]+$/' , $_POST [ 'pageselect' ]) === 1 ) {
$page = $_POST [ 'pageselect' ] + 0 ;
mysqli_query ( $link , 'UPDATE Admins SET Page=' . $page . ' WHERE ID=' . $account [ 'ID' ])
or muoribene ( __LINE__ . ': ' . $dbg . '<br>' . N . mysqli_error ( $link ), true );
}
2020-01-20 21:23:02 +01:00
$fi = 0 ;
$ji = 0 ;
$oi = 0 ;
2020-04-05 22:45:21 +02:00
$filtordon = false ;
2020-01-09 20:43:28 +01:00
$jsaddrows = '' ;
$jssetrows = '' ;
2020-01-13 17:16:33 +01:00
$jsordaddrows = '' ;
$jsordsetrows = '' ;
2020-01-08 16:06:09 +01:00
$sels = array ();
2020-01-08 14:52:20 +01:00
$joins = array ();
2020-01-18 07:48:06 +01:00
$havings = array ();
2020-01-08 14:52:20 +01:00
$where = '' ;
2020-01-13 17:16:33 +01:00
$order = '' ;
2020-04-04 19:17:10 +02:00
$res = mysqli_query ( $link , 'SELECT * FROM PresFiltCondsAdm WHERE AdmID=' . $account [ 'ID' ] . ' ORDER BY Pos ASC' )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ));
$blocks = mysqli_num_rows ( $res );
2020-04-05 22:45:21 +02:00
if ( $blocks > 0 ) $filtordon = true ;
2020-04-04 19:17:10 +02:00
while ( $row = mysqli_fetch_assoc ( $res )) {
$fi ++ ;
if ( preg_match ( '/^\(+$/' , $row [ 'OpenPar' ]) === 1 ) {
$where .= $row [ 'OpenPar' ];
$jssetrows .= 'setrow(' . $fi . ',' . json_encode ( $row [ 'OpenPar' ]);
} else {
$jssetrows .= 'setrow(' . $fi . ',"null"' ;
2020-01-09 20:43:28 +01:00
}
2020-04-04 19:17:10 +02:00
$jsaddrows .= 'addrow(' . $fi . ',false);' . N ;
preg_match ( '/^(.+):(.+):(.+)$/' , $row [ 'Field' ], $buf );
$tagk = $buf [ 1 ];
$type = $buf [ 2 ];
$subtype = $buf [ 3 ];
if ( array_key_exists ( $tagk , $cols ) && in_array ( $type , $types )) {
( $tagk == 'Instances.AdmCreatedAt' ) ? $inpisdate = true : $inpisdate = false ;
if ( strpos ( $cols [ $tagk ][ 'field' ], '%' ) !== false )
$ji ++ ;
$where .= str_replace ( '%' , $ji , $cols [ $tagk ][ 'field' ]);
if ( $type == 'join' || $type == 'joini' ) {
foreach ( $cols [ $tagk ][ 'join' ] as $join ) {
$join = str_replace ( '%' , $ji , $join );
if ( ! in_array ( $join , $joins ))
$joins [] = $join ;
2020-01-08 14:52:20 +01:00
}
}
2020-04-04 19:17:10 +02:00
if ( array_key_exists ( 'havings' , $cols [ $tagk ]) && ! in_array ( $cols [ $tagk ][ 'havings' ], $havings ))
$havings [] = $cols [ $tagk ][ 'havings' ];
if ( array_key_exists ( 'selmore' , $cols [ $tagk ]) && ! in_array ( $cols [ $tagk ][ 'selmore' ], $sels ))
$sels [] = $cols [ $tagk ][ 'selmore' ];
$jssetrows .= ',' . json_encode ( $row [ 'Field' ]);
2020-01-08 14:52:20 +01:00
}
2020-04-04 19:17:10 +02:00
$where .= ' ' . $row [ 'Cond' ] . ' ' ;
$cond = $row [ 'Cond' ];
$jssetrows .= ',' . json_encode ( $row [ 'Cond' ]);
// nel caso qui sotto, valuesel e valueinp sono entrambi disabilitati (non ci sono in $_POST), quindi li riempio di introvabile e nulla
if ( preg_match ( '/^IS NULL|IS NOT NULL$/' , $row [ 'Cond' ]) === 1 )
$jssetrows .= ',"NOMMITROVI!",""' ;
if ( ! is_null ( $row [ 'ValueSel' ])) {
$where .= $row [ 'ValueSel' ];
$jssetrows .= ',' . json_encode ( $row [ 'ValueSel' ]);
2020-01-09 20:43:28 +01:00
$jssetrows .= ',""' ;
}
2020-04-04 19:17:10 +02:00
if ( ! is_null ( $row [ 'ValueInp' ])) {
if ( $inpisdate && preg_match ( '/^([0-9]{1,2}) ([0-9]{1,2}) ([0-9]{4,5})$/' , $row [ 'ValueInp' ], $buf ) === 1 ) {
2020-03-09 22:16:54 +01:00
$where .= mktime ( 0 , 0 , 0 , $buf [ 2 ] + 0 , $buf [ 1 ] + 0 , $buf [ 3 ] + 0 );
} elseif ( preg_match ( '/^LIKE|NOT LIKE$/' , $cond ) === 1 ) {
2020-04-04 19:17:10 +02:00
$where .= '\'%' . myesc ( $link , $row [ 'ValueInp' ]) . '%\'' ;
2020-03-09 22:16:54 +01:00
} else {
2020-04-04 19:17:10 +02:00
$where .= '\'' . myesc ( $link , $row [ 'ValueInp' ]) . '\'' ;
2020-03-09 22:16:54 +01:00
}
2020-01-20 21:23:02 +01:00
$jssetrows .= ',"NOMMITROVI!"' ;
2020-04-04 19:17:10 +02:00
$jssetrows .= ',' . json_encode ( $row [ 'ValueInp' ]);
2020-01-08 14:52:20 +01:00
}
2020-04-04 19:17:10 +02:00
if ( preg_match ( '/^\)+$/' , $row [ 'ClosePar' ]) === 1 ) {
$where .= $row [ 'ClosePar' ];
$jssetrows .= ',' . json_encode ( $row [ 'ClosePar' ]);
} else {
$jssetrows .= ',"null"' ;
2020-01-09 20:43:28 +01:00
}
2020-04-04 19:17:10 +02:00
if ( preg_match ( '/^AND|OR$/' , $row [ 'AndOr' ]) === 1 ) {
if ( $fi < $blocks )
$where .= ' ' . $row [ 'AndOr' ] . ' ' ;
$jssetrows .= ',' . json_encode ( $row [ 'AndOr' ]) . ');' . N ;
} else {
$jssetrows .= ',"AND");' . N ;
2020-01-09 20:43:28 +01:00
}
2020-04-04 19:17:10 +02:00
}
2020-01-13 17:16:33 +01:00
2020-04-04 19:17:10 +02:00
$res = mysqli_query ( $link , 'SELECT * FROM PresOrdCondsAdm WHERE AdmID=' . $account [ 'ID' ] . ' ORDER BY Pos ASC' )
or muoribene ( __LINE__ . ': ' . mysqli_error ( $link ));
2020-04-05 22:45:21 +02:00
if ( mysqli_num_rows ( $res ) > 0 ) $filtordon = true ;
2020-04-04 19:17:10 +02:00
while ( $row = mysqli_fetch_assoc ( $res )) {
preg_match ( '/^(.+):(.+):(.+)$/' , $row [ 'Field' ], $buf );
$oi ++ ;
$tagk = $buf [ 1 ];
$type = $buf [ 2 ];
$subtype = $buf [ 3 ];
if ( array_key_exists ( $tagk , $cols ) && in_array ( $type , $types )) {
if ( $type == 'join' || $type == 'joini' ) {
if ( ! array_key_exists ( 'ordjoin' , $cols [ $tagk ])) {
foreach ( $cols [ $tagk ][ 'join' ] as $join )
if ( ! in_array ( $join , $joins ))
$joins [] = $join ;
2020-01-13 17:16:33 +01:00
} else {
2020-04-04 19:17:10 +02:00
foreach ( $cols [ $tagk ][ 'ordjoin' ] as $join )
if ( ! in_array ( $join , $joins ))
$joins [] = $join ;
2020-01-18 07:48:06 +01:00
}
2020-04-04 19:17:10 +02:00
}
if ( ! array_key_exists ( 'ordby' , $cols [ $tagk ])) {
$order .= $cols [ $tagk ][ 'field' ];
2020-01-13 17:16:33 +01:00
} else {
2020-04-04 19:17:10 +02:00
if ( ! in_array ( $cols [ $tagk ][ 'ordselmore' ], $sels ))
$sels [] = $cols [ $tagk ][ 'ordselmore' ];
$order .= $cols [ $tagk ][ 'ordby' ];
2020-01-13 17:16:33 +01:00
}
2020-04-04 19:17:10 +02:00
if ( array_key_exists ( 'havings' , $cols [ $tagk ]) && ! in_array ( $cols [ $tagk ][ 'havings' ], $havings ))
$havings [] = $cols [ $tagk ][ 'havings' ];
if ( array_key_exists ( 'selmore' , $cols [ $tagk ]) && ! in_array ( $cols [ $tagk ][ 'selmore' ], $sels ))
$sels [] = $cols [ $tagk ][ 'selmore' ];
$jsordaddrows .= 'ordaddrow(' . $oi . ',false);' . N ;
$jsordsetrows .= 'ordsetrow(' . $oi . ',' . json_encode ( $row [ 'Field' ]);
} else {
muoribene ( $dbg . '<br>Dati db corrotti.<br>Puoi <a href="instances.php">riprovare resettando i parametri</a> o <a href="index.php">tornare al login</a>.' , true );
2020-01-13 17:16:33 +01:00
}
2020-04-04 19:17:10 +02:00
$order .= ' ' . $row [ 'Sort' ] . ', ' ;
$jsordsetrows .= ',' . json_encode ( $row [ 'Sort' ]) . ');' . N ;
2020-01-09 20:43:28 +01:00
}
2020-04-04 19:17:10 +02:00
2020-01-09 20:43:28 +01:00
if ( $jsaddrows != '' ) {
2020-04-17 23:57:02 +02:00
$jsaddrows .= 'document.getElementById("filbut").value="Rimuovi tutti i criteri di filtraggio";' . N ;
2020-01-09 20:43:28 +01:00
$jsaddrows .= 'synctai();' . N ;
2020-01-05 05:46:29 +01:00
}
2020-01-13 17:16:33 +01:00
if ( $jsordaddrows != '' ) {
$jsordaddrows .= 'document.getElementById("ordbut").value="Rimuovi tutti i criteri di ordinamento";' . N ;
$jsordaddrows .= 'synctoi();' . N ;
}
2020-01-08 16:06:09 +01:00
if ( count ( $sels ) > 0 )
$sels = ', ' . implode ( ', ' , $sels );
else
$sels = '' ;
2020-01-08 14:52:20 +01:00
if ( $where != '' )
$where = 'WHERE ' . $where ;
2020-01-13 17:16:33 +01:00
if ( $order != '' )
$order = 'ORDER BY ' . substr ( $order , 0 , - 2 );
$dbg .= 'ORDER: ' . $order . '<br>' ;
2020-01-08 14:52:20 +01:00
if ( count ( $joins ) > 0 )
$joins = 'LEFT JOIN ' . implode ( ' LEFT JOIN ' , $joins );
else
$joins = '' ;
2020-01-18 07:48:06 +01:00
if ( count ( $havings ) > 0 )
$havings = 'HAVING ' . implode ( ' AND ' , $havings );
else
$havings = '' ;
2020-01-08 14:52:20 +01:00
2020-04-07 19:39:06 +02:00
$query = 'SELECT *, Instances.ID AS IID ' . $sels . ' FROM Instances ' . $joins . ' ' . $where . ' GROUP BY IID ' . $havings . ' ' . $order ;
$dbg .= 'QUERONA: ' . $query . '<br>' . N ;
$tini = microtime ( true );
2020-03-09 22:16:54 +01:00
$res = mysqli_query ( $link , $query )
or muoribene ( $dbg . '<br>' . $query . ': ' . mysqli_error ( $link ) . '<br>' . 'La query è fallita. <a href="instances.php">Resetta</a>.' , true );
2020-04-07 19:39:06 +02:00
$dbg .= 'Durata esecuzione query: ' . round ( microtime ( true ) - $tini , 4 ) . ' sec.<br>' . N ;
2020-03-09 22:16:54 +01:00
$cinsts = mysqli_num_rows ( $res );
$iperp = 25 ;
if ( $page * $iperp > $cinsts )
$page = 0 ;
$finst = $page * $iperp ;
2020-04-07 19:39:06 +02:00
if ( mysqli_num_rows ( $res ) < 1 ) {
2020-03-09 22:16:54 +01:00
$pgout = '' ;
2019-12-26 21:57:36 +01:00
$out = '<p>Nessuna istanza da mostrare.</p>' . N ;
} else {
2020-03-09 22:16:54 +01:00
// $pgout='Pag. '.($page+1).'/'.(ceil($cinsts/$iperp)-1);
2020-04-04 19:17:10 +02:00
$pgout = '<form method="post" id="pform">' . N ;
$pgout .= '<select id="pageselect" name="pageselect" onchange="document.getElementById(\'pform\').submit()">' . N ;
2020-03-09 22:16:54 +01:00
$totp = ceil ( $cinsts / $iperp );
for ( $i = 0 ; $i < $totp ; $i ++ ) {
$lastpi = $i * $iperp + $iperp ;
if ( $lastpi > $cinsts ) $lastpi = $cinsts ;
( $i != $page ) ? $selected = '' : $selected = ' selected' ;
$pgout .= '<option value="' . $i . '"' . $selected . '>Pagina ' . ( $i + 1 ) . '/' . $totp . ' (Istanze ' . ( $i * $iperp + 1 ) . '-' . $lastpi . '/' . $cinsts . ')</option>' . N ;
}
2020-04-04 19:17:10 +02:00
$pgout .= '</select>' . N ;
$pgout .= '</form>' ;
2020-03-09 22:16:54 +01:00
// ---
2020-04-07 19:39:06 +02:00
mysqli_data_seek ( $res , $finst );
2020-01-05 05:46:29 +01:00
$out = '' ;
2020-04-07 19:39:06 +02:00
$i = $finst ;
$ii = 0 ;
require ( 'include/dispinst.php' );
2019-12-26 21:57:36 +01:00
while ( $row = mysqli_fetch_assoc ( $res )) {
2020-04-07 19:39:06 +02:00
$i ++ ;
$ii ++ ;
if ( $ii > $iperp ) break ;
2020-05-01 06:51:22 +02:00
$out .= dispinst ( $row , $cols , $link , $dlang , $account , true , $i , $cinsts );
2019-12-26 21:57:36 +01:00
}
2020-04-07 19:39:06 +02:00
$out .= '<div class="bigtabfoot"></div>' . N ;
2019-12-26 21:57:36 +01:00
}
2020-01-27 17:26:37 +01:00
$presid = 0 ;
if ( array_key_exists ( 'presets' , $_POST ) && preg_match ( '/^[0-9]+$/' , $_POST [ 'presets' ]) === 1 )
$presid = $_POST [ 'presets' ];
$presopts = '<option value="null"></option>' . N ;
2020-02-01 21:50:23 +01:00
$res = mysqli_query ( $link , 'SELECT * FROM Presets ORDER BY LENGTH(Name) ASC, Name ASC' )
2020-01-20 21:23:02 +01:00
or muoribene ( mysqli_error ( $link ), true );
2020-01-27 17:26:37 +01:00
while ( $row = mysqli_fetch_assoc ( $res )) {
if ( $row [ 'ID' ] != $presid )
$presopts .= '<option value="' . $row [ 'ID' ] . '">' . hspech ( $row [ 'Name' ]) . '</option>' . N ;
else
$presopts .= '<option value="' . $row [ 'ID' ] . '" selected>' . hspech ( $row [ 'Name' ]) . '</option>' . N ;
}
2020-01-20 21:23:02 +01:00
2020-04-17 23:57:02 +02:00
require ( 'include/notifs.php' );
$notifs = notifs ( $link );
2020-04-16 22:56:12 +02:00
2020-01-02 22:03:34 +01:00
mysqli_close ( $link );
2019-12-26 21:57:36 +01:00
2020-04-05 22:45:21 +02:00
if ( $filtordon ) {
$filtordimgoff = 'imgs/cerca_act_off.svg' ;
$filtordimgon = 'imgs/cerca_act_on.svg' ;
} else {
$filtordimgoff = 'imgs/cerca_off.svg' ;
$filtordimgon = 'imgs/cerca_on.svg' ;
}
2019-12-26 21:57:36 +01:00
?>
<! DOCTYPE HTML >
< html lang = " it " >
< head >
2020-05-01 06:51:22 +02:00
< title > Mustard - Elenco istanze </ title >
2019-12-26 21:57:36 +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-01-08 14:52:20 +01:00
< script language = " JavaScript " src = " js/confirma.js?v=<?php echo( $cjrand ); ?> " ></ script >
2020-01-11 00:51:02 +01:00
< script language = " JavaScript " src = " js/alerta.js?v=<?php echo( $cjrand ); ?> " ></ script >
2019-12-26 21:57:36 +01:00
< link rel = " stylesheet " type = " text/css " href = " theme.css?v=<?php echo( $cjrand ); ?> " >
< script language = " JavaScript " >
<!--
2020-04-17 23:57:02 +02:00
< ? php require ( 'js/notifs.js.php' ); ?>
2020-01-08 14:52:20 +01:00
function shideplancia () {
var plancia = document . getElementById ( 'plancia' );
2020-03-11 08:43:56 +01:00
var plctrl = document . getElementById ( 'lente' );
2020-01-08 14:52:20 +01:00
if ( plancia . style . display == 'block' ) {
plancia . style . display = 'none' ;
2020-04-16 22:56:12 +02:00
plctrl . src = '<?php echo($filtordimgoff); ?>' ;
2020-04-17 23:57:02 +02:00
plctrl . title = 'Mostra il pannello di filtraggio e ordinamento' ;
2020-01-08 14:52:20 +01:00
} else {
plancia . style . display = 'block' ;
2020-04-16 22:56:12 +02:00
plctrl . src = '<?php echo($filtordimgon); ?>' ;
2020-04-17 23:57:02 +02:00
plctrl . title = 'Nascondi il pannello di filtraggio e ordinamento' ;
2020-04-16 22:56:12 +02:00
}
}
2020-03-09 22:16:54 +01:00
function hent ( str ) {
return str . replace ( /&/ g , '&' ) . replace ( />/ g , '>' ) . replace ( /</ g , '<' ) . replace ( / " /g,'"');
}
2020-01-05 05:46:29 +01:00
function truncsel ( el ) {
2020-03-24 23:22:07 +01:00
var sel = document . getElementById ( el );
sel . length = 0 ;
2020-01-05 05:46:29 +01:00
}
function inpdisif ( index ) {
2020-01-11 21:53:37 +01:00
console . log ( 'inpdisif index: ' + index );
2020-01-08 14:52:20 +01:00
var source = document . getElementById ( 'condsel-' + index );
2020-01-08 16:06:09 +01:00
var inp = document . getElementById ( 'valueinp-' + index );
var sel = document . getElementById ( 'valuesel-' + index );
2020-01-05 05:46:29 +01:00
var conds = [ 'IS NULL' , 'IS NOT NULL' ];
if ( conds . includes ( source . value )) {
2020-01-08 16:06:09 +01:00
inp . disabled = true ;
sel . disabled = true ;
2020-01-05 05:46:29 +01:00
} else {
2020-01-08 16:06:09 +01:00
if ( inp . style . display != 'none' ) inp . disabled = false ;
if ( sel . style . display != 'none' ) sel . disabled = false ;
2020-01-05 05:46:29 +01:00
}
}
2020-01-09 20:43:28 +01:00
function popusels ( index , valselval ) {
2020-01-11 21:53:37 +01:00
console . log ( 'popusels index: ' + index );
2020-01-08 14:52:20 +01:00
var key = document . getElementById ( 'fieldsel-' + index ) . value ;
2020-01-11 20:05:15 +01:00
var type = key . replace ( /^.*: ( .* ) :.* $ / , '$1' );
var subtype = key . replace ( /^.*:.*: ( .* ) $ / , '$1' );
key = key . replace ( /^ ( .* ) :.*:.* $ / , '$1' );
2020-01-08 14:52:20 +01:00
var condsel = document . getElementById ( 'condsel-' + index );
var valsel = document . getElementById ( 'valuesel-' + index );
var valinp = document . getElementById ( 'valueinp-' + index );
2020-01-11 21:53:37 +01:00
condsel . setAttribute ( 'onchange' , 'inpdisif(' + index + ');' );
2020-01-08 14:52:20 +01:00
if ( type == 'joini' )
type = subtype ;
2020-01-05 05:46:29 +01:00
if ( type == 'bool' ) {
2020-01-08 14:52:20 +01:00
truncsel ( 'condsel-' + index );
2020-03-11 17:25:06 +01:00
condsel . add ( new Option ( 'è' , 'IS' ));
2020-01-08 14:52:20 +01:00
truncsel ( 'valuesel-' + index );
2020-03-11 17:25:06 +01:00
valsel . add ( new Option ( 'vero' , 'TRUE' ));
valsel . add ( new Option ( 'falso' , 'FALSE' ));
valsel . add ( new Option ( 'definit@' , 'NOT NULL' ));
valsel . add ( new Option ( 'non definit@' , 'NULL' ));
2020-01-11 20:05:15 +01:00
if ( valselval !== false )
selind ( 'valuesel-' + index , valselval );
2020-01-11 21:53:37 +01:00
valinp . style . display = 'none' ;
2020-01-05 05:46:29 +01:00
valinp . disabled = true ;
2020-01-11 21:53:37 +01:00
valsel . style . display = 'block' ;
2020-01-05 05:46:29 +01:00
valsel . disabled = false ;
} else if ( type == 'text' ) {
2020-01-08 14:52:20 +01:00
truncsel ( 'condsel-' + index );
2020-03-11 17:25:06 +01:00
condsel . add ( new Option ( 'contiene' , 'LIKE' ));
condsel . add ( new Option ( 'non contiene' , 'NOT LIKE' ));
condsel . add ( new Option ( 'è uguale a' , '=' ));
condsel . add ( new Option ( 'è divers@ da' , '!=' ));
condsel . add ( new Option ( 'è maggiore o uguale a' , '>=' ));
condsel . add ( new Option ( 'è minore o uguale a' , '<=' ));
condsel . add ( new Option ( 'è maggiore di' , '>' ));
condsel . add ( new Option ( 'è minore di' , '<' ));
condsel . add ( new Option ( 'è definit@' , 'IS NOT NULL' ));
condsel . add ( new Option ( 'non è definit@' , 'IS NULL' ));
2020-01-11 21:53:37 +01:00
valsel . style . display = 'none' ;
2020-01-05 05:46:29 +01:00
valsel . disabled = true ;
2020-01-11 21:53:37 +01:00
valinp . style . display = 'block' ;
2020-01-05 05:46:29 +01:00
valinp . disabled = false ;
} else if ( type == 'int' || type == 'time' ) {
2020-01-08 14:52:20 +01:00
truncsel ( 'condsel-' + index );
2020-03-11 17:25:06 +01:00
condsel . add ( new Option ( 'è maggiore o uguale a' , '>=' ));
condsel . add ( new Option ( 'è minore o uguale a' , '<=' ));
condsel . add ( new Option ( 'è maggiore di' , '>' ));
condsel . add ( new Option ( 'è minore di' , '<' ));
condsel . add ( new Option ( 'è uguale a' , '=' ));
condsel . add ( new Option ( 'è divers@ da' , '!=' ));
condsel . add ( new Option ( 'è definit@' , 'IS NOT NULL' ));
condsel . add ( new Option ( 'non è definit@' , 'IS NULL' ));
2020-01-11 21:53:37 +01:00
valsel . style . display = 'none' ;
2020-01-05 05:46:29 +01:00
valsel . disabled = true ;
2020-01-11 21:53:37 +01:00
valinp . style . display = 'block' ;
2020-01-05 05:46:29 +01:00
valinp . disabled = false ;
2020-01-08 14:52:20 +01:00
} else if ( type == 'join' ) {
truncsel ( 'condsel-' + index );
2020-03-11 17:25:06 +01:00
condsel . add ( new Option ( 'è uguale a' , '=' ));
condsel . add ( new Option ( 'è divers@ da' , '!=' ));
condsel . add ( new Option ( 'è definit@' , 'IS NOT NULL' ));
condsel . add ( new Option ( 'non è definit@' , 'IS NULL' ));
2020-01-11 21:53:37 +01:00
valsel . style . display = 'block' ;
2020-01-08 14:52:20 +01:00
valsel . disabled = false ;
2020-01-11 21:53:37 +01:00
valinp . style . display = 'none' ;
2020-01-08 14:52:20 +01:00
valinp . disabled = true ;
truncsel ( 'valuesel-' + index );
2020-01-18 07:48:06 +01:00
pupwait ( true );
2020-01-09 20:43:28 +01:00
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 ++ )
2020-03-11 17:25:06 +01:00
valsel . add ( new Option ( jarr [ i ][ 1 ], jarr [ i ][ 0 ]));
2020-01-09 20:43:28 +01:00
console . log ( 'valsel pronto!' );
if ( valselval !== false )
selind ( 'valuesel-' + index , valselval );
2020-01-18 07:48:06 +01:00
pupwait ( false );
2020-01-09 20:43:28 +01:00
};
xhr . onerror = function () {
2020-01-27 17:26:37 +01:00
pupwait ( false );
alert ( 'La richiesta è fallita.' );
2020-01-09 20:43:28 +01:00
};
2020-01-05 05:46:29 +01:00
} else {
alert ( 'Attenziò: non so che farmene del tipo "' + type + '": diglielo, al programmatore.' );
}
}
2020-01-09 20:43:28 +01:00
function addrow ( index , refresh ) {
2020-01-08 14:52:20 +01:00
var table = document . getElementById ( 'planciafil' );
2020-03-09 22:16:54 +01:00
if ( table . rows . length < 9 ) {
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"><?php echo($fieldselopts); ?></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" title="Aggiungi un criterio sotto questo">' ;
newcell6 . style . width = '22px' ;
newcell7 . innerHTML = '<img class="minus" src="imgs/minus.svg" title="Rimuovi questo criterio">' ;
newcell7 . style . width = '22px' ;
if ( refresh ) {
synctai ();
popusels ( index , false );
}
} else {
2020-05-01 06:51:22 +02:00
alerta ( 'Attenzione' , '<p>Non è possibile impostare più di 8 criteri di filtraggio.</p>' );
2020-01-09 20:43:28 +01:00
}
2020-01-05 05:46:29 +01:00
}
2020-01-13 17:16:33 +01:00
function ordaddrow ( index , refresh ) {
var table = document . getElementById ( 'planciaord' );
2020-03-09 22:16:54 +01:00
if ( table . rows . length < 7 ) {
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"><?php echo($ordfieldselopts); ?></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" title="Aggiungi un criterio sotto questo">' ;
newcell3 . innerHTML = '<img class="minus" src="imgs/minus.svg" title="Rimuovi questo criterio">' ;
if ( refresh )
synctoi ();
} else {
2020-05-01 06:51:22 +02:00
alerta ( 'Attenzione' , '<p>Non è possibile impostare più di 6 criteri di ordinamento.<p>' );
2020-03-09 22:16:54 +01:00
}
2020-01-13 17:16:33 +01:00
}
2020-01-05 05:46:29 +01:00
function synctai () {
var i = 0 ;
2020-01-08 14:52:20 +01:00
var table = document . getElementById ( 'planciafil' );
2020-01-05 05:46:29 +01:00
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
2020-01-09 20:43:28 +01:00
nodes [ i ] . setAttribute ( 'onclick' , 'addrow(' + ( i + 2 ) + ',true);' );
2020-01-05 05:46:29 +01:00
// 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 -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'openpar-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'openpar-' + ( i + 1 ));
2020-01-05 05:46:29 +01:00
}
nodes = table . querySelectorAll ( '.fieldsel' );
for ( i = cnodes ; i >- 1 ; i -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'fieldsel-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'fieldsel-' + ( i + 1 ));
2020-01-09 20:43:28 +01:00
nodes [ i ] . setAttribute ( 'onchange' , 'popusels(' + ( i + 1 ) + ',false);' );
2020-01-05 05:46:29 +01:00
}
nodes = table . querySelectorAll ( '.condsel' );
for ( i = cnodes ; i >- 1 ; i -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'condsel-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'condsel-' + ( i + 1 ));
2020-01-11 21:53:37 +01:00
nodes [ i ] . setAttribute ( 'onchange' , 'inpdisif(' + ( i + 1 ) + ');' );
2020-01-05 05:46:29 +01:00
}
nodes = table . querySelectorAll ( '.valuesel' );
for ( i = cnodes ; i >- 1 ; i -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'valuesel-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'valuesel-' + ( i + 1 ));
2020-01-05 05:46:29 +01:00
}
nodes = table . querySelectorAll ( '.valueinp' );
for ( i = cnodes ; i >- 1 ; i -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'valueinp-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'valueinp-' + ( i + 1 ));
2020-01-05 05:46:29 +01:00
}
nodes = table . querySelectorAll ( '.closepar' );
for ( i = cnodes ; i >- 1 ; i -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'closepar-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'closepar-' + ( i + 1 ));
2020-01-05 05:46:29 +01:00
}
nodes = table . querySelectorAll ( '.andor' );
for ( i = cnodes ; i >- 1 ; i -- ) {
2020-01-08 14:52:20 +01:00
nodes [ i ] . setAttribute ( 'id' , 'andor-' + ( i + 1 ));
nodes [ i ] . setAttribute ( 'name' , 'andor-' + ( i + 1 ));
2020-01-05 05:46:29 +01:00
nodes [ i ] . disabled = false ;
}
2020-01-08 14:52:20 +01:00
if ( cnodes >= 0 )
2020-01-05 05:46:29 +01:00
nodes [ cnodes ] . disabled = true ;
}
2020-01-13 17:16:33 +01:00
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 ));
}
}
2020-01-09 20:43:28 +01:00
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 )
2020-01-11 20:05:15 +01:00
console . log ( '"' + val + '" non è stato trovato in "' + id + '"' );
2020-01-09 20:43:28 +01:00
}
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 ;
2020-01-11 20:05:15 +01:00
if ( condselv == 'IS NULL' || condselv == 'IS NOT NULL' ) {
document . getElementById ( 'valueinp-' + index ) . disabled = true ;
document . getElementById ( 'valuesel-' + index ) . disabled = true ;
}
2020-01-09 20:43:28 +01:00
selind ( 'closepar-' + index , closeparv );
selind ( 'andor-' + index , andorv );
}
2020-01-13 17:16:33 +01:00
function ordsetrow ( index , ordfieldselv , ascdescv ) {
selind ( 'ordfieldsel-' + index , ordfieldselv );
selind ( 'ascdesc-' + index , ascdescv );
}
2020-01-05 05:46:29 +01:00
function remrow ( index ) {
2020-01-08 14:52:20 +01:00
var table = document . getElementById ( 'planciafil' );
2020-01-05 05:46:29 +01:00
table . deleteRow ( index );
synctai ();
2020-01-08 14:52:20 +01:00
if ( table . rows . length < 2 )
2020-04-17 23:57:02 +02:00
document . getElementById ( 'filbut' ) . value = 'Aggiungi criteri di filtraggio' ;
2020-01-08 14:52:20 +01:00
}
2020-01-13 17:16:33 +01:00
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' ;
}
2020-01-08 14:52:20 +01:00
function truncfil () {
var table = document . getElementById ( 'planciafil' );
while ( table . rows . length > 1 )
remrow ( 1 );
}
2020-01-13 17:16:33 +01:00
function truncord () {
var table = document . getElementById ( 'planciaord' );
while ( table . rows . length > 1 )
ordremrow ( 1 );
}
2020-01-08 14:52:20 +01:00
function manfil () {
var filbut = document . getElementById ( 'filbut' );
var table = document . getElementById ( 'planciafil' );
var crows = table . rows . length ;
if ( crows < 2 ) {
2020-01-09 20:43:28 +01:00
addrow ( 1 , true );
2020-04-17 23:57:02 +02:00
filbut . value = 'Rimuovi tutti i criteri di filtraggio' ;
2020-01-08 14:52:20 +01:00
} else {
2020-04-17 23:57:02 +02:00
confirma ( '<p>Confermi di voler rimuovere tutti i criteri di filtraggio?</p>' , 'truncfil();filbut.value=\'Aggiungi criteri di filtraggio\'' );
2020-01-13 17:16:33 +01:00
}
}
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\'' );
2020-01-08 14:52:20 +01:00
}
}
2020-01-11 00:51:02 +01:00
function ckpar () {
var i = 0 ;
2020-01-09 20:43:28 +01:00
var table = document . getElementById ( 'planciafil' );
2020-01-11 00:51:02 +01:00
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 = '' ;
2020-05-01 06:51:22 +02:00
if ( ! ckpar ()) emsg += '<p>Qualcosa non va con le parentesi!</p>' ;
2020-01-11 20:05:15 +01:00
// emsg+='Comunque NO!<br>\n';
2020-01-11 00:51:02 +01:00
if ( emsg == '' ) {
var table = document . getElementById ( 'planciafil' );
var crows = table . rows . length ;
2020-01-11 20:05:15 +01:00
if ( crows > 1 )
document . getElementById ( 'andor-' + ( crows - 1 )) . disabled = false ;
2020-01-11 00:51:02 +01:00
document . getElementById ( 'f' ) . submit ();
} else {
2020-05-01 06:51:22 +02:00
alerta ( 'Errore' , emsg );
2020-04-03 10:59:02 +02:00
return false ;
2020-01-11 00:51:02 +01:00
}
2020-01-05 05:46:29 +01:00
}
2020-01-18 07:48:06 +01:00
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> <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' ;
}
}
2020-01-20 21:23:02 +01:00
//function setrow(index,openparv,fieldselv,condselv,valueselv,valueinpv,closeparv,andorv)
2020-01-27 17:26:37 +01:00
function loadpres () {
let pres = document . getElementById ( 'presets' );
if ( pres . value != 'null' ) {
pupwait ( true );
let formdata = new FormData ();
formdata . append ( 'act' , 'load' );
formdata . append ( 'pid' , pres . value );
let xhr = new XMLHttpRequest ();
2020-03-09 22:16:54 +01:00
xhr . open ( 'POST' , 'loadsaverempres.php' );
2020-01-27 17:26:37 +01:00
xhr . responseType = 'json' ;
xhr . send ( formdata );
xhr . onload = function () {
let jarr = xhr . response ;
truncfil ();
for ( i = 0 ; i < jarr [ 'f' ] . length ; i ++ ) {
console . log ( jarr [ 'f' ][ i ]);
addrow ( i + 1 , false );
}
synctai ();
for ( i = 0 ; i < jarr [ 'f' ] . length ; i ++ ) {
setrow ( i + 1 , jarr [ 'f' ][ i ][ 'OpenPar' ], jarr [ 'f' ][ i ][ 'Field' ], jarr [ 'f' ][ i ][ 'Cond' ], jarr [ 'f' ][ i ][ 'ValueSel' ], jarr [ 'f' ][ i ][ 'ValueInp' ], jarr [ 'f' ][ i ][ 'ClosePar' ], jarr [ 'f' ][ i ][ 'AndOr' ]);
}
if ( jarr [ 'f' ] . length > 0 )
2020-04-17 23:57:02 +02:00
document . getElementById ( 'filbut' ) . value = 'Rimuovi tutti i criteri di filtraggio' ;
2020-01-27 17:26:37 +01:00
truncord ();
for ( i = 0 ; i < jarr [ 'o' ] . length ; i ++ ) {
console . log ( jarr [ 'o' ][ i ]);
ordaddrow ( i + 1 , false );
}
synctoi ();
for ( i = 0 ; i < jarr [ 'o' ] . length ; i ++ ) {
ordsetrow ( i + 1 , jarr [ 'o' ][ i ][ 'Field' ], jarr [ 'o' ][ i ][ 'Sort' ]);
}
if ( jarr [ 'o' ] . length > 0 )
document . getElementById ( 'ordbut' ) . value = 'Rimuovi tutti i criteri di ordinamento' ;
pupwait ( false );
};
xhr . onerror = function () {
pupwait ( false );
alert ( 'La richiesta è fallita.' );
};
} else {
2020-05-01 06:51:22 +02:00
alerta ( 'Attenzione' , '<p>Non hai selezionato alcun preset ;)</p>' );
2020-01-27 17:26:37 +01:00
}
2020-01-20 21:23:02 +01:00
}
2020-03-09 22:16:54 +01:00
function rempres () {
pupwait ( true );
let pres = document . getElementById ( 'presets' );
let formdata = new FormData ( document . forms . f );
formdata . append ( 'act' , 'remove' );
formdata . append ( 'pid' , pres . value );
let xhr = new XMLHttpRequest ();
xhr . open ( 'POST' , 'loadsaverempres.php' );
xhr . responseType = 'json' ;
xhr . send ( formdata );
xhr . onload = function () {
console . log ( xhr . response );
pres . remove ( pres . selectedIndex );
pres . selectedIndex = 0 ;
pupwait ( false );
};
xhr . onerror = function () {
pupwait ( false );
alert ( 'La richiesta è fallita.' );
};
}
2020-01-27 17:26:37 +01:00
function savepres ( txt , asnew ) {
2020-01-20 21:23:02 +01:00
pupwait ( true );
2020-01-27 17:26:37 +01:00
let pres = document . getElementById ( 'presets' );
2020-01-20 21:23:02 +01:00
let formdata = new FormData ( document . forms . f );
2020-01-27 17:26:37 +01:00
formdata . append ( 'act' , 'save' );
formdata . append ( 'txt' , txt );
if ( ! asnew )
formdata . append ( 'pid' , pres . value );
2020-01-20 21:23:02 +01:00
let xhr = new XMLHttpRequest ();
2020-03-09 22:16:54 +01:00
xhr . open ( 'POST' , 'loadsaverempres.php' );
2020-01-20 21:23:02 +01:00
xhr . responseType = 'json' ;
xhr . send ( formdata );
xhr . onload = function () {
console . log ( xhr . response );
2020-01-27 17:26:37 +01:00
if ( ! asnew ) {
pres . options [ pres . selectedIndex ] . text = txt ;
} else {
let jarr = xhr . response ;
pres . add ( new Option ( txt , jarr [ 'pid' ]));
pres . selectedIndex = pres . options . length - 1 ;
}
2020-01-20 21:23:02 +01:00
pupwait ( false );
};
xhr . onerror = function () {
2020-01-27 17:26:37 +01:00
pupwait ( false );
alert ( 'La richiesta è fallita.' );
2020-01-20 21:23:02 +01:00
};
}
2020-01-27 17:26:37 +01:00
function pupsavepres ( asnew ) {
var pres = document . getElementById ( 'presets' );
if ( pres . value != 'null' || asnew ) {
var pup = document . getElementById ( 'popup' ), inpup = document . getElementById ( 'inpopup' );
var prestext = pres . options [ pres . selectedIndex ] . text ;
var pre = '<p>Se vuoi puoi modificare il nome del preset che stai per sovrascrivere</p>' ;
if ( asnew ) pre = '<p>Dai un nuovo nome al nuovo preset che stai per salvare</p>' ;
2020-03-09 22:16:54 +01:00
inpup . innerHTML = '<div class="loadsavepresbub">' + pre + '<input type="text" maxlength="256" value="' + hent ( prestext ) + '" id="presname"><input type="button" value="Salva" onClick="ckpresname(' + asnew + ');"><input type="button" value="Annulla" onClick="pupoff();"><div id="ckmsg"></div></div>' ;
2020-01-27 17:26:37 +01:00
pup . style . display = 'table' ;
} else {
2020-05-01 06:51:22 +02:00
alerta ( 'Attenzione' , '<p>Non hai selezionato alcun preset ;)</p>' );
2020-01-27 17:26:37 +01:00
}
}
2020-03-09 22:16:54 +01:00
function puprempres () {
var pres = document . getElementById ( 'presets' );
if ( pres . value != 'null' ) {
var prestext = pres . options [ pres . selectedIndex ] . text ;
2020-03-10 11:28:30 +01:00
confirma ( '<p>Confermi l’ eliminazione del preset «' + hent ( prestext ) + '»?</p>' , 'rempres()' );
2020-03-09 22:16:54 +01:00
} else {
2020-05-01 06:51:22 +02:00
alerta ( 'Attenzione' , '<p>Non hai selezionato alcun preset ;)</p>' );
2020-03-09 22:16:54 +01:00
}
}
2020-01-27 17:26:37 +01:00
function ckpresname ( asnew ) {
var pres = document . getElementById ( 'presets' );
var presname = document . getElementById ( 'presname' ) . value ;
var ckmsg = document . getElementById ( 'ckmsg' );
var ok = true ;
var i ;
if ( presname . trim == '' ) {
presname = '' ;
ok = false ;
ckmsg . innerHTML = 'Non puoi salvare un preset senza nome' ;
}
if ( ! asnew ) {
for ( i = 0 ; i < pres . options . length ; i ++ ) {
if ( i != pres . selectedIndex && presname == pres . options [ i ] . text ) {
ok = false ;
ckmsg . innerHTML = '<p>Esiste già un altro preset con questo nome</p>' ;
break ;
}
}
} else {
for ( i = 0 ; i < pres . options . length ; i ++ ) {
if ( presname == pres . options [ i ] . text ) {
ok = false ;
ckmsg . innerHTML = '<p>Esiste già un preset con questo nome</p>' ;
break ;
}
}
}
if ( ok ) {
pupoff ();
savepres ( presname , asnew );
}
}
function pupoff () {
var pup = document . getElementById ( 'popup' ), inpup = document . getElementById ( 'inpopup' );
inpup . innerHTML = '<div id="popupcont">...</div>' ;
pup . style . display = 'none' ;
}
2019-12-26 21:57:36 +01:00
//-->
</ script >
</ head >
2020-01-11 00:51:02 +01:00
< body >
2019-12-26 21:57:36 +01:00
< nav >
< div id = " hmenu " >
< ul >
< ? php echo ( $menuout ); ?>
</ ul >
2020-04-07 19:39:06 +02:00
< div class = " mtit " > Elenco istanze </ div >
2020-01-11 20:05:15 +01:00
< div id = " rightdiv " >
2020-04-17 23:57:02 +02:00
< 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(); " >
2020-04-21 12:35:53 +02:00
< img src = " imgs/esci.svg " class = " rlinks " title = " Logout " onclick = " document.location.href='logout.php'; " >
2020-03-09 22:16:54 +01:00
</ div >
2019-12-26 21:57:36 +01:00
</ div >
</ nav >
2020-04-17 23:57:02 +02:00
< ? php echo ( $notifs [ 'div' ]); ?>
2020-04-16 22:56:12 +02:00
2020-01-08 14:52:20 +01:00
< div id = " popup " >
< div id = " inpopup " >
< div id = " popupcont " >
...
</ div >
</ div >
</ div >
2019-12-26 21:57:36 +01:00
< div id = " footer " >
2020-03-09 22:16:54 +01:00
< ? php echo ( $pgout ); ?>
2019-12-26 21:57:36 +01:00
</ div >
2020-01-05 05:46:29 +01:00
2020-01-08 14:52:20 +01:00
< div id = " debug " >
< ? php echo ( $dbg ); ?>
</ div >
2020-01-05 05:46:29 +01:00
2020-01-08 14:52:20 +01:00
< div id = " plancia " >
2020-04-03 10:59:02 +02:00
< form method = " post " id = " f " onsubmit = " return ckf(); " >
2020-01-08 14:52:20 +01:00
< table id = " planciafil " class = " planciatab " >
2020-04-17 23:57:02 +02:00
< tr >< td colspan = " 8 " >< input type = " button " id = " filbut " value = " Aggiungi criteri di filtraggio " class = " ctrlbut " onclick = " manfil(); " ></ td ></ tr >
2020-01-05 05:46:29 +01:00
</ table >
2020-01-08 14:52:20 +01:00
< table id = " planciaord " class = " planciatab " >
2020-01-13 17:16:33 +01:00
< tr >< td colspan = " 4 " >< input type = " button " id = " ordbut " value = " Aggiungi criteri di ordinamento " class = " ctrlbut " onclick = " manord(); " ></ td ></ tr >
2020-01-08 14:52:20 +01:00
</ table >
< table id = " planciaothers " class = " planciatab " >
< tr >< td >< input type = " button " id = " subbut " value = " Applica " class = " ctrlbut " onclick = " ckf(); " ></ td ></ tr >
</ table >
2020-03-11 17:25:06 +01:00
< table class = " planciatab " >< tr >< td style = " width:1% " > Preset : </ td >< td style = " width:95% " >< select name = " presets " id = " presets " class = " presets " >< ? php echo ( $presopts ); ?> </select></td><td style="width:1%"><img src="imgs/fresu.svg" class="lilbut" onclick="loadpres();" title="Carica i criteri dal preset selezionato"></td><td style="width:1%"><img src="imgs/fregiu.svg" class="lilbut" onclick="pupsavepres(false);" title="Salva i criteri impostati nel preset selezionato sovrascrivendolo (permette inoltre di rinominarlo) ..."></td><td style="width:1%"><img src="imgs/fregiuplus.svg" class="lilbut" onclick="pupsavepres(true);" title="Salva i criteri impostati come nuovo preset ..."></td><td style="width:1%"><img src="imgs/minus.svg" class="lilbut" onclick="puprempres();" title="Elimina il preset selezionato"></td></tr></table>
2020-04-04 19:17:10 +02:00
< input type = " hidden " name = " filt " id = " filt " value = " filt " >
2020-01-05 05:46:29 +01:00
</ form >
2020-01-20 21:23:02 +01:00
</ div >
2020-01-05 05:46:29 +01:00
2020-01-09 20:43:28 +01:00
< script language = " JavaScript " >
<!--
< ? php
echo ( $jsaddrows );
echo ( $jssetrows );
2020-01-13 17:16:33 +01:00
echo ( $jsordaddrows );
echo ( $jsordsetrows );
2020-01-09 20:43:28 +01:00
?>
//-->
</ script >
< div id = " fullscreen " >
< div id = " middlerow " >
2020-01-05 05:46:29 +01:00
< ? php echo ( $out ); ?>
</ div >
</ div >
2019-12-26 21:57:36 +01:00
</ body >
</ html >