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 $colconf['visible'] = TRUE;
22 if (!isset($colconf['filename'])) {
23 continue; # exceptional storage
26 if (isset($colconf['values'])) {
27 if (!file_exists($colconf['filename'])) {
28 $colconf['visible'] = FALSE;
32 foreach (glob($colconf['filename'] . '/*') as $tag) {
33 $tagname = pathinfo($tag, PATHINFO_BASENAME);
34 $target = "$tag/{$user['name']}";
35 $val = file_exists($target);
36 $tags[$tagname] = ['value' => $val];
37 if (empty($User['admin'])) {
40 if (!is_writable($tag)) {
41 continue; # locked tag directory
43 if ($val and !is_writable($target)) {
44 continue; # existing file locked
46 $tags[$tagname]['target'] = $target;
50 $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
51 $colpath = $user['dir'] . '/' . $colconf['filename'];
52 if (file_exists($colpath)) {
53 $colconf['value'] = $filetype != 'txt' ? '' :
54 file_get_contents($colpath);
56 if (file_exists($user['dir']) and !is_writable($user['dir'])) {
57 continue; # locked parent directory
59 if (isset($colconf['value']) and !is_writable($colpath)) {
60 continue; # locked column file
62 $colconf['target'] = $colpath; # editing allowed
67 if (!file_exists($user['dir']) and !@mkdir($user['dir'])) {
68 print "<p class=warn>Fout bij het aanmaken van gebruikersprofiel voor <em>{$user['name']}</em>.</p>\n\n";
72 foreach ($_POST as $col => $val) {
73 if (!isset($cols[$col])) {
76 if (isset($cols[$col]['values'])) {
78 foreach ($val as $optcol => $optval) {
79 $option = &$cols[$col]['values'][$optcol];
80 if (!isset($option['target'])) {
81 $optok = FALSE; # forbidden
83 if ($option['value'] === !empty($optval)) {
86 elseif (empty($optval)) {
87 $optok = @unlink($option['target']);
90 # link option target to current user dir
91 $optok = @symlink("../../{$user['name']}", $option['target']);
93 $option['value'] = $optval; # update form value
95 $optwarn[$optcol] = TRUE;
99 $colwarn[$col] = "Wijziging niet opgeslagen voor "
100 . implode(', ', array_keys($optwarn));
105 if (isset($cols[$col]['filter'])) {
106 list ($targetstr, $inputstr) = $cols[$col]['filter'];
107 $val = str_replace($inputstr, $targetstr, $val);
109 if (isset($cols[$col]['value']) and $cols[$col]['value'] === $val) {
110 continue; # unaltered
112 $cols[$col]['value'] = $val; # update form value
113 if (empty($cols[$col]['target'])) {
114 if (empty($cols[$col]['input'])) {
115 $colwarn[$col] = "Kan niet worden aangepast.";
119 if (file_put_contents($cols[$col]['target'], $val) === FALSE) {
120 $colwarn[$col] = "Fout bij opslaan.";
124 foreach ($_FILES as $col => $val) {
125 if (!isset($cols[$col]) and @$cols[$col]['type'] == 'file') {
128 if (empty($cols[$col]['target'])) {
129 $colwarn[$col] = "Kan niet worden aangepast.";
133 require_once('upload.inc.php');
134 $target = userupload($val, NULL, $cols[$col]['target']);
135 if (!$target) continue;
136 $cols[$col]['value'] = '';
138 catch (Exception $e) {
139 $colwarn[$col] = ucfirst($e->getMessage()).'.';
143 if (!empty($_POST['newpass'])) {
144 require_once('login/pass.inc.php');
145 if ($error = passform($user, $_POST)) {
146 $colwarn['newpass'] = $error;
151 print "<p class=warn>Instellingen zijn niet (volledig) opgeslagen. Probeer het later nog eens.</p>\n\n";
154 print "<p>Alle instellingen zijn opgeslagen.</p>\n\n";
159 <form method="post" enctype="multipart/form-data">
162 foreach ($cols as $col => &$colconf) {
163 if (!$colconf['visible']) {
168 printf('<li><label for="%s">%s:</label>', $col, ucfirst($colconf['label']));
169 if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
170 printf('<a href="/%s"><img src="/thumb/%s/%s?%s" /></a><br />',
172 200, $colconf['target'], filemtime($colconf['target'])
176 if ($hide = @$colconf['hide'] and empty($_POST[$col])) {
177 printf('<a onclick="%s">Wijzigen</a><span id="%s" hidden>',
178 "document.getElementById('$hide').removeAttribute('hidden'); this.remove()",
183 if (isset($colconf['input'])) {
184 print $colconf['input'];
186 elseif (isset($colconf['values'])) {
187 foreach ($colconf['values'] as $tag => $val) {
190 '<input type="hidden" name="%1$s" value="" />' .
191 '<input type="checkbox" name="%s" value="1" id="%s"%s%s />' .
192 '<label for="%2$s"> %s</label>',
193 "tags[$tag]", "tag-$tag",
194 $val['value'] ? ' checked' : '',
195 isset($val['target']) ? '' : ' readonly',
201 if (isset($cols[$col]['filter'])) {
202 list ($targetstr, $inputstr) = $cols[$col]['filter'];
203 $colconf['value'] = str_replace($targetstr, $inputstr, $colconf['value']);
207 'type' => @$colconf['type'] ?: 'text',
210 'value' => htmlspecialchars(@$colconf['value']),
211 'placeholder' => "Niet ingesteld",
212 'readonly' => empty($colconf['target']),
213 'pattern' => @$colconf['pattern'] ?: FALSE,
214 'size' => @$colconf['size'] ?: FALSE,
216 if (@$colconf['type'] == 'file') {
217 $attrs['accept'] = "image/jpeg";
221 foreach ($attrs as $attr => $attrval) {
222 if ($attrval === FALSE) {
226 if ($attrval !== TRUE) {
227 printf('="%s"', $attrval);
233 if (!empty($colconf['explain'])) {
234 printf(' <span>(%s)</span>', $colconf['explain']);
241 if ($error = @$colwarn[$col]) {
242 print " <span class=warn>$error</span>\n";
248 <p><input type="submit" value="Opslaan" /></p>