2017-01-23 23:13:16 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( canEdit( 'Monitors' ) ) {
|
|
|
|
switch ( $_REQUEST['action'] ) {
|
|
|
|
case 'sort' :
|
|
|
|
{
|
|
|
|
$monitor_ids = $_POST['monitor_ids'];
|
2017-01-24 10:51:38 +08:00
|
|
|
# Two concurrent sorts could generate odd sortings... so lock the table.
|
|
|
|
dbQuery( 'LOCK TABLES Monitors WRITE' );
|
2017-01-23 23:13:16 +08:00
|
|
|
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;
|
|
|
|
}
|
2017-01-24 10:51:38 +08:00
|
|
|
dbQuery( 'UPDATE Monitors SET Sequence=? WHERE Id=?', array( $i, $monitor_id ) );
|
2017-01-23 23:13:16 +08:00
|
|
|
} // end for each monitor_id
|
2017-01-24 10:51:38 +08:00
|
|
|
dbQuery('UNLOCK TABLES');
|
|
|
|
return;
|
|
|
|
} // end case sort
|
2017-01-23 23:13:16 +08:00
|
|
|
default:
|
|
|
|
{
|
2017-01-24 10:51:38 +08:00
|
|
|
Warning("unknown action " . $_REQUEST['action'] );
|
2017-01-23 23:13:16 +08:00
|
|
|
} // end ddcase default
|
|
|
|
}
|
|
|
|
} else {
|
2017-01-24 10:51:38 +08:00
|
|
|
Warning("Cannot edit monitors" );
|
2017-01-23 23:13:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ajaxError( 'Unrecognised action or insufficient permissions' );
|
|
|
|
|
|
|
|
?>
|