1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Quota_Ui
24: {
25:
26: const SESSION_INTERVAL_KEY = 'quota_interval';
27:
28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: public function quota($mailbox = null, $force = true)
39: {
40: global $injector, $session;
41:
42: $qconfig = $injector->getInstance('IMP_Factory_Imap')->create()->config->quota;
43: if (!$qconfig) {
44: return false;
45: }
46:
47: $qlist = array();
48:
49: if (!is_null($mailbox)) {
50: $mailbox = IMP_Mailbox::get($mailbox);
51: if ($mailbox->nonimap) {
52: return false;
53: }
54:
55: if (!$force) {
56: $qlist = $session->get(
57: 'imp',
58: self::SESSION_INTERVAL_KEY,
59: $session::TYPE_ARRAY
60: );
61:
62: if (isset($qlist[strval($mailbox)]) &&
63: (time() < $qlist[strval($mailbox)])) {
64: return false;
65: }
66: }
67: }
68:
69: try {
70: $quotaDriver = $injector->getInstance('IMP_Quota');
71: $quota = $quotaDriver->getQuota($mailbox);
72: } catch (IMP_Exception $e) {
73: Horde::log($e, 'ERR');
74: return false;
75: }
76:
77: $qlist[strval($mailbox)] = $qconfig['params']['interval'] + time();
78: $session->set('imp', self::SESSION_INTERVAL_KEY, $qlist);
79:
80: if (empty($quota)) {
81: return false;
82: }
83:
84: $strings = $quotaDriver->getMessages();
85: list($calc, $unit) = $quotaDriver->getUnit();
86: $ret = array(
87: 'class' => '',
88: 'percent' => 0
89: );
90:
91: if ($quota['limit'] != 0) {
92: $quota['usage'] = $quota['usage'] / $calc;
93: $quota['limit'] = $quota['limit'] / $calc;
94: $ret['percent'] = ($quota['usage'] * 100) / $quota['limit'];
95: if ($ret['percent'] >= 90) {
96: $ret['class'] = 'quotaalert';
97: } elseif ($ret['percent'] >= 75) {
98: $ret['class'] = 'quotawarn';
99: }
100:
101: $ret['message'] = sprintf($strings['short'], $ret['percent'], $quota['limit'], $unit);
102: $ret['percent'] = sprintf("%.2f", $ret['percent']);
103: } elseif ($quotaDriver->isHiddenWhenUnlimited()) {
104: return false;
105: } elseif ($quota['usage'] != 0) {
106: $quota['usage'] = $quota['usage'] / $calc;
107:
108: $ret['message'] = sprintf($strings['nolimit_short'], $quota['usage'], $unit);
109: } else {
110: $ret['message'] = _("No limit");
111: }
112:
113: return $ret;
114: }
115:
116: }
117: