From e529743b9c18838cc6eedbaa85c17456f9dbb279 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 10 Sep 2015 18:52:17 +0200 Subject: Add org list to dozmod module --- lang/de/messages.json | 1 + lang/de/templates/dozmod/mailconfig.json | 20 +++++++ lang/de/templates/dozmod/orglist.json | 6 +++ lang/de/templates/dozmod/userlist.json | 11 ++++ lang/de/templates/main-menu.json | 1 + lang/en/messages.json | 1 + lang/en/templates/dozmod/mailconfig.json | 20 +++++++ lang/en/templates/dozmod/orglist.json | 6 +++ lang/en/templates/dozmod/userlist.json | 11 ++++ lang/en/templates/main-menu.json | 1 + lang/pt/templates/dozmod/mailconfig.json | 3 ++ lang/pt/templates/dozmod/orglist.json | 3 ++ lang/pt/templates/dozmod/userlist.json | 3 ++ modules/dozmod.inc.php | 84 ++++++++++++++++++++++++++--- templates/dozmod/orglist.html | 51 ++++++++++++++++++ templates/dozmod/userlist.html | 91 +++++++++++++++++++++----------- templates/main-menu.html | 3 ++ 17 files changed, 277 insertions(+), 39 deletions(-) create mode 100644 lang/de/templates/dozmod/mailconfig.json create mode 100644 lang/de/templates/dozmod/orglist.json create mode 100644 lang/de/templates/dozmod/userlist.json create mode 100644 lang/en/templates/dozmod/mailconfig.json create mode 100644 lang/en/templates/dozmod/orglist.json create mode 100644 lang/en/templates/dozmod/userlist.json create mode 100644 lang/pt/templates/dozmod/mailconfig.json create mode 100644 lang/pt/templates/dozmod/orglist.json create mode 100644 lang/pt/templates/dozmod/userlist.json create mode 100644 templates/dozmod/orglist.html diff --git a/lang/de/messages.json b/lang/de/messages.json index 7e449f8d..eddc564a 100644 --- a/lang/de/messages.json +++ b/lang/de/messages.json @@ -24,6 +24,7 @@ "invalid-path": "Ung\u00fcltiger Pfad.", "invalid-template": "Ausgew\u00e4hlte Template ist nicht g\u00fcltig", "loginfail": "Benutzername oder Kennwort falsch", + "mail-config-saved": "Mail-Konfiguration gespeichert", "missing-file": "Es wurde keine Datei ausgew\u00e4hlt!", "missing-title": "Kein Titel eingegeben", "module-added": "Modul erfolgreich hinzugef\u00fcgt", diff --git a/lang/de/templates/dozmod/mailconfig.json b/lang/de/templates/dozmod/mailconfig.json new file mode 100644 index 00000000..dde03c55 --- /dev/null +++ b/lang/de/templates/dozmod/mailconfig.json @@ -0,0 +1,20 @@ +{ + "lang_asteriskRequired": "Felder mit (*) sind erforderlich", + "lang_host": "Host", + "lang_mailConfig": "SMTP-Konfiguration zum Versenden von Mails", + "lang_mailConfigHeadline": "EMail-Konfiguration", + "lang_password": "Passwort", + "lang_port": "Port", + "lang_replyTo": "Reply-To Adresse (z.B. Helpdesk)", + "lang_save": "Konfiguration speichern", + "lang_senderAddress": "Absenderadresse", + "lang_senderName": "Absender Anzeigename", + "lang_ssl": "SSL-Modus", + "lang_sslExplicit": "Explizites SSL (\"STARTTLS\")", + "lang_sslImplicit": "Implizites SSL", + "lang_sslNone": "Kein SSL", + "lang_test": "Test-Mail senden", + "lang_testConfiguration": "Um die Konfiguration zu testen, geben Sie hier eine Empf\u00e4ngeradresse ein", + "lang_testRecipient": "Empf\u00e4nger", + "lang_username": "Benutzername (SMTP-Auth)" +} \ No newline at end of file diff --git a/lang/de/templates/dozmod/orglist.json b/lang/de/templates/dozmod/orglist.json new file mode 100644 index 00000000..938429f0 --- /dev/null +++ b/lang/de/templates/dozmod/orglist.json @@ -0,0 +1,6 @@ +{ + "lang_canLogin": "Nutzer dieser Einrichtung k\u00f6nnen sich am Satelliten anmelden", + "lang_organization": "Einrichtung", + "lang_organizationList": "Liste der Einrichtungen", + "lang_organizationListHeader": "Nutzungsrechte f\u00fcr den Satelliten festlegen" +} \ No newline at end of file diff --git a/lang/de/templates/dozmod/userlist.json b/lang/de/templates/dozmod/userlist.json new file mode 100644 index 00000000..5c9a0f5f --- /dev/null +++ b/lang/de/templates/dozmod/userlist.json @@ -0,0 +1,11 @@ +{ + "lang_canLogin": "Dieser Benutzer kann sich am Satelilten anmelden", + "lang_email": "EMail", + "lang_emailNotifications": "EMail-Benachrichtigungen aktiviert", + "lang_lastLogin": "Letzte Anmeldung", + "lang_organization": "Organisation", + "lang_superUser": "Ist SuperUser (darf alle Veranstaltungen und VMs bearbeiten\/l\u00f6schen)", + "lang_user": "Benutzername", + "lang_userList": "Benutzerliste", + "lang_userListHeader": "Dem Satelliten bekannte Benutzer" +} \ No newline at end of file diff --git a/lang/de/templates/main-menu.json b/lang/de/templates/main-menu.json index 98896969..efd918a3 100644 --- a/lang/de/templates/main-menu.json +++ b/lang/de/templates/main-menu.json @@ -4,6 +4,7 @@ "lang_clientLog": "Client Log", "lang_configurationBasic": "PXE\/Boot", "lang_configurationVariables": "KonfigurationsVariablen", + "lang_dozmod": "Dozentenmodul", "lang_eventLog": "Server Log", "lang_internetAccess": "Internetzugriff", "lang_language": "Sprachen", diff --git a/lang/en/messages.json b/lang/en/messages.json index 10314625..a18d2287 100644 --- a/lang/en/messages.json +++ b/lang/en/messages.json @@ -24,6 +24,7 @@ "invalid-path": "Invalid path.", "invalid-template": "Selected template is not valid", "loginfail": "Username or Password incorrect", + "mail-config-saved": "Mail config saved", "missing-file": "There was no file selected!", "missing-title": "No title given", "module-added": "Module successfully added", diff --git a/lang/en/templates/dozmod/mailconfig.json b/lang/en/templates/dozmod/mailconfig.json new file mode 100644 index 00000000..7628615e --- /dev/null +++ b/lang/en/templates/dozmod/mailconfig.json @@ -0,0 +1,20 @@ +{ + "lang_asteriskRequired": "Fields marked with (*) are required", + "lang_host": "Host", + "lang_mailConfig": "SMTP configuration for sending mails", + "lang_mailConfigHeadline": "email configuration", + "lang_password": "Password", + "lang_port": "Port", + "lang_replyTo": "Reply-To address", + "lang_save": "Save configuration", + "lang_senderAddress": "Sender address", + "lang_senderName": "Sender's display name", + "lang_ssl": "SSL mode", + "lang_sslExplicit": "Explicit SSL (\"STARTTLS\")", + "lang_sslImplicit": "Implicit SSL", + "lang_sslNone": "No SSL", + "lang_test": "Send test mail", + "lang_testConfiguration": "To test the configuration, enter a recipient address here", + "lang_testRecipient": "Recipient", + "lang_username": "User name (SMTP auth)" +} \ No newline at end of file diff --git a/lang/en/templates/dozmod/orglist.json b/lang/en/templates/dozmod/orglist.json new file mode 100644 index 00000000..37b89e02 --- /dev/null +++ b/lang/en/templates/dozmod/orglist.json @@ -0,0 +1,6 @@ +{ + "lang_canLogin": "Members of this organization can login", + "lang_organization": "Organization", + "lang_organizationList": "List of organizations", + "lang_organizationListHeader": "Set access permissions for organizations" +} \ No newline at end of file diff --git a/lang/en/templates/dozmod/userlist.json b/lang/en/templates/dozmod/userlist.json new file mode 100644 index 00000000..d6eca1c1 --- /dev/null +++ b/lang/en/templates/dozmod/userlist.json @@ -0,0 +1,11 @@ +{ + "lang_canLogin": "This user can login to this satellite", + "lang_email": "E-Mail", + "lang_emailNotifications": "E-Mail notifications enabled", + "lang_lastLogin": "Last login", + "lang_organization": "Organization", + "lang_superUser": "Is super user (can edit\/delete all lectures and VMs)", + "lang_user": "User name", + "lang_userList": "User list", + "lang_userListHeader": "Users known to this satellite" +} \ No newline at end of file diff --git a/lang/en/templates/main-menu.json b/lang/en/templates/main-menu.json index 4cb9cb74..839d65b1 100644 --- a/lang/en/templates/main-menu.json +++ b/lang/en/templates/main-menu.json @@ -4,6 +4,7 @@ "lang_clientLog": "Client Log", "lang_configurationBasic": "PXE\/Boot", "lang_configurationVariables": "Configuration Variables", + "lang_dozmod": "Tutor module", "lang_eventLog": "Server Log", "lang_internetAccess": "Internet access", "lang_language": "Language", diff --git a/lang/pt/templates/dozmod/mailconfig.json b/lang/pt/templates/dozmod/mailconfig.json new file mode 100644 index 00000000..c44dc44f --- /dev/null +++ b/lang/pt/templates/dozmod/mailconfig.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file diff --git a/lang/pt/templates/dozmod/orglist.json b/lang/pt/templates/dozmod/orglist.json new file mode 100644 index 00000000..c44dc44f --- /dev/null +++ b/lang/pt/templates/dozmod/orglist.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file diff --git a/lang/pt/templates/dozmod/userlist.json b/lang/pt/templates/dozmod/userlist.json new file mode 100644 index 00000000..c44dc44f --- /dev/null +++ b/lang/pt/templates/dozmod/userlist.json @@ -0,0 +1,3 @@ +[ + +] \ No newline at end of file diff --git a/modules/dozmod.inc.php b/modules/dozmod.inc.php index a4fbf57c..cec1c114 100644 --- a/modules/dozmod.inc.php +++ b/modules/dozmod.inc.php @@ -16,8 +16,6 @@ class Page_DozMod extends Page if ($action === 'mail') { $this->mailHandler(); - } else if ($action === 'setuser') { - $this->makeAdmin(); } } @@ -34,6 +32,7 @@ class Page_DozMod extends Page Render::addTemplate('dozmod/mailconfig', $conf); // User list for making people admin $this->listUsers(); + $this->listOrganizations(); } private function cleanMailArray() @@ -51,6 +50,21 @@ class Page_DozMod extends Page } protected function doAjax() + { + if (!User::hasPermission('superadmin')) + 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); + } + } + + private function handleTestMail() { $do = Request::post('button'); if ($do === 'test') { @@ -94,7 +108,7 @@ class Page_DozMod extends Page . ' ORDER BY lastname ASC, firstname ASC'); $rows = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $row['isbanned'] = $this->checked($row['canlogin'] == 0); + $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']); @@ -102,16 +116,72 @@ class Page_DozMod extends Page } Render::addTemplate('dozmod/userlist', array('users' => $rows)); } - - private function checked($val) { + + 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('dozmod/orglist', array('organizations' => $rows)); + } + + private function checked($val) + { if ($val) return 'checked="checked"'; return ''; } - private function makeAdmin() + 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/templates/dozmod/orglist.html b/templates/dozmod/orglist.html new file mode 100644 index 00000000..d325cc4d --- /dev/null +++ b/templates/dozmod/orglist.html @@ -0,0 +1,51 @@ +

{{lang_organizationList}}

+ +
+
+ {{lang_organizationListHeader}} +
+
+
+ + + + + + + + + {{#organizations}} + + + + + {{/organizations}} + +
{{lang_organization}}
{{displayname}}
+
+
+
+ + \ No newline at end of file diff --git a/templates/dozmod/userlist.html b/templates/dozmod/userlist.html index addb7edf..7fe52acc 100644 --- a/templates/dozmod/userlist.html +++ b/templates/dozmod/userlist.html @@ -1,34 +1,61 @@

{{lang_userList}}

-
-
- - - - - - - - - - - - - - - - {{#users}} - - - - - - - - - - {{/users}} - -
{{lang_user}}{{lang_organization}}{{lang_lastLogin}}{{lang_email}}
{{lastname}}, {{firstname}}{{orgname}}{{lastlogin}}{{email}}
-
-
\ No newline at end of file +
+
+ {{lang_userListHeader}} +
+
+
+ + + + + + + + + + + + + + {{#users}} + + + + + + + + + + {{/users}} + +
{{lang_user}}{{lang_organization}}{{lang_lastLogin}}{{lang_email}}
{{lastname}}, {{firstname}}{{orgname}}{{lastlogin}}{{email}}
+
+
+
+ + \ No newline at end of file diff --git a/templates/main-menu.html b/templates/main-menu.html index 77d5d5ee..57576fd7 100644 --- a/templates/main-menu.html +++ b/templates/main-menu.html @@ -36,6 +36,9 @@
  • {{lang_eventLog}}
  • +
  • + {{lang_dozmod}} +