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 $tagopt = &$colconf['values'][$tagname];
45 $tagopt = ['value' => $val];
46 if (!is_writable($tag)) {
47 continue; # locked tag directory
49 if ($val and !is_writable($target)) {
50 continue; # existing file locked
52 $tagopt['target'] = $target;
56 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
57 $colpath = $user['dir'] . '/' . $colconf['filename'];
58 if (file_exists($colpath)) {
59 $colconf['value'] = $filetype != 'txt' ? '' :
60 file_get_contents($colpath);
62 if (file_exists($user['dir']) and !is_writable($user['dir'])) {
63 continue; # locked parent directory
65 if (isset($colconf['value']) and !is_writable($colpath)) {
66 continue; # locked column file
68 $colconf['target'] = $colpath; # editing allowed
73 if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
74 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user['name']}</em>.</p>\n\n";
78 foreach ($_POST as $col => $val) {
79 if (!isset($cols[$col])) {
82 if (isset($cols[$col]['values'])) {
84 foreach ($val as $optcol => $optval) {
85 $option = &$cols[$col]['values'][$optcol];
86 if (!isset($option['target'])) {
87 $optok = FALSE; # forbidden
89 if ($option['value'] === !empty($optval)) {
92 elseif (empty($optval)) {
93 $optok = @unlink($option['target']);
96 # link option target to current user dir
97 $optok = @symlink("../../{$user['name']}", $option['target']);
99 $option['value'] = $optval; # update form value
101 $optwarn[$optcol] = TRUE;
105 $colwarn[$col] = "Wijziging niet opgeslagen voor "
106 . implode(', ', array_keys($optwarn));
111 if (isset($cols[$col]['filter'])) {
112 list ($targetstr, $inputstr) = $cols[$col]['filter'];
113 $val = str_replace($inputstr, $targetstr, $val);
115 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
116 continue; # unaltered
118 $cols[$col]['value'] = $val; # update form value
119 if (empty($cols[$col]['target'])) {
120 if (empty($cols[$col]['input'])) {
121 $colwarn[$col] = "Kan niet worden aangepast.";
125 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
126 $colwarn[$col] = "Fout bij opslaan.";
130 foreach ($_FILES as $col => $val) {
131 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
134 if (empty($cols[$col]['target'])) {
135 $colwarn[$col] = "Kan niet worden aangepast.";
139 require_once('upload.inc.php');
140 $target = userupload($val, NULL, $cols[$col]['target']);
141 if (!$target) continue;
142 $cols[$col]['value'] = '';
144 catch (Exception $e) {
145 $colwarn[$col] = ucfirst($e->getMessage()).'.';
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) {
169 if (!$colconf['visible']) {
174 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
175 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
176 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
178 200, $colconf['target'], filemtime($colconf['target'])
182 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
183 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
184 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
189 if (isset($colconf['input'])) {
190 print $colconf['input'];
192 elseif (isset($colconf['values'])) {
193 foreach ($colconf['values'] as $tag => $val) {
196 '<input type="hidden" name="%1$s" value="" />' .
197 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
198 '<label for="%2$s"> %s</label>',
199 "tags[$tag]", "tag-$tag",
200 $val['value'] ? ' checked' : '',
201 isset($val['target']) ? '' : ' readonly',
207 if (isset($cols[$col]['filter'])) {
208 list ($targetstr, $inputstr) = $cols[$col]['filter'];
209 $colconf['value'] = str_replace($targetstr, $inputstr, @$colconf['value']);
213 'type' => @$colconf['type'] ?: 'text',
216 'value' => htmlspecialchars(@$colconf['value']),
217 'placeholder' => "Niet ingesteld",
218 'readonly' => empty($colconf['target']),
219 'pattern' => @$colconf['pattern'] ?: FALSE,
220 'size' => @$colconf['size'] ?: FALSE,
222 if (@$colconf['type'] == 'file') {
223 $attrs['accept'] = "image/jpeg";
227 foreach ($attrs as $attr => $attrval) {
228 if ($attrval === FALSE) {
232 if ($attrval !== TRUE) {
233 printf('="%s"', $attrval);
239 if (!empty($colconf['explain'])) {
240 printf(' <span>(%s)</span>', $colconf['explain']);
247 if ($error = @$colwarn[$col]) {
248 print " <span class=warn>$error</span>\n";
254 <p><input type="submit" value="Opslaan" /></p>