Ticket #4261: recorded.php

File recorded.php, 18.1 KB (added by elkin@…, 16 years ago)

edited file

Line 
1<?php
2/**
3 * Show recorded programs.
4 *
5 * @url         $URL: http://svn.mythtv.org/svn/trunk/mythplugins/mythweb/modules/tv/tmpl/default/recorded.php $
6 * @date        $Date: 2007-09-11 18:52:27 +0200 (Tue, 11 Sep 2007) $
7 * @version     $Revision: 14483 $
8 * @author      $Author: skamithi $
9 * @license     GPL
10 *
11 * @package     MythWeb
12 * @subpackage  TV
13 *
14/**/
15
16// Set the desired page title
17    $page_title = 'MythWeb - '.t('Recorded Programs');
18
19// Custom headers
20    $headers[] = '<link rel="stylesheet" type="text/css" href="'.skin_url.'/tv_recorded.css" />';
21
22// Print the page header
23    require 'modules/_shared/tmpl/'.tmpl.'/header.php';
24
25// Global variables used here
26    global $All_Shows, $Total_Programs, $Total_Time, $Total_Used,
27           $Groups,    $Program_Titles;
28
29// Show the recgroup?
30    if (count($Groups) > 1) {
31        $recgroup_cols = 1;
32    }
33    else {
34        $recgroup_cols = 0;
35    }
36
37// Setup for grouping by various sort orders
38    $group_field = $_SESSION['recorded_sortby'][0]['field'];
39    if ($group_field == "") {
40        $group_field = "airdate";
41    } elseif ( ! (($group_field == "title") || ($group_field == "channum") || ($group_field == "airdate") || ($group_field == "recgroup")) ) {
42        $group_field = "";
43    }
44
45?>
46
47<script language="JavaScript" type="text/javascript">
48<!--
49
50// Some initial values for global counters
51    var diskused       = parseInt('<?php echo addslashes(disk_used) ?>');
52    var programcount   = parseInt('<?php echo addslashes($Total_Programs) ?>');
53    var programs_shown = parseInt('<?php echo count($All_Shows) ?>');
54    var totaltime      = parseInt('<?php echo addslashes($Total_Time) ?>');
55
56// Initialize some variables that will get set after the page table is printed
57    var rowcount     = new Array();
58    var rowsection   = new Array();
59    var titles       = new Object;
60    var groups       = new Object;
61
62// Load the known shows
63    var file  = null;
64    var files = new Array();
65
66<?php
67    foreach ($All_Shows as $show) {
68?>
69    file = new Object();
70    file.title      = '<?php echo addslashes($show->title)                  ?>';
71    file.subtitle   = '<?php echo addslashes($show->subtitle)               ?>';
72    file.chanid     = '<?php echo addslashes($show->chanid)                 ?>';
73    file.starttime  = '<?php echo addslashes($show->recstartts)             ?>';
74    file.recgroup   = '<?php echo addslashes(str_replace('%2F', '/', rawurlencode($show->recgroup)))    ?>';
75    file.filename   = '<?php echo addslashes(str_replace('%2F', '/', rawurlencode($show->filename)))    ?>';
76    file.size       = '<?php echo addslashes($show->filesize)               ?>';
77    file.length     = '<?php echo addslashes($show->recendts - $show->recstartts) ?>';
78    file.autoexpire = <?php echo $show->auto_expire ? 1 : 0                 ?>;
79    files.push(file);
80
81<?php
82    }
83?>
84
85// Set the autoexpire flag
86    function set_autoexpire(id) {
87        var file = files[id];
88        var r = new Ajax.Request('<?php echo root ?>tv/detail/' + file.chanid + '/' + file.starttime,
89                                 {
90                                    parameters: 'toggle_autoexpire='+(1 - file.autoexpire),
91                                  asynchronous: false
92                                 });
93        if (r.transport.responseText == 'success') {
94        // Update to the new value
95            file.autoexpire = 1 - file.autoexpire;
96        // Fix the images
97            $('autoexpire_'+id).src = '<?php echo skin_url, '/img/flags/' ?>'
98                                      + (file.autoexpire
99                                         ? ''
100                                         : 'no_')
101                                      + 'autoexpire.png';
102            if (file.autoexpire)
103                $('autoexpire_'+id).title = '<?php echo addslashes(t('Click to disable Auto Expire')) ?>';
104            else
105                $('autoexpire_'+id).title = '<?php echo addslashes(t('Click to enable Auto Expire')) ?>';
106        }
107        else if (r.transport.responseText) {
108            alert('Error: '+r.transport.responseText);
109        }
110    }
111
112    function confirm_delete(id, forget_old) {
113        var file = files[id];
114        if (confirm("<?php echo t('Are you sure you want to delete the following show?')
115                    ?>\n\n     "+file.title+": "+file.subtitle)) {
116            var url = '<?php echo root ?>tv/recorded?delete=yes&chanid='+file.chanid
117                      +'&starttime='+file.starttime
118                      +(forget_old
119                        ? '&forget_old=yes'
120                        : '');
121        // Do the actual deletion
122            if (programs_shown == 1)
123                location.href = url;
124            else {
125                ajax_add_request();
126                submit_url(url+'&ajax=yes', http_success, http_failure, id, file);
127            }
128        // Debug statements - uncomment to verify that the right file is being deleted
129            //alert('row number ' + id + ' belonged to section ' + section + ' which now has ' + rowcount[section] + ' elements');
130            //alert('just deleted an episode of "' + title + '" which now has ' + episode_count + ' episodes left');
131        }
132    }
133
134    function http_success(result, args) {
135        var id   = args.shift();
136        var file = args.shift();
137    // Hide the row from view
138        toggle_vis('inforow_' + id,   'display');
139        toggle_vis('statusrow_' + id, 'display');
140    // decrement the number of rows in a section
141        var section   = rowsection[id];
142        rowcount[section]--;
143    // Decrement the number of episodes for this title
144        titles[file.title]--;
145        var episode_count = titles[file.title]
146    // If we just hid the only row in a section, then hide the section break above it as well
147        if (rowcount[section] == 0) {
148            toggle_vis('breakrow_' + section, 'display');
149        }
150// UGLY! but works well enough...
151    <?php if (count($Groups) > 1) { ?>
152    // Change the recording groups dropdown on the fly.
153        if (file.recgroup) {
154        // Decrement the number of episodes for this group
155            groups[file.recgroup]--;
156            var group_count = groups[file.recgroup]
157        // Change the groups dropdown menu on the fly
158            if (group_count == 0) {
159                toggle_vis('Group ' + file.recgroup, 'display');
160            }
161            else {
162                var group_text;
163                group_text = (group_count > 1) ? ' (' + group_count + ' episodes)' : '';
164                $('Group ' + file.recgroup).innerHTML = file.recgroup + group_text;
165            }
166        }
167    <?php } ?>
168    // Change the recordings dropdown menu on the fly
169        if (episode_count == 0) {
170            toggle_vis('Title ' + file.title, 'display');
171        }
172        else {
173            var count_text;
174            count_text = (episode_count > 1) ? ' (' + episode_count + ' episodes)' : '';
175            $('Title ' + file.title).innerHTML = file.title + count_text;
176        }
177    // Decrement the total number of shows and update the page
178        programs_shown--;
179        programcount--;
180        $('programcount').innerHTML = programcount;
181    // Decrease the total amount of time by the amount of the show
182        totaltime -= file.length;
183        $('totaltime').innerHTML = nice_length(totaltime, <?php
184                                                         echo "'", addslashes(t('$1 hr')),   "', ",
185                                                              "'", addslashes(t('$1 hrs')),  "', ",
186                                                              "'", addslashes(t('$1 min')),  "', ",
187                                                              "'", addslashes(t('$1 mins')), "'";
188                                                         ?>);
189    // Decrease the disk usage indicator by the amount of the show
190        diskused -= file.size;
191        $('diskused').innerHTML = nice_filesize(diskused);
192    // Adjust the freespace shown
193        $('diskfree').innerHTML = nice_filesize(<?php echo disk_size ?> - diskused);
194        // Eventually, we should perform the removal-from-the-list here instead
195        // of in confirm_delete()
196        ajax_remove_request();
197    }
198
199    function http_failure(err, errstr, args) {
200        var file = args[0];
201        alert("Can't delete "+file.title+': '+file.subtitle+".\nHTTP Error:  " + errstr + ' (' + err + ')');
202        ajax_remove_request();
203    }
204
205// -->
206</script>
207
208<form id="change_title" action="<?php echo root ?>tv/recorded" method="get">
209<table id="title_choices" class="commandbox commands" border="0" cellspacing="0" cellpadding="4" align="center">
210<tr>
211<?php if (count($Groups) > 1) { ?>
212    <td class="-group"><?php echo t('Show group') ?>:</td>
213    <td><select name="recgroup" onchange="$('change_title').submit()">
214        <option value=""><?php echo t('All groups') ?></option><?php
215        foreach($Groups as $recgroup => $count) {
216            echo '<option id="Group '.htmlspecialchars($recgroup).'" value="'.htmlspecialchars($recgroup).'"';
217            if ($_GET['recgroup'] == $recgroup)
218                echo ' SELECTED';
219            echo '>'.html_entities($recgroup)
220                .' ('.tn('$1 recording', '$1 recordings', $count)
221                .')</option>';
222        }
223        ?>
224    </select></td>
225<?php
226    }
227?>
228    <td class="-recordings"><?php echo t('Show recordings') ?>:</td>
229    <td><select name="title" onchange="$('change_title').submit()">
230        <option id="All recordings" value=""><?php echo t('All recordings') ?></option>
231<?php
232        foreach($Program_Titles as $title => $count) {
233            echo '<option id="Title '.htmlspecialchars($title).'" value="'.htmlspecialchars($title).'"';
234            if ($_GET['title'] == $title)
235                echo ' SELECTED';
236            echo '>'.html_entities($title)
237                .($count > 1 ? ' ('.tn('$1 episode', '$1 episodes', $count).')' : "")
238                ."</option>\n";
239        }
240?>
241    </select></td>
242</tr>
243</table>
244</form>
245
246<table id="recorded_list" border="0" cellpadding="0" cellspacing="0" class="list small">
247<tr class="menu">
248    <td class="list"<?php if ($group_field) echo ' colspan="2"' ?>>&nbsp;</td>
249    <th class="-title"><?php     echo get_sort_link('title',     t('Title'))      ?></th>
250    <th class="-subtitle"><?php  echo get_sort_link('subtitle',  t('Subtitle'))   ?></th>
251    <th class="-programid"><?php echo get_sort_link('programid', t('Program ID')) ?></th>
252    <th class="-airdate"><?php   echo get_sort_link('airdate',   t('Airdate'))    ?></th>
253    <th class="-channum"><?php   echo get_sort_link('channum',   t('Channel'))    ?></th>
254<?php
255    if ($recgroup_cols)
256        echo '    <th class="-recgroup">', get_sort_link('recgroup', t('Recording Group')), "</td>\n";
257?>
258    <th class="-length"><?php        echo get_sort_link('length',    t('Length')) ?></td>
259    <th class="-filesize"><?php echo get_sort_link('file_size', t('File Size')) ?></td>
260</tr><?php
261    $row     = 0;
262    $section = -1;
263
264    $prev_group = '';
265    $cur_group  = '';
266
267    foreach ($All_Shows as $show) {
268
269    // Print a dividing row if grouping changes
270        switch ($group_field) {
271            case 'airdate':
272                $cur_group = strftime($_SESSION['date_listing_jump'], $show->starttime);
273                break;
274            case 'recgroup':
275                $cur_group = $show->recgroup;
276                break;
277            case 'channum':
278                $cur_group = $show->channel->channum.' - '.$show->channel->name;
279                break;
280            case 'title':
281                $cur_group = $show->title;
282                break;
283        }
284
285        if ( $cur_group != $prev_group && $group_field != '' ) {
286            $section++;
287            $colspan = 10 + $recgroup_cols;
288            print <<<EOM
289<tr id="breakrow_$section" class="list_separator">
290    <td colspan="$colspan" class="list_separator">$cur_group</td>
291</tr>
292EOM;
293        }
294
295        echo "<tr id=\"inforow_$row\" class=\"recorded\">\n";
296        if ($group_field != "")
297            echo "    <td class=\"list\" rowspan=\"2\">&nbsp;</td>\n";
298?>
299    <td rowspan="2" class="-pixmap<?php
300        if ($_SESSION['recorded_pixmaps']) { ?>">
301        <a class="-pixmap" href="<?php echo root ?>tv/detail/<?php echo $show->chanid, '/', $show->recstartts ?>" title="<?php echo t('Recording Details') ?>"
302            ><img src="<?php echo $show->thumb_url(100,0) ?>"></a>
303<?php   }
304        else {
305            echo ' -noimg">';
306        }
307?>
308        <a class="-download"
309            href="<?php echo video_url($show, true) ?>" title="<?php echo t('ASX Stream') ?>"
310            ><img src="<?php echo skin_url ?>/img/play_sm.png"></a>
311        <a class="-download"
312            href="<?php echo $show->url ?>" title="<?php echo t('Direct Download') ?>"
313            ><img src="<?php echo skin_url ?>/img/video_sm.png"></a>
314
315
316       <p>
317        <?php
318        //Status icons like Stereo or Cutlist etc
319        // Auto expire is interactive
320            echo '<a onclick="set_autoexpire(', $row, ')" class="_autoexpire">',
321                 '<img id="autoexpire_', $row, '" src="', skin_url, '/img/flags/';
322            if ($show->auto_expire)
323                echo 'autoexpire.png" title="', t('Click to disable Auto Expire'), '"';
324            else
325                echo 'no_autoexpire.png" title="', t('Click to enable Auto Expire'), '"';
326            echo '></a>';
327        // The rest of the flags are just for display
328            if ($show->closecaptioned)
329                echo '<img src="'.skin_url.'/img/flags/cc.png" title="'.t('Closed Captioning').'">';
330            if ($show->stereo)
331                echo '<img src="'.skin_url.'/img/flags/stereo.png" title="'.t('Stereo').'">';
332            if ($show->hdtv)
333                echo '<img src="'.skin_url.'/img/flags/hd.png" title="'.t('HD').'">';
334            if ($show->has_commflag)
335                echo '<img src="'.skin_url.'/img/flags/commflagged.png" title="'.t('Commercials Flagged').'">';
336            if ($show->has_cutlist)
337                echo '<img src="'.skin_url.'/img/flags/cutlist.png" title="'.t('Has Cutlist').'">';
338            if ($show->bookmark)
339                echo '<img src="'.skin_url.'/img/flags/bookmark.png" title="'.t('has Bookmark').'">';
340            if ($show->is_watched)
341                echo '<img src="'.skin_url.'/img/flags/watched.png" title="'.t('Watched').'">';
342        ?>
343       </p>
344
345        </td>
346    <td class="-title"><?php echo '<a href="', root, 'tv/detail/', $show->chanid, '/', $show->recstartts, '"'
347                    .($_SESSION['recorded_pixmaps'] ? '' : " name=\"$row\"")
348                    .' title="', t('Recording Details'), '"'
349                    .'>'.$show->title.'</a>' ?></td>
350    <td class="-subtitle"><?php echo '<a href="', root, 'tv/detail/', $show->chanid, '/', $show->recstartts, '"'
351                    .' title="', t('Recording Details'), '"'
352                    .'>'.$show->subtitle.'</a>' ?></td>
353    <td class="-programid"><?php echo $show->programid ?></td>
354    <td class="-airdate"><?php echo strftime($_SESSION['date_recorded'], $show->starttime) ?></td>
355    <td class="-channum"><?php echo $show->channel->channum, ' - ', $show->channel->name ?></td>
356<?php
357    if ($recgroup_cols)
358        echo "    <td class=\"-recgroup\">$show->recgroup</td>\n";
359?>
360    <td class="-length"><?php echo nice_length($show->length) ?></td>
361    <td class="-filesize"><?php echo nice_filesize($show->filesize) ?></td>
362    <td class="-commands commands" rowspan="2"><?php
363        if ($show->is_recording) {
364            echo '<a href="', root, 'tv/detail/', $show->chanid, '/', $show->recstartts, '">',
365                 t('Still Recording: Edit'),
366                 "</a>\n        ";
367        }
368        if ($show->can_delete) {
369        ?><a onclick="javascript:confirm_delete(<?php echo $row ?>, false)"
370            title="<?php echo html_entities(t('Delete $1', preg_replace('/: $/', '', $show->title.': '.$show->subtitle))) ?>"
371            ><?php if (get_backend_setting('AutoExpireInsteadOfDelete') > 0 &&
372                       $show->recgroup == 'Deleted')
373                        echo t('Delete Forever');
374                    else
375                        echo t('Delete');
376              ?></a>
377        <a onclick="javascript:confirm_delete(<?php echo $row ?>, true)"
378            title="<?php echo html_entities(t('Delete and allow rerecord: $1', preg_replace('/: $/', '', $show->title.': '.$show->subtitle))) ?>"
379            ><?php echo t('Delete + Rerecord') ?></a>
380
381<?php       if ($show->recgroup == 'Deleted') {
382                echo '<a href="', root, 'tv/recorded?undelete=yes&chanid=', $show->chanid,
383                    '&starttime=', $show->starttime, '" ' ?>
384                title="<?php echo html_entities(t('Undelete: $1', preg_replace('/: $/', '', $show->title.': '.$show->subtitle))) ?>"
385                <?php echo '>' , t('Undelete') ?></a>
386<?php       } ?>
387<?php   } ?>
388        </td>
389</tr><tr id="statusrow_<?php echo $row ?>" class="recorded">
390    <td colspan="<?php echo 7 + $recgroup_cols ?>" valign="top"><?php echo $show->description ?></td>
391</tr><?php
392        $prev_group = $cur_group;
393    // Keep track of how many shows are visible in each section
394        $row_count[$section]++;
395    // Keep track of which shows are in which section
396        $row_section[$row] = $section;
397    // Increment row last
398        $row++;
399    }
400?>
401
402</table>
403
404<script language="JavaScript" type="text/javascript">
405<?php
406    foreach ($row_count as $count) {
407        echo 'rowcount.push(['.escape($count)."]);\n";
408    }
409    foreach ($row_section as $section) {
410        echo 'rowsection.push(['.escape($section)."]);\n";
411    }
412    foreach($Program_Titles as $title => $count) {
413        echo 'titles['.escape($title).'] = '.escape($count).";\n";
414    }
415    foreach($Groups as $recgroup => $count) {
416        echo 'groups['.escape($recgroup).'] = '.escape($count).";\n";
417    }
418?>
419</script>
420
421<?php
422    echo '<p align="right" style="padding-right: 75px">'
423        .t('$1 programs, using $2 ($3) out of $4 ($5 free).',
424           '<span id="programcount">'.t($Total_Programs).'</span>',
425           '<span id="diskused">'.nice_filesize($Total_Used).'</span>',
426           '<span id="totaltime">'.nice_length($Total_Time).'</span>',
427           '<span id="disksize">'.nice_filesize(disk_size).'</span>',
428           '<span id="diskfree">'.nice_filesize(disk_size - disk_used).'</span>'
429          )
430        .'</p>';
431
432// Print the page footer
433    require 'modules/_shared/tmpl/'.tmpl.'/footer.php';
434
435