diff options
| author | Andreas Brachold <vdr07@deltab.de> | 2008-01-18 16:48:25 +0000 |
|---|---|---|
| committer | Andreas Brachold <vdr07@deltab.de> | 2008-01-18 16:48:25 +0000 |
| commit | 7e1edd7310c35548846e444cf1b81fcfd1ee2d8c (patch) | |
| tree | 5bfc809fd3a1253d5fd73255ca7c55de575fe43e /lib | |
| parent | 1f837ad310bfd99baa472c1a42123d344f7fb393 (diff) | |
| download | xxv-7e1edd7310c35548846e444cf1b81fcfd1ee2d8c.tar.gz xxv-7e1edd7310c35548846e444cf1b81fcfd1ee2d8c.tar.bz2 | |
* TIMERS: Use MD5Sum to reference timer
* AUTOTIMER: Fix double create timer if starttime less then 60 seconds changed
* AUTOTIMER: Hide 'use pdc' if TIMER::use pdc disabled
* AUTOTIMER: Bug #12960 dont create timer with pdc, if TIMER::use pdc disabled
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/XXV/MODULES/AUTOTIMER.pm | 194 | ||||
| -rw-r--r-- | lib/XXV/MODULES/EPG.pm | 22 | ||||
| -rw-r--r-- | lib/XXV/MODULES/MOVETIMER.pm | 94 | ||||
| -rw-r--r-- | lib/XXV/MODULES/RECORDS.pm | 4 | ||||
| -rw-r--r-- | lib/XXV/MODULES/TIMERS.pm | 824 |
5 files changed, 607 insertions, 531 deletions
diff --git a/lib/XXV/MODULES/AUTOTIMER.pm b/lib/XXV/MODULES/AUTOTIMER.pm index f3b595e..d39444c 100644 --- a/lib/XXV/MODULES/AUTOTIMER.pm +++ b/lib/XXV/MODULES/AUTOTIMER.pm @@ -130,24 +130,24 @@ sub module { Actions => [ q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); my $desc = getDataById($timer->{eventid}, 'EPG', 'eventid') if($timer->{eventid}); - my $autotimer = getDataById($timer->{AutotimerId}, 'AUTOTIMER', 'Id'); + my $autotimer = getDataById($timer->{autotimerid}, 'AUTOTIMER', 'Id'); my $title = sprintf(gettext("Autotimer('%s') found: %s"), - $autotimer->{Search}, $timer->{File}); + $autotimer->{Search}, $timer->{file}); my $description = ''; - my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{ChannelID}); + my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{channel}); $description .= sprintf(gettext("Channel: %s"), $channel); $description .= "\r\n"; Date_Init("Language=English"); - my $d = ParseDate($timer->{NextStartTime}); - $timer->{NextStartTime} = datum(UnixDate($d,"%s")) if($d); + my $d = ParseDate($timer->{starttime}); + $timer->{starttime} = datum(UnixDate($d,"%s")) if($d); $description .= sprintf(gettext("On: %s to %s"), - $timer->{NextStartTime}, - fmttime($timer->{Stop})); + $timer->{starttime}, + fmttime($timer->{stop})); $description .= "\r\n"; $description .= sprintf(gettext("Description: %s"), $desc->{description} ) if($desc && $desc->{description}); @@ -176,28 +176,28 @@ sub status { my $sql = qq| SELECT SQL_CACHE - t.Id as __Id, - t.File, - t.Status as __Status, + t.id as __id, + t.file, + t.flags as __flags, c.Name as Channel, c.Pos as __Pos, - DATE_FORMAT(t.Day, '%e.%c.%Y') as Day, - t.Start, - t.Stop, - t.Priority, - UNIX_TIMESTAMP(t.NextStartTime) as __Day, - t.Collision as __Collision, - t.eventid as __NextEpgId, - t.AutotimerId as __AutotimerId + DATE_FORMAT(t.day, '%e.%c.%Y') as Day, + t.start, + t.stop, + t.priority, + UNIX_TIMESTAMP(t.starttime) as __day, + t.collision as __collision, + t.eventid as __eventid, + t.autotimerid as __autotimerid FROM TIMERS as t, CHANNELS as c WHERE - t.ChannelID = c.Id + t.channel = c.Id and UNIX_TIMESTAMP(t.addtime) > ? - and t.AutotimerId > 0 + and t.autotimerid > 0 ORDER BY - t.NextStartTime|; + t.starttime|; my $fields = fields($obj->{dbh}, $sql); my $sth = $obj->{dbh}->prepare($sql); @@ -298,9 +298,9 @@ sub _init { |); main::after(sub{ - my $m = main::getModule('EPG'); - $m->updated( - sub{ + my $modE = main::getModule('EPG'); + $modE->updated( + sub{ my $watcher = shift; my $console = shift; my $waiter = shift; @@ -411,7 +411,7 @@ sub _autotimerLookup { my $now = time; # Get Timersmodule - my $timermod = main::getModule('TIMERS'); + my $modT = main::getModule('TIMERS'); foreach my $id (sort keys %$att) { my $a = $att->{$id}; @@ -424,18 +424,18 @@ sub _autotimerLookup { } # Build SQL Command and run it .... - my $events = $obj->_eventsearch($a, $timermod, $addtime ) || next; + my $events = $obj->_eventsearch($a, $modT, $addtime ) || next; # Only search for one at? if(ref $console && $autotimerid) { $console->message(sprintf(gettext("Found %d entries for '%s' in EPG database."), scalar keys %$events, $a->{Search})); foreach my $Id (sort keys %$events) { my $output = [ - [gettext("Title") , $events->{$Id}->{Title}], - [gettext("Subtitle") , $events->{$Id}->{Subtitle}], - [gettext("Channel") , $events->{$Id}->{Channel}], + [gettext("Title") , $events->{$Id}->{title}], + [gettext("Subtitle") , $events->{$Id}->{subtitle}], + [gettext("Channel") , $events->{$Id}->{channelname}], ]; - if($events->{$Id}->{vpsstart} and $a->{VPS}) { + if($events->{$Id}->{vpsstart} and $a->{VPS} and $modT->{usevpstime} eq 'y') { push(@$output, [gettext("Start") , datum($events->{$Id}->{vpsstart} )]); push(@$output, [gettext("Stop") , datum($events->{$Id}->{vpsstop} )]); } else { @@ -456,22 +456,33 @@ sub _autotimerLookup { foreach my $Id (sort keys %$events) { my $event = $events->{$Id}; - $event->{Activ} = 'y'; - $event->{Priority} = $a->{Priority}; - $event->{Lifetime} = $a->{Lifetime}; - - $event->{File} = $obj->_placeholder($event, $a); + $event->{activ} = 'y'; + $event->{priority} = $a->{Priority}; + $event->{lifetime} = $a->{Lifetime}; - if($event->{vpsstart} and $a->{VPS}) { - $event->{VPS} = 'y'; + if($event->{vpsstart} and $a->{VPS} and $modT->{usevpstime} eq 'y') { + $event->{vps} = 'y'; $event->{starttime} = $event->{vpsstart}; $event->{stoptime} = $event->{vpsstop}; } else { - $event->{VPS} = ''; + $event->{vps} = 'n'; } # ignore outdated event next if($event->{stoptime} < $now); + + # remove seconds from time 12:00:30 => 12:00:00 + $event->{starttime} -= ($event->{starttime} % 60); + $event->{stoptime} -= ($event->{stoptime} % 60); + + my ($bsec,$bmin,$bhour,$bmday,$bmon,$byear,$bwday,$byday,$bisdst) = localtime($event->{starttime}); + my ($esec,$emin,$ehour,$emday,$emon,$eyear,$ewday,$eyday,$eisdst) = localtime($event->{stoptime}); + + $event->{day} = sprintf("%04d-%02d-%02d",$byear+1900,$bmon+1,$bmday); + $event->{start} = sprintf("%02d%02d",$bhour,$bmin); + $event->{stop} = sprintf("%02d%02d",$ehour,$emin); + + $event->{file} = $obj->_placeholder($event, $a); # Add anchor for reidentify timer $event->{aux} = sprintf('#~AT[%d]', $id); @@ -486,32 +497,28 @@ sub _autotimerLookup { # Ignore timer if it already with same title recorded if(grep(/^chronicle$/, @done) && $obj->_chronicleexists($event)) { - lg sprintf("Don't create timer from AT(%d) '%s', because found same data on chronicle", $id, $event->{File}); + lg sprintf("Don't create timer from AT(%d) '%s', because found same data on chronicle", $id, $event->{file}); next; } # Ignore timer if it already with same title recorded if(grep(/^recording$/, @done) && $obj->_recordexists($event)){ - lg sprintf("Don't create timer from AT(%d) '%s', because found same data on recordings", $id, $event->{File}); + lg sprintf("Don't create timer from AT(%d) '%s', because found same data on recordings", $id, $event->{file}); next; } # Ignore timer if it already a timer with same title programmed, on other place if(grep(/^timer$/, @done) && $obj->_timerexiststitle($event)){ - lg sprintf("Don't create timer from AT(%d) '%s', because found same data on other timers", $id, $event->{File}); + lg sprintf("Don't create timer from AT(%d) '%s', because found same data on other timers", $id, $event->{file}); next; } } my $error = 0; - my ($bsec,$bmin,$bhour,$bmday,$bmon,$byear,$bwday,$byday,$bisdst) = localtime($event->{starttime}); - my ($esec,$emin,$ehour,$emday,$emon,$eyear,$ewday,$eyday,$eisdst) = localtime($event->{stoptime}); - - $event->{Day} = sprintf("%04d-%02d-%02d",$byear+1900,$bmon+1,$bmday); - $event->{Start} = sprintf("%02d%02d",$bhour,$bmin); - $event->{Stop} = sprintf("%02d%02d",$ehour,$emin); - - my $erg = $timermod->saveTimer($event, $timerID ? $timerID : undef); + if($timerID) { + $event->{pos} = $modT->getPos($timerID); + } + my $erg = $modT->saveTimer($event); foreach my $zeile (@$erg) { if($zeile =~ /^(\d{3})\s+(.+)/) { $error = $2 if(int($1) >= 500); @@ -526,16 +533,16 @@ sub _autotimerLookup { #my $tdata = getDataByTable('TIMERS'); #dumper($tdata); - $console->err(sprintf(gettext("Could not save timer for '%s' : %s"), $event->{File}, $error)) + $console->err(sprintf(gettext("Could not save timer for '%s' : %s"), $event->{file}, $error)) if(ref $console && $autotimerid); } else { if($timerID) { ++$m; - $console->message(sprintf(gettext("Modified timer for '%s'."), $event->{File})) + $console->message(sprintf(gettext("Modified timer for '%s'."), $event->{file})) if(ref $console && $autotimerid); } else { ++$c; - $console->message(sprintf(gettext("Timer for '%s' has been created."), $event->{File})) + $console->message(sprintf(gettext("Timer for '%s' has been created."), $event->{file})) if(ref $console && $autotimerid); } } @@ -572,7 +579,7 @@ sub _autotimerLookup { sleep 1; - $timermod->readData(); + $modT->readData(); return (\@{$log},$C,$M); } @@ -603,7 +610,7 @@ sub autotimerEdit { my $timerid = shift || 0; my $data = shift || 0; - my $mod = main::getModule('CHANNELS'); + my $modC = main::getModule('CHANNELS'); my $modT = main::getModule('TIMERS'); my $epg; @@ -615,7 +622,7 @@ sub autotimerEdit { # Channels Ids in Namen umwandeln if($epg->{Channels}) { - my @channels = map { $_ = $mod->ChannelToPos($_) } split(/[\s|,]+/, $epg->{Channels}); + my @channels = map { $_ = $modC->ChannelToPos($_) } split(/[\s|,]+/, $epg->{Channels}); $epg->{Channels} = \@channels; } @@ -655,9 +662,9 @@ sub autotimerEdit { my $DoneChoices = [$do{'timer'}, $do{'recording'}]; # Enable option "chronicle" only if activated. - my $cm = main::getModule('CHRONICLE'); + my $modCH = main::getModule('CHRONICLE'); push(@$DoneChoices, $do{'chronicle'}) - if($cm and $cm->{active} eq 'y'); + if($modCH and $modCH->{active} eq 'y'); my $questions = [ 'Id' => { @@ -713,14 +720,14 @@ You can also fine tune your search : 'Channels' => { typ => 'list', def => $epg->{Channels}, - choices => $mod->ChannelArray('Name', sprintf(' NOT (%s)', $obj->{exclude})), + choices => $modC->ChannelArray('Name', sprintf(' NOT (%s)', $obj->{exclude})), options => 'multi', msg => gettext('Limit search to these channels'), check => sub{ my $value = shift || return; my @vals; foreach my $chname ((ref $value eq 'ARRAY' ? @$value : split(/\s*,\s*/, $value))) { - if( my $chid = $mod->PosToChannel($chname) || $mod->NameToChannel($chname)) { + if( my $chid = $modC->PosToChannel($chname) || $modC->NameToChannel($chname)) { push(@vals, $chid); } else { return undef, sprintf(gettext("The channel '%s' does not exist!"),$chname); @@ -838,7 +845,7 @@ You can also fine tune your search : }, }, 'VPS' => { - typ => 'confirm', + typ => $modT->{usevpstime} eq 'y' ? 'confirm' : 'hidden', def => $epg->{VPS} || 'n', msg => gettext('Use PDC time to control created timer'), }, @@ -919,7 +926,7 @@ You can also fine tune your search : typ => 'string', msg => gettext('Group all recordings into one directory'), def => $epg->{Dir}, - # choices => main::getModule('TIMERS')->getRootDirs, + # choices => $modT->getRootDirs, }, 'startdate' => { typ => 'string', @@ -1194,7 +1201,7 @@ sub _eventsearch { # ------------------ my $obj = shift || return error('No object defined!'); my $a = shift || return error('No data defined!'); - my $timermod = shift || return error('No timer modul defined!'); + my $modT = shift || return error('No timer modul defined!'); my $addtime = shift; my $query; @@ -1268,12 +1275,12 @@ sub _eventsearch { if(defined $a->{prevminutes}) { $prev = $a->{prevminutes} * 60; } else { - $prev = $timermod->{prevminutes} * 60; + $prev = $modT->{prevminutes} * 60; } if(defined $a->{afterminutes}) { $after = $a->{afterminutes} * 60; } else { - $after = $timermod->{afterminutes} * 60; + $after = $modT->{afterminutes} * 60; } # } @@ -1283,9 +1290,8 @@ sub _eventsearch { my $sql = qq| SELECT SQL_CACHE e.eventid as eventid, - e.channel_id as ChannelID, - c.Name as Channel, - c.POS as POS, + e.channel_id as channel, + c.Name as channelname, e.title as Title, e.subtitle as Subtitle, e.description as description, @@ -1317,21 +1323,21 @@ sub _timerexists { # Avoid Timer already defined (the timer with the same data again do not put on) my $sql = "SELECT SQL_CACHE count(*) as cc from TIMERS where - ChannelID = ? - and UNIX_TIMESTAMP(NextStartTime) = ? - and UNIX_TIMESTAMP(NextStopTime) = ? + channel = ? + and UNIX_TIMESTAMP(starttime) = ? + and UNIX_TIMESTAMP(stoptime) = ? "; -# and Priority = ? -# and Lifetime = ? +# and priority = ? +# and lifetime = ? # and ( -# ( Status & 1 = '0' ) -# or ( File = ? ) +# ( flags & 1 = '0' ) +# or ( file = ? ) # ) my $sth = $obj->{dbh}->prepare($sql); - $sth->execute($eventdata->{ChannelID},$eventdata->{starttime},$eventdata->{stoptime}, -# $eventdata->{Priority},$eventdata->{Lifetime}, -# $eventdata->{File} + $sth->execute($eventdata->{channel},$eventdata->{starttime},$eventdata->{stoptime}, +# $eventdata->{priority},$eventdata->{lifetime}, +# $eventdata->{file} ) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $erg = $sth->fetchrow_hashref(); @@ -1348,22 +1354,22 @@ sub _timerexistsfuzzy { my $eventdata = shift || return error('No data defined!'); # Adjust timers set by the autotimer, if event changed +/- five minutes. - my $sql = "SELECT SQL_CACHE ID from TIMERS where - ChannelID = ? - and ? between (UNIX_TIMESTAMP(NextStartTime) - 300) AND (UNIX_TIMESTAMP(NextStartTime) + 300) - and ? between (UNIX_TIMESTAMP(NextStopTime) - 300) AND (UNIX_TIMESTAMP(NextStopTime) + 300) - and File = ? + my $sql = "SELECT SQL_CACHE id from TIMERS where + channel = ? + and ? between (UNIX_TIMESTAMP(starttime) - 300) AND (UNIX_TIMESTAMP(starttime) + 300) + and ? between (UNIX_TIMESTAMP(stoptime) - 300) AND (UNIX_TIMESTAMP(stoptime) + 300) + and file = ? and aux like ?"; my $sth = $obj->{dbh}->prepare($sql); - $sth->execute($eventdata->{ChannelID}, + $sth->execute($eventdata->{channel}, $eventdata->{starttime}, $eventdata->{stoptime}, - $eventdata->{File}, + $eventdata->{file}, "%".$eventdata->{aux}) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $erg = $sth->fetchrow_hashref(); - return $erg->{ID} + return $erg->{id} if($erg); return 0; } @@ -1381,7 +1387,7 @@ sub _recordexists { AND CONCAT_WS('~',e.title,IF(e.subtitle<>'',e.subtitle,NULL)) = ?"; my $sth = $obj->{dbh}->prepare($sql); - $sth->execute($eventdata->{File}) + $sth->execute($eventdata->{file}) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $erg = $sth->fetchrow_hashref(); return $erg->{cc} @@ -1395,13 +1401,13 @@ sub _chronicleexists { my $obj = shift || return error('No object defined!'); my $eventdata = shift || return error('No data defined!'); - my $chroniclemod = main::getModule('CHRONICLE'); + my $modCH = main::getModule('CHRONICLE'); return 0 - unless($chroniclemod and $chroniclemod->{active} eq 'y'); + unless($modCH and $modCH->{active} eq 'y'); my $sql = "SELECT SQL_CACHE count(*) as cc from CHRONICLE where title = ?"; my $sth = $obj->{dbh}->prepare($sql); - $sth->execute($eventdata->{File}) + $sth->execute($eventdata->{file}) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $erg = $sth->fetchrow_hashref(); return $erg->{cc} @@ -1415,10 +1421,10 @@ sub _timerexiststitle { my $obj = shift || return error('No object defined!'); my $eventdata = shift || return error('No data defined!'); - my $sql = "SELECT SQL_CACHE count(*) as cc from TIMERS where File = ?"; + my $sql = "SELECT SQL_CACHE count(*) as cc from TIMERS where file = ?"; my $sth = $obj->{dbh}->prepare($sql); - $sth->execute($eventdata->{File}) + $sth->execute($eventdata->{file}) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $erg = $sth->fetchrow_hashref(); return $erg->{cc} @@ -1470,8 +1476,8 @@ sub _placeholder { if($title =~ /.*%.*%.*/sig) { my %at_details; $at_details{'title'} = $data->{Title}; - $at_details{'subtitle'} = $data->{Subtitle} ? $data->{Subtitle} : $data->{Start}; - $at_details{'date'} = $data->{Day}; + $at_details{'subtitle'} = $data->{Subtitle} ? $data->{Subtitle} : $data->{start}; + $at_details{'date'} = $data->{day}; $at_details{'regie'} = $1 if $data->{description} =~ m/\|Director: (.*?)\|/; $at_details{'category'} = $1 if $data->{description} =~ m/\|Category: (.*?)\|/; $at_details{'genre'} = $1 if $data->{description} =~ m/\|Genre: (.*?)\|/; diff --git a/lib/XXV/MODULES/EPG.pm b/lib/XXV/MODULES/EPG.pm index 2a545eb..51c515c 100644 --- a/lib/XXV/MODULES/EPG.pm +++ b/lib/XXV/MODULES/EPG.pm @@ -202,7 +202,7 @@ sub _init { return 0; } - my $version = 26; # Must be increment if rows of table changed + my $version = 27; # Must be increment if rows of table changed # this tables hasen't handmade user data, # therefore old table could dropped if updated rows @@ -216,7 +216,7 @@ sub _init { $obj->{dbh}->do(qq| CREATE TABLE IF NOT EXISTS $table ( - eventid bigint unsigned NOT NULL default '0', + eventid int unsigned NOT NULL default '0', title text NOT NULL default '', subtitle text default '', description text, @@ -665,7 +665,7 @@ sub search { unshift(@$erg, $fields); } $console->table($erg, { - timers => $tim->getEpgIds, + timers => $tim->getEvents, runningTimer => $tim->getRunningTimer('eventid'), } ); @@ -722,7 +722,7 @@ order by $console->table($erg, { channels => $mod->ChannelArray('Name'), current => $mod->ChannelToPos($cid), - timers => $tim->getEpgIds, + timers => $tim->getEvents, runningTimer => $tim->getRunningTimer('eventid'), } ); @@ -803,7 +803,7 @@ where unshift(@$erg, $fields); my $tim = main::getModule('TIMERS'); - $console->table($erg,{timers => $tim->getEpgIds}); + $console->table($erg,{timers => $tim->getEvents}); } # ------------------ @@ -885,7 +885,7 @@ ORDER BY $console->table($erg, { - timers => $tim->getEpgIds, + timers => $tim->getEvents, runningTimer => $tim->getRunningTimer('eventid'), periods => $obj->{periods}, cgroups => $cgroups, @@ -960,7 +960,7 @@ ORDER BY my $tim = main::getModule('TIMERS'); $console->table($erg, { - timers => $tim->getEpgIds, + timers => $tim->getEvents, runningTimer => $tim->getRunningTimer('eventid'), zeit => $zeit, periods => $obj->{periods}, @@ -1104,7 +1104,7 @@ ORDER BY my $tim = main::getModule('TIMERS'); $console->table($data, { - timers => $tim->getEpgIds, + timers => $tim->getEvents, runningTimer => $tim->getRunningTimer('eventid'), zeitvon => $zeitvon, zeitbis => $zeitbis, @@ -1127,8 +1127,8 @@ sub checkOnTimer { my $sql = qq| SELECT SQL_CACHE - e.starttime as NextStartTime, - ADDDATE(e.starttime, INTERVAL e.duration SECOND) as NextStopTime, + e.starttime as starttime, + ADDDATE(e.starttime, INTERVAL e.duration SECOND) as stoptime, LEFT(c.Source,1) as source, c.TID as transponderid FROM @@ -1147,7 +1147,7 @@ WHERE my $tmod = main::getModule('TIMERS'); # Zeige den Title des Timers foreach (@$erg) { - $_ = $tmod->getTimerById((split(':', $_))[0])->{File} + $_ = $tmod->getTimerById((split(':', $_))[0])->{file} unless($_ eq 'ok'); } diff --git a/lib/XXV/MODULES/MOVETIMER.pm b/lib/XXV/MODULES/MOVETIMER.pm index 087e953..c9df382 100644 --- a/lib/XXV/MODULES/MOVETIMER.pm +++ b/lib/XXV/MODULES/MOVETIMER.pm @@ -184,31 +184,32 @@ sub _movetimer { my $sth = $self->{dbh}->prepare( q| select - t.Id as Id, - IF(t.Status & 1,'y','n') as Activ, - IF(t.Status & 4,'y','n') as VPS, - t.Status as Status, - t.ChannelID as ChannelID, - t.File as File, + t.id as id, + t.pos as pos, + IF(t.flags & 1,'y','n') as activ, + IF(t.flags & 4,'y','n') as vps, + t.flags as flags, + t.channel as channel, + t.file as file, t.aux as aux, - t.Day as Day, - t.Start as Start, - t.Stop as Stop, - t.Priority as Priority, - t.Lifetime as Lifetime, - t.Collision as Collision, - IF(t.Status & 1 and NOW() between t.NextStartTime and t.NextStopTime,1,0) as Running + t.day as day, + t.start as start, + t.stop as stop, + t.priority as priority, + t.lifetime as lifetime, + t.collision as collision, + IF(t.flags & 1 and NOW() between t.starttime and t.stoptime,1,0) as running from TIMERS as t,MOVETIMER as m where - m.source = t.channelid + m.source = t.channel and m.move != 'm' - and t.Status & 1 + and t.flags & 1 |); if(!$sth->execute()) { return error sprintf("Couldn't execute query: %s.",$sth->errstr); } - my $timer = $sth->fetchall_hashref('Id'); + my $timer = $sth->fetchall_hashref('id'); return unless($timer); $sth = $self->{dbh}->prepare("select * from MOVETIMER where move != 'n'"); @@ -229,7 +230,7 @@ q| my $rule = $rules->{$id}; - if($data->{ChannelID} eq $rule->{source}) { + if($data->{channel} eq $rule->{source}) { # Move timer if collision present if($rule->{move} eq 'collision') { @@ -243,39 +244,41 @@ q| if($col > $maxPrio); } # dont solve collision until lesser own Priority - last if($maxPrio < $data->{Priority}); + last if($maxPrio < $data->{priority}); } debug sprintf("Move timer %d (%s) at %s : from %s to %s", - $data->{Id}, - $data->{File}, - $data->{Day}, + $data->{pos}, + $data->{file}, + $data->{day}, $rule->{source}, $rule->{destination}); if($rule->{original} eq 'keep' ) { # Keep original timer but disable him - $data->{Activ} = 'n'; - $self->modifyTimer($data,$tid); + $data->{activ} = 'n'; + $self->modifyTimer($data); # Create new timer - $data->{Activ} = 'y'; - $data->{ChannelID} = $rule->{destination}; - $self->modifyTimer($data,0); + $data->{activ} = 'y'; + $data->{channel} = $rule->{destination}; + $data->{pos} = 0; + $self->modifyTimer($data); } elsif($rule->{original} eq 'copy' ) { # Copy to new timer - $data->{Activ} = 'y'; - $data->{ChannelID} = $rule->{destination}; - $self->modifyTimer($data,0); + $data->{activ} = 'y'; + $data->{channel} = $rule->{destination}; + $data->{pos} = 0; + $self->modifyTimer($data); } else { # Edit timer direct - $data->{ChannelID} = $rule->{destination}; - $self->modifyTimer($data,$tid); + $data->{channel} = $rule->{destination}; + $self->modifyTimer($data); } @@ -302,26 +305,25 @@ sub modifyTimer { # ------------------ my $self = shift || return error('No object defined!'); my $data = shift || return error('No data defined!'); - my $id = shift || 0; - my $status = ($data->{Activ} eq 'y' ? 1 : 0); - $status |= ($data->{VPS} eq 'y' ? 4 : 0); + my $flags = ($data->{activ} eq 'y' ? 1 : 0); + $flags |= ($data->{vps} eq 'y' ? 4 : 0); - $data->{File} =~ s/:/|/g; - $data->{File} =~ s/(\r|\n)//sig; + $data->{file} =~ s/:/|/g; + $data->{file} =~ s/(\r|\n)//sig; $self->{svdrp}->queue_cmds( sprintf("%s %s:%s:%s:%s:%s:%s:%s:%s:%s", - $id ? "modt $id" : "newt", - $status, - $data->{ChannelID}, - $data->{Day}, - $data->{Start}, - $data->{Stop}, - int($data->{Priority}), - int($data->{Lifetime}), - $data->{File}, - ($data->{aux} || '') + $data->{pos} ? "modt $data->{pos}" : "newt", + $flags, + $data->{channel}, + $data->{day}, + $data->{start}, + $data->{stop}, + int($data->{priority}), + int($data->{lifetime}), + $data->{file}, + ($data->{aux} || '') ) ); } diff --git a/lib/XXV/MODULES/RECORDS.pm b/lib/XXV/MODULES/RECORDS.pm index b48b588..afda6bf 100644 --- a/lib/XXV/MODULES/RECORDS.pm +++ b/lib/XXV/MODULES/RECORDS.pm @@ -269,7 +269,7 @@ sub _init { return 0; } - my $version = 26; # Must be increment if rows of table changed + my $version = 27; # Must be increment if rows of table changed # this tables hasen't handmade user data, # therefore old table could dropped if updated rows if(!tableUpdated($obj->{dbh},'RECORDS',$version,1)) { @@ -279,7 +279,7 @@ sub _init { # Look for table or create this table $obj->{dbh}->do(qq| CREATE TABLE IF NOT EXISTS RECORDS ( - eventid bigint unsigned NOT NULL, + eventid int unsigned NOT NULL, RecordId int unsigned not NULL, RecordMD5 varchar(32) NOT NULL, Path text NOT NULL, diff --git a/lib/XXV/MODULES/TIMERS.pm b/lib/XXV/MODULES/TIMERS.pm index 00d9ec3..ae978cc 100644 --- a/lib/XXV/MODULES/TIMERS.pm +++ b/lib/XXV/MODULES/TIMERS.pm @@ -143,24 +143,24 @@ sub module { Actions => [ q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); - return if($timer->{AutotimerId}); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); + return if($timer->{autotimerid}); my $desc = getDataById($timer->{eventid}, 'EPG', 'eventid') if($timer->{eventid}); - my $title = sprintf(gettext("New timer found: %s"),$timer->{File}); + my $title = sprintf(gettext("New timer found: %s"),$timer->{file}); my $description = ''; - my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{ChannelID}); + my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{channel}); $description .= sprintf(gettext("Channel: %s"), $channel); $description .= "\r\n"; Date_Init("Language=English"); - my $d = ParseDate($timer->{NextStartTime}); - $timer->{NextStartTime} = datum(UnixDate($d,"%s")) if($d); + my $d = ParseDate($timer->{starttime}); + $timer->{starttime} = datum(UnixDate($d,"%s")) if($d); $description .= sprintf(gettext("On: %s to %s"), - $timer->{NextStartTime}, - fmttime($timer->{Stop})); + $timer->{starttime}, + fmttime($timer->{stop})); $description .= "\r\n"; $description .= sprintf(gettext("Description: %s"), $desc->{description} ) if($desc && $desc->{description}); @@ -170,13 +170,13 @@ sub module { |, q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); my $soap = main::getModule('SHARE'); my $level = 1; - if($timer->{AutotimerId}) { - $level = (($timer->{Priority} <= 50 or $timer->{Lifetime} < 33) ? 2 : 3); + if($timer->{autotimerid}) { + $level = (($timer->{priority} <= 50 or $timer->{lifetime} < 33) ? 2 : 3); } else { - $level = (($timer->{Priority} <= 50 or $timer->{Lifetime} < 33) ? 4 : 5); + $level = (($timer->{priority} <= 50 or $timer->{lifetime} < 33) ? 4 : 5); } if($timer->{eventid}) { @@ -199,23 +199,23 @@ sub module { Actions => [ q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); - my $title = sprintf(gettext("Timer deleted: %s"),$timer->{File}); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); + my $title = sprintf(gettext("Timer deleted: %s"),$timer->{file}); my $desc = getDataById($timer->{eventid}, 'EPG', 'eventid') if($timer->{eventid}); my $description = ''; - my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{ChannelID}); + my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{channel}); $description .= sprintf(gettext("Channel: %s"), $channel); $description .= "\r\n"; Date_Init("Language=English"); - my $d = ParseDate($timer->{NextStartTime}); - $timer->{NextStartTime} = datum(UnixDate($d,"%s")) if($d); + my $d = ParseDate($timer->{starttime}); + $timer->{starttime} = datum(UnixDate($d,"%s")) if($d); $description .= sprintf(gettext("On: %s to %s"), - $timer->{NextStartTime}, - fmttime($timer->{Stop})); + $timer->{starttime}, + fmttime($timer->{stop})); $description .= "\r\n"; $description .= sprintf(gettext("Description: %s"), $desc->{description} ) if($desc && $desc->{description}); @@ -225,7 +225,7 @@ sub module { |, q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); my $soap = main::getModule('SHARE'); my $level = 1; @@ -249,28 +249,28 @@ sub module { Actions => [ q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); my $title; if($args->{Type} eq 'on') { - $title = sprintf(gettext("Timer activated: %s"),$timer->{File}); + $title = sprintf(gettext("Timer activated: %s"),$timer->{file}); } else { - $title = sprintf(gettext("Timer deactivated: %s"),$timer->{File}); + $title = sprintf(gettext("Timer deactivated: %s"),$timer->{file}); } my $description = ''; - my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{ChannelID}); + my $channel = main::getModule('CHANNELS')->ChannelToName($timer->{channel}); $description .= sprintf(gettext("Channel: %s"), $channel); $description .= "\r\n"; Date_Init("Language=English"); - my $d = ParseDate($timer->{NextStartTime}); - $timer->{NextStartTime} = datum(UnixDate($d,"%s")) if($d); + my $d = ParseDate($timer->{starttime}); + $timer->{starttime} = datum(UnixDate($d,"%s")) if($d); my $desc = getDataById($timer->{eventid}, 'EPG', 'eventid') if($timer->{eventid}); $description .= sprintf(gettext("On: %s to %s"), - $timer->{NextStartTime}, - fmttime($timer->{Stop})); + $timer->{starttime}, + fmttime($timer->{stop})); $description .= "\r\n"; $description .= sprintf(gettext("Description: %s"), $desc->{description} ) if($desc && $desc->{description}); @@ -280,13 +280,13 @@ sub module { |, q|sub{ my $args = shift; my $event = shift; - my $timer = getDataById($args->{TimerId}, 'TIMERS', 'Id'); + my $timer = getDataById($args->{TimerId}, 'TIMERS', 'pos'); my $soap = main::getModule('SHARE'); my $level = ($args->{Type} eq 'off' ? 1 : 2); - if($timer->{AutotimerId} and $args->{Type} eq 'on') { - $level = (($timer->{Priority} <= 50 or $timer->{Lifetime} < 33) ? 2 : 3); + if($timer->{autotimerid} and $args->{Type} eq 'on') { + $level = (($timer->{priority} <= 50 or $timer->{lifetime} < 33) ? 2 : 3); } elsif($args->{Type} eq 'on') { - $level = (($timer->{Priority} <= 50 or $timer->{Lifetime} < 33) ? 4 : 5); + $level = (($timer->{priority} <= 50 or $timer->{lifetime} < 33) ? 4 : 5); } if($timer->{eventid}) { @@ -308,21 +308,21 @@ sub module { Actions => [ q|sub{ my $args = shift; my $event = shift; - my $soap = main::getModule('SHARE'); - my $epg = main::getModule('EPG'); + my $modS = main::getModule('SHARE') or return; + my $modE = main::getModule('EPG') or return; for (my $i = 1; $i<=$args->{HighId}; $i++) { - my $timer = getDataById($i, 'TIMERS', 'Id'); + my $timer = getDataById($i, 'TIMERS', 'pos'); my $level = 1; - if($timer->{AutotimerId} and ($timer->{Status} & 1)) { - $level = (($timer->{Priority} <= 50 or $timer->{Lifetime} < 33) ? 2 : 3); - } elsif($timer->{Status} & 1) { - $level = (($timer->{Priority} <= 50 or $timer->{Lifetime} < 33) ? 4 : 5); + if($timer->{autotimerid} and ($timer->{flags} & 1)) { + $level = (($timer->{priority} <= 50 or $timer->{lifetime} < 33) ? 2 : 3); + } elsif($timer->{flags} & 1) { + $level = (($timer->{priority} <= 50 or $timer->{lifetime} < 33) ? 4 : 5); } if($timer->{eventid}) { - my $event = $epg->getId($timer->{eventid}, 'UNIX_TIMESTAMP(starttime) + duration as STOPTIME'); - $soap->setEventLevel($timer->{eventid}, $level, $event->{STOPTIME}); + my $event = $modE->getId($timer->{eventid}, 'UNIX_TIMESTAMP(starttime) + duration as STOPTIME'); + $modS->setEventLevel($timer->{eventid}, $level, $event->{STOPTIME}); } } }|, @@ -402,7 +402,7 @@ sub _init { return 0; } - my $version = 27; # Must be increment if rows of table changed + my $version = 28; # Must be increment if rows of table changed # this tables hasen't handmade user data, # therefore old table could dropped if updated rows if(!tableUpdated($obj->{dbh},'TIMERS',$version,1)) { @@ -412,26 +412,27 @@ sub _init { # Look for table or create this table $obj->{dbh}->do(qq| CREATE TABLE IF NOT EXISTS TIMERS ( - Id int(11) unsigned NOT NULL, - Status char(1) default 1, - ChannelID varchar(100) NOT NULL default '', - Day varchar(20) default '-------', - Start int(11) unsigned, - Stop int(11) unsigned, - Priority tinyint(2), - Lifetime tinyint(2), - File text, + id varchar(32) NOT NULL, + pos int(11) unsigned NOT NULL, + flags char(1) default 1, + channel varchar(100) NOT NULL default '', + day varchar(20) default '-------', + start int(11) unsigned, + stop int(11) unsigned, + priority tinyint(2), + lifetime tinyint(2), + file text, aux text default '', - NextStartTime datetime, - NextStopTime datetime, - Collision varchar(100) default '0', - eventid bigint unsigned default '0', + starttime datetime, + stoptime datetime, + collision varchar(100) default '0', + eventid int unsigned default '0', eventstarttime datetime, eventduration int unsigned default '0', - AutotimerId int(11) unsigned default '0', + autotimerid int(11) unsigned default '0', + checked char(1) default 0, addtime timestamp, - Checked char(1) default 0, - PRIMARY KEY (Id) + PRIMARY KEY(id) ) COMMENT = '$version' |); @@ -466,30 +467,20 @@ sub saveTimer { # ------------------ my $obj = shift || return error('No object defined!'); my $data = shift || return error('No data defined!'); - my $timerid = shift || 0; - $obj->_saveTimer($data,$timerid); + $obj->_saveTimer($data); if($obj->{svdrp}->queue_cmds('COUNT')) { my $erg = $obj->{svdrp}->queue_cmds("CALL"); # Aufrufen der Kommandos # Save shortly this timer in DB if this only a new timer (at) # Very Important for Autotimer! my $pos = $1 if($erg->[1] =~ /^250\s+(\d+)/); - if(! $timerid and $pos) { - $obj->insert([ - $data->{Status}, - $data->{ChannelID}, - $data->{Day}, - $data->{Start}, - $data->{Stop}, - int($data->{Priority}), - int($data->{Lifetime}), - $data->{File}, - ($data->{aux} || '') - ], $pos); + if(!(exists $data->{pos}) and $pos) { + $data->{pos} = $pos; + $obj->_insert($data); } - event sprintf('Save timer "%s" with id: "%d"', $data->{File}, $pos || 0); + event sprintf('Save timer "%s" with id: "%d"', $data->{file}, $pos || 0); return $erg; } @@ -501,25 +492,27 @@ sub _saveTimer { # ------------------ my $obj = shift || return error('No object defined!'); my $data = shift || return error('No data defined!'); - my $timerid = shift || 0; - $data->{Status} = ($data->{Activ} eq 'y' ? 1 : 0); - $data->{Status} |= ($data->{VPS} eq 'y' ? 4 : 0); + $data->{flags} = ($data->{activ} eq 'y' ? 1 : 0); + $data->{flags} |= ($data->{vps} eq 'y' ? 4 : 0); + + $data->{file} =~ s/(\r|\n)//sg; + $data->{aux} =~ s/(\r|\n)//sg; - $data->{File} =~ s/:/|/g; - $data->{File} =~ s/(\r|\n)//sig; + my $file = $data->{file}; + $file =~ s/:/|/g; $obj->{svdrp}->queue_cmds( sprintf("%s %s:%s:%s:%s:%s:%s:%s:%s:%s", - $timerid ? "modt $timerid" : "newt", - $data->{Status}, - $data->{ChannelID}, - $data->{Day}, - $data->{Start}, - $data->{Stop}, - int($data->{Priority}), - int($data->{Lifetime}), - $data->{File}, + $data->{pos} ? "modt $data->{pos}" : "newt", + $data->{flags}, + $data->{channel}, + $data->{day}, + $data->{start}, + $data->{stop}, + int($data->{priority}), + int($data->{lifetime}), + $file, ($data->{aux} || '') ) ); @@ -527,19 +520,19 @@ sub _saveTimer { sub _newTimerdefaults { my $obj = shift || return error('No object defined!'); - my $epg = shift; + my $timer = shift; - $epg->{Activ} = 'y'; - $epg->{Priority} = $obj->{Priority}; - $epg->{Lifetime} = $obj->{Lifetime}; + $timer->{activ} = 'y'; + $timer->{priority} = $obj->{Priority}; + $timer->{lifetime} = $obj->{Lifetime}; - if($epg->{VpsStart} && $obj->{usevpstime} eq 'y') { - $epg->{VPS} = 'y'; - $epg->{Day} = $epg->{VpsDay}; - $epg->{Start} = $epg->{VpsStart}; - $epg->{Stop} = $epg->{VpsStop}; + if($timer->{vpsstart} && $obj->{usevpstime} eq 'y') { + $timer->{vps} = 'y'; + $timer->{day} = $timer->{vpsday}; + $timer->{start} = $timer->{vpsstart}; + $timer->{stop} = $timer->{vpsstop}; } else { - $epg->{VPS} = 'n'; + $timer->{vps} = 'n'; } } # ------------------ @@ -557,15 +550,15 @@ sub newTimer { my $sql = qq| SELECT SQL_CACHE eventid, - channel_id as ChannelID, + channel_id as channel, description, - CONCAT_WS('~', title, subtitle) as File, - DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(starttime) - ? ), '%Y-%m-%d') as Day, - DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(starttime) - ? ), '%H%i') as Start, - DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(starttime) + duration + ? ), '%H%i') as Stop, - DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(vpstime)), '%Y-%m-%d') as VpsDay, - DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(vpstime)), '%H%i') as VpsStart, - DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(vpstime) + duration), '%H%i') as VpsStop + CONCAT_WS('~', title, subtitle) as file, + DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(starttime) - ? ), '%Y-%m-%d') as day, + DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(starttime) - ? ), '%H%i') as start, + DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(starttime) + duration + ? ), '%H%i') as stop, + DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(vpstime)), '%Y-%m-%d') as vpsday, + DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(vpstime)), '%H%i') as vpsstart, + DATE_FORMAT(FROM_UNIXTIME(UNIX_TIMESTAMP(vpstime) + duration), '%H%i') as vpsstop FROM EPG WHERE|; @@ -590,11 +583,11 @@ WHERE|; if(not ref $epg) { my $t = time; $epg = { - ChannelID => '', - File => gettext('New timer'), - Day => my_strftime("%Y-%m-%d",$t), - Start => my_strftime("%H%M",$t), - Stop => my_strftime("%H%M",$t) + channel => '', + file => gettext('New timer'), + day => my_strftime("%Y-%m-%d",$t), + start => my_strftime("%H%M",$t), + stop => my_strftime("%H%M",$t) }; $obj->_newTimerdefaults($epg); } @@ -615,21 +608,21 @@ sub _editTimer { my $sth = $obj->{dbh}->prepare( qq| SELECT SQL_CACHE - Id, - ChannelID, - File, + id, + channel, + file, aux, - Start, - Stop, - Day, - Priority, - Lifetime, - IF(Status & 1,'y','n') as Activ, - IF(Status & 4,'y','n') as VPS + start, + stop, + day, + priority, + lifetime, + IF(flags & 1,'y','n') as activ, + IF(flags & 4,'y','n') as vps FROM TIMERS WHERE - Id = ? + id = ? |); $sth->execute($timerid) or return $console->err(sprintf(gettext("Timer '%s' does not exist in the database!"),$timerid)); @@ -641,28 +634,33 @@ WHERE $timerData->{aux} =~ s/(\r|\n)//sig if(defined $timerData->{aux}); - my $mod = main::getModule('CHANNELS'); + my $modC = main::getModule('CHANNELS'); my $con = $console->typ eq "CONSOLE"; my $questions = [ - 'Id' => { + 'id' => { typ => 'hidden', - def => $timerData->{Id} || 0, + def => $timerData->{id} || 0, }, - 'Activ' => { + 'activ' => { typ => 'confirm', - def => $timerData->{Activ}, + def => $timerData->{activ}, msg => gettext('Enable this timer'), }, - 'VPS' => { + 'vps' => { typ => 'confirm', - def => $timerData->{VPS}, + def => $timerData->{vps}, msg => gettext('Use PDC time to control timer'), }, - 'ChannelID' => { + 'file' => { + msg => gettext('Title of recording'), + def => $timerData->{file}, + req => gettext("This is required!"), + }, + 'channel' => { typ => 'list', - def => $con ? $mod->ChannelToPos($timerData->{ChannelID}) : $timerData->{ChannelID}, - choices => $con ? $mod->ChannelArray('Name') : $mod->ChannelIDArray('Name'), + def => $con ? $modC->ChannelToPos($timerData->{channel}) : $timerData->{channel}, + choices => $con ? $modC->ChannelArray('Name') : $modC->ChannelIDArray('Name'), msg => gettext('Which channel should recorded'), req => gettext("This is required!"), check => sub{ @@ -670,17 +668,17 @@ WHERE return undef, gettext("This is required!") unless($value); - my $ch = $mod->ToCID($value); + my $ch = $modC->ToCID($value); return undef, sprintf(gettext("This channel '%s' does not exist!"),$value) unless($ch); return $ch; }, }, - 'Day' => { + 'day' => { typ => $con ? 'string' : 'date', def => sub{ # Convert day from VDR format to locale format - my $value = $timerData->{Day}; + my $value = $timerData->{day}; if($value and $value =~ /^\d{4}\-\d{2}-\d{2}$/) { Date_Init("Language=English"); my $d = ParseDate($value); @@ -715,10 +713,10 @@ WHERE } }, }, - 'Start' => { + 'start' => { typ => 'string', def => sub{ - return fmttime($timerData->{Start}); + return fmttime($timerData->{start}); }, msg => gettext("Start time in format 'HH:MM'"), check => sub{ @@ -734,10 +732,10 @@ WHERE } }, }, - 'Stop' => { + 'stop' => { typ => 'string', def => sub{ - return fmttime($timerData->{Stop} || 0 ); + return fmttime($timerData->{stop}); }, msg => gettext("End time in format 'HH:MM'"), check => sub{ @@ -753,10 +751,10 @@ WHERE } }, }, - 'Priority' => { + 'priority' => { typ => 'integer', msg => sprintf(gettext('Priority (%d ... %d)'),0,$console->{USER}->{MaxPriority} ? $console->{USER}->{MaxPriority} : 99 ), - def => int($timerData->{Priority}), + def => int($timerData->{priority}), check => sub{ my $value = shift || 0; if($value =~ /^\d+$/sig and $value >= 0 and $value < 100) { @@ -769,10 +767,10 @@ WHERE } }, }, - 'Lifetime' => { + 'lifetime' => { typ => 'integer', msg => sprintf(gettext('Lifetime (%d ... %d)'),0,$console->{USER}->{MaxLifeTime} ? $console->{USER}->{MaxLifeTime} : 99 ), - def => int($timerData->{Lifetime}), + def => int($timerData->{lifetime}), check => sub{ my $value = shift || 0; if($value =~ /^\d+$/sig and $value >= 0 and $value < 100) { @@ -785,19 +783,14 @@ WHERE } }, }, - 'File' => { - msg => gettext('Title of recording'), - def => $timerData->{File}, - req => gettext("This is required!"), - }, 'aux' => { typ => 'hidden', def => $timerData->{aux}, } ]; - if($timerData->{Id} || $timerData->{description}) { - my $description = $timerData->{description} || $obj->getEpgDesc($timerData->{Id}); + if($timerData->{id} || $timerData->{description}) { + my $description = $timerData->{description} || $obj->getEpgDesc($timerData->{id}); if($description) { push(@$questions, 'Description' => { @@ -813,7 +806,10 @@ WHERE : gettext('New timer')), $questions, $data); if(ref $datasave eq 'HASH') { - $obj->_saveTimer($datasave, $timerid); + if($timerid) { + $datasave->{pos} = $obj->getPos($timerid); + } + $obj->_saveTimer($datasave); return 1; } return 0; @@ -840,14 +836,14 @@ sub editTimer { unless($error) { debug sprintf('%s timer with title "%s" is saved%s', ($timerid ? 'Changed' : 'New'), - $data->{File}, + $data->{file}, ( $console->{USER} && $console->{USER}->{Name} ? sprintf(' from user: %s', $console->{USER}->{Name}) : "" ) ); $console->message($erg); } else { error sprintf('%s timer with title "%s" does\'nt saved : %s', ($timerid ? 'Changed' : 'New'), - $data->{File}, + $data->{file}, $error ); $console->err($erg); @@ -868,25 +864,31 @@ sub deleteTimer { my $timerid = shift || return $console->err(gettext("No timer defined for deletion! Please use tdelete 'tid'.")); # If timerid the edittimer my $answer = shift || 0; - my @timers = reverse sort{ $a <=> $b } split(/[^0-9]/, $timerid); + my @timers = split(/[^0-9a-f]/, $timerid); - my $sql = sprintf('SELECT SQL_CACHE Id,File,ChannelID,NextStartTime,IF(Status & 1 and NOW() between NextStartTime and NextStopTime,1,0) as Running FROM TIMERS where Id in (%s)', join(',' => ('?') x @timers)); + my $sql = sprintf('SELECT SQL_CACHE id,pos,file,channel,starttime,IF(flags & 1 and NOW() between starttime and stoptime,1,0) FROM TIMERS where id in (%s) ORDER BY pos desc', join(',' => ('?') x @timers)); my $sth = $obj->{dbh}->prepare($sql); $sth->execute(@timers) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); - my $data = $sth->fetchall_hashref('Id'); - - my $mod = main::getModule('CHANNELS') or return; - foreach my $tid (@timers) { - unless(exists $data->{$tid}) { - $console->err(sprintf(gettext("Timer '%s' does not exist in the database!"), $tid)); - next; - } + my $data = $sth->fetchall_arrayref(); + + my $modC = main::getModule('CHANNELS') or return; + foreach my $d (@$data) { + my $t = { + id => $d->[0], + pos => $d->[1], + file => $d->[2], + channel => $d->[3], + start => $d->[4], + running => $d->[5] + }; if(ref $console and $console->{TYP} eq 'CONSOLE') { - $data->{$tid}->{ChannelID} = $mod->ChannelToName($data->{$tid}->{ChannelID}); - - $console->table($data->{$tid}); + $console->table({ + gettext('Title') => $t->{file}, + gettext('Channel') => $modC->ChannelToName($t->{channel}), + gettext('Start') => $t->{start}, + }); my $confirm = $console->confirm({ typ => 'confirm', def => 'y', @@ -896,15 +898,30 @@ sub deleteTimer { } debug sprintf('Delete timer with title "%s"%s', - $data->{$tid}->{File}, + $t->{file}, ( $console->{USER} && $console->{USER}->{Name} ? sprintf(' from user: %s', $console->{USER}->{Name}) : "" ) ); - $obj->{svdrp}->queue_cmds(sprintf("modt %d off", $tid)) - if($data->{$tid}->{Running}); - $obj->{svdrp}->queue_cmds(sprintf("delt %d", $tid)); + $obj->{svdrp}->queue_cmds(sprintf("modt %d off", $t->{pos})) + if($t->{running}); + $obj->{svdrp}->queue_cmds(sprintf("delt %d", $t->{pos})); + + # Delete timer from request, if found in database + my $i = 0; + for my $x (@timers) { + if ( $x eq $t->{id} ) { # Remove known MD5 from user request + splice @timers, $i, 1; + } else { + $i++; + } + } } + con_err($console, + sprintf(gettext("Timer '%s' does not exist in the database!"), + join('\',\'',@timers))) + if(scalar @timers); + if($obj->{svdrp}->queue_cmds('COUNT')) { my $erg = $obj->{svdrp}->queue_cmds("CALL"); # Aufrufen der Kommandos $console->msg($erg, $obj->{svdrp}->err) @@ -931,38 +948,58 @@ sub toggleTimer { my $console = shift || return error('No console defined!'); my $timerid = shift || return $console->err(gettext("No timer defined to toggle! Please use ttoggle 'id'.")); # If timerid the edittimer - my @timers = reverse sort{ $a <=> $b } split(/[^0-9]/, $timerid); + my @timers = split(/[^0-9a-f]/, $timerid); - my $sql = sprintf('SELECT SQL_CACHE Id,File,Status,NextStartTime, NextStopTime FROM TIMERS where Id in (%s)', join(',' => ('?') x @timers)); + my $sql = sprintf('SELECT SQL_CACHE id,pos,file,flags,starttime,stoptime FROM TIMERS where id in (%s) ORDER BY pos desc', join(',' => ('?') x @timers)); my $sth = $obj->{dbh}->prepare($sql); $sth->execute(@timers) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); - my $data = $sth->fetchall_hashref('Id'); + my $data = $sth->fetchall_arrayref(); my $ref; - - for my $timer (@timers) { - - unless(exists $data->{$timer}) { - $console->err(sprintf(gettext("Timer '%s' does not exist in the database!"), $timer)); - next; - } + my @success; + + foreach my $d (@$data) { + my $t = { + id => $d->[0], + pos => $d->[1], + file => $d->[2], + flags => $d->[3], + start => $d->[4], + stop => $d->[5] + }; # Build query for all timers with possible collisions - $ref .= " or '$data->{$timer}->{NextStartTime}' between NextStartTime and NextStopTime" - . " or '$data->{$timer}->{NextStopTime}' between NextStartTime and NextStopTime"; + $ref .= " or '$t->{start}' between starttime and stoptime" + . " or '$t->{stop}' between starttime and stoptime"; - my $status = (($data->{$timer}->{Status} & 1) ? 'off' : 'on'); + my $status = (($t->{flags} & 1) ? 'off' : 'on'); debug sprintf('Timer with title "%s" is %s%s', - $data->{$timer}->{File}, + $t->{file}, ($status eq 'on' ? 'activated' : 'deactivated'), ( $console->{USER} && $console->{USER}->{Name} ? sprintf(' from user: %s', $console->{USER}->{Name}) : "" ) ); - $obj->{svdrp}->queue_cmds("modt $data->{$timer}->{Id} $status"); # Sammeln der Kommandos + $obj->{svdrp}->queue_cmds("modt $t->{pos} $status"); # Sammeln der Kommandos + + # Delete timer from request, if found in database + my $i = 0; + for my $x (@timers) { + if ( $x eq $t->{id} ) { # Remove known MD5 from user request + splice @timers, $i, 1; + } else { + $i++; + } + } + push(@success,$t->{id}); } + con_err($console, + sprintf(gettext("Timer '%s' does not exist in the database!"), + join('\',\'',@timers))) + if(scalar @timers); + if($obj->{svdrp}->queue_cmds('COUNT')) { my $erg = $obj->{svdrp}->queue_cmds("CALL"); # Aufrufen der Kommandos @@ -977,10 +1014,10 @@ sub toggleTimer { if(ref $console and $console->typ eq 'AJAX') { # { "data" : [ [ ID, ON, RUN, CONFLICT ], .... ] } # { "data" : [ [ 5, 1, 0, 0 ], .... ] } - my $sql = sprintf('SELECT SQL_CACHE Id, Status & 1 as Active, IF(NOW() between NextStartTime and NextStopTime,1,0) as Running, Collision from TIMERS where Id in (%s) %s', - join(',' => ('?') x @timers),$ref); + my $sql = sprintf('SELECT SQL_CACHE id, flags & 1 as Active, IF(NOW() between starttime and stoptime,1,0) as Running, Collision from TIMERS where id in (%s) %s', + join(',' => ('?') x @success),$ref); my $sth = $obj->{dbh}->prepare($sql); - $sth->execute(@timers) + $sth->execute(@success) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $erg = $sth->fetchall_arrayref(); $console->table($erg); @@ -995,62 +1032,62 @@ sub toggleTimer { # ------------------ -sub insert { +sub _insert { # ------------------ my $obj = shift || return error('No object defined!'); - my $data = shift || return; - my $pos = shift || return; + my $timer = shift || return; my $checked = shift || 0; # import only status which used from vdr and thereby exclude eventid from vdradmin - $data->[0] &= 15; + $timer->{flags} &= 15; # change pos to channelid, because change to telnet reader - if(index($data->[1], '-') < 0) { - $data->[1] = main::getModule('CHANNELS')->ToCID($data->[1]) - or return error(sprintf("Couldn't get channel from this data: %s", join(',', @$data))); + if(index($timer->{channel}, '-') < 0) { + $timer->{channel} = main::getModule('CHANNELS')->ToCID($timer->{channel}) + or return error(sprintf("Couldn't get channel from this timer: %d '%s'", $timer->{pos}, $timer->{channel})); } - # POS - unshift(@$data, $pos); - $data->[8] =~ s/\|/\:/g; + $timer->{file} =~ s/\|/\:/g; # NextTime - my $nexttime = $obj->getNextTime( $data->[3], $data->[4], $data->[5] ) - or return error(sprintf("Couldn't get time from this data: %s", join(',', @$data))); - push(@$data, $nexttime->{start}, $nexttime->{stop}); - - # insert placeholder - push(@$data, 0); # eventid - push(@$data, 0); # eventstarttime - push(@$data, 0); # eventduration + my $nexttime = $obj->getNextTime( $timer->{day}, $timer->{start}, $timer->{stop} ) + or return error(sprintf("Couldn't get time from this timer: %d '%s' '%s' '%s'", $timer->{pos}, $timer->{day}, $timer->{start}, $timer->{stop})); # AutotimerId - my $atxt = (split('~', $data->[9]))[-1]; + my $atxt = (split('~', $timer->{aux}))[-1]; my $aid = $1 if(defined $atxt and $atxt =~ /AT\[(\d+)\]/); - push(@$data, $aid || 0); - - # checked - push(@$data, $checked); # Search for event at EPG my $e = $obj->_getNextEpgId( { - Id => $data->[0], - Status => $data->[1], - ChannelID => $data->[2], - File => $data->[8], - NextStartTime => $data->[10], - NextStopTime => $data->[11], + pos => $timer->{pos}, + flags => $timer->{flags}, + channel => $timer->{channel}, + file => $timer->{file}, + start => $nexttime->{start}, + stop => $nexttime->{stop}, }); - if($e and exists $e->{eventid}) { - $data->[12] = $e->{eventid}; - $data->[13] = $e->{starttime}; - $data->[14] = $e->{duration}; - } - my $sth = $obj->{dbh}->prepare('REPLACE INTO TIMERS VALUES (?,?,?,?,?,?,?,?,?,?,FROM_UNIXTIME(?), FROM_UNIXTIME(?),0,?,?,?,?,NOW(),?)'); - $sth->execute( @$data ) - or return error sprintf("Couldn't execute query: %s.",$sth->errstr); + my $sth = $obj->{dbh}->prepare('REPLACE INTO TIMERS VALUES (MD5(CONCAT(?,?,?)),?,?,?,?,?,?,?,?,?,?,FROM_UNIXTIME(?), FROM_UNIXTIME(?),0,?,?,?,?,?,NOW())'); + $sth->execute( + $timer->{channel},$nexttime->{start},$nexttime->{stop}, + $timer->{pos}, + $timer->{flags}, + $timer->{channel}, + $timer->{day}, + $timer->{start}, + $timer->{stop}, + $timer->{priority}, + $timer->{lifetime}, + $timer->{file}, + $timer->{aux}, + $nexttime->{start}, + $nexttime->{stop}, + $e ? $e->{eventid} : 0, + $e ? $e->{starttime} : 0, + $e ? $e->{duration} : 0, + $aid, + $checked + ) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); } @@ -1079,9 +1116,21 @@ sub _readData { $line =~ s/^\d+[- ]+\d+\s//sig; $c++; my @data = split(':', $line, 9); - - $obj->insert(\@data, $c, 1) - if(scalar @data > 2); + if(scalar @data > 2) { + my $timer = { + pos => $c, + flags => $data[0], + channel => $data[1], + day => $data[2], + start => $data[3], + stop => $data[4], + priority=> $data[5], + lifetime=> $data[6], + file => $data[7], + aux => $data[8] + }; + $obj->_insert($timer, 1); + } } # Search for overlapping Timers @@ -1095,7 +1144,7 @@ sub _readData { if($oldTimers) { my $timers = $obj->getNewTimers($oldTimers); foreach my $timerdata (@$timers) { - event sprintf('New timer "%s" with id: "%d"', $timerdata->{File}, $timerdata->{Id}); + event sprintf('New timer "%s" with id: "%d"', $timerdata->{file}, $timerdata->{pos}); } $obj->updated() if(scalar @$timers); } @@ -1157,89 +1206,89 @@ sub list { my $term; my $search1 = ''; my $search2 = ''; - if($text and $text =~ /^[0-9,_ ]+$/ ) { - my @timers = split(/[^0-9]/, $text); - $search1 = sprintf(" AND t.Id in (%s)",join(',' => ('?') x @timers)); + if($text and $text =~ /^[0-9a-f,_ ]+$/ and length($text) >= 32 ) { + my @timers = split(/[^0-9a-f]/, $text); + $search1 = sprintf(" AND t.id in (%s)",join(',' => ('?') x @timers)); foreach(@timers) { push(@{$term},$_); } - $search2 = sprintf(" AND t.Id in (%s)",join(',' => ('?') x @timers)); + $search2 = sprintf(" AND t.id in (%s)",join(',' => ('?') x @timers)); foreach(@timers) { push(@{$term},$_); } } elsif($text) { - my $query1 = buildsearch("t.File,e.description",$text); + my $query1 = buildsearch("t.file,e.description",$text); $search1 = sprintf('AND ( %s )', $query1->{query}); foreach(@{$query1->{term}}) { push(@{$term},$_); } - my $query2 = buildsearch("t.File",$text); + my $query2 = buildsearch("t.file",$text); $search2 = sprintf('AND ( %s )', $query2->{query}); foreach(@{$query2->{term}}) { push(@{$term},$_); } } my %f = ( - 'Id' => gettext('Service'), - 'Status' => gettext('Status'), - 'Day' => gettext('Day'), - 'Channel' => gettext('Channel'), - 'Start' => gettext('Start'), - 'Stop' => gettext('Stop'), - 'Title' => gettext('Title'), - 'Priority' => gettext('Priority') + 'id' => gettext('Service'), + 'flags' => gettext('Status'), + 'day' => gettext('Day'), + 'channel' => gettext('Channel'), + 'start' => gettext('Start'), + 'stop' => gettext('Stop'), + 'title' => gettext('Title'), + 'priority' => gettext('Priority') ); my $sql = qq| SELECT SQL_CACHE - t.Id as \'$f{'Id'}\', - t.Status as \'$f{'Status'}\', - c.Name as \'$f{'Channel'}\', - c.Pos as __Pos, - t.Day as \'$f{'Day'}\', - DATE_FORMAT(t.NextStartTime, '%H:%i') as \'$f{'Start'}\', - DATE_FORMAT(t.NextStopTime, '%H:%i') as \'$f{'Stop'}\', - t.File as \'$f{'Title'}\', - t.Priority as \'$f{'Priority'}\', - UNIX_TIMESTAMP(t.NextStartTime) as __Day, - t.Collision as __Collision, + t.id as \'$f{'id'}\', + t.flags as \'$f{'flags'}\', + c.Name as \'$f{'channel'}\', + c.Pos as __pos, + t.day as \'$f{'day'}\', + DATE_FORMAT(t.starttime, '%H:%i') as \'$f{'start'}\', + DATE_FORMAT(t.stoptime, '%H:%i') as \'$f{'stop'}\', + t.file as \'$f{'title'}\', + t.priority as \'$f{'priority'}\', + UNIX_TIMESTAMP(t.starttime) as __day, + t.collision as __collision, t.eventid as __eventid, - t.AutotimerId as __AutotimerId, - UNIX_TIMESTAMP(t.NextStopTime) - UNIX_TIMESTAMP(t.NextStartTime) as __Duration, + t.autotimerid as __autotimerid, + UNIX_TIMESTAMP(t.stoptime) - UNIX_TIMESTAMP(t.starttime) as __duration, e.description as __description FROM TIMERS as t, CHANNELS as c, EPG as e WHERE - t.NextStopTime > NOW() - AND t.ChannelID = c.Id - and (t.eventid = e.eventid) + t.stoptime > NOW() + AND t.channel = c.Id + AND (t.eventid = e.eventid) $search1 UNION SELECT SQL_CACHE - t.Id as \'$f{'Id'}\', - t.Status as \'$f{'Status'}\', - c.Name as \'$f{'Channel'}\', - c.Pos as __Pos, - t.Day as \'$f{'Day'}\', - DATE_FORMAT(t.NextStartTime, '%H:%i') as \'$f{'Start'}\', - DATE_FORMAT(t.NextStopTime, '%H:%i') as \'$f{'Stop'}\', - t.File as \'$f{'Title'}\', - t.Priority as \'$f{'Priority'}\', - UNIX_TIMESTAMP(t.NextStartTime) as __Day, - t.Collision as __Collision, + t.id as \'$f{'id'}\', + t.flags as \'$f{'flags'}\', + c.Name as \'$f{'channel'}\', + c.Pos as __pos, + t.day as \'$f{'day'}\', + DATE_FORMAT(t.starttime, '%H:%i') as \'$f{'start'}\', + DATE_FORMAT(t.stoptime, '%H:%i') as \'$f{'stop'}\', + t.file as \'$f{'title'}\', + t.priority as \'$f{'priority'}\', + UNIX_TIMESTAMP(t.starttime) as __day, + t.collision as __collision, t.eventid as __eventid, - t.AutotimerId as __AutotimerId, - UNIX_TIMESTAMP(t.NextStopTime) - UNIX_TIMESTAMP(t.NextStartTime) as __Duration, + t.autotimerid as __autotimerid, + UNIX_TIMESTAMP(t.stoptime) - UNIX_TIMESTAMP(t.starttime) as __duration, "" as __description FROM TIMERS as t, CHANNELS as c WHERE - t.ChannelID = c.Id - and (t.eventid = 0) + t.channel = c.Id + AND ((t.eventid = 0) or (t.eventid is null)) $search2 ORDER BY - __Day + __day |; my $fields = fields($obj->{dbh}, $sql); @@ -1265,25 +1314,25 @@ sub getTimerById { my $sql = qq| SELECT SQL_CACHE - t.Id, - t.Status, + t.id, + t.flags, c.Name as Channel, c.Pos as __Pos, - t.Day as Prg, - t.Start, - t.Stop, - t.File, - t.Priority, - UNIX_TIMESTAMP(t.NextStartTime) as Day, - t.Collision as Collision, - t.eventid as eventid, - t.AutotimerId as AutotimerId + t.day as Date, + t.start, + t.stop, + t.file, + t.priority, + UNIX_TIMESTAMP(t.starttime) as Day, + t.collision, + t.eventid, + t.autotimerid FROM TIMERS as t, CHANNELS as c WHERE - t.ChannelID = c.Id - and t.Id = ? + t.channel = c.Id + and t.id = ? |; my $sth = $obj->{dbh}->prepare($sql); @@ -1297,8 +1346,8 @@ WHERE sub getRunningTimer { # ------------------ my $obj = shift || return error('No object defined!'); - my $rowname = shift || 'Id'; - my $sql = "SELECT SQL_CACHE $rowname from TIMERS where NOW() between NextStartTime and NextStopTime AND (Status & 1)"; + my $rowname = shift || 'id'; + my $sql = "SELECT SQL_CACHE $rowname from TIMERS where NOW() between starttime and stoptime AND (flags & 1)"; my $erg = $obj->{dbh}->selectall_hashref($sql, $rowname); return $erg; } @@ -1311,7 +1360,7 @@ sub getNewTimers { my $ret = []; foreach my $timerid (keys %$oldTimers) { - if(! $oldTimers->{$timerid}->{Checked}) { + if(! $oldTimers->{$timerid}->{checked}) { push(@$ret, $oldTimers->{$timerid}); } } @@ -1323,31 +1372,31 @@ sub getCheckTimer { # ------------------ my $obj = shift || return error('No object defined!'); my $sql = qq| -SELECT SQL_CACHE t.Id as Id, t.Status as Status,t.ChannelID as ChannelID, - t.Priority as Priority, t.Lifetime as Lifetime, - t.File as File, t.aux as aux, - t.Start as TimerStart,t.Stop as TimerStop, +SELECT SQL_CACHE t.id as id,t.pos as pos, t.flags as flags,t.channel as channel, + t.priority as priority, t.lifetime as lifetime, + t.file as file, t.aux as aux, + t.start as timerstart,t.stop as timerstop, UNIX_TIMESTAMP(e.starttime) as starttime, UNIX_TIMESTAMP(e.starttime) + e.duration as stoptime, UNIX_TIMESTAMP(e.vpstime) as vpsstart, UNIX_TIMESTAMP(e.vpstime) + e.duration as vpsstop, - ABS(UNIX_TIMESTAMP(t.eventstarttime) - UNIX_TIMESTAMP(NextStartTime)) as lead, - ABS(UNIX_TIMESTAMP(NextStopTime)-(UNIX_TIMESTAMP(t.eventstarttime) + t.eventduration)) as lag + ABS(UNIX_TIMESTAMP(t.eventstarttime) - UNIX_TIMESTAMP(t.starttime)) as lead, + ABS(UNIX_TIMESTAMP(t.stoptime)-(UNIX_TIMESTAMP(t.eventstarttime) + t.eventduration)) as lag FROM TIMERS as t, EPG as e - WHERE (Status & 1) + WHERE (flags & 1) AND e.eventid > 0 AND t.eventid = e.eventid AND ( - (((t.Status & 4) = 0) AND e.starttime != t.eventstarttime) - OR ((t.Status & 4) AND e.vpstime != t.eventstarttime) + (((t.flags & 4) = 0) AND e.starttime != t.eventstarttime) + OR ((t.flags & 4) AND e.vpstime != t.eventstarttime) OR (e.duration != t.eventduration) ) - AND SUBSTRING_INDEX( t.File , '~', 1 ) LIKE CONCAT('%', e.title ,'%') + AND SUBSTRING_INDEX( t.file , '~', 1 ) LIKE CONCAT('%', e.title ,'%') |; - my $erg = $obj->{dbh}->selectall_hashref($sql, 'Id'); + my $erg = $obj->{dbh}->selectall_hashref($sql, 'id'); foreach my $t (keys %$erg) { my %tt; @@ -1356,7 +1405,7 @@ SELECT SQL_CACHE t.Id as Id, t.Status as Status,t.ChannelID as ChannelID, my $start; my $stop; - if(($erg->{$t}->{Status} & 4) # Use VPS Time if used + if(($erg->{$t}->{flags} & 4) # Use PDC time if used and $erg->{$t}->{vpsstart} and $erg->{$t}->{vpsstop}) { $start = $erg->{$t}->{vpsstart}; @@ -1368,37 +1417,56 @@ SELECT SQL_CACHE t.Id as Id, t.Status as Status,t.ChannelID as ChannelID, # Format parameterhash for saveTimer my $tt = { - Activ => (($erg->{$t}->{Status} & 1) ? 'y' : 'n'), - VPS => (($erg->{$t}->{Status} & 4) ? 'y' : 'n'), - ChannelID => $erg->{$t}->{ChannelID}, - File => $erg->{$t}->{File}, + pos => $erg->{$t}->{pos}, + activ => (($erg->{$t}->{flags} & 1) ? 'y' : 'n'), + vps => (($erg->{$t}->{flags} & 4) ? 'y' : 'n'), + channel => $erg->{$t}->{channel}, + file => $erg->{$t}->{file}, aux => $erg->{$t}->{aux}, - Day => my_strftime("%Y-%m-%d",$start), - Start => my_strftime("%H%M",$start), - Stop => my_strftime("%H%M",$stop), - Priority => $erg->{$t}->{Priority}, - Lifetime => $erg->{$t}->{Lifetime} + day => my_strftime("%Y-%m-%d",$start), + start => my_strftime("%H%M",$start), + stop => my_strftime("%H%M",$stop), + priority => $erg->{$t}->{priority}, + lifetime => $erg->{$t}->{lifetime} }; - my $timer = $erg->{$t}->{Id}; - debug sprintf("Adjust timer %d (%s) at %s : from %s - %s to %s - %s", - $timer, - $tt->{File}, - $tt->{Day}, - fmttime($erg->{$t}->{TimerStart}), fmttime($erg->{$t}->{TimerStop}), - fmttime($tt->{Start}),fmttime($tt->{Stop})); + $tt->{pos}, + $tt->{file}, + $tt->{day}, + fmttime($erg->{$t}->{timerstart}), fmttime($erg->{$t}->{timerstop}), + fmttime($tt->{start}),fmttime($tt->{stop})); - $obj->saveTimer($tt, $timer); + $obj->saveTimer($tt); } return $erg; } # ------------------ -sub getEpgIds { +sub getPos { # ------------------ my $obj = shift || return error('No object defined!'); - my $sql = "SELECT SQL_CACHE Id, Status & 1 as Status, eventid from TIMERS where eventid > 0"; + my $tid = shift || return error('No id defined!'); + + my $sql = qq| +SELECT SQL_CACHE + pos from TIMERS as t +where + t.id = ? +|; + + my $sth = $obj->{dbh}->prepare($sql); + $sth->execute($tid) + or return error(sprintf("Timer '%s' does not exist in the database!",$tid)); + my $erg = $sth->fetchrow_hashref(); + return $erg ? $erg->{pos} : 0; +} + +# ------------------ +sub getEvents { +# ------------------ + my $obj = shift || return error('No object defined!'); + my $sql = "SELECT SQL_CACHE id, flags & 1 as activ, eventid from TIMERS where eventid > 0"; my $erg = $obj->{dbh}->selectall_hashref($sql, 'eventid'); return $erg; } @@ -1432,20 +1500,20 @@ sub getOverlappingTimer { my $sql = qq| SELECT SQL_CACHE - TIMERS.Id, - TIMERS.Priority, - TIMERS.NextStartTime, - TIMERS.NextStopTime, - CHANNELS.TID as transponderid, - LEFT(CHANNELS.Source,1) as source -from TIMERS, - CHANNELS -where TIMERS.ChannelID = CHANNELS.Id + t.id, + t.priority, + t.starttime, + t.stoptime, + c.TID as transponderid, + LEFT(c.Source,1) as source +from TIMERS as t, + CHANNELS as c +where t.channel = c.Id |; - my $erg = $obj->{dbh}->selectall_hashref($sql, 'Id'); + my $erg = $obj->{dbh}->selectall_hashref($sql, 'id'); my $return; - my $sth = $obj->{dbh}->prepare("UPDATE TIMERS SET Collision = ? WHERE Id = ?"); + my $sth = $obj->{dbh}->prepare("UPDATE TIMERS SET collision = ? WHERE id = ?"); foreach my $tid (keys %$erg) { my $result = $obj->checkOverlapping($erg->{$tid}); if(ref $result eq 'ARRAY' and scalar @$result) { @@ -1465,37 +1533,37 @@ sub checkOverlapping { my $obj = shift || return error('No object defined!'); my $data = shift || return error('No data defined!'); - my $NextStartTime = $data->{NextStartTime}; - my $NextStopTime = $data->{NextStopTime}; + my $starttime = $data->{starttime}; + my $stoptime = $data->{stoptime}; my $transponder = $data->{transponderid}; my $source = $data->{source}; - my $Priority = $data->{Priority} || $obj->{Priority}; - my $tid = $data->{Id} || 0; + my $Priority = $data->{priority} || $obj->{Priority}; + my $tid = $data->{id} || 0; my $sql = qq| SELECT SQL_CACHE - t.Id, - t.Priority, + t.id, + t.priority, c.TID FROM TIMERS as t, CHANNELS as c WHERE - ((? between t.NextStartTime AND t.NextStopTime) - OR (? between t.NextStartTime AND t.NextStopTime) - OR (t.NextStartTime between ? AND ?) - OR (t.NextStopTime between ? AND ?)) - AND t.Id != ? - AND (t.Status & 1) - AND t.ChannelID = c.Id + ((? between t.starttime AND t.stoptime) + OR (? between t.starttime AND t.stoptime) + OR (t.starttime between ? AND ?) + OR (t.stoptime between ? AND ?)) + AND t.id != ? + AND (t.flags & 1) + AND t.channel = c.Id AND c.TID != ? AND LEFT(c.Source,1) = ? ORDER BY - t.Priority desc + t.priority desc |; my $sth = $obj->{dbh}->prepare($sql); - $sth->execute($NextStartTime,$NextStopTime, - $NextStartTime,$NextStopTime, - $NextStartTime,$NextStopTime, + $sth->execute($starttime,$stoptime, + $starttime,$stoptime, + $starttime,$stoptime, $tid,$transponder,$source) or return error sprintf("Couldn't execute query: %s.",$sth->errstr); my $result = $sth->fetchall_arrayref(); @@ -1512,7 +1580,7 @@ ORDER BY # Store conflict line at line - my $col = sprintf('%d:%d', + my $col = sprintf('%s:%s', $probant->[0], $probant->[1]); @@ -1521,10 +1589,10 @@ ORDER BY foreach my $trans (@{$result}) { if(defined $trans->[0] - && $probant->[0] != $trans->[0] - && $probant->[2] == $trans->[2]) { + && $probant->[0] ne $trans->[0] + && $probant->[2] eq $trans->[2]) { - $col .= sprintf('|%d:%d', + $col .= sprintf('|%s:%s', $trans->[0], $trans->[1]); @@ -1569,12 +1637,12 @@ sub getNextTimer { my $watcher = $event->w; my $data = $watcher->data; - my $reportmod = main::getModule('REPORT'); - $reportmod->news( - sprintf(gettext("Timer %d with title '%s' has started the recording!"), $data->{Id}, $data->{File}), - sprintf(gettext("on channel: %s to %s"), $data->{Channel}, fmttime($data->{Stop})), + my $modR = main::getModule('REPORT'); + $modR->news( + sprintf(gettext("Timer title '%s' has started the recording!"), $data->{file}), + sprintf(gettext("on channel: %s to %s"), $data->{channel}, fmttime($data->{stop})), 'tedit', - $data->{Id}, + $data->{id}, 'harmless' ); $watcher->cancel; @@ -1591,8 +1659,8 @@ sub _getNextEpgId { my $timer = shift || return error('No data defined!'); my $e; - my @file = split('~', $timer->{File}); - my $timemode = ($timer->{Status} & 4) ? 'vpstime' : 'starttime'; + my @file = split('~', $timer->{file}); + my $timemode = ($timer->{flags} & 4) ? 'vpstime' : 'starttime'; if(scalar @file >= 2) { # title and subtitle defined my $sth = $obj->{dbh}->prepare(sprintf(qq| SELECT SQL_CACHE eventid,%s as starttime,duration from EPG @@ -1602,13 +1670,13 @@ sub _getNextEpgId { AND (title like ? or title like ? ) ORDER BY ABS(( ? )-UNIX_TIMESTAMP(%s)) LIMIT 1 |,$timemode,$timemode,$timemode)); - if(!$sth->execute($timer->{ChannelID}, - $timer->{NextStartTime}, - $timer->{NextStopTime}, + if(!$sth->execute($timer->{channel}, + $timer->{start}, + $timer->{stop}, '%'.$file[-2].'%', '%'.$file[-1].'%', - $timer->{NextStartTime})) { - lg sprintf("Couldn't find epg event for timer with id %d - %s", $timer->{Id} , $timer->{File} ); + $timer->{start})) { + lg sprintf("Couldn't find epg event for timer with id %d - %s", $timer->{pos} , $timer->{file} ); return 0; } $e = $sth->fetchrow_hashref(); @@ -1622,19 +1690,19 @@ sub _getNextEpgId { AND (title like ? ) ORDER BY ABS(( ? )-UNIX_TIMESTAMP(%s)) LIMIT 1 |,$timemode,$timemode,$timemode)); - if(!$sth->execute($timer->{ChannelID}, - $timer->{NextStartTime}, - $timer->{NextStopTime}, - '%'.$timer->{File}.'%', - $timer->{NextStartTime})) { - lg sprintf("Couldn't find epg event for timer with id %d - %s", $timer->{Id} , $timer->{File} ); + if(!$sth->execute($timer->{channel}, + $timer->{start}, + $timer->{stop}, + '%'.$timer->{file}.'%', + $timer->{start})) { + lg sprintf("Couldn't find epg event for timer with id %d - %s", $timer->{pos} , $timer->{file} ); return 0; } $e = $sth->fetchrow_hashref(); } - lg sprintf("Couldn't find epg event for timer with id %d - %s", $timer->{Id} , $timer->{File} ) + lg sprintf("Couldn't find epg event for timer with id %d - %s", $timer->{pos} , $timer->{file} ) if(not exists $e->{eventid}); return $e; } @@ -1736,7 +1804,7 @@ sub getTimersByAutotimer { activeTimer => [], deactiveTimer => [], }; - my $erg = getDataBySearch('TIMERS', 'AutotimerId = ?', $aid); + my $erg = getDataBySearch('TIMERS', 'autotimerid = ?', $aid); map { my $type = ($_->[1] ? 'activeTimer' : 'deactiveTimer'); push(@{$obj->{AIDS}->{$aid}->{$type}}, $_->[0]); @@ -1754,7 +1822,7 @@ sub getTimersByAutotimer { sub getRootDirs { my $obj = shift || return error('No object defined!'); my $count = shift || 1; - my $sql = "SELECT SQL_CACHE distinct SUBSTRING_INDEX(File,'~',$count) from TIMERS;"; + my $sql = "SELECT SQL_CACHE distinct SUBSTRING_INDEX(file,'~',$count) from TIMERS;"; my $erg = $obj->{dbh}->selectall_arrayref($sql); my @ret; for(@$erg) { @@ -1792,15 +1860,15 @@ sub suggest { if($search) { my $sql = qq| SELECT SQL_CACHE - File + file FROM TIMERS WHERE - ( File LIKE ? ) + ( file LIKE ? ) GROUP BY - File + file ORDER BY - File + file LIMIT 25 |; my $sth = $obj->{dbh}->prepare($sql); |
