File: Contact.php

package info (click to toggle)
turba2 2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,332 kB
  • ctags: 2,927
  • sloc: php: 11,046; xml: 1,690; sql: 507; makefile: 62; perl: 17; sh: 1
file content (134 lines) | stat: -rw-r--r-- 4,940 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
<?php
/**
 * @package Turba
 */

/** Turba_ContactForm */
require_once TURBA_BASE . '/lib/Forms/Contact.php';

/**
 * The Turba_View_Contact:: class provides an API for viewing events.
 *
 * $Horde: turba/lib/Views/Contact.php,v 1.16.2.2 2008/02/29 04:38:11 chuck Exp $
 *
 * @author  Chuck Hagenbuch <chuck@horde.org>
 * @since   Turba 2.2
 * @package Turba
 */
class Turba_View_Contact {

    /**
     * @var Turba_Object
     */
    var $contact;

    /**
     * @var boolean
     */
    var $print = false;

    /**
     * @param Turba_Object &$contact
     */
    function Turba_View_Contact(&$contact, $print = null)
    {
        $this->contact = &$contact;
        if (!is_null($print)) {
            $this->print = $print;
        }

        /* Set print link. */
        if (!$this->print) {
            $GLOBALS['print_link'] = Util::addParameter($this->contact->url(), 'print', 1);
        }
    }

    function getTitle()
    {
        if (!$this->contact || is_a($this->contact, 'PEAR_Error')) {
            return _("Not Found");
        }
        return $this->contact->getValue('name');
    }

    function html($active = true)
    {
        global $conf, $prefs, $registry;

        if (!$this->contact || is_a($this->contact, 'PEAR_Error') || !$this->contact->hasPermission(PERMS_READ)) {
            echo '<h3>' . _("The requested contact was not found.") . '</h3>';
            return;
        }

        $vars = new Variables();
        $form = &new Turba_ContactForm($vars, $this->contact);
        $userId = Auth::getAuth();

        /* Get the contact's history. */
        if ($this->contact->getValue('__uid')) {
            $history = &Horde_History::singleton();
            $log = $history->getHistory($this->contact->getGuid());
            if ($log && !is_a($log, 'PEAR_Error')) {
                foreach ($log->getData() as $entry) {
                    switch ($entry['action']) {
                    case 'add':
                        if ($userId != $entry['who']) {
                            $createdby = sprintf(_("by %s"), Turba::getUserName($entry['who']));
                        } else {
                            $createdby = _("by me");
                        }
                        $v = &$form->addVariable(_("Created"), 'object[__created]', 'text', false, false);
                        $v->disable();
                        $vars->set('object[__created]', strftime($prefs->getValue('date_format'), $entry['ts']) . ' ' . date($prefs->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts']) . ' ' . @htmlspecialchars($createdby, ENT_COMPAT, NLS::getCharset()));
                        break;

                    case 'modify':
                        if ($userId != $entry['who']) {
                            $modifiedby = sprintf(_("by %s"), Turba::getUserName($entry['who']));
                        } else {
                            $modifiedby = _("by me");
                        }
                        $v = &$form->addVariable(_("Last Modified"), 'object[__modified]', 'text', false, false);
                        $v->disable();
                        $vars->set('object[__modified]', strftime($prefs->getValue('date_format'), $entry['ts']) . ' ' . date($prefs->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts']) . ' ' . @htmlspecialchars($modifiedby, ENT_COMPAT, NLS::getCharset()));
                        break;
                    }
                }
            }
        }

        echo '<div id="Contact"' . ($active ? '' : ' style="display:none"') . '>';
        $form->renderInactive(new Horde_Form_Renderer(), $vars);

        /* Comments. */
        if (!empty($conf['comments']['allow']) && $registry->hasMethod('forums/doComments')) {
            $comments = $registry->call('forums/doComments', array('turba', $this->contact->driver->name . '.' . $this->contact->getValue('__key'), 'commentCallback'));
            if (is_a($comments, 'PEAR_Error')) {
                Horde::logMessage($comments, __FILE__, __LINE__, PEAR_LOG_DEBUG);
                $comments = array();
            }
        }
        if (!empty($comments['threads'])) {
            echo '<br />' . $comments['threads'];
        }
        if (!empty($comments['comments']) && !$this->print) {
            echo '<br />' . $comments['comments'];
        }

        echo '</div>';

        if ($active && $GLOBALS['browser']->hasFeature('dom')) {
            if ($this->contact->hasPermission(PERMS_EDIT)) {
                require_once TURBA_BASE . '/lib/Views/EditContact.php';
                $edit = new Turba_View_EditContact($this->contact);
                $edit->html(false);
            }
            if ($this->contact->hasPermission(PERMS_DELETE)) {
                require_once TURBA_BASE . '/lib/Views/DeleteContact.php';
                $delete = new Turba_View_DeleteContact($this->contact);
                $delete->html(false);
            }
        }
    }

}