From 7b366ecc2a107d77ce274790207a3e65866a8184 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Tue, 2 Aug 2016 15:56:37 +0200 Subject: mail template editor. --- .../dozmod/inc/pagemailtemplates.inc.php | 119 ++++++++++++++++++ modules-available/dozmod/lang/de/module.json | 6 +- .../dozmod/lang/de/template-tags.json | 3 +- modules-available/dozmod/page.inc.php | 31 +++++ .../dozmod/templates/images-delete.html | 4 +- .../dozmod/templates/runtimeconfig.html | 2 +- modules-available/dozmod/templates/templates.html | 140 +++++++++++++++++++++ modules-available/dozmod/templates/userlist.html | 4 +- 8 files changed, 302 insertions(+), 7 deletions(-) create mode 100644 modules-available/dozmod/inc/pagemailtemplates.inc.php create mode 100644 modules-available/dozmod/templates/templates.html (limited to 'modules-available/dozmod') diff --git a/modules-available/dozmod/inc/pagemailtemplates.inc.php b/modules-available/dozmod/inc/pagemailtemplates.inc.php new file mode 100644 index 00000000..fedb13c8 --- /dev/null +++ b/modules-available/dozmod/inc/pagemailtemplates.inc.php @@ -0,0 +1,119 @@ +fetchTemplates(); + } elseif ($action === 'save') { + $this->handleSave(); + } + } + + private function enrichHtml() { + /* for each template */ + foreach ($this->templates as $k => $t) { + $lis = ""; + $optManVars = ""; + $optVars = ""; + foreach ($t['mandatory_variables'] as $var) { + $optManVars .= ""; + $lis .= "
  • $var
  • "; + } + foreach($t['optional_variables'] as $var) { + $optVars .= ""; + $lis .= "
  • $var
  • "; + } + /* also options for hidden inputs */ + + $this->templates[$k]['html_availableVariables'] = $lis; + $this->templates[$k]['html_mandatoryVariables'] = $optManVars; + $this->templates[$k]['html_optionalVariables'] = $optVars; + + /* also for javascript */ + $this->templates[$k]['list_mandatoryVariables'] = + implode(',', $this->templates[$k]['mandatory_variables']); + + $this->templates[$k]['list_optionalVariables'] = + implode(',', $this->templates[$k]['optional_variables']); + } + + } + protected function doRender() + { + //echo '
    ';
    +		//var_dump($this->templates);
    +		//echo '
    '; + //die(); + $this->enrichHtml(); + Render::addTemplate('templates', ['templates' => $this->templates]); + } + + private function handleSave() { + $data = []; + $data['templates'] = Request::post('templates'); + $data = $this->cleanTemplateArray($data); + if ($data!= NULL) { + $data = json_encode($data, JSON_PRETTY_PRINT); + //echo '
    ';
    +			//print_r($data);
    +			//echo '
    '; + //die(); + Database::exec("UPDATE sat.configuration SET value = :value WHERE parameter = 'templates'", array('value' => $data)); + Message::addSuccess('templates-saved'); + + Util::redirect('?do=dozmod§ion=templates&action=show'); + } else { + die('error while encoding'); + } + + } + + private function fetchTemplates() { + $templates= Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'templates')); + if ($templates != null) { + $templates = @json_decode($templates['value'], true); + if (is_array($templates)) { + $this->templates = $templates['templates']; + } + } + + } + + private function cleanTemplateArray($in) { + $out = []; + foreach ($in['templates'] as $t) { + $tcopy = $t; + $tcopy['mandatory_variables'] = $this->toArray($t['mandatory_variables']); + $tcopy['optional_variables'] = $this->toArray($t['optional_variables']); + $tcopy['description'] = $t['description']; + $tcopy['name'] = $t['name']; + + $out['templates'][] = $tcopy; + } + return $out; + } + + private function toArray($value) { + if (empty($value)) { + return []; + } else if(is_array($value)) { + return $value; + } else { + return array($value); + } + } +} diff --git a/modules-available/dozmod/lang/de/module.json b/modules-available/dozmod/lang/de/module.json index fd4c6aff..df2b5d4b 100644 --- a/modules-available/dozmod/lang/de/module.json +++ b/modules-available/dozmod/lang/de/module.json @@ -1,4 +1,8 @@ { "module_name": "Dozentenmodul", - "page_title": "Verwalten des Dozentenmoduls" + "page_title": "Verwalten des Dozentenmoduls", + "submenu_mailconfig": "Email-Konfiguration", + "submenu_runtime": "Laufzeit", + "submenu_templates": "Vorlagen E-Mail", + "submenu_users": "Benutzer" } \ No newline at end of file diff --git a/modules-available/dozmod/lang/de/template-tags.json b/modules-available/dozmod/lang/de/template-tags.json index 79d918f2..f123db5b 100644 --- a/modules-available/dozmod/lang/de/template-tags.json +++ b/modules-available/dozmod/lang/de/template-tags.json @@ -8,8 +8,9 @@ "lang_defaultImagePermissions": "Standard-Berechtigungen f\u00fcr Images", "lang_defaultLecturePermissions": "Standard-Berechtigungen f\u00fcr Vorlesungen", "lang_delButton": "Gew\u00e4hlte Images endg\u00fcltig l\u00f6schen", - "lang_description": "Diese Liste zeigt Images, die entweder abgelaufen sind, oder deren Datei besch\u00e4digt, verschoben oder gel\u00f6scht wurde. Diese Images sind zur Zeit im Lehrpool nicht verf\u00fcgbar, ihre endg\u00fcltige L\u00f6schung muss aber manuell best\u00e4tigt werden, um gr\u00f6\u00dfere Katastrophen durch Softwarefehler, verstellte Systemuhren etc. zu vermeiden.", + "lang_description": "Beschreibung", "lang_descriptionRuntimeConfig": "Blah blah blah", + "lang_description_delete_images": "Diese Liste zeigt Images, die entweder abgelaufen sind, oder deren Datei besch\u00e4digt, verschoben oder gel\u00f6scht wurde. Diese Images sind zur Zeit im Lehrpool nicht verf\u00fcgbar, ihre endg\u00fcltige L\u00f6schung muss aber manuell best\u00e4tigt werden, um gr\u00f6\u00dfere Katastrophen durch Softwarefehler, verstellte Systemuhren etc. zu vermeiden.", "lang_email": "EMail", "lang_emailNotifications": "EMail-Benachrichtigungen aktiviert", "lang_hasNewer": "Neuere Version existiert", diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php index 669538e5..a9505f22 100644 --- a/modules-available/dozmod/page.inc.php +++ b/modules-available/dozmod/page.inc.php @@ -2,6 +2,8 @@ class Page_DozMod extends Page { + /* sub page classes */ + private $mail_templates; protected function doPreprocess() { @@ -12,6 +14,25 @@ class Page_DozMod extends Page Util::redirect('?do=Main'); } + /* add sub-menus */ + Dashboard::addSubmenu('?do=dozmod', Dictionary::translate('submenu_mailconfig')); + Dashboard::addSubmenu('?do=dozmod§ion=templates', Dictionary::translate('submenu_templates')); + Dashboard::addSubmenu('?do=dozmod#runtime-configuration', Dictionary::translate('submenu_runtime')); + Dashboard::addSubmenu('?do=dozmod#users', Dictionary::translate('submenu_users')); + + /* instantiate sub pages */ + $this->mail_templates = new Page_mail_templates(); + + + + /* different pages for different sections */ + $section = Request::get('section', 'mailconfig', 'string'); + if ($section == 'templates') { + $this->mail_templates->doPreprocess(); + return; + } + + /* execute actions */ $action = Request::post('action'); if ($action === 'mail') { @@ -31,6 +52,16 @@ class Page_DozMod extends Page protected function doRender() { + /* different pages for different sections */ + $section = Request::get('section', 'mailconfig', 'string'); + if ($section == 'templates') { + $this->mail_templates->doRender(); + return; + } + + + + $this->listDeletePendingImages(); // Mail config $mailConf = Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'mailconfig')); diff --git a/modules-available/dozmod/templates/images-delete.html b/modules-available/dozmod/templates/images-delete.html index 99ffb85d..f8836b83 100644 --- a/modules-available/dozmod/templates/images-delete.html +++ b/modules-available/dozmod/templates/images-delete.html @@ -5,7 +5,7 @@ {{lang_subHeading}}
    -

    {{lang_description}}

    +

    {{lang_description_delete_images}}

    @@ -85,4 +85,4 @@ document.addEventListener("DOMContentLoaded", function() { slxChangeSingle(); }, false); ---> \ No newline at end of file +--> diff --git a/modules-available/dozmod/templates/runtimeconfig.html b/modules-available/dozmod/templates/runtimeconfig.html index 06de8d8f..eced5784 100644 --- a/modules-available/dozmod/templates/runtimeconfig.html +++ b/modules-available/dozmod/templates/runtimeconfig.html @@ -1,4 +1,4 @@ -

    {{lang_runtimeConfigHeadline}}

    +

    {{lang_runtimeConfigHeadline}}

    diff --git a/modules-available/dozmod/templates/templates.html b/modules-available/dozmod/templates/templates.html new file mode 100644 index 00000000..e8e3f592 --- /dev/null +++ b/modules-available/dozmod/templates/templates.html @@ -0,0 +1,140 @@ +

    Templates

    + + + + + +
    + + {{#templates}} + +
    +
    +
    +

    + +

    + {{description}} + +
    +
    +
    +
    +
    +
    + + + + + + + + + +
    + + +

    {{lang_placeholders}}

    + + +
      + {{{html_availableVariables}}} +
    +
    +
    +
    + + + {{/templates}} +
    + +
    + +
    + + diff --git a/modules-available/dozmod/templates/userlist.html b/modules-available/dozmod/templates/userlist.html index a76eae5e..3ccff4d9 100644 --- a/modules-available/dozmod/templates/userlist.html +++ b/modules-available/dozmod/templates/userlist.html @@ -1,4 +1,4 @@ -

    {{lang_userList}}

    +

    {{lang_userList}}

    @@ -59,4 +59,4 @@ function setu(action, el, uid) { }); } ---> \ No newline at end of file +--> -- cgit v1.2.3-55-g7522