summaryrefslogtreecommitdiffstats
path: root/modules-available/dozmod/inc/pagedozmodusers.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-08-16 18:05:29 +0200
committerSimon Rettberg2016-08-16 18:05:29 +0200
commitbf3bb604fa82e0738fdb21d9bd4fd07000ed35bd (patch)
treed89f1aff06f9374ea44587542c3fd319cc727187 /modules-available/dozmod/inc/pagedozmodusers.inc.php
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
Diffstat (limited to 'modules-available/dozmod/inc/pagedozmodusers.inc.php')
-rw-r--r--modules-available/dozmod/inc/pagedozmodusers.inc.php115
1 files changed, 115 insertions, 0 deletions
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