HomeAudio/ajax/ajax_listsongs.php

68 lines
2.6 KiB
PHP

<?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['currentsong'] = array("art"=>"", "title"=>"", "artist"=>"", "album"=>"", "year"=>"");
$data['songhistory'] = array();
$data['songlist'] = "";
if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$song = new Song($row['songid']);
$data['currentsong']["arturl"] = $song->getArtFile(ARTURL);
$data['currentsong']["title"] = $song->getTitle(HTMLSAFE);
$data['currentsong']["artist"] = $song->getArtist(HTMLSAFE);
$data['currentsong']["album"] = $song->getAlbum(HTMLSAFE);
$data['currentsong']["year"] = $song->getYear(HTMLSAFE);
}
while ( $row = $sth->fetch() ) {
$song = new Song($row['songid']);
$curdata = array();
$curdata["arturl"] = $song->getArtFile(ARTURL);
$curdata["title"] = $song->getTitle(HTMLSAFE);
$curdata["artist"] = $song->getArtist(HTMLSAFE);
$curdata["album"] = $song->getAlbum(HTMLSAFE);
$curdata["year"] = $song->getYear(HTMLSAFE);
$data['songhistory'][] = $curdata;
$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";
}
header('Content-Type: application/json');
echo json_encode($data);
exit();
// vim: set ts=3 sw=3 ai: