[mythtv] [PATCH] Mythweb Delete Channels
Chris Petersen
lists at forevermore.net
Tue May 25 22:45:55 EDT 2004
> I was surprised to see no way to delete channels from within Mythweb so
> I wrote a patch to work with the current Channels->Settings.
Could you resubmit the "simple" patch against mythweb CVS? You could
try to do the advanced patch again, but with the datadirect stuff, it
may not be feasible.
-Chris
> I have two
> versions of this patch. I have a simple patch that just removes the
> entries from the database. This removes the "important" factors like
> showing in the guide and channel surfing, however, it obviously leaves
> xmltv to still grab channel info from the internet but the data is so
> small I really don't think it matters. Just to see how it would work I
> wrote a more advanced patch to also append "not" to your source.xmltv
> file but this of course requires additional configuration and touches
> more files. Choose which ever feels best.
>
> Eric Hokanson
>
> ______________________________________________________________________
> diff -ur mythweb-0.14-old\settings_channels.php mythweb-0.14\settings_channels.php
> --- mythweb-0.14-old\settings_channels.php Sat Nov 22 02:59:16 2003
> +++ mythweb-0.14\settings_channels.php Mon Apr 26 23:16:54 2004
> @@ -15,22 +15,28 @@
> // Figure out the chanid, or leave
> if (!preg_match('/^channum_(\\d+)$/', $key, $match)) continue;
> list($match, $chanid) = $match;
> - // First, grab values that can be empty
> - $query = 'UPDATE channel SET freqid='.escape($_POST['freqid_'.$chanid]) .','
> - .'finetune='.escape($_POST['finetune_'.$chanid]) .','
> - .'videofilters='.escape($_POST['videofilters_'.$chanid]).','
> - .'brightness='.escape($_POST['brightness_'.$chanid]) .','
> - .'contrast='.escape($_POST['contrast_'.$chanid]) .','
> - .'colour='.escape($_POST['colour_'.$chanid]) .','
> - .'hue='.escape($_POST['hue_'.$chanid]) .','
> - .'recpriority='.escape($_POST['recpriority_'.$chanid]);
> + // First, delete any unwanted channels
> + if ($_POST['delete_'.$chanid] == "true") {
> + $query = 'DELETE FROM channel';
> + }
> + else {
> + // Not deleting so grab values that can be empty
> + $query = 'UPDATE channel SET freqid='.escape($_POST['freqid_'.$chanid]) .','
> + .'finetune='.escape($_POST['finetune_'.$chanid]) .','
> + .'videofilters='.escape($_POST['videofilters_'.$chanid]).','
> + .'brightness='.escape($_POST['brightness_'.$chanid]) .','
> + .'contrast='.escape($_POST['contrast_'.$chanid]) .','
> + .'colour='.escape($_POST['colour_'.$chanid]) .','
> + .'hue='.escape($_POST['hue_'.$chanid]) .','
> + .'recpriority='.escape($_POST['recpriority_'.$chanid]);
> // next, the fields that need to have a value, so we won't change them if they were emptied
> - if ($_POST['channum_'.$chanid])
> - $query .= ',channum='.escape($_POST['channum_'.$chanid]);
> - if ($_POST['callsign_'.$chanid])
> - $query .= ',callsign='.escape($_POST['callsign_'.$chanid]);
> - if ($_POST['name_'.$chanid])
> - $query .= ',name='.escape($_POST['name_'.$chanid]);
> + if ($_POST['channum_'.$chanid])
> + $query .= ',channum='.escape($_POST['channum_'.$chanid]);
> + if ($_POST['callsign_'.$chanid])
> + $query .= ',callsign='.escape($_POST['callsign_'.$chanid]);
> + if ($_POST['name_'.$chanid])
> + $query .= ',name='.escape($_POST['name_'.$chanid]);
> + }
> // Submit the query
> $result = mysql_query($query.' WHERE chanid='.escape($chanid))
> or trigger_error('SQL Error: '.mysql_error(), FATAL);
> diff -ur mythweb-0.14-old\themes\Default\settings_channels.php mythweb-0.14\themes\Default\settings_channels.php
> --- mythweb-0.14-old\themes\Default\settings_channels.php Sat Nov 22 02:59:16 2003
> +++ mythweb-0.14\themes\Default\settings_channels.php Mon Apr 26 12:33:15 2004
> @@ -20,6 +20,7 @@
>
> <table width="100%" border="0" cellpadding="4" cellspacing="2" class="list small">
> <tr class="menu" align="center">
> + <td width="4%">delete</td>
> <td width="4%">sourceid</td>
> <td width="5%">channum</td>
> <td width="12%">callsign</td>
> @@ -27,14 +28,15 @@
> <td width="5%">freqid</td>
> <td width="5%">finetune</td>
> <td width="5%">videofilters</td>
> - <td width="8%">brightness</td>
> - <td width="8%">contrast</td>
> - <td width="8%">colour</td>
> - <td width="8%">hue</td>
> + <td width="7%">brightness</td>
> + <td width="7%">contrast</td>
> + <td width="7%">colour</td>
> + <td width="7%">hue</td>
> <td width="5%">recpriority</td>
> </tr><?php
> foreach ($Channels as $channel) {
> ?><tr class="settings" align="center">
> + <td><input type="checkbox" name="delete_<?php echo $channel['chanid']?>" id="delete_<?php echo $channel['chanid']?>" value="true"></td>
> <td><?php echo htmlentities($channel['sourceid'])?></td>
> <td><input type="text" size="3" name="channum_<?php echo $channel['chanid']?>" id="channum_<?php echo $channel['chanid']?>" value="<?php echo htmlentities($channel['channum'])?>"></td>
> <td><input type="text" size="15" name="callsign_<?php echo $channel['chanid']?>" id="callsign_<?php echo $channel['chanid']?>" value="<?php echo htmlentities($channel['callsign'])?>"></td>
>
> ______________________________________________________________________
> diff -ur mythweb-0.14-old\config\conf.php mythweb-0.14\config\conf.php
> --- mythweb-0.14-old\config\conf.php Tue Jan 27 20:16:42 2004
> +++ mythweb-0.14\config\conf.php Mon Apr 26 12:36:16 2004
> @@ -35,6 +35,9 @@
>
> // Path to the mythvideo "covers" directory
> define('video_img_path', '');
> +
> +// Path to the mythtv channel file (this must be writable by PHP!)
> + define('channel_source_path', '/home/mythtv/.mythtv/channels.xmltv');
>
> // Movie word
> define('movie_word', 'Movie');
> diff -ur mythweb-0.14-old\includes\channels.php mythweb-0.14\includes\channels.php
> --- mythweb-0.14-old\includes\channels.php Thu Jan 15 21:36:04 2004
> +++ mythweb-0.14\includes\channels.php Mon Apr 26 15:23:24 2004
> @@ -43,6 +43,27 @@
> }
>
> /*
> + delete_channel:
> + Comments out the channel from the /.mythtv/<sourcename>.xmltv file by inserting the word "not " (including the space) in front of the unwanted entry.
> +*/
> + function delete_channel($channum,$channame) {
> + $lines = file(channel_info_path);
> + foreach ($lines as $line_num => $line) {
> + if (strpos($line,"channel: $channum $channame") !== false)
> + $lines[$line_num] = "not $line";
> + }
> + if ($handle = fopen(channel_info_path, "w")) {
> + foreach ($lines as $line) {
> + fputs($handle, $line) or trigger_error("Can't write channel file!");
> + }
> + fclose($handle);
> + }
> + else {
> + trigger_error("Can't open channel source file for writing, check permissions and try again.");
> + }
> + }
> +
> +/*
> Channel:
> A class to hold all channel-related data
> */
> diff -ur mythweb-0.14-old\settings_channels.php mythweb-0.14\settings_channels.php
> --- mythweb-0.14-old\settings_channels.php Sat Nov 22 02:59:16 2003
> +++ mythweb-0.14\settings_channels.php Mon Apr 26 23:42:33 2004
> @@ -15,22 +15,29 @@
> // Figure out the chanid, or leave
> if (!preg_match('/^channum_(\\d+)$/', $key, $match)) continue;
> list($match, $chanid) = $match;
> - // First, grab values that can be empty
> - $query = 'UPDATE channel SET freqid='.escape($_POST['freqid_'.$chanid]) .','
> - .'finetune='.escape($_POST['finetune_'.$chanid]) .','
> - .'videofilters='.escape($_POST['videofilters_'.$chanid]).','
> - .'brightness='.escape($_POST['brightness_'.$chanid]) .','
> - .'contrast='.escape($_POST['contrast_'.$chanid]) .','
> - .'colour='.escape($_POST['colour_'.$chanid]) .','
> - .'hue='.escape($_POST['hue_'.$chanid]) .','
> - .'recpriority='.escape($_POST['recpriority_'.$chanid]);
> + // First, delete any unwanted channels
> + if ($_POST['delete_'.$chanid] == "true") {
> + delete_channel($_POST['channum_'.$chanid],$_POST['callsign_'.$chanid]);
> + $query = 'DELETE FROM channel';
> + }
> + else {
> + // Not deleting so grab values that can be empty
> + $query = 'UPDATE channel SET freqid='.escape($_POST['freqid_'.$chanid]) .','
> + .'finetune='.escape($_POST['finetune_'.$chanid]) .','
> + .'videofilters='.escape($_POST['videofilters_'.$chanid]).','
> + .'brightness='.escape($_POST['brightness_'.$chanid]) .','
> + .'contrast='.escape($_POST['contrast_'.$chanid]) .','
> + .'colour='.escape($_POST['colour_'.$chanid]) .','
> + .'hue='.escape($_POST['hue_'.$chanid]) .','
> + .'recpriority='.escape($_POST['recpriority_'.$chanid]);
> // next, the fields that need to have a value, so we won't change them if they were emptied
> - if ($_POST['channum_'.$chanid])
> - $query .= ',channum='.escape($_POST['channum_'.$chanid]);
> - if ($_POST['callsign_'.$chanid])
> - $query .= ',callsign='.escape($_POST['callsign_'.$chanid]);
> - if ($_POST['name_'.$chanid])
> - $query .= ',name='.escape($_POST['name_'.$chanid]);
> + if ($_POST['channum_'.$chanid])
> + $query .= ',channum='.escape($_POST['channum_'.$chanid]);
> + if ($_POST['callsign_'.$chanid])
> + $query .= ',callsign='.escape($_POST['callsign_'.$chanid]);
> + if ($_POST['name_'.$chanid])
> + $query .= ',name='.escape($_POST['name_'.$chanid]);
> + }
> // Submit the query
> $result = mysql_query($query.' WHERE chanid='.escape($chanid))
> or trigger_error('SQL Error: '.mysql_error(), FATAL);
> diff -ur mythweb-0.14-old\themes\Default\settings_channels.php mythweb-0.14\themes\Default\settings_channels.php
> --- mythweb-0.14-old\themes\Default\settings_channels.php Sat Nov 22 02:59:16 2003
> +++ mythweb-0.14\themes\Default\settings_channels.php Mon Apr 26 12:33:15 2004
> @@ -20,6 +20,7 @@
>
> <table width="100%" border="0" cellpadding="4" cellspacing="2" class="list small">
> <tr class="menu" align="center">
> + <td width="4%">delete</td>
> <td width="4%">sourceid</td>
> <td width="5%">channum</td>
> <td width="12%">callsign</td>
> @@ -27,14 +28,15 @@
> <td width="5%">freqid</td>
> <td width="5%">finetune</td>
> <td width="5%">videofilters</td>
> - <td width="8%">brightness</td>
> - <td width="8%">contrast</td>
> - <td width="8%">colour</td>
> - <td width="8%">hue</td>
> + <td width="7%">brightness</td>
> + <td width="7%">contrast</td>
> + <td width="7%">colour</td>
> + <td width="7%">hue</td>
> <td width="5%">recpriority</td>
> </tr><?php
> foreach ($Channels as $channel) {
> ?><tr class="settings" align="center">
> + <td><input type="checkbox" name="delete_<?php echo $channel['chanid']?>" id="delete_<?php echo $channel['chanid']?>" value="true"></td>
> <td><?php echo htmlentities($channel['sourceid'])?></td>
> <td><input type="text" size="3" name="channum_<?php echo $channel['chanid']?>" id="channum_<?php echo $channel['chanid']?>" value="<?php echo htmlentities($channel['channum'])?>"></td>
> <td><input type="text" size="15" name="callsign_<?php echo $channel['chanid']?>" id="callsign_<?php echo $channel['chanid']?>" value="<?php echo htmlentities($channel['callsign'])?>"></td>
>
> ______________________________________________________________________
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
More information about the mythtv-dev
mailing list