<%pre>

#include <tools.h>
#include <epgsearch.h>
#include <setup.h>
#include <users.h>

#include <iomanip>

using namespace vdrlive;
</%pre>
<%args>
  // input parameters
  std::string searchtimerid;
  std::string test;

  // form parameters
  std::string search = "";
  int mode = 0;
  bool matchcase = false;
  int tolerance = 1;
  bool usetitle = false;
  bool usesubtitle = false;
  bool usedescr = false;
  bool usecontentids = false;
  int usechannel = SearchTimer::NoChannel;
  std::string channelfrom_string = "";
  std::string channelto_string = "";
  std::string changrpsel = "";
  bool usetime = false;
  std::string start_s = "00:00";
  std::string stop_s = "00:00";
  bool useduration = false;
  int durationmin_h = 0;
  int durationmin_m = 0;
  int durationmax_h = 1;
  int durationmax_m = 30;
  bool useweekday = false;
  bool wday_mon = false;
  bool wday_tue = false;
  bool wday_wed = false;
  bool wday_thu = false;
  bool wday_fri = false;
  bool wday_sat = false;
  bool wday_sun = false;
  bool useinfavorites = false;
  int useassearchtimer = 0;
  int searchtimeraction = 0;
  bool seriesrecording = false;
  std::string directory = "";
  int delrecafterdays = 0;
  int keeprecs = 0;
  int pauseonrecs = 0;
  int blacklistmode = 3;
  int switchminbefore = 0;
  bool useextepginfo = false;
  std::string extepgvalues[];
  bool avoidrepeats = false;
  int allowedrepeats = 0;
  int repeatswithindays = 0;
  bool comparetitle = false;
  int comparesubtitle = 0;
  bool comparesummary = false;
  unsigned avoidrepeatscatselected[];
  int priority = 0;
  int lifetime = 0;
  int marginstart = 0;
  int marginstop = 0;
  bool usevps = false;
  int delmode = 0;
  int delaftercountrecs = 0;
  int delafterdaysoffirstrec = 0;
  std::string blacklistids;
  std::string useassearchtimerfrom;
  std::string useassearchtimerto;
  bool ignoreMissingEPGCats = false;
  bool unmutesoundonswitch = false;
  int comparesummarymatchinpercent = 0;
  int comparedate = 0;
  int nav_back = 1;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%request scope="page">
ExtEPGInfos extEPGInfos;
ChannelGroups channelGroups;
Blacklists blacklists;
RecordingDirs recordingdirs;
SearchTimer* editsearchtimer;
SearchTimer newSearchTimer;
std::string contentsFilter;
</%request>
<%include>page_init.eh</%include>
<{
if (!logged_in && LiveSetup().UseAuth()) {
  cToSvConcat<0> targetUrl = "/login.html?redirect=";
  targetUrl.appendUrlEscaped(request.getQuery());
  return reply.redirect(targetUrl.data());
}
}>
<%cpp>

  if (!cUser::CurrentUserHasRightTo(UR_EDITSTIMERS))
    throw HtmlError( tr("Sorry, no permission. Please contact your administrator!") );

#define SELECTIF(x) reply.out() << ( (x) ? "selected=\"selected\"" : "" );
#define CHECKIF(x) reply.out() << ( (x) ? "checked=\"checked\"" : "" );
#if TNTVERSION >= 30000
const char *TNT_ARRAY = "[]";
#else
const char *TNT_ARRAY = "";
#endif

  // ensure match with VDR settings
  constexpr uint contentGroups = 16;
  constexpr uint contentIdentifiersPerGroup = 16;
  constexpr uint contentIdentifiers = contentGroups * contentIdentifiersPerGroup;

  SearchTimers searchtimers;
  bool testmode = !test.empty();

  tChannelID channelfrom = tChannelID::FromString(channelfrom_string.c_str());
  tChannelID channelto   = tChannelID::FromString(channelto_string.c_str());

  if ( request.getMethod() == "POST") {
    SearchTimer searchtimer;
    if ( !searchtimerid.empty() && !testmode) {
      editsearchtimer = searchtimers.GetByTimerId( searchtimerid );
      if (!editsearchtimer)
        throw HtmlError( tr("Couldn't find search timer. Maybe you mistyped your request?") );
      // duplicate the search timer to preserve yet unknown fields
      searchtimer = *editsearchtimer;
    }

    searchtimer.SetSearch(search);
    searchtimer.SetSearchMode(mode);
    searchtimer.SetTolerance(tolerance);
    searchtimer.SetMatchCase(matchcase);
    searchtimer.SetUseTitle(usetitle);
    searchtimer.SetUseSubtitle(usesubtitle);
    searchtimer.SetUseDescription(usedescr);
    cToSvConcat contentsFilterString;
    if (usecontentids) {
      for (uint groupID = 0; groupID < contentGroups; groupID++) {
        cToSvFormatted<16> useGroupHexID("usegid%x0", groupID);
        if (qparam.has(useGroupHexID.data())) {
          for (uint contentID = 0; contentID < contentIdentifiersPerGroup; contentID++) {
            cToSvFormatted<8> contentHexID("cid%x%x", groupID, contentID);
            if (qparam.has(contentHexID.data())) {
              contentsFilterString.appendFormatted("%x%x", groupID, contentID);
            }
          }
        }
      }
    }
    searchtimer.SetContentsFilter(contentsFilterString.data());
    searchtimer.SetUseExtEPGInfo(useextepginfo);
    if (useextepginfo)
    {
      std::vector<std::string> infos;
      unsigned int i = 0;
      for (ExtEPGInfos::iterator extinfo = extEPGInfos.begin(); extinfo != extEPGInfos.end(); ++extinfo, i++)
      {
      std::stringstream os;
      os << extinfo->Id() << "#" << (i < extepgvalues.size() ? extepgvalues[i] : "");
      infos.push_back(os.str());
      }
      searchtimer.SetExtEPGInfo(infos);
      searchtimer.SetIgnoreMissingEPGCats(ignoreMissingEPGCats);
    }
    searchtimer.SetUseChannel((SearchTimer::eUseChannel)usechannel);
    if (usechannel == SearchTimer::Interval)
    {
      searchtimer.SetChannelMin(channelfrom);
      searchtimer.SetChannelMax(channelto);
    }
    if (usechannel == SearchTimer::Group)
      searchtimer.SetChannelText(changrpsel);

    searchtimer.SetUseTime(usetime);
    if (usetime)
    {
      searchtimer.SetStartTime(timeStringToInt(start_s));
      searchtimer.SetStopTime(timeStringToInt(stop_s));
    }
    searchtimer.SetUseDuration(useduration);
    if (useduration)
    {
      searchtimer.SetMinDuration(durationmin_h * 100 + durationmin_m);
      searchtimer.SetMaxDuration(durationmax_h * 100 + durationmax_m);
    }
    searchtimer.SetUseDayOfWeek(useweekday);
    if (useweekday)
    {
      int dayofweek = 0;
      if (wday_sun) dayofweek |= 0x01;
      if (wday_mon) dayofweek |= 0x02;
      if (wday_tue) dayofweek |= 0x04;
      if (wday_wed) dayofweek |= 0x08;
      if (wday_thu) dayofweek |= 0x10;
      if (wday_fri) dayofweek |= 0x20;
      if (wday_sat) dayofweek |= 0x40;
      searchtimer.SetDayOfWeek(-dayofweek);
    }
    searchtimer.SetUseInFavorites(useinfavorites);
    searchtimer.SetUseAsSearchTimer(useassearchtimer);
    if (useassearchtimer == 2)
    {
      searchtimer.SetUseAsSearchTimerFrom(useassearchtimerfrom, "yyyy-mm-dd");
      searchtimer.SetUseAsSearchTimerTil(useassearchtimerto, "yyyy-mm-dd");
    }
    searchtimer.SetSearchTimerAction(searchtimeraction);
    searchtimer.SetUseSeriesRecording(seriesrecording);
    searchtimer.SetDirectory(directory);
    searchtimer.SetDelRecsAfterDays(delrecafterdays);
    searchtimer.SetKeepRecs(keeprecs);
    searchtimer.SetPauseOnRecs(pauseonrecs);
    searchtimer.SetBlacklistMode(blacklistmode);
    if (blacklistmode == 1)
      searchtimer.ParseBlacklist(blacklistids);
    searchtimer.SetSwitchMinBefore(switchminbefore);
    searchtimer.SetUnmuteSoundOnSwitch(unmutesoundonswitch);
    searchtimer.SetAvoidRepeats(avoidrepeats);
    if (avoidrepeats)
    {
      searchtimer.SetAllowedRepeats(allowedrepeats);
      searchtimer.SetRepeatsWithinDays(repeatswithindays);
      searchtimer.SetCompareTitle(comparetitle);
      searchtimer.SetCompareSubtitle(comparesubtitle);
      searchtimer.SetCompareSummary(comparesummary);
      searchtimer.SetCompareSummaryMatchInPercent(comparesummarymatchinpercent);
      searchtimer.SetCompareDate(comparedate);
    }
    unsigned long catsselected = 0;
    for (unsigned int i = 0; i < avoidrepeatscatselected.size(); i++)
      catsselected |= (1 << (avoidrepeatscatselected[i] - 1));
    searchtimer.SetCompareCategories(catsselected);
    searchtimer.SetPriority(priority);
    searchtimer.SetLifetime(lifetime);
    searchtimer.SetMarginStart(marginstart);
    searchtimer.SetMarginStop(marginstop);
    searchtimer.SetUseVPS(usevps);
    searchtimer.SetDelMode(delmode);
    if (delmode)
    {
      searchtimer.SetDelAfterCountRecs(delaftercountrecs);
      searchtimer.SetDelAfterDaysOfFirstRec(delafterdaysoffirstrec);
    }
    if (!testmode)
    {
      searchtimers.Save(&searchtimer);
</%cpp>
<!DOCTYPE html>
<html>
  <script>
    history.go(<$-nav_back-1$>);
<#  window.location = "searchtimers.html";  #>
  </script>
</html>
<%cpp>
    }
    else
    {
      searchtimer.SetId(0);
      std::string md5 = SearchResults::AddQuery(searchtimer.ToText());
</%cpp>
<!DOCTYPE html>
<html>
  <script>
    window.location = "searchresults.html?searchtimerquery=<$md5$>";
  </script>
</html>
<%cpp>
    }
  }
  SearchTimer* searchtimer;
  if (!searchtimerid.empty()) {
    searchtimer = editsearchtimer = searchtimers.GetByTimerId(searchtimerid);
    if (!searchtimer)
      throw HtmlError( tr("Couldn't find search timer. Maybe you mistyped your request?") );
  } else {
    searchtimer = &newSearchTimer;
  }
  search = searchtimer->Search();
  mode = searchtimer->SearchMode();
  tolerance = searchtimer->Tolerance();
  matchcase = searchtimer->MatchCase();
  usetitle = searchtimer->UseTitle();
  usesubtitle = searchtimer->UseSubtitle();
  usedescr = searchtimer->UseDescription();
  usechannel = searchtimer->UseChannel();
  channelfrom = searchtimer->ChannelMin();
  channelto = searchtimer->ChannelMax();
  if (!channelto.Valid() && channelfrom.Valid())
    channelto = channelfrom;
  if (usechannel == SearchTimer::Group)
    changrpsel = searchtimer->ChannelText();
  usetime = searchtimer->UseTime();
  start_s = intToTimeString(searchtimer->StartTime() );
  stop_s  = intToTimeString(searchtimer->StopTime() );
  useduration = searchtimer->UseDuration();
  if (useduration)
  {
    durationmin_m = searchtimer->MinDuration() % 100;
    durationmin_h = searchtimer->MinDuration() / 100;
    durationmax_m = searchtimer->MaxDuration() % 100;
    durationmax_h = searchtimer->MaxDuration() / 100;
  }
  useweekday = searchtimer->UseDayOfWeek();
  if (useweekday)
  {
    int dayofweek = searchtimer->DayOfWeek();
    if (dayofweek >= 0)
    {
      wday_sun = (dayofweek == 0);
      wday_mon = (dayofweek == 1);
    wday_tue = (dayofweek == 2);
      wday_wed = (dayofweek == 3);
    wday_thu = (dayofweek == 4);
      wday_fri = (dayofweek == 5);
      wday_sat = (dayofweek == 6);
    }
    else
    {
    wday_sun = -dayofweek & 0x01;
    wday_mon = -dayofweek & 0x02;
    wday_tue = -dayofweek & 0x04;
    wday_wed = -dayofweek & 0x08;
    wday_thu = -dayofweek & 0x10;
    wday_fri = -dayofweek & 0x20;
    wday_sat = -dayofweek & 0x40;
    }
  }
  useinfavorites = searchtimer->UseInFavorites();
  useassearchtimer = searchtimer->UseAsSearchTimer();
  if (useassearchtimer == 2)
  {
    useassearchtimerfrom = searchtimer->UseAsSearchTimerFrom("yyyy-mm-dd");
    useassearchtimerto = searchtimer->UseAsSearchTimerTil("yyyy-mm-dd");
  }
  searchtimeraction = searchtimer->SearchTimerAction();
  seriesrecording = searchtimer->UseSeriesRecording();
  directory = searchtimer->Directory();
  delrecafterdays = searchtimer->DelRecsAfterDays();
  keeprecs = searchtimer->KeepRecs();
  pauseonrecs = searchtimer->PauseOnRecs();
  blacklistmode = searchtimer->BlacklistMode();
  switchminbefore = searchtimer->SwitchMinBefore();
  unmutesoundonswitch = searchtimer->UnmuteSoundOnSwitch();
  useextepginfo = searchtimer->UseExtEPGInfo();
  std::vector<std::string> infos = searchtimer->ExtEPGInfo();
  for (unsigned int i = 0; i < extEPGInfos.size(); i++) {
    if (i < infos.size()) {
      cSplit<std::string> parts(infos[i], '#');
      extepgvalues.push_back(parts.size() > 1? *(++parts.begin()):"");
    } else
      extepgvalues.push_back("");
  }
  ignoreMissingEPGCats = searchtimer->IgnoreMissingEPGCats();
  avoidrepeats = searchtimer->AvoidRepeats();
  allowedrepeats =  searchtimer->AllowedRepeats();
  repeatswithindays = searchtimer->RepeatsWithinDays();
  comparetitle = searchtimer->CompareTitle();
  comparesubtitle = searchtimer->CompareSubtitle();
  comparesummary = searchtimer->CompareSummary();
  comparesummarymatchinpercent = searchtimer->CompareSummaryMatchInPercent();
  comparedate = searchtimer->CompareDate();
  contentsFilter = searchtimer->ContentsFilter();     // no part of form, thus camelCase
  for (unsigned int i = 0; i < extEPGInfos.size(); i++)
  {
    bool selected = searchtimer->CompareCategories() & (1<<i);
    avoidrepeatscatselected.push_back(selected);
  }
  priority = searchtimer->Priority();
  lifetime = searchtimer->Lifetime();
  marginstart = searchtimer->MarginStart();
  marginstop = searchtimer->MarginStop();
  usevps = searchtimer->UseVPS();
  delmode = searchtimer->DelMode();
  delaftercountrecs = searchtimer->DelAfterCountRecs();
  delafterdaysoffirstrec = searchtimer->DelAfterDaysOfFirstRec();
</%cpp>
<& pageelems.doc_type &>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>VDR Live - <$ editsearchtimer ? tr("Edit search timer") : tr("New search timer") $></title>

    <& pageelems.stylesheets &>
    <& pageelems.ajax_js &>

    <script type="text/javascript">
    function initform()
    {
      changedsearchmode(document.getElementById("search_mode"));
      changedchannelmode(document.getElementById("channel_mode"));
      changedusetime(document.getElementById("usetime"));
      changeduseduration(document.getElementById("useduration"));
      changeduseweekday(document.getElementById("useweekday"));
      for (let gid = 0; gid < <$ contentGroups $>; gid++ ) {
        const hexID = gid.toString(16) + "0";
        changedusecontentgroup(document.getElementById("usecontentgroup" + hexID));
      }
      changedusecontentids(document.getElementById("usecontentids"));
%     if (extEPGInfos.size() > 0) {
        changeduseextepginfo(document.getElementById("useextepginfo"));
%     }
      changedblacklistmode(document.getElementById("blacklistmode"));
      changeduseassearchtimer(document.getElementById("useassearchtimer"));
      changedavoidrepeats(document.getElementById("avoidrepeats"));
      changedcomparesummary(document.getElementById("comparesummary"));
      changeddelmode(document.getElementById("delmode"));
    }

    function checksearchterm()
    {
      if (document.getElementById("searchterm").value.length <= 3)
        return confirm('<$ tr("Search text too short - use anyway?") $>');
      return true;
    }

    function changedsearchmode(selection)
    {
      const tolerance = document.getElementById("tolerance");
      if (selection.options[selection.selectedIndex].value == 5) {
        tolerance.style.display = "revert-layer";
        tolerance.disabled = false;
      } else {
        tolerance.style.display = "none";
        tolerance.disabled = true;
      }
    }

    function changedchannelmode(selection)
    {
      const value = selection.options[selection.selectedIndex].value;
      document.getElementById("channelinterval").style.display = (value == 1 ? "revert-layer" : "none");
      document.getElementById("channelgroup").style.display = (value == 2 ? "revert-layer" : "none");
    }

    function changedusetime(selection)
    {
      document.getElementById("timesettings").style.display = (selection.checked ? "revert-layer" : "none");
    }

    function changeduseduration(selection)
    {
      const durationSettings = document.getElementById("durationsettings");
      if (selection.checked) {
        durationSettings.style.display = "revert-layer";
        for (const input of durationSettings.getElementsByTagName("input")) {
          input.disabled = false;
        }
      } else {
        durationSettings.style.display = "none";
        for (const input of durationSettings.getElementsByTagName("input")) {
          input.disabled = true;
        }
      }
    }

    function changeduseweekday(selection)
    {
      document.getElementById("weekdaysettings").style.display = (selection.checked ? "revert-layer" : "none");
    }

    function changedusecontentids(selection)
    {
      document.getElementById("use_content_ids").style.display = (selection.checked ? "revert-layer" : "none");
    }

    function changedusecontentgroup(selection)
    {
      if (selection !== null) {
        const gid = selection.id.slice(-2);
        const group = document.getElementById("content_group_" + gid);
        if (group !== null) {
          group.style.display = (selection.checked ? "revert-layer" : "none");
        }
      }
    }

    function changeduseextepginfo(selection)
    {
      const useExtEpgSettings = document.getElementById("use_extepg_settings");
      if (useExtEpgSettings) useExtEpgSettings.style.display = (selection.checked ? "revert-layer" : "none");
    }

    function changedextepginfo(selection)
    {
      const extEpg = selection.id.replace(/_option_.*$/, "_");
      const input = document.getElementById(extEpg + "value");
      input.value = "";
      for (let i = 0; true; i++)
      {
        const option = document.getElementById(extEpg + "option_" + i);
        const label =  document.getElementById(extEpg + "label_" + i);
        if (!option || !label) break;
        if (option.checked)
        {
          if (input.value) input.value += ",";
          input.value += label.innerText;
        }
      }
    }

    function changedblacklistmode(selection)
    {
      document.getElementById("blacklistmodesettings").style.display =
        (selection.options[selection.selectedIndex].value == 1 ? "revert-layer" : "none");
    }

    function changedblacklists(selection)
    {
      const base = selection.id.replace(/_.*$/, "_");
      const input = document.getElementById("blacklistids");
      input.value = "";
      for (let i = 0; true; i++)
      {
        const blacklist = document.getElementById(base + i);
        if (!blacklist) break;
        if (blacklist.checked)
        {
          if (input.value) input.value += "|";
          input.value += blacklist.name.replace(/^.*_(\\d+)$/, "$1");
        }
      }
    }

    function changeduseassearchtimer(selection)
    {
      document.getElementById("searchtimeractionsettings").style.display =
        (selection.options[selection.selectedIndex].value > 0) ? "revert-layer" : "none";
      document.getElementById("useassearchtimeruserdef").style.display =
        (selection.options[selection.selectedIndex].value == 2) ? "revert-layer" : "none";
      changedsearchtimeraction(document.getElementById("searchtimeraction"));
    }

    function changedsearchtimeraction(selection)
    {
      const actionTimerSettings = document.getElementById("searchtimeraction05settings");
      const useAsSearchTimer = document.getElementById("useassearchtimer");
      const searchTimerMode = useAsSearchTimer.options[useAsSearchTimer.selectedIndex].value;
      // settings if action is (in)active timer
      let hidden = false;
      if (searchTimerMode > 0 && ["0", "5"].includes(selection.options[selection.selectedIndex].value)) {
          actionTimerSettings.style.display = "revert-layer";
      } else {
          actionTimerSettings.style.display = "none";
          hidden = true;
      }
      for (const input of actionTimerSettings.getElementsByTagName("input")) {
        if (input.type == "number") input.disabled = hidden;
      }
      changedavoidrepeats(document.getElementById("avoidrepeats"), hidden);
      changeddelmode(document.getElementById("delmode"), hidden);
      // settings if action is channel switching
      const actionAnncouncementSettings = document.getElementById("searchtimeraction23settings");
      const switchMinBefore = document.getElementById("switchminbefore");
      if (searchTimerMode > 0 && ["2", "3"].includes(selection.options[selection.selectedIndex].value)) {
        actionAnncouncementSettings.style.display = "revert-layer";
        switchMinBefore.disabled = false;
      } else {
        actionAnncouncementSettings.style.display = "none";
        switchMinBefore.disabled = true;
      }
    }

    function changeddirselection(selection)
    {
      document.getElementById("directory").value = selection.value;
    }

    function changedavoidrepeats(selection, hidden)
    {
      hidden ||= !selection.checked;
      const avoidRepeatsSettings = document.getElementById("avoidrepeatssettings");
      avoidRepeatsSettings.style.display = (selection.checked ? "revert-layer" : "none");
      for (const input of avoidRepeatsSettings.getElementsByTagName("input")) {
        if (input.type == "number") input.disabled = hidden;
      }
      changedcomparesummary(document.getElementById("comparesummary"), hidden);
    }

    function changedcomparesummary(selection, hidden)
    {
      const summaryMatchInPercent = document.getElementById("summarymatchinpercent");
      const compareSummaryMatchInPercent = document.getElementById("comparesummarymatchinpercent");
      if ((selection.checked && !hidden)) {
        summaryMatchInPercent.style.display =  "revert-layer";
        compareSummaryMatchInPercent.disabled = false;
      } else {
        summaryMatchInPercent.style.display =  "none";
        compareSummaryMatchInPercent.disabled = true;
      }
    }

    function changeddelmode(selection, hidden)
    {
      const delModeRecordings = document.getElementById("delmoderecordings");
      const delAfterCountRecordings = document.getElementById("delaftercountrecs");
      if (selection.value == 1 && !hidden) {
        delModeRecordings.style.display = "revert-layer";
        delAfterCountRecordings.disabled = false;
      } else {
        delModeRecordings.style.display = "none";
        delAfterCountRecordings.disabled = true;
      }
      const delModeDays = document.getElementById("delmodedays");
      const delAfterCountDays = document.getElementById("delafterdaysoffirstrec");
      if (selection.value == 2 && !hidden) {
        delModeDays.style.display = "revert-layer";
        delAfterCountDays.disabled = false;
      } else {
        delModeDays.style.display = "none";
        delAfterCountDays.disabled = true;
      }
    }
    </script>

  </head>
  <body onload="initform()" onpagehide="saveScrollPosition('content')" onpageshow="restoreScrollPosition()">
    <& pageelems.logo &>
    <& menu active=("searchtimers") &>
      <div id="content">
        <div class="spacebar"><# spacer with fade-out effect #></div>
        <form method="post" name="edit_searchtimer" action="edit_searchtimer.ecpp">
          <input type="hidden" name="searchtimerid" value="<$ searchtimerid $>"/>
          <input type="hidden" name="blacklistids" value="<$ blacklistids $>" id="blacklistids"/>
          <input type="hidden" name="nav_back" value="<$ nav_back $>"/>
          <table class="form" cellpadding="0" cellspacing="0">
            <tr class="head">
              <td  class="toprow leftcol rightcol" colspan="2"><div class="boxheader"><div class="caption"><$ editsearchtimer ? tr("Edit search timer") : tr("New search timer") $></div></div></td>
            </tr>

            <!-- Search term -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Search term") $>:</div></td>
              <td class="rightcol"><input type="text" name="search" value="<$ search $>" class="width99" size="55" id="searchterm" /></td>
            </tr>

            <!-- Search mode -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Search mode" ) $>:</div></td>
              <td class="rightcol">
                <div class="options">
                  <select onchange="changedsearchmode(this)" name="mode" size="1" id="search_mode">
                    <option value="0" <{ SELECTIF(mode == 0) }> ><$ tr("phrase") $></option>
                    <option value="1" <{ SELECTIF(mode == 1) }> ><$ tr("all words") $></option>
                    <option value="2" <{ SELECTIF(mode == 2) }> ><$ tr("at least one word") $></option>
                    <option value="3" <{ SELECTIF(mode == 3) }> ><$ tr("match exactly") $></option>
                    <option value="4" <{ SELECTIF(mode == 4) }> ><$ tr("regular expression") $></option>
                    <option value="5" <{ SELECTIF(mode == 5) }> ><$ tr("fuzzy") $></option>
                  </select>
                  <div id="tolerance" style="display: none">
                      <$ tr("Tolerance" ) $>:
                    <input type="number" name="tolerance" size="2" min="1" max="9" value="<$ tolerance $>" />
                  </div>
                </div>
              </td>
            </tr>

            <!-- Match case -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Match case") $>:</div></td>
              <td class="rightcol"><input type="checkbox" name="matchcase" value="1" <{ CHECKIF(matchcase) }> id="matchcase"/></td>
            </tr>

            <!-- Search in -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Search in") $>:</div></td>
              <td class="rightcol"><div class="options">
                <div class="dotted">
                  <input type="checkbox" name="usetitle" value="1" <{ CHECKIF(usetitle) }> />
                  <label for="usetitle"><$ tr("Title") $> </label>
                </div>
                <div class="dotted">
                  <input type="checkbox" name="usesubtitle" value="1" <{ CHECKIF(usesubtitle) }> />
                  <label for="usesubtitle"><$ tr("Episode") $> </label>
                </div>
                <div class="dotted">
                  <input type="checkbox" name="usedescr" value="1" <{ CHECKIF(usedescr) }> />
                  <label for="usedescr"><$ tr("Description") $> </label>
                </div>
              </div></td>
            </tr>

            <!-- Use content IDs -->
<%cpp>
            // collect the defined content IDs
            std::set<std::string> contentStrings;             // for identifying duplicates
            std::vector<uint> contentStringIDs;               // all defined content IDs
            for (uint contentID = 0; contentID < contentIdentifiers; contentID++) {
              const std::string contentDescription = cEvent::ContentToString(contentID);
              if (!contentDescription.empty() && contentStrings.find(contentDescription) == contentStrings.end()) {
                contentStrings.insert(contentDescription);
                contentStringIDs.push_back(contentID);
              }
            }
            // create the indicators of the filtered content IDs (for initializing the check marks)
            bool filteredContentIDs[contentIdentifiers] = { false };
            bool filteredContentGroupIDs[contentGroups] = { false };
            cSv contentFilterIDs = cToSvToLower(contentsFilter);
            for (size_t i = 0; i < contentFilterIDs.length(); i += 2) {
              uint contentID = parse_hex<uint>(contentFilterIDs.substr(i, 2));
              if (contentID < contentIdentifiers) filteredContentIDs[contentID] = true;
              uint groupID = contentID / contentIdentifiersPerGroup;
              if (groupID < contentGroups) filteredContentGroupIDs[groupID] = true;
            }
            if (contentStringIDs.size() > 0) {
</%cpp>
              <tr>
                <td class="label leftcol"><div class="withmargin"><$ tr("Use content categories") $>:</div></td>
                <td class="rightcol">
                  <input type="checkbox" name="usecontentids" value="1" <{ CHECKIF(contentFilterIDs.length() > 0) }> onclick="changedusecontentids(this)" id="usecontentids"/>
                  <div id="use_content_ids" style="display: none">
                    <table class="dependent" border="0" cellspacing="0" cellpadding="0">
                    <# we rely on the uniqueness of the content IDs and that group identifiers are always present #>
%                   for (uint contentID : contentStringIDs) {
%                     uint groupID = contentID / contentIdentifiersPerGroup;
%                     cToSvFormatted<8> hexID("%02x", contentID);
%                     cToSvConcat contentString;
%                     AppendHtmlEscapedAndCorrectNonUTF8(contentString, cEvent::ContentToString(contentID));
%                     contentString.replaceAll("/", "/<wbr>");
                      <# we subsequently deviate from our indentation scheme for better visual tag alignment #>
%                     if (contentID % contentIdentifiersPerGroup == 0) {
%                       if (contentID != contentStringIDs.front()) {
                            </div>
                          </td>
                        </tr>
%                       }
                        <tr>
%                         cToSvConcat contentLabel;
%                         if (groupID == 0xB) {
%                           // this is kind of a "miscellaneous" group, i.e. the first group entry
%                           // does not represent a meaningful group heading (cf. EN 300 468, Table 18)
%                           AppendHtmlEscapedAndCorrectNonUTF8(contentLabel, tr("Special Characteristics"));
%                         } else
%                           contentLabel.append(contentString);
                          <td class="label"><div class="withmargin"><$$ contentLabel $>:</div></td>
                          <td><input type="checkbox" name="usegid<$ hexID $>" value="1" <{ CHECKIF(groupID < contentIdentifiersPerGroup && filteredContentGroupIDs[groupID]) }> onclick="changedusecontentgroup(this)" id="usecontentgroup<$ hexID $>"/>
                            <div class="descriptors options" id="content_group_<$ hexID $>">
%                     }
                              <div class="dotted"><# like in EPGsearch, the groupID is the first item for selection #>
                                <input type="checkbox" name="cid<$ hexID $>" value="1" <{ CHECKIF(contentID < contentIdentifiers && filteredContentIDs[contentID]) }> onclick="" id="cid<$ hexID $>"/>
                                <label for="cid<$ hexID $>"><$$ contentString $></label>
                              </div>
%                   }
%                   if (contentStringIDs.size() > 0) {
                            </div>
                          </td>
                        </tr>
%                   }
                    </table>
                  </div>
                </td>
              </tr>
%           }

%           if (extEPGInfos.size() > 0) {
            <!-- Use ext. EPG categories -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use extended EPG info" ) $>:</div></td>
              <td class="rightcol">
                <input type="checkbox" name="useextepginfo" value="1" <{ CHECKIF(useextepginfo) }> onclick="changeduseextepginfo(this)" id="useextepginfo"/>
                <div id="use_extepg_settings" style="display: none">
                  <table class="dependent" border="0" cellspacing="0" cellpadding="0">
                    <!-- Extended EPG categories -->
%                   int i = 0; for (ExtEPGInfos::iterator extinfo = extEPGInfos.begin(); extinfo != extEPGInfos.end(); ++extinfo, i++) {
                    <tr>
                      <td class="label"><div class="withmargin"><$ extinfo->Name() $>:</div></td>
                      <# EPGsearch returns a one-element list with an empty string for text-type categories #>
%                     bool isTextCategory = extinfo->Values().size() == 0 || (extinfo->Values().size() == 1 && extinfo->Values()[0].empty());
%                     cToSvConcat<16> id("extepg_");
%                     id.appendInt<1>(extinfo->Id());
                      <td>
                        <input type="text" name="extepgvalues<$TNT_ARRAY$>" value="<$extepgvalues[i]$>" size="20" id="<$ id $>_value" <?? !isTextCategory ? " hidden=\"1\" readonly=\"1\"" ?> />
%                       if (!isTextCategory) {
                          <div class="categories options">
%                         for (unsigned int j = 0; j < extinfo->Values().size(); j++) {
                            <div class="dotted">
                              <input type="checkbox" id="<$ id $>_option_<$ j $>" name="<$ id $>_option" value="1" <{ CHECKIF(extinfo->Selected(j, extepgvalues[i])) }> onchange="changedextepginfo(this)" />
                              <label id="<$ id $>_label_<$ j $>" for="<$ id $>_<$ j $>"><$ extinfo->Values()[j] $></label>
                            </div>
%                         }
                          </div>
%                       }
                      </td>
                    </tr>
%                   }

                    <!-- Ignore missing EPG categories -->
                    <tr>
                      <td colspan="2"><div class="options">
                        <div class="dotted">
                          <input type="checkbox" name="ignoreMissingEPGCats" value="1" <{ CHECKIF(ignoreMissingEPGCats) }> />
                          <label for="ignoreMissingEPGCats"><$ tr("Ignore missing EPG info") $> </label>
                          <& tooltip.help text=(tr("When active this can cause very many timers. So please always first test this search before using it as search timer!")) &>
                        </div>
                      </div></td>
                    </tr>
                  </table>
                </div>
              </td>
            </tr>
%           }

            <!-- Use channel -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use channel" ) $>:</div></td>
              <td class="rightcol">
                <select onchange="changedchannelmode(this)" name="usechannel" size="1" id="channel_mode">
                  <option value="0" <{ SELECTIF(usechannel == 0) }> ><$ trVDR("no") $></option>
                  <option value="1" <{ SELECTIF(usechannel == 1) }> ><$ tr("interval") $></option>
                  <option value="2" <{ SELECTIF(usechannel == 2) }> ><$ tr("channel group") $></option>
                  <option value="3" <{ SELECTIF(usechannel == 3) }> ><$ tr("only FTA") $></option>
                </select>

                <div id="channelinterval" style="display: none;">
                  <table class="dependent" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("from channel" ) $>:</div></td>
                      <td><& channels_widget name=("channelfrom_string") channelid=(true) selected=(channelfrom) &></td>
                    </tr>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("to channel" ) $>:</div></td>
                      <td><& channels_widget name=("channelto_string") channelid=(true) selected=(channelto) &></td>
                    </tr>
                  </table>
                </div>

                <div id="channelgroup" style="display: none">
%               if (channelGroups.size() > 0) {
                  <select name="changrpsel" size="1" id="changrpsel">
%                 int i = 0; for (ChannelGroups::iterator changrp = channelGroups.begin(); changrp != channelGroups.end(); ++changrp, i++) {
                    <option value="<$ changrp->Name() $>" <{ SELECTIF(changrpsel == changrp->Name()) }> ><$ changrp->Name() $></option>
%                 }
                  </select>
%               }
                </div>
              </td>
            </tr>

            <!-- Use time -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use time") $>:</div></td>
              <td class="rightcol">
                <input type="checkbox" name="usetime" value="1" <{ CHECKIF(usetime) }> onclick="changedusetime(this)" id="usetime" />
                <div id="timesettings" style="display: none">
                  <table class="dependent" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Start after") $>:</div></td>
                      <td>
                        <input type="time" name="start_s" value="<$ start_s $>" />
                        <& tooltip.help text=(tr("The time the show may start at the earliest")) &>
                      </td>
                    </tr>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Start before") $>:</div></td>
                      <td>
                        <input type="time" name="stop_s" value="<$ stop_s $>" />
                        <& tooltip.help text=(tr("The time the show may start at the latest")) &>
                      </td>
                    </tr>
                  </table>
                </div>
              </td>
            </tr>

            <!-- Use duration -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use duration") $>:</div></td>
              <td class="rightcol">
                <input type="checkbox" name="useduration" value="1" <{ CHECKIF(useduration) }> onclick="changeduseduration(this)" id="useduration" />
                <div id="durationsettings" style="display: none">
                  <table class="dependent" border="0" cellpadding="0" cellspacing="0">
                    <# cannot use time input, as time would be rendered acc. to locale (potentially as 12-hour am/pm) #>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Min. duration") $>:</div></td>
                      <td><input type="number" min="0" max= "23" step="1" size="2" name="durationmin_h" value="<$ durationmin_h $>" /> : <input type="number" min="0" max= "59" step="1" size="2" name="durationmin_m" value="<$ durationmin_m $>" /> </td>
                    </tr>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Max. duration") $>:</div></td>
                      <td><input type="number" min="0" max= "23" step="1" size="2" name="durationmax_h" value="<$ durationmax_h $>" /> : <input type="number" min="0" max= "59" step="1" size="2" name="durationmax_m" value="<$ durationmax_m $>" /> </td>
                    </tr>
                  </table>
                </div>
              </td>
            </tr>

            <!-- Use weekday -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use day of week") $>:</div></td>
              <td class="rightcol">
                <input type="checkbox" name="useweekday" value="1" <{ CHECKIF(useweekday) }> onclick="changeduseweekday(this)" id="useweekday" />
                <div id="weekdaysettings" class="dependent options" style="display: none">
                  <div class="dotted"><input type="checkbox" name="wday_mon" value="1" <{ CHECKIF(wday_mon) }> /> <$ tr("Monday") $></div>
                  <div class="dotted"><input type="checkbox" name="wday_tue" value="1" <{ CHECKIF(wday_tue) }> /> <$ tr("Tuesday") $></div>
                  <div class="dotted"><input type="checkbox" name="wday_wed" value="1" <{ CHECKIF(wday_wed) }> /> <$ tr("Wednesday") $></div>
                  <div class="dotted"><input type="checkbox" name="wday_thu" value="1" <{ CHECKIF(wday_thu) }> /> <$ tr("Thursday") $></div>
                  <div class="dotted"><input type="checkbox" name="wday_fri" value="1" <{ CHECKIF(wday_fri) }> /> <$ tr("Friday") $></div>
                  <div class="dotted"><input type="checkbox" name="wday_sat" value="1" <{ CHECKIF(wday_sat) }> /> <$ tr("Saturday") $></div>
                  <# add class "first" if weekdays shall start with sunday #>
                  <div class="dotted"><input type="checkbox" name="wday_sun" value="1" <{ CHECKIF(wday_sun) }> /> <$ tr("Sunday") $></div>
                </div>
              </td>
            </tr>

            <!-- Use blacklists -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use blacklists" ) $>:</div></td>
              <td class="rightcol">
                <select onchange="changedblacklistmode(this)" name="blacklistmode" size="1" id="blacklistmode">
                  <option value="3" <{ SELECTIF(blacklistmode == 3) }> ><$ trVDR("no") $></option>
                  <option value="0" <{ SELECTIF(blacklistmode == 0) }> ><$ tr("only global") $></option>
                  <option value="1" <{ SELECTIF(blacklistmode == 1) }> ><$ tr("Selection") $></option>
                  <option value="2" <{ SELECTIF(blacklistmode == 2) }> ><$ tr("all") $></option>
                </select>
                <div class="dependent" id="blacklistmodesettings" style="display: none">
%               if (blacklists.size() > 0) {
                  <div class="blacklists options">
%                 int i = 0; for (Blacklists::iterator blacklist = blacklists.begin(); blacklist != blacklists.end(); ++blacklist, i++) {
%                   cToSvConcat<16> id("blacklist_");
%                   id.appendInt<1>(i);
                    <div class="dotted">
                      <input type="checkbox" id="<$ id $>" name="<$ id $>_<$ blacklist->Id() $>" value="1" <{ CHECKIF(searchtimer && searchtimer->BlacklistSelected(blacklist->Id())) }> onchange="changedblacklists(this)" />
                      <label for="<$ id $>"><$ blacklist->Search() $></label>
                    </div>
%                 }
                  </div>
%               }
                </div>
              </td>
            </tr>

            <!-- Use in favorites menu -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use in favorites menu") $>:</div></td>
              <td class="rightcol"><input type="checkbox" name="useinfavorites" value="1" <{ CHECKIF(useinfavorites) }>/></td>
            </tr>

            <!-- Use as search timer -->
            <tr>
              <td class="label leftcol"><div class="withmargin"><$ tr("Use as search timer" ) $>:</div></td>
              <td class="rightcol">
                <div>
                  <select onchange="changeduseassearchtimer(this)" name="useassearchtimer" size="1" id="useassearchtimer">
                    <option value="0" <{ SELECTIF(useassearchtimer == 0) }> ><$ trVDR("no") $></option>
                    <option value="1" <{ SELECTIF(useassearchtimer == 1) }> ><$ trVDR("yes") $></option>
                    <option value="2" <{ SELECTIF(useassearchtimer == 2) }> ><$ tr("user defined") $></option>
                  </select>
                </div>
                <div id="useassearchtimeruserdef" style="display: none">
                  <table class="dependent" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("from date") $>:</div></td>
                      <td><input id="datefrom" name="useassearchtimerfrom" type="date" value="<$ useassearchtimerfrom $>" /></td>
                    </tr>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("to date") $>:</div></td>
                      <td><input id="dateto" name="useassearchtimerto" type="date" value="<$ useassearchtimerto $>" /></td>
                    </tr>
                  </table>
                </div>
                <div id="searchtimeractionsettings" style="display: none">
                  <select onchange="changedsearchtimeraction(this)" name="searchtimeraction" size="1" id="searchtimeraction">
                    <option value="0" <{ SELECTIF(searchtimeraction == 0) }> ><$ tr("Record") $></option>
                    <option value="1" <{ SELECTIF(searchtimeraction == 1) }> ><$ tr("Announce only") $></option>
                    <option value="2" <{ SELECTIF(searchtimeraction == 2) }> ><$ tr("Switch only") $></option>
                    <option value="3" <{ SELECTIF(searchtimeraction == 3) }> ><$ tr("Announce and Switch") $></option>
                    <option value="4" <{ SELECTIF(searchtimeraction == 4) }> ><$ tr("Announce via email") $></option>
                    <option value="5" <{ SELECTIF(searchtimeraction == 5) }> ><$ tr("Inactive Record") $></option>
                  </select>
                </div>
                <div id="searchtimeraction05settings" style="display: none">
                  <table class="dependent" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Series recording") $>:</div></td>
                      <td><input type="checkbox" name="seriesrecording" value="1" <{ CHECKIF(seriesrecording) }>/></td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Directory") $>:</div></td>
                      <td>
                        <div><input type="text" name="directory" id="directory" value="<$ directory $>" class="width99" size="70" /></div>
                        <div><select onchange="changeddirselection(this)" name="recordingdirsselection" size="1" id="recordingdirsselection">
                      <option/>
%                     for (RecordingDirs::iterator rdir = recordingdirs.begin(); rdir != recordingdirs.end(); ++rdir) {
                        <option value="<$ *rdir $>"><$ *rdir $></option>
%                     }
                      </select></div>
                      </td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Delete recordings after ... days") $>:</div></td>
                      <td>
                        <input type="number" min="0" max="99" name="delrecafterdays" id="delrecafterdays" size="6" value="<$ delrecafterdays $>"/>&nbsp;&nbsp;
                        <$ tr("Keep ... recordings") $>:
                        <input type="number" min="0" max="10" name="keeprecs" size="6" value="<$ keeprecs $>"/>
                      </td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Pause when ... recordings exist") $>:</div></td>
                      <td><input type="number" min="0" max="99" name="pauseonrecs" id="pauseonrecs" size="6" value="<$ pauseonrecs $>"/></td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Avoid repeats" ) $>:</div></td>
                      <td><input type="checkbox" name="avoidrepeats" value="1" <{ CHECKIF(avoidrepeats) }> onclick="changedavoidrepeats(this)" id="avoidrepeats"/>
                        <div id="avoidrepeatssettings" style="display: none">
                          <table class="dependent" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td class="label"><div class="withmargin"><$ tr("Allowed repeats") $>:</div></td>
                              <td>
                                <input type="number" min="0" max="10" size="6" name="allowedrepeats" value="<$ allowedrepeats $>" /><span class="withmargin"><$ tr("Only repeats within ... days") $>:</span><input type="number" min="0" max="999" size="6" name="repeatswithindays" value="<$ repeatswithindays $>" />
                              </td>
                            </tr>

                            <tr>
                              <td class="label"><div class="withmargin"><$ tr("Compare title" ) $>:</div></td>
                              <td><input type="checkbox" name="comparetitle" value="1" <{ CHECKIF(comparetitle) }>/>
                            </tr>

                            <tr>
                              <td class="label"><div class="withmargin"><$ tr("Compare subtitle" ) $>:</div></td>
                              <td><select name="comparesubtitle" size="1" id="comparesubtitle">
                                <option value="0" <{ SELECTIF(comparesubtitle == 0) }> ><$ trVDR("no") $></option>
                                <option value="1" <{ SELECTIF(comparesubtitle == 1) }> ><$ trVDR("yes") $></option>
                                <option value="2" <{ SELECTIF(comparesubtitle == 2) }> ><$ tr("if present") $></option></select></td>
                            </tr>

                            <tr>
                              <td class="label"><div class="withmargin"><$ tr("Compare summary" ) $>:</div></td>
                              <td>
                                <input type="checkbox" name="comparesummary" value="1" <{ CHECKIF(comparesummary) }> id="comparesummary" onclick="changedcomparesummary(this)">
                                <# value is restricted in EPGsearch #>
                                <span id="summarymatchinpercent" style="display: none">
                                  <$ tr("Match in percent" ) $>:
                                  <input type="number" min="1" max="100" name="comparesummarymatchinpercent" id="comparesummarymatchinpercent" size="6" value="<$ comparesummarymatchinpercent $>">
                                </span>
                              </td>
                            </tr>
                            <tr>
                              <td class="label"><div class="withmargin"><$ tr("Compare date" ) $>:</div></td>
                              <td><select name="comparedate" size="1" id="comparedate">
                                <option value="0" <{ SELECTIF(comparedate == 0) }> ><$ trVDR("no") $></option>
                                <option value="1" <{ SELECTIF(comparedate == 1) }> ><$ tr("same day") $></option>
                                <option value="2" <{ SELECTIF(comparedate == 2) }> ><$ tr("same week") $></option><
                                <option value="3" <{ SELECTIF(comparedate == 3) }> ><$ tr("same month") $></option></select>
                              </td>
                            </tr>

%                           if (extEPGInfos.size() > 0) {
%                             int i = 0; for (ExtEPGInfos::iterator extinfo = extEPGInfos.begin(); extinfo != extEPGInfos.end(); ++extinfo, i++) {
                                <tr>
                                  <td class="label"><div class="withmargin"><$ tr("Compare" ) $> <$ extinfo->Name() $>:</div></td>
                                  <td><input type="checkbox" name="avoidrepeatscatselected<$TNT_ARRAY$>" value="<$ i+1 $>" <{ CHECKIF(avoidrepeatscatselected[i]) }>/></td>
                                </tr>
%                             }
%                           }
                          </table>
                        </div>
                      </td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ trVDR("Priority") $>:</div></td>
                      <td><input type="number" min="0" max="99" name="priority" size="6" value="<$ priority $>"/></td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ trVDR("Lifetime") $>:</div></td>
                      <td><input type="number" min="0" max="99" name="lifetime" size="6" value="<$ lifetime $>"/></td>
                    </tr>

                    <tr>
                      <# validation may fail upon editing, since EPGsearch does not restrict the value #>
                      <td class="label"><div class="withmargin"><$ trVDR("Setup.Recording$Margin at start (min)") $>:</div></td>
                      <td><input type="number" min="0" max="30" name="marginstart" size="6" value="<$ marginstart $>"/></td>
                    </tr>

                    <tr>
                      <# validation may fail upon editing, since EPGsearch does not restrict the value #>
                      <td class="label"><div class="withmargin"><$ trVDR("Setup.Recording$Margin at stop (min)") $>:</div></td>
                      <td><input type="number" min="0" max="30" name="marginstop" size="6" value="<$ marginstop $>"/></td>
                    </tr>

                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Use VPS") $>:</div></td>
                      <td><input type="checkbox" name="usevps" value="1" <{ CHECKIF(usevps) }>/></td>
                    </tr>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Auto-delete search timer") $>:</div></td>
                      <td>
                        <select onchange="changeddelmode(this)" name="delmode" size="1" id="delmode">
                          <option value="0" <{ SELECTIF(delmode == 0) }> ><$ trVDR("no") $></option>
                          <option value="1" <{ SELECTIF(delmode == 1) }> ><$ tr("based on recordings") $></option>
                          <option value="2" <{ SELECTIF(delmode == 2) }> ><$ tr("based on days") $></option>
                        </select>
                        <div id="delmoderecordings" style="display: none">
                          <span class="label"><$ tr("after ... recordings") $>:</span>
                          <input type="number" min="0" max="999" size="6" name="delaftercountrecs" id="delaftercountrecs" value="<$ delaftercountrecs $>" />
                        </div>
                        <div id="delmodedays" style="display: none">
                          <span class="label"><$ tr("after ... days after first rec.") $>:</span>
                          <input type="number" min="0" max="999" size="6" name="delafterdaysoffirstrec" id="delafterdaysoffirstrec" value="<$ delafterdaysoffirstrec $>" />
                        </div>
                      </td>
                    </tr>
                  </table>
                </div>

                <div id="searchtimeraction23settings" style="display: none">
                  <table class="dependent" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Switch ... minutes before start") $>:</div></td>
                      <td><input type="number" min="0" max="20"  name="switchminbefore" id="switchminbefore" size="6" value="<$ switchminbefore $>"/></td>
                    </tr>
                    <tr>
                      <td class="label"><div class="withmargin"><$ tr("Unmute sound on switch" ) $>:</div></td>
                      <td><input type="checkbox" name="unmutesoundonswitch" value="1" <{ CHECKIF(unmutesoundonswitch) }>/></td>
                     <tr>
                  </table>
                </div>
              </td>
            </tr>

            <!-- Messages and buttons -->
            <tr>
              <td class="buttonpanel leftcol rightcol bottomrow" colspan="2">
                <div class="submission">
                  <div class="warning"><span id="compatibility">
%                 if (searchtimers.begin() != searchtimers.end()) {
%                   if (searchtimers.begin()->HasInsufficientFields()) {
                      <$ tr("The searchtimer lacks some form fields, so that their values cannot be saved. Please upgrade to the most recent version of EPGsearch.") $>
%                   } else if (searchtimers.begin()->HasUnknownFields()) {
                      <$ tr("The searchtimer includes extra fields. These will be saved with their original values.") $>
%                   }
%                 }
                  </span></div>
                  <div class="buttons">
                    <button class="green" type="submit" name="test" value="test" onclick="return checksearchterm();"><$ tr("Test") $></button>
                    <button class="green" type="submit" name="save" onclick="return checksearchterm();"><$ tr("Save") $></button>
                    <button type="button" class="red" onclick="history.go(<$-nav_back$>)"><$ tr("Cancel") $></button>
                  </div>
                </div>
              </td>
            </tr>
          </table>
        </form>
        <div class="spacebar"><# spacer with fade-out effect #></div>
      </div>
  </body>
</html>
<%include>page_exit.eh</%include>
