<?php

require 'header.php';

if ( isset($_REQUEST['debug']) ) {
   $debug = true;
} else {
   $debug = false;
}

$data = array();

if ( $debug ) echo "<pre>";
$query = "SELECT value FROM " . SETTINGSTABLE . " WHERE parameter='CHRISTMAS'";
$sth = $globaldbh->prepare($query);
$sth->execute();
$row = $sth->fetch();
$data['christmas'] = ($row['value'] == 'true') ? true : false;

$query = "SELECT value FROM " . SETTINGSTABLE . " WHERE parameter='CHRISTMASFREQ'";
$sth = $globaldbh->prepare($query);
$sth->execute();
$row = $sth->fetch();
$data['christmasfreq'] = $row['value'];

$query = "SELECT songid FROM " . RECENTSTABLE . " ORDER BY timeplayed DESC limit 15";
$sth = $globaldbh->prepare($query);
$sth->execute();
$data['volume'] = getSystemVolume();
system("HOME=" . WEBUSERHOMEDIR . " && scripts/homeaudio_togglemute.pl -show", $retval);
$data['muted'] = ($retval == 0) ? false : true;
$data['songplaying'] = "";
$data['songlist'] = "";
$firstsong = true;
while ( $row = $sth->fetch() ) {
   $song = new Song($row['songid']);
   if ( $firstsong ) {
      $data['songplaying'] .= "<div class='playing_art'><img class='playing_img' src='{$song->getArtFile(ARTURL)}'></div>\n";
      $data['songplaying'] .= "<div class='playing_details'>\n";
      $data['songplaying'] .= "  <p class='nomargin'><span class='playing_label'>Title:</span> {$song->getTitle(HTMLSAFE)}</p>\n";
      $data['songplaying'] .= "  <p class='nomargin'><span class='playing_label'>Artist:</span> {$song->getArtist(HTMLSAFE)}</p>\n";
      $data['songplaying'] .= "  <p class='nomargin'><span class='playing_label'>Album:</span> {$song->getAlbum(HTMLSAFE)}</p>\n";
      $data['songplaying'] .= "  <p class='nomargin'><span class='playing_label'>Year:</span> {$song->getYear(HTMLSAFE)}</p>\n";
      $data['songplaying'] .= "</div>\n";
      $firstsong = false;
   } else {
      $data['songlist'] .= "<div class='songlist_song_container'>\n";
      $data['songlist'] .= "  <div class='songlist_img_container'><img class='songlist_img' src='{$song->getArtFile(ARTURL)}'></div>\n";
      $data['songlist'] .= "  <div class='songlist_details_container'>\n";
      $data['songlist'] .= "    <p class='nomargin'><span class='playing_label'>Title:</span> {$song->getTitle(HTMLSAFE)}</p>\n";
      $data['songlist'] .= "    <p class='nomargin'><span class='playing_label'>Artist:</span> {$song->getArtist(HTMLSAFE)}</p>\n";
      $data['songlist'] .= "    <p class='nomargin'><span class='playing_label'>Album:</span> {$song->getAlbum(HTMLSAFE)}</p>\n";
      $data['songlist'] .= "  </div>\n";
      $data['songlist'] .= "</div>\n";
      $data['songlist'] .= "<hr class='songlist'>\n";
   }
}
if ( $debug ) {
   var_dump($data);
   echo "</pre>";
} else {
   echo json_encode($data);
}
exit();


?>
