login/edit: declare column file storage
[minimedit.git] / login / edit.php
index 46b6132a6213f5b10ec2ff01292717468f543755..e174b065045182d0996eedf332a42da481a86f2f 100644 (file)
@@ -4,7 +4,8 @@ if (empty($user = &$User)) {
        return;
 }
 
-if (!empty($User['admin']) and !empty($Place['user'])) {
+if (!empty($User['admin'])
+and !empty($Place['user']) and $Place['user'] !== $User['name']) {
        $username = strtolower($Place['user']);
        unset($user);
        $user = [
@@ -17,21 +18,30 @@ $cols = [
        'name'  => [
                'label' => 'volledige naam',
                'explain' => "Alleen zichtbaar voor andere leden.",
+               'filter' => ["\n", '; '],
+               'size' => 30,
+               'filename' => 'name.txt',
        ],
        'email' => [
                'label' => 'e-mailadres',
                'type' => 'email',
                'explain' => "Voor contact van of met deze site. Wij zullen dit nooit vrij- of doorgeven.",
+               'size' => 30,
+               'filename' => 'email.txt',
        ],
        'avatar' => [
                'label' => 'portretfoto',
                'type' => 'file',
+               'filename' => 'avatar.jpg',
        ],
 ];
 
 foreach ($cols as $col => &$colconf) {
+       if (!isset($colconf['filename'])) {
+               continue;  # exceptional storage
+       }
        $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
-       $colpath = "{$user['dir']}/$col.$filetype";
+       $colpath = $user['dir'] . '/' . $colconf['filename'];
        if (file_exists($colpath)) {
                $colconf['value'] = $filetype != 'txt' ? '' :
                        file_get_contents($colpath);
@@ -51,6 +61,7 @@ $cols = [
                'value' => $user['name'],
                'target' => NULL,
                'pattern' => "[a-z0-9-]+",
+               'size' => 10,
        ],
 ] + $cols;
 
@@ -134,6 +145,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
                }
@@ -230,6 +246,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,
@@ -238,6 +259,7 @@ foreach ($cols as $col => &$colconf) {
                        'placeholder' => "Niet ingesteld",
                        'readonly'    => empty($colconf['target']),
                        'pattern'     => @$colconf['pattern'] ?: FALSE,
+                       'size'        => @$colconf['size'] ?: FALSE,
                ];
                if (@$colconf['type'] == 'file') {
                        $attrs['accept'] = "image/jpeg";