edit/page: editor notification of save results
[minimedit.git] / login / edit.php
index 4a2e6f4665c39d429d08a8fea4203ee401878150..ad9dbda68faa8f378081dfcbf2bee041bb74190a 100644 (file)
@@ -14,32 +14,7 @@ and !empty($Place['user']) and $Place['user'] !== $User['name']) {
        ];
 }
 
-$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',
-       ],
-       'tags' => [
-               'label' => 'groepen',
-               'values' => [],
-               'filename' => 'profile/.tags',
-       ],
-];
+require_once('edit.inc.php');
 
 foreach ($cols as $col => &$colconf) {
        if (!isset($colconf['filename'])) {
@@ -85,29 +60,6 @@ foreach ($cols as $col => &$colconf) {
        $colconf['target'] = $colpath;  # editing allowed
 }
 
-$cols = [
-       'username' => [
-               'label' => 'login',
-               'value' => $user['name'],
-               'target' => NULL,
-               'pattern' => "[a-z0-9-]+",
-               'size' => 10,
-       ],
-] + $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'])) {
@@ -171,27 +123,19 @@ if ($_POST) {
                if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
                        continue; # unknown
                }
-               switch ($val['error']) {
-               case UPLOAD_ERR_OK:
-                       break;
-               case UPLOAD_ERR_NO_FILE:
-                       continue 2; # current
-               default:
-                       $colwarn[$col] = "Afbeelding niet goed ontvangen.";
-                       continue 2;
-               }
                if (empty($cols[$col]['target'])) {
                        $colwarn[$col] = "Kan niet worden aangepast.";
                        continue;
                }
-               if (!@move_uploaded_file($val['tmp_name'], $cols[$col]['target'])) {
-                       $colwarn[$col] = "Fout bij opslaan.";
+               try {
+                       require_once('upload.inc.php');
+                       $target = userupload($val, NULL, $cols[$col]['target']);
+                       if (!$target) continue;
+                       $cols[$col]['value'] = '';
                }
-               foreach (@glob('thumb/*/') as $thumbres) {
-                       # attempt to remove old derivations
-                       @unlink($thumbres.'/'.$cols[$col]['target']);
+               catch (Exception $e) {
+                       $colwarn[$col] = ucfirst($e->getMessage()).'.';
                }
-               $cols[$col]['value'] = '';
        }
 
        if (!empty($_POST['newpass'])) {