qa-page-feedback.php 5.32 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3 4 5 6 7
/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-include/qa-page-feedback.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Controller for feedback page


	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.
Scott Vivian committed
18

Gideon Greenspan committed
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
	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
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}

	require_once QA_INCLUDE_DIR.'qa-app-captcha.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.php';


//	Get useful information on the logged in user

	$userid=qa_get_logged_in_userid();

	if (isset($userid) && !QA_FINAL_EXTERNAL_USERS)
		list($useraccount, $userprofile)=qa_db_select_with_pending(
			qa_db_user_account_selectspec($userid, true),
			qa_db_user_profile_selectspec($userid, true)
		);

Gideon Greenspan committed
46
	$usecaptcha=qa_opt('captcha_on_feedback') && qa_user_use_captcha();
Gideon Greenspan committed
47 48


Gideon Greenspan committed
49
//	Check feedback is enabled and the person isn't blocked
Gideon Greenspan committed
50 51 52 53

	if (!qa_opt('feedback_enabled'))
		return include QA_INCLUDE_DIR.'qa-page-not-found.php';

Gideon Greenspan committed
54 55 56 57 58 59
	if (qa_user_permit_error()) {
		$qa_content=qa_content_prepare();
		$qa_content['error']=qa_lang_html('users/no_permission');
		return $qa_content;
	}

Gideon Greenspan committed
60 61

//	Send the feedback form
Scott Vivian committed
62

Gideon Greenspan committed
63
	$feedbacksent=false;
Scott Vivian committed
64

Gideon Greenspan committed
65 66 67
	if (qa_clicked('dofeedback')) {
		require_once QA_INCLUDE_DIR.'qa-app-emails.php';
		require_once QA_INCLUDE_DIR.'qa-util-string.php';
Scott Vivian committed
68

Gideon Greenspan committed
69 70 71 72
		$inmessage=qa_post_text('message');
		$inname=qa_post_text('name');
		$inemail=qa_post_text('email');
		$inreferer=qa_post_text('referer');
Scott Vivian committed
73

Gideon Greenspan committed
74 75
		if (!qa_check_form_security_code('feedback', qa_post_text('code')))
			$pageerror=qa_lang_html('misc/form_security_again');
Scott Vivian committed
76

Gideon Greenspan committed
77 78 79
		else {
			if (empty($inmessage))
				$errors['message']=qa_lang('misc/feedback_empty');
Scott Vivian committed
80

Gideon Greenspan committed
81 82
			if ($usecaptcha)
				qa_captcha_validate_post($errors);
Scott Vivian committed
83

Gideon Greenspan committed
84 85 86 87 88 89 90 91 92 93
			if (empty($errors)) {
				$subs=array(
					'^message' => $inmessage,
					'^name' => empty($inname) ? '-' : $inname,
					'^email' => empty($inemail) ? '-' : $inemail,
					'^previous' => empty($inreferer) ? '-' : $inreferer,
					'^url' => isset($userid) ? qa_path_absolute('user/'.qa_get_logged_in_handle()) : '-',
					'^ip' => qa_remote_ip_address(),
					'^browser' => @$_SERVER['HTTP_USER_AGENT'],
				);
Scott Vivian committed
94

Gideon Greenspan committed
95 96 97 98 99 100 101 102 103 104 105 106
				if (qa_send_email(array(
					'fromemail' => qa_email_validate(@$inemail) ? $inemail : qa_opt('from_email'),
					'fromname' => $inname,
					'toemail' => qa_opt('feedback_email'),
					'toname' => qa_opt('site_title'),
					'subject' => qa_lang_sub('emails/feedback_subject', qa_opt('site_title')),
					'body' => strtr(qa_lang('emails/feedback_body'), $subs),
					'html' => false,
				)))
					$feedbacksent=true;
				else
					$pageerror=qa_lang_html('main/general_error');
Scott Vivian committed
107

Gideon Greenspan committed
108 109 110 111 112 113 114 115
				qa_report_event('feedback', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array(
					'email' => $inemail,
					'name' => $inname,
					'message' => $inmessage,
					'previous' => $inreferer,
					'browser' => @$_SERVER['HTTP_USER_AGENT'],
				));
			}
Gideon Greenspan committed
116 117
		}
	}
Scott Vivian committed
118 119


Gideon Greenspan committed
120 121 122 123 124
//	Prepare content for theme

	$qa_content=qa_content_prepare();

	$qa_content['title']=qa_lang_html('misc/feedback_title');
Scott Vivian committed
125

Gideon Greenspan committed
126
	$qa_content['error']=@$pageerror;
Gideon Greenspan committed
127 128

	$qa_content['form']=array(
Gideon Greenspan committed
129
		'tags' => 'method="post" action="'.qa_self_html().'"',
Scott Vivian committed
130

Gideon Greenspan committed
131
		'style' => 'tall',
Scott Vivian committed
132

Gideon Greenspan committed
133 134 135 136
		'fields' => array(
			'message' => array(
				'type' => $feedbacksent ? 'static' : '',
				'label' => qa_lang_html_sub('misc/feedback_message', qa_opt('site_title')),
Gideon Greenspan committed
137
				'tags' => 'name="message" id="message"',
Gideon Greenspan committed
138 139 140 141 142 143 144 145
				'value' => qa_html(@$inmessage),
				'rows' => 8,
				'error' => qa_html(@$errors['message']),
			),

			'name' => array(
				'type' => $feedbacksent ? 'static' : '',
				'label' => qa_lang_html('misc/feedback_name'),
Gideon Greenspan committed
146
				'tags' => 'name="name"',
Gideon Greenspan committed
147 148 149 150 151 152
				'value' => qa_html(isset($inname) ? $inname : @$userprofile['name']),
			),

			'email' => array(
				'type' => $feedbacksent ? 'static' : '',
				'label' => qa_lang_html('misc/feedback_email'),
Gideon Greenspan committed
153
				'tags' => 'name="email"',
Gideon Greenspan committed
154 155 156 157
				'value' => qa_html(isset($inemail) ? $inemail : qa_get_logged_in_email()),
				'note' => $feedbacksent ? null : qa_opt('email_privacy'),
			),
		),
Scott Vivian committed
158

Gideon Greenspan committed
159 160 161 162 163
		'buttons' => array(
			'send' => array(
				'label' => qa_lang_html('main/send_button'),
			),
		),
Scott Vivian committed
164

Gideon Greenspan committed
165 166
		'hidden' => array(
			'dofeedback' => '1',
Gideon Greenspan committed
167
			'code' => qa_get_form_security_code('feedback'),
Gideon Greenspan committed
168 169 170
			'referer' => qa_html(isset($inreferer) ? $inreferer : @$_SERVER['HTTP_REFERER']),
		),
	);
Scott Vivian committed
171

Gideon Greenspan committed
172 173 174 175 176
	if ($usecaptcha && !$feedbacksent)
		qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors);


	$qa_content['focusid']='message';
Scott Vivian committed
177

Gideon Greenspan committed
178 179 180 181 182
	if ($feedbacksent) {
		$qa_content['form']['ok']=qa_lang_html('misc/feedback_sent');
		unset($qa_content['form']['buttons']);
	}

Scott Vivian committed
183

Gideon Greenspan committed
184
	return $qa_content;
Scott Vivian committed
185

Gideon Greenspan committed
186 187 188 189

/*
	Omit PHP closing tag to help avoid accidental output
*/