summaryrefslogtreecommitdiff
path: root/pages/edit_timer.ecpp
blob: 28fa096fa9e084671469d90a88f3c038b06916c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<%pre>
#include <sstream>
#include <vdr/config.h>
#include <vdr/i18n.h>
#include <tnt/savepoint.h>
#include "exception.h"
#include "tools.h"
#include "timers.h"

using namespace std;
using namespace vdrlive;

</%pre>
<%args>
timerid;
bool active = true;
channel = "";
title = "";
day = FormatDateTime( "%d", time( 0 ) );
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 start_h = StringToInt( FormatDateTime( "%H", time( 0 ) ) );
int start_m = StringToInt( FormatDateTime( "%M", time( 0 ) ) );
int end_h = StringToInt( FormatDateTime( "%H", time( 0 ) ) );
int end_m = StringToInt( FormatDateTime( "%M", time( 0 ) ) );
bool vps = ::Setup.UseVps;
int priority = ::Setup.DefaultPriority;
int lifetime = ::Setup.DefaultLifetime;
aux = "";
</%args>
<%request scope="global">
std::string pageTitle( tr("Edit timer") );
</%request>
<%cpp>
try {
	ReadLock channelsLock( Channels );
	if ( !channelsLock )
		throw HtmlError( tr("Channels"), tr("Couldn't aquire access to channels, please try again later.") );

	cMutexLock timersLock( &LiveTimerManager() );
	SortedTimers& timers = LiveTimerManager().GetTimers();

	cTimer* timer = 0;
	if ( !timerid.empty() ) {
		timer = timers.GetByTimerId( timerid );
		if ( timer == 0 )
			throw HtmlError( tr("Timers"), tr("Couldn't find channel. Maybe you mistyped your request?") );
	}

	if ( request.getMethod() != "POST" && timer != 0 ) {
		active = timer->Flags() & tfActive;
		channel = *timer->Channel()->GetChannelID().ToString();
		title = timer->File() ? timer->File() : "";
		day = timer->Day() ? FormatDateTime( "%d", timer->Day() ) : "";
		wday_mon = timer->WeekDays() & 0x01;
		wday_tue = timer->WeekDays() & 0x02;
		wday_wed = timer->WeekDays() & 0x04;
		wday_thu = timer->WeekDays() & 0x08;
		wday_fri = timer->WeekDays() & 0x10;
		wday_sat = timer->WeekDays() & 0x20;
		wday_sun = timer->WeekDays() & 0x40;
		start_h = ( timer->Start() / 100 ) % 100;
		start_m = timer->Start() % 100;
		end_h = ( timer->Stop() / 100 ) % 100;
		end_m = timer->Stop() % 100;
		vps = timer->Flags() & tfVps;
		priority = timer->Priority();
		lifetime = timer->Lifetime();
		aux = timer->Aux() ? timer->Aux() : "";
	}

	std::string result;
	if ( request.getMethod() == "POST" ) {
		uint flags = ( active ? tfActive : 0 ) | ( vps ? tfVps : 0 );
		string weekdays = string( wday_mon ? "M" : "-" ) + ( wday_tue ? "T" : "-" ) + ( wday_wed ? "W" : "-" ) 
							  + ( wday_thu ? "T" : "-" ) + ( wday_fri ? "F" : "-" ) + ( wday_sat ? "S" : "-" )
							  + ( wday_sun ? "S" : "-" );
		ostringstream builder;
		builder << flags << ":" << channel << ":" << ( weekdays != "-------" ? weekdays : "" )
				<< ( weekdays == "-------" || day.empty() ? "" : "@" ) << day << ":" << ( start_h * 100 + start_m )
				<< ":" << ( end_h * 100 + end_m ) << ":" << priority << ":" << lifetime << ":" << title << ":" << aux;

		std::string error = LiveTimerManager().UpdateTimer( timer, builder.str() );
		if ( !error.empty() )
			throw HtmlError( tr("Timers"), error );
	}

	tnt::Savepoint spoint( reply );
</%cpp>
<html>
	<head>
		<title>VDR Live - <$ timer ? tr("Edit timer") : tr("New timer") $></title>
		<link rel="stylesheet" type="text/css" href="/styles.css" />
	</head>
	<body>
		<div class="left_area">
			<img src="logo.png" alt="VDR Live!" border="0" />
<& menu >
		</div>
		<div class="inhalt">
			<div class="head_box"><$ timer ? tr("Edit timer") : tr("New timer") $></div>
			<form method="POST" name="edit_timer">
				<input type="hidden" name="timerid" value="<$ timerid $>"/>
				<input type="hidden" name="aux" value="<$ aux $>"/>
				<table class="edit" cellpadding="0" cellspacing="0">
					<tr class="active">
						<td class="label"><$ tr("Active") $>:</td>
						<td>
							<input name="active" value="1" <{ reply.out() << ( active ? "checked=\"checked\"" : "" ); }> type="radio"><$ tr("Yes") $>
							<input name="active" value="0" <{ reply.out() << ( !active ? "checked=\"checked\"" : "" ); }> type="radio"><$ tr("No") $>
						</td>
					</tr>
					<tr>
						<td class="label"><$ tr("Channel") $>:</td>
						<td>
<& channels_widget name=("channel") channelId=(true) selected=(channel) &>
						</td>
					</tr>
					
					<tr class="active">
						<td class="label"><$ tr("Title" ) $>:</td>
						<td><input type="text" name="title" value="<$ title $>" size="80" /></td>
					</tr>
					
					
					<tr>
						<td class="label"><$ tr("Day") $>:</td>
						<td><input type="text" name="day" value="<$ day $>" size="2" maxlength="2" /></td>
					</tr>
					
					<tr class="active">
						<td class="label"><$ tr("Weekday") $>:</td>
						<td>
							<input type="checkbox" name="wday_mon" value="1" <{ reply.out() << ( wday_mon ? "checked=\"checked\"" : "" ); }>/> <$ tr("Monday") $>
							<input type="checkbox" name="wday_tue" value="1" <{ reply.out() << ( wday_tue ? "checked=\"checked\"" : "" ); }>/> <$ tr("Tuesday") $>
							<input type="checkbox" name="wday_wed" value="1" <{ reply.out() << ( wday_wed ? "checked=\"checked\"" : "" ); }>/> <$ tr("Wednesday") $>
							<input type="checkbox" name="wday_thu" value="1" <{ reply.out() << ( wday_thu ? "checked=\"checked\"" : "" ); }>/> <$ tr("Thursday") $>
							<input type="checkbox" name="wday_fri" value="1" <{ reply.out() << ( wday_fri ? "checked=\"checked\"" : "" ); }>/> <$ tr("Friday") $>
							<input type="checkbox" name="wday_sat" value="1" <{ reply.out() << ( wday_sat ? "checked=\"checked\"" : "" ); }>/> <$ tr("Saturday") $>
							<input type="checkbox" name="wday_sun" value="1" <{ reply.out() << ( wday_sun ? "checked=\"checked\"" : "" ); }>/> <$ tr("Sunday") $>
						</td>
					</tr>
					
					<tr>
						<td class="label"><$ tr("Start") $>:</td>
						<td><input type="text" size="2" maxlength="2" name="start_h" value="<$ start_h $>" /> : <input type="text" size="2" maxlength="2" name="start_m" value="<$ start_m $>" /></td>
					</tr>
					
					<tr class="active">
						<td class="label"><$ tr("Stop") $>:</td>
						<td><input type="text" size="2" maxlength="2" name="end_h" value="<$ end_h $>" /> : <input type="text" size="2" maxlength="2" name="end_m" value="<$ end_m $>" /></td>
					</tr>
					
					<tr>
						<td class="label"><$ tr("Use VPS") $>:</td>
						<td><input type="checkbox" name="vps" value="1" <{ reply.out() << ( vps ? "checked=\"checked\"" : "" ); }>/></td>
					</tr>

					<tr class="active">
						<td class="label"><$ tr("Priority") $>:</td>
						<td><input type="text" size="2" maxlength="2" name="priority" value="<$ priority $>" /></td>
					</tr>
					
					<tr>
						<td class="label"><$ tr("Lifetime") $>:</td>
						<td><input type="text" size="2" maxlength="2" name="lifetime" value="<$ lifetime $>" /></td>
					</tr>
					
					<tr class="active">
						<td class="buttonpanel" colspan="2"><button name="submit" type="submit"><$ tr("Save") $></button></td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>
<%cpp>
	spoint.commit();
} catch ( HtmlError const& ex ) {
	cxxtools::QueryParams param = qparam;
	param.add( "errorTitle", ex.GetTitle() );
	param.add( "errorMessage", ex.GetMessage() );
	callComp( "error", request, reply, param );
}
</%cpp>