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", '; '],
23 'label' => 'e-mailadres',
25 'explain' => "Voor contact van of met deze site. Wij zullen dit nooit vrij- of doorgeven.",
28 'label' => 'portretfoto',
33 foreach ($cols as $col => &$colconf) {
34 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
35 $colpath = "{$user['dir']}/$col.$filetype";
36 if (file_exists($colpath)) {
37 $colconf['value'] = $filetype != 'txt' ? '' :
38 file_get_contents($colpath);
40 if (file_exists($user['dir']) and !is_writable($user['dir'])) {
41 continue; # locked parent directory
43 if (isset($colconf['value']) and !is_writable($colpath)) {
44 continue; # locked column file
46 $colconf['target'] = $colpath; # editing allowed
52 'value' => $user['name'],
54 'pattern' => "[a-z0-9-]+",
58 $tagdir = 'profile/.tags';
59 if (file_exists($tagdir)) {
61 foreach (glob("$tagdir/*") as $tag) {
62 $tagname = pathinfo($tag, PATHINFO_BASENAME);
63 $target = "$tag/{$user['name']}";
64 $val = file_exists($target);
65 $tags[$tagname] = ['value' => $val];
66 if (empty($User['admin'])) {
69 if (!is_writable($tag)) {
70 continue; # locked tag directory
72 if ($val and !is_writable($target)) {
73 continue; # existing file locked
75 $tags[$tagname]['target'] = $target;
86 if (isset($user['pass'])) {
88 'label' => 'wachtwoord',
90 <input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
91 <input type="password" id="newpass" name="newpass" value="" placeholder="Nieuw wachtwoord" />
92 <input type="password" name="passconf" value="" placeholder="Nogmaals" />
101 if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
102 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user['name']}</em>.</p>\n\n";
106 foreach ($_POST as $col => $val) {
107 if (!isset($cols[$col])) {
110 if (isset($cols[$col]['values'])) {
112 foreach ($val as $optcol => $optval) {
113 $option = &$cols[$col]['values'][$optcol];
114 if (!isset($option['target'])) {
115 $optok = FALSE; # forbidden
117 if ($option['value'] === !empty($optval)) {
118 continue; # unaltered
120 elseif (empty($optval)) {
121 $optok = @unlink($option['target']);
124 # link option target to current user dir
125 $optok = @symlink("../../{$user['name']}", $option['target']);
127 $option['value'] = $optval; # update form value
129 $optwarn[$optcol] = TRUE;
133 $colwarn[$col] = "Wijziging niet opgeslagen voor "
134 . implode(', ', array_keys($optwarn));
139 if (isset($cols[$col]['filter'])) {
140 list ($targetstr, $inputstr) = $cols[$col]['filter'];
141 $val = str_replace($inputstr, $targetstr, $val);
143 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
144 continue; # unaltered
146 $cols[$col]['value'] = $val; # update form value
147 if (empty($cols[$col]['target'])) {
148 if (empty($cols[$col]['input'])) {
149 $colwarn[$col] = "Kan niet worden aangepast.";
153 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
154 $colwarn[$col] = "Fout bij opslaan.";
158 foreach ($_FILES as $col => $val) {
159 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
162 switch ($val['error']) {
165 case UPLOAD_ERR_NO_FILE:
166 continue 2; # current
168 $colwarn[$col] = "Afbeelding niet goed ontvangen.";
171 if (empty($cols[$col]['target'])) {
172 $colwarn[$col] = "Kan niet worden aangepast.";
175 if (!@move_uploaded_file($val['tmp_name'], $cols[$col]['target'])) {
176 $colwarn[$col] = "Fout bij opslaan.";
178 foreach (@glob('thumb/*/') as $thumbres) {
179 # attempt to remove old derivations
180 @unlink($thumbres.'/'.$cols[$col]['target']);
182 $cols[$col]['value'] = '';
185 if (!empty($_POST['newpass'])) {
186 require_once('login/pass.inc.php');
187 if ($error = passform($user, $_POST)) {
188 $colwarn['newpass'] = $error;
193 print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
196 print "<p>Alle instellingen zijn opgeslagen.</p>\n\n";
201 <form method="post" enctype="multipart/form-data">
204 foreach ($cols as $col => &$colconf) {
206 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
207 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
208 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
210 200, $colconf['target'], filemtime($colconf['target'])
214 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
215 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
216 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
221 if (isset($colconf['input'])) {
222 print $colconf['input'];
224 elseif (isset($colconf['values'])) {
225 foreach ($colconf['values'] as $tag => $val) {
228 '<input type="hidden" name="%1$s" value="" />' .
229 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
230 '<label for="%2$s"> %s</label>',
231 "tags[$tag]", "tag-$tag",
232 $val['value'] ? ' checked' : '',
233 isset($val['target']) ? '' : ' readonly',
239 if (isset($cols[$col]['filter'])) {
240 list ($targetstr, $inputstr) = $cols[$col]['filter'];
241 $colconf['value'] = str_replace($targetstr, $inputstr, $colconf['value']);
245 'type' => @$colconf['type'] ?: 'text',
248 'value' => htmlspecialchars(@$colconf['value']),
249 'placeholder' => "Niet ingesteld",
250 'readonly' => empty($colconf['target']),
251 'pattern' => @$colconf['pattern'] ?: FALSE,
253 if (@$colconf['type'] == 'file') {
254 $attrs['accept'] = "image/jpeg";
258 foreach ($attrs as $attr => $attrval) {
259 if ($attrval === FALSE) {
263 if ($attrval !== TRUE) {
264 printf('="%s"', $attrval);
270 if (!empty($colconf['explain'])) {
271 printf(' <span>(%s)</span>', $colconf['explain']);
278 if ($error = @$colwarn[$col]) {
279 print " <span class=warn>$error</span>\n";
285 <p><input type="submit" value="Opslaan" /></p>