tiki-admin_notifications.php 3.97 KB
Newer Older
lrargerich's avatar
lrargerich committed
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.
9
// $Id$
changi67's avatar
changi67 committed
10

changi67's avatar
changi67 committed
11
$inputConfiguration = array(
12 13 14 15 16 17 18 19 20 21 22
	array(
		'staticKeyFilters' => array(
			'offset' => 'digits',
			'maxRecords' => 'digits',
			'removeevent' => 'digits',
			'removetype' => 'word',
			'daconfirm' => 'word',
			'ticket' => 'word',
			'sort_mode' => 'word',
			'find' => 'striptags',
			'email' => 'email',
23
			'event' => 'text',
24 25 26 27 28 29 30
			'add' => 'alpha',
			'delsel_x' => 'alpha',
		) ,
		'staticKeyFiltersForArrays' => array(
			'checked' => 'alnum',
		) ,
	)
changi67's avatar
changi67 committed
31
);
lrargerich's avatar
lrargerich committed
32
// Initialization
33
require_once ('tiki-setup.php');
34
$access->check_permission(array('tiki_p_admin_notifications'));
35

36 37
$notificationlib = TikiLib::lib('notification');

changi67's avatar
changi67 committed
38
$auto_query_args = array(
39 40 41 42
	'offset',
	'sort_mode',
	'find',
	'maxRecords'
changi67's avatar
changi67 committed
43
);
44 45
$watches = $notificationlib->get_global_watch_types();

46
$save = true;
47
$login = '';
48
if (isset($_REQUEST["add"])) {
49 50 51 52 53
	check_ticket('admin-notif');
	if (!empty($_REQUEST['login'])) {
		if ($userlib->user_exists($_REQUEST['login'])) {
			$login = $_REQUEST['login'];
		} else {
54
			Feedback::error(tra('Invalid username'));
55 56 57 58 59 60
			$save = false;
		}
	} elseif (!empty($_REQUEST['email'])) {
		if (validate_email($_REQUEST['email'], $prefs['validateEmail'])) {
			$email = $_REQUEST['email'];
		} else {
61
			Feedback::error(tra('Invalid email'));
62 63 64
			$save = false;
		}
	} else {
65
		Feedback::error(tra('You need to provide a username or an email'));
66 67 68
		$save = false;
	}
	if ($save and isset($_REQUEST['event']) and isset($watches[$_REQUEST['event']])) {
69
		$result = $tikilib->add_user_watch($login, $_REQUEST["event"], $watches[$_REQUEST['event']]['object'], $watches[$_REQUEST['event']]['type'], $watches[$_REQUEST['event']]['label'], $watches[$_REQUEST['event']]['url'], isset($email) ? $email : NULL);
70
		if (!$result) {
71
			Feedback::error(tra('The user has no email set. No notifications will be sent.'));
72
		}
73
	}
lrargerich's avatar
lrargerich committed
74
}
75

76
if (isset($_REQUEST["removeevent"]) && isset($_REQUEST['removetype'])) {
77 78 79
	$access->check_authenticity();
	if ($_REQUEST['removetype'] == 'user') {
		$tikilib->remove_user_watch_by_id($_REQUEST["removeevent"]);
80
	} else {
81
		$tikilib->remove_group_watch_by_id($_REQUEST["removeevent"]);
82
	}
lrargerich's avatar
lrargerich committed
83
}
84
if (isset($_REQUEST['delsel_x']) && isset($_REQUEST['checked'])) {
85
	check_ticket('admin-notif');
86
	foreach ($_REQUEST['checked'] as $id) {
87 88 89
		if (strpos($id, 'user') === 0) $tikilib->remove_user_watch_by_id(substr($id, 4));
		else $tikilib->remove_group_watch_by_id(substr($id, 5));
	}
changi67's avatar
changi67 committed
90
}
91
if (!isset($_REQUEST["sort_mode"])) {
92
	$sort_mode = 'event_asc';
lrargerich's avatar
lrargerich committed
93
} else {
94
	$sort_mode = $_REQUEST["sort_mode"];
95 96
}
if (!isset($_REQUEST["offset"])) {
97
	$offset = 0;
lrargerich's avatar
lrargerich committed
98
} else {
99
	$offset = $_REQUEST["offset"];
lrargerich's avatar
lrargerich committed
100
}
101 102
$smarty->assign_by_ref('offset', $offset);
if (isset($_REQUEST["find"])) {
103
	$find = $_REQUEST["find"];
lrargerich's avatar
lrargerich committed
104
} else {
105
	$find = '';
lrargerich's avatar
lrargerich committed
106
}
107 108
$smarty->assign_by_ref('find', $find);
if (!empty($_REQUEST['maxRecords'])) {
109
	$maxRecords = $_REQUEST['maxRecords'];
110
}
111
$smarty->assign_by_ref('watches', $watches);
112
$smarty->assign_by_ref('maxRecords', $maxRecords);
113
$smarty->assign_by_ref('sort_mode', $sort_mode);
114
$channels = $tikilib->list_watches($offset, $maxRecords, $sort_mode, $find);
115
$smarty->assign_by_ref('cant', $channels['cant']);
116
$smarty->assign_by_ref('channels', $channels["data"]);
117
if ($prefs['feature_trackers'] == 'y') {
lphuberdeau's avatar
lphuberdeau committed
118
	$trklib = TikiLib::lib('trk');
119 120
	$trackers = $trklib->get_trackers_options(0, 'outboundemail', $find, 'empty');
	$smarty->assign_by_ref('trackers', $trackers);
121 122
}
if ($prefs['feature_forums'] == 'y') {
123
	$commentslib = TikiLib::lib('comments');
124 125
	$forums = $commentslib->get_outbound_emails();
	$smarty->assign_by_ref('forums', $forums);
126
}
mose's avatar
mose committed
127
ask_ticket('admin-notif');
128 129
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
130

lrargerich's avatar
lrargerich committed
131
// Display the template
132
$smarty->assign('mid', 'tiki-admin_notifications.tpl');
133
$smarty->display("tiki.tpl");