diff --git a/lang/en/moodleoverflow.php b/lang/en/moodleoverflow.php
index e8e64de575..baf22c92b5 100644
--- a/lang/en/moodleoverflow.php
+++ b/lang/en/moodleoverflow.php
@@ -412,8 +412,9 @@
$string['anonymous:everything'] = 'Questioners and answerers (Irreversible!)';
$string['anonym_you'] = 'Anonymous (You)';
$string['allowanonymous'] = 'Allow anonymous';
-$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode';
+$string['allowanonymous_desc'] = 'Allow teachers to put moodleoverflow forums into anonymous question or full anonymous mode. Once enabled, anonymous forums will stay anonymous, even when this setting is disabled. If you really want to, you can reset anonymity in all forums here.';
$string['questioner'] = 'Questioner';
$string['answerer'] = 'Answerer #{$a}';
$string['desc:only_questions'] = 'The name of questioners will not be displayed in their question and comments.';
$string['desc:anonymous'] = 'No names will be displayed.';
+$string['resetanonymous_warning'] = 'Are you sure? If you are in production, this is most certainly a bad decision because your students and teachers posted their questions and answers, believing they would remain anonymous.
{$a->fullanoncount} forums are currently fully anonymized, and in {$a->questionanoncount} additional forums the questioners are anonymized.
In all these forums, the real names of posters will be displayed again, even in already existing posts!There is no way of reverting those changes!';
diff --git a/mod_form.php b/mod_form.php
index ae37dd5cc1..9410776316 100644
--- a/mod_form.php
+++ b/mod_form.php
@@ -82,9 +82,11 @@ public function definition() {
$possiblesettings[anonymous::NOT_ANONYMOUS] = get_string('no');
}
- $mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
- $mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
- $mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
+ if (get_config('moodleoverflow', 'allowanonymous') == '1') {
+ $mform->addElement('select', 'anonymous', get_string('anonymous', 'moodleoverflow'), $possiblesettings);
+ $mform->addHelpButton('anonymous', 'anonymous', 'moodleoverflow');
+ $mform->setDefault('anonymous', anonymous::NOT_ANONYMOUS);
+ }
// Attachments.
$mform->addElement('header', 'attachmentshdr', get_string('attachments', 'moodleoverflow'));
@@ -220,7 +222,7 @@ public function definition() {
* @param array $data data from the form.
*/
public function data_postprocessing($data) {
- if ($data->anonymous != anonymous::NOT_ANONYMOUS) {
+ if (isset($data->anonymous) && $data->anonymous != anonymous::NOT_ANONYMOUS) {
$data->coursewidereputation = false;
}
}
diff --git a/resetanonymous.php b/resetanonymous.php
new file mode 100644
index 0000000000..f130b33392
--- /dev/null
+++ b/resetanonymous.php
@@ -0,0 +1,60 @@
+.
+
+/**
+ * Resets all forums anonymity level, if the admin really wants to.
+ *
+ * @package mod_moodleoverflow
+ * @copyright 2022 Justus Dieckmann WWU
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+use mod_moodleoverflow\anonymous;
+
+require_once('../../config.php');
+
+global $DB, $PAGE, $OUTPUT;
+
+$PAGE->set_url('/mod/moodleoverflow/resetanonymous.php');
+$PAGE->set_context(context_system::instance());
+
+require_admin();
+
+$confirmed = optional_param('confirmed', false, PARAM_BOOL);
+
+$returnurl = new moodle_url('/admin/settings.php?section=modsettingmoodleoverflow');
+
+if ($confirmed !== 1) {
+ $a = new stdClass();
+ $a->fullanoncount = $DB->count_records('moodleoverflow',
+ ['anonymous' => anonymous::EVERYTHING_ANONYMOUS]);
+ $a->questionanoncount = $DB->count_records('moodleoverflow',
+ ['anonymous' => anonymous::QUESTION_ANONYMOUS]);
+ echo $OUTPUT->header();
+ echo html_writer::div(
+ $OUTPUT->confirm(get_string('resetanonymous_warning', 'moodleoverflow', $a),
+ new moodle_url($PAGE->url, ['confirmed' => true, 'sesskey' => sesskey()]), $returnurl),
+ 'mod_moodleoverflow-hack-primary-to-danger-btn'
+ );
+ echo $OUTPUT->footer();
+ die();
+}
+
+require_sesskey();
+
+$DB->execute('UPDATE {moodleoverflow} SET anonymous = ?', [anonymous::NOT_ANONYMOUS]);
+
+redirect($returnurl);
diff --git a/settings.php b/settings.php
index cad6481acc..09957e082f 100644
--- a/settings.php
+++ b/settings.php
@@ -77,9 +77,11 @@
$settings->add(new admin_setting_configselect('moodleoverflow/cleanreadtime', get_string('cleanreadtime', 'moodleoverflow'),
get_string('configcleanreadtime', 'moodleoverflow'), 2, $options));
+ $url = new moodle_url('/mod/moodleoverflow/resetanonymous.php');
+
$settings->add(new admin_setting_configcheckbox('moodleoverflow/allowanonymous',
get_string('allowanonymous', 'moodleoverflow'),
- get_string('allowanonymous_desc', 'moodleoverflow'),
+ get_string('allowanonymous_desc', 'moodleoverflow', $url->out(false)),
1
));
diff --git a/styles.css b/styles.css
index f47cba4cfe..9f517a6591 100644
--- a/styles.css
+++ b/styles.css
@@ -520,6 +520,17 @@ span.unread {
text-align: right;
}
+.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary {
+ background-color: #a90000;
+ border-color: #a90000;
+}
+
+.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:hover,
+.mod_moodleoverflow-hack-primary-to-danger-btn .btn-primary:focus {
+ background-color: #900000;
+ border-color: #900000;
+}
+
@media (max-width: 600px) {
.hide-600 {
display: none;