10 require_once('edit.inc.php');
12 foreach ($cols as $col => &$colconf) {
13 if (isset($colconf['visible'])) {
14 if ($colconf['visible'] == 'admin' and !$User->admin('user')) {
15 $colconf['visible'] = FALSE;
20 $colconf['visible'] = TRUE;
23 if (!isset($colconf['filename'])) {
24 continue; # exceptional storage
27 if (isset($colconf['values'])) {
28 if (!file_exists($colconf['filename'])) {
29 $colconf['visible'] = FALSE;
33 foreach (glob($colconf['filename'] . '/*') as $tag) {
34 $tagname = pathinfo($tag, PATHINFO_BASENAME);
35 $target = "$tag/{$user->login}";
36 $val = file_exists($target);
37 $tagopt = &$colconf['values'][$tagname] ?: [];
38 $tagopt['value'] = $val;
39 if (!is_writable($tag)) {
40 continue; # locked tag directory
42 if ($val and !is_writable($target)) {
43 continue; # existing file locked
45 $tagopt['target'] = $target;
49 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
50 $colpath = $user->dir . '/' . $colconf['filename'];
51 if (file_exists($colpath)) {
52 $colconf['value'] = $filetype != 'txt' ? '' :
53 rtrim(file_get_contents($colpath));
55 if (file_exists($user->dir) and !is_writable($user->dir)) {
56 continue; # locked parent directory
58 if (isset($colconf['value']) and !is_writable($colpath)) {
59 continue; # locked column file
61 $colconf['target'] = $colpath; # editing allowed
66 if (!file_exists($user->dir) and !@mkdir($user->dir)) {
67 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user->login}</em>.</p>\n\n";
71 foreach ($_POST as $col => $val) {
72 if (!isset($cols[$col])) {
75 if (isset($cols[$col]['values'])) {
77 foreach ($val as $optcol => $optval) {
78 $option = &$cols[$col]['values'][$optcol];
79 if (!isset($option['target'])) {
80 $optok = FALSE; # forbidden
82 if ($option['value'] === !empty($optval)) {
85 elseif (empty($optval)) {
86 $optok = @unlink($option['target']);
89 # link option target to current user dir
90 $optok = @symlink("../../{$user->login}", $option['target']);
92 $option['value'] = $optval; # update form value
94 $optwarn[$optcol] = TRUE;
98 $colwarn[$col] = "Wijziging niet opgeslagen voor "
99 . implode(', ', array_keys($optwarn));
104 if (isset($cols[$col]['filter'])) {
105 list ($targetstr, $inputstr) = $cols[$col]['filter'];
106 $val = str_replace($inputstr, $targetstr, $val);
108 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
109 continue; # unaltered
111 $cols[$col]['value'] = $val; # update form value
112 if (empty($cols[$col]['target'])) {
113 if (empty($cols[$col]['input'])) {
114 $colwarn[$col] = "Kan niet worden aangepast.";
118 if (@$cols[$col]['type'] != 'file') {
119 $val .= "\n"; # eol in text files
121 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
122 $colwarn[$col] = "Fout bij opslaan.";
126 foreach ($_FILES as $col => $val) {
127 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
130 if (empty($cols[$col]['target'])) {
131 $colwarn[$col] = "Kan niet worden aangepast.";
135 require_once('upload.inc.php');
136 $target = userupload($val, NULL, $cols[$col]['target']);
137 if (!$target) continue;
138 $cols[$col]['value'] = '';
140 catch (Exception $e) {
141 $colwarn[$col] = ucfirst($e->getMessage()).'.';
145 if (!empty($_POST['newpass'])) {
146 require_once('login/pass.inc.php');
147 if ($error = passform($user, $_POST)) {
148 $colwarn['newpass'] = $error;
153 print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
156 print "<p>Alle instellingen zijn opgeslagen.</p>\n\n";
161 <form method="post" enctype="multipart/form-data">
164 foreach ($cols as $col => &$colconf) {
165 if (!$colconf['visible']) {
170 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
171 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
172 $target = $user->dir . '/' . $colconf['filename'];
173 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
175 200, $target, filemtime($target)
179 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
180 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
181 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
186 if (isset($colconf['input'])) {
187 print $colconf['input'];
189 elseif (isset($colconf['values'])) {
190 foreach ($colconf['values'] as $tag => $val) {
193 '<input type="hidden" name="%1$s" value="" />' .
194 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
195 '<label for="%2$s"> %s</label>',
196 "tags[$tag]", "tag-$tag",
197 !empty($val['value']) ? ' checked' : '',
198 isset($val['target']) ? '' : ' readonly',
199 @$val['label'] ?: ucfirst($tag)
203 elseif (@$colconf['type'] !== 'file' or isset($colconf['target'])) {
204 if (isset($cols[$col]['filter'])) {
205 list ($targetstr, $inputstr) = $cols[$col]['filter'];
206 $colconf['value'] = str_replace($targetstr, $inputstr, @$colconf['value']);
210 'type' => @$colconf['type'] ?: 'text',
213 'value' => htmlspecialchars(@$colconf['value']),
214 'placeholder' => "Niet ingesteld",
215 'readonly' => empty($colconf['target']),
216 ] + (@$colconf['attr'] ?: []);
219 foreach ($attrs as $attr => $attrval) {
220 if ($attrval === FALSE) {
224 if ($attrval !== TRUE) {
225 printf('="%s"', $attrval);
231 if (!empty($colconf['explain'])) {
232 printf(' <span>(%s)</span>', $colconf['explain']);
239 if ($error = @$colwarn[$col]) {
240 print " <span class=warn>$error</span>\n";
246 <p><input type="submit" value="Opslaan" /></p>