3 if (empty($user = &$User)) {
8 and !empty($Place['user']) and $Place['user'] !== $User->login) {
9 $username = strtolower($Place['user']);
11 $user = new User("profile/$username");
14 require_once('edit.inc.php');
16 foreach ($cols as $col => &$colconf) {
17 if (isset($colconf['visible'])) {
18 if ($colconf['visible'] == 'admin' and !$User->admin) {
19 $colconf['visible'] = FALSE;
24 $colconf['visible'] = TRUE;
27 if (!isset($colconf['filename'])) {
28 continue; # exceptional storage
31 if (isset($colconf['values'])) {
32 if (!file_exists($colconf['filename'])) {
33 $colconf['visible'] = FALSE;
37 foreach (glob($colconf['filename'] . '/*') as $tag) {
38 $tagname = pathinfo($tag, PATHINFO_BASENAME);
39 $target = "$tag/{$user->login}";
40 $val = file_exists($target);
41 $tagopt = &$colconf['values'][$tagname] ?: [];
42 $tagopt['value'] = $val;
43 if (!is_writable($tag)) {
44 continue; # locked tag directory
46 if ($val and !is_writable($target)) {
47 continue; # existing file locked
49 $tagopt['target'] = $target;
53 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
54 $colpath = $user->dir . '/' . $colconf['filename'];
55 if (file_exists($colpath)) {
56 $colconf['value'] = $filetype != 'txt' ? '' :
57 rtrim(file_get_contents($colpath));
59 if (file_exists($user->dir) and !is_writable($user->dir)) {
60 continue; # locked parent directory
62 if (isset($colconf['value']) and !is_writable($colpath)) {
63 continue; # locked column file
65 $colconf['target'] = $colpath; # editing allowed
70 if (!file_exists($user->dir) and !@mkdir($user->dir)) {
71 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user->login}</em>.</p>\n\n";
75 foreach ($_POST as $col => $val) {
76 if (!isset($cols[$col])) {
79 if (isset($cols[$col]['values'])) {
81 foreach ($val as $optcol => $optval) {
82 $option = &$cols[$col]['values'][$optcol];
83 if (!isset($option['target'])) {
84 $optok = FALSE; # forbidden
86 if ($option['value'] === !empty($optval)) {
89 elseif (empty($optval)) {
90 $optok = @unlink($option['target']);
93 # link option target to current user dir
94 $optok = @symlink("../../{$user->login}", $option['target']);
96 $option['value'] = $optval; # update form value
98 $optwarn[$optcol] = TRUE;
102 $colwarn[$col] = "Wijziging niet opgeslagen voor "
103 . implode(', ', array_keys($optwarn));
108 if (isset($cols[$col]['filter'])) {
109 list ($targetstr, $inputstr) = $cols[$col]['filter'];
110 $val = str_replace($inputstr, $targetstr, $val);
112 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
113 continue; # unaltered
115 $cols[$col]['value'] = $val; # update form value
116 if (empty($cols[$col]['target'])) {
117 if (empty($cols[$col]['input'])) {
118 $colwarn[$col] = "Kan niet worden aangepast.";
122 if (@$cols[$col]['type'] != 'file') {
123 $val .= "\n"; # eol in text files
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 $target = $user['dir'] . '/' . $colconf['filename'];
177 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
179 200, $target, filemtime($target)
183 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
184 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
185 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
190 if (isset($colconf['input'])) {
191 print $colconf['input'];
193 elseif (isset($colconf['values'])) {
194 foreach ($colconf['values'] as $tag => $val) {
197 '<input type="hidden" name="%1$s" value="" />' .
198 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
199 '<label for="%2$s"> %s</label>',
200 "tags[$tag]", "tag-$tag",
201 !empty($val['value']) ? ' checked' : '',
202 isset($val['target']) ? '' : ' readonly',
203 @$val['label'] ?: ucfirst($tag)
207 elseif (@$colconf['type'] !== 'file' or isset($colconf['target'])) {
208 if (isset($cols[$col]['filter'])) {
209 list ($targetstr, $inputstr) = $cols[$col]['filter'];
210 $colconf['value'] = str_replace($targetstr, $inputstr, @$colconf['value']);
214 'type' => @$colconf['type'] ?: 'text',
217 'value' => htmlspecialchars(@$colconf['value']),
218 'placeholder' => "Niet ingesteld",
219 'readonly' => empty($colconf['target']),
220 ] + (@$colconf['attr'] ?: []);
223 foreach ($attrs as $attr => $attrval) {
224 if ($attrval === FALSE) {
228 if ($attrval !== TRUE) {
229 printf('="%s"', $attrval);
235 if (!empty($colconf['explain'])) {
236 printf(' <span>(%s)</span>', $colconf['explain']);
243 if ($error = @$colwarn[$col]) {
244 print " <span class=warn>$error</span>\n";
250 <p><input type="submit" value="Opslaan" /></p>