<%pre>

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

using namespace vdrlive;

</%pre>
<%args>
	// input parameters
	std::string searchtimerid;
	std::string action;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%include>page_init.eh</%include>
<%cpp>
if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
</%cpp>
<%cpp>
	pageTitle = tr("Searchtimers");
	SearchTimers timers;
	if ( !searchtimerid.empty() ) {
		if (action == "toggle")
			timers.ToggleActive(searchtimerid);
		if (action == "delete") {
			if (!cUser::CurrentUserHasRightTo(UR_DELSTIMERS))
				throw HtmlError( tr("Sorry, no permission. Please contact your administrator!") );
			timers.Delete(searchtimerid);
		}
	}
	if (action == "update")
		timers.TriggerUpdate();
</%cpp>
<& pageelems.doc_type &>
<html>
	<head>
		<title>VDR-Live - <$ pageTitle $></title>
		<& pageelems.stylesheets &>
		<& pageelems.ajax_js &>
	</head>
	<body onload="adjustHeader()" onresize="adjustHeader()">
		<& pageelems.logo &>
		<& menu active=("searchtimers") component=("searchtimers.searchtimer_actions")>
		<div class="inhalt">
			<table class="listing" cellspacing="0" cellpadding="0">
				<tr class="head">
					<td colspan="8">
						<div class="boxheader"><div><div><$ pageTitle $></div></div></div>
					</td>
				</tr>
				<tr class="description">
					<td class="action leftcol"><img src="img/transparent.png" alt="" width="16px" height="16px"/></td>
					<td><div class="withmargin"><$ tr("Expression") $></div></td>
					<td><div class="withmargin"><$ tr("Channel") $></div></td>
					<td><div class="withmargin"><$ tr("Starts between") $></div></td>
					<td class="rightcol" colspan="4"/>
				</tr>
<%cpp>
				for (SearchTimers::iterator timer = timers.begin(); timer != timers.end(); ++timer) {
					SearchTimers::iterator nextTimer = timer; ++nextTimer;
					bool bottom = (nextTimer == timers.end());
</%cpp>
				<tr>
					<td class="action leftcol <? bottom ? "bottomrow" ?>"><%cpp> if(timer->UseAsSearchTimer()) { </%cpp><img src="<$ LiveSetup().GetThemedLink("img", "arrow.png") $>" alt=""></img><%cpp> } </%cpp></td>
					<td class="<? bottom ? "bottomrow" ?>"><div class="withmargin"><$ timer->Search() $></div></td>
					<td class="<? bottom ? "bottomrow" ?>"><div class="withmargin"><$ timer->ChannelText() $></div></td>
					<td class="<? bottom ? "bottomrow" ?>"><div class="withmargin"><? timer->UseTime() ? timer->StartTimeFormatted()+" - "+timer->StopTimeFormatted() ?></div></td>
					<td class="action <? bottom ? "bottomrow" ?>"><a href="searchtimers.html?searchtimerid=<$ timer->Id() $>&action=toggle"><img src="<$ LiveSetup().GetThemedLink("img", timer->UseAsSearchTimer() ? "active.png" : "inactive.png") $>" alt="<$ tr("Toggle search timer actions (in)active") $>" <& tooltip.hint text=(tr("Toggle search timer actions (in)active")) &>></img></a></td>
					<td class="action <? bottom ? "bottomrow" ?>"><a href="searchresults.html?searchtimerid=<$ timer->Id() $>"><img src="<$ LiveSetup().GetThemedLink("img", "search.png") $>" alt="<$ tr("Browse search timer results") $>" <& tooltip.hint text=(tr("Browse search timer results")) &>></img></a></td>
					<td class="action <? bottom ? "bottomrow" ?>"><a href="edit_searchtimer.html?searchtimerid=<$ timer->Id() $>"><img src="<$ LiveSetup().GetThemedLink("img", "edit.png") $>" alt="<$ tr("Edit search timer") $>" <& tooltip.hint text=(tr("Edit search timer")) &>></img></a></td>
					<td class="action rightcol <? bottom ? "bottomrow" ?>"><a href="searchtimers.html?searchtimerid=<$ timer->Id() $>&action=delete" onclick="return confirm('<$ tr("Delete this search timer?") $>')"><img src="<$ LiveSetup().GetThemedLink("img", "del.png") $>" alt="<$ tr("Delete search timer") $>" <& tooltip.hint text=(tr("Delete search timer")) &>></img></a></td>
				</tr>
<%cpp>
				}
</%cpp>
				<tr class="spacer">
					<td colspan="8"/>
				</tr>
			</table>
		</div>
	</body>
</html>
<%include>page_exit.eh</%include>

<%def searchtimer_actions>
<a href="edit_searchtimer.html"><$ tr("New search timer") $></a>
<span class="sep">|</span>
<a href="searchtimers.html?action=update"><$ tr("Trigger search timer update") $></a>
</%def>
