1<?php
2/**
3 * Federated Login for DokuWiki - manage user claimed identities class
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @link       http://www.dokuwiki.org/plugin:fedauth
7 * @author     Aoi Karasu <aoikarasu@gmail.com>
8 */
9
10/**
11 * Class enabling users to manage their claimed identities.
12 *
13 * @author     Aoi Karasu <aoikarasu@gmail.com>
14 */
15class fa_manage extends fa_login {
16
17    /**
18     * Creates the class instance bound to a plugin instance and an authentication provider.
19     *
20     * @param objref $manager object reference to the admin plugin
21     * @param string $cmd name of the command to handle
22     * @param string $provid (optional) an authentication provider id
23     */
24    function __construct(&$manager, $cmd, $provid='') {
25        parent::__construct(&$manager, $cmd, $provid);
26    }
27
28    /**
29     * No pocessing for the time being.
30     * This method is intended to suppress the 'unknown command' message only.
31     */
32    function process_manage() {
33        $this->success = true;
34        return null;
35    }
36
37    /**
38     * Renders the user identities management page.
39     */
40    function html_manage() {
41//        print "<pre>".print_r($_REQUEST, true)."</pre>";
42
43        $out = $this->manager->locale_xhtml('mylogins');
44        $out = str_replace('@MYLOGINSLIST@', $this->html_mylogins_form(), $out);
45        print $out;
46
47        $this->html_login_service_from();
48    }
49
50    /**
51     * Renders the user's identities associated with his wiki account.
52     */
53    function html_mylogins_form() {
54        global $ID;
55
56        $out = '<div id="fa__mylogins"><form action="'.wl($ID, 'do=fedauth', true, '&').'" method="post">'
57             . '  <fieldset class="hidden">'
58//             . '    <input type="hidden" name="do" value="fedauth" />'
59             . formSecurityToken(false)
60             . '  </fieldset>'
61             . '  <div id="axwrap__mylogins">'
62             . $this->html_mylogins_list()
63             . '  </div>'
64             . '</form></div>';
65        return $out;
66    }
67
68    function html_mylogins_list() {
69//        global $conf;
70
71        $even = false;
72        // TODO: sanity checks
73        $store = $this->getUserStore();
74        $data =& $store->getUserData();
75//        $out = "<pre>".print_r($data, true)."</pre>";
76        $current = isset($_SESSION[DOKU_COOKIE]['fedauth']) ? $_SESSION[DOKU_COOKIE]['fedauth']['prid'] : '';
77
78        foreach ($data as $entry) {
79            $id = $entry['id'];
80            $pro = $this->manager->providers->get($id);
81            $class = $even = !$even ? ' class="even"' : '';
82            $using = $id == $current ? '<span class="inuse">('.$this->manager->getLang('inuse').')</span>' : '';
83
84            $out .= '    <fieldset'.$class.'>'
85                 .  '      <legend>'.$id.'</legend>'
86                 .  '      <div class="legend"><label for="dw__p_'.$id.'">'.$pro->getImageXHTML().$pro->getName().'</label>'
87                 .  $using
88                 .  '      <div id="fa__det_'.$id.'">'.$entry['ident'].'</div></div>'
89                 .  '      <span class="lastused">'.dformat($entry['last']).'</span>'
90                 .  $this->_html_button($id, base64_encode($entry['ident']),'remove', $id == $current, 6)
91                 .  '    </fieldset>';
92        }
93
94        return $out;
95    }
96
97    function _html_button($provid, $aid, $btn, $disabled=false, $indent=0, $class='') {
98        $disabled = ($disabled) ? 'disabled="disabled"' : '';
99        return str_repeat(' ', $indent)
100            . '<input type="submit" class="button '.$class.'" '.$disabled.' name="fa['.$btn.']['.$provid.']['.$aid.']" title="'.$this->lang['btn_'.$btn].'" value="'.$this->lang['btn_'.$btn].'" />';
101    }
102
103} /* fa_manage */
104
105/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
106