forked from Panopto/Moodle-2.0-plugin-for-Panopto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panopto_content.php
170 lines (148 loc) · 9.56 KB
/
panopto_content.php
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
<?php
define('AJAX_SCRIPT', true);
require('../../config.php');
require_once("lib/panopto_data.php");
try {
require_login();
require_sesskey();
header('Content-Type: text/html; charset=utf-8');
global $CFG;
$courseid = $_POST["courseid"];
// Sync role mapping. In case this is the first time block is running we need to load old settings from db.
// They will be the default values if this is the first time running.
$mapping = panopto_data::get_course_role_mappings($courseid);
panopto_data::set_course_role_permissions($courseid, $mapping['publisher'], $mapping['creator']);
$content = new stdClass;
//Initialize $content->text to an empty string here to avoid trying to append to it before
//it has been initialized and throwing a warning. Bug 33163
$content->text = "";
// Construct the Panopto data proxy object.
$panoptodata = new panopto_data($courseid);
if (empty($panoptodata->servername) || empty($panoptodata->instancename) || empty($panoptodata->applicationkey)) {
$content->text = get_string('unprovisioned', 'block_panopto') . "
<br/><br/>
<a href='$CFG->wwwroot/blocks/panopto/provision_course_internal.php?id=$courseid'>" . get_string('provision_course_link_text', 'block_panopto'). "</a>";
$content->footer = "";
return $content;
}
try {
if (!$panoptodata->sessiongroupid) {
$content->text = get_string('no_course_selected', 'block_panopto');
} else {
// Get course info from SOAP service.
$courseinfo = $panoptodata->get_course();
// Panopto course was deleted, or an exception was thrown while retrieving course data.
if ($courseinfo->Access == "Error") {
$content->text .= "<span class='error'>" . get_string('error_retrieving', 'block_panopto') . "</span>";
} else {
// SSO form passes instance name in POST to keep URLs portable.
$content->text .= "
<form name='SSO' method='post'>
<input type='hidden' name='instance' value='$panoptodata->instancename' />
</form>";
$content->text .= '<div><b>' . get_string('live_sessions', 'block_panopto') . '</b></div>';
$livesessions = $panoptodata->get_live_sessions();
if (!empty($livesessions)) {
$i = 0;
foreach ($livesessions as $livesession) {
// Alternate gray background for readability.
$altclass = ($i % 2) ? "listItemAlt" : "";
$livesessiondisplayname = s($livesession->Name);
$content->text .= "<div class='listItem $altclass'>
$livesessiondisplayname
<span class='nowrap'>
[<a href='javascript:panopto_launchNotes(\"$livesession->LiveNotesURL\")'
>" . get_string('take_notes', 'block_panopto') . '</a>]';
if ($livesession->BroadcastViewerURL) {
$content->text .= "[<a href='$livesession->BroadcastViewerURL' onclick='return panopto_startSSO(this)'>"
. get_string('watch_live', 'block_panopto') . '</a>]';
}
$content->text .= "
</span>
</div>";
$i++;
}
} else {
$content->text .= '<div class="listItem">'
. get_string('no_live_sessions', 'block_panopto') . '</div>';
}
$content->text .= "<div class='sectionHeader'><b>"
. get_string('completed_recordings', 'block_panopto') . '</b></div>';
$completeddeliveries = $panoptodata->get_completed_deliveries();
if (!empty($completeddeliveries)) {
$i = 0;
foreach ($completeddeliveries as $completeddelivery) {
// Collapse to 3 lectures by default.
if ($i == 3) {
$content->text .= "<div id='hiddenLecturesDiv'>";
}
// Alternate gray background for readability.
$altclass = ($i % 2) ? "listItemAlt" : "";
$completeddeliverydisplayname = s($completeddelivery->DisplayName);
$content->text .= "<div class='listItem $altclass'>
<a href='$completeddelivery->ViewerURL' onclick='return panopto_startSSO(this)'>
$completeddeliverydisplayname
</a>
</div>";
$i++;
}
// If some lectures are hidden, display "Show all" link.
if ($i > 3) {
$content->text .= "</div>";
$content->text .= "<div id='showAllDiv'>";
$content->text .= "[<a id='showAllToggle' href='javascript:panopto_toggleHiddenLectures()'>"
. get_string('show_all', 'block_panopto') . '</a>]';
$content->text .= "</div>";
}
} else {
$content->text .= "<div class='listItem'>" . get_string('no_completed_recordings', 'block_panopto') . '</div>';
}
if ($courseinfo->AudioPodcastURL) {
$content->text .= "<div class='sectionHeader'><b>" . get_string('podcast_feeds', 'block_panopto') . "</b></div>
<div class='listItem'>
<img src='$CFG->wwwroot/blocks/panopto/images/feed_icon.gif' />
<a href='$courseinfo->AudioPodcastURL'>" . get_string('podcast_audio', 'block_panopto') . "</a>
<span class='rssParen'>(</span
><a href='$courseinfo->AudioRssURL' target='_blank' class='rssLink'>RSS</a
><span class='rssParen'>)</span>
</div>";
if ($courseinfo->VideoPodcastURL) {
$content->text .= "
<div class='listItem'>
<img src='$CFG->wwwroot/blocks/panopto/images/feed_icon.gif' />
<a href='$courseinfo->VideoPodcastURL'>" . get_string('podcast_video', 'block_panopto') . "</a>
<span class='rssParen'>(</span
><a href='$courseinfo->VideoRssURL' target='_blank' class='rssLink'>RSS</a
><span class='rssParen'>)</span>
</div>";
}
}
$context = context_course::instance($courseid, MUST_EXIST);
if (has_capability('moodle/course:update', $context)) {
$content->text .= "<div class='sectionHeader'><b>" . get_string('links', 'block_panopto') . "</b></div>
<div class='listItem'>
<a href='$courseinfo->CourseSettingsURL' onclick='return panopto_startSSO(this)'
>" . get_string('course_settings', 'block_panopto') . "</a>
</div>\n";
$systeminfo = $panoptodata->get_system_info();
$content->text .= "<div class='listItem'>
" . get_string('download_recorder', 'block_panopto') . "
<span class='nowrap'>
(<a href='$systeminfo->RecorderDownloadUrl'>Windows</a>
| <a href='$systeminfo->MacRecorderDownloadUrl'>Mac</a>)</span>
</div>";
}
}
}
} catch (Exception $e) {
$content->text .= "<br><br><span class='error'>" . get_string('error_retrieving', 'block_panopto') . "</span>";
}
$content->footer = '';
echo $content->text;
} catch (Exception $e) {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400);
if (isloggedin()) {
header('Content-Type: text/plain; charset=utf-8');
echo $e->getMessage();
}
}