unsubscribe.php 2.3 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	Description: Controller for unsubscribe page (unsubscribe link is sent in mass mailings)


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

Scott committed
22
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
23
	header('Location: ../../');
Scott committed
24 25
	exit;
}
Scott committed
26

Scott committed
27
require_once QA_INCLUDE_DIR . 'db/users.php';
Scott committed
28 29


Scott committed
30
// Check we're not using single-sign on integration
Scott committed
31

Scott committed
32 33
if (QA_FINAL_EXTERNAL_USERS)
	qa_fatal_error('User login is handled by external code');
Scott committed
34 35


Scott committed
36
// Check the code and unsubscribe the user if appropriate
Scott committed
37

Scott committed
38 39
$unsubscribed = false;
$loginuserid = qa_get_logged_in_userid();
Scott committed
40

Scott committed
41 42
$incode = trim(qa_get('c')); // trim to prevent passing in blank values to match uninitiated DB rows
$inhandle = qa_get('u');
Scott committed
43

Scott committed
44 45
if (!empty($inhandle)) { // match based on code and handle provided on URL
	$userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inhandle, false));
Scott committed
46

Scott committed
47 48 49
	if (strtolower(trim(@$userinfo['emailcode'])) == strtolower($incode)) {
		qa_db_user_set_flag($userinfo['userid'], QA_USER_FLAGS_NO_MAILINGS, true);
		$unsubscribed = true;
Scott committed
50
	}
Scott committed
51
}
Scott committed
52

Scott committed
53
if (!$unsubscribed && isset($loginuserid)) { // as a backup, also unsubscribe logged in user
Scott committed
54 55 56
	qa_db_user_set_flag($loginuserid, QA_USER_FLAGS_NO_MAILINGS, true);
	$unsubscribed = true;
}
Scott committed
57 58


Scott committed
59
// Prepare content for theme
Scott committed
60

Scott committed
61
$qa_content = qa_content_prepare();
Scott committed
62

Scott committed
63
$qa_content['title'] = qa_lang_html('users/unsubscribe_title');
Scott committed
64

Scott committed
65
if ($unsubscribed) {
66
	$qa_content['success'] = strtr(qa_lang_html('users/unsubscribe_complete'), array(
Scott committed
67 68 69 70 71 72 73
		'^0' => qa_html(qa_opt('site_title')),
		'^1' => '<a href="' . qa_path_html('account') . '">',
		'^2' => '</a>',
	));
} else {
	$qa_content['error'] = qa_insert_login_links(qa_lang_html('users/unsubscribe_wrong_log_in'), 'unsubscribe');
}
Scott committed
74 75


Scott committed
76
return $qa_content;