function editSubmit($p) { $f = UserDataField::get($p['id']); $f->name = $p['name']; $f->label = $p['label']; $f->type = $p['type']; $f->id = $f->store(); switch ($f->type) { case UserDataField::RADIO: for ($i = 1; $i < 6; $i++) { if (!empty($p['opt_' . $i])) { UserDataFieldOption::set($f->id, 'opt_' . $i, $p['opt_' . $i]); } } break; case UserDataField::AVATAR: for ($i = 1; $i < 6; $i++) { if (!empty($p['avatar_' . $i])) { if ($p['avatar_' . $i]['error'] == UPLOAD_ERR_NO_FILE) { continue; } $fileId = File::importImage(SITE, $p['avatar_' . $i]); UserDataFieldOption::set($f->id, 'avatar_' . $i, $fileId); } } break; } js_redirect('a/userdata/list'); }
echo '<h1>Edit your profile</h1>'; echo '<br/>'; $form = new XhtmlForm(); $fields = UserDataField::getAll(); foreach ($fields as $f) { switch ($f->type) { case UserDataField::RADIO: $opts = UserDataFieldOption::getAll($f->id); $arr = array(); foreach ($opts as $o) { $arr[$o['id']] = $o['value']; } $form->addRadio($f->name, $f->label, $arr, UserSetting::get($session->id, $f->name)); break; case UserDataField::AVATAR: $opts = UserDataFieldOption::getAll($f->id); $arr = array(); foreach ($opts as $o) { $img = new XhtmlComponentImage(); $img->src = getThumbUrl($o['value']); $arr[$o['id']] = $img->render(); } $form->addRadio($f->name, $f->label, $arr, UserSetting::get($session->id, $f->name)); break; case UserDataField::IMAGE: $pic_id = UserSetting::get($session->id, 'picture'); if ($pic_id) { $img = new XhtmlComponentImage(); $img->src = getThumbUrl($pic_id); $form->add($img, 'Existing picture'); $form->addCheckbox('remove_' . $f->id, 'Remove photo');
echo 'User level: ' . UserHandler::getUserLevel($user_id) . '<br/>'; $gender_id = UserSetting::get($user_id, 'gender'); $gender = Setting::getById(USERDATA_OPTION, $gender_id); echo 'Gender: ' . $gender . '<br/>'; $pres = UserSetting::get($user_id, 'presentation'); if ($pres) { echo 'Presentation: ' . $pres . '<br/>'; } $pic_id = UserSetting::get($user_id, 'picture'); if ($pic_id) { echo 'Profile picture:<br/>'; $a = new XhtmlComponentA(); $a->href = getThumbUrl($pic_id, 0, 0); $a->content = showThumb($pic_id, 'Profilbild', 150, 150); echo $a->render(); } else { $avatar_opt = UserSetting::get($user_id, 'avatar'); // get pic id from avatar_id $avatar_id = UserDataFieldOption::getById($avatar_opt); if ($avatar_id) { echo 'Avatar:<br/>'; $a = new XhtmlComponentA(); $a->href = getThumbUrl($avatar_id, 0, 0); $a->content = showThumb($avatar_id, 'Avatar', 150, 150); echo $a->render(); } } break; default: echo 'No handler for view ' . $this->owner; }