tiki-admin_newsletter_subscriptions.php 8.43 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
3
// 
4 5
// 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.
6
// $Id$
changi67's avatar
changi67 committed
7

8
$section = 'newsletters';
9 10
require_once ('tiki-setup.php');
include_once ('lib/newsletters/nllib.php');
changi67's avatar
changi67 committed
11
$auto_query_args = array(
12 13 14 15 16 17 18
	'sort_mode',
	'offset',
	'find',
	'nlId',
	'sort_mode_g',
	'offset_g',
	'find_g'
changi67's avatar
changi67 committed
19
);
20

21
$access->check_feature('feature_newsletters');
22

23
if (!isset($_REQUEST["nlId"])) {
24 25 26 27
	$smarty->assign('msg', tra('No newsletter indicated'));
	$smarty->display('error.tpl');
	die;
}
28

29
$info = $nllib->get_newsletter($_REQUEST["nlId"]);
30

31 32 33
if (empty($info)) {
	$smarty->assign('msg', tra('Newsletter does not exist'));
	$smarty->display('error.tpl');
34
	die;
35
}
36

37
$smarty->assign('nlId', $_REQUEST["nlId"]);
38

39 40
$tikilib->get_perm_object($_REQUEST['nlId'], 'newsletter');

41
$access->check_permission('tiki_p_admin_newsletters');
42

43 44 45 46 47 48 49
if (isset($_REQUEST['delsel_x']) && isset($_REQUEST['checked'])) {
	$access->check_authenticity();
	foreach($_REQUEST['checked'] as $check) {
		$nllib->remove_newsletter_subscription_code($check);
	}
}

50 51
$smarty->assign('nl_info', $info);
if (isset($_REQUEST["remove"])) {
52 53 54 55 56
	$access->check_authenticity();
	if (isset($_REQUEST["email"])) $nllib->remove_newsletter_subscription($_REQUEST["remove"], $_REQUEST["email"], "n");
	elseif (isset($_REQUEST["subuser"])) $nllib->remove_newsletter_subscription($_REQUEST["remove"], $_REQUEST["subuser"], "y");
	elseif (isset($_REQUEST["group"])) $nllib->remove_newsletter_group($_REQUEST["remove"], $_REQUEST["group"]);
	elseif (isset($_REQUEST["included"])) $nllib->remove_newsletter_included($_REQUEST["remove"], $_REQUEST["included"]);
57
	elseif (isset($_REQUEST['page'])) $nllib->remove_newsletter_page($_REQUEST['remove'], $_REQUEST['page']);
58
}
59

60
if (isset($_REQUEST["valid"])) {
61 62 63
	check_ticket('admin-nl-subsriptions');
	if (isset($_REQUEST["email"])) $nllib->valid_subscription($_REQUEST["valid"], $_REQUEST["email"], "n");
	elseif (isset($_REQUEST["subuser"])) $nllib->valid_subscription($_REQUEST["valid"], $_REQUEST["subuser"], "y");
changi67's avatar
changi67 committed
64
}
65

changi67's avatar
changi67 committed
66 67
if (isset($_REQUEST["confirmEmail"]) && $_REQUEST["confirmEmail"] == "on") $confirmEmail = "n";
else $confirmEmail = $info["validateAddr"];
68

changi67's avatar
changi67 committed
69 70
if (isset($_REQUEST["addemail"]) && $_REQUEST["addemail"] == "y") $addEmail = "y";
else $addEmail = "n";
71

72
if (isset($_REQUEST["add"]) && isset($_REQUEST["email"]) && $_REQUEST["email"] != "") {
73 74
	check_ticket('admin-nl-subsriptions');
	if (strpos($_REQUEST["email"], ',')) {
75
		$emails = explode(',', $_REQUEST["email"]);
76 77 78 79 80 81 82 83 84 85
		foreach($emails as $e) {
			if ($userlib->user_exists(trim($e))) {
				$nllib->newsletter_subscribe($_REQUEST["nlId"], trim($e) , "y", $confirmEmail, $addEmail);
			} else {
				$nllib->newsletter_subscribe($_REQUEST["nlId"], trim($e) , "n", $confirmEmail, "");
			}
		}
	} else {
		$nllib->newsletter_subscribe($_REQUEST["nlId"], trim($_REQUEST["email"]) , "n", $confirmEmail, "");
	}
86
}
87

88
if (isset($_REQUEST["add"]) && isset($_REQUEST['subuser']) && $_REQUEST['subuser'] != "") {
89 90
	check_ticket('admin-nl-subsriptions');
	$sid = $nllib->newsletter_subscribe($_REQUEST["nlId"], $_REQUEST["subuser"], "y", $confirmEmail, $addEmail);
91
}
92

93
if (isset($_REQUEST["add"]) && isset($_REQUEST["addall"]) && $_REQUEST["addall"] == "on") {
94 95
	check_ticket('admin-nl-subsriptions');
	$nllib->add_all_users($_REQUEST["nlId"], $confirmEmail, $addEmail);
96
}
97

98
if (isset($_REQUEST["add"]) && isset($_REQUEST['group']) && $_REQUEST['group'] != "") {
99 100
	check_ticket('admin-nl-subsriptions');
	$nllib->add_group_users($_REQUEST["nlId"], $_REQUEST['group'], $confirmEmail, $addEmail);
101
}
102

103
if (((isset($_REQUEST["addbatch"]) && isset($_FILES['batch_subscription'])) || (isset($_REQUEST['importPage']) && !empty($_REQUEST['wikiPageName']))) && $tiki_p_batch_subscribe_email == 'y' && $tiki_p_subscribe_email == 'y') {
104 105 106 107
	check_ticket('admin-nl-subscription');
	// array with success and errors
	$ok = array();
	$error = array();
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
	if (isset($_REQUEST["addbatch"])) {
		if (!$emails = file($_FILES['batch_subscription']['tmp_name'])) {
			$smarty->assign('msg', tra("Error opening uploaded file"));
			$smarty->display("error.tpl");
			die;
		}
	} else if (isset($_REQUEST["importPage"])) {
		
		$emails = $nllib->get_emails_from_page($_REQUEST['wikiPageName']);
		
		if (!$emails) {
			$smarty->assign('msg', tra('Error importing from wiki page: ') . $_REQUEST['wikiPageName']);
			$smarty->display('error.tpl');
			die;
		}
123
	}
124
	
125 126
	foreach($emails as $email) {
		$email = trim($email);
127
		if (empty($email)) continue;
128
		if ($nllib->newsletter_subscribe($_REQUEST["nlId"], $email, 'n', $confirmEmail, 'y')) {
129 130 131 132 133
			$ok[] = $email;
		} else {
			$error[] = $email;
		}
	}
134
}
135

changi67's avatar
changi67 committed
136
if (isset($_REQUEST["addgroup"]) && isset($_REQUEST['group']) && $_REQUEST['group'] != "") {
137
	check_ticket('admin-nl-subsriptions');
138
	$nllib->add_group($_REQUEST["nlId"], $_REQUEST['group'], isset($_REQUEST['include_groups']) ? 'y' : 'n');
139
}
140

changi67's avatar
changi67 committed
141
if (isset($_REQUEST["addincluded"]) && isset($_REQUEST['included']) && $_REQUEST['included'] != "") {
142 143
	check_ticket('admin-nl-subsriptions');
	$nllib->add_included($_REQUEST["nlId"], $_REQUEST['included']);
144
}
145

146 147 148 149
if (isset($_REQUEST["addPage"]) && !empty($_REQUEST['wikiPageName'])) {
	check_ticket('admin-nl-subsriptions');
	$nllib->add_page($_REQUEST["nlId"], $_REQUEST['wikiPageName'], empty($_REQUEST['noConfirmEmail']) ? 'y' : 'n', empty($_REQUEST['noSubscribeEmail']) ? 'y' : 'n');
}
150

151
if (isset($_REQUEST['export'])) {
152 153 154 155 156 157 158 159 160 161 162 163 164
	check_ticket('admin-nl-subsriptions');
	$users = $nllib->get_all_subscribers($_REQUEST['nlId'], 'y');
	$data = "email\n";
	foreach($users as $u) {
		if (!empty($u['email'])) $data.= $u['email'] . "\n";
	}
	header('Content-type: text/plain');
	header('Content-Disposition: attachment; filename=' . $info['name'] . '.csv');
	header('Expires: 0');
	header('Cache-Control: must-revalidate, post-check=0,pre-check=0');
	header('Pragma: public');
	echo $data;
	die;
165
}
166

167
if (!isset($_REQUEST["sort_mode"])) {
168
	$sort_mode = 'subscribed_desc';
169
} else {
170
	$sort_mode = $_REQUEST["sort_mode"];
171
}
172

173
if (!isset($_REQUEST["offset"])) {
174
	$offset = 0;
175
} else {
176
	$offset = $_REQUEST["offset"];
177
}
178

179
$smarty->assign_by_ref('offset', $offset);
180

181
if (isset($_REQUEST["find"])) {
182
	$find = $_REQUEST["find"];
183
} else {
184
	$find = '';
185
}
186

187 188 189
$smarty->assign('find', $find);
$smarty->assign_by_ref('sort_mode', $sort_mode);
$channels = $nllib->list_newsletter_subscriptions($_REQUEST["nlId"], $offset, $maxRecords, $sort_mode, $find);
190
$smarty->assign_by_ref('cant_pages', $channels["cant"]);
191
$smarty->assign_by_ref('channels', $channels["data"]);
changi67's avatar
changi67 committed
192
$sort_mode_g = (isset($_REQUEST["sort_mode_g"])) ? $_REQUEST["sort_mode_g"] : 'groupName_asc';
193
$smarty->assign_by_ref('sort_mode_g', $sort_mode_g);
changi67's avatar
changi67 committed
194
$offset_g = (isset($_REQUEST["offset_g"])) ? $_REQUEST["offset_g"] : 0;
195
$smarty->assign_by_ref('offset_g', $offset_g);
changi67's avatar
changi67 committed
196
$find_g = (isset($_REQUEST["find_g"])) ? $_REQUEST["find_g"] : '';
197 198 199 200 201
$smarty->assign('find_g', $find_g);
$groups_g = $nllib->list_newsletter_groups($_REQUEST["nlId"], $offset_g, $maxRecords, $sort_mode_g, $find_g);
$cant_pages_g = ceil($groups_g["cant"] / $maxRecords);
$smarty->assign_by_ref('cant_pages_g', $cant_pages_g);
$smarty->assign('actual_page_g', 1 + ($offset_g / $maxRecords));
202

203
if ($groups_g["cant"] > ($offset_g + $maxRecords)) {
204
	$smarty->assign('next_offset_g', $offset_g + $maxRecords);
205
} else {
206
	$smarty->assign('next_offset_g', -1);
207
}
208

209
if ($offset_g > 0) {
210
	$smarty->assign('prev_offset_g', $offset_g - $maxRecords);
211
} else {
212
	$smarty->assign('prev_offset_g', -1);
213
}
214

215 216
$smarty->assign_by_ref('groups_g', $groups_g["data"]);
$smarty->assign("nb_groups", $groups_g["cant"]);
217
$included_n = $nllib->list_newsletter_included($_REQUEST["nlId"], 0, -1);
changi67's avatar
changi67 committed
218 219
$smarty->assign('included_n', $included_n);
$smarty->assign('nb_included', count($included_n));
220 221 222
$pages = $nllib->list_newsletter_pages($_REQUEST["nlId"], 0, -1);
$smarty->assign('pages', $pages['data']);
$smarty->assign('nb_pages', $pages['cant']);
223

224
$groups = $userlib->list_all_groups();
225 226 227
$smarty->assign_by_ref('groups', $groups);
$users = $userlib->list_all_users();
$smarty->assign_by_ref('users', $users);
changi67's avatar
changi67 committed
228
$newsletters = $nllib->list_newsletters(0, -1, "created_desc", false, '', '', 'n');
229
$smarty->assign_by_ref('newsletters', $newsletters['data']);
230
include_once ('tiki-section_options.php');
231
ask_ticket('admin-nl-subsriptions');
232

233 234
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
235

236
// Display the template
237
$smarty->assign('mid', 'tiki-admin_newsletter_subscriptions.tpl');
238
$smarty->display("tiki.tpl");