login/edit: column descriptions; explain name visibility
[minimedit.git] / login / edit.php
index 6dfbfab5caf8f6ac00f563ad06c8ea9f40604278..017a56221a5c9765c99915b840d3a977a9c632ac 100644 (file)
@@ -13,8 +13,15 @@ if (!empty($User['admin']) and $Page == 'login/edit' and $Args) {
 }
 
 $cols = [
-       'name'  => ['label' => 'volledige naam'],
-       'email' => ['label' => 'e-mailadres', 'type' => 'email'],
+       'name'  => [
+               'label' => 'volledige naam',
+               'explain' => "Alleen zichtbaar voor andere leden.",
+       ],
+       'email' => [
+               'label' => 'e-mailadres',
+               'type' => 'email',
+               'explain' => "Voor contact van of met deze site. Wij zullen dit nooit vrij- of doorgeven.",
+       ],
        'avatar' => [
                'label' => 'portretfoto',
                'type' => 'file',
@@ -41,6 +48,19 @@ $cols = [
        'login' => ['label' => 'login', 'value' => $user['name'], 'target' => NULL],
 ] + $cols;
 
+if (isset($user['pass'])) {
+       $cols['newpass'] = [
+               'label' => 'wachtwoord',
+               'input' => <<<'EOT'
+                       <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
+                       <input type="password" id="newpass" name="newpass" value="" placeholder="Nieuw wachtwoord" />
+                       <input type="password" name="passconf" value="" placeholder="Nogmaals" />
+EOT
+               ,
+               'hide'  => 'pass',
+       ];
+}
+
 $colwarn = [];
 if ($_POST) {
        if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
@@ -95,7 +115,7 @@ if ($_POST) {
        if (!empty($_POST['newpass'])) {
                require_once('login/pass.inc.php');
                if ($error = passform($user, $_POST)) {
-                       $colwarn['pass'] = $error;
+                       $colwarn['newpass'] = $error;
                }
        }
 
@@ -109,10 +129,6 @@ if ($_POST) {
 
 ?>
 <form method="post" enctype="multipart/form-data">
-       <p>
-       Geef een e-mailadres op waarmee we u kunnen bereiken indien nodig.
-       Wij zullen dit adres nooit vrij- of doorgeven.
-       </p>
        <ul class="grid">
 <?php
 foreach ($cols as $col => &$colconf) {
@@ -125,7 +141,17 @@ foreach ($cols as $col => &$colconf) {
                );
        }
 
-       {
+       if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
+               printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
+                       "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
+                       $hide
+               );
+       }
+
+       if (isset($colconf['input'])) {
+               print $colconf['input'];
+       }
+       else {
                $attrs = [
                        'type'        => @$colconf['type'] ?: 'text',
                        'name'        => $col,
@@ -150,34 +176,18 @@ foreach ($cols as $col => &$colconf) {
                }
                print ' />';
        }
-
-       if ($error = @$colwarn[$col]) {
-               print " <span class=warn>$error</span>\n";
+       if (!empty($colconf['explain'])) {
+               printf(' <span>(%s)</span>', $colconf['explain']);
        }
-       print "</li>\n";
-}
 
-if (isset($user['pass'])) {
-?>
-       <li><label for="newpass">Wachtwoord:</label>
-<?php
-       if ($hide = empty($_POST['newpass'])) {
-?>
-               <a onclick="document.getElementById('pass').removeAttribute('hidden'); this.remove()">Wijzigen</a>
-<?php
+       if ($hide) {
+               print '</span>';
        }
-?>
-               <span id="pass"<?php if ($hide) print ' hidden'; ?>>
-                       <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
-                       <input type="password" name="newpass" value="" placeholder="Nieuw wachtwoord" />
-                       <input type="password" name="passconf" value="" placeholder="Nogmaals" />
-<?php
-       if ($error = @$colwarn['pass']) {
+
+       if ($error = @$colwarn[$col]) {
                print " <span class=warn>$error</span>\n";
        }
-?>
-       </li>
-<?php
+       print "</li>\n";
 }
 ?>
        </ul>