Made delete happen immediately without leaving the current page.
[recordtv.git] / playonwii / index.php
blob4d921b5723b063c064fa18f8a98439c30a813f97
1 <?php
3 include_once( "functions.php" );
5 function pretty_date( $date )
7 global $num_to_month;
9 $tm = mktime(
10 (int)( substr( $date, 11, 2 ) ),
11 (int)( substr( $date, 14, 2 ) ),
13 (int)( substr( $date, 5, 2 ) ),
14 (int)( substr( $date, 8, 2 ) ),
15 (int)( substr( $date, 0, 4 ) ) );
17 return date( "D d M, H:i", $tm );
20 function get_info_from_file( $fn )
22 $title = "";
23 $sub_title = "";
24 $description = "";
25 $date = "";
26 $channel = "";
28 $handle = fopen( $fn, "r" );
30 if( $handle )
32 while ( !feof( $handle ) )
34 $line = fgets( $handle );
35 $line = substr( $line, 0, -1 );
37 list( $k, $v ) = split( "=", $line, 2 );
39 switch( $k )
41 case "title":
43 $title = $v;
44 break;
46 case "sub_title":
48 $sub_title = $v;
49 break;
51 case "description":
53 $description = $v;
54 break;
56 case "startTime":
58 $date = $v;
59 break;
61 case "channel_pretty":
63 $channel = $v;
64 break;
69 fclose( $handle );
72 return array( $title, $date, $channel, $sub_title, $description );
75 function get_info_from_filename( $fn )
77 if( preg_match( '/^(.*?)-(.*)\\..*$/', $fn, $matches ) )
79 $title = $matches[1];
80 $date = $matches[2];
82 else
84 $title = substr( $fn, 0, strlen( $fn ) - 4 );
85 $date = "";
88 return array( $title, $date );
91 function get_info( $filename, $filenames )
93 global $videos_dir;
95 $title = Null;
97 if( preg_match( '/^(.*)\\.flv$/', $filename, $matches ) )
100 $infofn = $matches[1] . ".rtvinfo";
102 if( array_key_exists( $infofn, $filenames ) )
104 list( $title, $date, $channel, $sub_title, $description ) =
105 get_info_from_file( $videos_dir . "/" . $infofn );
107 else
109 list( $title, $date ) = get_info_from_filename( $filename );
110 $channel = "";
111 $sub_title = "";
112 $description = "";
114 $titles[$title][] = array( $num, $date, $channel, $sub_title,
115 $description );
116 $num++;
119 return array( $title, $date, $channel, $sub_title, $description );
122 // This is a hash filename -> nothing of all files in the videos directory
123 $filenames = array();
124 $handle = opendir( $videos_dir );
125 if( $handle )
127 while( ( $filename = readdir( $handle ) ) )
129 $filenames[$filename] = '';
132 closedir($handle);
135 // This is a hash filename -> nothing of all files in the deleted directory
136 $deleted_filenames = array();
137 $handle = opendir( $deleted_dir );
138 if( $handle )
140 while( ( $filename = readdir( $handle ) ) )
142 $deleted_filenames[$filename] = '';
145 closedir($handle);
148 // This is a hash title->array( array( filenumber, date, filename, channel ) )
149 $titles = array();
150 $num = 0;
152 $nondeleted_filenames = array_diff_key( $filenames, $deleted_filenames );
154 $sorted_fns = array_keys( $nondeleted_filenames );
155 rsort( $sorted_fns );
157 foreach( $sorted_fns as $filename )
159 list( $title, $date, $channel, $sub_title, $description ) = get_info(
160 $filename, $nondeleted_filenames );
162 if( $title != Null )
164 $titles[$title][] = array( $num, $date, $channel, $sub_title,
165 $description, $filename );
166 $num++;
172 <html>
174 <head>
175 <title>Recorded programmes</title>
176 <style type="text/css">
177 body {
178 font-family: verdana, sans-serif;
179 text-align: center;
182 text-decoration: none;
183 color: black;
185 a:hover {
186 color: red;
188 a.deletelink {
189 color:red;
190 font-size: xx-small;
192 a.title {
193 color: blue;
195 span.smalltime {
196 font-size: smaller;
197 color: gray;
199 span.smalltime:hover {
200 color: red;
202 h2 {
203 font-size: x-large;
204 font-weight: normal;
205 color: blue;
206 margin: 2px;
208 td.dates {
209 font-size: small;
211 </style>
212 <script language="JavaScript">
214 function makeRequest( url, arg )
216 var httpRequest;
218 if( window.XMLHttpRequest ) // Mozilla, Safari etc.
220 httpRequest = new XMLHttpRequest();
222 else if( window.ActiveXObject ) // IE
226 httpRequest = new ActiveXObject( "Msxml2.XMLHTTP" );
228 catch( e )
232 httpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
234 catch( e )
240 if( !httpRequest )
242 return false;
245 httpRequest.onreadystatechange = function()
247 receiveAnswer( httpRequest, arg );
250 httpRequest.open('GET', url, true);
251 httpRequest.send('');
254 function receiveAnswer( httpRequest, prog_filename )
256 if( httpRequest.readyState == 4 )
258 if( httpRequest.status != 200 )
260 document.location = "delete_error.php?filename=" + prog_filename
266 function mouse_over( tr_id )
268 tr_el = document.getElementById( tr_id );
269 tr_el.style.backgroundColor = '#ffaaaa';
272 function mouse_out( tr_id )
274 tr_el = document.getElementById( tr_id );
275 tr_el.style.backgroundColor = 'transparent';
278 function title_click( table_id )
280 table_el = document.getElementById( table_id );
281 if( table_el.style.display == 'inline' )
283 table_el.style.display = 'none';
285 else
287 table_el.style.display = 'inline';
292 function delete_prog( prog_filename )
294 makeRequest( 'delete.php?filename=' + prog_filename, prog_filename );
295 tr_el = document.getElementById( 'tr_' + prog_filename );
296 tr_el.style.display = 'none';
299 </script>
300 </head>
302 <body>
303 <h1>Recorded programmes</h1>
305 <center>
306 <?php
307 ksort( $titles );
308 $table_counter = 0;
309 foreach( $titles as $title => $arr )
311 list( $num, $date, $channel, $sub_title ) = $arr[0];
312 print "<h2><a class='title' href='javascript: title_click( \"table_$table_counter\" )'>$title</a></h2>\n";
314 print "<table id='table_$table_counter' style='display: none' width='90%' cellpadding='0' cellspacing='0' border='0'>";
315 foreach( $arr as $lst )
317 list( $num, $date, $channel, $sub_title, $description,
318 $filename ) = $lst;
319 print "<tr id='tr_$filename'><td><a href='play.php?filename=$filename' style='padding-right: 10px'";
321 print " title='$description'";
323 print ">";
325 if( $sub_title )
327 print $sub_title . " <span class='smalltime'>(";
330 print pretty_date( $date );
332 if( $channel )
334 print " on $channel";
337 if( $sub_title )
339 print ")</span>";
342 print "</a></td>";
343 print "<td><a class='deletelink' onmouseover='mouse_over(\"tr_$filename\")' onmouseout='mouse_out(\"tr_$filename\")' href='javascript: delete_prog( \"$filename\" )'>[DELETE]</a></td></tr>\n";
345 print "</table>\n";
346 $table_counter += 1;
348 print "</table>\n";
350 </center>
352 </body>
354 </html>