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