From ab3fd81995c1a09a36aa20e5d1374eaac7590131 Mon Sep 17 00:00:00 2001
From: fneumann <neumann@ilias.de>
Date: Sat, 24 Feb 2024 02:35:14 +0100
Subject: [PATCH] Version 1.3

---
 CHANGELOG.md                                 |  6 ++-
 README.md                                    |  2 +-
 classes/Corrector/class.CorrectorContext.php | 32 +++++++------
 classes/Data/Task/class.EditorSettings.php   | 20 ++++++--
 classes/Task/class.EditorSettingsGUI.php     | 11 ++++-
 classes/class.BaseGUI.php                    | 12 +++++
 classes/class.ServiceContext.php             |  3 +-
 lang/ilias_de.lang                           | 10 ++--
 plugin.php                                   |  2 +-
 sql/dbupdate.php                             | 15 ++++++
 templates/css/content.css                    | 49 +++++++++++++++++++-
 templates/css/headlines-single.css           |  4 ++
 templates/css/headlines-three.css            | 13 ++++++
 13 files changed, 149 insertions(+), 30 deletions(-)
 create mode 100644 templates/css/headlines-single.css
 create mode 100644 templates/css/headlines-three.css

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 47e3517b..27830586 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,8 @@
 # Change log
 
 ## Version 1.3 (upcoming)
-- Applied code style of ILIAS 8
+- unnumbered headlines schemes with one or three levels
+- switch to allow browser spellcheck for writing a task
 - fixed 0040291: Imagemagick error in edutiek on ubuntu 22.04
 - fixed 0040150: pdf upload generates an error
 - fixed 0040296: Missing German Translation in Participant Management // Supervision Log
@@ -10,8 +11,9 @@
   - keep and exclude participant if writing hasn't started (prevent further access in tasks with instant participation)
   - log entries are not yet created for addition
 - fixed 0040304: format templates for hierarchizing headings should display the preview in the dropdown menu
+- Applied code style of ILIAS 8
 
-## Version 1.2 (2042-01-21)
+## Version 1.2 (2024-01-21)
 - fixed error with ascii control characters when written text is processed
 - fixed juristic headline scheme
 - added settings for processing written text (paragraph numbers, correction margins)
diff --git a/README.md b/README.md
index 7e90d870..ac778249 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,7 @@ Please clear your browser cache after an update before you start the writing and
 
 The plugin is published for ILIAS in different branches:
 
-* **release1_ilias7** will receive bug fixes only
+* **release1_ilias7** will receive bug fixes mainly
 * **release2_ilias8** will be created by March 2024
 * **main** is the current development branch. Please do not use it for production.
 
diff --git a/classes/Corrector/class.CorrectorContext.php b/classes/Corrector/class.CorrectorContext.php
index 8aea61be..858317bc 100644
--- a/classes/Corrector/class.CorrectorContext.php
+++ b/classes/Corrector/class.CorrectorContext.php
@@ -160,19 +160,19 @@ public function getCorrectionTask(): CorrectionTask
      */
     public function getCorrectionSettings(): CorrectionSettings
     {
-        if (!empty($repoSettings = $this->localDI->getTaskRepo()->getCorrectionSettingsById($this->task->getTaskId()))) {
-            return new CorrectionSettings(
-                (bool) $repoSettings->getMutualVisibility(),
-                (bool) $repoSettings->getMultiColorHighlight(),
-                (int) $repoSettings->getMaxPoints(),
-                (float) $repoSettings->getMaxAutoDistance(),
-                (bool) $repoSettings->getStitchWhenDistance(),
-                (bool) $repoSettings->getStitchWhenDecimals(),
-                (string) $repoSettings->getPositiveRating(),
-                (string) $repoSettings->getNegativeRating()
-            );
-        }
-        return new CorrectionSettings(false, false, 0, 0, false, false, '', '');
+        $repoEditorSettings = $this->localDI->getTaskRepo()->getEditorSettingsById($this->task->getTaskId());
+        $repoCorrectionSettings = $this->localDI->getTaskRepo()->getCorrectionSettingsById($this->task->getTaskId());
+        return new CorrectionSettings(
+            (bool) $repoCorrectionSettings->getMutualVisibility(),
+            (bool) $repoCorrectionSettings->getMultiColorHighlight(),
+            (int) $repoCorrectionSettings->getMaxPoints(),
+            (float) $repoCorrectionSettings->getMaxAutoDistance(),
+            (bool) $repoCorrectionSettings->getStitchWhenDistance(),
+            (bool) $repoCorrectionSettings->getStitchWhenDecimals(),
+            (string) $repoCorrectionSettings->getPositiveRating(),
+            (string) $repoCorrectionSettings->getNegativeRating(),
+            (string) $repoEditorSettings->getHeadlineScheme()
+        );
     }
 
     /**
@@ -548,8 +548,10 @@ public function getCorrectorsOfItem(string $item_key): array
         $currentCorrectorKey = $this->getCurrentCorrectorKey();
         
         $add_others = true;
-        if (empty($correctionSettings = $this->localDI->getTaskRepo()->getCorrectionSettingsById($this->task->getTaskId()))
-           || $correctionSettings->getMutualVisibility() == 0) {
+        if (!$this->object->canMaintainCorrectors() && (
+            empty($correctionSettings = $this->localDI->getTaskRepo()->getCorrectionSettingsById($this->task->getTaskId()))
+                || $correctionSettings->getMutualVisibility() == 0)
+        ) {
             $add_others = false;
         }
       
diff --git a/classes/Data/Task/class.EditorSettings.php b/classes/Data/Task/class.EditorSettings.php
index b01df067..b11a6515 100644
--- a/classes/Data/Task/class.EditorSettings.php
+++ b/classes/Data/Task/class.EditorSettings.php
@@ -10,7 +10,8 @@
  */
 class EditorSettings extends RecordData
 {
-    const HEADLINE_SCHEME_NONE = 'none';
+    const HEADLINE_SCHEME_SINGLE = 'single';
+    const HEADLINE_SCHEME_THREE = 'three';
     const HEADLINE_SCHEME_NUMERIC = 'numeric';
     const HEADLINE_SCHEME_EDUTIEK = 'edutiek';
 
@@ -33,11 +34,12 @@ class EditorSettings extends RecordData
         'add_paragraph_numbers' => 'integer',
         'add_correction_margin' => 'integer',
         'left_correction_margin' => 'integer',
-        'right_correction_margin' => 'integer'
+        'right_correction_margin' => 'integer',
+        'allow_spellcheck' => 'integer',
     ];
 
     protected int $task_id;
-    protected string $headline_scheme = self::HEADLINE_SCHEME_NONE;
+    protected string $headline_scheme = self::HEADLINE_SCHEME_THREE;
     protected string $formatting_options = self::FORMATTING_OPTIONS_MEDIUM;
     protected int $notice_boards = 0;
     protected int $copy_allowed = 0;
@@ -45,12 +47,24 @@ class EditorSettings extends RecordData
     protected int $add_correction_margin = 0;
     protected int $left_correction_margin = 0;
     protected int $right_correction_margin = 0;
+    protected int $allow_spellcheck = 0;
 
     public function __construct(int $task_id)
     {
         $this->task_id = $task_id;
     }
 
+    public function getAllowSpellcheck() : bool
+    {
+        return (bool) $this->allow_spellcheck;
+    }
+
+    public function setAllowSpellcheck(bool $allow_spellcheck) : self
+    {
+        $this->allow_spellcheck = (int) $allow_spellcheck;
+        return $this;
+    }
+
     public static function model()
     {
         return new self(0);
diff --git a/classes/Task/class.EditorSettingsGUI.php b/classes/Task/class.EditorSettingsGUI.php
index fa0d702a..5cd698e4 100644
--- a/classes/Task/class.EditorSettingsGUI.php
+++ b/classes/Task/class.EditorSettingsGUI.php
@@ -55,10 +55,12 @@ protected function editSettings()
         $fields['headline_scheme'] = $factory->select(
             $this->plugin->txt('headline_scheme'),
             [
-                EditorSettings::HEADLINE_SCHEME_NONE => $this->plugin->txt('headline_scheme_none'),
+                EditorSettings::HEADLINE_SCHEME_SINGLE => $this->plugin->txt('headline_scheme_single'),
+                EditorSettings::HEADLINE_SCHEME_THREE => $this->plugin->txt('headline_scheme_three'),
                 EditorSettings::HEADLINE_SCHEME_NUMERIC => $this->plugin->txt('headline_scheme_numeric'),
                 EditorSettings::HEADLINE_SCHEME_EDUTIEK => $this->plugin->txt('headline_scheme_edutiek'),
-            ]
+            ],
+            $this->plugin->txt('headline_scheme_description')
         )
             ->withRequired(true)
             ->withValue($editorSettings->getHeadlineScheme());
@@ -104,6 +106,10 @@ protected function editSettings()
         $fields['copy_allowed'] = $factory->checkbox($this->plugin->txt('copy_allowed'), $this->plugin->txt('copy_allowed_info'))
             ->withValue($editorSettings->isCopyAllowed());
 
+        $fields['allow_spellcheck'] = $factory->checkbox($this->plugin->txt('allow_spellcheck'), $this->plugin->txt('allow_spellcheck_info'))
+            ->withValue($editorSettings->getAllowSpellcheck());
+
+
         $sections['editor'] = $factory->section($fields, $this->plugin->txt('editor_settings'));
 
         // Processing
@@ -198,6 +204,7 @@ protected function editSettings()
             $editorSettings->setFormattingOptions($data['editor']['formatting_options']);
             $editorSettings->setNoticeBoards((int) $data['editor']['notice_boards']);
             $editorSettings->setCopyAllowed((bool) $data['editor']['copy_allowed']);
+            $editorSettings->setAllowSpellcheck((bool) $data['editor']['allow_spellcheck']);
 
             if (!$hasComments) {
                 $editorSettings->setAddParagraphNumbers((bool) $data['processing']['add_paragraph_numbers']);
diff --git a/classes/class.BaseGUI.php b/classes/class.BaseGUI.php
index 8945b80a..10f941d0 100644
--- a/classes/class.BaseGUI.php
+++ b/classes/class.BaseGUI.php
@@ -143,6 +143,12 @@ public function displayContent(?string $html) : string
     {
         if (!empty($settings = $this->localDI->getTaskRepo()->getEditorSettingsById($this->object->getId()))) {
             switch ($settings->getHeadlineScheme()) {
+                case EditorSettings::HEADLINE_SCHEME_SINGLE:
+                    $headline_class = "headlines-single";
+                    break;
+                case EditorSettings::HEADLINE_SCHEME_THREE:
+                    $headline_class = "headlines-three";
+                    break;
                 case EditorSettings::HEADLINE_SCHEME_EDUTIEK:
                     $headline_class = "headlines-edutiek";
                     break;
@@ -163,6 +169,12 @@ public function addContentCss() : void
 
         if (!empty($settings = $this->localDI->getTaskRepo()->getEditorSettingsById($this->object->getId()))) {
             switch ($settings->getHeadlineScheme()) {
+                case EditorSettings::HEADLINE_SCHEME_SINGLE:
+                    $this->tpl->addCss($this->plugin->getDirectory() .'/templates/css/headlines-single.css');
+                    break;
+                case EditorSettings::HEADLINE_SCHEME_THREE:
+                    $this->tpl->addCss($this->plugin->getDirectory() .'/templates/css/headlines-three.css');
+                    break;
                 case EditorSettings::HEADLINE_SCHEME_EDUTIEK:
                     $this->tpl->addCss($this->plugin->getDirectory() .'/templates/css/headlines-edutiek.css');
                     break;
diff --git a/classes/class.ServiceContext.php b/classes/class.ServiceContext.php
index aec15033..6fd9c6a7 100644
--- a/classes/class.ServiceContext.php
+++ b/classes/class.ServiceContext.php
@@ -403,7 +403,8 @@ public function getWritingSettings(): WritingSettings
             $repoSettings->getAddParagraphNumbers(),
             $repoSettings->getAddCorrectionMargin(),
             $repoSettings->getLeftCorrectionMargin(),
-            $repoSettings->getRightCorrectionMargin()
+            $repoSettings->getRightCorrectionMargin(),
+            $repoSettings->getAllowSpellcheck()
         );
     }
 
diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang
index 89739db5..c3127ace 100644
--- a/lang/ilias_de.lang
+++ b/lang/ilias_de.lang
@@ -108,9 +108,11 @@ task_solution#:#Lösungshinweise
 task_solution_info#:#Die Lösungshinweise werden erst ab einem festgelegten Zeitpunkt oder am Ende angezeigt. Dieser wird unter „Organisation ► Lösungshinweise verfügbar“ aktiviert und konfiguriert. Zusätzliche Hinweise können als Datei oder Weblink unter "Material" bereitgestellt werden.
 editor_settings#:#Schreiben der Aufgabe
 headline_scheme#:#Überschriften-Schema
-headline_scheme_none#:#Ohne Numerierung
-headline_scheme_numeric#:#Numeriert: 1 ‧ 1.1 ‧ 1.1.1
-headline_scheme_edutiek#:#Gutachten: A. ‧ I. ‧ 1. ‧ a. ‧ aa. ‧ (1)
+headline_scheme_single#:#Eine Ebene, ohne Numerierung
+headline_scheme_three#:#Drei Ebenen, ohne Numerierung
+headline_scheme_numeric#:#Hierarchische Numerierung: 1 ‧ 1.1 ‧ 1.1.1  ‧ ...
+headline_scheme_edutiek#:#Gutachten-Stil: A. ‧ I. ‧ 1. ‧ a. ‧ aa. ‧ (1)
+headline_scheme_description#:#Bei drei Ebenen ohne Numerierung haben die Überschriften unterschiedliche Größe, sonst eine einheitliche.
 formatting_options#:#Text-Formatierung
 formatting_options_none#:#Aus
 formatting_options_none_info#:#Keine Formatatierungs-Optionen
@@ -124,6 +126,8 @@ notice_boards#:#Notizbretter
 notice_boards_info#:#Anzahl der zur Verfügung gestellten Notitzbretter
 copy_allowed#:#Freies Kopieren erlauben
 copy_allowed_info#:#Texte können auch von anderen Webseiten kopiert werden. Das Kopieren im Text und von den Notizbrettern ist immer erlaubt.
+allow_spellcheck#:#Rechtschreibprüfung zulassen
+allow_spellcheck_info#:#Beim Schreiben der Aufgabe wird eine Rechtschreibprüfung durch den Browser zugelassen.
 add_resource#:#Material hinzufügen
 lp_passed#:#Bestanden
 lp_passed_info#:#Für Lernfortschritt und Vorbedingungen gilt diese Notenstufe als bestanden.
diff --git a/plugin.php b/plugin.php
index 7b3b3244..ae06f17d 100644
--- a/plugin.php
+++ b/plugin.php
@@ -5,7 +5,7 @@
 $id = 'xlas';
 
 // code version; must be changed for all code changes
-$version = '1.2';
+$version = '1.3';
 // ilias min and max version; must always reflect the versions that should
 // run with the plugin
 $ilias_min_version = '7.25';
diff --git a/sql/dbupdate.php b/sql/dbupdate.php
index 8a9278ca..3d77ab9d 100644
--- a/sql/dbupdate.php
+++ b/sql/dbupdate.php
@@ -2036,4 +2036,19 @@
     ]);
     $ilDB->addPrimaryKey('xlas_pdf_settings', ['task_id']);
 }
+?>
+<#91>
+<?php
+    $ilDB->manipulate("UPDATE xlas_editor_settings SET headline_scheme='three' WHERE headline_scheme='none'");
+?>
+<#92>
+<?php
+    if (!$ilDB->tableColumnExists('xlas_editor_settings', 'allow_spellcheck')) {
+        $ilDB->addTableColumn('xlas_editor_settings', 'allow_spellcheck', [
+            'notnull' => '1',
+            'type' => 'integer',
+            'length' => '4',
+            'default' => '0'
+        ]);
+}
 ?>
\ No newline at end of file
diff --git a/templates/css/content.css b/templates/css/content.css
index 08efaf9d..ecb15a50 100644
--- a/templates/css/content.css
+++ b/templates/css/content.css
@@ -4,7 +4,7 @@
 
 .mce-content-body, .long-essay-content {
     font-family: serif;
-    font-size: 16px;
+    font-size: 1em;
     max-width: 60em;
     line-height: 150%;
 }
@@ -14,7 +14,7 @@
 .mce-content-body h4, .long-essay-content h4,
 .mce-content-body h5, .long-essay-content h5,
 .mce-content-body h6, .long-essay-content h6 {
-    font-size: 16px;
+    font-size: 1em;
     font-weight: bold;
     padding: 0;
     margin-top: 0;
@@ -26,3 +26,48 @@
     margin-left: 10px;
     margin-bottom: 20px;
 }
+
+.mce-content-body li, .long-essay-content li {
+    margin-left: 20px;
+    margin-bottom: 5px;
+}
+
+.mce-content-body p, .long-essay-content p {
+    margin-top: 0;
+    margin-bottom: 10px;
+}
+
+.mce-content-body, .long-essay-content, .tox-menu {
+    counter-reset: h1 h2 h3 h4 h5 h6;
+}
+.mce-content-body h1, .long-essay-content h1, .tox-menu h1 {
+    counter-increment: h1;
+    counter-reset: h2 h3 h4 h5 h6;
+}
+.mce-content-body h2, .long-essay-content h2, .tox-menu h2 {
+    counter-increment: h2;
+    counter-reset: h3 h4 h5 h6;
+}
+.mce-content-body h3, .long-essay-content h3, .tox-menu h3 {
+    counter-increment: h3;
+    counter-reset: h4 h5 h6;
+}
+.mce-content-body h4, .long-essay-content h4, .tox-menu h4 {
+    counter-increment: h4;
+    counter-reset: h5 h6;
+}
+.mce-content-body h5, .long-essay-content h5, .tox-menu h5 {
+    counter-increment: h5;
+    counter-reset: h6;
+}
+.mce-content-body h6, .long-essay-content h6, .tox-menu h6 {
+    counter-increment: h6;
+}
+
+/*
+    Make font sizes in the tiny formats menu independent from changing font sizes in the content area
+    May be refined by headlines css files
+*/
+.tox-menu p, .tox-menu h1, .tox-menu h2, .tox-menu h3, .tox-menu h4, .tox-menu h5, .tox-menu h6, .tox-menu pre, .tox-menu li   {
+    font-size:1em!important;
+}
diff --git a/templates/css/headlines-single.css b/templates/css/headlines-single.css
new file mode 100644
index 00000000..ec39188d
--- /dev/null
+++ b/templates/css/headlines-single.css
@@ -0,0 +1,4 @@
+/**
+ * Single Level headline style of written contents
+ */
+
diff --git a/templates/css/headlines-three.css b/templates/css/headlines-three.css
new file mode 100644
index 00000000..845d5077
--- /dev/null
+++ b/templates/css/headlines-three.css
@@ -0,0 +1,13 @@
+/**
+ * Three level headline style of written contents
+ */
+
+.mce-content-body h1, .tox-menu h1, .headlines-three h1 {
+    font-size: 1.3em!important;
+}
+.mce-content-body h2, .tox-menu h2, .headlines-three h2 {
+    font-size: 1.15em!important;
+}
+.mce-content-body h3, .tox-menu h3, .headlines-three h3 {
+    font-size: 1.0em!important;
+}