tiki-contact.php 3 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 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 12 13 14 15 16 17 18
$inputConfiguration =	[[
	'staticKeyFilters'	=> [
		'send'			=> 'word', 		// post
		'priority'		=> 'int', 		// post
		'from'			=> 'striptags',	// post
		'subject'		=> 'striptags',	// post
		'body'			=> 'xss',		// post
		'to'			=> 'email',		// post
	]]];
19 20

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

22
$messulib = TikiLib::lib('message');
23

24
// This feature needs both 'feature_contact' and 'feature_messages' to work
25
$access->check_feature(array('feature_contact', 'feature_messages'));
26

27 28
$auto_query_args = array();

29 30 31
if ($user) {
	$access->check_permission('tiki_p_messages');
} else {
32
	$access->check_feature('contact_anon');
33
}
34

35
$smarty->assign('sent', 0);
36

37 38 39 40 41 42
$priority = 3;
$from = $user ? $user : '';
$subject = '';
$body = '';
if (isset($_REQUEST['send'])) {
	if (isset($_REQUEST['priority'])) {
43
		$priority = $_REQUEST['priority'];
44
	}
45 46 47
	if (!$user && validate_email($_REQUEST['from'])) {
		$from =  'tiki-contact.php';
		$body .= tra('From') . " " . $_REQUEST['from'] . ":\n";
48 49 50 51 52
	}
	if (isset($_REQUEST['subject'])) {
		$subject =  $_REQUEST['subject'];
	}
	if (isset($_REQUEST['body'])) {
53
		$body .=  $_REQUEST['body'];
54 55
	}
}
56

57 58 59 60
if (isset($_REQUEST['send'])) {
	// Validation:
	// must have a subject or body non-empty (or both)
	$hasContent = !empty($_REQUEST['subject']) || !empty($_REQUEST['body']);
61

62 63 64 65 66
	$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)) {
67
			$message = tra("You must make sure to have a valid email address in the From field.");
68 69
		} else {
			$message = $captchalib->getErrors();
70
		}
71 72 73
		$smarty->assign('errorMessage', $message);
	} else {
		$access->check_ticket();
74
		$body = tr("%0 sent you a message:", $from) . "\n" . $body;
75
		$messulib->post_message(
76 77 78 79 80 81
			$prefs['contact_user'],
			$from,
			$_REQUEST['to'],
			'',
			$_REQUEST['subject'],
			$body,
82
			$priority
83
		);
84 85 86
		$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 />';
87
		$smarty->assign('sent', 1);
88 89
		$smarty->assign('message', $message);
	}
90 91
}

92 93 94
$email = $userlib->get_user_email($prefs['contact_user']);
if ($email == '') $email = $userlib->get_admin_email();
$smarty->assign('email0', $email);
95
$email = TikiMail::scrambleEmail($email, $tikilib->get_user_preference('admin', "email is public"));
96 97
$smarty->assign('email', $email);

98 99 100 101
$smarty->assign('priority', $priority);
$smarty->assign('from', $from);
$smarty->assign('subject', $subject);
$smarty->assign('body', $body);
102

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