File: Account.php

package info (click to toggle)
php-horde 5.2.13%2Bdebian0-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,652 kB
  • sloc: php: 11,153; xml: 6,751; javascript: 5,560; sh: 92; makefile: 33; sql: 1
file content (125 lines) | stat: -rw-r--r-- 4,043 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
 * Copyright 2001-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL-2). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author  Eric Jon Rostetter <eric.rostetter@physics.utexas.edu>
 * @author  Jan Schneider <jan@horde.org>
 * @package Horde
 */
class Horde_Block_Account extends Horde_Core_Block
{
    /**
     */
    public function __construct($app, $params = array())
    {
        parent::__construct($app, $params);
        $this->_name = _("Account Information");
    }

    /**
     */
    protected function _title()
    {
        return _("My Account Information");
    }

    /**
     */
    protected function _content()
    {
        global $registry, $conf;

        $params = array_merge(
            (array)$conf['accounts']['params'],
            array('user' => $registry->getAuth()));

        switch ($conf['accounts']['driver']) {
        case 'null':
            $mydriver = new Horde_Block_Account_Base($params);
            break;

        case 'localhost':
        case 'finger':
        //case 'kolab':
            $class = 'Horde_Block_Account_' . Horde_String::ucfirst($conf['accounts']['driver']);
            $mydriver = new $class($params);
            break;

        case 'ldap':
            $params = Horde::getDriverConfig('accounts', 'ldap');
            $params['ldap'] = $GLOBALS['injector']
                ->getInstance('Horde_Core_Factory_Ldap')
                ->create('horde', 'accounts');
            $params['user'] = $registry->getAuth($params['strip'] ? 'bare' : null);
            $mydriver = new Horde_Block_Account_Ldap($params);
            break;

        default:
            return '';
        }

        try {
            // Check for password status.
            $status = $mydriver->checkPasswordStatus();

            $table = array(_("User Name") => $mydriver->getUsername());
            if ($fullname = $mydriver->getFullname()) {
                $table[_("Full Name")] = $fullname;
            }
            if ($home = $mydriver->getHome()) {
                $table[_("Home Directory")] = $home;
            }
            if ($shell = $mydriver->getShell()) {
                $table[_("Default Shell")] = $shell;
            }
            if ($quota = $mydriver->getQuota()) {
                $table[_("Quota")] = sprintf(
                    _("%.2fMB used of %.2fMB allowed (%.2f%%)"),
                    $quota['used'] / ( 1024 * 1024.0),
                    $quota['limit'] / ( 1024 * 1024.0),
                    ($quota['used'] * 100.0) / $quota['limit']);
            }
            if ($lastchange = $mydriver->getPasswordChange()) {
                $table[_("Last Password Change")] = $lastchange;
            }
        } catch (Horde_Exception $e) {
            return $e->getMessage();
        }

        $output = '<table class="item" width="100%" cellspacing="1">';

        if ($status) {
            $output .= '<tr><td colspan="2"><p class="notice">' .
                Horde_Themes_Image::tag('alerts/warning.png', array('alt' => _("Warning"))) .
                '&nbsp;&nbsp;' . $status . '</p></td></tr>';
        }

        foreach ($table as $key => $value) {
            $output .= "<tr class=\"text\"><td>$key</td><td>$value</td></tr>\n";
        }
        $output .= "</table>\n";

        if (!$registry->isInactive('forwards') &&
            $registry->hasMethod('summary', 'forwards')) {
            try {
                $summary = $registry->callByPackage('forwards', 'summary');
                $output .= '<br />' . $summary . "\n";
            } catch (Exception $e) {
            }
        }

        if (!$registry->isInactive('vacation') &&
            $registry->hasMethod('summary', 'vacation')) {
            try {
                $summary = $registry->callByPackage('vacation', 'summary');
                $output .= '<br />' . $summary . "\n";
            } catch (Exception $e) {
            }
        }

        return $output;
    }
}