From 8df6df7272aec371dec9f69a3857ef3e2553129d Mon Sep 17 00:00:00 2001
From: DFNVC <git@vc.dfn.de>
Date: Thu, 8 Feb 2018 11:28:37 +0100
Subject: [PATCH] =?UTF-8?q?Verbesserungen=20und=20Bug-Fixes=20im=20Bereich?=
 =?UTF-8?q?=20Aufzeichnungen:=20Meetings=20k=C3=B6nnen=20nicht=20mehr=20ve?=
 =?UTF-8?q?rsehentlich=20gel=C3=B6scht=20werden,=20falls=20noch=20Aufzeich?=
 =?UTF-8?q?nungen=20enthalten=20sind.=20Neue=20Veranstalter-L=C3=B6schfunk?=
 =?UTF-8?q?tion=20f=C3=BCr=20Aufzeichungen.=20Eine=20Adobe-Connect-Aktivit?=
 =?UTF-8?q?=C3=A4t=20kann=20nicht=20mehr=20erzeugt=20werden,=20wenn=20die?=
 =?UTF-8?q?=20angegebene=20Meeting-URL=20bereits=20existiert.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 delrecording.php         | 36 ++++++++++++++++++++++++++++++++++++
 index.php                |  3 ++-
 lang/de/adobeconnect.php | 17 +++++++++++------
 lang/en/adobeconnect.php | 23 +++++++++--------------
 lib.php                  | 18 +++++++++++-------
 locallib.php             |  3 ++-
 mod_form.php             | 23 +++++++++++++++--------
 renderer.php             | 10 +++++++++-
 version.php              |  2 +-
 9 files changed, 96 insertions(+), 39 deletions(-)
 create mode 100644 delrecording.php

diff --git a/delrecording.php b/delrecording.php
new file mode 100644
index 0000000..85bd359
--- /dev/null
+++ b/delrecording.php
@@ -0,0 +1,36 @@
+<?php
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+require_once(dirname(__FILE__).'/locallib.php');
+require_once(dirname(__FILE__).'/connect_class.php');
+require_once(dirname(__FILE__).'/connect_class_dom.php');
+
+$id         = required_param('id', PARAM_INT);
+$recordingscoid = required_param('recording', PARAM_INT);
+
+global $CFG, $USER, $DB, $PAGE, $OUTPUT;
+
+// Do the usual Moodle setup
+if (! $cm = get_coursemodule_from_id('adobeconnect', $id)) {
+    error('Course Module ID was incorrect');
+}
+$cond = array('id' => $cm->course);
+if (! $course = $DB->get_record('course', $cond)) {
+    error('Course is misconfigured');
+}
+
+$cond = array('id' => $cm->instance);
+if (! $adobeconnect = $DB->get_record('adobeconnect', $cond)) {
+    error('Course module is incorrect');
+}
+require_login($course, true, $cm);
+
+$context = context_module::instance($id);
+$user_is_host = has_capability('mod/adobeconnect:meetinghost', $context);
+
+if ($user_is_host) {
+    $aconnect = aconnect_login();
+    aconnect_remove_meeting($aconnect, $recordingscoid);
+}
+
+redirect('https://moodle.vc.dfn.de/mod/adobeconnect/view.php?id=' . $id);
\ No newline at end of file
diff --git a/index.php b/index.php
index 860c10b..5f5587c 100644
--- a/index.php
+++ b/index.php
@@ -52,7 +52,7 @@ if (! $adobeconnects = get_all_instances_in_course('adobeconnect', $course)) {
 
 $usesections = course_format_uses_sections($course->format);
 if ($usesections) {
-    $sections = get_all_sections($course->id);
+//    $sections = get_all_sections($course->id);
 }
 
 $table = new html_table();
@@ -88,4 +88,5 @@ foreach ($adobeconnects as $adobeconnect) {
 
 echo html_writer::table($table);
 
+
 echo $OUTPUT->footer();
\ No newline at end of file
diff --git a/lang/de/adobeconnect.php b/lang/de/adobeconnect.php
index d129f1f..2d80213 100644
--- a/lang/de/adobeconnect.php
+++ b/lang/de/adobeconnect.php
@@ -61,6 +61,7 @@ $string['presenterlabel'] = 'Moderator';
 $string['recordinghdr'] = 'Meeting-Aufzeichnung';
 $string['record_force'] = 'Meeting-Aufzeichnung erzwingen';
 $string['record_force_desc'] = 'Alle Meetings aufzeichnen. Dies ist eine Einstellung für den gesamten Adobe Connect Server. Der Server muss dazu neu gestartet werden. ';
+$string['record_play'] = 'Aufzeichung abspielen';
 $string['record_convert'] = 'Konvertieren';
 $string['record_convert_help'] = 'Hilfe: Konvertieren von Aufzeichnungen';
 $string['convert_recording_help'] = '<h2>Konvertierung von Adobe Connect Aufzeichnungen</h2>
@@ -74,6 +75,9 @@ Adobe Connect Host zugewiesen werden.
 Die Konvertierungsdauer entspricht immer der Länge der Aufzeichnung, da ein Download<br>
 der Original-Aufzeichnungen unter Adobe Connect nicht möglich ist.
 </p>';
+$string['record_delete'] = 'Aufzeichnung löschen';
+$string['confirm_record_delete'] = 'Wollen Sie die Aufzeichnung "{$a}" wirklich löschen ?';
+$string['recording_error'] = 'Das Meeting kann nicht gelöscht werden, da es noch Aufzeichnungen enthält !';
 
 $string['removeparticipant'] = 'Entfernen';
 $string['removepresenter'] = 'Entfernen';
@@ -123,14 +127,15 @@ $string['error2'] = 'Die Eigenschaft \'{$a}\' is leer. Geben Sie bitte einen Wer
 $string['settingblurb'] = '<p>Dieses Plugin wurde durch den DFN-Verein für den DFNVC Webkonferenz-Dienst modifiziert.<br>
 Es wurde ursprünglich von Remote-Learner und Adobe entwickelt.</p>';
 
-$string['meeturl_help'] = '<p>Sie können die für den Aufbau der Verbidnung zum Meetingraum verwendete URL anpassen. 
-Der Domain-Teil bleibt immer die gleiche (webconf.vc.dfn.de). Nur der Teil nach der Domain kann geändert werden.</p>
+$string['meeturl_help'] = '<p>Sie können die für den Aufbau der Verbidnung zum Meetingraum verwendete URL anpassen.<br>
+Der Domain-Teil bleibt immer die gleiche (webconf.vc.dfn.de). Nur der Teil nach der Domain kann geändert werden.
+</p>
+<p>
+Erlaubt sind nur alphanumerische ASCII-Zeichen und Bindestriche.
+</p>
 
 <p>Beispiele für korrekte URL-Einträge:
-<ul><li>meinmeeting</li><li>/meinmeeting</li></ul>
-
-Nicht korrekte URL-Einträge:
-<ul><li>meinmeeting/meinmeeting</li><li>/meinmeeting/meinmeeting/</li><li>meinmeeting/</li></ul>
+<ul><li>meinmeeting</li><li>mein-meeting</li></ul>
 </p>
 
 <p>Wenn ein Meeting gespeichert wurde, ist es nicht mehr möglich dieses Feld zu ändern. Das Feld wird deaktiviert.
diff --git a/lang/en/adobeconnect.php b/lang/en/adobeconnect.php
index e7bdf88..1bb9cbf 100644
--- a/lang/en/adobeconnect.php
+++ b/lang/en/adobeconnect.php
@@ -62,6 +62,7 @@ $string['presenterlabel'] = 'Presenter';
 $string['recordinghdr'] = 'Meeting Recordings';
 $string['record_force'] = 'Force Meeting Recordings';
 $string['record_force_desc'] = 'Force all Adobe Connect meetings to be recorded.  This is a site wide effect and the Adobe Connect server must be restarted';
+$string['record_play'] = 'Play recording';
 $string['record_convert'] = 'Convert';
 $string['record_convert_help'] = 'Help: Converting Recordings';
 $string['convert_recording_help'] = '<h2>Converting Adobe Connect Recordings</h2>
@@ -75,6 +76,9 @@ the Adobe Connect Host role.<br>
 The conversion duration eqates to the length of the recording becaus it is<br>
 not possible to download the original Adobe Connect recording in advance.
 </p>';
+$string['record_delete'] = 'Delete recording';
+$string['confirm_record_delete'] = 'Do you really want to delete the recroding {$a}?';
+$string['recording_error'] = 'The meeting cannot be deleted because it still contains recordings!';
 
 $string['removeparticipant'] = 'Remove';
 $string['removepresenter'] = 'Remove';
@@ -125,24 +129,15 @@ $string['settingblurb'] = 'Plugin modified by DFN-Verein.
     single-sign-on between the two systems with easy creation and management of Adobe Connect Pro
     meetings.</p>';
 
-$string['meeturl_help'] = '<p>You can customize the URL that is used to connect to the Adobe connect meeting.  The Adobe Server domain will always remain the same.
-  However the last part of the URL can be customized.
-</p>
-<p>For example if the Adobe Connect server domain was located at <b>http://adobe.connect.server/</b>
-  when customizing the URL to <b>mymeeting</b>, the URL to connect to the meeting would be <b>http://adobe.connect.server/mymeeting</b>.  Leave out the trailing forward slash
+$string['meeturl_help'] = '<p>You can customize the URL that is used to connect to the Adobe connect meeting. The Adobe Server domain will always remain the same.<br>
+However the last part of the URL can be customized.</p>
+<p>Only alphanumeric characters and hyphen are allowed.
 </p>
+
 <p>Valid URL entries consists of the name with
 <ul>
 <li>mymeeting</li>
-<li>/mymeeting</li>
-</ul>
-
-Invalid URL entries consist of more than one forward slash:
-<ul>
-<li>mymeeting/mymeeting</li>
-<li>mymeeting/mymeeting/</li>
-<li>mymeeting/mymeeting//anothermeeting</li>
-<li>mymeeting/</li>
+<li>my-meeting</li>
 </ul>
 
 </p>
diff --git a/lib.php b/lib.php
index a7cd260..f2ff723 100644
--- a/lib.php
+++ b/lib.php
@@ -411,20 +411,26 @@ function adobeconnect_update_instance($adobeconnect) {
  */
 function adobeconnect_delete_instance($id) {
     global $DB;
-
+    
     $param = array('id' => $id);
     if (! $adobeconnect = $DB->get_record('adobeconnect', $param)) {
         return false;
     }
 
-    $result = true;
-
-    // Remove meeting from Adobe connect server
     $param = array('instanceid' => $adobeconnect->id);
     $adbmeetings = $DB->get_records('adobeconnect_meeting_groups', $param);
+    $meetingscoid = $DB->get_field('adobeconnect_meeting_groups', 'meetingscoid',$param);
 
+    $aconnect = aconnect_login();
+    if (aconnect_get_recordings($aconnect, $meetingscoid, $meetingscoid)) {
+        $delerror = get_string('recording_error','adobeconnect');
+        print_error($delerror,' ');
+        aconnect_logout($aconnect);        
+        return false;        
+    }
+
+    $result = true;
     if (!empty($adbmeetings)) {
-        $aconnect = aconnect_login();
         foreach ($adbmeetings as $meeting) {
             // Update calendar event
             $param = array('courseid' => $adobeconnect->course, 'instance' => $adobeconnect->id,
@@ -441,10 +447,8 @@ function adobeconnect_delete_instance($id) {
 
         aconnect_logout($aconnect);
     }
-
     $param = array('id' => $adobeconnect->id);
     $result &= $DB->delete_records('adobeconnect', $param);
-
     $param = array('instanceid' => $adobeconnect->id);
     $result &= $DB->delete_records('adobeconnect_meeting_groups', $param);
 
diff --git a/locallib.php b/locallib.php
index 7dba24e..593faa0 100644
--- a/locallib.php
+++ b/locallib.php
@@ -208,10 +208,11 @@ function adobe_connection_test($host = '', $port = 80, $username = '',
                     echo '<p style="color:#680000">XML response:<br />'. htmlspecialchars($aconnectDOM->_xmlresponse). '</p>';		    
 		}
 
+        //
         // Test creating a user
 		// DFNVC
 		//
-                echo '<p><b>Test creating a user:</b></p>';		
+        echo '<p><b>Test creating a user:</b></p>';		
                 $user = new stdClass();
                 $res = preg_split('/@/',$username);
                 $apiuserdomain = $res[1];
diff --git a/mod_form.php b/mod_form.php
index f88d161..e639517 100644
--- a/mod_form.php
+++ b/mod_form.php
@@ -124,12 +124,12 @@ class mod_adobeconnect_mod_form extends moodleform_mod {
 
         // Search for a Meeting with the same starting name.  It will cause a duplicate
         // meeting name (and error) when the user begins to add participants to the meeting
-	// DFNVC
-	//
-	// $meetfldscoid = aconnect_get_folder($aconnect, 'meetings');
-	$meetfldscoid = aconnect_get_meeting_folder($aconnect);
-	//
-	//
+        // DFNVC
+        //
+        // $meetfldscoid = aconnect_get_folder($aconnect, 'meetings');
+        $meetfldscoid = aconnect_get_meeting_folder($aconnect);
+        //
+        //
         $filter = array('filter-like-name' => $data['name']);
         $namematches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter);
 
@@ -137,6 +137,8 @@ class mod_adobeconnect_mod_form extends moodleform_mod {
             $namematches = array();
         }
 
+
+        
         // Now search for existing meeting room URLs
         $url = $data['meeturl'];
         $url = $data['meeturl'] = adobeconnect_clean_meet_url($data['meeturl']);
@@ -147,9 +149,14 @@ class mod_adobeconnect_mod_form extends moodleform_mod {
             $errors['meeturl'] = get_string('invalidadobemeeturl', 'adobeconnect');
         }
 
-        $filter = array('filter-like-url-path' => $url);
+#        $filter = array('filter-like-url-path' => $url);
+#       DFNVC ERROR !!
+#
+        $filter = array('filter-url-path' => "/$url/");        
         $urlmatches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter);
+        #$errors['meeturl'] = 'urlmatches:';
 
+        
         if (empty($urlmatches)) {
             $urlmatches = array();
         } else {
@@ -196,7 +203,7 @@ class mod_adobeconnect_mod_form extends moodleform_mod {
 
             foreach($urlmatches as $matchkey => $match) {
                 $matchurl = rtrim($match->url, '/');
-                if (0 == substr_compare($matchurl, $url . '_', 0, strlen($url . '_'), false)) {
+                if ($matchurl == $url) {
                     $errors['meeturl'] = get_string('duplicateurl', 'adobeconnect');
                 }
             }
diff --git a/renderer.php b/renderer.php
index c8d10a7..f5e4f95 100644
--- a/renderer.php
+++ b/renderer.php
@@ -112,7 +112,7 @@ class mod_adobeconnect_renderer extends plugin_renderer_base {
                     $url = $CFG->wwwroot . '/mod/adobeconnect/joinrecording.php?id=' . $cmid . '&recording='. $recording_scoid . '&groupid='. $groupid . '&sesskey=' . $USER->sesskey;
                     // recording name
                     $name = '<img src="' . $CFG->wwwroot .'/pix/e/insert_edit_video.svg"/>&nbsp;&nbsp;';
-                    $name .= html_writer::link($url, format_string($recording->name), array('target' => '_blank','title'=>'Play Recording'));
+                    $name .= html_writer::link($url, format_string($recording->name), array('target' => '_blank','title'=>get_string('record_play','adobeconnect')));
                     // start date
                     $startdate = format_string($recording->startdate);
                     $time = strtotime($startdate);
@@ -126,10 +126,18 @@ class mod_adobeconnect_renderer extends plugin_renderer_base {
                     // Moodle users with role meeting host can convert recordings on their local Windows PCs
                     $action = '';
                     if ($user_is_host) {
+                        // Konvertieren
                         $converturl = $url . '&convert=true';
                         $param = array('target' => '_blank','title'=>get_string('record_convert','adobeconnect'));
                         $action = html_writer::link($converturl,get_string('record_convert','adobeconnect'),$param);
                         array_push($row, $action);
+                        // Löschen
+                        $delurl = "/mod/adobeconnect/delrecording.php?id=$cmid&recording=$recording_scoid";
+                        $a = $recording->name;
+                        $confirmdel = get_string('confirm_record_delete','adobeconnect',$a);
+                        $param = array('onclick' => "return confirm('$confirmdel')", 'title'=>get_string('record_delete','adobeconnect'));
+                        $del = html_writer::link($CFG->wwwroot . $delurl, '<img alt="' . get_string('record_delete','adobeconnect') . '" src="' . $CFG->wwwroot  .'/pix/t/delete.svg" />', $param);
+                        array_push($row, $del);
                         // Help
                         $param = array('target' => '_blank','title'=>get_string('record_convert_help','adobeconnect'));
                         $help = html_writer::link($CFG->wwwroot . "/help.php?component=adobeconnect&identifier=convert_recording&lang=$COURSE->lang", '<img alt="' . get_string('record_convert_help','adobeconnect') . '" src="' . $CFG->wwwroot  .'/pix/help.svg" />', $param);
diff --git a/version.php b/version.php
index c7d69f3..cfb3fc5 100644
--- a/version.php
+++ b/version.php
@@ -7,7 +7,7 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-$plugin->version  = 2016011800;  // The current module version (Date: YYYYMMDDXX)
+$plugin->version  = 2018020800;  // The current module version (Date: YYYYMMDDXX)
 $plugin->requires  = 2014051212; // Requires this Moodle version
 $plugin->component = 'mod_adobeconnect';
 $plugin->cron     = 0;           // Period for cron to check this module (secs)
-- 
GitLab