summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-08-16 18:05:29 +0200
committerSimon Rettberg2016-08-16 18:05:29 +0200
commitbf3bb604fa82e0738fdb21d9bd4fd07000ed35bd (patch)
treed89f1aff06f9374ea44587542c3fd319cc727187
parent[render] Restore debug template generation (diff)
downloadslx-admin-bf3bb604fa82e0738fdb21d9bd4fd07000ed35bd.tar.gz
slx-admin-bf3bb604fa82e0738fdb21d9bd4fd07000ed35bd.tar.xz
slx-admin-bf3bb604fa82e0738fdb21d9bd4fd07000ed35bd.zip
[dozmod] Implement action log subpage
-rw-r--r--modules-available/dozmod/inc/pagedozmodlog.inc.php156
-rw-r--r--modules-available/dozmod/inc/pagedozmodusers.inc.php115
-rw-r--r--modules-available/dozmod/inc/pagemailtemplates.inc.php7
-rw-r--r--modules-available/dozmod/lang/de/module.json1
-rw-r--r--modules-available/dozmod/lang/de/template-tags.json14
-rw-r--r--modules-available/dozmod/lang/en/module.json1
-rw-r--r--modules-available/dozmod/lang/en/template-tags.json14
-rw-r--r--modules-available/dozmod/page.inc.php145
-rw-r--r--modules-available/dozmod/templates/actionlog-header.html1
-rw-r--r--modules-available/dozmod/templates/actionlog-image.html30
-rw-r--r--modules-available/dozmod/templates/actionlog-lecture.html30
-rw-r--r--modules-available/dozmod/templates/actionlog-log.html41
-rw-r--r--modules-available/dozmod/templates/actionlog-user.html23
-rw-r--r--modules-available/dozmod/templates/orglist.html34
-rw-r--r--modules-available/dozmod/templates/userlist.html34
15 files changed, 498 insertions, 148 deletions
diff --git a/modules-available/dozmod/inc/pagedozmodlog.inc.php b/modules-available/dozmod/inc/pagedozmodlog.inc.php
new file mode 100644
index 00000000..f31edf5b
--- /dev/null
+++ b/modules-available/dozmod/inc/pagedozmodlog.inc.php
@@ -0,0 +1,156 @@
+<?php
+
+class Page_dozmod_log extends Page
+{
+
+ private $action;
+ private $uuid;
+
+ protected function doPreprocess()
+ {
+ $this->action = Request::get('action', '', 'string');
+ if ($this->action !== '' && $this->action !== 'showtarget' && $this->action !== 'showuser') {
+ Util::traceError('Invalid action for actionlog: "' . $this->action . '"');
+ }
+ $this->uuid = Request::get('uuid', '', 'string');
+ }
+
+ protected function doRender()
+ {
+ Render::addTemplate('actionlog-header');
+ if ($this->action === '') {
+ $this->generateLog("SELECT al.dateline, al.targetid, al.description,"
+ . " img.displayname AS imgname, tu.firstname AS tfirstname, tu.lastname AS tlastname, l.displayname AS lecturename,"
+ . " al.userid AS uuserid, usr.firstname AS ufirstname, usr.lastname AS ulastname"
+ . " FROM sat.actionlog al"
+ . " LEFT JOIN sat.imagebase img ON (img.imagebaseid = targetid)"
+ . " LEFT JOIN sat.user usr ON (usr.userid = al.userid)"
+ . " LEFT JOIN sat.user tu ON (tu.userid = al.targetid)"
+ . " LEFT JOIN sat.lecture l ON (l.lectureid = targetid)"
+ . " ORDER BY al.dateline DESC LIMIT 500", array(), true, true);
+ } elseif ($this->action === 'showuser') {
+ $this->listUser();
+ } else {
+ $this->listTarget();
+ }
+ }
+
+ private function listUser()
+ {
+ // Query user
+ $user = Database::queryFirst('SELECT userid, firstname, lastname, email, lastlogin,'
+ . ' organization.displayname AS orgname FROM sat.user'
+ . ' LEFT JOIN sat.organization USING (organizationid)'
+ . ' WHERE userid = :uuid'
+ . ' LIMIT 1', array('uuid' => $this->uuid));
+ if ($user === false) {
+ Message:addError('unknown-userid', $this->uuid);
+ Util::redirect('?do=dozmod&section=actionlog');
+ }
+ // Mangle date and render
+ $user['lastlogin_s'] = date('d.m.Y H:i', $user['lastlogin']);
+ Render::addTemplate('actionlog-user', $user);
+ // Finally add the actionlog
+ $this->generateLog("SELECT al.dateline, al.targetid, al.description,"
+ . " img.displayname AS imgname, usr.firstname AS tfirstname, usr.lastname AS tlastname, l.displayname AS lecturename"
+ . " FROM sat.actionlog al"
+ . " LEFT JOIN sat.imagebase img ON (img.imagebaseid = targetid)"
+ . " LEFT JOIN sat.user usr ON (usr.userid = targetid)"
+ . " LEFT JOIN sat.lecture l ON (l.lectureid = targetid)"
+ . " WHERE al.userid = :uuid"
+ . " ORDER BY al.dateline DESC LIMIT 500", array('uuid' => $this->uuid), false, true);
+ }
+
+ private function listTarget()
+ {
+ // We have to guess what kind of target it is
+ if (!$this->addImageHeader()
+ && !$this->addLectureHeader()) {
+ Message:addError('unknown-targetid', $this->uuid);
+ // Keep going, there might still be log entries for a deleted uuid
+ }
+
+ // Finally add the actionlog
+ $this->generateLog("SELECT al.dateline, al.userid AS uuserid, al.description,"
+ . " usr.firstname AS ufirstname, usr.lastname AS ulastname"
+ . " FROM sat.actionlog al"
+ . " LEFT JOIN sat.user usr ON (usr.userid = al.userid)"
+ . " WHERE al.targetid = :uuid"
+ . " ORDER BY al.dateline DESC LIMIT 500", array('uuid' => $this->uuid), true, false);
+ }
+
+ private function addImageHeader()
+ {
+ $image = Database::queryFirst('SELECT o.userid AS ouserid, o.firstname AS ofirstname, o.lastname AS olastname,'
+ . ' u.userid AS uuserid, u.firstname AS ufirstname, u.lastname AS ulastname,'
+ . ' img.displayname, img.description, img.createtime, img.updatetime,'
+ . ' os.displayname AS osname'
+ . ' FROM sat.imagebase img'
+ . ' LEFT JOIN sat.user o ON (img.ownerid = o.userid)'
+ . ' LEFT JOIN sat.user u ON (img.updaterid = u.userid)'
+ . ' LEFT JOIN sat.operatingsystem os ON (img.osid = os.osid)'
+ . ' WHERE img.imagebaseid = :uuid'
+ . ' LIMIT 1', array('uuid' => $this->uuid));
+ if ($image !== false) {
+ // Mangle date and render
+ $image['createtime_s'] = date('d.m.Y H:i', $image['createtime']);
+ $image['updatetime_s'] = date('d.m.Y H:i', $image['updatetime']);
+ $image['descriptionHtml'] = nl2br(htmlspecialchars($image['description']));
+ Render::addTemplate('actionlog-image', $image);
+ }
+ return $image !== false;
+ }
+
+ private function addLectureHeader()
+ {
+ $lecture = Database::queryFirst('SELECT o.userid AS ouserid, o.firstname AS ofirstname, o.lastname AS olastname,'
+ . ' u.userid AS uuserid, u.firstname AS ufirstname, u.lastname AS ulastname,'
+ . ' l.displayname, l.description, l.createtime, l.updatetime,'
+ . ' img.displayname AS imgname, img.imagebaseid'
+ . ' FROM sat.lecture l'
+ . ' LEFT JOIN sat.user o ON (l.ownerid = o.userid)'
+ . ' LEFT JOIN sat.user u ON (l.updaterid = u.userid)'
+ . ' LEFT JOIN sat.imageversion ver ON (ver.imageversionid = l.imageversionid)'
+ . ' LEFT JOIN sat.imagebase img ON (img.imagebaseid = ver.imagebaseid)'
+ . ' WHERE l.lectureid = :uuid'
+ . ' LIMIT 1', array('uuid' => $this->uuid));
+ if ($lecture !== false) {
+ // Mangle date and render
+ $lecture['createtime_s'] = date('d.m.Y H:i', $lecture['createtime']);
+ $lecture['updatetime_s'] = date('d.m.Y H:i', $lecture['updatetime']);
+ $lecture['descriptionHtml'] = nl2br(htmlspecialchars($lecture['description']));
+ Render::addTemplate('actionlog-lecture', $lecture);
+ }
+ return $lecture !== false;
+ }
+
+ private function generateLog($query, $params, $showActor, $showTarget)
+ {
+ // query action log
+ $res = Database::simpleQuery($query, $params);
+ $events = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $row['dateline_s'] = date('d.m.Y H:i', $row['dateline']);
+ if (isset($row['imgname'])) {
+ $row['targeturl'] = '?do=dozmod&section=actionlog&action=showtarget&uuid=' . $row['targetid'];
+ $row['targetname'] = $row['imgname'];
+ } elseif (isset($row['tlastname'])) {
+ $row['targeturl'] = '?do=dozmod&section=actionlog&action=showuser&uuid=' . $row['targetid'];
+ $row['targetname'] = $row['tlastname'] . ', ' . $row['tfirstname'];
+ } elseif (isset($row['lecturename'])) {
+ $row['targeturl'] = '?do=dozmod&section=actionlog&action=showtarget&uuid=' . $row['targetid'];
+ $row['targetname'] = $row['lecturename'];
+ }
+ $events[] = $row;
+ }
+ $data = array('events' => $events);
+ if ($showActor) {
+ $data['showActor'] = true;
+ }
+ if ($showTarget) {
+ $data['showTarget'] = true;
+ }
+ Render::addTemplate('actionlog-log', $data);
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/dozmod/inc/pagedozmodusers.inc.php b/modules-available/dozmod/inc/pagedozmodusers.inc.php
new file mode 100644
index 00000000..8da07923
--- /dev/null
+++ b/modules-available/dozmod/inc/pagedozmodusers.inc.php
@@ -0,0 +1,115 @@
+<?php
+
+class Page_dozmod_users extends Page
+{
+
+ protected function doPreprocess()
+ {
+
+ }
+
+ protected function doRender()
+ {
+ $this->listUsers();
+ $this->listOrganizations();
+ }
+
+ protected function doAjax()
+ {
+ $action = Request::post('action', '', 'string');
+ if ($action === 'setmail' || $action === 'setsu' || $action == 'setlogin') {
+ $this->setUserOption($action);
+ } elseif ($action === 'setorglogin') {
+ $this->setOrgOption($action);
+ } else {
+ die('No such action');
+ }
+ }
+
+ // Helpers
+
+ private function listUsers()
+ {
+ $res = Database::simpleQuery('SELECT userid, firstname, lastname, email, lastlogin, user.canlogin, issuperuser, emailnotifications,'
+ . ' organization.displayname AS orgname FROM sat.user'
+ . ' LEFT JOIN sat.organization USING (organizationid)'
+ . ' ORDER BY lastname ASC, firstname ASC');
+ $rows = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $row['canlogin'] = $this->checked($row['canlogin']);
+ $row['issuperuser'] = $this->checked($row['issuperuser']);
+ $row['emailnotifications'] = $this->checked($row['emailnotifications']);
+ $row['lastlogin'] = date('d.m.Y', $row['lastlogin']);
+ $rows[] = $row;
+ }
+ Render::addTemplate('userlist', array('users' => $rows));
+ }
+
+ private function listOrganizations()
+ {
+ $res = Database::simpleQuery('SELECT organizationid, displayname, canlogin FROM sat.organization'
+ . ' ORDER BY displayname ASC');
+ $rows = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $row['canlogin'] = $this->checked($row['canlogin']);
+ $rows[] = $row;
+ }
+ Render::addTemplate('orglist', array('organizations' => $rows));
+ }
+
+ private function checked($val)
+ {
+ if ($val)
+ return 'checked="checked"';
+ return '';
+ }
+
+ private function setUserOption($option)
+ {
+ $val = (string) Request::post('value', '-');
+ if ($val !== '1' && $val !== '0')
+ die('Nein');
+ if ($option === 'setmail') {
+ $field = 'emailnotifications';
+ } elseif ($option === 'setsu') {
+ $field = 'issuperuser';
+ } elseif ($option === 'setlogin') {
+ $field = 'canlogin';
+ } else {
+ die('Unknown');
+ }
+ $user = (string) Request::post('userid', '?');
+ $ret = Database::exec("UPDATE sat.user SET $field = :onoff WHERE userid = :userid", array(
+ 'userid' => $user,
+ 'onoff' => $val
+ ));
+ error_log("Setting $field to $val for $user - affected: $ret");
+ if ($ret === false)
+ die('Error');
+ if ($ret === 0)
+ die(1 - $val);
+ die($val);
+ }
+
+ private function setOrgOption($option)
+ {
+ $val = (string) Request::post('value', '-');
+ if ($val !== '1' && $val !== '0')
+ die('Nein');
+ if ($option === 'setorglogin') {
+ $field = 'canlogin';
+ } else {
+ die('Unknown');
+ }
+ $ret = Database::exec("UPDATE sat.organization SET $field = :onoff WHERE organizationid = :organizationid", array(
+ 'organizationid' => (string) Request::post('organizationid', ''),
+ 'onoff' => $val
+ ));
+ if ($ret === false)
+ die('Error');
+ if ($ret === 0)
+ die(1 - $val);
+ die($val);
+ }
+
+} \ No newline at end of file
diff --git a/modules-available/dozmod/inc/pagemailtemplates.inc.php b/modules-available/dozmod/inc/pagemailtemplates.inc.php
index 73ce0ade..ef52ec12 100644
--- a/modules-available/dozmod/inc/pagemailtemplates.inc.php
+++ b/modules-available/dozmod/inc/pagemailtemplates.inc.php
@@ -7,13 +7,6 @@ class Page_mail_templates extends Page
protected function doPreprocess()
{
- User::load();
-
- if (!User::hasPermission('superadmin')) {
- Message::addError('main.no-permission');
- Util::redirect('?do=Main');
- }
-
$action = Request::post('action', 'show', 'string');
if ($action === 'show') {
$this->fetchTemplates();
diff --git a/modules-available/dozmod/lang/de/module.json b/modules-available/dozmod/lang/de/module.json
index 3ab1062d..5840d8af 100644
--- a/modules-available/dozmod/lang/de/module.json
+++ b/modules-available/dozmod/lang/de/module.json
@@ -1,6 +1,7 @@
{
"module_name": "bwLehrpool-Suite",
"page_title": "Verwalten der bwLehrpool-Suite",
+ "submenu_actionlog": "Aktions-Log",
"submenu_mailconfig": "Email-Konfiguration",
"submenu_runtime": "Limits und Standardwerte",
"submenu_templates": "Textbausteine f\u00fcr E-Mails",
diff --git a/modules-available/dozmod/lang/de/template-tags.json b/modules-available/dozmod/lang/de/template-tags.json
index 18198ab8..fe558ed5 100644
--- a/modules-available/dozmod/lang/de/template-tags.json
+++ b/modules-available/dozmod/lang/de/template-tags.json
@@ -1,6 +1,9 @@
{
+ "lang_actionTarget": "Aktionsziel",
"lang_asteriskRequired": "Felder mit (*) sind erforderlich",
"lang_canLogin": "Nutzer dieser Einrichtung k\u00f6nnen sich am Satelliten anmelden",
+ "lang_createTime": "Erstellt",
+ "lang_currentFilter": "Aktueller Filter",
"lang_defaultImagePermissionAdmin": "Administrieren",
"lang_defaultImagePermissionDownload": "Download",
"lang_defaultImagePermissionEdit": "Bearbeiten",
@@ -13,15 +16,19 @@
"lang_descriptionPermissionConfig": "Dies sind die Berechtigungen, die ein Benutzer standardm\u00e4\u00dfig f\u00fcr fremde VMs\/Veranstaltungen hat. Sie werden angewandt, wenn der Besitzer keine anderweitigen Berechtigungen w\u00e4hlt.",
"lang_descriptionRuntimeLimits": "Hier k\u00f6nnen Sie verschiedene Limits festlegen, z.B. wie lange eine VM nach dem Hochladen g\u00fcltig ist. Nach Ablauf dieses Zeitraums ist der Verantwortliche gezwungen, eine neue Version der VM hochzuladen. Damit k\u00f6nnen Sie das Ansammeln nicht mehr ben\u00f6tigter VMs eind\u00e4mmen. Weiterhin k\u00f6nnen Sie die maximale Anzahl gleichzeitiger Transfers pro Benutzer einschr\u00e4nken.",
"lang_description_delete_images": "Diese Liste zeigt VMs, 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_dozmodLogHeading": "bwLehrpool-Suite Aktionslog",
"lang_email": "EMail",
"lang_emailNotifications": "EMail-Benachrichtigungen aktiviert",
"lang_error": "Fehler",
+ "lang_event": "Ereignis",
"lang_followingPlaceholdersUnused": "Folgende Platzhalter m\u00fcssen im Template verwendet werden",
"lang_hasNewer": "Neuere Version existiert",
"lang_heading": "Zu l\u00f6schende VM-Versionen",
"lang_host": "Host",
"lang_image": "VM",
+ "lang_lastEditor": "Zuletzt bearbeitet von",
"lang_lastLogin": "Letzte Anmeldung",
+ "lang_lecture": "Veranstaltung",
"lang_lecturePermissionAdmin": "Administration",
"lang_lecturePermissionEdit": "Bearbeiten",
"lang_loadDefaults": "Alle Texte auf Auslieferungszustand zur\u00fccksetzen",
@@ -36,6 +43,7 @@
"lang_organization": "Einrichtung",
"lang_organizationList": "Liste der Einrichtungen",
"lang_organizationListHeader": "Nutzungsrechte f\u00fcr den Satelliten festlegen",
+ "lang_os": "Betriebssystem",
"lang_owner": "Besitzer",
"lang_password": "Passwort",
"lang_placeholders": "Platzhalter",
@@ -54,15 +62,19 @@
"lang_sslNone": "Kein SSL",
"lang_subHeading": "Images, die abgelaufen oder besch\u00e4digt sind",
"lang_superUser": "Ist SuperUser (darf alle Veranstaltungen und VMs bearbeiten\/l\u00f6schen)",
+ "lang_system": "System",
"lang_template": "Template",
"lang_templatePageDescription": "Hier k\u00f6nnen Sie die Textbausteine bearbeiten, aus denen die Mails generiert werden, die der bwLehrpool-Server bez\u00fcglich Virtueller Maschinen und Veranstaltungen versendet. Diese Funktionalit\u00e4t unterst\u00fctzt zur Zeit keine Internationalisierung.",
"lang_test": "Test-Mail senden",
"lang_testConfiguration": "Um die Konfiguration zu testen, geben Sie hier eine Empf\u00e4ngeradresse ein",
"lang_testRecipient": "Empf\u00e4nger",
+ "lang_updateTime": "Letzte Bearbeitung",
"lang_user": "Benutzername",
+ "lang_userId": "Benutzer-ID",
"lang_userList": "Benutzerliste",
"lang_userListDescription": "Hier k\u00f6nnen Sie individuelle Nutzer zu \"Super-Usern\" machen. Diese haben im Dozentenmodul auf alle Veranstaltungen und VMs Vollzugriff, unabh\u00e4ngig von den gesetzten Berechtigungen. Au\u00dferdem k\u00f6nnen Sie hier Benutzer vom Zugriff mittels des Dozentenmoduls ausschlie\u00dfen.",
"lang_userListHeader": "Dem Satelliten bekannte Benutzer",
"lang_username": "Benutzername (SMTP-Auth)",
- "lang_version": "Version vom"
+ "lang_version": "Version vom",
+ "lang_when": "Wann"
} \ No newline at end of file
diff --git a/modules-available/dozmod/lang/en/module.json b/modules-available/dozmod/lang/en/module.json
index c54d9784..742aa848 100644
--- a/modules-available/dozmod/lang/en/module.json
+++ b/modules-available/dozmod/lang/en/module.json
@@ -1,6 +1,7 @@
{
"module_name": "bwLehrpool-Suite",
"page_title": "Manage the bwLehrpool-Suite",
+ "submenu_actionlog": "action log",
"submenu_mailconfig": "email configuration",
"submenu_runtime": "limits and defaults",
"submenu_templates": "templates",
diff --git a/modules-available/dozmod/lang/en/template-tags.json b/modules-available/dozmod/lang/en/template-tags.json
index dd7f9391..6a0434a3 100644
--- a/modules-available/dozmod/lang/en/template-tags.json
+++ b/modules-available/dozmod/lang/en/template-tags.json
@@ -1,6 +1,9 @@
{
+ "lang_actionTarget": "Action target",
"lang_asteriskRequired": "Fields marked with (*) are required",
"lang_canLogin": "Members of this organization can login",
+ "lang_createTime": "Created",
+ "lang_currentFilter": "Current filter",
"lang_defaultImagePermissionAdmin": "Administrate",
"lang_defaultImagePermissionDownload": "Download",
"lang_defaultImagePermissionEdit": "Edit",
@@ -13,15 +16,19 @@
"lang_descriptionPermissionConfig": "These are the default permissions being used for VMs and lectures if the owner does not specify any.",
"lang_descriptionRuntimeLimits": "Here you can define some limits, e.g. how long a newly uploaded VM will be valid. This should make sure that you don't end up with a lot of old, unused VMs over time.",
"lang_description_delete_images": "This is a list of VMs that either expired, or where the disk image is damaged or missing. These VMs are not available in bwLehrpool currently, but you have to manually confirm the deletion of the disk images for safety reasons (clock skew etc.)",
+ "lang_dozmodLogHeading": "bwLehrpool-Suite action log",
"lang_email": "E-Mail",
"lang_emailNotifications": "E-Mail notifications enabled",
"lang_error": "Error",
+ "lang_event": "Event",
"lang_followingPlaceholdersUnused": "The following placeholders are not being used",
"lang_hasNewer": "Newer version exists",
"lang_heading": "Images marked for deletion",
"lang_host": "Host",
"lang_image": "VM",
+ "lang_lastEditor": "Edited by",
"lang_lastLogin": "Last login",
+ "lang_lecture": "Lecture",
"lang_lecturePermissionAdmin": "Administrate",
"lang_lecturePermissionEdit": "Edit",
"lang_loadDefaults": "Reset all templates to their defaults",
@@ -36,6 +43,7 @@
"lang_organization": "Organization",
"lang_organizationList": "List of organizations",
"lang_organizationListHeader": "Set access permissions for organizations",
+ "lang_os": "Operating System",
"lang_owner": "Owner",
"lang_password": "Password",
"lang_placeholders": "Placeholders",
@@ -54,15 +62,19 @@
"lang_sslNone": "No SSL",
"lang_subHeading": "Expired or damaged images",
"lang_superUser": "Is super user (can edit\/delete all lectures and VMs)",
+ "lang_system": "System",
"lang_template": "Template",
"lang_templatePageDescription": "Here you can edit text fragments that are used to compose the information and reminder mails sent by the bwLehrpool server, e.g. when a lecture or VM is about to expire.",
"lang_test": "Send test mail",
"lang_testConfiguration": "To test the configuration, enter a recipient address here",
"lang_testRecipient": "Recipient",
+ "lang_updateTime": "Last update",
"lang_user": "User name",
+ "lang_userId": "User id",
"lang_userList": "User list",
"lang_userListDescription": "Here you can promote \"super users\", which will have all permissions in the \"Dozenzenmodul\". You can also ban users from accessing this server via the \"Dozentenmodul\".",
"lang_userListHeader": "Users known to this satellite",
"lang_username": "User name (SMTP auth)",
- "lang_version": "Version timestamp"
+ "lang_version": "Version timestamp",
+ "lang_when": "When"
} \ No newline at end of file
diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php
index 9272f9ff..7bed2380 100644
--- a/modules-available/dozmod/page.inc.php
+++ b/modules-available/dozmod/page.inc.php
@@ -2,8 +2,26 @@
class Page_DozMod extends Page
{
- /* sub page classes */
- private $mail_templates;
+ /** @var \Page sub page classes */
+ private $subPage = false;
+
+ private function setupSubPage()
+ {
+ if ($this->subPage !== false)
+ return;
+ /* different pages for different sections */
+ $section = Request::any('section', 'mailconfig', 'string');
+ /* instantiate sub pages */
+ if ($section === 'templates') {
+ $this->subPage = new Page_mail_templates();
+ }
+ if ($section === 'users') {
+ $this->subPage = new Page_dozmod_users();
+ }
+ if ($section === 'actionlog') {
+ $this->subPage = new Page_dozmod_log();
+ }
+ }
protected function doPreprocess()
{
@@ -19,16 +37,11 @@ class Page_DozMod extends Page
Dashboard::addSubmenu('?do=dozmod&section=templates', Dictionary::translate('submenu_templates', true));
Dashboard::addSubmenu('?do=dozmod&section=runtimeconfig', Dictionary::translate('submenu_runtime', true));
Dashboard::addSubmenu('?do=dozmod&section=users', Dictionary::translate('submenu_users', true));
+ Dashboard::addSubmenu('?do=dozmod&section=actionlog', Dictionary::translate('submenu_actionlog', true));
- /* 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();
+ $this->setupSubPage();
+ if ($this->subPage !== false) {
+ $this->subPage->doPreprocess();
return;
}
@@ -52,15 +65,15 @@ class Page_DozMod extends Page
protected function doRender()
{
+ $this->listDeletePendingImages();
+
/* different pages for different sections */
- $section = Request::get('section', 'mailconfig', 'string');
- if ($section == 'templates') {
- $this->mail_templates->doRender();
+ if ($this->subPage !== false) {
+ $this->subPage->doRender();
return;
}
-
- $this->listDeletePendingImages();
+ $section = Request::get('section', 'mailconfig', 'string');
if ($section === 'mailconfig') {
// Mail config
@@ -103,11 +116,6 @@ class Page_DozMod extends Page
Render::addTemplate('runtimeconfig', $runtimeConf);
}
- // User list for making people admin
- if ($section === 'users') {
- $this->listUsers();
- $this->listOrganizations();
- }
}
private function listDeletePendingImages()
@@ -159,16 +167,19 @@ class Page_DozMod extends Page
protected function doAjax()
{
+ User::load();
if (!User::hasPermission('superadmin'))
return;
+ $this->setupSubPage();
+ if ($this->subPage !== false) {
+ $this->subPage->doAjax();
+ return;
+ }
+
$action = Request::post('action');
if ($action === 'mail') {
$this->handleTestMail();
- } elseif ($action === 'setmail' || $action === 'setsu' || $action == 'setlogin') {
- $this->setUserOption($action);
- } elseif ($action === 'setorglogin') {
- $this->setOrgOption($action);
} elseif ($action === 'delimages') {
die($this->handleDeleteImages());
}
@@ -282,88 +293,4 @@ class Page_DozMod extends Page
Util::redirect('?do=DozMod&section=runtimeconfig');
}
- private function listUsers()
- {
- $res = Database::simpleQuery('SELECT userid, firstname, lastname, email, lastlogin, user.canlogin, issuperuser, emailnotifications,'
- . ' organization.displayname AS orgname FROM sat.user'
- . ' LEFT JOIN sat.organization USING (organizationid)'
- . ' ORDER BY lastname ASC, firstname ASC');
- $rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $row['canlogin'] = $this->checked($row['canlogin']);
- $row['issuperuser'] = $this->checked($row['issuperuser']);
- $row['emailnotifications'] = $this->checked($row['emailnotifications']);
- $row['lastlogin'] = date('d.m.Y', $row['lastlogin']);
- $rows[] = $row;
- }
- Render::addTemplate('userlist', array('users' => $rows));
- }
-
- private function listOrganizations()
- {
- $res = Database::simpleQuery('SELECT organizationid, displayname, canlogin FROM sat.organization'
- . ' ORDER BY displayname ASC');
- $rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $row['canlogin'] = $this->checked($row['canlogin']);
- $rows[] = $row;
- }
- Render::addTemplate('orglist', array('organizations' => $rows));
- }
-
- private function checked($val)
- {
- if ($val)
- return 'checked="checked"';
- return '';
- }
-
- private function setUserOption($option)
- {
- $val = (string) Request::post('value', '-');
- if ($val !== '1' && $val !== '0')
- die('Nein');
- if ($option === 'setmail') {
- $field = 'emailnotifications';
- } elseif ($option === 'setsu') {
- $field = 'issuperuser';
- } elseif ($option === 'setlogin') {
- $field = 'canlogin';
- } else {
- die('Unknown');
- }
- $user = (string) Request::post('userid', '?');
- $ret = Database::exec("UPDATE sat.user SET $field = :onoff WHERE userid = :userid", array(
- 'userid' => $user,
- 'onoff' => $val
- ));
- error_log("Setting $field to $val for $user - affected: $ret");
- if ($ret === false)
- die('Error');
- if ($ret == 0)
- die(1 - $val);
- die($val);
- }
-
- private function setOrgOption($option)
- {
- $val = (string) Request::post('value', '-');
- if ($val !== '1' && $val !== '0')
- die('Nein');
- if ($option === 'setorglogin') {
- $field = 'canlogin';
- } else {
- die('Unknown');
- }
- $ret = Database::exec("UPDATE sat.organization SET $field = :onoff WHERE organizationid = :organizationid", array(
- 'organizationid' => (string) Request::post('organizationid', ''),
- 'onoff' => $val
- ));
- if ($ret === false)
- die('Error');
- if ($ret === 0)
- die(1 - $val);
- die($val);
- }
-
}
diff --git a/modules-available/dozmod/templates/actionlog-header.html b/modules-available/dozmod/templates/actionlog-header.html
new file mode 100644
index 00000000..bb32efda
--- /dev/null
+++ b/modules-available/dozmod/templates/actionlog-header.html
@@ -0,0 +1 @@
+<h2>{{lang_dozmodLogHeading}}</h2> \ No newline at end of file
diff --git a/modules-available/dozmod/templates/actionlog-image.html b/modules-available/dozmod/templates/actionlog-image.html
new file mode 100644
index 00000000..cd8c8d1d
--- /dev/null
+++ b/modules-available/dozmod/templates/actionlog-image.html
@@ -0,0 +1,30 @@
+<h3>{{lang_currentFilter}}</h3>
+<table class="table table-bordered table-striped" style="width: auto">
+ <tr>
+ <th class="text-nowrap">{{lang_image}}</th>
+ <td>{{displayname}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_os}}</th>
+ <td>{{osname}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_owner}}</th>
+ <td><a href="?do=dozmod&amp;section=actionlog&amp;action=showuser&amp;uuid={{ouserid}}">{{ofirstname}} {{olastname}}</a></td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_lastEditor}}</th>
+ <td><a href="?do=dozmod&amp;section=actionlog&amp;action=showuser&amp;uuid={{uuserid}}">{{ufirstname}} {{ulastname}}</a></td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_createTime}}</th>
+ <td>{{createtime_s}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_updateTime}}</th>
+ <td>{{updatetime_s}}</td>
+ </tr>
+ <tr>
+ <td colspan="2">{{{descriptionHtml}}}</td>
+ </tr>
+</table> \ No newline at end of file
diff --git a/modules-available/dozmod/templates/actionlog-lecture.html b/modules-available/dozmod/templates/actionlog-lecture.html
new file mode 100644
index 00000000..4fb2b4d0
--- /dev/null
+++ b/modules-available/dozmod/templates/actionlog-lecture.html
@@ -0,0 +1,30 @@
+<h3>{{lang_currentFilter}}</h3>
+<table class="table table-bordered table-striped" style="width: auto">
+ <tr>
+ <th class="text-nowrap">{{lang_lecture}}</th>
+ <td>{{displayname}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_owner}}</th>
+ <td><a href="?do=dozmod&amp;section=actionlog&amp;action=showuser&amp;uuid={{ouserid}}">{{ofirstname}} {{olastname}}</a></td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_lastEditor}}</th>
+ <td><a href="?do=dozmod&amp;section=actionlog&amp;action=showuser&amp;uuid={{uuserid}}">{{ufirstname}} {{ulastname}}</a></td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_createTime}}</th>
+ <td>{{createtime_s}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_updateTime}}</th>
+ <td>{{updatetime_s}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_image}}</th>
+ <td><a href="?do=dozmod&amp;section=actionlog&amp;action=showtarget&amp;uuid={{imagebaseid}}">{{imgname}}</a></td>
+ </tr>
+ <tr>
+ <td colspan="2">{{{descriptionHtml}}}</td>
+ </tr>
+</table> \ No newline at end of file
diff --git a/modules-available/dozmod/templates/actionlog-log.html b/modules-available/dozmod/templates/actionlog-log.html
new file mode 100644
index 00000000..3b523899
--- /dev/null
+++ b/modules-available/dozmod/templates/actionlog-log.html
@@ -0,0 +1,41 @@
+<table class="table table-striped table-bordered">
+ <tr>
+ <th class="text-nowrap">{{lang_when}}</th>
+ {{#showActor}}
+ <th class="text-nowrap">{{lang_user}}</th>
+ {{/showActor}}
+ {{#showTarget}}
+ <th class="text-nowrap">{{lang_actionTarget}}</th>
+ {{/showTarget}}
+ <th class="text-nowrap">{{lang_event}}</th>
+ </tr>
+ {{#events}}
+ <tr>
+ <td>{{dateline_s}}</td>
+ {{#showActor}}
+ <td>
+ {{#uuserid}}
+ <a href="?do=dozmod&amp;section=actionlog&amp;action=showuser&amp;uuid={{uuserid}}">{{ulastname}}, {{ufirstname}}</a>
+ {{/uuserid}}
+ {{^uuserid}}
+ {{lang_system}}
+ {{/uuserid}}
+ </td>
+ {{/showActor}}
+ {{#showTarget}}
+ <td>
+ {{#targeturl}}
+ <a href="{{targeturl}}">{{targetname}}</a>
+ {{/targeturl}}
+ {{^targeturl}}
+ {{targetname}}
+ {{^targetname}}
+ <span class="small">{{targetid}}</span>
+ {{/targetname}}
+ {{/targeturl}}
+ </td>
+ {{/showTarget}}
+ <td>{{description}}</td>
+ </tr>
+ {{/events}}
+</table> \ No newline at end of file
diff --git a/modules-available/dozmod/templates/actionlog-user.html b/modules-available/dozmod/templates/actionlog-user.html
new file mode 100644
index 00000000..eefe1386
--- /dev/null
+++ b/modules-available/dozmod/templates/actionlog-user.html
@@ -0,0 +1,23 @@
+<h3>{{lang_currentFilter}}</h3>
+<table class="table table-bordered table-striped" style="width: auto">
+ <tr>
+ <th class="text-nowrap">{{lang_user}}</th>
+ <td>{{firstname}} {{lastname}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_userId}}</th>
+ <td>{{userid}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_organization}}</th>
+ <td>{{orgname}}</td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_email}}</th>
+ <td><a href="mailto:{{email}}">{{email}}</a></td>
+ </tr>
+ <tr>
+ <th class="text-nowrap">{{lang_lastLogin}}</th>
+ <td>{{lastlogin_s}}</td>
+ </tr>
+</table> \ No newline at end of file
diff --git a/modules-available/dozmod/templates/orglist.html b/modules-available/dozmod/templates/orglist.html
index 34fa039c..bb002b3b 100644
--- a/modules-available/dozmod/templates/orglist.html
+++ b/modules-available/dozmod/templates/orglist.html
@@ -35,33 +35,35 @@ function seto(action, el, orgid) {
var v = el.checked ? '1' : '0';
var old = el.checked == true;
box.css('display', 'none');
- $.post('?do=DozMod', { token: TOKEN, action: action, organizationid: orgid, value: v }).done(function (data) {
- if (data != 1 && data != 0) {
+ $.post('?do=DozMod', { token: TOKEN, section: 'users', action: action, organizationid: orgid, value: v }).done(function (data) {
+
+ if (data !== '1' && data !== '0') {
el.checked = !old;
box.parent().css('background-color', 'red !important');
} else {
el.checked = (data == 1);
+ box.parent().css('background-color', '');
+ /* 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('fast', function () {
+ $notification.fadeOut('slow', function () { $notification.remove() });
+ });
}
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');
box.css('display', '');
+
});
}
diff --git a/modules-available/dozmod/templates/userlist.html b/modules-available/dozmod/templates/userlist.html
index 79d4848b..7dd84fd4 100644
--- a/modules-available/dozmod/templates/userlist.html
+++ b/modules-available/dozmod/templates/userlist.html
@@ -22,7 +22,7 @@
<tbody>
{{#users}}
<tr>
- <td class="text-left slx-nowrap">{{lastname}}, {{firstname}}</td>
+ <td class="text-left slx-nowrap"><a href="?do=dozmod&amp;section=actionlog&amp;action=showuser&amp;uuid={{userid}}">{{lastname}}, {{firstname}}</a></td>
<td class="text-left slx-nowrap">{{orgname}}</td>
<td class="text-left slx-nowrap">{{lastlogin}}</td>
<td class="text-left slx-nowrap"><a href="mailto:{{email}}">{{email}}</a></td>
@@ -44,29 +44,35 @@ function setu(action, el, uid) {
var v = el.checked ? '1' : '0';
var old = el.checked == true;
box.css('display', 'none');
- $.post('?do=DozMod', { token: TOKEN, action: action, userid: uid, value: v }).done(function (data) {
- if (data != 1 && data != 0) {
+ $.post('?do=DozMod', { token: TOKEN, section: 'users', action: action, userid: uid, value: v }).done(function (data) {
+
+ if (data !== '1' && data !== '0') {
el.checked = !old;
box.parent().css('background-color', 'red !important');
} else {
el.checked = (data == 1);
+ box.parent().css('background-color', '');
+ /* 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('fast', function () {
+ $notification.fadeOut('slow', function () { $notification.remove() });
+ });
}
- /* 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;
box.parent().css('background-color', 'red !important');
box.css('display', '');
+
});
}