summaryrefslogtreecommitdiff
path: root/pages/multischedule.ecpp
blob: ab97d9b1b04ecc8395067953e04ef7957afe416b (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
<%pre>
#include <vdr/plugin.h>
#include <vdr/channels.h>
#include <vdr/epg.h>
#include <vdr/config.h>
#include <vdr/device.h>
#include "exception.h"
#include "livefeatures.h"
#include "setup.h"
#include "tools.h"
#include "epg_events.h"
#include "i18n.h"

using namespace std;
using namespace vdrlive;

struct SchedEntry {
	string title;
	string short_description;
	string description;
	string start;
	string end;
	string day;
	string epgid;
	int start_row;
	int row_count;
};

</%pre>
<%args>
	int channel = -1;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%request scope="page">
	cChannel* Channel;
</%request>
<%include>page_init.eh</%include>
<%cpp>
if (!logged_in && LiveSetup().UseAuth()) return reply.redirect("login.html");
</%cpp>
<%cpp>
	pageTitle = trVDR("Schedule");

	cSchedulesLock schedulesLock;
	cSchedules const* schedules = cSchedules::Schedules( schedulesLock );

	ReadLock channelsLock( Channels );
	if ( !channelsLock )
		throw HtmlError( tr("Couldn't aquire access to channels, please try again later.") );

	// cChannel* Channel; (see %request above)
	if ( channel > 0 ) {
		Channel = Channels.GetByNumber( channel );
	}
	else {
		if (cDevice::CurrentChannel()) {
			Channel = Channels.GetByNumber(cDevice::CurrentChannel());
		}
		else {
			Channel = Channels.Get( Channels.GetNextNormal( -1 ) );
		}
	}
	if ( Channel == 0 )
		throw HtmlError( tr("Couldn't find channel or no channels available. Maybe you mistyped your request?") );

	cSchedule const* Schedule = schedules->GetSchedule( Channel );
</%cpp>
<& pageelems.doc_type &>
<html>
	<head>
		<title>VDR Live - <$ pageTitle $></title>
		<& pageelems.stylesheets &>
		<& pageelems.ajax_js &>
	</head>
	<body>
		<& pageelems.logo &>
		<& menu active=("multischedule") component=("schedule.channel_selection") &>
		<div class="inhalt">
<%cpp>
	if ( Schedule == 0 ) {
</%cpp>
			<$ tr("No schedules available for this channel") $>.
<%cpp>
	}
	else {
		time_t now = time(NULL) - ::Setup.EPGLinger * 60;
		time_t sched_start = 3600 * (now / 3600); // start at a full hour
		// tChannelID channel_id(Channel->GetChannelID());
		// int evntNr = 0;
#define MAX_CHANNELS 5
#define MAX_EVENTS 200
#define MINUTES_PER_ROW 6
		SchedEntry table[MAX_CHANNELS][MAX_EVENTS];
		int prev_row = -1;
		int count = 0;
		for (const cEvent *Event = Schedule->Events()->First(); Event && count < MAX_EVENTS; 
				Event = Schedule->Events()->Next(Event)) {
			if (Event->EndTime() <= sched_start )
				continue;

			EpgInfoPtr epgEvent = EpgEvents::CreateEpgInfo(Channel, Event);
			SchedEntry &en=table[0][count];

			en.title = epgEvent->Title();
			en.short_description = epgEvent->ShortDescr();
			en.description = epgEvent->LongDescr();
			en.start = epgEvent->StartTime(tr("%I:%M %p"));
			en.end = epgEvent->EndTime(tr("%I:%M %p"));
			en.day = epgEvent->StartTime(tr("%A, %b %d %Y"));
			en.epgid = EpgEvents::EncodeDomId(Channel->GetChannelID(), Event->EventID());
			// string strEventID = lexical_cast<string>(Event->EventID();

			en.start_row = prev_row > 0 ? prev_row : 0;
			prev_row = en.start_row;
			int end_time = Schedule->Events()->Next(Event) ? 
				Schedule->Events()->Next(Event)->StartTime() :
				Event->EndTime();
			int next_event_start_row = (end_time - sched_start) / 60 / MINUTES_PER_ROW;
			en.row_count = next_event_start_row - en.start_row;
			if ( en.row_count < 2 )
				en.row_count = 2;
			prev_row = en.start_row + en.row_count;
			count++;
		};
</%cpp>
		<table class="listing" cellspacing="0" cellpadding="0">
<%cpp>
		time_t sched_end = sched_start + 60 * 60 * 12; // 12 hr
		int sched_end_row = ( sched_end - sched_start ) / 60 / MINUTES_PER_ROW;
		int cur_event = 0;
		for (int row = 0 ; row < sched_end_row; row++ )
		{

</%cpp>
		       <tr class=" topaligned ">
		       <td>
<%cpp>
			if ( (sched_start +  row * 60 * MINUTES_PER_ROW ) % 3600 == 0 )
			{
</%cpp>
		       <$ FormatDateTime( tr("%I:%M %p"), sched_start +  row * 60 * MINUTES_PER_ROW )  $>
<%cpp>
			}
			else
			{
</%cpp>
			 &nbsp;
<%cpp>
			}
</%cpp>
		       </td>
<%cpp>
			if ( table[0][cur_event].start_row == row )
			{
				SchedEntry &en=table[0][cur_event];
				bool truncated = false;
</%cpp>
			<td class="topaligned leftcol rightcol" rowspan="<$ en.row_count $>">
			  <div class="more withmargin"><a <& tooltip.hint text=(StringEscapeAndBreak(StringWordTruncate(en.description, 300, truncated)) + "<br />" + tr("Click to view details.")) &>><span class="title"><$ en.title $></span><br /><span class="short"><$ en.short_description.empty() ? "&nbsp;" : en.short_description $></span></a><$ en.start + "-" + en.end $></div></td>
<%cpp>
				cur_event++;
			}
</%cpp>
		       </tr>
<%cpp>
		}
</%cpp>
			</table>
<%cpp>
	}
</%cpp>
		</div>
	</body>
</html>
<%include>page_exit.eh</%include>

<%def channel_selection>
<form action="multischedule.html" method="get" id="channels">
   <span>
     <label for="channel"><$ tr("Channel") $>:&nbsp;<span class="bold"><$ Channel->Number() $></span></label>
     <& channels_widget name=("channel") selected=(Channel ? *Channel->GetChannelID().ToString() : "") onchange=("document.forms.channels.submit()") &>
     <& pageelems.ajax_action_href action="switch_channel" tip=(tr("Switch to this channel.")) param=(Channel->GetChannelID()) image="zap.png" alt="" &>
     <& pageelems.vlc_stream_channel channelId=(Channel->GetChannelID()) &>
   </span>
</form>
</%def>