File: problem.php

package info (click to toggle)
horde3 3.1.3-4etch7
  • links: PTS
  • area: main
  • in suites: etch
  • size: 22,876 kB
  • ctags: 18,071
  • sloc: php: 75,151; xml: 2,979; sql: 1,069; makefile: 79; sh: 64
file content (133 lines) | stat: -rw-r--r-- 5,494 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
<?php
/**
 * $Horde: horde/services/problem.php,v 2.114.8.8 2006/01/16 14:24:03 chuck Exp $
 *
 * Copyright 1999-2006 Charles J. Hagenbuch <chuck@horde.org>
 * Copyright 1999-2006 Jon Parise <jon@horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

/* Send the browser back to the correct page. */
function _returnToPage()
{
    $url = Util::getFormData('return_url', Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/login.php', true));
    header('Location: ' . str_replace('&amp;', '&', $url));
    exit;
}

@define('AUTH_HANDLER', true);
@define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once HORDE_BASE . '/lib/version.php';
require_once 'Horde/Identity.php';

if (!Horde::showService('problem')) {
    _returnToPage();
}

$identity = &Identity::singleton();
$email = $identity->getValue('from_addr');
if (!$email) {
    $email = Util::getFormData('email', Auth::getAuth());
}
$message = Util::getFormData('message', '');
$name = Util::getFormData('name', $identity->getValue('fullname'));
$subject = Util::getFormData('subject', '');

$actionID = Util::getFormData('actionID');
switch ($actionID) {
case 'send_problem_report':
    if ($subject && $message) {
        // This is not a gettext string on purpose.
        $remote = (!empty($_SERVER['REMOTE_HOST'])) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR'];
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $body = "This problem report was received from $remote. " .
            "The user clicked the problem report link from the following location:\n" .
            Util::getFormData('return_url', 'No requesting page') .
            "\nand is using the following browser:\n$user_agent\n\n" .
            str_replace("\r\n", "\n", $message);

        // Default to a relatively reasonable email address.
        if (!$email) {
            $email = 'horde-problem@' . $conf['problems']['maildomain'];
        }

        if (!empty($conf['problems']['tickets']) &&
            $registry->hasMethod('tickets/addTicket')) {
            $info = array_merge($conf['problems']['ticket_params'],
                                array('summary' => $subject,
                                      'comment' => $body,
                                      'user_email' => $email));
            $result = $registry->call('tickets/addTicket', array($info));
            if (is_a($result, 'PEAR_Error')) {
                $notification->push($result);
            } else {
                _returnToPage();
            }
        } else {
            require_once 'Horde/MIME.php';
            require_once 'Horde/MIME/Headers.php';
            require_once 'Horde/MIME/Message.php';

            // Add user's name to the email address if provided.
            if ($name) {
                @list($mailbox, $host) = @explode('@', $email, 2);
                if (empty($host)) {
                    $host = $conf['problems']['maildomain'];
                }
                $email = MIME::rfc822WriteAddress($mailbox, $host, $name);
            }

            $msg_headers = &new MIME_Headers();
            $msg_headers->addReceivedHeader();
            $msg_headers->addMessageIdHeader();
            $msg_headers->addAgentHeader();
            $msg_headers->addHeader('Date', date('r'));
            $msg_headers->addHeader('To', $conf['problems']['email']);
            $msg_headers->addHeader('Subject', _("[Problem Report]") . ' ' . $subject);
            $msg_headers->addHeader('From', $email);
            $msg_headers->addHeader('Sender', 'horde-problem@' . $conf['problems']['maildomain']);

            $mime = &new MIME_Message();
            $mime->addPart(new MIME_Part('text/plain',
                                         String::wrap($body, 80, "\n"),
                                         NLS::getCharset()));
            $msg_headers->addMIMEHeaders($mime);

            $mail_driver = $conf['mailer']['type'];
            $mail_params = $conf['mailer']['params'];
            if ($mail_driver == 'smtp' && $mail_params['auth'] &&
                empty($mail_params['username'])) {
                if (Auth::getAuth()) {
                    $mail_params['username'] = Auth::getAuth();
                    $mail_params['password'] = Auth::getCredential('password');
                } elseif (!empty($conf['problems']['username']) &&
                          !empty($conf['problems']['password'])) {
                    $mail_params['username'] = $conf['problems']['username'];
                    $mail_params['password'] = $conf['problems']['password'];
                }
            }

            if (!is_a($sent = $mime->send($conf['problems']['email'], $msg_headers, $mail_driver, $mail_params), 'PEAR_Error')) {
                /* We succeeded. Return to previous page and exit this script. */
                _returnToPage();
            } else {
                $notification->push($sent);
            }
        }
    }
    break;

case 'cancel_problem_report':
    _returnToPage();
}

$title = _("Problem Description");
$menu = &new Menu(HORDE_MENU_MASK_ALL & ~HORDE_MENU_MASK_PREFS);
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/menu/menu.inc';
$notification->notify(array('listeners' => 'status'));
require HORDE_TEMPLATES . '/problem/problem.inc';
require HORDE_TEMPLATES . '/common-footer.inc';