contact.php 3.54 KB
Newer Older
Richard Mansfield's avatar
Richard Mansfield committed
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
<?php
/**
 * This program is part of Mahara
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage core
 * @author     Penny Leach <penny@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

define('INTERNAL', 1);
28
define('PUBLIC', 1);
Richard Mansfield's avatar
Richard Mansfield committed
29
30

require('init.php');
Richard Mansfield's avatar
Richard Mansfield committed
31
32
33
require_once('form.php');

if ($SESSION->is_logged_in()) {
34
    $name = display_name($USER);
Richard Mansfield's avatar
Richard Mansfield committed
35
36
37
38
39
40
41
42
43
44
45
    $email = $USER->email;
}
else {
    $name = '';
    $email = '';
}

$contactform = form(array(
    'name'     => 'contactus',
    'method'   => 'post',
    'action'   => '',
46
    'ajaxpost' => true,
Richard Mansfield's avatar
Richard Mansfield committed
47
48
49
50
    'elements' => array(
        'name' => array(
            'type'  => 'text',
            'title' => get_string('name'),
51
            'defaultvalue' => $name,
Richard Mansfield's avatar
Richard Mansfield committed
52
53
54
55
56
57
58
            'rules' => array(
                'required'    => true
            ),
        ),
        'email' => array(
            'type'  => 'text',
            'title' => get_string('email'),
59
            'defaultvalue' => $email,
Richard Mansfield's avatar
Richard Mansfield committed
60
61
62
63
64
65
66
            'rules' => array(
                'required'    => true
            ),
        ),
        'subject' => array(
            'type'  => 'text',
            'title' => get_string('subject'),
67
            'defaultvalue' => '',
Richard Mansfield's avatar
Richard Mansfield committed
68
69
70
71
72
73
        ),
        'message' => array(
            'type'  => 'textarea',
            'rows'  => 10,
            'cols'  => 60,
            'title' => get_string('message'),
74
            'defaultvalue' => '',
Richard Mansfield's avatar
Richard Mansfield committed
75
76
77
78
79
80
81
82
83
84
            'rules' => array(
                'required'    => true
            ),
        ),
        'submit' => array(
            'type'  => 'submit',
            'value' => get_string('submitcontactinformation')
        ),
    )
));
Richard Mansfield's avatar
Richard Mansfield committed
85

86
87
88
89
90
91
function contactus_submit($values) {
    $contactemail = get_config('contactaddress');
    if (empty($contactemail)) {
        json_reply('local', get_string('nositecontactaddress'));
    }

92
    // email_user requires firstname, lastname to be set, so put something in
93
    $to = new StdClass;
94
    $to->firstname = get_config('sitename');
95
    $to->lastname = get_string('contactaddress');
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    $to->email = $contactemail;

    $fromnames = explode(' ',$values['name']);
    if (empty($fromnames)) {
        json_reply('local', get_string('nosendernamefound'));
    }
    $from = new StdClass;
    $from->firstname = $fromnames[0];
    $from->lastname = count($fromnames) < 2 ? $fromnames[0] : implode(' ',array_slice($fromnames,1));
    $from->email = $values['email'];

    try {
        email_user($to,$from,$values['subject'],$values['message']);
    }
    catch (Exception $e) {
111
        json_reply('local', get_string('emailnotsent', 'mahara', $e->getMessage()));
112
113
114
115
116
117
    }

    json_reply(false, get_string('contactinformationsent'));
}


Richard Mansfield's avatar
Richard Mansfield committed
118
$smarty = smarty();
Richard Mansfield's avatar
Richard Mansfield committed
119
120
$smarty->assign('page_content', $contactform);
$smarty->assign('site_menu', site_menu());
Richard Mansfield's avatar
Richard Mansfield committed
121
122
123
$smarty->display('sitepage.tpl');

?>