tiki-contact.php 2.8 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
10 11

require_once ('tiki-setup.php');
12

13
include_once ('lib/messu/messulib.php');
14 15
include_once ('lib/userprefs/scrambleEmail.php');

16
// This feature needs both 'feature_contact' and 'feature_messages' to work
17
$access->check_feature(array('feature_contact', 'feature_messages'));
18

19 20
$auto_query_args = array();

21 22 23
if ($user) {
	$access->check_permission('tiki_p_messages');
} else {
24
	$access->check_feature('contact_anon');
25
}
26

27
$smarty->assign('sent', 0);
28

29 30 31 32 33 34
$priority = 3;
$from = $user ? $user : '';
$subject = '';
$body = '';
if (isset($_REQUEST['send'])) {
	if (isset($_REQUEST['priority'])) {
35
		$priority = $_REQUEST['priority'];
36
	}
37 38 39
	if (!$user && validate_email($_REQUEST['from'])) {
		$from =  'tiki-contact.php';
		$body .= tra('From') . " " . $_REQUEST['from'] . ":\n";
40 41 42 43 44
	}
	if (isset($_REQUEST['subject'])) {
		$subject =  $_REQUEST['subject'];
	}
	if (isset($_REQUEST['body'])) {
45
		$body .=  $_REQUEST['body'];
46 47
	}
}
48

49 50 51 52
if (isset($_REQUEST['send'])) {
	// Validation:
	// must have a subject or body non-empty (or both)
	$hasContent = !empty($_REQUEST['subject']) || !empty($_REQUEST['body']);
53

54 55 56 57 58
	$failsCaptcha = !$user && $prefs['feature_antibot'] == 'y' && !$captchalib->validate();
	if (!$hasContent || empty($from) || $failsCaptcha) {
		if (!$hasContent) {
			$message = tra("You must include a subject or a message.");
		} elseif (empty($from)) {
59
			$message = tra("You must make sure to have a valid email address in the From field.");
60 61
		} else {
			$message = $captchalib->getErrors();
62
		}
63 64 65
		$smarty->assign('errorMessage', $message);
	} else {
		$access->check_ticket();
66
		$body = tr("%0 sent you a message:", $from) . "\n" . $body;
67
		$messulib->post_message(
68 69 70 71 72 73
			$prefs['contact_user'],
			$from,
			$_REQUEST['to'],
			'',
			$_REQUEST['subject'],
			$body,
74
			$priority
75
		);
76 77 78
		$contact_name = $userlib->get_user_preference($prefs['contact_user'], 'realName');
		if ($contact_name == '') $contact_name = $prefs['contact_user'];
		$message = tra('Message sent to'). ': ' . $contact_name . '<br />';
79
		$smarty->assign('sent', 1);
80 81
		$smarty->assign('message', $message);
	}
82 83
}

84 85 86 87 88 89
$email = $userlib->get_user_email($prefs['contact_user']);
if ($email == '') $email = $userlib->get_admin_email();
$smarty->assign('email0', $email);
$email = scrambleEmail($email, $tikilib->get_user_preference('admin', "email is public"));
$smarty->assign('email', $email);

90 91 92 93
$smarty->assign('priority', $priority);
$smarty->assign('from', $from);
$smarty->assign('subject', $subject);
$smarty->assign('body', $body);
94

95
$smarty->assign('mid', 'tiki-contact.tpl');
96
$smarty->display("tiki.tpl");