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['visible'])) {
21 if ($colconf['visible'] == 'admin' and empty($User['admin'])) {
22 $colconf['visible'] = FALSE;
27 $colconf['visible'] = TRUE;
30 if (!isset($colconf['filename'])) {
31 continue; # exceptional storage
34 if (isset($colconf['values'])) {
35 if (!file_exists($colconf['filename'])) {
36 $colconf['visible'] = FALSE;
40 foreach (glob($colconf['filename'] . '/*') as $tag) {
41 $tagname = pathinfo($tag, PATHINFO_BASENAME);
42 $target = "$tag/{$user['name']}";
43 $val = file_exists($target);
44 $tags[$tagname] = ['value' => $val];
45 if (!is_writable($tag)) {
46 continue; # locked tag directory
48 if ($val and !is_writable($target)) {
49 continue; # existing file locked
51 $tags[$tagname]['target'] = $target;
55 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
56 $colpath = $user['dir'] . '/' . $colconf['filename'];
57 if (file_exists($colpath)) {
58 $colconf['value'] = $filetype != 'txt' ? '' :
59 file_get_contents($colpath);
61 if (file_exists($user['dir']) and !is_writable($user['dir'])) {
62 continue; # locked parent directory
64 if (isset($colconf['value']) and !is_writable($colpath)) {
65 continue; # locked column file
67 $colconf['target'] = $colpath; # editing allowed
72 if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
73 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user['name']}</em>.</p>\n\n";
77 foreach ($_POST as $col => $val) {
78 if (!isset($cols[$col])) {
81 if (isset($cols[$col]['values'])) {
83 foreach ($val as $optcol => $optval) {
84 $option = &$cols[$col]['values'][$optcol];
85 if (!isset($option['target'])) {
86 $optok = FALSE; # forbidden
88 if ($option['value'] === !empty($optval)) {
91 elseif (empty($optval)) {
92 $optok = @unlink($option['target']);
95 # link option target to current user dir
96 $optok = @symlink("../../{$user['name']}", $option['target']);
98 $option['value'] = $optval; # update form value
100 $optwarn[$optcol] = TRUE;
104 $colwarn[$col] = "Wijziging niet opgeslagen voor "
105 . implode(', ', array_keys($optwarn));
110 if (isset($cols[$col]['filter'])) {
111 list ($targetstr, $inputstr) = $cols[$col]['filter'];
112 $val = str_replace($inputstr, $targetstr, $val);
114 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
115 continue; # unaltered
117 $cols[$col]['value'] = $val; # update form value
118 if (empty($cols[$col]['target'])) {
119 if (empty($cols[$col]['input'])) {
120 $colwarn[$col] = "Kan niet worden aangepast.";
124 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
125 $colwarn[$col] = "Fout bij opslaan.";
129 foreach ($_FILES as $col => $val) {
130 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
133 if (empty($cols[$col]['target'])) {
134 $colwarn[$col] = "Kan niet worden aangepast.";
138 require_once('upload.inc.php');
139 $target = userupload($val, NULL, $cols[$col]['target']);
140 if (!$target) continue;
141 $cols[$col]['value'] = '';
143 catch (Exception $e) {
144 $colwarn[$col] = ucfirst($e->getMessage()).'.';
148 if (!empty($_POST['newpass'])) {
149 require_once('login/pass.inc.php');
150 if ($error = passform($user, $_POST)) {
151 $colwarn['newpass'] = $error;
156 print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
159 print "<p>Alle instellingen zijn opgeslagen.</p>\n\n";
164 <form method="post" enctype="multipart/form-data">
167 foreach ($cols as $col => &$colconf) {
168 if (!$colconf['visible']) {
173 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
174 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
175 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
177 200, $colconf['target'], filemtime($colconf['target'])
181 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
182 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
183 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
188 if (isset($colconf['input'])) {
189 print $colconf['input'];
191 elseif (isset($colconf['values'])) {
192 foreach ($colconf['values'] as $tag => $val) {
195 '<input type="hidden" name="%1$s" value="" />' .
196 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
197 '<label for="%2$s"> %s</label>',
198 "tags[$tag]", "tag-$tag",
199 $val['value'] ? ' checked' : '',
200 isset($val['target']) ? '' : ' readonly',
206 if (isset($cols[$col]['filter'])) {
207 list ($targetstr, $inputstr) = $cols[$col]['filter'];
208 $colconf['value'] = str_replace($targetstr, $inputstr, @$colconf['value']);
212 'type' => @$colconf['type'] ?: 'text',
215 'value' => htmlspecialchars(@$colconf['value']),
216 'placeholder' => "Niet ingesteld",
217 'readonly' => empty($colconf['target']),
218 'pattern' => @$colconf['pattern'] ?: FALSE,
219 'size' => @$colconf['size'] ?: FALSE,
221 if (@$colconf['type'] == 'file') {
222 $attrs['accept'] = "image/jpeg";
226 foreach ($attrs as $attr => $attrval) {
227 if ($attrval === FALSE) {
231 if ($attrval !== TRUE) {
232 printf('="%s"', $attrval);
238 if (!empty($colconf['explain'])) {
239 printf(' <span>(%s)</span>', $colconf['explain']);
246 if ($error = @$colwarn[$col]) {
247 print " <span class=warn>$error</span>\n";
253 <p><input type="submit" value="Opslaan" /></p>