3 if (empty($user = &$User)) {
7 if (!empty($User['admin']) and !empty($Place['user'])) {
8 $username = strtolower($Place['user']);
11 'dir' => "profile/$username",
18 'label' => 'volledige naam',
19 'explain' => "Alleen zichtbaar voor andere leden.",
20 'filter' => ["\n", '; '],
24 'label' => 'e-mailadres',
26 'explain' => "Voor contact van of met deze site. Wij zullen dit nooit vrij- of doorgeven.",
30 'label' => 'portretfoto',
35 foreach ($cols as $col => &$colconf) {
36 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
37 $colpath = "{$user['dir']}/$col.$filetype";
38 if (file_exists($colpath)) {
39 $colconf['value'] = $filetype != 'txt' ? '' :
40 file_get_contents($colpath);
42 if (file_exists($user['dir']) and !is_writable($user['dir'])) {
43 continue; # locked parent directory
45 if (isset($colconf['value']) and !is_writable($colpath)) {
46 continue; # locked column file
48 $colconf['target'] = $colpath; # editing allowed
54 'value' => $user['name'],
56 'pattern' => "[a-z0-9-]+",
61 $tagdir = 'profile/.tags';
62 if (file_exists($tagdir)) {
64 foreach (glob("$tagdir/*") as $tag) {
65 $tagname = pathinfo($tag, PATHINFO_BASENAME);
66 $target = "$tag/{$user['name']}";
67 $val = file_exists($target);
68 $tags[$tagname] = ['value' => $val];
69 if (empty($User['admin'])) {
72 if (!is_writable($tag)) {
73 continue; # locked tag directory
75 if ($val and !is_writable($target)) {
76 continue; # existing file locked
78 $tags[$tagname]['target'] = $target;
89 if (isset($user['pass'])) {
91 'label' => 'wachtwoord',
93 <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
94 <input type="password" id="newpass" name="newpass" value="" placeholder="Nieuw wachtwoord" />
95 <input type="password" name="passconf" value="" placeholder="Nogmaals" />
104 if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
105 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user['name']}</em>.</p>\n\n";
109 foreach ($_POST as $col => $val) {
110 if (!isset($cols[$col])) {
113 if (isset($cols[$col]['values'])) {
115 foreach ($val as $optcol => $optval) {
116 $option = &$cols[$col]['values'][$optcol];
117 if (!isset($option['target'])) {
118 $optok = FALSE; # forbidden
120 if ($option['value'] === !empty($optval)) {
121 continue; # unaltered
123 elseif (empty($optval)) {
124 $optok = @unlink($option['target']);
127 # link option target to current user dir
128 $optok = @symlink("../../{$user['name']}", $option['target']);
130 $option['value'] = $optval; # update form value
132 $optwarn[$optcol] = TRUE;
136 $colwarn[$col] = "Wijziging niet opgeslagen voor "
137 . implode(', ', array_keys($optwarn));
142 if (isset($cols[$col]['filter'])) {
143 list ($targetstr, $inputstr) = $cols[$col]['filter'];
144 $val = str_replace($inputstr, $targetstr, $val);
146 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
147 continue; # unaltered
149 $cols[$col]['value'] = $val; # update form value
150 if (empty($cols[$col]['target'])) {
151 if (empty($cols[$col]['input'])) {
152 $colwarn[$col] = "Kan niet worden aangepast.";
156 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
157 $colwarn[$col] = "Fout bij opslaan.";
161 foreach ($_FILES as $col => $val) {
162 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
165 switch ($val['error']) {
168 case UPLOAD_ERR_NO_FILE:
169 continue 2; # current
171 $colwarn[$col] = "Afbeelding niet goed ontvangen.";
174 if (empty($cols[$col]['target'])) {
175 $colwarn[$col] = "Kan niet worden aangepast.";
178 if (!@move_uploaded_file($val['tmp_name'], $cols[$col]['target'])) {
179 $colwarn[$col] = "Fout bij opslaan.";
181 foreach (@glob('thumb/*/') as $thumbres) {
182 # attempt to remove old derivations
183 @unlink($thumbres.'/'.$cols[$col]['target']);
185 $cols[$col]['value'] = '';
188 if (!empty($_POST['newpass'])) {
189 require_once('login/pass.inc.php');
190 if ($error = passform($user, $_POST)) {
191 $colwarn['newpass'] = $error;
196 print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
199 print "<p>Alle instellingen zijn opgeslagen.</p>\n\n";
204 <form method="post" enctype="multipart/form-data">
207 foreach ($cols as $col => &$colconf) {
209 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
210 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
211 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
213 200, $colconf['target'], filemtime($colconf['target'])
217 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
218 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
219 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
224 if (isset($colconf['input'])) {
225 print $colconf['input'];
227 elseif (isset($colconf['values'])) {
228 foreach ($colconf['values'] as $tag => $val) {
231 '<input type="hidden" name="%1$s" value="" />' .
232 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
233 '<label for="%2$s"> %s</label>',
234 "tags[$tag]", "tag-$tag",
235 $val['value'] ? ' checked' : '',
236 isset($val['target']) ? '' : ' readonly',
242 if (isset($cols[$col]['filter'])) {
243 list ($targetstr, $inputstr) = $cols[$col]['filter'];
244 $colconf['value'] = str_replace($targetstr, $inputstr, $colconf['value']);
248 'type' => @$colconf['type'] ?: 'text',
251 'value' => htmlspecialchars(@$colconf['value']),
252 'placeholder' => "Niet ingesteld",
253 'readonly' => empty($colconf['target']),
254 'pattern' => @$colconf['pattern'] ?: FALSE,
255 'size' => @$colconf['size'] ?: FALSE,
257 if (@$colconf['type'] == 'file') {
258 $attrs['accept'] = "image/jpeg";
262 foreach ($attrs as $attr => $attrval) {
263 if ($attrval === FALSE) {
267 if ($attrval !== TRUE) {
268 printf('="%s"', $attrval);
274 if (!empty($colconf['explain'])) {
275 printf(' <span>(%s)</span>', $colconf['explain']);
282 if ($error = @$colwarn[$col]) {
283 print " <span class=warn>$error</span>\n";
289 <p><input type="submit" value="Opslaan" /></p>