From c986de8a41e03252e643d2d06e2278388822c59a Mon Sep 17 00:00:00 2001
From: Peter Fricke <peter.fricke@hs-hannover.de>
Date: Fri, 14 Sep 2018 09:04:39 +0200
Subject: [PATCH] init

---
 contact.php                        |   5 +-
 contact_form.php                   |  30 +++++----
 lang/de/local_contactform.php      |  19 +++---
 lang/en/local_contactform.php      |  33 +++++-----
 lib.php                            |  30 +++++++--
 module.js                          |   3 -
 participants_export_form.php       |  50 ++++++++++++++
 participants_export_xls_groups.php | 102 +++++++++++++++++++++++++++++
 8 files changed, 217 insertions(+), 55 deletions(-)
 create mode 100644 participants_export_form.php
 create mode 100644 participants_export_xls_groups.php

diff --git a/contact.php b/contact.php
index daceff0..61c9c64 100644
--- a/contact.php
+++ b/contact.php
@@ -61,11 +61,8 @@ $PAGE->requires->js_init_call('M.local_contactform.init',
     $jsdata,
     false,
     $jsmodule);
-<<<<<<< HEAD
-$PAGE->requires->strings_for_js(array('contacttoelc','recording','clicker','moodle','loncapa','evaexam','eexam','training', 'other','improvement','technical','usercreate','loginprob','pleasechoose','dataloss'),'local_contactform');
-=======
+
 $PAGE->requires->strings_for_js(array('contacttoelc','recording','clicker','moodle','loncapa','evaexam','eexam','training', 'other','improvement','technical','usercreate','userdelete','coursedelete','loginprob','pleasechoose','dataloss'),'local_contactform');
->>>>>>> hsh/develop
 echo $OUTPUT->header();
 echo $OUTPUT->heading($strtitle);
 // Show the request form.
diff --git a/contact_form.php b/contact_form.php
index 7925ea3..523e8ce 100644
--- a/contact_form.php
+++ b/contact_form.php
@@ -46,11 +46,10 @@ class contact_form extends moodleform {
         $values = array(get_string('improvement', 'local_contactform') => get_string('improvement', 'local_contactform'),
             get_string('technical', 'local_contactform') => get_string('technical', 'local_contactform'),
             get_string('usercreate', 'local_contactform') => get_string('usercreate', 'local_contactform'),
-<<<<<<< HEAD
-=======
+
             get_string('userdelete', 'local_contactform') => get_string('userdelete', 'local_contactform'),
             get_string('coursedelete', 'local_contactform') => get_string('coursedelete', 'local_contactform'),
->>>>>>> hsh/develop
+
             get_string('loginprob', 'local_contactform') => get_string('loginprob', 'local_contactform'),
             get_string('dataloss', 'local_contactform') => get_string('dataloss', 'local_contactform'));
         sort($values);
@@ -68,7 +67,7 @@ class contact_form extends moodleform {
             $mform->setDefault('telephone', $USER->phone1);
         }
         if (!empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey)) {
-            $mform->addElement('recaptcha', 'recaptcha_element', 'style="margin: 10em"');
+			$mform->addElement('recaptcha', 'recaptcha_element', get_string('security_question', 'auth'), array('https' => $CFG->loginhttps),'style="margin: 10em"');
 
         }
 
@@ -77,6 +76,7 @@ class contact_form extends moodleform {
     }
 
     function validation($data, $files) {
+        global $CFG;
         if(empty($data["lastname"])){
             $errors['lastname'] = get_string('missinglastname');
         }
@@ -89,16 +89,18 @@ class contact_form extends moodleform {
         if (! validate_email($data['email'])) {
             $errors['email'] = get_string('invalidemail');
         }
-        $recaptcha_element = $this->_form->getElement('recaptcha_element');
-        if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
-            $challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
-            $response_field = $this->_form->_submitValues['recaptcha_response_field'];
-            if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
-                $errors['recaptcha'] = $result;
-            }
-        } else {
-            $errors['recaptcha'] = get_string('missingrecaptchachallengefield');
-        }
+		if (!empty($CFG->recaptchapublickey) && !empty($CFG->recaptchaprivatekey)) {
+			$recaptcha_element = $this->_form->getElement('recaptcha_element');
+			if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
+				$challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
+				$response_field = $this->_form->_submitValues['recaptcha_response_field'];
+				if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
+					$errors['recaptcha_element'] = $result;
+				}
+			} else {
+				$errors['recaptcha_element'] = get_string('missingrecaptchachallengefield');
+			}
+		}
         return $errors;
     }
 
diff --git a/lang/de/local_contactform.php b/lang/de/local_contactform.php
index 2f635e2..be72f64 100644
--- a/lang/de/local_contactform.php
+++ b/lang/de/local_contactform.php
@@ -40,17 +40,11 @@ $string['recording'] = 'Vorlesungsaufzeichnung';
 $string['dataloss'] = 'Datenverlust';
 $string['loginprob'] = 'Loginprobleme';
 $string['usercreate'] = 'Nutzeranlegung';
-<<<<<<< HEAD
-$string['technical'] = 'Technisches Problem';
-$string['improvement'] = 'Verbesserungsvorschlag';
-$string['course'] = 'Moodle course';
-=======
 $string['userdelete'] = 'Nutzerlöschung';
 $string['technical'] = 'Technisches Problem';
 $string['improvement'] = 'Verbesserungsvorschlag';
 $string['course'] = 'Moodle Kurs';
 $string['coursedelete'] = 'Moodle Kurslöschung';
->>>>>>> hsh/develop
 $string['submit'] = 'Abschicken';
 $string['confirmrequest'] = 'Ihre Anfrage wurde zum zuständigen Support-Team weitergeleitet. In Kürze wird sich jemand mit Ihnen in Verbindung setzen.';
 
@@ -61,8 +55,8 @@ $string['fullnamecourse'] = 'Vollst&auml;ndiger Kurstitel';
 $string['fullnamecourse_help'] = 'Der vollst&auml;ndige Kurstitel wird auf jeder Kursseite oben und in der Kurs&uuml;bersicht angezeigt.';
 $string['shortnamecourse'] = 'Gek&uuml;rzter Kurstitel';
 $string['shortnamecourse_help'] = 'Der gek&uuml;rzte Kurstitel wird immer dann verwendet, wenn der vollst&auml;ndige Kurstitel zu lang w&auml;re (z.B. in der Navigation oder in der Betreffzeile von E-Mails).';
-$string['enrolmentkey'] = 'Kurspasswort';
-$string['enrolmentkey_help'] = 'Mit dem Kurspasswort gelangen Studierende in den Kurs. Bitte tragen Sie hier eine Zeichenfolge ein, welche weder im vollst&auml;ndigen Kurstitel, im gek&uuml;rzten Kurstitel oder in der Kursbeschreibung enthalten ist.';
+$string['enrolmentkey'] = 'Einschreibeschl&uuml;ssel';
+$string['enrolmentkey_help'] = 'Mit dem Einschreibeschl&uuml;ssel gelangen Studierende in den Kurs. Bitte tragen Sie hier eine Zeichenfolge ein, welche weder im vollst&auml;ndigen Kurstitel, im gek&uuml;rzten Kurstitel oder in der Kursbeschreibung enthalten ist.';
 $string['wrongcategory'] = 'Es ist leider nicht erlaubt diese Kategorie auszuw&auml;hlen.';
 $string['containspassword'] = 'Der {$a} und das Kurspasswort haben zu starke &Auml;hnlichkeit. Bitte vergeben Sie ein anderes Kurspasswort!';
 $string['reason'] = 'Grund';
@@ -106,7 +100,7 @@ $string['courseapprovedemail2'] = '
 
 Zum neuen Kurs gelangen Sie über {$a->url}.
 
-Bei Rückfragen zur Nutzung der Moodle Plattform beraten wir Sie gerne telefonisch oder per E-Mail elc@hs-hannover.de.
+Bei Rückfragen zur Nutzung der Moodle Plattform beraten wir Sie gerne telefonisch oder per <a href="mailto:elc@hs-hannover.de>E-Mail</a>.
 Sie wünschen eine persönliche Beratung zu Moodle oder anderen E-Learning Werkzeugen? Gerne vereinbaren wir einen individuellen Termin.
 ';
 $string['courseapprovedemailfooter'] = 'Mit freundlichen Grüßen
@@ -117,5 +111,10 @@ $string['courseapprovedemailfooter'] = 'Mit freundlichen Grüßen
 ';
 $string['courseapprovedsubject'] = 'Der beantragte Kurs, "{$a->coursename}", wurde angelegt.';
 
-$string['courserequestsuccess'] = 'Ihr Kursantrag wurde an das E-Learning Center übertragen und wird so schnell wie möglich (i.d.R. in den nächsten drei Werktagen) bearbeitet. Sie werden umgehend per E-Mail über die Freischaltung informiert. Bei zeitkritischen Anträgen oder Nachfragen wenden Sie sich bitte an: elc@hs-hannover.de oder nutzen Sie unser Kontaktformular. https://moodle.hs-hannover.de/local/contactform/contact.php';
+$string['courserequestsuccess'] = 'Ihr Kursantrag wurde an das E-Learning Center übertragen und wird so schnell wie möglich (i.d.R. in den nächsten drei Werktagen) bearbeitet. Sie werden umgehend per per <a href="mailto:elc@hs-hannover.de>E-Mail</a> über die Freischaltung informiert. Bei zeitkritischen Anträgen oder Nachfragen wenden Sie sich bitte an: <a href="mailto:elc@hs-hannover.de>elc@hs-hannover.de</a> oder nutzen Sie unser <a href="https://moodle.hs-hannover.de/local/contactform/contact.php">Kontaktformular</a>.';
 $string['coursespending'] = 'Ihre beantragten Kurse (Freischaltung in Arbeit)';
+
+
+// Export Module
+
+$string['navigationtext'] = 'Teilnehmer*innen als Liste (Excel)';
diff --git a/lang/en/local_contactform.php b/lang/en/local_contactform.php
index 78362e6..d087e95 100644
--- a/lang/en/local_contactform.php
+++ b/lang/en/local_contactform.php
@@ -39,17 +39,11 @@ $string['recording'] = 'Video recording of courses';
 $string['dataloss'] = 'Data loss';
 $string['loginprob'] = 'Login problems';
 $string['usercreate'] = 'User creation';
-<<<<<<< HEAD
-$string['technical'] = 'Technical problem';
-$string['improvement'] = 'Suggestion for improvement';
-$string['course'] = 'Moodle course';
-=======
 $string['userdelete'] = 'User deletion';
 $string['technical'] = 'Technical problem';
 $string['improvement'] = 'Suggestion for improvement';
 $string['course'] = 'Moodle course';
 $string['coursedelete'] = 'Moodle course deletion';
->>>>>>> hsh/develop
 $string['submit'] = 'Submit';
 $string['confirmrequest'] = 'Your request has been mailed to our support team. Our supporter will become connected with you.';
 
@@ -103,7 +97,7 @@ $string['coursecopyinform'] = 'INFORMATION: If you have requested an import of c
 $string['courseapprovedemail2'] = '
 Please click the following link to access your course {$a->url}.
 
-In case of questions regarding the moodle platform please get in touch with the ELC Team at Hochschule Hannover. We are happy to help via elc@hs-hannover.de or in a quick phone call.
+In case of questions regarding the moodle platform please get in touch with the ELC Team at Hochschule Hannover. We are happy to help via <a href="mailto:elc@hs-hannover.de>e-mail</a> or in a quick phone call.
 If you need any further assistance or training for Moodle or other E-Learning tools don\'t hesitate to make an individual appointment.
 
  ';
@@ -113,25 +107,30 @@ If you need any further assistance or training for Moodle or other E-Learning to
 
 $string['courseapprovedemailfooter'] = 'Best regards
 
-
 {$a->responser}
 {$a->email}
 {$a->telefon}
+
 ';
 $string['courseapprovedemailfooter2'] = 'Hochschule Hannover
-University of Applied Sciences and Arts
-ZSW - E-Learning Center
-Expo Plaza 12
-30539 Hannover
+    University of Applied Sciences and Arts
+    ZLB - E-Learning Center
+    Expo Plaza 3
+    30539 Hannover
 
-Raum 3.59: Herr Dr. Tjettmers, Frau Chukhlova, Frau Müller
-Raum 3.61: Herr Saatze, Herr Werner
+Raum 5.21: Herr Dr. Tjettmers
+Raum 5.28: Frau Chukhlova, Frau Kirchberg, Frau Müller
+Raum 5.27: Herr Reiser, Herr Fricke
 
-E-Mail: elc@hs-hannover.de
-Tel.: ++49 (511) 9296-2655
+E-Mail: <a href="mailto:elc@hs-hannover.de>elc@hs-hannover.de</a>
+Tel.: ++49 (511) 9296-2777
 Fax: ++49 (511) 9296-2603';
 
 $string['courseapprovedsubject'] = 'Your course {$a->coursename} has been approved.';
 
-$string['courserequestsuccess'] = 'Ihr Kursantrag wurde an das E-Learning Center übertragen und wird so schnell wie möglich (i.d.R. in den nächsten drei Werktagen) bearbeitet. Sie werden umgehend per E-Mail über die Freischaltung informiert. Bei zeitkritischen Anträgen oder Nachfragen wenden Sie sich bitte an: elc@hs-hannover.de oder nutzen Sie unser Kontaktformular. https://moodle.hs-hannover.de/local/contactform/contact.php';
+$string['courserequestsuccess'] = 'Ihr Kursantrag wurde an das E-Learning Center übertragen und wird so schnell wie möglich (i.d.R. in den nächsten drei Werktagen) bearbeitet. Sie werden umgehend per E-Mail über die Freischaltung informiert. Bei zeitkritischen Anträgen oder Nachfragen wenden Sie sich bitte an: <a href="mailto:elc@hs-hannover.de>elc@hs-hannover.de</a> oder nutzen Sie unser <a href="https://moodle.hs-hannover.de/local/contactform/contact.php">Kontaktformular</a>.';
 $string['coursespending'] = 'Ihre beantragten Kurse (Freischaltung in Arbeit)';
+
+// Export Module
+
+$string['navigationtext'] = 'Excel export';
\ No newline at end of file
diff --git a/lib.php b/lib.php
index 329751f..e8f2f21 100644
--- a/lib.php
+++ b/lib.php
@@ -1,13 +1,14 @@
 <?php
+
 /**
  * Created by PhpStorm.
  * User: wernerpe
  * Date: 21.01.2015
  * Time: 10:45
  */
-require_once($CFG->libdir.'/moodlelib.php');
-class contactform{
+require_once($CFG->libdir . '/moodlelib.php');
 
+class contactform {
 
     public static function create($eventdata) {
         global $CFG;
@@ -19,22 +20,37 @@ class contactform{
         } else if ($eventdata->contacttoselect == 0) {
             $formatted_subject .= "[Moodle] ";
         }
-		
+
         $formatted_subject .= $eventdata->subject;
 
         $message = 'Sehr geehrtes E-Learning Center, <br /><br />';
-        $message .= "\n".$eventdata->message.'<br /><br />';
+        $message .= "\n" . $eventdata->message . '<br /><br />';
         $message .= 'Mit freundlichen Gr&uuml;&szlig;en <br />';
-        $message .= $eventdata->firstname.' '.$eventdata->lastname.'<br />';
-        $message .= 'Telefon: '.$eventdata->telephone;
+        $message .= $eventdata->firstname . ' ' . $eventdata->lastname . '<br />';
+        $message .= 'Telefon: ' . $eventdata->telephone;
 
         $mail->Subject = $formatted_subject;
         $mail->Body = $message;
         $mail->AltBody = $message;
         $mail->From = $eventdata->email;
-        $mail->FromName = $eventdata->lastname.", ".$eventdata->firstname;
+        $mail->FromName = $eventdata->lastname . ", " . $eventdata->firstname;
         $mail->addAddress("elc@hs-hannover.de");
         $mail->send();
         return $mail;
     }
+
+}
+
+function local_contactform_extend_navigation_course(navigation_node $parentnode, stdClass $course, context_course $context) {
+    if (has_capability('moodle/grade:export', $context)) {
+        $strfoo = get_string('navigationtext', 'local_contactform');
+        $url = new moodle_url('/local/contactform/participants_export_form.php', array('id' => $course->id));
+        $settingsnode = navigation_node::create(
+               $strfoo, $url, navigation_node::NODETYPE_LEAF, 'contactform', 'contactform', new pix_icon('i/export', $strfoo));
+        $reportnode = $parentnode->get('users');
+        if (isset($settingsnode) && !empty($reportnode)) {
+            $reportnode->add_node($settingsnode);
+        }
+    }
 }
+
diff --git a/module.js b/module.js
index 78bdd3a..f9f1abd 100644
--- a/module.js
+++ b/module.js
@@ -12,11 +12,8 @@ M.local_contactform = {
         moodlestrings.push(M.util.get_string('dataloss','local_contactform'));
         moodlestrings.push(M.util.get_string('loginprob','local_contactform'));
         moodlestrings.push(M.util.get_string('usercreate','local_contactform'));
-<<<<<<< HEAD
-=======
         moodlestrings.push(M.util.get_string('userdelete','local_contactform'));
         moodlestrings.push(M.util.get_string('coursedelete','local_contactform'));
->>>>>>> hsh/develop
         moodlestrings.push(M.util.get_string('technical','local_contactform'));
         moodlestrings.push(M.util.get_string('improvement','local_contactform'));
         moodlestrings.sort();
diff --git a/participants_export_form.php b/participants_export_form.php
new file mode 100644
index 0000000..bc37c83
--- /dev/null
+++ b/participants_export_form.php
@@ -0,0 +1,50 @@
+<?php
+
+/* 
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+require_once '../../config.php';
+require_once $CFG->dirroot.'/grade/export/lib.php';
+require_once 'participants_export_xls_groups.php';
+
+$id                = required_param('id', PARAM_INT); // course id
+$PAGE->set_url('/local/contactform/participants_export_form.php', array('id'=>$id));
+
+if (!$course = $DB->get_record('course', array('id'=>$id))) {
+    print_error('nocourseid');
+}
+
+require_login($course);
+$context = context_course::instance($id);
+$groupid = groups_get_course_group($course, true);
+
+require_capability('moodle/grade:export', $context);
+
+// We need to call this method here before any print otherwise the menu won't display.
+// If you use this method without this check, will break the direct grade exporting (without publishing).
+$key = optional_param('key', '', PARAM_RAW);
+if (!empty($CFG->gradepublishing) && !empty($key)) {
+    print_grade_page_head($COURSE->id, 'export', 'xls_groups', get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xls_groups'));
+}
+
+if (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
+    if (!groups_is_member($groupid, $USER->id)) {
+        print_error('cannotaccessgroup', 'grades');
+    }
+}
+$mform = new grade_export_form(null, array('publishing' => true, 'simpleui' => true, 'multipledisplaytypes' => true));
+$formdata = $mform->get_data();
+$export = new participants_export_xls_groups($course, true);
+
+// If the gradepublishing is enabled and user key is selected print the grade publishing link.
+if (!empty($CFG->gradepublishing) && !empty($key)) {
+    groups_print_course_menu($course, 'index.php?id='.$id);
+    echo $export->get_grade_publishing_url();
+    echo $OUTPUT->footer();
+} else {
+    $export->print_grades();
+}
+
diff --git a/participants_export_xls_groups.php b/participants_export_xls_groups.php
new file mode 100644
index 0000000..3ed95ed
--- /dev/null
+++ b/participants_export_xls_groups.php
@@ -0,0 +1,102 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+require_once($CFG->dirroot . '/grade/export/lib.php');
+require_once($CFG->dirroot . '/lib/excellib.class.php');
+
+class participants_export_xls_groups {
+
+    public $course = '';
+    public $print_groups = true;
+    public $profilefields = null;
+    public $users = null;
+    public $context = 0;
+
+    /**
+     * Constructor should set up all the private variables ready to be pulled
+     * @param object $course
+     * @param boolean $groups
+     */
+    public function __construct($course, $print_groups) {
+        $this->course = $course;
+        $this->print_groups = $print_groups;
+    }
+
+    public function print_grades() {
+
+        $this->context = context_course::instance($this->course->id);
+        require_capability('moodle/grade:export', $this->context);
+        // Calculate file name
+        $shortname = format_string($this->course->shortname, true, array('context' => $this->context));
+        $downloadfilename = clean_filename("$shortname.xls");
+        // Creating a workbook
+        $workbook = new MoodleExcelWorkbook("-");
+        // Sending HTTP headers
+        $workbook->send($downloadfilename);
+
+        // Print names of all the fields
+        $this->profilefields = array('lastname' => get_string('lastname'), 'firstname' => get_string('firstname'), 'email' => get_string('email'));
+
+        $this->users = get_enrolled_users($this->context, null, 0, 'u.*');
+        $myxls = $workbook->add_worksheet(strip_tags($shortname));
+        $myxls->write_string(0, 0, $shortname);
+        $this->print_profilefields($myxls);
+        $this->print_values($myxls);
+
+        if ($this->print_groups) {
+            // Get all groups
+            $this->print_groups($workbook);
+        }
+        /// Close the workbook
+        $workbook->close();
+        exit;
+    }
+
+    public function print_profilefields($myxls) {
+        $i = 0;
+        foreach ($this->profilefields as $id => $field) {
+            $myxls->write_string(1, $i++, $field);
+        }
+    }
+
+    public function print_values($myxls) {
+        $i = 2;
+        foreach ($this->users as $userid => $value) {
+            $j = 0;
+            foreach ($this->profilefields as $id => $field) {
+                //$fieldvalue = grade_helper::get_user_field_value($userid, $field);
+                $array = (array) $value;
+                $myxls->write_string($i, $j++, $array[$id]);
+            }
+            $i++;
+        }
+    }
+
+    public function print_groups($workbook) {
+        global $DB;
+        $groups = $DB->get_records('groups', array('courseid' => $this->course->id), 'name');
+        foreach ($groups as $act_group) {
+            // Adding the worksheet
+            $myxls = $workbook->add_worksheet(strip_tags(format_string($act_group->name)));
+            $myxls->write_string(0, 0, format_string($act_group->name));
+            $this->print_profilefields($myxls);
+            $this->users = get_enrolled_users($this->context, null, $act_group->id, 'u.*');
+            $this->print_values($myxls);
+        }
+    }
+
+}
-- 
GitLab