<%pre>

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

using namespace vdrlive;
</%pre>
<%args>
  // input parameters

  // form parameters
  bool useextendedsearch = false;
  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;
  int blacklistmode = 3;
  bool useextepginfo = false;
  std::string extepgvalues[];
  std::string blacklistids;
  bool ignoreMissingEPGCats = false;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%request scope="page">
ExtEPGInfos extEPGInfos;
ChannelGroups channelGroups;
Blacklists blacklists;
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>

#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;

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

  if ( request.getMethod() == "POST") {
    SearchTimer searchtimer;

    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.SetBlacklistMode(blacklistmode);
    if (blacklistmode == 1)
      searchtimer.ParseBlacklist(blacklistids);
    searchtimer.SetId(0);
    std::string md5 = SearchResults::AddQuery(searchtimer.ToText());
</%cpp>
<!DOCTYPE html>
<html>
  <script>
    window.location = "searchresults.html?searchtimerquery=<$md5$>";
  </script>
</html>
<%cpp>
  }
  for (unsigned int i = 0; i < extEPGInfos.size(); i++)
    extepgvalues.push_back("");
  usetitle = true;
  usesubtitle = true;
  usedescr = true;
</%cpp>
<& pageelems.doc_type &>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>VDR Live - <$ tr("Search") $></title>
    <& pageelems.stylesheets &>
    <& pageelems.ajax_js &>

    <script type="text/javascript">
    function initform()
    {
      changeduseextendedsearch(document.getElementById("useextendedsearch"));
      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"));
    }

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

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

    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");
        }
      }
    }
    </script>

  </head>
  <body onload="initform()" onpagehide="saveScrollPosition('content')" onpageshow="restoreScrollPosition()">
    <& pageelems.logo &>
    <& menu active=("searchepg") &>
    <div id="content">
      <div class="spacebar"><# spacer with fade-out effect #></div>
      <form method="post" name="searchepg" action="searchepg.ecpp">
        <input type="hidden" name="blacklistids" value="<$ blacklistids $>" id="blacklistids"/>
        <table class="form" cellpadding="0" cellspacing="0">
          <tr class="head">
            <td  class="toprow leftcol rightcol" colspan="2"><div class="boxheader"><div class="caption"><$ tr("Search settings") $></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>
          <tr>
            <td class="label leftcol"><div class="withmargin"><$ tr("Extended search") $>:</div></td>
            <td class="rightcol">
              <input type="checkbox" name="useextendedsearch" value="1" <{ CHECKIF(useextendedsearch) }> onclick="changeduseextendedsearch(this)" id="useextendedsearch"/>
            <div id="extendedsearch" style="display: none">
            <table class="dependent" border="0" cellpadding="0" cellspacing="0">

            <!-- Search mode -->
            <tr>
              <td class="label"><div class="withmargin"><$ tr("Search mode" ) $>:</div></td>
              <td>
                <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"><div class="withmargin"><$ tr("Match case") $>:</div></td>
              <td><input type="checkbox" name="matchcase" value="1" <{ CHECKIF(matchcase) }> id="matchcase"/></td>
            </tr>

            <!-- Search in -->
            <tr>
              <td class="label"><div class="withmargin"><$ tr("Search in") $>:</div></td>
              <td><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"><div class="withmargin"><$ tr("Use content categories") $>:</div></td>
                <td>
                  <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"><div class="withmargin"><$ tr("Use extended EPG info" ) $>:</div></td>
              <td>
                <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"><div class="withmargin"><$ tr("Use channel" ) $>:</div></td>
              <td>
                <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"><div class="withmargin"><$ tr("Use time") $>:</div></td>
              <td>
                <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"><div class="withmargin"><$ tr("Use duration") $>:</div></td>
              <td>
                <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"><div class="withmargin"><$ tr("Use day of week") $>:</div></td>
              <td>
                <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"><div class="withmargin"><$ tr("Use blacklists" ) $>:</div></td>
              <td>
                <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" onchange="changedblacklists(this)" />
                      <label for="<$ id $>"><$ blacklist->Search() $></label>
                    </div>
%                 }
                  </div>
%               }
                </div>
              </td>
            </tr>
            </table>
            </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 search lacks some form fields, so that their values cannot be used for searching the EPG. Please upgrade to the most recent version of EPGsearch.") $>
%                 } else if (searchtimers.begin()->HasUnknownFields()) {
                    <$ tr("The search supports extra fields. These will be not be taken into account.") $>
%                 }
%               }
                </span></div>
                <div class="buttons">
                  <button class="green" type="submit" name="save" onclick="return checksearchterm();"><$ tr("Search") $></button>
                </div>
              </div>
            </td>
          </tr>
        </table>
      </form>
      <div class="spacebar"><# spacer with fade-out effect #></div>
    </div>
  </body>
</html>
<%include>page_exit.eh</%include>
