add an ajax file for console to do sorting

This commit is contained in:
Isaac Connor 2017-01-23 10:13:16 -05:00
parent fdd71a826a
commit e937b4099b
1 changed files with 32 additions and 0 deletions

32
web/ajax/console.php Normal file
View File

@ -0,0 +1,32 @@
<?php
if ( canEdit( 'Monitors' ) ) {
switch ( $_REQUEST['action'] ) {
case 'sort' :
{
$monitor_ids = $_POST['monitor_ids'];
for ( $i = 0; $i < count($monitor_ids); $i += 1 ) {
$monitor_id = $monitor_ids[$i];
$monitor_id = preg_replace( '/^monitor_id-/', '', $monitor_id );
if ( ( ! $monitor_id ) or ! ( is_integer( $monitor_id ) or ctype_digit( $monitor_id ) ) ) {
Warning( "Got $monitor_id from " . $monitor_ids[$i] );
continue;
}
Error("Updating monitor ".$monitor_ids[$i] . " to position $i" );
dbQuery( 'update Monitors set Sequence=? where Id=?', array( $i, $monitor_ids[$i] ) );
} // end for each monitor_id
break;
Warning("unknown action");
} // end ddcase sort
default:
{
Warning("unknown action " . $_REQUEST['action'] );
} // end ddcase default
}
} else {
Warning("Cannot edit monitors" );
}
ajaxError( 'Unrecognised action or insufficient permissions' );
?>