<?php

require 'header.php';

if ( RESTRICTQUEUES && (substr($_SERVER['REMOTE_ADDR'], 0, strlen(LOCALNETWORK)) != LOCALNETWORK) ) {
   exit();
}

$query = "SELECT id, songid FROM " . INSTANTQTABLE . " ORDER BY id LIMIT 1";
$sth = $globaldbh->prepare($query);
$sth->execute();

if ( false !== ($row = $sth->fetch()) ) {
   killPlayingSong();
   exit();
}

$query = "DELETE FROM " . QUEUECONTENTSTABLE . " ";
$query .= "WHERE qid=(SELECT id FROM " . QUEUESTABLE . " WHERE active='true' AND type='user') ";
$query .= "AND songid=(SELECT songid FROM " . RECENTSTABLE . " ORDER BY timeplayed DESC LIMIT 1)";
$sth = $globaldbh->prepare($query);
$sth->execute();

killPlayingSong();
exit();

?>
