summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
authorSimon Rettberg2016-08-03 10:02:46 +0200
committerSimon Rettberg2016-08-03 10:02:46 +0200
commit227b2a17ba9aeba9b4dd519fd5266ee52f77a015 (patch)
tree50f18da953f05ac1ac0f62fab154cbb27a546c11 /modules-available
parent[statistics] Tweak layout, ellipsis in table without ruining layout (super aw... (diff)
parentsplitted dozmod page into several subpages. (diff)
downloadslx-admin-227b2a17ba9aeba9b4dd519fd5266ee52f77a015.tar.gz
slx-admin-227b2a17ba9aeba9b4dd519fd5266ee52f77a015.tar.xz
slx-admin-227b2a17ba9aeba9b4dd519fd5266ee52f77a015.zip
Merge branch 'modularization' of dnbd3:openslx-ng/slx-admin into modularization
Diffstat (limited to 'modules-available')
-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.php108
-rw-r--r--modules-available/dozmod/templates/images-delete.html4
-rw-r--r--modules-available/dozmod/templates/orglist.html21
-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.html15
9 files changed, 373 insertions, 45 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..c1c19b15 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&section=mailconfig', Dictionary::translate('submenu_mailconfig'));
+ Dashboard::addSubmenu('?do=dozmod&section=templates', Dictionary::translate('submenu_templates'));
+ Dashboard::addSubmenu('?do=dozmod&section=runtimeconfig', Dictionary::translate('submenu_runtime'));
+ Dashboard::addSubmenu('?do=dozmod&section=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,47 +52,62 @@ 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'));
- if ($mailConf != null) {
- $mailConf = @json_decode($mailConf['value'], true);
- if (is_array($mailConf)) {
- $mailConf['set_' . $mailConf['ssl']] = 'selected="selected"';
+
+ if ($section === 'mailconfig') {
+ // Mail config
+ $mailConf = Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'mailconfig'));
+ if ($mailConf != null) {
+ $mailConf = @json_decode($mailConf['value'], true);
+ if (is_array($mailConf)) {
+ $mailConf['set_' . $mailConf['ssl']] = 'selected="selected"';
+ }
}
+ Render::addTemplate('mailconfig', $mailConf);
}
- Render::addTemplate('mailconfig', $mailConf);
- // Runtime config
- $runtimeConf = Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'runtimelimits'));
- if ($runtimeConf != null) {
- $runtimeConf = json_decode($runtimeConf['value'], true);
-
- /* convert some value to corresponding "selected" texts */
- if ($runtimeConf['defaultLecturePermissions']['edit']) {
- $runtimeConf['defaultLecturePermissions']['edit'] = 'checked="checked"';
- }
- if ($runtimeConf['defaultLecturePermissions']['admin']) {
- $runtimeConf['defaultLecturePermissions']['admin'] = 'checked="checked"';
- }
- if ($runtimeConf['defaultImagePermissions']['edit']) {
- $runtimeConf['defaultImagePermissions']['edit'] = 'checked="checked"';
- }
- if ($runtimeConf['defaultImagePermissions']['admin']) {
- $runtimeConf['defaultImagePermissions']['admin'] = 'checked="checked"';
- }
- if ($runtimeConf['defaultImagePermissions']['link']) {
- $runtimeConf['defaultImagePermissions']['link'] = 'checked="checked"';
- }
- if ($runtimeConf['defaultImagePermissions']['download']) {
- $runtimeConf['defaultImagePermissions']['download'] = 'checked="checked"';
- }
+ if ($section === 'runtimeconfig') {
+ // Runtime config
+ $runtimeConf = Database::queryFirst('SELECT value FROM sat.configuration WHERE parameter = :param', array('param' => 'runtimelimits'));
+ if ($runtimeConf != null) {
+ $runtimeConf = json_decode($runtimeConf['value'], true);
+
+ /* convert some value to corresponding "selected" texts */
+ if ($runtimeConf['defaultLecturePermissions']['edit']) {
+ $runtimeConf['defaultLecturePermissions']['edit'] = 'checked="checked"';
+ }
+ if ($runtimeConf['defaultLecturePermissions']['admin']) {
+ $runtimeConf['defaultLecturePermissions']['admin'] = 'checked="checked"';
+ }
+ if ($runtimeConf['defaultImagePermissions']['edit']) {
+ $runtimeConf['defaultImagePermissions']['edit'] = 'checked="checked"';
+ }
+ if ($runtimeConf['defaultImagePermissions']['admin']) {
+ $runtimeConf['defaultImagePermissions']['admin'] = 'checked="checked"';
+ }
+ if ($runtimeConf['defaultImagePermissions']['link']) {
+ $runtimeConf['defaultImagePermissions']['link'] = 'checked="checked"';
+ }
+ if ($runtimeConf['defaultImagePermissions']['download']) {
+ $runtimeConf['defaultImagePermissions']['download'] = 'checked="checked"';
+ }
+ }
+ Render::addTemplate('runtimeconfig', $runtimeConf);
}
- Render::addTemplate('runtimeconfig', $runtimeConf);
// User list for making people admin
- $this->listUsers();
- $this->listOrganizations();
+ if ($section === 'users') {
+ $this->listUsers();
+ $this->listOrganizations();
+ }
}
private function listDeletePendingImages()
@@ -199,7 +235,7 @@ class Page_DozMod extends Page
));
Message::addSuccess('mail-config-saved');
}
- Util::redirect('?do=DozMod');
+ Util::redirect('?do=DozMod&section=mailconfig');
}
private function runtimeHandler()
@@ -236,7 +272,7 @@ class Page_DozMod extends Page
));
Message::addSuccess('runtimelimits-config-saved');
}
- Util::redirect('?do=DozMod');
+ Util::redirect('?do=DozMod&section=runtimeconfig');
}
private function listUsers()
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/orglist.html b/modules-available/dozmod/templates/orglist.html
index d325cc4d..34fa039c 100644
--- a/modules-available/dozmod/templates/orglist.html
+++ b/modules-available/dozmod/templates/orglist.html
@@ -17,7 +17,9 @@
{{#organizations}}
<tr>
<td class="text-left slx-nowrap">{{displayname}}</td>
- <td><input onclick="seto('setorglogin', this, '{{organizationid}}')" type="checkbox" {{{canlogin}}}></td>
+ <td class="text-nowrap">
+ <input onclick="seto('setorglogin', this, '{{organizationid}}')" type="checkbox" {{{canlogin}}}>
+ </td>
</tr>
{{/organizations}}
</tbody>
@@ -41,6 +43,21 @@ function seto(action, el, orgid) {
el.checked = (data == 1);
}
box.css('display', '');
+
+ /* show success notification */
+ $notification = $('<span></span>')
+ .addClass('glyphicon glyphicon-saved')
+ .css('color', '#2ecc71')
+ .css('width', '0px')
+ .css('position', 'relative')
+ .css('right', '20px')
+ .hide();
+ box.before($notification);
+ $notification.fadeIn('slow', function () {$notification.fadeOut('fast');});
+
+
+
+
}).fail(function() {
el.checked = !old;
box.parent().css('background-color', 'red !important');
@@ -48,4 +65,4 @@ function seto(action, el, orgid) {
});
}
---> </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..79d4848b 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">
@@ -51,6 +51,17 @@ function setu(action, el, uid) {
} else {
el.checked = (data == 1);
}
+ /* show success notification */
+ $notification = $('<span></span>')
+ .addClass('glyphicon glyphicon-saved')
+ .css('color', '#2ecc71')
+ .css('width', '0px')
+ .css('position', 'relative')
+ .css('right', '20px')
+ .hide();
+ box.before($notification);
+ $notification.fadeIn('slow', function () {$notification.fadeOut('fast');});
+
box.css('display', '');
}).fail(function() {
el.checked = !old;
@@ -59,4 +70,4 @@ function setu(action, el, uid) {
});
}
---> </script> \ No newline at end of file
+--> </script>