This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmessu-broadcast.php
134 lines (129 loc) · 5.01 KB
/
messu-broadcast.php
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 tikiwiki
*/
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// 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.
// $Id$
$section = 'user_messages';
require_once ('tiki-setup.php');
include_once ('lib/messu/messulib.php');
$access->check_user($user);
$access->check_feature('feature_messages');
$auto_query_args = array('to', 'cc', 'bcc', 'subject', 'body', 'priority', 'replyto_hash', 'groupbr');
if (!isset($_REQUEST['to'])) $_REQUEST['to'] = '';
if (!isset($_REQUEST['cc'])) $_REQUEST['cc'] = '';
if (!isset($_REQUEST['bcc'])) $_REQUEST['bcc'] = '';
if (!isset($_REQUEST['subject'])) $_REQUEST['subject'] = '';
if (!isset($_REQUEST['body'])) $_REQUEST['body'] = '';
if (!isset($_REQUEST['priority'])) $_REQUEST['priority'] = 3;
if (!isset($_REQUEST['replyto_hash'])) $_REQUEST['replyto_hash'] = '';
$smarty->assign('to', $_REQUEST['to']);
$smarty->assign('cc', $_REQUEST['cc']);
$smarty->assign('bcc', $_REQUEST['bcc']);
$smarty->assign('subject', $_REQUEST['subject']);
$smarty->assign('body', $_REQUEST['body']);
$smarty->assign('priority', $_REQUEST['priority']);
$smarty->assign('replyto_hash', $_REQUEST['replyto_hash']);
$smarty->assign('mid', 'messu-broadcast.tpl');
$smarty->assign('sent', 0);
$groups = $userlib->list_all_groups();
$groups = array_diff($groups, array('Anonymous'));
$groups = array_filter(
$groups,
function ($groupName) {
$perms = Perms::get('group', $groupName);
return $perms->broadcast;
}
);
if (empty($groups)) {
$access->display_error('', tra("You do not have permission to use this feature").": ". $permission, '403', false);
exit;
}
$smarty->assign('groups', $groups);
if (isset($_REQUEST['send']) || isset($_REQUEST['preview'])) {
check_ticket('messu-broadcast');
$message = '';
// Validation:
// must have a subject or body non-empty (or both)
if (empty($_REQUEST['subject']) && empty($_REQUEST['body'])) {
$smarty->assign('message', tra('ERROR: Either the subject or body must be non-empty'));
$smarty->display("tiki.tpl");
die;
}
// Remove invalid users from the to, cc and bcc fields
if (isset($_REQUEST['groupbr'])) {
if ($_REQUEST['groupbr'] == 'all' && $tiki_p_broadcast_all == 'y') {
$a_all_users = $userlib->get_users(0, -1, 'login_desc', '');
$all_users = array();
foreach ($a_all_users['data'] as $a_user) {
$all_users[] = $a_user['user'];
}
} elseif (in_array($_REQUEST['groupbr'], $groups)) {
$all_users = $userlib->get_group_users($_REQUEST['groupbr']);
} else {
$access->display_error('', tra("You do not have permission to use this feature").": ". $permission, '403', false);
}
$smarty->assign('groupbr', $_REQUEST['groupbr']);
}
$users = array();
foreach ($all_users as $a_user) {
if (!empty($a_user)) {
if ($userlib->user_exists($a_user)) {
if (!$userlib->user_has_permission($a_user, 'tiki_p_messages')) {
$message .= sprintf(tra('User %s does not have the permission'), htmlspecialchars($a_user)). "<br />" ;
} elseif ($tikilib->get_user_preference($a_user, 'allowMsgs', 'y') == 'y') {
$users[] = $a_user;
} else {
$message.= sprintf(tra("User %s does not want to receive messages"), htmlspecialchars($a_user)). "<br />" ;
}
} else {
$message.= tra("Invalid user") . "$a_user<br />";
}
}
}
$users = array_unique($users);
// Validation: either to, cc or bcc must have a valid user
if (count($users) > 0) {
$users_formatted = array();
foreach ($users as $rawuser)
$users_formatted[] = htmlspecialchars($rawuser);
if (isset($_REQUEST['send'])) {
$message .= tra('The message has been sent to:').' ';
} else {
$message .= tra('The message will be sent to:').' ';
}
$message .= implode(',', $users_formatted) . "<br />";
} else {
$message .= tra('ERROR: No valid users to send the message');
$smarty->assign('message', $message);
$smarty->display("tiki.tpl");
die;
}
if (isset($_REQUEST['send'])) {
$smarty->assign('sent', 1);
// Insert the message in the inboxes of each user
foreach ($users as $a_user) {
$messulib->post_message($a_user, $user, $a_user, '', $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority']);
// if this is a reply flag the original messages replied to
if ($_REQUEST['replyto_hash'] <> '') {
$messulib->mark_replied($a_user, $_REQUEST['replyto_hash']);
}
}
// Insert a copy of the message in the sent box of the sender
$messulib->save_sent_message($user, $user, $_REQUEST['groupbr'], $_REQUEST['cc'], $_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['priority'], $_REQUEST['replyto_hash']);
$smarty->assign('message', $message);
if ($prefs['feature_actionlog'] == 'y') {
$logslib->add_action('Posted', '', 'message', 'add=' . strlen($_REQUEST['body']));
}
} else {
$smarty->assign('message', $message);
$smarty->assign('preview', 1);
}
}
ask_ticket('messu-broadcast');
include_once ('tiki-section_options.php');
include_once ('tiki-mytiki_shared.php');
$smarty->display("tiki.tpl");