xref: /dokuwiki/inc/Ui/UserProfile.php (revision bde2a644b7f10af4f4d8a7ca52281cd954538ea9)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\Form\Form;
6
7/**
8 * DokuWiki User Profile Interface
9 *
10 * @package dokuwiki\Ui
11 */
12class UserProfile extends Ui
13{
14    /**
15     * Display the User Profile Form Panel
16     *
17     * @author   Andreas Gohr <andi@splitbrain.org>
18     *
19     * @triggers HTMLFORM_UPDATEPROFILE_OUTPUT
20     * @triggers HTMLFORM_PROFILEDELETE_OUTPUT
21     * @return void
22     */
23    public function show()
24    {
25        global $lang;
26        global $conf;
27        global $INPUT;
28        global $INFO;
29        /** @var AuthPlugin $auth */
30        global $auth;
31
32        // print intro
33        print p_locale_xhtml('updateprofile');
34        print '<div class="centeralign">';
35
36        $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
37        $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
38
39        // create the updateprofile form
40        $form = new Form(['id' => 'dw__register']);
41        $form->addTagOpen('div')->addClass('no');
42        $form->addFieldsetOpen($lang['profile']);
43        $form->setHiddenField('do', 'profile');
44        $form->setHiddenField('save', '1');
45
46        $attr = array('size' => '50', 'disabled' => 'disabled');
47        $input = $form->addTextInput('login', $lang['user'])->attrs($attr)->addClass('edit')
48            ->val($INPUT->server->str('REMOTE_USER'));
49        $input->getLabel()->attr('class', 'block');
50        $form->addHTML("<br>\n");
51
52        $attr = array('size' => '50');
53        if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
54        $input = $form->addTextInput('fullname', $lang['fullname'])->attrs($attr)->addClass('edit')
55            ->val($fullname);
56        $input->getLabel()->attr('class', 'block');
57        $form->addHTML("<br>\n");
58
59        $attr = array('type' => 'email', 'size' =>  '50');
60        if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
61        $input = $form->addTextInput('email', $lang['email'])->attrs($attr)->addClass('edit')
62            ->val($email);
63        $input->getLabel()->attr('class', 'block');
64        $form->addHTML("<br>\n");
65
66        if ($auth->canDo('modPass')) {
67            $attr = array('size'=>'50');
68            $input = $form->addPasswordInput('newpass', $lang['newpass'])->attrs($attr)->addClass('edit');
69            $input->getLabel()->attr('class', 'block');
70            $form->addHTML("<br>\n");
71
72            $input = $form->addPasswordInput('passchk', $lang['passchk'])->attrs($attr)->addClass('edit');
73            $input->getLabel()->attr('class', 'block');
74            $form->addHTML("<br>\n");
75        }
76
77        if ($conf['profileconfirm']) {
78            $form->addHTML("<br>\n");
79            $attr = array('size' => '50', 'required' => 'required');
80            $input = $form->addPasswordInput('oldpass', $lang['oldpass'])->attrs($attr)->addClass('edit');
81            $input->getLabel()->attr('class', 'block');
82            $form->addHTML("<br>\n");
83        }
84
85        $form->addButton('', $lang['btn_save'])->attr('type', 'submit');
86        $form->addButton('', $lang['btn_reset'])->attr('type', 'reset');
87
88        $form->addFieldsetClose();
89        $form->addTagClose('div');
90
91        // print form that might be modified by HTMLFORM_UPDATEPROFILE_OUTPUT event handlers
92        print $form->toHTML('updateprofile');
93
94
95        if ($auth->canDo('delUser') && actionOK('profile_delete')) {
96
97            // create the profiledelete form
98            $form = new Form(['id' => 'dw__profiledelete']);
99            $form->addTagOpen('div')->addClass('no');
100            $form->addFieldsetOpen($lang['profdeleteuser']);
101            $form->setHiddenField('do', 'profile_delete');
102            $form->setHiddenField('delete', '1');
103
104            $form->addCheckbox('confirm_delete', $lang['profconfdelete'])
105                ->attrs(['required' => 'required'])
106                ->id('dw__confirmdelete')
107                ->val('1');
108
109            if ($conf['profileconfirm']) {
110                $form->addHTML("<br>\n");
111                $attr = array('size' => '50', 'required' => 'required');
112                $input = $form->addPasswordInput('oldppass', $lang['oldpass'])->attrs($attr)
113                    ->addClass('edit');
114                $input->getLabel()->attr('class', 'block');
115                $form->addHTML("<br>\n");
116            }
117
118            $form->addButton('', $lang['btn_deleteuser'])->attr('type', 'submit');
119            $form->addFieldsetClose();
120            $form->addTagClose('div');
121
122            // print form that might be modified by HTMLFORM_PROFILEDELETE_OUTPUT event handlers
123            print $form->toHTML('profiledelete');
124        }
125
126        print '</div>';
127    }
128
129}
130