summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-08-02 15:56:37 +0200
committerChristian Klinger2016-08-02 15:56:37 +0200
commit7b366ecc2a107d77ce274790207a3e65866a8184 (patch)
treefcb7699882ef9b91f21bb73d891b5f4d1809767d
parentdozmod runtimeconfig. (diff)
downloadslx-admin-7b366ecc2a107d77ce274790207a3e65866a8184.tar.gz
slx-admin-7b366ecc2a107d77ce274790207a3e65866a8184.tar.xz
slx-admin-7b366ecc2a107d77ce274790207a3e65866a8184.zip
mail template editor.
-rw-r--r--modules-available/dozmod/inc/pagemailtemplates.inc.php119
-rw-r--r--modules-available/dozmod/lang/de/module.json6
-rw-r--r--modules-available/dozmod/lang/de/template-tags.json3
-rw-r--r--modules-available/dozmod/page.inc.php31
-rw-r--r--modules-available/dozmod/templates/images-delete.html4
-rw-r--r--modules-available/dozmod/templates/runtimeconfig.html2
-rw-r--r--modules-available/dozmod/templates/templates.html140
-rw-r--r--modules-available/dozmod/templates/userlist.html4
8 files changed, 302 insertions, 7 deletions
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 @@
+<?php
+
+class Page_mail_templates extends Page
+{
+
+ private $templates = [];
+
+ protected function doPreprocess()
+ {
+ User::load();
+
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('main.no-permission');
+ Util::redirect('?do=Main');
+ }
+
+ $action = Request::get('action', 'show', 'string');
+
+ if ($action === 'show') {
+ $this->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 .= "<option selected=\"selected\" value=\"$var\">$var</option>";
+ $lis .= "<li><strong>$var</strong></li>";
+ }
+ foreach($t['optional_variables'] as $var) {
+ $optVars .= "<option selected=\"selected\" value=\"$var\">$var</option>";
+ $lis .= "<li>$var</li>";
+ }
+ /* 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 '<pre>';
+ //var_dump($this->templates);
+ //echo '</pre>';
+ //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 '<pre>';
+ //print_r($data);
+ //echo '</pre>';
+ //die();
+ Database::exec("UPDATE sat.configuration SET value = :value WHERE parameter = 'templates'", array('value' => $data));
+ Message::addSuccess('templates-saved');
+
+ Util::redirect('?do=dozmod&section=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&section=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}}
</div>
<div class="panel-body">
- <p>{{lang_description}}</p>
+ <p>{{lang_description_delete_images}}</p>
<div class="table-responsive">
<form id="delform" method="post" action="?do=DozMod" onsubmit="return slxPostdel()">
<input type="hidden" name="token" value="{{token}}">
@@ -85,4 +85,4 @@ document.addEventListener("DOMContentLoaded", function() {
slxChangeSingle();
}, false);
---> </script> \ No newline at end of file
+--> </script>
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 @@
-<h2>{{lang_runtimeConfigHeadline}}</h2>
+<h2 id="runtime-configuration">{{lang_runtimeConfigHeadline}}</h2>
<div class="panel panel-default">
<div class="panel-heading">
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 @@
+<h1> Templates</h1>
+
+<form id="templateForm" role="form" method="POST" action="?do=dozmod&section=templates&action=save">
+ <input type="hidden" name="token" value="{{token}}">
+
+
+ <div class="panel-group" id="accordion">
+
+ {{#templates}}
+
+ <div class="panel panel-default">
+ <div id="heading_{{name}}" class="panel-heading">
+ <div class="panel-title">
+ <h4>
+ <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#panel_{{name}}">
+ {{name}}
+ </a>
+ </h4>
+ <small>{{description}}</small>
+
+ </div>
+ </div>
+ <div id="panel_{{name}}" class="panel-collapse collapse">
+ <div class="panel-body">
+ <div id="msgbox_{{name}}">
+ </div>
+ <label for="n_{{name}}">{{lang_name}}</label>
+ <input name="templates[{{name}}][name]" value="{{name}}" class="form-control"/>
+
+ <label for="n_{{description}}">{{lang_description}}</label>
+ <input name="templates[{{name}}][description]" value="{{description}}" class="form-control"/>
+
+
+
+ <label for="ta_{{name}}">{{lang_template}}</label>
+ <br/>
+ <textarea data-mandatory="{{list_mandatoryVariables}}" name="templates[{{name}}][template]" data-setting="{{name}}" id="ta_{{name}}"
+ class="form-control templateEditor" style="min-height:200px"
+ >{{template}}</textarea>
+
+ <h3>{{lang_placeholders}}</h3>
+ <select name="templates[{{name}}][mandatory_variables]" multiple="multiple" class="hidden">
+ {{{html_mandatoryVariables}}}
+ </select>
+ <select name="templates[{{name}}][optional_variables]" multiple="multiple" class="hidden">
+ {{{html_optionalVariables}}}
+ </select>
+ <ul>
+ {{{html_availableVariables}}}
+ </ul>
+ </div>
+ </div>
+ </div>
+
+
+ {{/templates}}
+ </div>
+
+ <div class="btn-group">
+ <button type="button" onclick="sendForm()" class="btn btn-primary">{{lang_save}}</button>
+ </div>
+</form>
+<script type="application/javascript"><!--
+
+
+/* check that all necessary placeholders are used */
+function validateForm() {
+ var ok = true;
+
+ $('.templateEditor').each(function (i, editor) {
+
+ var id = $(editor).attr('id');
+ var setting = $(editor).attr('data-setting');
+ var mandatory = $(editor).attr('data-mandatory').split(",");
+ var value = $(editor).val();
+
+
+ /* ? */
+ if (mandatory.length == 1 && mandatory[0] == "") {
+ mandatory = [];
+ }
+
+ var missing = [];
+
+ mandatory.forEach(function (v,i) {
+ if (value.indexOf("%" + v + "%") == -1) {
+ missing.push(v);
+ }
+ });
+ console.log("missing are");
+ console.log(missing);
+
+ var $msgBox = $("#msgbox_" + setting);
+ var $panel = $("#panel_" + setting);
+ var $header = $("#heading_" + setting);
+
+
+ if (missing.length > 0) {
+ /* add errors */
+ var missingL = missing.join(", ");
+ var msg="<strong>Fehler:</strong> Folgende wichtige Platzhalter wurden nicht verwendet: " +missingL;
+ console.log("msg box has " + $msgBox.size());
+ $msgBox.html('<div class="alert alert-danger">' + msg + '</div>');
+ $panel.addClass('witherror');
+ $header.addClass('witherror');
+ /* overall result */
+ ok = false;
+ } else {
+ $msgBox.html("");
+ $panel.removeClass('witherror');
+ $header.removeClass('witherror');
+ }
+
+
+ });
+ return ok;
+}
+
+function submitForm() {
+ console.log('sending form');
+ $('#templateForm').submit();
+}
+
+
+function sendForm() {
+ var ok = validateForm();
+ if (ok) {
+ console.log("is ok");
+ submitForm();
+ } else {
+ console.log("form is not ok");
+ }
+}
+
+document.addEventListener("DOMContentLoaded", function () {
+
+
+
+});
+</script>
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 @@
-<h2>{{lang_userList}}</h2>
+<h2 id="users">{{lang_userList}}</h2>
<div class="panel panel-default">
<div class="panel-heading">
@@ -59,4 +59,4 @@ function setu(action, el, uid) {
});
}
---> </script> \ No newline at end of file
+--> </script>