login/edit: filter to replace newlines in input values
[minimedit.git] / login / edit.php
index 36058be29af2221ffbc108ad76a4e628d5a6963f..6f3eff211002b818a0f3e698eacb31a3c05d4869 100644 (file)
@@ -4,8 +4,9 @@ if (empty($user = &$User)) {
        return;
 }
 
-if (!empty($User['admin']) and $Page == 'login/edit' and $Args) {
-       $username = strtolower(ltrim($Args, '/'));
+if (!empty($User['admin']) and !empty($Place['user'])) {
+       $username = strtolower($Place['user']);
+       unset($user);
        $user = [
                'dir' => "profile/$username",
                'name' => $username,
@@ -16,6 +17,7 @@ $cols = [
        'name'  => [
                'label' => 'volledige naam',
                'explain' => "Alleen zichtbaar voor andere leden.",
+               'filter' => ["\n", '; '],
        ],
        'email' => [
                'label' => 'e-mailadres',
@@ -133,6 +135,11 @@ if ($_POST) {
                        }
                        continue;
                }
+
+               if (isset($cols[$col]['filter'])) {
+                       list ($targetstr, $inputstr) = $cols[$col]['filter'];
+                       $val = str_replace($inputstr, $targetstr, $val);
+               }
                if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
                        continue; # unaltered
                }
@@ -229,6 +236,11 @@ foreach ($cols as $col => &$colconf) {
                }
        }
        else {
+               if (isset($cols[$col]['filter'])) {
+                       list ($targetstr, $inputstr) = $cols[$col]['filter'];
+                       $colconf['value'] = str_replace($targetstr, $inputstr, $colconf['value']);
+               }
+
                $attrs = [
                        'type'        => @$colconf['type'] ?: 'text',
                        'name'        => $col,