3 if (empty($user = &$User)) {
7 if (!empty($User['admin'])
8 and !empty($Place['user']) and $Place['user'] !== $User['name']) {
9 $username = strtolower($Place['user']);
12 'dir' => "profile/$username",
17 require_once('edit.inc.php');
19 foreach ($cols as $col => &$colconf) {
20 if (!isset($colconf['filename'])) {
21 continue; # exceptional storage
24 if (isset($colconf['values'])) {
25 if (!file_exists($colconf['filename'])) {
30 foreach (glob($colconf['filename'] . '/*') as $tag) {
31 $tagname = pathinfo($tag, PATHINFO_BASENAME);
32 $target = "$tag/{$user['name']}";
33 $val = file_exists($target);
34 $tags[$tagname] = ['value' => $val];
35 if (empty($User['admin'])) {
38 if (!is_writable($tag)) {
39 continue; # locked tag directory
41 if ($val and !is_writable($target)) {
42 continue; # existing file locked
44 $tags[$tagname]['target'] = $target;
48 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
49 $colpath = $user['dir'] . '/' . $colconf['filename'];
50 if (file_exists($colpath)) {
51 $colconf['value'] = $filetype != 'txt' ? '' :
52 file_get_contents($colpath);
54 if (file_exists($user['dir']) and !is_writable($user['dir'])) {
55 continue; # locked parent directory
57 if (isset($colconf['value']) and !is_writable($colpath)) {
58 continue; # locked column file
60 $colconf['target'] = $colpath; # editing allowed
65 if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
66 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user['name']}</em>.</p>\n\n";
70 foreach ($_POST as $col => $val) {
71 if (!isset($cols[$col])) {
74 if (isset($cols[$col]['values'])) {
76 foreach ($val as $optcol => $optval) {
77 $option = &$cols[$col]['values'][$optcol];
78 if (!isset($option['target'])) {
79 $optok = FALSE; # forbidden
81 if ($option['value'] === !empty($optval)) {
84 elseif (empty($optval)) {
85 $optok = @unlink($option['target']);
88 # link option target to current user dir
89 $optok = @symlink("../../{$user['name']}", $option['target']);
91 $option['value'] = $optval; # update form value
93 $optwarn[$optcol] = TRUE;
97 $colwarn[$col] = "Wijziging niet opgeslagen voor "
98 . implode(', ', array_keys($optwarn));
103 if (isset($cols[$col]['filter'])) {
104 list ($targetstr, $inputstr) = $cols[$col]['filter'];
105 $val = str_replace($inputstr, $targetstr, $val);
107 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
108 continue; # unaltered
110 $cols[$col]['value'] = $val; # update form value
111 if (empty($cols[$col]['target'])) {
112 if (empty($cols[$col]['input'])) {
113 $colwarn[$col] = "Kan niet worden aangepast.";
117 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
118 $colwarn[$col] = "Fout bij opslaan.";
122 foreach ($_FILES as $col => $val) {
123 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
126 switch ($val['error']) {
129 case UPLOAD_ERR_NO_FILE:
130 continue 2; # current
132 $colwarn[$col] = "Afbeelding niet goed ontvangen.";
135 if (empty($cols[$col]['target'])) {
136 $colwarn[$col] = "Kan niet worden aangepast.";
139 if (!@move_uploaded_file($val['tmp_name'], $cols[$col]['target'])) {
140 $colwarn[$col] = "Fout bij opslaan.";
142 foreach (@glob('thumb/*/') as $thumbres) {
143 # attempt to remove old derivations
144 @unlink($thumbres.'/'.$cols[$col]['target']);
146 $cols[$col]['value'] = '';
149 if (!empty($_POST['newpass'])) {
150 require_once('login/pass.inc.php');
151 if ($error = passform($user, $_POST)) {
152 $colwarn['newpass'] = $error;
157 print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
160 print "<p>Alle instellingen zijn opgeslagen.</p>\n\n";
165 <form method="post" enctype="multipart/form-data">
168 foreach ($cols as $col => &$colconf) {
170 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
171 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
172 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
174 200, $colconf['target'], filemtime($colconf['target'])
178 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
179 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
180 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
185 if (isset($colconf['input'])) {
186 print $colconf['input'];
188 elseif (isset($colconf['values'])) {
189 foreach ($colconf['values'] as $tag => $val) {
192 '<input type="hidden" name="%1$s" value="" />' .
193 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
194 '<label for="%2$s"> %s</label>',
195 "tags[$tag]", "tag-$tag",
196 $val['value'] ? ' checked' : '',
197 isset($val['target']) ? '' : ' readonly',
203 if (isset($cols[$col]['filter'])) {
204 list ($targetstr, $inputstr) = $cols[$col]['filter'];
205 $colconf['value'] = str_replace($targetstr, $inputstr, $colconf['value']);
209 'type' => @$colconf['type'] ?: 'text',
212 'value' => htmlspecialchars(@$colconf['value']),
213 'placeholder' => "Niet ingesteld",
214 'readonly' => empty($colconf['target']),
215 'pattern' => @$colconf['pattern'] ?: FALSE,
216 'size' => @$colconf['size'] ?: FALSE,
218 if (@$colconf['type'] == 'file') {
219 $attrs['accept'] = "image/jpeg";
223 foreach ($attrs as $attr => $attrval) {
224 if ($attrval === FALSE) {
228 if ($attrval !== TRUE) {
229 printf('="%s"', $attrval);
235 if (!empty($colconf['explain'])) {
236 printf(' <span>(%s)</span>', $colconf['explain']);
243 if ($error = @$colwarn[$col]) {
244 print " <span class=warn>$error</span>\n";
250 <p><input type="submit" value="Opslaan" /></p>