From d955f2d0837ca4c145546f56a8fe0d3a87f59052 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 7 Jul 2018 15:30:19 +0200 Subject: [PATCH] login/edit: apply tags input to target links Allow admins to change user presence in listed tags. --- login/edit.php | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/login/edit.php b/login/edit.php index 759eba5..894264b 100644 --- a/login/edit.php +++ b/login/edit.php @@ -59,7 +59,18 @@ if (file_exists($tagdir)) { foreach (glob("$tagdir/*") as $tag) { $tagname = pathinfo($tag, PATHINFO_BASENAME); $target = "$tag/{$user['name']}"; - $tags[$tagname] = file_exists($tagname); + $val = file_exists($target); + $tags[$tagname] = ['value' => $val]; + if (empty($User['admin'])) { + continue; # forbidden + } + if (!is_writable($tag)) { + continue; # locked tag directory + } + if ($val and !is_writable($target)) { + continue; # existing file locked + } + $tags[$tagname]['target'] = $target; } if ($tags) { @@ -70,8 +81,8 @@ if (file_exists($tagdir)) { '' . ' %s', $tag, - $val ? ' checked' : '', - ' readonly', + $val['value'] ? ' checked' : '', + isset($val['target']) ? '' : ' readonly', ucfirst($tag) ); } @@ -79,6 +90,7 @@ if (file_exists($tagdir)) { $cols['tags'] = [ 'label' => 'groepen', 'input' => $options, + 'values' => $tags, ]; } } @@ -120,6 +132,29 @@ if ($_POST) { } } + if (isset($cols['tags']) and !empty($_POST['tags'])) { + $tagok = []; + foreach ($_POST['tags'] as $col => $val) { + $tag = $cols['tags']['values'][$col]; + if (!isset($tag['target'])) { + $tagok[$col] = 'forbidden'; + } + if ($tag['value'] === !empty($val)) { + $tagok[$col] = NULL; # unaltered + } + elseif (empty($val)) { + $tagok[$col] = !@unlink($tag['target']); + } + else { + $tagok[$col] = !@symlink("../../{$user['name']}", $tag['target']); + } + } + if ($tagok = array_filter($tagok)) { + $colwarn['tags'] = "Wijziging niet opgeslagen voor " + . implode(', ', array_keys($tagok)); + } + } + foreach ($_FILES as $col => $val) { if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') { continue; # unknown -- 2.30.0