unsubscribe.php 2.33 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 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-page-unsubscribe.php
	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
23 24 25 26
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
	header('Location: ../');
	exit;
}
Scott committed
27

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


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

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


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

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

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

Scott committed
45 46
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
47

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

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


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

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

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

Scott committed
66 67 68 69 70 71 72 73 74
if ($unsubscribed) {
	$qa_content['error'] = strtr(qa_lang_html('users/unsubscribe_complete'), array(
		'^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
75 76


Scott committed
77
return $qa_content;