Add a dequeue image.
[adorno.git] / inc / menu.php
blob6a19c32d17bd1cb606b8f1d18302f8ee1ed4f73c
1 <?php
2 require_once("LinkClass.php");
3 require_once("DataEntry.php");
5 $url = '<a href="#" onclick="act(\'%s\');"><img src="/img/%s" title="%s" /></a>'."\n";
6 $controls = "";
8 $controls .= sprintf( $url, 'pause', 'pause.png', 'Pause the playback');
9 $controls .= sprintf( $url, 'resume','resume.png','Resume the paused playback');
10 $controls .= sprintf( $url, 'next', 'next.png', 'Skip ahead to the next track');
11 $controls .= sprintf( $url, 'stop', 'stop.png', 'Stop playing tracks');
12 $controls .= sprintf( $url, 'clear', 'clear.png', 'Clear the currently queued tracks');
13 $controls .= sprintf( $url, 'off', 'off.png', 'Shut music server down and turn off');
15 $url = "";
16 if ( "$lltr" <> "" ) $url .= "&lltr=" . rawurlencode($lltr);
17 elseif ( "$altr" <> "" ) $url .= "&altr=" . rawurlencode($altr);
18 if ( "$a" <> "" ) $url .= "&a=" . rawurlencode($a);
19 elseif ( "$l" <> "" ) $url .= "&l=" . rawurlencode($l);
21 if ( !isset($ltrtype) ) {
22 $ltrtype = 'artist';
23 if ( preg_match( '/album.php/', $_SERVER['REQUEST_URI']) ) $ltrtype = 'album';
26 $url = $_SERVER['PHP_SELF'] . preg_replace( '/^&/', '?', $url . '&' );
27 if ( !preg_match( '{/(artist|album)\.php}', $url) ) {
28 error_log( "$sysabbr: DBG: >>$url<< " . (preg_match('{/(artist|album)\.php}', $url)? 'true':'false') );
29 // $url = preg_replace( '{/[a-z0-9_-]+\.php}i', '/artist.php', $url );
30 $url .= sprintf('type=%s&', $ltrtype);
32 $ls = new LinkSet( '<a href="'.str_replace('%','%%',$url).'altr=%s"%s%s>%s</a>', 'alphabetica' );
33 error_log( "$sysabbr: DBG: >>$ls->template<<" );
35 $menubar = '<table width="100%" border="0"><tr class="tr_menu"><td class="h3"><span id="current_type" onclick="toggle_type();">'.ucfirst($ltrtype).'</span>s:</td><td id="alphabet">';
36 $qry = new AwlQuery("SELECT letter, pattern, $ltrtype"."_count AS count FROM letter_groups ORDER BY 1;");
37 if ( $qry->Exec("artist") && $qry->rows() > 0 ) {
38 while ( $letter = $qry->Fetch() ) {
39 $help = "Display $letter->count $ltrtype"."s beginning with the letter '$letter->letter'.";
40 $display = $letter->letter;
41 if ( trim($letter->letter) == "#" ) {
42 $help = 'List all '."$letter->count $ltrtype".'s not beginning with an alphabetic character.';
44 $menubar .= $ls->Link( urlencode($letter->pattern), $display, $help );
47 $menubar .= '</td>';
48 // $menubar .= '<td class="h3">Search:</td>';
49 $sf = new EntryForm( $refresh_url, $GLOBALS, true );
50 $sf->SimpleForm();
51 $menubar .= $sf->StartForm(array('method' => 'get'));
52 if ( isset($lltr) ) $menubar .= $sf->HiddenField( 'lltr', $lltr );
53 if ( isset($altr) ) $menubar .= $sf->HiddenField( 'altr', $altr );
54 if ( isset($a) ) $menubar .= $sf->HiddenField( 'a', $a );
55 else if ( isset($l) ) $menubar .= $sf->HiddenField( 'l', $l );
56 $f = new EntryField( 'text', 'search',
57 array( 'title' => 'Enter a regular expression to search for artists / albums that match that',
58 'size' => '15', 'class' => 'search_field'),
59 "$search" );
60 $menubar .= '<td align="right">'.$f->Render().'</td>';
61 $menubar .= '<td>'.$sf->SubmitButton("submit","Search").'</td>';
62 $menubar .= $sf->EndForm();
64 $ls = new LinkSet("", "alphabetica");
65 $menubar .= '<td align="right">';
66 $menubar .= $ls->Link("/", "Home");
67 $menubar .= $ls->Link("/artist.php", "Artist");
68 $menubar .= $ls->Link("/album.php", "Album");
69 // $menubar .= $ls->Link("/genre.php", "Genre");
70 // $menubar .= $ls->Link("/stream.php", "Streams");
71 $menubar .= '</td>';
73 $menubar .= '</tr></table>';
75 // $menubar .= '<hr class="thin_hr">';
77 echo <<<EOHTML
78 <body>
79 <script language="javascript"><!--
80 function toggle_type() {
81 var type_span = document.getElementById('current_type');
82 var type = type_span.innerHTML.toLowerCase();
83 var old_type = type;
84 // alert(type);
85 if ( type == 'artist' ) { type = 'album'; }
86 else if ( type == 'album' ) { type = 'stream'; }
87 else if ( type == 'stream' ) { type = 'genre'; }
88 else if ( type == 'genre' ) { type = 'artist'; }
89 // alert(type);
90 type_span.innerHTML = type.substring(0,1).toUpperCase() + type.substring(1);
92 var alphabet = document.getElementById('alphabet').childNodes;
94 var href;
95 var title;
96 var title_match = new RegExp('([0-9]+ )?' + old_type,'g');
98 for (var i = 0; i < alphabet.length; i++)
100 href = alphabet[i].href;
101 alphabet[i].href = href.replace(old_type,type);
102 title = alphabet[i].title;
103 alphabet[i].title = title.replace(title_match,type);
104 // if ( alphabet[i].innerHTML == 'F' ) {
105 // alert(alphabet[i].title);
106 // }
111 var base_url = 'http://aiw/';
112 var status_req = new XMLHttpRequest();
113 var mytime;
114 var redo_queue = true;
115 function update_now_playing() {
116 var td = document.getElementById('now_playing');
117 status_req.open('GET', base_url + 'current.php', true);
118 status_req.onreadystatechange = function (aEvt) {
119 if ( status_req.readyState == 4 ) {
120 if ( status_req.status == 200 ) {
121 if ( td.innerHTML != status_req.responseText ) {
122 td.innerHTML = status_req.responseText;
123 var in_td = td.childNodes;
124 var title = '';
125 if ( in_td.length == 1 ) {
126 var nodecontent = status_req.responseText;
127 if ( nodecontent.match(/Nothing is currently playing/i) ) {
128 title = 'Adorno: stopped';
130 else if ( nodecontent.match(/paused/i) ) {
131 title = 'Adorno: paused';
133 in_td = in_td[0].childNodes;
135 for ( var i=0; i < in_td.length; i++ ) {
136 if ( in_td[i].innerHTML == undefined ) continue;
137 if ( title == '' )
138 title = in_td[i].innerHTML;
139 else
140 title = title + ' : ' + in_td[i].innerHTML;
142 document.title = title;
143 update_queue();
145 else if ( redo_queue )
146 update_queue();
148 // else
149 // td.innerHTML = "<p>Error loading page</p>";
152 status_req.send(null);
153 mytime=setTimeout('update_now_playing()',10000);
156 function update_queue() {
157 var td = document.getElementById('queue');
158 redo_queue = false;
159 status_req.open('GET', base_url + 'queue.php', true);
160 status_req.onreadystatechange = function (aEvt) {
161 if ( status_req.readyState == 4 ) {
162 if ( status_req.status == 200 ) {
163 td.innerHTML = status_req.responseText;
165 // else
166 // td.innerHTML = "<p>Error loading page</p>";
169 status_req.send(null);
172 var last_action_result = '';
173 function act( action ) {
174 var act_req = new XMLHttpRequest();
175 status_req.open('GET', base_url + 'action.php?action=' + action, true);
176 status_req.onreadystatechange = function (aEvt) {
177 if ( status_req.readyState == 4 ) {
178 if ( status_req.status == 200 ) {
179 last_action_result = 'success';
180 redo_queue = true;
181 update_now_playing();
183 else
184 last_action_result = 'failure';
187 status_req.send(null);
190 function enqueue(artist,album,track) {
191 var act_req = new XMLHttpRequest();
192 var details = '&a=' + artist + '&l=' + album;
193 if ( track != '' ) details = details + '&t=' + track;
194 var url = base_url + 'action.php?action=enqueue' + details
195 // alert(url);
196 status_req.open('GET', url, true);
197 status_req.onreadystatechange = function (aEvt) {
198 if ( status_req.readyState == 4 ) {
199 if ( status_req.status == 200 ) {
200 last_action_result = 'success';
201 redo_queue = true;
202 update_now_playing();
204 else
205 last_action_result = 'failure';
208 status_req.send(null);
210 --></script>
211 <table id="header">
212 <tr>
213 <td id="now_playing">Stopped</td>
214 <td id="controls">
215 $controls </td>
216 </tr>
217 </table>
218 <div id="menu">
219 $menubar
220 </div>
221 <div id="playurl">
222 <form id="urlform" method="POST"><input name="url" class="playurl" type="text"><input class="submit" type="submit" name="act" value="Play URL"></form>
223 </div>
224 <script language="javascript"><!--
225 update_now_playing();
226 --></script>
227 <div id="content">
229 EOHTML;